DIM symbolname$ ( maxlength ) ' kept for
backward compatibility
or
DIM symbolname ( maxlength ) AS STRING
or
DIM symbolname ( maxlength ) AS BYTE
A STRING is a special array of BYTE terminated by a byte of 0, and
is limited to 256 characters. String operations must be limited to the
first 256 characters and there is no runtime check.
Despite the use of
the maxlength , an implicit &H0 is
added to the end of the STRING, to allow for variable length during program
execution. For this reason a &H0 may not be used within a
string.
Byte arrays can be used using an allocation as BYTE, and they may exceed 256 characters. When referring to an element of a BYTE ARRAY, you must specify which element in the array in parenthesis. If you use just the BYTE ARRAY name, the BASIC compiler will attempt to treat that as a string. BYTE ARRAYs may also contain embedded &H0 elements. But if they do, string operations can not be used. For instance a byte array of &H0, &H1, &H2 can be built as-
DIM ba(10) AS BYTE
ba(0) =
0
ba(1) =
1
ba(2) = 2
ba(3) = 3
But the following will NOT work-
ba = chr(0) + chr(1) + chr(2) + chr(3) ' fails as the first 0 terminates this string operation
But it can be done as-
ba = chr(1) + chr(1) + chr(2) +
chr(3)
ba(0) =
0
' replace the first character with a $0
STRINGs are not checked for length at run time, so care must be taken to
avoid filling it beyond the declared DIM.
Individual characters within a
string can be accessed like an array, such as astr(12) returns the character in
position 13, with the first element at offset 0.
Single character strings are a special case, and usually replaced by the byte constant representing that character. So "A" can be used interchangeably with &H41 or 63.