contents   index   previous   next



Fixed-length strings

 

Visual Basic also allows the creation of fixed-length strings. These strings resemble Fortran strings in that the maximum number of characters they can hold is pre-determined at compile time. Also, Visual Basic's fixed-length strings are padded with trailing spaces. The similarities, however, end here. Visual Basic's fixed-length strings are still BStrings; they have a header indicating the length of the string (including any trailing spaces), and are null-terminated.

 

To declare a fixed length string, you use Visual Basic's Dim statement, indicating the maximum length of the string:

 

Dim MyStr as String*9

 

If you assign a string with less than nine characters, MyStr is padded with enough trailing spaces to total nine characters. For example,

 

MyStr="Example"

 

results in the string represented in Figure 1.7. If you assign a string that is too long, Visual Basic truncates the characters to the size of the declared variable.