[TIP] Sorting by ValueList and synchronized sorting
FlexibleLearning at tiscali.co.uk
Sat Jun 14 13:25:35 CDT 2008
Have you needed to sort lists by a value list or synchronize different
lists, but thought it not easily do-able in Rev? You may find the following
In a field, type some lines where the first word is a random day of the
sort lines of fld 1 by valueList(word 1 of each)
function valueList what
put "Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday" into tList
Of couse you could also apply any valid chunking expression such as (word 2
to -1 of item 3 of each), apply the valueList sort to variables as well as
fields, store multiple valueLists as re-usable custom properties, make the
valueList conditional upon other factors and so on. The point is that the
built-in sort keys can be extended to include your own preferential order.
Applying the same logic above to multiple fields (or indeed variables), the
following implements parallel sorting of linked fields, keeping the lists
synchronized (based on an old HyperCard script by Brett Sher)...
Create 3 fields called 'data1', 'data2' and 'data3'. Add lines of text into
each field, for example a list of first names, last names, ages, then...
sortBy "data1" --| Sort by first name
on sortBy keyField
put fld keyField into lKeyData
put "data1,data2,data3" into dataFields --| fill in your own field names
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()
add 1 to lLineCounter
return line lLineCounter of lKeyData
Hope some of you may find the above helpful.
www.ssBk.co.uk, Home of the Scripter's Scrapbook
More information about the use-livecode