On-gosub – Rockwell Automation 1771-DB BASIC MODULE User Manual

Page 176

Advertising
background image

Chapter
Statements

11

11 -24

Use the ON-GOSUB statement to transfer control to the line(s) you
specified with the GOSUB statement (page 11 -13) when the value of the
expression following the ON statement is encountered in the BASIC
program.

All comments that apply to GOSUB apply to the ON statement. If the expr
after the ON is less than zero an

ERROR: BAD ARGUMENT

message is

generated. If the expr after the ON is greater than the line number list
following the GOSUB statement, an

ERROR: BAD SYNTAX

message is

generated. The ON-GOSUB statement provides conditional branching
options within the BASIC module program.

Important: Excessive nesting exceeds the limits of the control stack,
generating an error, and causing the module to enter Command mode.
For more information see control stack, page 8 -1.

Syntax

ON

expr GOSUB ln num, ln num,...ln num

Example

>1 REM EXAMPLE PROGRAM

>10 ON Q GOSUB 100,200,300

If Q is equal to 0, control is transferred to line number 100. If Q is equal to
1, control is transferred to line number 200. If Q is equal to 2, control is
transferred to line number 300, and so on.

ON-GOSUB

Advertising