savefile()

Examples


The savefile() function creates a dialog box allowing a user to enter a file name and select a path for the file’s location. It returns a boolean value indicating which button the user clicked in the dialog box.

The file types displayed in the dialog can be a predefined set, or you can create your own custom set of file types.

Syntax

savefile(prompt, file_type, path {,custom_file_types})

Parameters

prompt – The string to display in the dialog box.

file_type An integer variable or field that the file type value will be returned to. If you don’t supply a custom set of file types, the value returned will correspond to one of the following constants:

[spacer]

Constant

Description

TEXTFILE

Text file

TABFILE

Tab-delimited file

COMMAFILE

Comma-delimited file

HTMLFILE

HTML file

XMLFILE

XML file


The value indicates the file type selected by the user. You can then use this value to set up report outputs or export routines according to the file type selected.

If you create a set of custom file types, the value returned indicates which of the file types the user selected. The value 1 indicates the first custom file type, 2 indicates the second custom file type, and so on.

path – A string field or variable. You can set the value of this variable before calling the savefile() function to specify the default filename and location that will appear in the dialog box. If you supply only a filename, the current path will be used. If you supply a complete path (in native format) the default location will also be set in the dialog. If you set this variable to the empty string (""), the default filename will have the form “Export#”, where # is an integer value.

If the user clicks Save in the dialog, the path for the file, including the user-entered name and extension will be returned. If the user clicks Cancel, the empty string ("") will be returned.

custom_file_types – An optional string that specifies a custom set of file types to use. The set of custom file types is defined using the following syntax:

description |type|

The description parameter is a string that describes the file type, such as “Comma-Separated Values (*.CSV)”. It must be followed by a pipe (|) character.

The type parameter specifies a file extension, such as “*.CSV”. When this file type is used, files that match this extension will be displayed in the dialog box. The type parameter should not contain spaces. End the type parameter with a pipe (|) character.

Several custom file types can be concatenated within the custom_file_types string.

Return value

A boolean indicating which button was clicked. If Save is clicked, the value true is returned. If Cancel is clicked, the value false is returned.

Comments

If you will be using custom file type, consider creating messages or constants for each file type. You can then easily concatenate the filter types together and build the custom_file_types string. This is shown in the third example.


Documentation Feedback