Hi Jay
These days there are multiple ways to build your ribbon interface through MapBasic.
When I'm using the RibbonLib to build my interface, I use a structure like this:
For nCtrl = 1 To Ubound(marrFavoriteMaps) nCtrlIdx = RBNGroupAddButton("openBaseMap" & nCtrl, marrFavoriteMaps(nCtrl).sName, "", marrAddToRibbon(nTab).sTabName, marrAddToRibbon(nTab).sGroupName) If nCtrlIdx > 0 Then Call RBNControlSetToolTipIdx(nCtrlIdx, PRGIGetApplicationName(), marrFavoriteMaps(nCtrl).sName, "") Call RBNControlSetIconsIdx(nCtrlIdx, mnImageSize, "", marrFavoriteMaps(nCtrl).sImageFile) Call RBNControlSetCustomMBXHandlerIdx(nCtrlIdx, "MENUFavoriteMapClicked") nCount = Ubound(marrCommand2FavoriteMap) + 1 ReDim marrCommand2FavoriteMap(nCount) marrCommand2FavoriteMap(nCount).nCommandId = RBNControlGetControlIDIdx(nCtrlIdx) marrCommand2FavoriteMap(nCount).nFavoriteMapItem = nCtrl End IfNextThe general idea is that for flexibility, the buttons are stored in an array. This makes it easy to add more, and in this case, I can let the user add as many as they would like.
To create the buttons on the ribbon, I can now loop over this array:
For nCtrl = 1 To Ubound(marrFavoriteMaps)Every time I have added a new control/button, I get the Control ID and store this in an array too:
ReDim marrCommand2FavoriteMap(nCount) marrCommand2FavoriteMap(nCount).nCommandId = RBNControlGetControlIDIdx(nCtrlIdx) marrCommand2FavoriteMap(nCount).nFavoriteMapItem = nCtrlNow my example may be a bit more complicated than your solution.
If you only have a few buttons, you can store the Control IDs in a couple of variables instead.
This is from a tool called Favorites Maps. You can find
the full source code here on GitHub.
The RibbonLib is part of
the MapBasic Library that can be found on Github too.
If you are using the new
Create Ribbon statement that we added to MapBasic v2021, you can use the function
RibbonItemInfo to get to the ControlID via the attribute
PROPERTY_CONTROLID.
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
------------------------------