sorting a container by multiple items?

Sarah Reichelt sarah.reichelt at gmail.com
Wed May 3 17:56:54 EDT 2006


On 5/4/06, Josh Mellicker <josh at dvcreators.net> wrote:
> I'm trying to sort the lines of a container by one, then another
> item... so I'm using a function to concatenate two fields:
>
>
> sort lines of fld "userTasks" by buildSortFld(item 2 of fld
> "userTasks", item 15 of fld "userTasks")
>
>
> function buildSortFld f1, f2
>      return f1 && f2
> end buildSortFld
>
>
> This doesn't work because I need an "of each" so the sort function
> does all the lines... but wherever I put "for each", I get an error...
>

Sorts are non-destructive so you can just do sequential sorts and you
should get what you need e.g.
  sort lines of fld "userTasks" by item 2 of each
  sort lines of fld "userTasks" by item 15 of each
(or possibly the other way around).

As always operating on variables is faster than fields, so if the
"userTasks" field has a lot of data, it would be faster to put it into
a variable, sort the variable and then put it back into the field.

There is a way to do the custom sort function but I always forget it
and rely on Jacque to remind me :-) However in this case, I think it
is overkill.

Cheers,
Sarah



More information about the use-livecode mailing list