Connecting Tech Pros Worldwide Forums | Help | Site Map

Object referense not set to instance error

Stephen
Guest
 
Posts: n/a
#1: Nov 20 '05
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.



Brian
Guest
 
Posts: n/a
#2: Nov 20 '05

re: Object referense not set to instance error


Did you use NEW to declare your array list? Your code worked perfectly when
I tried it.

Dim tColors as New ArrayList()





"Stephen" <graybeal@bellatlantic.net> wrote in message
news:%23pUKZQWiDHA.2380@tk2msftngp13.phx.gbl...[color=blue]
> 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??[/color]
It[color=blue]
> is clearly defined right above.
>
>[/color]


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#3: Nov 20 '05

re: Object referense not set to instance error


"Stephen" <graybeal@bellatlantic.net> scripsit:[color=blue]
> 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.[/color]

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

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Fergus Cooney
Guest
 
Posts: n/a
#4: Nov 20 '05

re: Object referense not set to instance error


Hi Stephen,

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

You've eliminated str.

;-)

Regards,
Fergus


Stephen
Guest
 
Posts: n/a
#5: Nov 20 '05

re: Object referense not set to instance error


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.

"Brian" <nospam@prairie.lakes.com> wrote in message
news:vnpuuo2bjeih94@corp.supernews.com...[color=blue]
> Did you use NEW to declare your array list? Your code worked perfectly[/color]
when[color=blue]
> I tried it.
>
> Dim tColors as New ArrayList()
>
>
>
>
>
> "Stephen" <graybeal@bellatlantic.net> wrote in message
> news:%23pUKZQWiDHA.2380@tk2msftngp13.phx.gbl...[color=green]
> > I hate this error and usually can find a way to fix it but this one has[/color][/color]
me[color=blue][color=green]
> > 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??[/color]
> It[color=green]
> > is clearly defined right above.
> >
> >[/color]
>
>[/color]


Closed Thread