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

Jim Ault JimAultWins at yahoo.com
Tue Mar 20 17:36:48 EDT 2007


This specific technique can be used to branch to the one that will work for
you.  The basic idea is to sort varB by the values in varA using a temporary
array.

Restrictions:  
varA and varB have the same number of items to be sorted
varA has unique values
varB has unique values

-------------
   put varA into varAoriginal
   set the itemdel to "^"
    repeat with x = 1 to the number of items in varA --before sorting
      put x into tempArrayOfVarA[item x of varA]
    end repeat
    sort items of varA descending
    repeat with x = 1 to the number of items in varA  --now sorted
      --now we find the orignal 'x' before sorting
      put tempArrayOfVarA[item x of varA] into k
      put item k of varB & "^" after varNewB
    end repeat
    delete the last char of varNewB
    put varNewB into varB

and now we could use
varAoriginal, or varA, but in either case varB is in new sort order,
-------------
Also will work with
sort lines

I could not find an easy way to get "sort by each" to handle this, unless it
built a script local or global to hold the original 'x', so I just used an
array.

Jim Ault
Las Vegas





More information about the use-livecode mailing list