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

Standard and custom dialog boxes in MapBasic

12/12/2016

0 Comments

 
If you search for Dialog Statement in MapBasic Help you will see that its purpose is to create custom dialog boxes.
In  a previous blog we used the Note statement, which is the most basic of MapInfo’s standard dialogs. The Help section on Dialogs states: - “The Dialog statement lets you create a custom dialog box. If you want to display a standard dialog box (for example, a File>Open dialog box), use one of the following statements or functions: Ask() function, Note statement, ProgressBar statement, FileOpenDlg() function, FileSaveAsDlg() function, or GetSeamlessSheet() function).”

The Ask() function displays a dialog box which asks the user a yes or no question. The example in the Help section is as follows:-
​

Dim more As Logical
more = Ask("Do you want to continue?", "OK", "Stop")

This code by itself will not show an Ask dialogue box so please do not try and run this example. This is because it will cause MapInfo to run the program in the background without displaying the Ask dialogue box. The code will compile and can be run, but with the result of having to reboot your computer to cancel the code from the system. If curiosity gets the better of you and you run this code you will only be aware of the problem as the MapInfo icon at the bottom of your computer screen will flash intermittently. If you attempt to close MapInfo you will get a message saying that you cannot quit MapInfo. You can resolve the problem by restarting which will close MapInfo and the underlying problem. Needless to say you are better off just accepting that this code is to be run only as part of a larger section of code as shown in the code sample below:-

'************************************************************************************
'** Ask Function Example
'**
'** Author: Joe Short
'** Date: 12th December 2016
'** Version: AppVersion (see below)
'** Example created with the help of code developed by Egge-Jan Pollé
'************************************************************************************
Include "MAPBASIC.DEF"
Include "ICONS.DEF"
Include "MENU.DEF"

Declare Sub Main
Declare Sub About
Declare Sub End_Program

Define AppName "Ask Function Example"
Define AppVersion 1.0

'Defining Dialog Width and Height
'This allows you to specify width and height clauses in terms of characters (i.e., Width 30dW, Height 10dH).
Define dW *4 'Four dialog units equals one character in width
Define dH *8 'Eight dialog units equals one character in height

'*********************************************************************************************
Sub Main
'*********************************************************************************************

Call About

End Sub Main

'*********************************************************************************************
Sub About
'*********************************************************************************************
Dialog
Title "About " + AppName + " (Version " + AppVersion + ")"
Control StaticText title "This simple application demonstrates how the Ask function works." Position 3dW, 1dH
Control StaticText title "To see how it works:" Position 3dW, 3dH
Control StaticText title "- Look at the Sub End_Program section of the code" Position 3dW, 4dH
Control StaticText title " You have the option of closing the application " Position 3dW, 5dH
Control StaticText title "If you select Cancel the program closes" Position 3dW, 7dH
Control StaticText title "If you select Exit the application will display the Ask dialogue box" Position 3dW, 8dH
Control StaticText title "This gives you the option of cancelling or continuing the program" Position 3dW, 9dH
Control StaticText title "This is a simple example of how to use the Ask() function" Position 3dW, 10dH
Control StaticText title Chr$(169) + " 2016 - Joe Short" Position 50dW, 14dH
Control OKButton Title "&Exit" Calling End_Program
Control CancelButton

End Sub About

'*********************************************************************************************
Sub End_Program
'*********************************************************************************************

Dim Finished as Logical

Finished = Ask("Are you sure you want to remove the application " + AppName + "?", "&Yes", "&No")

If not Finished then Dialog Preserve

Else

End Program

End if

End Sub End_Program

'*********************************************************************************************​
This code calls the Sub About routine which displays a dialogue box containing a Title and three Control types: StaticText, OKButton and CancelButton. ​
​
Picture
The dialogue box is self explanatory so I will not repeat the options offered. Some points to note are how Define statements enable updates to code can be made without having to make multiple changes. Title "About " + AppName + " (Version " + AppVersion + ")" and dW and dH are examples of how this can be used. The copyright icon is created by using Chr$(169) in your code.​

If you click on the Exit button the Ask dialogue box appears as below:-
​
Picture
Clicking on the No button will take you back to the information dialogue box. Clicking on the Yes button removes the program from MapInfo.

If you look up the Dialog Preserve statement in MapBasic Help the following code sample is shown:-

Sub confirm_cancel

             
If  Ask("Do you really want to lose your changes?",

                   
  "Yes", "No" ) = FALSE  Then

                     
  Dialog Preserve

            
  End If

​
End Sub

This code checks to see if the user wants to lose any changes. If the response is No (FALSE) then the Dialog Preserve statement reactivates the original dialogue box. For more information on Dialog Preserve look up this option in the MapBasic Help facility. For more information on customising dialogue boxes check out the Dialog statement in MapBasic Help.
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