Re: Coordinating lists
Re: Coordinating lists
- Subject: Re: Coordinating lists
- From: Pat Cannon <email@hidden>
- Date: Tue, 2 Apr 2002 21:03:40 -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?
...
>
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
How 'bout this (It returns zero if the item's not in the list, something
the run block above doesn't test):
--------------
on offsetInList(theItem, theList)
repeat with thisIndex from 1 to count of theList
if item thisIndex of theList is theItem then return thisIndex
end repeat
return 0 -- only happens if the repeat isn't exited via "return thisIndex"
end offsetInList
--------------
Pat
AppleScript Big Frog in the Colorhouse Little Pond
_______________________________________________
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.