Return selected item of option menu
Ralph R. Forehand
ralf at dol.net
Fri Nov 12 11:21:51 EST 2004
Kaveh,
You wrote;
>This must be easy, but I can't find it!
>
>I have an option menu with 3 lines in the content:
>
>choice 1
>choice 2
>choice 3
>
>I want to get the selected item. What is the command for that? when I type
>
>put btn myButton
>
>I get all three lines
>
>When I ask for selectedLine, I get
>
>line 3 of button 8
>
>----------------------
In the following scripts, the menuPick step is what you need to use. It will return the item picked (theItem) from the button' pull-down menu.
=================================================================
-- Previously set-up elsewhere in stack
global userNames
put "Jones,Smith,Doe,Test,Fifth,Sixth,Seventh" into userNames
-- Set-up variable length pull-down button and items
on mouseDown
global userNames
put number of items in userNames into userCount
put "User?" & Return into userList
repeat with i = 1 to userCount
put item i of userNames & Return after userList
end repeat
put format(userList) into tItems
put num of lines of me
-- sort tItems # optional
set the text of me to tItems
set the menuLines of me to num of lines of me
end mouseDown
-- Select item from menu
menuPick # select menu item
on menuPick theItem -- in button pulldown menu
set name of me to theItem
--
-- Do whatever with menu item (User) picked
--
-- Reset button to "User?" prompt for next pick
put "User??" into first Item of me
end menuPick
=================================================================
>Also, is there a handler to test when the selection of the button has been
>changed? i.e. like MenuPick, but only if the menu item picked is different
>to the one there previously.
>--
Not that I know of (but I'm a newbie!)
One way would be to save your menu pick in a global (myMenuPick) after, and then check each new pick (theItem) against the global, and reset the global if it's different.
Testing this approach;
=======================
global myMenuPick
on mouseUp
global myMenuPick
put "First" into myMenuPick
put myMenuPick into message
wait 3 seconds
put "Second" into theItem
if theItem <> myMenuPick then put theItem into myMenuPick
put myMenuPick into message
end mouseUp
=====================
Good Luck and TAKE CARE,
Ralph
More information about the use-livecode
mailing list