• Status: Solved
• Priority: Medium
• Security: Public
• Views: 3847

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:

1
1177
1189
12
1237
1261
1377

Of course, in the example above, the list is not truly sorted as 12 should be after the 1 in the list.
0
abnc
1 Solution

Software 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.

0

Commented:
How do you get the numbers, in an arrray ? Where do you want them to get sorted ? In a listbox ?
0

Software ArchitectCommented:
Start creating an array with numbers:

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

Use a for ... next statement
0

Commented:
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.

0

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.

0

IT Project ManagerCommented:
lol, posted mine after vinnyd79's -  his would work just as well, even better...
0
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.