• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Accessing a Record by variable--the solutions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing a Record by variable--the solutions


  • Subject: Re: Accessing a Record by variable--the solutions
  • From: Nigel Garvey <email@hidden>
  • Date: Wed, 14 Feb 2001 21:38:25 +0000

email@hidden (Douglas Wagner) wrote on Wed, 14 Feb 2001 13:30:26
-0400:

>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)

Arthur's has my vote (without testing, that is). It uses a single string
instead of a list (memory) and doesn't need a repeat (time). It could be
simplied a little:

property kStrMonths : "DumJanFebMarAprMayJunJulAugSepOctNovDec"

on monthIndex(mon) -- Note, mon must be case-sensitive
return (offset of mon in kStrMonths) div 3
end monthIndex

set theMonth to "Feb"
monthIndex(theMonth)

... and (for form's sake) kStrMonths would ideally be set as a local
variable within the handler.

By the way, Arthur, does the 'k' stand for 'kNapp'?

NG


  • Prev by Date: Re: how can I automatically compile a script
  • Next by Date: Re: generic event handlers
  • Previous by thread: Accessing a Record by variable--the solutions
  • Next by thread: Re: Accessing a Record by variable--the solutions
  • Index(es):
    • Date
    • Thread