Object referense not set to instance error

  • Thread starter Thread starter Stephen
  • Start date Start date
S

Stephen

I hate this error and usually can find a way to fix it but this one has me
stumped

tColors is an ArrayList

At first I had this:

tColors.Add(ColorsTextBox.Text)

Now I have this:

Dim str As String
str = ColorsTextBox.Text
tColors.Add(str)

Neither one works and both give me the "Object reference not set to an
instance of an object" error. How is str NOT an instance of an object?? It
is clearly defined right above.
 
Did you use NEW to declare your array list? Your code worked perfectly when
I tried it.

Dim tColors as New ArrayList()
 
Stephen said:
tColors is an ArrayList

At first I had this:

tColors.Add(ColorsTextBox.Text)

Now I have this:

Dim str As String
str = ColorsTextBox.Text
tColors.Add(str)

Neither one works and both give me the "Object reference not set to an
instance of an object" error. How is str NOT an instance of an object?? It
is clearly defined right above.

I think the problem is that 'ColorsTextBox' is pointing to 'Nothing'.
Where do you use this code?
 
Hi Stephen,

Sherlock Holmes:
When you have eliminated the impossible,
whatever remains - however improbable -
<must> be the truth.

You've eliminated str.

;-)

Regards,
Fergus
 
I don't know why, but that worked. I've been programming in VB for years
and never really understood the difference between a declaration with and
without New.

Thanks.
 
Back
Top