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
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
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
Can u please post from initializing array !!..
ReplyDelete