Solved

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
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…

615 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