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.
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(
.
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
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.
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.