sort question

Wouter wouter.abraham at scarlet.be
Fri Jun 3 22:33:05 EDT 2005


On 03 Jun 2005, at 20:09, Jim Ault wrote:

> Greetings, jack

snip


> on sortFldSource
>   put fld "source" into tSource  --lines to sort
>   sort lines of tSource numeric by numberConvert(each)
>   put tSource into fld "destination"  --output for your review
> end sortFldSource
>
> function numberConvert pStrToConvert
>   if pStrToConvert is "" then
>     return ""
>   else
>     set itemdel to  "."
>     if the last char of pStrToConvert is "-" then
>       put the last char of pStrToConvert into tSign
>       delete the last char of pStrToConvert
>     end if
>     put item 1 of pStrToConvert into tIntPart
>     put item 2 of pStrToConvert into tDecPart1
>     if the number of items in pStrToConvert > 2 then
>       put item 3 of pStrToConvert into tDecPart2
>     else
>       put "" into tDecPart2
>     end if
>     put tSign & tIntPart & "." & tDecPart1 & tDecPart2 into tReply
>     return tReply
>   end if
> end numberConvert
>
> Thanks to jeanne a. e. devoto for this (each) form of the "sort  
> lines of"
> command.
>
> Jim Ault
> Las Vegas
>
> On 6/3/05 9:45 AM, "revinfo1155 at aol.com" <revinfo1155 at aol.com> wrote:

Hi Jim,

I don't know on your computer but on my mac this handler gives the  
following result for Jack's list:

10.101-
11.151-
4.101-
5.101.1-
20.101-
11.101.1-
10.501-
10.401-
10.351-
10.301.1-
10.201-
9.351-
9.101.1-
8.301-
8.101-
7.501.1-
7.401-
7.251-
7.201.1-
7.151.1-
7.101-
6.401.1-
6.301-
6.201.1-
6.101.1-
5.701-
5.651-
5.501-
5.451-
5.401-
5.351.1-
5.301-
5.201-
5.151-
4.991-
3.101-
2.301-
2.101-
1.101-

To make it more universal (no matter leading or trailing - and +) one  
could change it to:

on mouseUp
   get field 1
   put numsort(it,"ascending") into fld 2
end mouseUp

function numSort pList,pDirection
   set the itemdelimiter to "."
   repeat for each line i in pList
     put i into x
     if char -1 of word 1 of i is in "-+" then put char -1 of word 1  
of i & char 1 to -2 of word 1 of i into x
     if the num of items in x > 2 then put item 1 to 2 of x & item 3  
of x into x
     put i into numArray[x]
   end repeat
   put the keys of numArray into y
   if pDirection = "ascending" then sort lines of y numeric ascending
   else sort lines of y numeric descending
   repeat for each line i in y
     put numArray[i] & cr after tList
   end repeat
   return tList
end numSort

Greetings,
Wouter


More information about the use-livecode mailing list