Page 1 of 1

A bit out of SORTS

Posted: Sat Sep 19, 2009 12:21 pm
by user#606
I thought I would be smart and sort a table field using the first item and only lines 2 to the number of lines in the table.
The reason is to preserve "Default settings" called Default in item 1 of the first line, to remain in the first line.

Default
Armitage
Base
...... etc

by using

sort line 2 to NumberOfLines of field "SortedTable" ascending text by item 1 of each -- sorts from second item, text, ascending

This compiles, but will not run. It fails saying

"button "ID 1251": execution error at line 15 (sort: error sorting), char 1"

So, what is wrong with it, it makes sense to me?

Posted: Sat Sep 19, 2009 1:59 pm
by Klaus
Hi user#606,

I think "sort" will only accept one complete "container" to work with.

Try this:
...
put line 2 to -1 of fld "table field" into tField
set itemdel to TAB
sort lines of tField by item 1 of each
## DEFAULT = ascending and text ;-)
put tField into line 2 to -1 of fld "table field"
...

Not tested but should work :-)


Best

Klaus

Posted: Sat Sep 19, 2009 2:26 pm
by FourthWorld
I don't know of a way to use chunk expressions to sort only part of a container, but you could write a function to handle that:

Code: Select all

on mouseUp
  put SortAllButFirstLine(fld 1) into fld 2
end mouseUp

function SortAllButFirstLine pList
  put line 1 of pList into tSaveLine
  delete line 1 of pList
  sort lines of pList
  return tSaveLine &cr& pList
end SortAllButFirstLine

Sorted the SORT

Posted: Sat Sep 19, 2009 2:46 pm
by user#606
I suspected there was no alternative but to introduce more variables to hold, sort and replace.
Thank you for your help though.