Thanks:  0
Likes:  0
Dislikes:  0

1. ## Sort Number qtp(VBscript)

How can i write a QTP or VBscript for sorting numbers ascending or descending

02,86,22,92,08,06,.....

2. Sub Sort(Ar)
Cnt = UBound(Ar)
For i = 0 To Cnt-1
For j = 0 To Cnt-1-i
If Ar(j+1) < Ar(j) Then
tmp = Ar(j)
Ar(j) = Ar(j+1)
Ar(j+1) = tmp
End If
Next
Next
End Sub

Ar = Array(5,3,2,4,1)

Call Sort(Ar)

MsgBox Ar(0)
MsgBox Ar(1)
MsgBox Ar(2)
MsgBox Ar(3)
MsgBox Ar(4)

Mark Smith

3. another way
'02,86,22,92,08,06,.....
Set objArrayList = CreateObject( "System.Collections.ArrayList" )
objArrayList.sort
objArrayList.Remove(06)

For Each al In objArrayList
WScript.Echo al
Next

4. Seems like everyone's first 2 years of every computer science major is writing sort algorithms over and over again.
1st semester - Beginning programming class, usually the 3rd assignment is sorting an array.
2nd semester - calculating big O(n), and examples always used is sorting
3rd semester - data structures, again sorting is the common assignments for applying those data structures. (B-Trees, linked lists, etc..)
4th semester - programming patterns. Usually 1/2 the assignments involve prioritizing, which coincidentally involves sorting.

Originally Posted by venkatswapna
How can i write a QTP or VBscript for sorting numbers ascending or descending

02,86,22,92,08,06,.....

5. dlai, there are several ways to do a tasks, but chosing the optimal way is always difficult....

6. I learned GW BASIC at DeVry around 1981 while going for an Electronics Engineering degree. Here I am still using some form of BASIC. I hardly ever run into Voltage = Current times resistance.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.