"Can't Find File" OPENing New QuickBASIC Random or APPEND File (33052)
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 "Disable File Not Found Dialog"
option. This option also works correctly in the interpreter part of
QuickBASIC if you select the "Disable File Not Found Dialog" box in
the Options... item (from QuickBASIC's Run menu) before running the
program.
Otherwise, to create a random file and avoid the "Can't Find: <file>"
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:
"Can't find: <file>. Would you like to look for it?"
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 "File not Found"
(or error number 74 "Unknown Volume" 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
"Disable File Not Found Dialog" option in the Options... from the Run
menu.
You may disable the "Can't Find: <file>" processing by selecting the
"Disable File Not Found Dialog" option in the Options... from the
QuickBASIC Run menu. If this option is selected, then a run-time error
53, "File Not Found", 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 "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
Modification Type: |
Minor |
Last Reviewed: |
1/8/2003 |
Keywords: |
KB33052 |
|