Selecting Menu Item in Option Menu

Ken Ray kray at
Wed Jan 28 11:06:00 EST 2009

> You can either set the label or the menuHistory
> property.
> ##
> set the label of button "MyOptionMenu" to "Choice 1"
> set the menuHistory of button "MyOptionMenu" to 1
> ##
> When you set the label, no "menuPick" message is sent;
> however, if you use the menuHistory, then your option
> menu will receive a "menuPick" message.
> If you want to use the menuHistory property, but avoid
> the "menuPick" message, you can always wrap it in a
> lock/unlock messages pair.
> ##
> lock messages
> set the menuHistory of button "MyOptionMenu" to 1
> unlock messages
> ##

One thing I'd add to that - if you set the label, when you go to use the
menu again, the item that's highlighted will *not* be what you set the label
to, but what the current menuHistory property of the button is set to.

For example, if you drag out an option button onto a clean stack in Rev, it
comes with three pre-created menu items: "Choice 1", "Choice 2", and "Choice
3", with the label reading "Choice 1" and when you click the button, the
"Choice 1" menu item is the one that is highlighted.

If you do:

  set the label of btn 1 to "Choice 2"

You'll see the button read "Choice 2", but when you click on it, "Choice 1"
will still be the highlighted choice (since the menuHistory of the button is
still "1").

Personally, I've found it always better to lock messages and set the
menuHistory, but it would be great if there was a better/easier way to do
this, especially since 90% of the time I know the name I want on the button,
not the number, and I end up doing something like this:

lock messages
set the menuHistory of btn 1 to lineOffset("Choice 2",the text of btn 1)
unlock messages

and of course if for some reason if the name isn't found, it sets it to the
first item in the list, which may not be what I want, so I would have to do:

lock messages
put lineOffset("Choice 2",the text of btn 1) into tNum
if tNum <> 0 then
  set the menuHistory of btn 1 to tNum
end if
unlock messages

Personally, I'd love to be able to have syntax like:

  set the menuChoice of <buttonObj> to <menuItemString>

that would act like "set the menuHistory", but take the name of the menu
item as an argument, and NOT trigger menuPick. Then return in "the result" a
non-empty value if for some reason the menu item you named doesn't exist.

set the menuChoice of btn 1 to "Choice 2"
if the result is not empty then
  -- "Choice 2" doesn't exist and I can do something about it
end if



Ken Ray
Sons of Thunder Software, Inc.
Email: kray at
Web Site:

More information about the Use-livecode mailing list