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

Page 253

Advertising
background image

Publication 1746-RM001A-US-P

String Functions 15-11

STRING

Purpose

Use the STRING statement to allocate memory for strings. Initially, no memory is
allocated for strings. If you attempt to define a string with a statement such as LET
$(1)=HELLO before memory is allocated for strings, an

ERROR: MEMORY

ALLOCATION

message is generated. The first expression ([expr]) in the STRING

statement is the total number of bytes you want to allocate for string storage. The
second expression ([expr]) gives the maximum number of bytes in each string. The
second value should not be larger than 254. These two numbers determine the
total number of defined string variables.

The module requires one additional byte for each string, plus one additional byte
overall. The additional character for each string is allocated for the carriage return
character that terminates the string. This means that the statement STRING
100,10 allocates enough memory for 9 string variables, ranging from $(0) to $(8)
and all of the 100 allocated bytes are used. Note that $(0) is a valid string in the
module.

Syntax

STRING [expr], [expr]

IMPORTANT

If an ASCII null character is used within the string it acts as a
marker denoting the end of a string.

IMPORTANT

After memory is allocated for string storage, commands
(example:

NEW

) and statements (example:

CLEAR

) cannot

de-allocate this memory. Cycling power also cannot de-allocate
this memory unless battery backup is disabled. You can
de-allocate memory by executing a STRING 0,0 statement.
STRING 0,0 allocates no memory to string variables.

IMPORTANT

The module executes the equivalent of a CLEAR statement every
time the STRING [expr],[expr] statement executes. This is
necessary because string variables and numeric variables occupy
the same external memory space. After the STRING statement
executes, all variables are wiped out. Because of this, you should
perform string memory allocation early in a program (during the
first statement if possible). If you re-allocate string memory you
destroy all defined variables.

Advertising