Click to See Complete Forum and Search --> : Sorting Integer arrays


JasonB
October 18th, 1999, 03:49 PM
Hi,

I'm taking a VB course at evening class and I have been given the task of generating lottery numbers.

I need to sort the generated numbers into ascending order and display them at the bottom of the form. I have tried putting the values into a sorted listbox but this seems to add a second copy of the numbers.

eg 1, 1, 23, 23 .....

Can anyone help?

I would be most grateful for any suggestions.

BrewGuru99
October 18th, 1999, 04:30 PM
Not to do your homework or anything, but here you go: (I ought to tell your teacher of this!!!)


for a = LBound(Lottery) to UBound(Lottery) 'Pass through the array once for every index.
for b = LBound(Lottery) to UBound(Lottery) - 1
If Lottery(b) > Lottery(b + 1) then 'Swap positions if number is greater
temp = Lottery(b + 1)
Lottery(b + 1) = Lottery(i)
Lottery(b) = temp
End If
next
next