Pop -17, Purpose, Syntax – Rockwell Automation 1746-BAS BASIC LANGUAGE User Manual

Page 113: Example

Advertising
background image

Publication 1746-RM001A-US-P

Execution Control and Interrupt Support Functions 8-17

POP

Purpose

Use the POP statement to remove values from the module argument stack. The
value at the top of the argument stack is assigned to the variable following the POP
statement and the argument stack is POPped (example: incremented by 6). You
can place values in the stack using the PUSH statement.

You can pop more than one variable off the argument stack using a single POP
statement with multiple variables ([var], [var],.[var]). Each expression must be
followed by a comma.

Syntax

POP [var], [var],.......[var]

Example

See the PUSH statement.

You can use the PUSH and POP statements to minimize GLOBAL variable
problems. These are caused by the main program and all main program
subroutines using the same variable names (example: GLOBAL VARIABLES). If
you cannot use the same variables in a subroutine as in the main program, you can
re-assign a number of variables (example: A-Q) before a GOSUB statement is
executed.

If you reserve some variable names just for subroutines (S1, S2) and pass variables
on the stack as shown in the previous example, you can avoid any GLOBAL
variable problems in the module.

The PUSH and POP statements accept dimensioned variables A(4) and S1(12) as
well as scalar variables. This is useful when using CALL routines in which large
amounts of data must be PUSHed or POPped, as shown below.

>1

REM EXAMPLE PROGRAM

>40 FOR I=1 TO 64

>50 PUSH I

>60 CALL 10

>70 POP A(I)

>80 NEXT I

IMPORTANT

If a POP statement executes and no number is in the argument
stack, an A-Stack error occurs and the module enters Command
mode.

Advertising