As their name implies, fixed-length strings have a pre-defined length, and any attempt to assign a string longer than the defined length will result in truncation. If you assign a string (a string constant, or a dynamic or ASCIIZ string variable) to a fixed-length string that is shorter than the defined length, the string will be padded on the right with spaces. The major difference between dynamic strings and fixed-length strings is that once defined, the length of a fixed-length string cannot be changed. It is "fixed" for the duration of program execution.
You declare fixed-length string variables using the STRING * x format with the DIM statement. For example:
DIM MyStr AS STRING * 10
Although fixed-length strings were provided mainly to allow you to define string fields within a User-Defined Type or Union, they can also be used wherever other string values are valid.
Unlike dynamic strings, the length of fixed-length strings is determined
at compile-time, not run-time. In addition, unlike dynamic (variable-length)
strings, fixed-length strings do not use handles. When you pass
a fixed-length string to a
A declaration of a fixed-length string or fixed-length string pointer must explicitly state the length of the variable, because the compiler must know it to allocate memory, and to pad the variable with spaces upon assignment.
The address of the contents of a fixed length string can always be obtained with the VARPTR function. LOCAL fixed-length string memory is released when the associated Sub or Function ends. Subsequent calls to the Sub or Function will result in new storage locations for the fixed-length string data; however, the location of a LOCAL fixed-length string does not move until the string memory is released when the Sub/Function terminates.
LOCAL fixed-length strings are created on the stack frame, so LOCAL fixed-length strings will be limited to the amount of available stack space available. Typically this is less than 1 Mb unless a larger stack frame has been allocated with #STACK metastatement. If larger fixed-length (or ASCIIZ) strings are required, it is advisable to make them STATIC or GLOBAL since those are not created within the stack frame.
The address of the contents of STATIC and GLOBAL fixed-length strings stays constant for the duration of the module. STATIC and GLOBAL Scalar (non-array) fixed-length strings may be up to 16,777,216 bytes each.
See Also
Dynamic (Variable-length) strings ($)