Setting an inital value in an Array in a Structure

  • Thread starter Thread starter Lance
  • Start date Start date
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
 
Nevermind. Adding

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

before

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

solved it
 
Back
Top