Structure with arrays - Problem writing to arrays!!! Please help!

skyyakal

Regular
Joined
Oct 3, 2003
Messages
74
STRUCTURE with arrays - Problem writing to arrays!!! Please help!

Good afternoon Gentlemen,
my problem is the following:

I coded following structure + array of that structure
Visual Basic:
    Structure CardValueStructure
        Dim Value() As Integer
        Dim Scenario_ID() As Integer
    End Structure
    Shared CardValueArray(0) As CardValueStructure

....
ReDim Preserve CardValueArray(2)
        CardValueArray(1).Value(0) = 5

The Line
CardValueArray(1).Value(0) = 5
produces an error message I never saw in my life (tons of line codes in a MsgBox-like Form showing different .dll files that went wrong or something... have no idea). Would anybody know what is wrong with this code?

Is there any other way to declare a structure with two dynamic arrays inside?

Thanks a lot for your time and statements!
skyyakal
 
Last edited by a moderator:
If VB.NET is like C#, you'll have to set each array inside the struct to a valid array, maybe something like this:
Visual Basic:
Structure CardValueStructure
    Dim Value() As Integer
    Dim Scenario_ID() As Integer
End Structure
Shared CardValueArray(0) As CardValueStructure

....
ReDim Preserve CardValueArray(2)
[b]ReDim CardValueArray(1).Value(1)[/b]
CardValueArray(1).Value(0) = 5

The change above shows a redim of the Value member of the struct. Your original code redim'd the CardValueArray variable, but each instance's Value and Scenario_ID members are still empty (undim'd) arrays. I hope my syntax is right, or that you can fix it if it's wrong :)

-Ner
 
Back
Top