PC Review


Reply
Thread Tools Rate Thread

Arraylist and Structure why am I getting an error Tia sal

 
 
sal
Guest
Posts: n/a
 
      23rd Nov 2004
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
 
Reply With Quote
 
 
 
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      23rd Nov 2004
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


"sal" <(E-Mail Removed)> wrote in message
news:Xns95AAB11E089salsppnet@216.77.188.18...
> 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



 
Reply With Quote
 
sal
Guest
Posts: n/a
 
      23rd Nov 2004
Thanks that fixed it..I'm glad it was something simple
:-)

"Jay B. Harlow [MVP - Outlook]" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> 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
>
>
> "sal" <(E-Mail Removed)> wrote in message
> news:Xns95AAB11E089salsppnet@216.77.188.18...
>> 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

>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Arraylist IndexOf Structure ray@Mississauga.Canada Microsoft ASP .NET 0 18th Feb 2010 03:15 PM
structure and arraylist mm Microsoft VB .NET 6 5th Dec 2005 12:03 AM
Update Element in ArrayList Structure wg Microsoft VB .NET 8 26th Jun 2005 04:58 PM
How do I use an arraylist and a structure together? RBCC Microsoft VB .NET 3 8th Feb 2004 04:32 PM
Changing a Structure that's in an ArrayList Adam Microsoft VB .NET 7 6th Feb 2004 10:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:41 PM.