Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 562
  • Last Modified:

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.
0
ucla11
Asked:
ucla11
  • 2
  • 2
1 Solution
 
Bob LearnedCommented:
0
 
eozz_2000Commented:
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
 
eozz_2000Commented:
of course, if you are gonna play with higher values you can use Int64 or Double.
0
 
Bob LearnedCommented:
You could also do it by implementing the IComparer method.

Bob

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now