Rockwell Automation 57C610 Enhanced Basic Language, AutoMax User Manual
Page 50

6Ć10
line_number_1 through line_number_N =
line numbers to which control is
transferred depending on the
evaluated expression
The line numbers always correspond to the value of the expression.
If the expression evaluates to 1, control is transferred to
line_number_1. If the expression evaluates to 2, control is
transferred to line_number_2, and so on to line_number_N.
There is no corresponding line number for zero (0). Fractional
numbers are truncated to an integer value.
For example, if A%=5, the result of the integer expression A%/3
would truncate from 1 2/3 to a value of 1. If there is no
corresponding line number, the next sequential statement after the
ON GOTO is executed.
The following are valid ON GOTO statements:
20 ON A% GO TO 100, 200, 300, 400
20 ON ((A%) -5)GOTO 100, 205, 300,515
6.4.3
GOSUB, ON GOSUB, and RETURN Statements
(Subroutines)
A subroutine is a block of statements that performs an operation
and returns control of the program to the point from which it came.
Including a subroutine in a program allows you to repeat a
sequence of statements in several places without writing the same
statements several times.
In BASIC, you can include more than one subroutine in the same
program. Subroutines are easier to locate and edit if they are
located together, usually near the end of the program.
The first line of a subroutine can be any legal BASIC statement,
including a remark statement. You can nest subroutines (one
subroutine within another) up to the point that memory becomes
insufficient to keep the return information for the subroutines.
The GOSUB statement has the following format:
GOSUB line_number
where:
line_number =
line number of the entry point in the subroutine;
can be an integer constant or integer
expression.
If the result of the expression value does not match a line number in
the task, execution falls through to the next sequential statement
after the GOSUB. No error is reported.
When BASIC executes the GOSUB statement, it stores internally the
location of the next sequential statement after the GOSUB and
transfers control to the line specified. BASIC executes the subroutine
until it encounters a RETURN statement, which causes BASIC to
transfer control back to the statement immediately following the
calling GOSUB statement. A subroutine called by a GOSUB must
exit by a RETURN statement.
The RETURN statement has the following format:
RETURN