Arrays declared as structure members cannot be declared with an initial size

An array in a structure is declared with an initial size. You cannot initialize any structure element, and declaring an array size is one form of initialization.

Error ID: BC31043

To correct this error

  1. Define the array in your structure as dynamic (no initial size).

  2. If you require a certain size of array, you can redimension a dynamic array with a ReDim Statement (Visual Basic) when your code is running. The following example illustrates this.

    Structure demoStruct
        Public demoArray() As Integer
    End Structure
    Sub useStruct()
        Dim struct As demoStruct
        ReDim struct.demoArray(9)
        Struct.demoArray(2) = 777
    End Sub
    

See Also

Tasks

How to: Declare a Structure (Visual Basic)

Other Resources

Arrays in Visual Basic