Solved

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

Posted on 2004-10-04
4
522 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

837 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