Basic menu item question

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Basic menu item question

Post by hamlynart » Sun Mar 23, 2008 6:50 pm

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

BIX
Posts: 33
Joined: Fri Oct 27, 2006 2:54 pm

Post by BIX » Sun Mar 23, 2008 8:29 pm

You were close,

Code: Select all

on menuPick myPick
  answer myPick
end menuPick
BIX

hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Basic menu item question

Post by hamlynart » Mon Mar 24, 2008 1:25 am

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Mar 24, 2008 3:01 am

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Mon Mar 24, 2008 7:00 am

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.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Post by hamlynart » Mon Mar 24, 2008 6:45 pm

Ah the label!

Thanks - it works perfectly now.

also

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

Thanks again

Jim H

Post Reply