Microsoft KB Archive/33052

= &quot;Can't Find File&quot; OPENing New QuickBASIC Random or APPEND File =

Article ID: 33052

Article Last Modified on 11/21/2006



This article was previously published under Q33052



SUMMARY
The only way for an OPEN statement to automatically create a new file opened for random access (or APPEND access) in Macintosh QuickBASIC is to compile the program with the &quot;Disable File Not Found Dialog&quot; option. This option also works correctly in the interpreter part of QuickBASIC if you select the &quot;Disable File Not Found Dialog&quot; box in the Options... item (from QuickBASIC's Run menu) before running the program.

Otherwise, to create a random file and avoid the &quot;Can't Find: &quot; dialog when opening a new file with random access (or APPEND), you must first create an empty file with an OPEN FOR OUTPUT statement (i.e., sequential access), followed by CLOSE, after which you can open the file for random access (or for APPEND). This was not a requirement in earlier versions of the BASIC compiler and interpreters for the Macintosh.



MORE INFORMATION
If an OPEN statement for a random access file or sequential (INPUT or APPEND) access file in a Macintosh QuickBASIC program cannot find a data file in the current folder, it will prompt you to look for the data file with the following statement:

&quot;Can't find:. Would you like to look for it?&quot;

You can then click OK, change to the right folder, and open the needed file. If you don't find the random or sequential file through this dialog box, the program generates an error number 53 &quot;File not Found&quot; (or error number 74 &quot;Unknown Volume&quot; if you specified an OPEN path with a disk name that is not in the system).

In earlier versions of the BASIC compiler and interpreters for the Macintosh, opening a new file for random access automatically creates the file. You can emulate this behavior in QuickBASIC by selecting the &quot;Disable File Not Found Dialog&quot; option in the Options... from the Run menu.

You may disable the &quot;Can't Find: &quot; processing by selecting the &quot;Disable File Not Found Dialog&quot; option in the Options... from the QuickBASIC Run menu. If this option is selected, then a run-time error 53, &quot;File Not Found&quot;, will directly occur on the OPEN when a file cannot be found in the current folder or with the specified full path.

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: KB33052

-

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

© Microsoft Corporation. All rights reserved.