Rockwell Automation 57C610 Enhanced Basic Language, AutoMax User Manual

Page 51

Advertising
background image

6Ć11

When BASIC executes a GOSUB, it stores the return location of the

statement following a GOSUB.
Each time a GOSUB is executed, BASIC stores another location.

Each time a RETURN is executed,BASIC retrieves the last location

and transfers control to it. In this way, no matter how many

subroutines there are or how many times they are called, BASIC

always knows where to transfer control.

100 IF MOTOR_SPEED%<JOG_SPEED% THEN 80

110 GOSUB 200

120...

130...

140...

.

.

.

200 ! THIS IS A COMMENT

210 MOTOR_SPEED%=MOTOR_SPEED%+(GAIN%/2)

.

.

.

290 RETURN

The ON GOSUB statement has the following format:

ON integer_expression GOSUB line number_1,...,line number_N

where:

integer_expression =

any arithmetic expression that results in an

integer value

line_number_1,..., line_number_N =

line numbers to which control is transferred

depending on the evaluated expression

Line numbers always correspond to the value of the expression. The

value 1 transfers control to the first line number listed. The value 2

transfers control to the second line number listed, etc. There is no

corresponding line number for zero (0). Fractional numbers are

truncated to an integer value. If no corresponding line number exists

for the result of the integer expression, control falls to the next

sequential statement after the ON GOSUB. When a RETURN is

executed from one of the subroutines referenced in the ON GOSUB,

it returns to the next statement after the ON GOSUB.
The following are valid ON GOSUB statements:

20 ON (A% + B% + C%) GOSUB 103,220,475,650

30 ON GAIN% GOSUB 200,300,400,500

Advertising
This manual is related to the following products: