set an option menu item to default on start

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
fhs14647
Posts: 21
Joined: Sat May 16, 2020 11:40 am

set an option menu item to default on start

Post by fhs14647 » Thu Jun 18, 2020 1:04 pm

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

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: set an option menu item to default on start

Post by Klaus » Thu Jun 18, 2020 1:21 pm

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! 8)

***Or if the commands/functions do not work as you exspected!

Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: set an option menu item to default on start

Post by dunbarx » Thu Jun 18, 2020 1:41 pm

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

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: set an option menu item to default on start

Post by Klaus » Thu Jun 18, 2020 2:07 pm

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!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: set an option menu item to default on start

Post by dunbarx » Thu Jun 18, 2020 3:52 pm

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

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: set an option menu item to default on start

Post by Klaus » Thu Jun 18, 2020 4:01 pm

Sure, but a menubutton without functionality does not make much sense. :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: set an option menu item to default on start

Post by dunbarx » Thu Jun 18, 2020 5:08 pm

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

asayd
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 107
Joined: Mon Apr 10, 2006 7:02 pm
Location: Provo, Utah, USA
Contact:

Re: set an option menu item to default on start

Post by asayd » Thu Jun 18, 2020 5:19 pm

Klaus wrote:
Thu Jun 18, 2020 4:01 pm
Sure, but a menubutton without functionality does not make much sense. :D
But there are other ways to script a menu button. You can also use mouseUp, circumventing the menuPick handler altogether.
Devin Asay
Learn to code with LiveCode University
https://livecode.com/store/education/

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: set an option menu item to default on start

Post by Klaus » Thu Jun 18, 2020 5:25 pm

Oh boy, I did not exspect the "Spanish Inquisition"! :D

Sorry, folks, when I read menubutton I immediatley think "menupick".

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: set an option menu item to default on start

Post by bogs » Thu Jun 18, 2020 9:14 pm

(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)
Image

fhs14647
Posts: 21
Joined: Sat May 16, 2020 11:40 am

Re: set an option menu item to default on start

Post by fhs14647 » Sun Jun 21, 2020 10:10 pm

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”