Microsoft KB Archive/45451
Article ID: 45451
Article Last Modified on 11/21/2006
- 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
This article was previously published under Q45451
The CLEAR statement in a QuickBasic program turns off error handling routines. Any error that happens after a CLEAR statement is not trapped by an error handling routine that was initiated before the CLEAR statement. To trap errors after a CLEAR statement, you must reinstate the error handling routine with a new ON ERROR GOTO clause.
This applies to Microsoft QuickBasic Versions 3.00, 4.00, 4.00b, and 4.50, and Microsoft Basic Compiler Versions 6.00, 6.00b for MS-DOS and MS OS/2, and Microsoft Basic PDS 7.00 for MS-DOS and MS OS/2.
The following two programs show an error trapping routine that does not work correctly and an error trapping routine that does work:
REM This error handling routine will not trap the error. ON ERROR GOTO Handler CLEAR REM The ERROR handling routine is now turned off ERROR 1 END Handler: Print "In the ERROR Handler" RESUME
The output for this program is only an error message from QuickBasic.
REM This ERROR Handling routine will trap the error. ON ERROR GOTO Handler CLEAR REM The ERROR Handling routine is now turned off. ON ERROR GOTO Handler REM The ERROR Handling routine is now turned back on. ERROR 1 END Handler : Print "In the ERROR Handler" RESUME
The output for this program is as follows:
In the ERROR Handler
Additional query words: QuickBas BasicCom