Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Upgrade Recommendation: Avoid Arrays and Fixed-Length Strings in User-Defined Types 

Due to changes made which allow Visual Basic 2005 arrays and structures (formerly known as user-defined types) to be fully compatible with other Visual Studio languages, fixed-length strings are no longer supported in the language. In most cases this is not a problem, because there is a compatibility class which provides fixed-length string behavior, so the code:

Dim FixedLengthString As String * 100

upgrades to the following:

Dim FixedLengthString As New VB6.FixedLengthString(100)

However, fixed-length strings do cause a problem when used in structures. The problem arises because the fixed-length string class is not automatically created when the structure is created. Likewise, fixed-size arrays are not created when the structure is created.

When your code is upgraded, user-defined types with fixed-length strings or arrays will be converted to structures and marked with a comment telling you to initialize the fixed-length string or array before referencing the structure in code. However, you can shield yourself from this modification by changing your Visual Basic 6.0 user-defined types to use strings instead of fixed-length strings, and uninitialized arrays instead of fixed-size arrays. For example:

Private Type uType
    anArray(5) As Integer
    aFixedString As String * 100
End Type
Sub SomeFunction()
    Dim aVariable As uType
End Sub

can be changed to:

Private Type uType
    anArray() As Integer
    aFixedString As String
End Type
Sub SomeFunction()
    Dim aVariable As uType
    ReDim aVariable.anArray(5) As Integer
    aVariable.aFixedString = String$(100, " ")
End Sub

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2015 Microsoft