Solved

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

Posted on 2004-10-04
4
535 Views
Last Modified: 2008-02-01
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
Comment
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
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12221392
0
 
LVL 4

Accepted Solution

by:
eozz_2000 earned 250 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

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

Expert Comment

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

Bob

0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - String Manipulation Scenario 2 45
vb.net background worker crossthread 11 46
Need to Interpret Json in Vb.net ( .net 3.5  framework) 11 52
vb.net code 9 29
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question