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

MapBasic FileSaveAsDlg() Function

7/1/2017

0 Comments

 
Like the FileOpenDlg() function the FileSaveAsDlg() has four string arguments: the default path, default name, file type and a dialogue prompt. Just as the FileOpenDlg() function does not open files in the same way the FileSaveAsDlg() function does not save files. The FileSaveAsDlg() function returns a string representing a file path. The user can either choose a new name for the file or choose to overwrite an existing file.
Here is some sample code using the FileSaveAsDlg() function to save a file with a new name and then opening a map and browser for this new file
' Program: File Save As Dialog Program.mb
' Purpose: Demonstrate the FileSaveAsDlg() function
'Includes
Include "mapbasic.def"
'Declares
Declare Sub Main()
Declare Sub WorkWithCopyOfTable(ByVal sTarget As String)
Define DEF_TABLE_TO_COPY  "STATES"
Define DEF_NEW_TABLE_NAME  "STATES_NEW"

' Procedure: Main()
' Purpose: Main Control

Sub Main ()
     Dim sNewTable As String
    ' Make sure the table to be copied exists.
    If (FileExists(DEF_TABLE_TO_COPY + ".tab")) Then
    ' Use FileOpenDlg() to get file path.
    ' You will use this path to save a copy of the table later.
    sNewTable = FileSaveAsDlg(ApplicationDirectory$(),
                            DEF_NEW_TABLE_NAME + ".tab",
                            "TAB",
                            "Make copy of " + DEF_TABLE_TO_COPY + ":")
     ' Verify that user did not click CANCEL.
          If (sNewTable <> "" ) Then
               Open Table DEF_TABLE_TO_COPY
                ' Save old table under a new name and path.
               Commit Table DEF_TABLE_TO_COPY As sNewTable
               Close Table DEF_TABLE_TO_COPY
                ' Call routine to process only the copy.
               Call WorkWithCopyOfTable(sNewTable)
           Else
              ' User clicked Cancel.
               Note "No name chosen for copy.  Exiting program."
           End If
    Else
        ' The call to FileExists() returned False.
        Note "Table to be copied does not exist."
    End If
End Sub

' Procedure: WorkWithCopyOfTable()
' Purpose: Carry out tasks on table
Sub WorkWithCopyOfTable(ByVal sTargetTable As String)
' Work with copied table here.
    If (sTargetTable <> "") Then
        Open Table sTargetTable
       ' Use the TableInfo() function to obtain the tablename
       sTargetTable = TableInfo(0, TAB_INFO_NAME)
       Map From sTargetTable ' Open a map window
       Browse * From sTargetTable ' Open a browser
    Else
        Note "No Table Found"
        End Program
    End If
End Sub
 When this code is run in MapInfo a dialogue box opens similar to the following:-
Picture
 If the user decides to save the file then MapInfo will open the new table and then produce a map and browser for this table.
Picture
 As previously mentioned FileSaveAsDlg() function does not actually save files, instead it offers the user a choice of file name to save via a dialogue box. The user can choose this file name or choose another file with a different path when using this option. In order to save the data under this file name chosen by the user we need to issue a Commit Table statement. You can obtain more information about FileSaveAsDlg() and the Commit Table 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