Microsoft KB Archive/58214
Article ID: 58214
Article Last Modified on 8/16/2005
- Microsoft QuickBasic 4.0
- Microsoft QuickBASIC 4.0b
- Microsoft QuickBasic 4.5 for MS-DOS
- Microsoft BASIC Compiler 6.0
- Microsoft BASIC Compiler 6.0b
- Microsoft BASIC Professional Development System 7.0
- Microsoft BASIC Professional Development System 7.1
- Microsoft GW-BASIC 3.2
- Microsoft GW-BASIC 3.22
- Microsoft GW-BASIC 3.23
This article was previously published under Q58214
The FILES "filespec" statement prints the names of the files residing on the specified disk. However, the manual doesn't mention that if the "filespec" parameter does not describe any current filenames, an error 53 ("File Not Found") is returned. Unless this error is trapped, program execution is halted.
When a FILES statement is used to list the files in a specific directory and the pattern that FILES is searching for does not exist, an error 53 ("File Not Found") is returned.
If the error is not trapped by the program, the error message "File Not Found" is displayed in the interpreter environment. In executable programs, the message displayed is "File Not Found In Module [Filename] at SEG:OFF," where SEG:OFF represents the segment and the offset from that segment of code where the error happened.
To avoid halting the program, the program needs only to trap the error 53 that is returned to the program. The program examples below demonstrate this, assuming that a file named ABC.XYZ does not exist on the root directory of drive C.
Example for Compiled Basics -- BASPROG.BAS
ON ERROR GOTO ErrorHandle FILES "c:\abc.xyz" END ErrorHandle: IF ERR = 53 THEN PRINT "Error 53 was trapped. File not found." RESUME NEXT
You can compile and link BASPROG.BAS as follows in QuickBasic 4.00, 4.00b, or 4.50, Basic compiler 6.00 or 6.00b, or Basic PDS 7.00:
BC /x Basprog; LINK Basprog;
Use QB /x Basprog in QuickBasic Versions 2.00, 2.01, 3.00.
Use BASCOM /x Basprog in QuickBasic Versions 1.00, 1.01, 1.02.
Example for GW-Basic Interpreter
10 ON ERROR GOTO 999 20 FILES "c:\abc.xyz" 30 END 999 IF ERR = 53 THEN PRINT "Error 53 was trapped. File not found." 1000 RESUME NEXT
Additional query words: QuickBas BasicCom