Array Function

  • Thread starter Thread starter Rock
  • Start date Start date
R

Rock

I am getting an error: "Object reference not set to an instance of an
object." when trying to use a function that returns an array list. Can I
not do this, how would I set the instance of a public function???

I have a global function FieldArray in Class 1:

Public Function FieldArray(s1, s2) as arraylist
FieldArray.Add(s1)
FieldArray.Add(s2)
End function

which I call from my form:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim arrFields as new ArrayList
Dim cls as new Class1
arrFields = cls.FieldArray(str1, str2)

End Sub
 
As far as I can tell you are just recursively calling the same function. VB
will let you call functions without the paren there necessarily.
 
You're referencing "FieldArray" in your function, and for the life of me, I
can't see where you've created it. Perhaps it is Nothing?

In addition, a Function returns a value. Yours doesn't. That should take
care of the next question you would be posting.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
You're both right: I ended up keeping the function as type arraylist, but
creating an internal array, adding the values to that, then returning the
internal array.

Thanks.
 
Back
Top