Wednesday, February 22, 2012

Sorting an array using VBScript/ QTP

Following code can be used to sort an array using QTP. Let sortme is name of the array which is to be sorted. I have used "Bubble Sort" principle of sorting.





A) Descending Sort
For a = UBound(sortme) - 1 To 0 Step -1
  For j= 0 to a
If sortme(j+1) > sortme(j) Then
temp = sortme(j)
sortme(j) = sortme(j+1)
sortme(j+1) = temp
End If
Next
Next




B) Ascending Sort
For a = UBound(sortme) - 1 To 0 Step -1
  For j= 0 to a
If sortme(j+1) < sortme(j) Then
temp = sortme(j)
sortme(j) = sortme(j+1)
sortme(j+1) = temp
End If
Next
Next

1 comment: