sorting advice

Jan Schenkel janschenkel at yahoo.com
Fri Jun 19 04:59:48 EDT 2009


Hi Nicolas,

Custom sort functions to the rescue!

I made a simple stack with 2 fields and a button. The first field contains your original data, and the button has the following script:
##
on mouseUp
   put field 1 into tData
   sort tData ascending by MyCustomSort(each)
   put tData into field 2
end mouseUp

function MyCustomSort pLine
   set the itemDelimiter to space
   put item 2 of pLine into tDate
   replace ".." with "/" in tDate
   convert tDate from english date to dateItems
   set the itemDelimiter to comma
   put format("%4u%02u%02u", \
        item 1 of tDate, \
        item 2 of tDate, \
        item 3 of tDate) into tSortableDate
   return tSortableDate
end MyCustomSort
##

Clicking the button produced the expected results in field 2.

The trick is to return from your function a value that will sort the content correctly. In this case, the function will turn 12.3.09 into 20091203, 3.2.04 into 20040302, etc. And those 'YYYYMMDD' versions of the date will sort correctly.

HTH,

Jan Schenkel
=====
Quartam Reports & PDF Library for Revolution
<http://www.quartam.com>

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)


--- On Thu, 6/18/09, Nicolas Cueto <niconiko at gmail.com> wrote:

> From: Nicolas Cueto <niconiko at gmail.com>
> Subject: sorting advice
> To: "How to use Revolution" <use-revolution at lists.runrev.com>
> Date: Thursday, June 18, 2009, 10:23 PM
> Still avoiding thinking too much...
> 
> Given this list (a ref-number followed
> by a dot-separated date):
> 
>  bg2334 12.21.09
>  bg9788 1.10.02
>  bg6554 11.30.11
>  bg8902 6.6.04
>  bg4021 2.29.12
>  bg1210 1.2.02
>  bg3008 12.3.09
>  bg5526 5.29.04
> 
> what sort-command combo would
> re-order it ascending by the date
> to become:
> 
>   bg1210 1.2.02
>   bg9788 1.10.02
>   bg5526 5.29.04
>   bg8902 6.6.04
>   bg3008 12.3.09
>   bg2334 12.21.09
>   bg6554 11.30.11
>   bg4021 2.29.12
> 
> 
> Note that the ref-number and the date
> are space-separated, and I'm using
> "." instead of the english date's "/".
> Also, the date form is "month[1-12,
> no leading zero], day[1-31], year [00-
> 09, leading zero].
> 
> I'll be experimenting on my own to hit on
> the magic combination, but in the meantime
> I thought I'd post a plea since someone is
> very likely to reply a solution sooner than I
> can guess one up.
> 
> Thank you.
> 
> --
> Nicolas Cueto
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage
> your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
> 


      




More information about the use-livecode mailing list