Stata 15 help for window fopen

[P] window fopen -- Display open/save dialog box

Syntax

window {fopen|fsave} macroname "title" "filter" [extension]

Description

window fopen and window fsave allow Stata programmers to use standard File > Open... and File > Save dialog boxes in their programs.

Remarks

window fopen and window fsave call forth the operating system's standard File > Open... and File > Save dialog boxes. The commands do not themselves open or save any files; they merely obtain from the user the name of the file to be opened or saved and return it to you. The filename returned is guaranteed to be valid and includes the full path.

The filename is returned in the global macro macroname. In addition, if macroname is defined at the outset, its contents will be used to fill in the default filename selection.

title is displayed as the title of the dialog.

filter must be specified. One possible specification is "", meaning no filter. Alternatively, filter consists of pairs of descriptions and wildcard file selection strings separated by '|', such as

"Stata Graphs|*.gph|All Files|*.*"

Stata uses the filter to restrict the files the user sees. The above example allows the user either to see Stata graph files or to see all files. The dialog will display a drop-down list from which the user can select a file type (extension). The first item of each pair (Stata Graphs and All Files) will be listed as the choices in the drop-down list. The second item of each pair restricts the files displayed in the dialog box to those that match the wildcard description. For instance, if the user selects Stata Graphs from the list box, only files with extension .gph will be displayed in the file dialog box.

Finally, extension is optional. It may contain a string of characters to be added to the end of filenames by default. For example, if the extension were specified as xyz, and the user typed a filename of abc in the file dialog box, abc.xyz would be returned in macroname.

In Windows, the default extension is ignored if a filter other than *.* is in effect. For example, if the user's current filter is *.gph, the default extension will be .gph, regardless of the extension specified.

Because Windows allows long filenames, extension can lead to unexpected results. For example, if extension were specified as xyz and the user typed a filename of abc.def, Windows would append .xyz before returning the filename to Stata, so the resulting filename is abc.def.xyz. Windows users should be aware that if they want to specify an extension different from the default, they must enter a filename in the file dialog box enclosed in double quotes: "abc.def". This applies to all programs, not just Stata.

If the user presses the Cancel button on the file dialog, window fopen and window fsave set macroname to be empty and exit with a return code of 601. Programmers should use the capture command to prevent the 601 return code from appearing to the user.

----------------------------------------------- begin dtaview.ado ---- program dtaview version 15.1 capture window fopen D_dta "Select a dataset to use:" /* */ "Stata Data (*.dta)|*.dta|All Files (*.*)|*.*" dta if _rc==0 { display "User chose $D_dta as the filename." use "$D_dta" } end ----------------------------------------------- end dtaview.ado ------


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index