Upgrading and migrating > Converting encyclopedias to current version > Modifying macros created with older System Architect versions > Guidelines for adding macro items to menus programmatically > Adding a macro to a menu
  
Adding a macro to a menu
The main SA2001.Application method to support the adding of macro items is:
InsertMacroItemInMenu(MacroName as String, MacroItemCaption as String, InMenuTitleCaption as String, [BeforeMenuItemCaption as string]) as long
This function adds the MacroName (which comprises "<Project>.<Module>.<Subroutine>") using the caption MacroItemCaption to the SA/User menu titled InMenuTitleCaption, before the menu item titled BeforeMenuItemCaption. If no Before item is specified then the item is added to the end of the menu. If the before item is #TOP# then the item is inserted at the top of the menu.
The function returns 0 if successful, otherwise non‑zero.
In other words:
Set App = New SA2001.Application
x = App.InsertMacroItemInMenu("MyProject.MyModule.MySub", "&Test Item", "&Tools","&Macros")
This inserts the item “Test Item” in the Tools menu, before the Macros popup item. When the item is clicked on, the “MySub” subroutine is executed in the “MyModule” module in the “MyProject” project.
For this to succeed, the subroutine specified must already exist, and the captions must be specified exactly as in the menu.
For example, “Tools” is represented as the string &Tools
An ampersand implies an underscore under the following letter. This is case‑sensitive.
The subroutine name, should not have () following it.
The adding of BMPs to menu items is done by the AssignBMPtoMacroItem method, for example:
AssignBMPtoMacroItem(MacroName as String, BMPFileName as String) as long
This function returns zero if successful, or non‑ zero otherwise.
This should be done prior to adding the macro item to the menu, but need only be done one time.
Example
Set App = New SA2001.Application
x = App.AssignBMPtoMacroItem("MyProject.MyModule.MySub", "C:\Piccy.BMP")
x = App.InsertMacroItemInMenu("MyProject.MyModule.MySub", "&Test Item", "&Tools","&Macros")
This will add the piccy.bmp to the MySub macro, then add it to the menus as in the previous example. Note that the customize menus (right‑click on menus) option will now include the Piccy.BMP and the caption '&Test Item', if you wanted to put the menu item anywhere else in your menus.
See also
Guidelines for adding macro items to menus programmatically