Funtion taking n number of args

mmb

Active member
Joined
Aug 1, 2004
Messages
42
Programming Experience
1-3
Do anybody know how can a Function can take n number of arguments.

Help required.
Bye
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
use the optional keyword such as

VB.NET:
 friend function MyFunction(optional byval MyInt As integer = 1, optional byval OtherInt As integer = 2) as integer
 'do stuff
 end function
 

mmb

Active member
Joined
Aug 1, 2004
Messages
42
Programming Experience
1-3
Sir JuggaloBrotha,

The code u have written above is still accepting maximum 2 args and minimum zero args.
I want that the arguments of a Function to be set at run time.

Is this possible?
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
i'm just curious as to why you would need to at run time set the number of arguements for a function

and overloading/optional are the only way i know of to change the number of arguements, but you cant do that at runtime either
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
If all the arguments are of the same type, you could use an array or arraylist.

I'm also curious as to what you're trying to accomplish. You often get a better answer if you give some background about the question :).
 

mmb

Active member
Joined
Aug 1, 2004
Messages
42
Programming Experience
1-3
I have made a generic class for making DataGrid Functionality(Load,Insert,Update,delete).

In one of the functions of the class ,tables name is to be passed. Table can be one or it can be 5 or so on. For this the number of args of the function should be dynamic.

If there s any way out here do let me know.
 

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
Like Paszt said use an array/list. You could also use a delimiter string, but there wouldn't really be any difference.
 
Top Bottom