Call Procedure from Pop Up Menu Button

I have a Pop Up Menu Button. I want to call procedures from this button. How do I accomplish this? I have searched help, tutorials and a few of the videos but I still cannot find a solution.

Any help is appreciated.

If you want to do something different for each menu item, the easiest way is to add a CODE option to the definition of each of them. So you might have a menu defined like this:

menu("MyPopupMenu")+
    menuitem("1st item","CODE",{call "First procedure"})+
    menuitem("2nd item","CODE",{call "Second procedure", argument})+
    menuitem("3rd item","CODE",{call "Third procedure"})

Or to have one procedure to deal with the whole menu, either put its code in, or call a named procedure from, the procedure code for the button, which is run when a selection is made from the pop-up menu. Then either test the variable PopupMenuResult to find the text of the menu item selected, or if you have added an IDENTIFIER option to each menuitem(, use info("menuidentifier") to find the identifier of the item selected and act accordingly.

See the help page for ā€˜Popup Menu Button Object’ and the section ā€˜Menu Item Operation (CODE and ACTION options)’ on the help page for menuitem(.

1 Like

Thank you. I am going to try this later today. Appreciate it.

With you help, and as a test, I was able to add an item ā€œAccountsā€ to the menubar:

windowmenubar ā€œbasicā€,
menu(ā€œAccountsā€ )+
menuitem(ā€œCheckingā€, ā€œCODEā€ , {call ā€œpCheckingā€})+
menuitem(ā€œSavingsā€, ā€œCODEā€, {call ā€œpSavingsā€})

This works great and will be very helpful.

However, I was not able to use the above (or some variant) to call the procedures (pChecking and pSavings) in a Popup Menu Button Object. I’m am not sure what to put into: Popup Button Items, Procedure and Formula. I’ve tried many things but can’t seem to make it work. I’ve read and reread the documentation as you suggested. Any further suggestions?

If the formula for the popup menu is ā€œChecking,Savings,ā€ you can place simple code like this in the procedure tab for the popup button object.

if Account="Checking" call pChecking else call pSavings endif
1 Like

The PopUp Menu button allows you to associate the the object with a field or variable. Once the menu item is selected, that field or variable will contain the value that was selected. If you have code in the Procedure tab, that code can reference the field or variable to decide what to do.

If you just want to run code, and don’t need to have the menu associated with a field or variable, it’s usually simpler to just use a push button (or any kind of object, even a rectangle or other shape) and use the popupclick statement to generate the menu. This is described in a subsection of the Popup Menu help page.

1 Like

I used this method and it works great. Used the example in the documentation. Used the example suggested by @epansoft to call procedure.

Also, thanks to @pcnewble for examples for use of custom menus.

Thanks to all.

Follow-up question. This is some of the documentation for popupclick:

ā€œYou can also use the menu( and menuitem( functions to create the menu, as shown in this example. This is more complicated but gives you more control – you can give menu items different colors or styles, or even include submenus in your pop-up menu.ā€

I found some old discussions related to submenus that said it didn’t work. Can submenus be used on buttons using popupclick? Just want to make sure before I continue testing.

No. Only with (a) menu-bar menus and (b) context-sensitive (right-click) menus in the data sheet.

1 Like