Re: "choose list" question....
Re: "choose list" question....
- Subject: Re: "choose list" question....
- From: kai <email@hidden>
- Date: Thu, 10 Feb 2005 20:45:59 +0000
On Thu, 10 Feb 2005 09:09:44 -0700, David Crowe
<email@hidden> wrote:
This is a problem I've had several times. I have a list composed of
lists, e.g.:
{ {1, "H"}, {2, "He"}, {3, "Li"}...}
I want to use 'choose list' to have someone select one or more entries.
First problem, how to get the list of text strings -- {"H", "He",
"Li"...}?
Second problem, "choose list" returns the string (or strings)
selected (e.g. {"Mg","Mn"} ).
Is there a way to figure out what the other part of the tuple was
without scanning the first list.
This all seems very awkward to me.
Take heart, David. :-)
Ideally, you'd probably be better off starting with a couple of
separate lists - rather than a compound one. However, if that's not
possible, then yes - you'd need to extract individual lists, perhaps
something like this:
--=======================================
set l to {{1, "H"}, {2, "He"}, {3, "Li"}}
set x to {}
set y to {}
repeat with i in l
tell i
set x's end to item 2
set y's end to item 1
end tell
end repeat
-----------------------------------------
-- Then choose from list x and 'convert' the values to those from list
y:
-----------------------------------------
set c to choose from list x with multiple selections allowed
if c is false then error number -128
set r to {}
tell x to repeat with n from 1 to count
if item n is in c then set r's end to y's item n
end repeat
r
--=======================================
Of course, if the list of integers is simply a positional sequence
(that is, a straight run like {1, 2, 3, 4, 5, 6, 7, etc...}) then you
shouldn't really need to use it anyway. Instead, you can take advantage
of the numbering sequence created by the final repeat loop, like this:
--=======================================
set l to {{1, "H"}, {2, "He"}, {3, "Li"}}
set x to {}
repeat with i in l
tell i to set x's end to item 2
end repeat
set c to choose from list x with multiple selections allowed
if c is false then error number -128
set r to {}
tell x to repeat with n from 1 to count
if item n is in c then set r's end to n
end repeat
r
--=======================================
For very long lists, there are faster ways of achieving similar results
- although I imagine the above should be adequate for most general
lists involving the 'choose from list' command.
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden