Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays of Structs in Structs 1

Status
Not open for further replies.

NBartomeli

Programmer
Jul 1, 2003
111
0
0
US
I am trying to create arrays of structs nested in other structs in my class, as follows:

Code:
<Serializable()> _
Public Structure clsEquityTrackerMetric
	Public Name As String
	Public Measure As String
	Public MeasureID As String
	Public MeasureType As String
	Public ThresholdHigh As Integer
	Public ThresholdLow As Integer
End Structure

<Serializable()> _
Public Structure clsEquityTrackerGroup
	Public Name As String
	Public ID As Integer
	Public SubGroup() As clsEquityTrackerSubGroup
End Structure

<Serializable()> _
Public Structure clsEquityTrackerSubGroup
	Public Name As String
	Public ID As Integer
	Public Metric() As clsEquityTrackerMetric
End Structure

My problem is when I do a statement like: "Redim Preserve subgroup.metric(+1)", on the first pass it makes an array of 2, not one. If I try to assign a value to the array in position 0 without a redim, I get a "not set to an instance of object" error.

Is there any way around this? Thanks
 
One thing to remember though - when getting the UpperBound - if you try to do this on an empty array you will still get your "not set to an instance of object" error.
 
Right JohnYingling 8P

When declaring a dynamic array I tend to think that it is empty right off the bat, and not unallocated.

Another thing that might be helpful though is to use a numeric variable to keep track of your array counts. Default it to -1 and increment when you before you redim the array, or default it to 0 and increment after the redim. If you were going to do that I would suggest putting the numeric var in the structs that declare the dynamic array.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top