text sortType
Dar Scott
dsc at swcp.com
Tue May 28 16:04:59 EDT 2013
Whoops, I didn't read Peter's solution all the way.
I guessed at what he was doing instead of giving it the attention it deserved.
I guess my thumbs up was for using the sorting value function and for putting in zero digits.
I would (off the top of my head) simplify (and change) that to this:
function reformatLine pL
get item 1 of it
return (word 1 to -2 of it) && char -6 to -1 of ("000000" & word -1 of it)
end reformatLine
By adding leading zeros for a fixed length, a text sort is the same as a number sort.
A 3rd solution is to put fixed length numerals in the last word of the original data.
(I could try using the *s as an excuse, but it is not a good excuse, sorry for commenting after only a glance.)
Dar
On May 28, 2013, at 1:51 PM, Dar Scott wrote:
> I think this and Geoff's are good! This one is more general if you can come up with some sort of metric or sortvalue for each item/list. Geoff's is simpler for this case. The speed difference will depend on the length of the list.
>
> Shouldn't the zero be put 'before' instead of 'after' to force a numerical sort?
>
> Also, there is a shortcut.
>
> put char -6 to -1 of ("000000" & tKey) into tKey
>
> Dar
>
>
> On May 28, 2013, at 1:41 PM, Peter Haworth wrote:
>
>> The following worked for me (with apologies ofr any asterisks that may be
>> inserted into the script by my email client)
>>
>> It assumes there won;t be any numbers > 6 digits.
>>
>> *on* mouseUp
>>
>> *sort* lines of field "Field" by reformatLine(each)
>>
>> *end* mouseUp
>>
>>
>> *function* reformatLine l
>>
>> *local* tKey
>>
>> *put* word 1 to -2 of item 1 of l into tKey
>>
>> *repeat* 6-the length of word -1 of item 1 of l
>>
>> *put* zero after tKey
>>
>> *end* *repeat*
>>
>> *put* word -1 of item 1 of l after tKey
>>
>> *return* tKey
>>
>> *end* reformatLine
>>
>> Pete
>> lcSQL Software <http://www.lcsql.com>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list