Sorting by item ... of each and item ... of each

Ralph DiMola rdimola at evergreeninfo.net
Tue Sep 5 17:05:50 EDT 2023


You can at least detect if the sorting function has failed using a global
variable.

global s1

command test1
   local t1
   
   --put "10,9,8,7,6,5,4,3,2,1" into t1 -- This line will not show an error
   put "10,9,8,7a,6,5,4,3,2,1" into t1 -- This line will show an error
   
   put 0 into s1
   sort items of t1 numeric by f1(each)
   
   if s1 <> the number of items in t1 then answer "Sort Function failed"
   put t1 & cr & s1
   
end test1


function f1 pEach
   local tEach
   put pEach into tEach
   add 1 to tEach
   add 1 to s1
   return tEach
end f1

Ralph DiMola
IT Director
Evergreen Information Services
rdimola at evergreeninfo.net

-----Original Message-----
From: use-livecode [mailto:use-livecode-bounces at lists.runrev.com] On Behalf
Of matthias rebbe via use-livecode
Sent: Saturday, September 02, 2023 9:03 PM
To: How to use LiveCode
Cc: matthias_livecode_150811 at m-r-d.de
Subject: Re: Sorting by item ... of each and item ... of each

Of course my "not working" sort code look like this

set the itemdelimiter to  ";"
sort lines of tList numeric by item 3 of each and item 2 of each.




> Am 03.09.2023 um 02:59 schrieb matthias_livecode_150811 at m-r-d.de:
> 
> Maybe i do not see the forest for the trees....
> 
> I have a tab delimited list which i want to sort. I am using this code to
sort it by item 3 and  item 2
> 
> set the itemdelimiter to tab
> sort lines of tList numeric by item 3 of each and item 2 of each.
> 
> But that code does not sort as i expected it. Column 2 is not sorted
correctly.
> The following list is the result. 
> 
> 113254;8420;3016365
> 113254;8423;3016365
> 113254;8422;3016365
> 113254;8420;3016365
> 113254;8420;3016365
> 113254;8420;3016365
> 113254;8421;3016365
> 203212;8420;3016366
> 203212;8423;3016366
> 203212;8422;3016366
> 203212;8420;3016366
> 
> 
> My expectation for example  was that for value 3016365 in column 3 the
values in Col 2 would be sorted like this
> 
> 113254;8423;3016365
> 113254;8422;3016365
> 113254;8421;3016365
> 113254;8420;3016365
> 113254;8420;3016365
> 113254;8420;3016365
> 113254;8420;3016365
> 
> Tried also    'by item 2 of each and item 3 of each', but the sort result
is the same?
> 
> Am i missing something?
> 
> Regards,
> Matthias
> 


_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list