Arraylist and Structure why am I getting an error Tia sal

S

sal

Greetings All

I'm learning to use arraylist and structures but I'm getting a
System.NullReferenceException Error and I'm not sure why. I followed the
VB.net book all I did was change the names. See code below

Structure SppElementProperties
Dim Element As String
Dim North As String
Dim South As String
Dim Wave As String
Dim Wake As String
End Structure

Private Sub testform2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim SppElementProperties As ArrayList
Dim Spp As New SppElementProperties

Spp.Element = "Element1"
Spp.North = "North1"
Spp.South = "South1"
Spp.Wave = "Wave1"
Spp.Wake = "Wake1"
SppElementProperties.Add(Spp) 'This is the Line I get an error on
Spp.Element = "Element2"
Spp.North = "North2"
Spp.South = "South2"
Spp.Wave = "Wave2"
Spp.Wake = "Wake2"
SppElementProperties.Add(Spp)
Spp.Element = "Element3"
Spp.North = "North3"
Spp.South = "South3"
Spp.Wave = "Wave3"
Spp.Wake = "Wake3"
SppElementProperties.Add(Spp)
Dim REnum As IEnumerator
REnum = SppElementProperties.GetEnumerator
While REnum.MoveNext
MessageBox.Show(REnum.Current)
End While

End Sub

TIA
 
J

Jay B. Harlow [MVP - Outlook]

Sal
Dim SppElementProperties As ArrayList
Dim Spp As New SppElementProperties

Spp.Element = "Element1"
Spp.North = "North1"
Spp.South = "South1"
Spp.Wave = "Wave1"
Spp.Wake = "Wake1"
SppElementProperties.Add(Spp) 'This is the Line I get an error on

You never initialize the SppElementProperties variable.

Try:
Dim SppElementProperties As New ArrayList

Hope this helps
Jay
 

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