|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Reurning ArraysI 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
Show quote
Hide quote
"HardySpicer" <gyansor***@gmail.com> schrieb How do you return the array from the function?> 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? Armin 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. -- Show quoteHide quoteTerry "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 > 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
Multithreading dilemma
Advice Required - Vb or Not VB (or even .NET) Weird bug Trouble with sendkey TAB Saving an image from a picturebox Please vote for rendering bug (loss of AlphaChannel) for ico-files! Parallel Post Acess Server Explorer - VS 2005 Building GUIs with VB.Net (from a VB.Net beginner) Passing a ColorPalette as an argument |
|||||||||||||||||||||||