String – Rockwell Automation 1771-DB BASIC MODULE User Manual

Page 189

Advertising
background image

Chapter
Statements

11

11 -37

Use the STRING statement to allocate memory for strings.
Initially, memory is not 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 in the STRING statement is the total
number of bytes you want to allocate for string storage. The second
expression 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.

You can only use one STRING statement in your program to allocate
memory for all the strings you want to use in your program.
When allocating memory for strings remember that the STRING statement
itself has one overhead byte. As well, remember that BASIC uses one
overhead byte per string declared within the STRING statement.
The additional character for each string is allocated for the carriage return
character that terminates the string. For example, the statement STRING
100,10 allocates enough memory for nine 10-byte 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 BASIC module.

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 (ex.
NEW, page 10 -10) and statements (ex. CLEAR, page 11 -2) 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.

STRING

Advertising