MapInfo Pro Developers User Group

 View Only
Expand all | Collapse all

Running mbx file from a button closes ribbon

  • 1.  Running mbx file from a button closes ribbon

    Posted 05-26-2020 14:48
    Edited by Michel Li 05-26-2020 14:48
    Hi! I created a button in which when clicking on the button, it will call the procedure to execute. In this procedure, I am calling "run application  mbx". When I first clicked, it is working fine and it does execute the mbx file. When I clicked it again to execute the same mbx file because I want to run it again. It closes my ribbon tab. Does anyone know what can be the reason? Here are the codes.

    nCtrlIdx = RBNGroupAddButton("showAerialGrid", "Generate Aerial Grid", "A1", sTabName, sGroupName)
    	If nCtrlIdx > 0 Then
    		'Create & Set the button tooltip
    		Call RBNControlSetToolTipIdx(nCtrlIdx, "Generate Aerial Grid", "This will generate Aerial Grid","")
    		'Set the button icon
    		Call RBNControlSetIconsIdx(nCtrlIdx, CONTROL_SIZE_LARGE, "", PATH_IMAGES & "aerialgrid.png")
    		'Set Custom MapBasic Handle to the button
    		Call RBNControlSetCustomMBXHandlerIdx(nCtrlIdx, "LaunchAerialGrid")
    	End If
    ​

    an example is this procedure is:

    Sub LaunchAerialGrid
    	
    	Run Application "C:\GeoApps\MapApp2007\AerialGrid\AerialGrid.mbx"
    
    End Sub
    ​


    ------------------------------
    Michel Li
    Programmer
    GEOSEARCH LLP
    Austin TX
    ------------------------------


  • 2.  RE: Running mbx file from a button closes ribbon

    Employee
    Posted 05-27-2020 03:01
    Hi Michel

    It seems that something makes your tool crash silently. At least that might explain why the ribbon tab get's removed.

    Can you try to put a Note statement before and after the Run Application statement? This might tell you if you successfully run and finish the statement in the procedure called by the button.

    Does the AerialGrid tool get loaded?

    ------------------------------
    Peter Horsbøll Møller
    Distinguished Engineer
    Pitney Bowes Software & Data
    ------------------------------



  • 3.  RE: Running mbx file from a button closes ribbon

    Posted 05-27-2020 11:41
    Peter and Bill,

    Thanks for replying to my questions.
    I did put a note before and after the run application statement. It said the mbx file is already executed. I think part of my design is not correct. How do I do to make sure it run each time I press the button to execute the mbx file?

    This is my design.

    For my codes. I called the mbx file with button from my main program.

    Call RBNControlSetCustomMBXHandlerIdx(nCtrlIdx, "LaunchAerialGrid")​

    Then in my aerialtopo.mb, I called the mbx file.

    Sub LaunchAerialGrid
    	
    	Run Application "C:\GeoApps\MapApp2007\AerialGrid\AerialGrid.mbx"
    	
    End Sub
    ​

    What do I need to do so the program does not complain it is already excecuted.

    I did add the EndHandler sub as Bill Wemple suggested after my main program. I am not sure if I did right.

    Sub EndHandler
    
    	Call RBNEndHandler
    	Exit Sub
    
    End Sub
    ​



    ------------------------------
    Michel Li
    Programmer
    GEOSEARCH LLP
    Austin TX
    ------------------------------



  • 4.  RE: Running mbx file from a button closes ribbon

    Employee
    Posted 05-27-2020 08:21
    Is there an EndHandler sub in the code so the program does not unload after AerialGrid.MBX is run?

    ------------------------------
    Bill Wemple
    Principal QA Engineer
    Pitney Bowes
    Troy, NY
    ------------------------------



  • 5.  RE: Running mbx file from a button closes ribbon

    Posted 05-27-2020 11:43
    Bill,

    I did add the EndHandler as you suggested but it still does close the ribbon tab. I put more information to the reply above. Thank you for your help.

    ------------------------------
    Michel Li
    Programmer
    GEOSEARCH LLP
    Austin TX
    ------------------------------



  • 6.  RE: Running mbx file from a button closes ribbon

    Employee
    Posted 05-28-2020 04:52
    Your AerialGrid application... does that also stay loaded or does it unload after you have used it?
    If it stays loaded, that might explain the issue. If you try to run a tool that already is loaded you might see some issues.

    If you add some error handling to your procedure, you can prevent your tool from crashing when errors occur. They could look like this:

    Sub LaunchAerialGrid

    OnError GoTo ErrorOccured:

    Run Application "C:\GeoApps\MapApp2007\AerialGrid\AerialGrid.mbx"

    Exit Sub
    '---------

    ErrorOccured:
       Note "Some Error happened: " & Err()  " " & Error$()
    End Sub

    ------------------------------
    Peter Horsbøll Møller
    Distinguished Engineer
    Pitney Bowes Software & Data
    ------------------------------



  • 7.  RE: Running mbx file from a button closes ribbon

    Posted 05-28-2020 09:28
    Peter,

    When I load the main mbx file to generate the ribbon tab, it will generate the mbx launchaerialgrid file also. Then when I clicked the button that allows to run the launchaerialgrid mbx, it works the first time. Then when I launched it again it is where it crashes and the main ribbon tab crashed it also. Is it because I created a mbx file inside a main mbx that causes the crash?

    ------------------------------
    Michel Li
    Programmer
    GEOSEARCH LLP
    Austin TX
    ------------------------------



  • 8.  RE: Running mbx file from a button closes ribbon

    Employee
    Posted 05-29-2020 02:17

    Hi Michel

    That might be the problem but I'm not sure what you mean by "I created a mbx file inside a main mbx"? I assume you mean you load/run one MBX from another MBX, right?

    To me, it seems that your main MBX starts and creates a number of buttons on the ribbon interface. One of these launches another MBX. This isn't a general problem. It depends on how your other MBX "behaves". If this other MBX also loads itself into memory and stays loaded in MapInfo Pro, you might run into a problem when you try to run it again.

    If the other MBX just runs and performs a certain task and then unloads itself again, there shouldn't be a problem. Can you see the other MBX in the Tools window after you have clicked the button to run it?

    But again, I think you can get around the issue by adding the error handling I mentioned above to the procedure where you try to run the MBX. This will catch any errors and should also prevent your main MBX from crashing,



    ------------------------------
    Peter Horsbøll Møller
    Distinguished Engineer
    Pitney Bowes Software & Data
    ------------------------------



  • 9.  RE: Running mbx file from a button closes ribbon

    Posted 05-29-2020 10:36
    Edited by Michel Li 05-29-2020 11:27
    Peter,

    You are correct. The other mbx (LaunchAerialGrid) stays loaded in Mapinfo Pro. Once I clicked the button to run it, it runs the application. It stays which is what I want. I tried to add the error handling you mentioned in the LaunchAerialGrid sub and it is still crashing. I think I know why. In my launchAerialgrid mbx application, it connects to SQL and I think it could not create a table in there so it crashes.




    ------------------------------
    Michel Li
    Programmer
    GEOSEARCH LLP
    Austin TX
    ------------------------------



  • 10.  RE: Running mbx file from a button closes ribbon

    Employee
    Posted 06-04-2020 09:10
    Hi Michel

    You could try to run the application in the MapInfo Pro scope/session instead of in the scope/session of your MapBasic application. You can do that by using the Run Command to execute your statement, see below.

    Sub LaunchAerialGrid

    OnError GoTo ErrorOccured:

    Run Command "Run Application " & Chr$(34) & "C:\GeoApps\MapApp2007\AerialGrid\AerialGrid.mbx" & Chr$(34)

    Exit Sub
    '---------

    ErrorOccured:
       Note "Some Error happened: " & Err()  " " & Error$()
    End Sub

    That might prevent your initial application from crashing if the AerialGrid.MBX is crashing.

    ------------------------------
    Peter Horsbøll Møller
    Distinguished Engineer
    Pitney Bowes Software & Data
    ------------------------------



  • 11.  RE: Running mbx file from a button closes ribbon

    Posted 06-09-2020 14:27
    Thanks Peter.

    I added your code and it did prevent the initial application from crashing. I am still trying to figure out why it crashed. I ran the same mbx file on Mapinfo 12.5 and it did not crash.

    ------------------------------
    Michel Li
    Programmer
    GEOSEARCH LLP
    Austin TX
    ------------------------------