Microsoft KB Archive/40714

= In Macintosh BASIC, FILES$(0) Doesn't Create File; OPEN Does =

Article ID: 40714

Article Last Modified on 11/21/2006



This article was previously published under Q40714



SUMMARY
The purpose of the FILES$(0) function is to prompt you for the name of a file that will be created or accessed later in the program.

FILES$(0) does NOT actually create a file. You must execute an OPEN statement on the filename string returned by FILES$(0) to actually create the file.



MORE INFORMATION
Note: In QuickBASIC, OPENing a new file for Random or APPEND access displays a &quot;Can't Find: &quot; dialog box, unless you select the &quot;Disable File Not Found Dialog&quot; option, or first create the file with OPEN FOR OUTPUT. For more information about the &quot;Can't Find: &quot; 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 &quot;disk:folder:filename&quot;. 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,&quot;Name the file:&quot;) 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 &quot;No&quot;, you are allowed to change the name or CANCEL. If you select &quot;Yes&quot;, FILES$(0) returns a name of the form &quot;disk:folder:filename&quot;. 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 &quot;QuickBASIC For Apple Macintosh: Language Reference&quot; manual.

Code Example 1

OPEN FOR OUTPUT never gives you a &quot;Can't Find: &quot; dialog prompt (regardless of QuickBASIC's &quot;Disable File Not Found Dialog&quot; option): NewFile$ = FILES$(0, &quot;Name the new file:&quot;) 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 &quot;Disable File Not Found Dialog&quot; option: NewFile$ = FILES$(0, &quot;Name the new file&quot;) 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 &quot;Disable File Not Found Dialog&quot; option ' before running this program in QuickBASIC (interpreter or ' compiler). Works as is in earlier BASICs for Macintosh. NewFile$ = FILES$(0, &quot;Name the new file&quot;) OPEN NewFile$ AS #1   ' Opens new file for random access. ' Write to the file here if you wish. CLOSE END

Additional query words: MQuickB

Keywords: KB40714

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.