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

MapBasic FileOpenDlg() function

2/1/2017

0 Comments

 
The FileOpenDlg() function doesn’t actually open files, rather the function offers the user the option of opening a file. This function takes up to four string type arguments. These include a default path, a default name, a file type and a prompt in the header bar. If all four of these options are left as NULL, the default path is chosen, the default name is an empty string, file type is *.TAB and the default header prompt is “Open”.

​Below is a coding example showing how FileOpenDlg() can be used to prompt the user to select a file to open in MapInfo. The user in this case is not prompted to open a specific file. Note that even if a default path and name are offered the user is free to choose a different path and file name.
 'Program: File Open Dialog Program.mb
' Purpose: Demonstrate the FileOpenDlg() function
' Includes
Include "MAPBASIC.DEF"
' Declares
Declare Sub Main
Declare Sub WorkWithTable(ByVal sTargetTable As String)
' Function: Main()
' Purpose: Main Control
Sub Main()
' Create a variable to hold the chosen filename and assign the user's choice to this variable
Dim s_filename As String
s_filename = FileOpenDlg("","","","")
' Check to see if a filename has been chosen
      If (s_filename <> "") Then
         Open Table s_filename
         Call WorkWithTable(s_filename)
      Else
         Note "No table chosen. Closing the program."
         End Program
       End If
End Sub

' Procedure: WorkWithTable()
' Purpose: Carry out tasks on the table
Sub WorkWithTable(ByVal sTargetTable As String)
      If (sTargetTable <> "") Then
          ' Use TableInfo to obtain the tablename
          sTargetTable = TableInfo(0, TAB_INFO_NAME)
          Map From sTargetTable ‘Open a map
          Browse * From sTargetTable 'Open a browser
      Else
          Note "No Table Found"
          End Program
      End If
End Sub

If you run this code a dialogue box opens similar to the one below:-
Picture
Note that the default name for the dialogue box is Open, the file name is left blank and the file type defaults to TAB. The user can choose a file from this or another location. On this occasion STATES table is chosen as in the following screen:-
Picture
 If the user chooses to open this file then MapInfo will also open a map and browser window as shown in the following screen:-

Picture
If the user decides to cancel the Open dialogue box instead of choosing a file the following Note statement will appear in MapInfo as shown in this screen:-
Picture
 When the user clicks OK on this message box the program is closed.

There is further information on the FileOpenDlg() function in the MapBasic Help. Here you will find a complete description of all the fuctionality avaiable including the following code snippet :-

Dim s_filename As String
s_filename = FileOpenDlg("","","TAB","Open Table")

As discussed in previous blogs not all code snippets are suitable for copying and pasting into MapBasic for running on their own (even though they may successfully compile).  The above code snippet, like other examples within MapBasic Help, is only given as a reminder of the syntax needed within your program should you want, as in this case, to prompt the user to open a file.


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

    March 2024
    October 2023
    September 2023
    August 2023
    March 2023
    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