jps services
  • Home Page
  • GIS Training Courses
    • QGIS Training Courses
    • ArcGIS Training Courses
    • MapInfo Pro Training Courses >
      • MapBasic Training Course
  • About
  • Blog

Updating menu based MapBasic code to the new ribbon based interface

11/1/2017

0 Comments

 
If you run any menu based MapBasic code in the latest version of MapInfo Pro it should still be available to use. The code is converted to accommodate the new ribbon interface. In this case your code will create a Legacy tab automatically as seen in the example below.
Picture
In many cases this is sufficient for the user and perhaps updating the code is not necessary. However, if the code does need to be updated then the process is not altogether a difficult task. All of the steps have been clearly explained by Peter Horsboll Moller in his slide presentations. Using the steps outlined in these presentations you could modify existing menu based code to a ribbon based solution.

To use the ribbon based interface used in the slide presentation examples, you also need some understanding of modular programming. Again this has been fully explained by Egg-Jan Polle in his pdf Modular Programming in MapBasic. As the example code for Modular Programming in MapBasic uses the menu based version of MapInfo Pro we could modify the User Interface Module: ProjectUI.mb. This module contains menu based code and can be used to demonstrate how to update existing code to a ribbon based interface. One of the advantages of modular code is that only those modules requiring changes need to be modified. All the other modules can be linked again to form the executable without further work or need for compiling of these modules.
Using the slide presentation we can create the appropriate file structures to create the revised version of this modular programming application. Below is the first stage in the process:-
Picture
Once you have created the above code and have compiled it into an MBO you can create a project file as in the following example:-
Picture
Now after linking this file you can run the ProjectRibbon.mbx which will produce the following result in MapInfo Pro:-

Picture
So far we have created some code which runs in MapBasic Pro but as yet we do not have a Tab or Group element in our code. This is the next stage of the process as shown in the following code:-
Picture
Here we have created a new Tab and Group for the user interface MBO part of our code. When this code is compiled and linked we can run it in MapInfo with the following results:-
Picture
At this stage we need to add the relevant buttons to enable the user to access the features of the code. This is demonstrated in the following code snippet:-
Picture
Next we need to update the MBP file to include those modules we intend to access. As shown in the following image:-
Picture
The above code snippets, when compiled and linked, will create a button with an image of a clock in MapInfo to reflect the fact that this is module gives us the current time.

When you create custom code you will either have to create images or download them from the web. The presentation by Peter Hors Boller, mentioned earlier, includes the various options regarding images including using one of the numerous icons available within MapInfo Pro.  In this coding example some free images for the time, date and about buttons were downloaded from the web.  These images were then resized to 32x32 pixels using the Paint program.The above code snippets, when compiled and linked, will create a button with an image of a clock in MapInfo to reflect the fact that this  module gives us the current time.
Picture
If the clock button is pressed the time module is called as shown below:-
Picture
The next stage is to create icons for the other two modules. We can do this by copying the appropriate code that we used to create the first icon and then updating the information. Normally, I would not recommend just copying code. There is a school of thought which believes that the learning process is enhanced when you actually type code rather than just cutting and pasting. However, on this occasion the copying process is acceptable as it will ensure that errors are minimised when creating the next two buttons for our ribbon based app.
​
Here is the updated code:-
Picture
As well as updating this section of code we also need to make other changes to get the app to run successfully. The About and End_Program sections of code have been put into separate modules and therefore have also been added the ProjectRibbon.mbp.
​
Here is the code for the About module:-
Picture
Here is the code for the End_Program module:-
Picture
Finally, here is the code for the ProjectRibbon.mbp:-
Picture
If the code is now compiled and linked when the code is run the following screen shows the launch statement:-
Picture
A new tab called Sample Code is loaded which now has three buttons as shown in the next screen:-

Picture
Clicking on the first Time button will produce the current time as shown below:-
Picture
Clicking on the Date button shows the current date as shown below:-
Picture
​Finally clicking on the about button will show the following dialogue box:-
Picture
When the exit button is clicked the option to close the program is given as shown below:-
Picture
Clicking on the yes button closes the application and removes the added ribbon tab.

In summary in this blog we have taken existing legacy code and revised it so that it could be run as a ribbon based application. The code example requires an understanding of how modular programs work as well as some understanding of how to implement ribbon based applications.  
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    Author

    Joe Short BSc has been involved with various mapping solutions for over twenty years.  If you are considering implementing a GIS  or have ArcGIS Pro, MapInfo Pro or QGIS training requirements, jps services would be happy to be of assistance to your organisation. 

    Archives

    April 2020
    March 2020
    October 2019
    September 2019
    August 2019
    July 2019
    March 2019
    November 2018
    October 2018
    August 2018
    July 2018
    November 2017
    October 2017
    September 2017
    July 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    May 2016
    February 2016
    September 2015
    August 2015
    April 2015
    February 2015
    November 2014
    October 2014
    July 2014
    June 2014
    May 2014
    March 2014
    February 2014
    December 2013
    November 2013
    October 2013
    September 2013
    August 2013
    June 2013
    May 2013
    April 2013
    February 2013
    December 2012
    October 2012
    September 2012
    August 2012
    July 2012

    Categories

    All
    Arc Gis
    Arcview
    Autodesk
    Cad
    Gis Training
    Local Government
    Mapbasic
    Mapinfo
    Quantum Gis
    Relational Databases
    Saga Gis

    RSS Feed