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

Jim Ault JimAultWins at yahoo.com
Tue Mar 20 21:35:06 EDT 2007


On 3/20/07 4:34 PM, "Dick Kriesel" <dick.kriesel at mail.com> wrote:
> On 3/20/07 2:36 PM, "Jim Ault" <JimAultWins at yahoo.com> wrote:
>> 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.
> Hi, Jim.  Here's a way:
> split varB by comma
> sort items of varA descending by varB[itemOffset(each,varA)]
> 
Great tip!!!
Far better than the variations that I was constructing.
Again, unique values need to be in each list, but that can work so many
places.  
One way of checking for this condition is to make your wonderful 2-liner
into ....

put the number of items in varB into iCount
>split varB by comma
put the number of lines in the keys of varB into kCount
if iCount <> kCount then
answer "duplicate varA item(s) found"
exit to top
end if

put the number of items in varA into iCount
get varA
split it by comma
put the number of lines in the keys of it into kCount
if iCount <> kCount then
answer "duplicate varA item(s) found"
exit to top
end if
> sort items of varA descending by varB[itemOffset(each,varA)]


Thanks!  and this is going in my scrapbook.

Jim Ault
Las Vegas





More information about the use-livecode mailing list