Accessing a Record by variable--the solutions
Accessing a Record by variable--the solutions
- Subject: Accessing a Record by variable--the solutions
- From: email@hidden (Douglas Wagner)
- Date: Wed, 14 Feb 2001 13:30:26 -0400
Hello:
My thanks to Bill Cheesman, Ken Dobson, Arthur Knapp and Ric Phillips
for your solutions and in particular to Ric for the additional
illumination in his comment on, "de-referencing a label/variable via
the contents of another label/variable".
Now I have three solutions. (I don't believe I've missed any). I
wonder which is the most efficient.
1 Can one make any useful generalizations about the solutions
offered without testing?
(Speed, memory usage, procedural efficiency etc.)
2 And is there a procedure which would ensure all three are
tested to the same base line?
Have a good day: Douglas Wagner
Arthur Knapp:
property kStrMonths : "JanFebMarAprMayJunJulAugSepOctNovDec"
on monthIndex(mon) -- Note, mon must be case-sensitive
set x to offset of mon in kStrMonths
if (x = 0) then
return 0 -- or cause error
else
return x div 3 + 1
end if
end monthIndex
set theMonth to "Feb"
monthIndex(theMonth)
Ric Phillips
set theMonths to {{mthName:"jan", mthNum:"1"}, ,
--line end char <,> is <option lowercase L>
{mthName:"feb", mthNum:"2"}, ,
{mthName:"mar", mthNum:"3"}, ,
{mthName:"apr", mthNum:"4"}, ,
{mthName:"may", mthNum:"5"}, ,
{mthName:"jun", mthNum:"6"}, ,
{mthName:"jul", mthNum:"7"}, ,
{mthName:"aug", mthNum:"8"}, ,
{mthName:"sep", mthNum:"9"}, ,
{mthName:"oct", mthNum:"10"}, ,
{mthName:"nov", mthNum:"11"}, ,
{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
monthNumber
-->2
Ken Dobson
set aMth to "Feb"
set theMths to {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec"}
set mthNum to list_position(aMth, theMths)
--> 2
on list_position(x, this_list)
repeat with i from 1 to (count of this_list)
if item i of this_list is x then return i
end repeat
end list_position