Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted (edited)

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

   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

Edited by PlausiblyDamp
  • *Experts*
Posted

If VB.NET is like C#, you'll have to set each array inside the struct to a valid array, maybe something like this:

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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...