Variables – Rockwell Automation 1771-DB BASIC MODULE User Manual

Page 112

Advertising
background image

Chapter
Expressions, Variables and Operators

9

9 -2

Variables may represent either numeric values or strings. Numeric values
are floating point variables and do not require a type declaration.
Strings are string variable types and do require a type declaration.
The type declaration character for string is $. Variable names:

Must be no more than 8 characters long.

Must have a unique first and last character when the variable length is

the same. (For example, the BASIC module reads “cat” and “cot” as the
same variable name. However, “cat” and “cod” are unique and so are
“cat” and “chant”.)

Can include letters, numbers and a decimal point.

Cannot be a reserved word.

Can include special type declaration characters ($ for string)

A variable can be a letter followed by a:

single-dimension expression (ex.

G(A+6)

)

number followed by a single-dimension expression (ex.

G2(A+6)

)

number or letter (ex.

G1

or

GA

) except for these combinations:

CR, DO, IE, IF, IP, ON, PI, SP, TO, UI, UO

Important: Embedded reserved words cannot be used as variable names
(ex. FORT, PRINTER, LENGTH).

Variables that include a single-dimension expression expr are called
dimensioned or arrayed variables (ex.

J(4), G(A+6)

). Variables that

contain a letter or a letter and a number are called scalar variables (ex.

AA,

A1

) . Any variables entered in lower case are changed to upper case.

The BASIC module allocates variables in a static manner, meaning the first
time a variable is used, the BASIC module allocates a portion of memory
(8 bytes) specifically for that variable. You cannot de-allocate this
memory on a variable to variable basis. For example, if you execute a
statement, you cannot tell the BASIC module that the variable no longer
exists to free up the 8 bytes of memory that belong to that variable.
You can clear the memory allocated to variables with a CLEAR statement
(page 11 -2). The CLEAR statement frees all memory allocated to
variables. Variables may be set aside for reuse to save memory.

Important: The BASIC module requires less time to find a scalar variable
because there is not an expression to evaluate. To run a program as fast as
possible, use dimensioned variables only when necessary. Use scalar
variables for intermediate variables and assign the final result to a
dimensioned variable. Also, put the most frequently used variables first.
Variables defined first require the least amount of time to locate.

Variables

Advertising