CLEAR Resets ON ERROR GOTO and Turns Off Error Trapping (45451)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0

This article was previously published under Q45451

SUMMARY

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.

MORE INFORMATION

The following two programs show an error trapping routine that does not work correctly and an error trapping routine that does work:

Program 1

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.

Program 2

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


Modification Type:MinorLast Reviewed:1/8/2003
Keywords:KB45451