Page 1 of 1
set an option menu item to default on start
Posted: Thu Jun 18, 2020 1:04 pm
by fhs14647
Dear experts
I have an option menu which I want to be selected always with the first item. I made this on the stack with startup.
Code: Select all
on startup
set the menuLines of button "optionMenu" to 1
end startup
But whenever I make a change and another item is selected on saving, the last used item is shown.
Maybe you have a solution
Thanks
Re: set an option menu item to default on start
Posted: Thu Jun 18, 2020 1:21 pm
by Klaus
Hi fhs14647,
1. "on startup" is not the right time for this, better use "on preopenstack".
2. Menulines is not the correct thing to set, you want to set the LABEL.
So something like this should do the trick:
Code: Select all
on preopenstack
## This way always the first line (menuitem) will be displayed in the option button when the stack opens
set the label of btn "optionmenu" to line 1 of the text of btn "optionButton"
end preopenstack
Please look up unknown*** terms like startup and menulines in the dictionary.
It is better than its reputation!
***Or if the commands/functions do not work as you exspected!
Best
Klaus
Re: set an option menu item to default on start
Posted: Thu Jun 18, 2020 1:41 pm
by dunbarx
Please look up unknown*** terms like startup and menulines in the dictionary.
What Klaus means is that even though LiveCode is a very conversational language, it still has a defined vocabulary. You are on the right track with your thinking, you just need to make sure that the words you use are actually part of the language.
Also know that you can set the "menuHistory" property of the button to '1". The menuHistory is, to me, the more precise way to "select" a particular menuItem.
Craig
Re: set an option menu item to default on start
Posted: Thu Jun 18, 2020 2:07 pm
by Klaus
dunbarx wrote: ↑Thu Jun 18, 2020 1:41 pm
...
Also know that you can set the "menuHistory" property of the button to '1". The menuHistory is, to me, the more precise way to "select" a particular menuItem.
CAVEAT:
Setting "the menuhistory" of a button is just like selecting the menuitem with the mouse, means the command for the menuitem will get executed! Unless you ->
lock messages before setting the menuhistory!
Re: set an option menu item to default on start
Posted: Thu Jun 18, 2020 3:52 pm
by dunbarx
Klaus wrote:
Setting "the menuhistory" of a button is just like selecting the menuitem with the mouse
True, but only if you have a "menuPick" handler in play. The OP wanted this selection to occur automatically, so I assumed selecting the menuItem was also intended to invoke it. This may not be true. So, fhs14647, did you only want the label to show, or the label to show and the button to operate?
Craig
Re: set an option menu item to default on start
Posted: Thu Jun 18, 2020 4:01 pm
by Klaus
Sure, but a menubutton without functionality does not make much sense.

Re: set an option menu item to default on start
Posted: Thu Jun 18, 2020 5:08 pm
by dunbarx
Sure, but a menubutton without functionality does not make much sense.
I don't see your point. What does making sense have to do with it?
Craig
Re: set an option menu item to default on start
Posted: Thu Jun 18, 2020 5:19 pm
by asayd
Klaus wrote: ↑Thu Jun 18, 2020 4:01 pm
Sure, but a menubutton without functionality does not make much sense.
But there are other ways to script a menu button. You can also use mouseUp, circumventing the menuPick handler altogether.
Re: set an option menu item to default on start
Posted: Thu Jun 18, 2020 5:25 pm
by Klaus
Oh boy, I did not exspect the "Spanish Inquisition"!
Sorry, folks, when I read
menubutton I immediatley think "
menupick".
Re: set an option menu item to default on start
Posted: Thu Jun 18, 2020 9:14 pm
by bogs
(The door flies open and Cardinal Ximinez of Spain enters, flanked by two junior cardinals. Cardinal Biggles has goggles pushed over his forehead. Cardinal Fang is just Cardinal Fang
Ximinez: NOBODY expects the Spanish Inquisition! Our chief weapon is surprise...surprise and fear...fear and surprise.... Our two weapons are fear and surprise...and ruthless efficiency.... Our *three* weapons are fear, surprise, and ruthless efficiency...and an almost fanatical devotion to the Pope.... Our *four*...no... *Amongst* our weapons.... Amongst our weaponry...are such elements as fear, surprise.... I'll come in again.
(Exit and exeunt)
Re: set an option menu item to default on start
Posted: Sun Jun 21, 2020 10:10 pm
by fhs14647
Thanks to all your help!!!
I have chosen this solution and it works perfect for me
Code: Select all
on preopenstack
set the label of btn "optionMenu" to line 1 of the text of btn "optionMenu"
put "+" into field "labelKind"
end preopenstack