[TIP} co-sort variable 1 based on values in variable 2
JimAultWins at yahoo.com
Tue Mar 20 23:52:10 CDT 2007
On 3/20/07 7:47 PM, "J. Landman Gay" <jacque at hyperactivesw.com> wrote:
> Jim Ault wrote:
>> The basic idea is to sort varB by the values in varA using a temporary
> Do you need to use an array? Would this do?:
> sort items of varB by itemOffset(each,varA)
The reason for the array is that we need to reorder the varA items by
sorting (descending) --> thus varB gets reordered accordingly.
In your example, the itemoffset(each,varA) will = 0 unless there is an item
in varA that matches one in varB.
Dick's version says (step-by-step)
itemoffset(each,varB) -- the position of the item in its own variable
varA --return the item in varA that is in the same position
now sort by the returned values from varA
put "car,bike,VWvan,glider" into varA
put "key,helmet,rubberband,hang" into of varB
split varA using cr and comma:
then Rev builds the lists
itemoffset("key",varB) => 1 => varA => car
itemoffset("helmet",varB) => 2 => varA => bike
itemoffset("rubberband",varB) => 3 => varA => VWVan
itemoffset("hang",varB) => 4 => varA => glider
now Rev sorts by the returned values, descending text...
bike, car, glider,VWVan <-- after sorting
helmet, key,hang, rubberband --is the correct order
(a rubberband can be used as a fan belt in the VW)
the others make sense :-)
My version would build the varA array the long way
My version would not take advantage of using "each"
My version worked, but it ain't as good as Dick's, not even close.
More information about the use-livecode