Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am trying to create a structure that contains an arraylist of another structure. As far as I know an arraylist can be a member of a structure and an arraylist can contain any object, including another structure... so I don't know what the problem is. The compiler is stopping on

 

results.elementArray.Add(elementInfo)

 

and saying:

"An unhandled exception of type 'System.NullReferenceException' occurred in application.exe

 

Additional information: Object reference not set to an instance of an object."

 

I think it is upset about elementArray. Can anyone offer any advice? Here is the code:

 

Module ModuleParse
   Structure elementStruct
       Public name As String
       Public clinicalLow As Decimal
       Public clinicalHigh As Decimal
       Public value As String
   End Structure

   Structure resultsStruct
       Public patientID As String
       Public lastName As String
       Public firstName As String
       Public gender As String
       Public birthdate As String
       Public weight As String
       Public bloodType As String
       Public dateDrawn As String
       Public elementArray As ArrayList
   End Structure

   Function parseResults(ByRef results As resultsStruct)
       Dim elementInfo As elementStruct
       results.patientID = "123456"

       elementInfo.name = "Nitrogen"
       elementInfo.clinicalLow = 44
       elementInfo.clinicalHigh = 51.7

       results.elementArray.Add(elementInfo)

       Return results
   End Function
End Module

 

Thanks!

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...