This documentation is archived and is not being maintained.

String Length Declaration Changes in Visual Basic

Visual Basic .NET 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 .NET

In Visual Basic .NET, 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 As String 
' ... 
Name = "Name is now 30 characters long" ' Length can be changed later. 

See Also

String Data Type | Dim Statement | Attributes Used in Visual Basic .NET | Programming Element Support Changes Summary