Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

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

Posted on 2004-10-04
Medium Priority
552 Views
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
Question by:ucla11
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 96

Expert Comment

ID: 12221392
0

LVL 4

Accepted Solution

eozz_2000 earned 1000 total points
ID: 12221729
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

LVL 4

Expert Comment

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

LVL 96

Expert Comment

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

Bob

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
###### Suggested Courses
Course of the Month6 days, 14 hours left to enroll