Solved

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

Posted on 2004-10-04
4
490 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
Comment Utility
0
 
LVL 4

Accepted Solution

by:
eozz_2000 earned 250 total points
Comment Utility
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
Comment Utility
of course, if you are gonna play with higher values you can use Int64 or Double.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
You could also do it by implementing the IComparer method.

Bob

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB.Net - Find String in Array 3 25
GridDataView 6 44
Copy a file to a share on a Domain 3 53
visual Basic Net vs c# net 8 52
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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now