Guidance指路人g.yi.org Guidance Forums / Reginald Rexx / Sort question
 最新 LeonAutoBackup
 Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next  1 1. Sort question#11891Posted by: Michael S 2007-09-22 09:55:27 Last edited by: Michael S 2007-09-22 10:16:34 (Total edited 1 time) Given the following example``` temp.0 = 9 temp.1 = 'hello 2007/03/12-10:01' temp.2 = 'hellohello 2007/03/12-10:00' temp.3 = 'adam 2007/04/12-10:00' temp.4 = 'eve 2007/03/12-10:00' temp.5 = 'stockholm 2007/03/12-10:00' temp.6 = 'london 2007/05/28-10:00' temp.7 = 'me 2007/03/12-10:00' temp.8 = 'yes 2007/03/12-10:00' temp.9 = 'no 2007/03/12-10:00' SORT temp. . a +4 b +6 c +9 DO i = 1 TO temp.0 SAY 'temp.'i' = 'temp.i END ```what I'm trying to do is to sort the stem based on the (in this example) year, month and day in ascending order. By specifing the dot after temp. I imagined that the lengths would be taken from the beginning of the next word, but that doesn't seem to be working (unless I'm doing it wrong). Is there a way of doing the above without aligning the columns so that all the dates are "under" each other ?(I also tried sort temp. . A which works fine in this scenario. The reason I include the positional parms is when the dates are a different format, English for example. The example above is Swedish date formatting which means that the simple sort temp. . A works okay) 2. #11926Posted by: DougA 2007-10-01 23:43:16 There does appear to be some confusion as to how the +nn value works when it's used as in your example.  Jeff would have to explain.However, how about using this instead:SORT temp. .  a '/' b '/' c '-'Doug 3. I don't think that will work#11929Posted by: Michael S 2007-10-02 15:23:41 Remember, I'm trying to sort based on years, months and days. Where these items are in the date string depends on the XP language you have. I would have (?) have variations like ``` SORT temp. c '/' b '/' a '-' ```for the language that has its date as 28/03/2003, but ``` SORT temp. a '/' c '/' b '-' ```for the language that has its date as 2003/28/03 (not sure if the examples are correct, but you get my drift) 4. #11934Posted by: DougA 2007-10-03 21:54:36 Doesn't your original example, using offsets, have the same issue ?If the issue is the XP setting,  how about converting the date into a non-position form ?  Say  basedate, then sort that ?Doug 5. That's the whole point#11935Posted by: Michael S 2007-10-04 01:08:54 Last edited by: Michael S 2007-10-04 01:18:00 (Total edited 1 time) I calculate/generate the offsets based on an attempted interpretation of the date received. In the other append (?) I showed that if you use hard-coded values for the offsets, the sort worked, but not when the offsets were variables.I tried your example as in``` temp.0 = 9 temp.1 = 'hello 09/03/2007-10:00' temp.2 = 'hellohello 12/03/2007-11:00' temp.3 = 'adam 12/04/2007-12:00' temp.4 = 'eve 12/03/2007-10:00' temp.5 = 'stockholm 12/03/2005-10:23' temp.6 = 'london 28/05/2007-12:32' temp.7 = 'me 12/03/2007-12:12' temp.8 = 'yes 12/03/2007-12:12' temp.9 = 'no 12/03/2007-12:12' SORT temp. . c '/' b '/' a '-' . DO i = 1 TO temp.0 SAY 'temp.'i' = 'temp.i END ```but as you can see, unless you can see hat I'm doing something wrong, it doesn't seem to be working with this variation either. 6. #11936Posted by: DougA 2007-10-04 01:46:20 Last edited by: DougA 2007-10-04 01:48:33 (Total edited 1 time) I don't think offsets can be placed into variables  (someone correct me if that's wrong )Since you have to calculate/generate offsets, you have the logic to determine which order it's in, can't you then do something like:Select  when {somelogic} then sort temp. .  a '/'  b '/' c '-' .  when {somelogic} then sort temp. .  c '/'  b '/' a '-' .  else                               sort temp. .  b '/'  c '/' a '-' .endAt least the logic would be clearer I'd think.(edit ... I guess you could use this same approach with hard coded offsets too)As to the example, here are my results:temp.1 = stockholm  12/03/2005-10:23temp.2 = me         12/03/2007-12:12temp.3 = no         12/03/2007-12:12temp.4 = eve        12/03/2007-10:00temp.5 = yes        12/03/2007-12:12temp.6 = hello      09/03/2007-10:00temp.7 = hellohello 12/03/2007-11:00temp.8 = adam       12/04/2007-12:00temp.9 = london     28/05/2007-12:32It looks ok, except for the 'c' sort (item 6) ... this looks like a bug in the sortDoug Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next  1