How to sort in QTP?
With the ‘System.Collections.Arraylist’,we can sort,
sBf=""
Set myObj=CreateObject("System.Collections.ArrayList")
myObj.Add("1")
myObj.Add("4")
myObj.Add("5")
myObj.Add("8")
myObj.Add("0")
myObj.Add("9")
myObj.Add("6")
myObj.Add("3")
myObj.Add("2")
myObj.sort()
myObj.reverse() 'Disable this line if you want to sort in an ascending order.
For each sNames in myObj
sBf=sBf&sNames&"-->"
Next
msgbox sBf,0,"Ascending order"
Set myObj=Nothing
(OR)
Dim narray(5)
narray(0) = "abc"
narray(1) = "d"
narray(2) = "ef"
narray(3) = 10
narray(4) = 2
For i = 0 to ubound(narray)
For j = i + 1 to ubound(narray)
If narray(i) > narray(j) Then
temp = narray(j)
narray(j) = narray(i)
narray(i) = temp
End If
Next
Next
For i = lbound(narray) to ubound(narray)
msg = msg& " " & narray(i)
Next
Msgbox msg
sBf=""
Set myObj=CreateObject("System.Collections.ArrayList")
myObj.Add("1")
myObj.Add("4")
myObj.Add("5")
myObj.Add("8")
myObj.Add("0")
myObj.Add("9")
myObj.Add("6")
myObj.Add("3")
myObj.Add("2")
myObj.sort()
myObj.reverse() 'Disable this line if you want to sort in an ascending order.
For each sNames in myObj
sBf=sBf&sNames&"-->"
Next
msgbox sBf,0,"Ascending order"
Set myObj=Nothing

Dim narray(5)
narray(0) = "abc"
narray(1) = "d"
narray(2) = "ef"
narray(3) = 10
narray(4) = 2
For i = 0 to ubound(narray)
For j = i + 1 to ubound(narray)
If narray(i) > narray(j) Then
temp = narray(j)
narray(j) = narray(i)
narray(i) = temp
End If
Next
Next
For i = lbound(narray) to ubound(narray)
msg = msg& " " & narray(i)
Next
Msgbox msg

Comments
Post a Comment