A bit out of SORTS

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

A bit out of SORTS

Post by user#606 » Sat Sep 19, 2009 12:21 pm

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?

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Sat Sep 19, 2009 1:59 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Sat Sep 19, 2009 2:26 pm

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Sorted the SORT

Post by user#606 » Sat Sep 19, 2009 2:46 pm

I suspected there was no alternative but to introduce more variables to hold, sort and replace.
Thank you for your help though.

Post Reply