• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3845
  • Last Modified:

Sorting Numbers and Finding Next Highest Number

I am needed suggestions on how to accomplish the following task with numbers.

Step 1: Sort the numbers.
Step 2: Select one of the numbers in the list.
Step 3: Find the next highest number from the number selected in step 2.

For example, my app is returning a list of numbers, such as:


Of course, in the example above, the list is not truly sorted as 12 should be after the 1 in the list.
1 Solution
Jaime OlivaresSoftware ArchitectCommented:
Well, there are many sorting algorithms, the easiest I think is sustitution:
Just scan all elements of array (minus one) and compare with the next element, if greater, swap them. Scan again until no swap is made.
once ordered select a number in the list (array) and the next element will be next highest number.
How do you get the numbers, in an arrray ? Where do you want them to get sorted ? In a listbox ?
Jaime OlivaresSoftware ArchitectCommented:
Start creating an array with numbers:

Dim myArray(10) as Integer
myArray(1) = 1
myArray(2) = 1177

Use a for ... next statement
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

If the numbers are in a Listbox you can set the sorted property to true and use Format to add 0's so they sort properly.

List1.AddItem Format("1", "000#")
List1.AddItem Format("1177", "000#")
List1.AddItem Format("12", "000#")
Glen A.IT Project ManagerCommented:
If this is a listbox you can pad the items in the listbox with spaces, then it sorts properly.

IE:  if you populate the listbox this way, with spaces, then it will be sorted.

   List1.AddItem "   1"
   List1.AddItem "1177"
   List1.AddItem "1189"
   List1.AddItem "  12"
   List1.AddItem "1237"
   List1.AddItem "1261"
   List1.AddItem "1377"

Glen A.IT Project ManagerCommented:
lol, posted mine after vinnyd79's -  his would work just as well, even better...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now