Sorting Multiple Fields

Alex Tweedly alex at tweedly.net
Sat Apr 30 19:54:12 EDT 2005


Roger Guay wrote:

> I have 6 list fields side-by-side each with the same number of  
> lines,  with synchronized scrolling and synchronized hilitedLines.   
> Is there an easy way to sort the first field and have the data in the  
> other fields follow the sort.  That is to sort the whole group on the  
> first field?
>
Seems like there should be an easy way, doesn't it :-)

but I couldn't  think of one when I did something similar recently - 
here's what  I came up with is (with 3 fields to save me typing)

>   set the itemDel to TAB
>   put 0 into ct
>   put empty into temp
>   repeat for each line L in field "F1"
>     put L & TAB & line ct of field "F2" & TAB & line ct of field "F3" 
> & cr after temp
>     add 1 to ct
>   end repeat
>   sort temp
>   put empty into field "F1"
>   put empty into field "F2"
>   put empty into field "F3"
>   repeat for each line L in temp
>     put item 1 of L & cr after field "F1"
>     put item 2 of L & cr after field "F2"
>     put item 3 of L & cr after field "F3"
>   end repeat
>  

Note - it would be faster to copy the whole of each field into a 
variable before doing something like the above - then copying the whole 
variable back at the end; only worth it if these are very large fields.


-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.10.4 - Release Date: 27/04/2005



More information about the use-livecode mailing list