Re: Coordinating lists
Re: Coordinating lists
- Subject: Re: Coordinating lists
- From: Matthew Stuckwisch <email@hidden>
- Date: Tue, 2 Apr 2002 13:48:32 -0600
I need to get an item's position and value based on a choice from another
list. The values in lines 4 and 5 are placeholders. Any pointers?
I don't work with lists much, but this should work, it seems to work
decently fast enough (but I don't know if you need it to expand to larger
lists, which might slow it down a bit):
on run
set list1 to {"Apple", "Banana", "Grape", "Orange"}
set list2 to {34, 56, 56, 8}
set theItem to choose from list list1
set theOffset to findOffset(list1, theItem as string)
set theNum to item theOffset of list1
set theCode to item theOffset of list2
display dialog ("You chose " & theItem & ", Item " & theNum & ",
Code " & ,
theCode) as string
end run
on findOffset(theList, theEntry)
set repVar to 0
set listAsText to ""
repeat
set repVar to repVar + 1
if (item repVar of theList) = theEntry then exit repeat
end repeat
return repVar as integer
end findOffset
It's also possible to shorten this code by at least one line, but I
figured to show exactly what was going it was better to keep it as is.
There may be some other way of finding the offset in lists, but like I
said, I don't work with them very much (now watch, in ten seconds upon
sending this mail I'll already have gotten a response "oh just use [input
command] to find the offset of an entry in a list" :P )
Matthew Stuckwisch
[AIM/MSN]{GuifaSwimmer} | [Yahoo!]{SapphireTree} | [ICQ]{137477701}
[IRC]{guifa / G}(esperNET / irc.massinova.com)
_______________________________________________
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.