In Visual Basic 6.0, all members of a user-defined type (UDT) were initialized when they were declared inside the Type statement block.
In Visual Basic .NET, user-defined types are replaced by structures. Members that require parameterless constructors (such as fixed-length strings, fixed-size arrays, and variables declared with the New keyword) require initialization. During upgrade, an Initialize() subroutine is added to the structure. Calls to the Initialize subroutine must be added whenever the structure is declared.
When an array of structures is declared or redimensioned, the Initialize() subroutine has to be called for each element of the array, or some members of the structures will not be initialized as they were in Visual Basic 6.0.
What to do next
- Add a call to the Initialize() subroutine wherever the array is declared or redimensioned:
' After upgrade to Visual Basic .NET
Private Structure MyStruct
Dim MyClass1 As Class1
' UPGRADE_TODO: "Initialize" must be called to initialize instances of this structure.
Public Sub Initialize()
MyClass1 = New Class1
End Sub
End Structure
Private Structure StructArray
Dim MyArray As MyStruct
' UPGRADE_TODO: "Initialize" must be called to initialize instances of this structure.
Public Sub Initialize()
MyArray.Initialize
End Sub
End Structure
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
' UPGRADE_WARNING: Array MyStructArray may need to have individual elements initialized.
Dim MyStructArray(1) as StructArray
MyStructArray(0).MyArray.Initialize()
MyStructArray(1).MyArray.Initialize()
End Sub
See Also
Initialize must be called to initialize instances of this structure