RE: Record sorting routine
RE: Record sorting routine
- Subject: RE: Record sorting routine
- From: "Jerry Podhajsky" <email@hidden>
- Date: Sun, 9 Feb 2003 15:37:23 -0600
- Thread-topic: Record sorting routine
Well, that's certainly a more elegant solution than the one I built
(BTW, I no more than submitted my original post than I figured out the
problem with my sorting script.). So at least I can say I solved it
myself.
However, I'll be using yours. Thanks a lot for the assistance.
jp
-----Original Message-----
From: Kai [
mailto:email@hidden]
Sent: Sun 2/9/2003 7:06 AM
To: email@hidden
Cc:
Subject: Re: Record sorting routine
on Sat, 8 Feb 2003 13:40:36 -0600, "Jerry Podhajsky"
<email@hidden>
wrote:
> I have a list of records that I'd like to sort by a date field
contained
> in all the records. I'm trying to roll my own with
Applescript, but
> have come up short and very confused.
>
> Does anyone have a basic Applescript routine (I'm trying to
avoid an
> OSAX, so that I can see the code and maybe learn something)
that takes a
> list of records and sorts them by a specified field in the
record?
Try something like this, Jerry:
=======================================
to sortRecords from rList
if rList's length < 2 then return rList
set {l, h, {m, s}} to {{}, {}, rList's {item 1, rest}}
repeat with r in s
if m's d > r's d then
set l's end to r's contents
else
set h's end to r's contents
end if
end repeat
if l's length > 1 then set l to sortRecords from l
if h's length > 1 then set h to sortRecords from h
l & {m} & h
end sortRecords
sortRecords from putYourRecordListHere
=======================================
Depending on how your records are set up, you may need to modify
the first
line of the repeat loop (which currently reads: 'if m's d > r's
d then').
Firstly, unless the date label in your records just happens to
be 'd', then
substitute your own date label.
Secondly, if your dates are entered in a text format (such as
"5/3/1995"),
they'll need coercing to a date - so the repeat loop should
start with
something like this instead:
=======================================
if date (m's d) > date (r's d) then
=======================================
--
Kai
_______________________________________________
applescript-users mailing list |
email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.