On Error Goto Statement In Gwbasic
Contents |
direct mode errors, (for
On Error Goto -1 Vba Excel
example, syntax errors) cause GW-BASIC to branch to "on error goto -1" the line in the program which begins the specified error-handling subroutine. GW-BASIC branches to the line specified by the ON ERROR statement until a RESUME statement is found. If line number does not exist, an "Undefined line" error results. To disable error trapping, execute the following statement: ON ERROR GOTO 0 Subsequent errors print an error message and halt execution. An ON ERROR GOTO 0 statement in an error-trapping subroutine causes GW-BASIC to stop and print the error message for the error that caused the trap. It is recommended that all error-trapping subroutines execute an ON ERROR GOTO 0 if an error is encountered for which there is no recovery action. If an error occurs during execution of an error-handling subroutine, the GW-BASIC error message is printed and execution terminated. Error trapping does not occur within the error-handling subroutine. Examples: 10 ON ERROR GOTO 1000 . . . 1000 A=ERR: B=ERL 1010 PRINT A, B 1020 RESUME NEXT Line 1010 prints the type and location of the error on the screen (see the ERR and ERL variables). Line 1020 causes program execution to continue with the line following the error.
where execution is to resume: SyntaxResult RESUME or RESUME 0 Execution resumes at http://www.antonis.de/qbebooks/gwbasman/onerror.html the statement that caused an error. RESUME NEXT Execution resumes at the statement immediately following the one that caused an error. RESUME line number Execution http://www.antonis.de/qbebooks/gwbasman/resume.html resumes at the specified line number. A RESUME statement that is not in an error trapping routine causes a "RESUME without error" message to be printed. Examples: 10 ON ERROR GOTO 900 . . . 900 IF (ERR=230) AND (ERL=90) THEN PRINT "TRY AGAIN": RESUME 80 . . . If an error occurs after line 10 is executed, the action indicated in line 900 is taken and the program continues at line 80.
the http://pages.intnet.mu/jhbpage/Program/Qbasic/tutorial/Ch8d.htm instruction after the "label1" label until the value of variable "x" is equal to 5. Code Output DIM x AS INTEGER x = 0 label1: x = x + 1 PRINT x IF x on error < 5 THEN GOTO label1 END IF 1 2 3 4 5 You should advoid using the GOTO statement wherever possible. Programmers who used GW-BASIC, the predecessor of qbasic, used to put a lot of GOTO on error goto statements, branching in every directions, in their programs, thus making it difficult to maintain. It was called spaghetti codes. The above program is simpler to write if you use the DO LOOP statement instead. The same as above using the DO - LOOP 'This program displays a sentence 5 times CLS DIM x AS INTEGER x = 0 DO PRINT x x = x + 1 LOOP UNTIL x = 5 However, in some cases, there are no alternatives. The GOTO statement is used in conjunction with the ON ERROR statement which is used to trap errors in your program. [ Previous Index Next ] pages viewed since January 19 2002
be down. Please try the request again. Your cache administrator is webmaster. Generated Sun, 23 Oct 2016 13:27:26 GMT by s_wx1196 (squid/3.5.20)