sort by two paremeters?

Richard Gaskin ambassador at fourthworld.com
Mon Apr 14 00:56:06 EDT 2008


Nicolas Cueto wrote:
> Before I go ahead and script something complex,
> I'm wondering if Rev already has a built-in way of
> doing the following sort.
> 
> Given a list of 2-item lines, such as
> 
>   a 1
>   d 3
>   c 3
>   c 2
>   a 3
>   d 2
>   a 2
>   c 1
>   d 1
> 
> I'd like the list to be sorted by item 1,
> and, in the case of lines with the
> same item 1, sorted by item 2, thus:
> 
>   a 1
>   a 2
>   a 3
>   c 1
>   c 2
>   c 3
>   d 1
>   d 2
>   d 3
> 
> Any suggestions?
> 
> Thanks.

Just two successive sorts seem to do the trick.

This script assumes that the source data shown above is in field 1, and 
you want the output shown in field 2:

on mouseUp
   put fld 1 into tData
   sort lines of tData by word 2 of each
   sort lines of tData
   put tData into fld 2
end mouseUp


-- 
  Richard Gaskin
  Managing Editor, revJournal
  _______________________________________________________
  Rev tips, tutorials and more: http://www.revJournal.com



More information about the use-livecode mailing list