Setting an inital value in an Array in a Structure

L

Lance

Hi all,

Last week a reply from Tom Shelton helped me with declaring a Structure containing an
array of a priviously defined structure like so :

/////
Public Structure GM_ProjAttrValue_t
Public mAttr As PROJATTR ' Attribute (Defined Elsewhere)
Public mValue As Double ' Attribute value
End Structure

Public Structure GM_Projection_t
Public mProjSys As PROJSYS ' Defined Elsewhere
Public mDatum As DATUM ' Defined Elsewhere
Public mUnit As UNIT ' Defined Elsewhere
Public mNumAttrs As Int32
<MarshalAs (UnmanagedType.ByValArray, SizeConst:=16)> Public mAttrList() As
GM_ProjAttrValue_t
End Structure
///////

That all works fine for reading a GM_Projection_t. But when trying to initialize one like
so

/////
Dim InitialProj As GM_Projection_t

InitialProj.mProjSys = PROJSYS.GM_PRJ_SPCS
InitialProj.mDatum = DATUM.GM_DATUM_NAD27
InitialProj.mUnit = UNIT.GM_PRJ_UNIT_US_FEET
InitialProj.mNumAttrs = 1
InitialProj.mAttrList(0).mValue = 4205
InitialProj.mAttrList(0).mAttr = PROJATTR.ZONE
/////

I get an "Object reference not set to an instance of an object" error on the line
"InitialDatum.mAttrList(0).mValue = 4205" because the mAttrList member is Nothing. How do
I properly initialize it?

Thanks,
Lance
 
L

Lance

Nevermind. Adding

/////
ReDim InitialProj.mAttrList(16)
/////

before

/////
InitialProj.mAttrList(0).mValue = 4205
InitialProj.mAttrList(0).mAttr = PROJATTR.ZONE
/////

solved it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top