How do you sort 2 3 10 20 1 into proper order

I have spent hours of trying to sort this out (I am sure I am not looking in the right place).

I have a TextField into which a user can type only Integers (I have that covered) separated by a space. Here is a possible input: “1 2 3 4 5 6 10 25 3 2” - this is the result: “1 10 2 2 25 3 3 4 5 6”.

How can I get the 10 and 25 (and probably 100 and 299) into the correct order? I want to use these integers further in the program, but I think it would look better (more professional) if they were in proper numerical order. I notice the same thing happens on Windows.

Thanks in advance

what your seeing is the difference between sorting “strings” - which sort lexically (dictionary style) - vs sorting “numbers” which sort numerically

convert the items to numeric values & sort them by their numeric value

Oh, thanks Norman. I wish I had waited about 20 seconds for my “solution”. Yours is much simpler, and easier to do.

Another bit of information added to the mystery.

Thanks a lot

Also keep SortWith in mind. You can “sort” an array into any arbitrary order by creating a second, “index” array, filling it with values that determine order, then sorting it along with your original array. In your case, if you wanted to keep the original array as strings instead of converting them to integers, you’d do this:

dim IntArr() as Integer
redim IntArr( StrArr.Ubound )
for i as Integer = 0 to StrArr.Ubound
  IntArr( i ) = Val( StrArr( i ) )
next i

IntArr.SortWith( StrArr )
// Now StrArr is in numerical order instead of "alphabetical" order

Thanks Kem,
Works Great.
Lennox

Nice !

Less for a Magazine Column where you have the name and issue number.

This let me think “why do I put the magazine name in the issue # column (or index column) ?"
(bad) Habits ?

Lennox: 1 year, 4 months and some days to send the answer ? (or !)

Put the issue number in ColumnTag (or CellTag ?) at ListBox filling time and use that to sort the Rows by the colum’s tag # ?