Re: Accessing a Record by variable
Re: Accessing a Record by variable
- Subject: Re: Accessing a Record by variable
- From: Ric Phillips <email@hidden>
- Date: Wed, 14 Feb 2001 16:52:30 +1100
>
> I rather think you've missed Douglas' point. I think what he's after is the
>
> equivalent of a hash table. Your solution hard codes Feb into the script, and
>
> Douglas wants to look up any arbitrary month's value depending on program
>
> input,...
>
>
I suffer from the curse of literal-mindedness. If he had asked the right
>
question, I would have given him the right answer. ;->
>
Bill Cheeseman
Oops...here is my offering again (without the typos).
(A lot of programming languages don't allow de-referencing a
label/variable via the contents of another label/variable.
When one is coding, it is easy to become focused on finding a
procedural, code based solution to a problem. Sometimes, changing
your data structures offers the easiest way out.
If you pretend the repeat loop isn't there, this is as close to
a hash table as I have been able to get in Apple Script - oh, I
do love my PERL.
Anyway, hope this helps.)
-----------------------------------------------------
set theMonths to {{mthName:"jan", mthNum:"1"},<option-l>
{mthName:"feb", mthNum:"2"},<option-l>
{mthName:"mar", mthNum:"3"},<option-l>
{mthName:"apr", mthNum:"4"},<option-l>
{mthName:"may", mthNum:"5"},<option-l>
{mthName:"jun", mthNum:"6"},<option-l>
{mthName:"jul", mthNum:"7"},<option-l>
{mthName:"aug", mthNum:"8"},<option-l>
{mthName:"sep", mthNum:"9"},<option-l>
{mthName:"oct", mthNum:"10"},<option-l>
{mthName:"nov", mthNum:"11"},<option-l>
{mthName:"dec", mthNum:"12"}}
set monthToFind to "feb"
repeat with thisMonth in theMonths
if the mthName of thisMonth = monthToFind then
set monthNumber to the mthNum of thisMonth
end if
end repeat
-------------------------------------------------------
(Where <option-l> is the character produced by pressing
the option key and "l" together.)
Ric Phillips
Computer Laboratory Support Officer
Faculty of Humanities and Social Sciences
La Trobe University
9479 2792