• 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: A Lookup Function?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A Lookup Function?


  • Subject: Re: A Lookup Function?
  • From: BareFeetWare <email@hidden>
  • Date: Tue, 25 Jan 2011 05:53:05 +1100

On 25/01/2011, at 4:30 AM, Marconi wrote:

> Is there a lookup function in AppleScript that will look in a list of values (a table?) and get a corresponding value?

> My lookup table would be:
>
> A	Alpha
> B	Bravo
> ...
> Z	Zulu

> What's the most efficient way to store and initialize the table, and look up the values?


I'd do this:

on LookupInList(keyValue, keyColumn, listOfLists, lookupColumn)
	repeat with thisList in listOfLists
		if item keyColumn in thisList is keyValue then
			set lookupValue to item lookupColumn in thisList
			exit repeat
		end if
	end repeat
	return lookupValue
end LookupInList

like this:

on run
	set phoneticTable to {{"A", "Alpha"}, {"B", "Bravo"}, {"Z", "Zulu"}}
	get LookupInList("B", 1, phoneticTable, 2)
end run

Tom
BareFeetWare

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >A Lookup Function? (From: Marconi <email@hidden>)

  • Prev by Date: Re: A Lookup Function?
  • Next by Date: Re:Lookup Table
  • Previous by thread: Re: A Lookup Function?
  • Next by thread: Re: A Lookup Function?
  • Index(es):
    • Date
    • Thread