Programmatically add option to menu.

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

Programmatically add option to menu.

Post by CAsba » Wed Feb 22, 2023 11:13 am

Hi,
I've been trying to set up a new customer, and need to add the new customer code to a menu, so that the user can select the customer when raising an invoice, for example. I've tried to achieve this with all the types of menu in the tools pallette without success, and can't find anything in the lessons about it. Is it possible to do it, or will I have to resort to something entirely different ?

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

Re: Programmatically add option to menu.

Post by Klaus » Wed Feb 22, 2023 11:27 am

Hi CAsba,

you need to modify "the text of btn yourmenuhere".
Example to add a new name to an existing menubutton:

Code: Select all

...
put the text of btn "your menu button here..." into tText
put CR & "Joe Average" after tText
set the text of btn "your menu button here..." to tText
...
If that is what you mean.

Best

Klaus

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

Re: Programmatically add option to menu.

Post by CAsba » Wed Feb 22, 2023 1:28 pm

Thanks, Klaus. It works, but...
The first time the new line in the menu is immediately under the top line, it is on the next linr. Subsequent additions of options skip a line. I have removed the "CR &" from the line and still does it. I've also tried using a field instead of the variable tText.
If I'm stuck with this, is there an easy way to remove blank lines in the menu ?

SparkOut
Posts: 2944
Joined: Sun Sep 23, 2007 4:58 pm

Re: Programmatically add option to menu.

Post by SparkOut » Wed Feb 22, 2023 2:19 pm

Yes, the easy way is

Code: Select all

filter tText without empty

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

Re: Programmatically add option to menu.

Post by CAsba » Wed Feb 22, 2023 2:31 pm

Thanks SparkOut, that did it !

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

Re: Programmatically add option to menu.

Post by Klaus » Wed Feb 22, 2023 3:06 pm

Yep, use FILTER as SparkOut or check if the text = EMPTY! 8)

Code: Select all

...
put the text of btn "your menu button here..." into tText
put "Joe Average" into tItem
if tText <> EMPTY then
   put CR before tItem
end if
put tItem after tText
set the text of btn "your menu button here..." to tText
...

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

Re: Programmatically add option to menu.

Post by Klaus » Wed Feb 22, 2023 4:39 pm

Always think about how you would handle this in "real life"!

If you have a sheet of paper (tText), you would start to write at the top only if the sheet is empty.
If not, you would start to write on a new line!

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

Re: Programmatically add option to menu.

Post by dunbarx » Wed Feb 22, 2023 8:42 pm

What Klaus said.

But that said, it is indeed a little confusing because in a field, it is not obvious if a return character lurks at the end of a line. Returns are invisible.

Try this on a card with a field. In the message box:

Code: Select all

put "ABC" & return into fld 1
Now:

Code: Select all

put "ABC" after fld 1
You get two lines. But if you:

Code: Select all

put "ABC" into fld 1
And then

Code: Select all

put "ABC" after fld 1
You get one line of text.

You have to watch it.

Craig

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

Re: Programmatically add option to menu.

Post by dunbarx » Wed Feb 22, 2023 8:45 pm

And just to sober you, if you:

Code: Select all

 put "ABC" & return into fld 1
and then ask for the number of lines in fld 1, you will get "1" as answer. The same as if you did not include the trailing return. A return char is just a character, oftentimes sitting invisibly at the end of a line.

But it does things we need it to. You just have to watch it if you are playing in that space.

Craig

Post Reply