Home All Groups Group Topic Archive Search About
Author
23 Nov 2007 6:24 PM
HardySpicer
I have a function which returns an array of strings. I want to display
say the zeroth element and I do

mystring = myarrayofstrings(0)

which is it happy with. However, when i compile it complains twith
this error

System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."

Then it says to use the new keyword to create an object instance!

What does that all mean?

Hardy

Author
23 Nov 2007 6:57 PM
Armin Zingler
Show quote Hide quote
"HardySpicer" <gyansor***@gmail.com> schrieb
> I have a function which returns an array of strings. I want to
> display say the zeroth element and I do
>
> mystring = myarrayofstrings(0)
>
> which is it happy with. However, when i compile it complains twith
> this error
>
> System.NullReferenceException was unhandled
>  Message="Object reference not set to an instance of an object."
>
> Then it says to use the new keyword to create an object instance!
>
> What does that all mean?


How do you return the array from the function?


Armin
Author
23 Nov 2007 7:10 PM
Terry
You say when you compile.... You mean when you run it?

It means that either myarrayofstrings or myarrayofstrings(0) is 'Nothing'. 
Better check the function.  Remember that myarrayofstrings and
myarrayofstrings(0) are 'pointers'.  This is the error you get when you try
to use a null reference.
--
Terry


Show quoteHide quote
"HardySpicer" wrote:

> I have a function which returns an array of strings. I want to display
> say the zeroth element and I do
>
> mystring = myarrayofstrings(0)
>
> which is it happy with. However, when i compile it complains twith
> this error
>
> System.NullReferenceException was unhandled
>   Message="Object reference not set to an instance of an object."
>
> Then it says to use the new keyword to create an object instance!
>
> What does that all mean?
>
> Hardy
>
Author
24 Nov 2007 10:10 AM
Michel Posseth [MCP]
You should investigate your myarrayofstrings function as it is obviously not
returning a valid array of strings during runtime

also make sure you have
option strict on  and option explicit on   this will tackle most of the
common problems like these

example :

dim MyArr () as string

msgbox   (Myarr(0))

the above wil compile fine when option strict is off but will throw an error
during runtime

HTH

Michel



Show quoteHide quote
"HardySpicer" <gyansor***@gmail.com> schreef in bericht
news:e49fedd7-088e-4eee-aa38-a1fa4e27e39b@i29g2000prf.googlegroups.com...
>I have a function which returns an array of strings. I want to display
> say the zeroth element and I do
>
> mystring = myarrayofstrings(0)
>
> which is it happy with. However, when i compile it complains twith
> this error
>
> System.NullReferenceException was unhandled
>  Message="Object reference not set to an instance of an object."
>
> Then it says to use the new keyword to create an object instance!
>
> What does that all mean?
>
> Hardy