Page 1 of 1

Programmatically add option to menu.

Posted: Wed Feb 22, 2023 11:13 am
by CAsba
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 ?

Re: Programmatically add option to menu.

Posted: Wed Feb 22, 2023 11:27 am
by Klaus
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

Re: Programmatically add option to menu.

Posted: Wed Feb 22, 2023 1:28 pm
by CAsba
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 ?

Re: Programmatically add option to menu.

Posted: Wed Feb 22, 2023 2:19 pm
by SparkOut
Yes, the easy way is

Code: Select all

filter tText without empty

Re: Programmatically add option to menu.

Posted: Wed Feb 22, 2023 2:31 pm
by CAsba
Thanks SparkOut, that did it !

Re: Programmatically add option to menu.

Posted: Wed Feb 22, 2023 3:06 pm
by Klaus
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
...

Re: Programmatically add option to menu.

Posted: Wed Feb 22, 2023 4:39 pm
by Klaus
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!

Re: Programmatically add option to menu.

Posted: Wed Feb 22, 2023 8:42 pm
by dunbarx
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

Re: Programmatically add option to menu.

Posted: Wed Feb 22, 2023 8:45 pm
by dunbarx
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