Xbasic

UI_GET_FILE Function

Syntax

Result_String as C = UI_GET_FILE(C title,C file_types[,C default_choice[,C exist_flag]])

Arguments

Result_String

The filename you specify is returned as a Result_String. The Result_String will be empty ("") if the Cancel button is selected. The Result_String can up to 64,000 characters in length.

title

The title of the dialog box. If the Title has the word "save" in it, the button on the File Open dialog will be "Save". Otherwise, it will be "Open".

file_types

May contain one or more file types which will be available in the file type drop-down list. The Open File dialog box will display only those files whose filename extensions match the selected type. The file type is specified by writing the file type description followed by the extension template: (*.AAA), where A represents one of the extension characters. For example, to show only table files, the File Type String would be " Tables(*.DBF) ". To include multiple file types, separate each description and template with the "|" separator. For example: " Text(*.TXT)|Excel(*.XLS) ". The dropdown box in the file selector will show "Text (*.TXT)" as the selected option and if you open the dropdown, the other options will be shown. Each selector can include multiple file types. For example, you could show .txt and .csv files for the Text option shown above. For example "Text(*.TXT;*.CSV)|Excel(*.XLS*}". To show only file names beginning with the letter "c" use " (c*.*) ".

default_choice

Optional. The filename that appears in the File Name field when the dialog box first appears.

exist_flag

Optional.

"X" = Filename must already exist.
"N" = Filename must not already exist.
"M" = Allows you select multiple files with the Alpha Anywhere file select dialog
"ME" = Allows you to select multiple files with a standard Windows file select dialog box.

Description

Prompt user for filename.

Discussion

UI_GET_FILE() displays the File Open dialog box to obtain a filename and path. Note : If the user selects more than one file, the first entry in the returned list is the path to the files. Subsequent entries are file names.

Example

This script sets the default directory to "c:\documents" before opening the file selection dialog.

dim defdir as C = "c:\documents"
filename = ui_get_file("Select File", "", defdir +"\*.*")

This script opens the specified table and copies it to a new file.

table_to_copy = ui_get_file("Open Table to Copy", "Table(*.DBF)", "","X")
if (table_to_copy = "") then
    end
end if
tbl = table.open(table_to_copy, FILE_RW_EXCLUSIVE)
new_table_name = ui_get_file("Name the new table", "Table(*.DBF)", "","N")
if (new_table_name = "") then
    tbl.close()
    end
end if
tbl.duplicate(new_table_name, 0)
tbl.close()

These examples show the effect of different values for Exist_Code.

? ui_get_file("","","")
= "C:\Databases\AlphaMovies\AlphaMovies.adb"
? ui_get_file("","","","m")
= "C:\Databases\AlphaMovies\ AlphaMovies.adb AlphaMovies.ALB AlphaMovies.ALM"
? ui_get_file("","","","me")
= C:\Databases\AlphaMovies
AlphaMovies.ALM
AlphaMovies.adb
AlphaMovies.ALB

Limitations

Desktop applications only

See Also