FileOpenDlg() function - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Displays a File Open dialog box, and returns the name of the file the user selected. You can issue this statement from the MapBasic window in MapInfo Pro.

Syntax

FileOpenDlg ( path, filename, filetype, prompt )

path is a string value, indicating the directory or folder to choose files from.

filename is a string value, indicating the default file name for the user to choose.

filetype is a string value, three or four characters long, indicating a file type (for example, "TAB" to specify tables).

prompt is a string title that appears on the bar at the top of the dialog box.

Return Value

String value, representing the name of the file the user chose (or an empty string if the user canceled).

Description

The FileOpenDlg() function displays a dialog box similar to the one that displays when the user chooses Open command.

To choose a file from the list that appears in the dialog box, the user can either click a file in the list and click the OK button, or simply double-click a file in the list. In either case, the FileOpenDlg() function returns a character string representing the full path and name of the file the user chose. Alternately, if the user clicks the Cancel button instead of picking a file, the dialog returns a null string ("").

The FileOpenDlg() function does not actually open any files; it merely presents the user with a dialog box, and lets the user choose a file. If your application then needs to actually open the file chosen by the user, the application must issue a statement such as the Open Table statement. If you want your application to display an Open dialog box, and then you want MapInfo Pro to automatically open the selected file, you can issue a statement such as the Run Menu Command statement with M_FILE_OPEN or M_FILE_ADD_WORKSPACE.

The path parameter specifies the directory or folder from which the user will choose an existing file. Note that the path parameter only dictates the initial directory, it does not prevent the user from changing directories once the dialog box appears. If the path parameter is blank (a null string), the dialog box presents a list of files in the current working directory.

The filename parameter specifies the default file name for the user to choose.

The filetype parameter is a string, usually three or four characters long, which indicates the type of files that should appear in the dialog box. Some filetype settings have special meaning; for example, if the filetype parameter is "TAB", the dialog box presents a list of MapInfo tables, and if the filetype parameter is "WOR", the dialog box presents a list of MapInfo workspace files.

There are also a variety of other filetype values, summarized in the table below. If you specify one of the special type values from the table below, the dialog box includes a control that lets the user choose between seeing a list of table files or a list of all files ("*.*").

filetype parameter Type of files that appear
"TAB" MapInfo tables
"WOR" MapInfo workspaces
"MIF" MapInfo Interchange Format files, used for importing / exporting maps from / to ASCII text files.
"DBF" dBASE or compatible data files
"WKS", "WK1" Lotus spreadsheet files
"XLS", "XLSX" Excel spreadsheet files
"DXF" AutoCAD data interchange format files
"MDB", "ACCDB" Microsoft Access Database files
"MMI", "MBI" MapInfo for DOS interchange files
"MB" MapBasic source program files
"MBX" Compiled MapBasic applications
"TXT" Text files
"BMP" Windows bitmap files
"WMF" Windows metafiles

Each of the three-character file types listed above corresponds to an actual file extension; in other words, specifying a filetype parameter of "WOR" tells MapBasic to display a list of files having the ".WOR" file extension, because that is the extension used by MapInfo Pro workspaces.

To help you write portable applications, MapBasic lets you use the same three-character filetype settings on all platforms. On Windows, a control in the lower left corner of the dialog box lets the user choose whether to see a list of files with the .TAB extension, or a list of all files in the current directory. If the FileOpenDlg() function specifies a filetype parameter which is not listed in the table of file extensions above, the dialog box appears without that control.

Example

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

See Also:

FileSaveAsDlg() function, Open File statement, Open Table statement