[TIP} co-sort variable 1 based on values in variable 2

J. Landman Gay jacque at hyperactivesw.com
Wed Mar 21 14:20:14 EDT 2007


Jim Ault wrote:

> It is pretty simple actually, and here is an example.
> 
> Let's say one list you have last names, in another, their telephone numbers
> in the same order.  You need to keep two separate lists, but you would like
> both sorted to the same order, according to the last names.

After getting some sleep, I realized you were talking about parallel 
sorts. Dick's way is much cooler than what I've always done, which uses 
a custom sort function:

** Parallel sort ***

local lKeyData, lLineCounter

on sortBy keyField -- parallel sorting of linked flds
   put fld keyField into lKeyData
   put "data1,data2,data3" into dataFields -- fill in your fld names here
   repeat with i = 1 to the number of items of dataFields
     put 0 into lLineCounter
     sort lines of fld (item i of dataFields) by key()
   end repeat
end sortBy

function key
   add 1 to lLineCounter
   return line lLineCounter of lKeyData
end key

This sorts lines, but the idea is the same. I like Dick's better.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list