Gw Basic On Error
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.
or using joysticks). Syntax: ON event specifier GOSUB line number Comments: The syntax shown sets up an event trap line number for the specified event. A line number of 0 disables trapping for this event. Once trap line numbers have been set, event trapping http://www.antonis.de/qbebooks/gwbasman/oncomn.html itself can be controlled with the following syntax lines: event specifier ON When an event is ON, and a nonzero line number is specified for the trap, then every time BASIC starts a new statement, it checks to see if the specified event has occurred. If it has, BASIC performs a GOSUB to the line specified in the ON statement. event specifier OFF When an event is OFF, no trapping occurs and the event is not remembered, even if it occurs. event on error specifier STOP When an event is stopped, no trapping can occur, but if the event happens, it is remembered so an immediate trap occurs when an event specifier ON is executed. When a trap is made for a particular event, the trap automatically causes a stop on that event, so recursive traps can never take place. The return from the trap routine automatically does an ON unless an explicit OFF has been performed inside the trap routine. When an error trap takes place, on error goto this automatically disables all trapping. Trapping will never take place when BASIC is not executing a program. The following are valid values for event specifier: COM(n) n is the number of the COM channel (1 or 2). KEY(n) n is a function key number 1-20. 1 through 10 are the function keys F1 through F10. 11 through 14 are the cursor control keys as follows: 11= CURSOR UP 13= CURSOR RIGHT 12= CURSOR LEFT 14= CURSOR DOWN 15-20 are user-defined keys. PEN Since there is only one pen, no number is given. PLAY(n) n is an integer expression in the range of 1-32. Values outside this range result in "Illegal function call" errors. STRIG(n) n is 0, 2, 4 or 6. (0=trigger A1; 4=trigger A2; 2=trigger B1; 6=trigger B2). TIMER(n) n is a numeric expression within the range of 1 to 86,400. A value outside of this range results in an "Illegal function call" error. RETURN line number This optional form of RETURN is primarily intended for use with event trapping. The event-trapping routine may want to go back into the GW-BASIC program at a fixed line number while still eliminating the GOSUB entry that the trap created. Use of the nonlocal RETURN must be done with care. Any other GOSUB, WHILE, or FOR that was active at the time of the trap remains active. If the trap comes out of a subroutine, any attempt to continue loops outside the subroutine results in a "