Change Option Menu SELECTION via Script?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
cmhjon
Posts: 191
Joined: Tue Aug 04, 2015 11:55 am

Change Option Menu SELECTION via Script?

Post by cmhjon » Thu Oct 08, 2020 1:25 pm

Hi all,

I have an option menu with the following menu items:

Please Select:
Option 1
Option 2
Option 3

Suppose the user selects "Option 2" from the menu. I need to be able to "reset" the option menu back to "Please Select:" via script but I cannot find a way to do this. I can GET the selection of the option menu but I cannot SET it via script. I can set the LABEL of it but that doesn't change the SELECTION of it. The menuLines and menuHistory commands don't seem to be what I want either.

I'm sure it's something simple but I cannot seem to find the answer here or in the dictionary.

Thanks,
Jon

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Change Option Menu SELECTION via Script?

Post by dunbarx » Thu Oct 08, 2020 1:51 pm

Hi.

There are two ways to "set" a menu-style button.

Code: Select all

set the menuHistory of btn "yourButton" to 1
set the label of btn "yourButton" to "Please Select"
These work differently, but after all is said and done, do the same thing. But it is instructive to play with them, since they open other possibilities for you when fooling around with pulldowns, option buttons, etc.

Craig

cmhjon
Posts: 191
Joined: Tue Aug 04, 2015 11:55 am

Re: Change Option Menu SELECTION via Script?

Post by cmhjon » Thu Oct 08, 2020 2:19 pm

Hi Craig,

Thank you for the reply. It would appear that the menuHistory command does in fact do the trick. After testing the command, the SELECTION shows correctly. The label command by itself does not work as the SELECTION still shows "Option 2" as the selected item.

Best regards,
Jon
dunbarx wrote:
Thu Oct 08, 2020 1:51 pm
Hi.

There are two ways to "set" a menu-style button.

Code: Select all

set the menuHistory of btn "yourButton" to 1
set the label of btn "yourButton" to "Please Select"
These work differently, but after all is said and done, do the same thing. But it is instructive to play with them, since they open other possibilities for you when fooling around with pulldowns, option buttons, etc.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Change Option Menu SELECTION via Script?

Post by dunbarx » Thu Oct 08, 2020 2:49 pm

cmJohn

Ah, now I see what you wanted. Yes, setting the label only shows the value of the displayed text in the optionMenu. Surely go with the menuHistory, since it actually changes the state of a menu-style button, as if you invisibly clicked and reset that button, and not just changed the displayed text.

Both actions may have their own uses, however.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Change Option Menu SELECTION via Script?

Post by dunbarx » Thu Oct 08, 2020 2:58 pm

Hi again.
The label command by itself does not work as the SELECTION still shows "Option 2" as the selected item.
Not sure what you mean by this. If you simply set the label of your option button, the displayed text will be "Please Select:" but the menuHistory will remain as it was when the user actually selected a menuItem. These are two different properties, and can coexist, even if they structurally seem to be at odds with each other.

But it will not visibly remain as "Option 2". Right?

Craig

cmhjon
Posts: 191
Joined: Tue Aug 04, 2015 11:55 am

Re: Change Option Menu SELECTION via Script?

Post by cmhjon » Thu Oct 08, 2020 3:09 pm

Hi Craig,

Setting the LABEL will visually change the button to say "Please Select:" but it does not change its SELECTION. When my app does all its magic, it gets the SELECTION of the button in question.

Thank you,
Jon :)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Change Option Menu SELECTION via Script?

Post by dunbarx » Thu Oct 08, 2020 5:27 pm

You did mention, and loudly, "SELECTION" right at the outset. I got sidetracked. Glad the menuHistory was the cure.

Craig

Post Reply