sorting numbers in a listbox in desending order , Arrays and BubbleSort

I want to make a program that will sort the users inputed numbers in a desending order.  On my form I  have a listbox ,a texrbox and two Buttons.
The user enters a several numbers  (anywhere from a value of 1 to a million or so) example: 2; 25; 1,794; 4,009,546 etc.  They then click one of the cmdButtons and this number is added to the listbox and I am guessing to an array.  Once the user has entered all the numbers they need sorted., they click the other Button and the  numbers in the listbox are sorted.  I am not familiar with sorting(bubble, quick) or arrays (how to populate them in real time)so any code on how to accomplish this would be greatly appreciated.  Also I guess I would need a third button  to clear listbox and the array (ReDim?) so the user could enter a new set of numbers to be sorted from least to greatest.
Asked:
Who is Participating?

Commented:
Dim i, j As Integer
For i = 0 To Me.ListBox1.Items.Count - 2
For j = i + 1 To Me.ListBox1.Items.Count - 1
If CInt(Me.ListBox1.Items.Item(i)) < CInt(Me.ListBox1.Items.Item(j)) Then
Dim aux As Integer
aux = CInt(Me.ListBox1.Items.Item(i))
Me.ListBox1.Items.Item(i) = Me.ListBox1.Items.Item(j)
Me.ListBox1.Items.Item(j) = aux
End If
Next
Next

Descending order
0

Commented:
0

Commented:
of course, if you are gonna play with higher values you can use Int64 or Double.
0

Commented:
You could also do it by implementing the IComparer method.

Bob

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Already a member? Login.

All Courses

From novice to tech pro — start learning today.