Dela via


String Length Declaration for Visual Basic 6.0 Users

Visual Basic 2008 updates string length declaration for interoperability with the common language runtime.

Visual Basic 6.0

In Visual Basic 6.0, you can specify the length of a string in its declaration. This causes the string to have a fixed length, as in the following example:

Dim Name As String * 30 

Visual Basic 2005

In Visual Basic 2008, you cannot declare a string to have a fixed length unless you use the VBFixedStringAttribute Class attribute in the declaration. The code in the preceding example causes an error.

You declare a string without a length. When your code assigns a value to the string, the length of the value determines the length of the string, as in the following example:

Dim Name AsString' ... 
Name = "Name is now 30 characters long" ' Length can be changed later. 

See Also

Concepts

Attributes Used in Visual Basic

Programming Element Support Changes Summary

Reference

String Data Type (Visual Basic)

Dim Statement (Visual Basic)