Menu items, hard-coded or references

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
CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Menu items, hard-coded or references

Post by CAsba » Tue Nov 08, 2022 1:45 pm

Hi
Is it possible to populate the list of menu items by reference to fields or variables instead of hard-coded items ?

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Menu items, hard-coded or references

Post by Klaus » Tue Nov 08, 2022 2:31 pm

Sorry, no idea what you mean, could you give an example?

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: Menu items, hard-coded or references

Post by CAsba » Tue Nov 08, 2022 2:48 pm

Hi Klaus,
I need to populate a menu with years, to include the current year. As this will change, instead of hardcoding 2022 as a menu item, the menu item needs to reference a field or variable referring to the current year, or, as the current year changes, code is invoked to put the current year into the list of menu items. Is it possible ?

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

Re: Menu items, hard-coded or references

Post by dunbarx » Tue Nov 08, 2022 2:55 pm

If I understand what you mean, know that the menu items of a button are just the contents of that button. So if you:

Code: Select all

put "A" & return & "B" & return & "C" into button "yourComboBox"
Those values will appear as three choices when you click there.

Craig

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Menu items, hard-coded or references

Post by Klaus » Tue Nov 08, 2022 2:56 pm

You can always update/fill the content of a menu button dynamically "on mousedown", if that helps.
Ah, Craig already showed you how to do this...

But still no idea what kind of menu you are trying to create "on the fly".
Could you give an example?

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

Re: Menu items, hard-coded or references

Post by dunbarx » Tue Nov 08, 2022 2:59 pm

Klaus.

That is TWO times I beat you by just minutes in the last week!!! You now only lead by 28,435 to 2

Craig

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Menu items, hard-coded or references

Post by Klaus » Tue Nov 08, 2022 3:09 pm

THIS MUST STOP, Craig! :D :D :D
Maybe I'm just getting old...

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

Re: Menu items, hard-coded or references

Post by dunbarx » Tue Nov 08, 2022 3:09 pm

CAsba

Did you examine the handler in the "Click here" button of the stack I posted? It shows just that, loading the contents of a field into the "contents" of a button.

And as Klaus belatedly :D mentioned, you can do that (very nicely, in fact) right at the menu button itself, on mouseDown. Do you see all that?

Craig

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

Re: Menu items, hard-coded or references

Post by dunbarx » Tue Nov 08, 2022 3:10 pm

I just wanted to get to 8700.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Menu items, hard-coded or references

Post by FourthWorld » Tue Nov 08, 2022 5:44 pm

CAsba, the others here have handled your question well. I just want to add a small but hopefully inspiring insight:

The LiveCode IDE is written in LiveCode Script. Anything you see it do -- such as providing an interface for setting the text of menu items -- is something you can do in your own apps.

So when you using the IDE to do something you'd like to do in your own script, you can look at the property name shown in the Inspector, and look that property up in the LiveCode API Dictionary.

Also, to get an empowering overview of the scope of object properties and how to use them, the User Guide included in the install (see the Help menu) is worth a skim. Just a few minutes reviewing the scope of content there will tell you where to turn to learn most aspects of LiveCode as they come up in your work.

These forums are a great resource, the people there very helpful. And when you need an answer right away, those two resources -- the Dictionary and the User Guide -- can often get you going in just minutes.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: Menu items, hard-coded or references

Post by CAsba » Wed Nov 09, 2022 11:12 am

Hi
Thanks everyone for your replies, and Craig, the code snippet you provided was spot on, it solved my prob.
Once again,
thanks to all of you.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Menu items, hard-coded or references

Post by jacque » Wed Nov 09, 2022 7:24 pm

So when you using the IDE to do something you'd like to do in your own script, you can look at the property name shown in the Inspector, and look that property up in the LiveCode API Dictionary.
If you haven't changed it in preferences, you will see an explanation of the property instead of the LC name. To see what you should look up in the dictionary, hover the mouse over the name to see the actual property name.

Do yourself a favor and change the inspector to show the real property name. That reverses the response so that hovering shows the description.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply