Page 1 of 1

Basic menu item question

Posted: Sun Mar 23, 2008 6:50 pm
by hamlynart
I've got a menu popup with two choices. How do I answer the selected item of the list? Presumably something like this:

answer the ??????? of button "myButton"

No doubt it'll be embarrassingly simple but it's foiling my poor brain :(

Jim H

Posted: Sun Mar 23, 2008 8:29 pm
by BIX
You were close,

Code: Select all

on menuPick myPick
  answer myPick
end menuPick

Basic menu item question

Posted: Mon Mar 24, 2008 1:25 am
by hamlynart
Thanks for the reply but that's not working the way I need. I'd like to get the selected choice when another button is pressed.

so I need something like:

on mouseDown
answer the chosenItem of button myPopUp
end mouseDown

Sometimes the user won't have clicked the popup.

At the moment I'm doing it like this (below) but I can't help thinking there must be an easier way:

put the menuHistory of button amPM into tAmPm
if tAmPm =1 then
put " AM" into tPmAm
end if
if tAmPm =2 then
put " PM" into tPmAm
end if

Thanks in advance

Jim H

Posted: Mon Mar 24, 2008 3:01 am
by Mark
Hi Jim,

What you do isn't bad at all. Just one little improvement:

Code: Select all

put the menuHistory of button amPM into tAmPm
if tAmPm = 1 then
put " AM" into tPmAm
else if tAmPm = 2 then
put " PM" into tPmAm
end if 
You can also use a switch control structure and you could use the label of the button instead of the menuHistory.

Best regards,

Mark

Posted: Mon Mar 24, 2008 7:00 am
by Janschenkel
Hi Jim,

To get the visible side of the selected line:

Code: Select all

put the label of button "MyOptionMenu" into tLabel
To get the lineoffset of the selected line:

Code: Select all

put the menuHistory of button "MyOptionMenu" into tLineNumber
which you can then still use to get the label:

Code: Select all

put line tLineNumber of the text of button "MyOptionMenu" into tLabel
or slightly shorter:

Code: Select all

put line tLineNumber of button "MyOptionMenu" into tLabel
If you plan to develop multi-language software, 'the menuHistory' is your friend.

Hope this helped,

Jan Schenkel.

Posted: Mon Mar 24, 2008 6:45 pm
by hamlynart
Ah the label!

Thanks - it works perfectly now.

also

"else" - great - that'll neaten things up to.

Thanks again

Jim H