473,395 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Array Function

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
Nov 19 '05 #1
3 1076
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.

"Rock" <ro********@yahoo.com> wrote in message
news:OC**************@TK2MSFTNGP14.phx.gbl...
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

Nov 19 '05 #2
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.

"Rock" <ro********@yahoo.com> wrote in message
news:OC**************@TK2MSFTNGP14.phx.gbl...
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

Nov 19 '05 #3
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.

"Rock" <ro********@yahoo.com> wrote in message
news:OC**************@TK2MSFTNGP14.phx.gbl...
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

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
11
by: deko | last post by:
I need to create a basic one-dimensional array of strings, but I don't know how many strings I'm going to have until the code is finished looping. pseudo code: Dim astrMyArray() Do While Not...
8
by: Tweaxor | last post by:
Hey, I was trying to figure out was it possible in C to pass the values in an array from one function to another function. Is the possible in C? ex. y is the array that holds seven values If...
6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
4
by: assgar | last post by:
Hi Seasons Greetings Its back, I am being haunted. I thought I had resolved this problem but I am intermittently the receving the warnings below. This code consist of a 1) HTML form, 2)...
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
7
by: bowlderster | last post by:
Hello,all. I want to get the array size in a function, and the array is an argument of the function. I try the following code. /*************************************** */ #include<stdio.h>...
9
by: =?Utf-8?B?RGFya21hbg==?= | last post by:
Hi, I am wondering how you multi-dimension an array function? My declared function looks like this: Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long, ByVal Val3 As...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.