Dim Topp(10), Bottom(10), array$(2, 26), LastArray
Sub B_SortArray_Click ()
Call SortArray(array$())
For i = 0 To LastArray
List2.List(i) = array$(1, i)
List3.List(i) = array$(2, i)
Next
Label4.caption = "Note that the second element of the array is sorted along with the first."
End Sub
Sub B_SortList_Click ()
Call SortList(List1)
Label1.caption = "Note that the lines are sorted alphabetically, not numerically."
End Sub
Sub Command1_Click ()
Msg$ = "This sample program contains two routines: " + Chr$(10) + Chr$(13)
Msg$ = Msg$ + "One to sort a List box and one to sort an array. " + Chr$(10) + Chr$(13) + Chr$(10) + Chr$(13)
Msg$ = Msg$ + "The routines are under General Proc.'s " + Chr$(10) + Chr$(13) + Chr$(10) + Chr$(13)
Msg$ = Msg$ + "This sample file is Copyright 1991 Nelson Ford, PsL."
Msg$ = Msg$ + "You may modify and use the routines. You may also distribute this file to others, as long you do not change the contents." + Chr$(10) + Chr$(13) + Chr$(10) + Chr$(13)
Msg$ = Msg$ + "For more routines for VB, see DLs 1 and 6 on MSLANG on CIS, "
Msg$ = Msg$ + "or call Public (software) Library for a free newsletter. "
Msg$ = Msg$ + "800-242-4775 or on CIS: 71355,470."
MsgBox Msg$
End Sub
Sub Form_Load ()
For i = 26 To 1 Step -1
List1.AddItem Str$(i)
Next
j = 0
For i = 90 To 65 Step -1
List2.AddItem Chr$(i)
List3.AddItem Str$(i)
array$(1, j) = Chr$(i)
array$(2, j) = Str$(i)
j = j + 1
Next
LastArray = 25
End Sub
Sub SortArray (array$())
MousePointer = 11
Ply = 1
Bottom(1) = 0
Topp(1) = LastArray
While Ply > 0
If Bottom(Ply) >= Topp(Ply) Then
Ply = Ply - 1
Else
i = Bottom(Ply) - 1
j = Topp(Ply)
Pt$ = array$(1, j)
While i < j
i = i + 1
j = j - 1
While array$(1, i) < Pt$: i = i + 1: Wend
While array$(1, j) > Pt$ And j > i: j = j - 1: Wend
If i < j Then
x$ = array$(1, i)
array$(1, i) = array$(1, j)
array$(1, j) = x$
x$ = array$(2, i)
array$(2, i) = array$(2, j)
array$(2, j) = x$
End If
Wend
j = Topp(Ply)
If i <> j And array$(1, i) > array$(1, j) Then
x$ = array$(1, i)
array$(1, i) = array$(1, j)
array$(1, j) = x$
x$ = array$(2, i)
array$(2, i) = array$(2, j)
array$(2, j) = x$
End If
If i - Bottom(Ply) < Topp(Ply) - i Then
Bottom(Ply + 1) = Bottom(Ply)
Topp(Ply + 1) = i - 1
Bottom(Ply) = i + 1
Else
Topp(Ply + 1) = Topp(Ply)
Bottom(Ply + 1) = i + 1
Topp(Ply) = i - 1
End If
Ply = Ply + 1
End If
Wend
MousePointer = 0
End Sub
Sub SortList (slist1 As Control)
MousePointer = 11
Ply = 1
Bottom(1) = 0
Topp(1) = slist1.listcount - 1
While Ply > 0
If Bottom(Ply) >= Topp(Ply) Then
Ply = Ply - 1
Else
i = Bottom(Ply) - 1
j = Topp(Ply)
Pt$ = slist1.List(j)
While i < j
i = i + 1
j = j - 1
While slist1.List(i) < Pt$: i = i + 1: Wend
While slist1.List(j) > Pt$ And j > i: j = j - 1: Wend
If i < j Then
x$ = slist1.List(i)
slist1.List(i) = slist1.List(j)
slist1.List(j) = x$
End If
Wend
j = Topp(Ply)
If i <> j And slist1.List(i) > slist1.List(j) Then