MORE INFORMATION
Note: In QuickBASIC, OPENing a new file for Random or APPEND access
displays a "Can't Find: <file>" dialog box, unless you select the
"Disable File Not Found Dialog" option, or first create the file with
OPEN FOR OUTPUT. For more information about the "Can't Find: <file>"
dialog box, please refer to a separate article in this database (query
for RANDOM AND DIALOG AND DISABLE AND QUICKBASIC AND MACINTOSH).
The remainder of this article is a tutorial for the FILES$(0)
function.
FILES$(0) prompts you with a standard Macintosh dialog box that allows
you to type a filename and choose the folder or DRIVE (volume) for the
new file to reside in. The SAVE button becomes enabled as soon as you
type one or more characters. If you click the SAVE button (or press
the RETURN or ENTER key), FILES$(0) returns a string with a
path-qualified filename of the form "disk:folder:filename". If you
click the CANCEL button, FILES$(0) returns a null string.
For a better understanding of FILES$(0), just run the following
program:
N$ = FILES$(0,"Name the file:")
PRINT N$
If you type the name of an existing file in response to the FILES$(0)
prompt, an alert box asks you whether or not to replace the existing
file. If you select "No", you are allowed to change the name or
CANCEL. If you select "Yes", FILES$(0) returns a name of the form
"disk:folder:filename". The existing file is NOT affected unless later
in the program you execute an OPEN statement with that filename.
FILES$(1) is different than FILES$(0). The function FILES$(1) prompts
you with a standard Macintosh dialog box of EXISTING files and returns
the name of an existing file. You can then execute an OPEN statement
on the returned filename string.
The FILES$(0) and FILES$(1) functions are documented on Pages 131
through 133 of the "QuickBASIC For Apple Macintosh: Language
Reference" manual.
Code Example 1
OPEN FOR OUTPUT never gives you a "Can't Find: <file>" dialog prompt
(regardless of QuickBASIC's "Disable File Not Found Dialog" option):
NewFile$ = FILES$(0, "Name the new file:")
OPEN NewFile$ FOR OUTPUT AS #1
' Write to the file here if you wish.
CLOSE
END
Code Example 2
' This random access works in QuickBASIC as is, regardless of
' the "Disable File Not Found Dialog" option:
NewFile$ = FILES$(0, "Name the new file")
OPEN NewFile$ FOR OUTPUT AS #1
CLOSE #1 ' First create and close file before opening with random
OPEN NewFile$ AS #1 ' or APPEND access.
' Write to the file here if you wish.
CLOSE
END
Code Example 3
' You must select the "Disable File Not Found Dialog" option
' before running this program in QuickBASIC (interpreter or
' compiler). Works as is in earlier BASICs for Macintosh.
NewFile$ = FILES$(0, "Name the new file")
OPEN NewFile$ AS #1 ' Opens new file for random access.
' Write to the file here if you wish.
CLOSE
END