Connecting Tech Pros Worldwide Help | Site Map

Object referense not set to instance error

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 20th, 2005, 02:26 AM
Stephen
Guest
 
Posts: n/a
Default Object referense not set to instance error

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.



  #2  
Old November 20th, 2005, 02:26 AM
Brian
Guest
 
Posts: n/a
Default 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]


  #3  
Old November 20th, 2005, 02:26 AM
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
Default 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>
  #4  
Old November 20th, 2005, 02:27 AM
Fergus Cooney
Guest
 
Posts: n/a
Default 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


  #5  
Old November 20th, 2005, 02:27 AM
Stephen
Guest
 
Posts: n/a
Default 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]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.