PDA

View Full Version : Solved: Sorting numeric and non-numeric text.



Gracon
04-02-2007, 02:49 PM
Hello,

I am working on a project where the program scans a Word document for references to Figures or Illustrations and then fills in a Text box with the results of the search.

The problem I run into, is that some of the Fig. numbers are non-numeric (as in 1-1 or 1A), so I have to store the values in a String variable type and am having issues sorting them.
Example: Document references Figs 1 - 10 and 10-1.
Code returns: 1, 10-1, 2, 3, (etc.)

My numeric sort is taken care of with a standard bubble sort (will be changing as it's slow), but I don't know of an easy way to sort the 1A and 1-1 types. I was thinking of splitting the 1-1 types into a multi-dimensional array with half of the number in each side, and then sorting that numericly, but I'm hoping that someone might know of an easier way. : pray2:

Any Ideas?


-Gracon

TrippyTom
04-02-2007, 04:44 PM
Hi Gracon,

Try this (from the help files under "Troubleshoot Sorting"):


If you sort the data numerically, numbers that contain hyphens (such as phone numbers or postal codes) might be sorted incorrectly.

Try one of the following solutions:

Sort the data by text. Select the list or table, and then click Sort on the Table menu. In the Type box, click Text. Finally, complete the sort as usual.

Replace the hyphens before you sort. Try this option if you want to sort the data numerically. First, use the Find and Replace feature to replace the hyphens with periods (.). Select the list or table, and then click Sort on the Table menu. In the Type box, click Number. Then complete the sort as usual. Finally, replace the periods with hyphens.

fumei
04-03-2007, 03:19 AM
I believe this is being attempted programmatically.

Gracon
04-05-2007, 08:14 AM
Hello,

Yes I was attempting to do this programmatically, but I was able to adapt Tom's idea of changing the dashes to periods, since a 1.1 type is not allowed. Thanks for that!

As for the alphanumeric types, I decided to split the text each time it changed between numeric and alphabetic. That allowed me to sort with purely numeric or purely alphabetic.

Thanks a lot for the help!

-Gracon