Limitation of parameters in functions

BravoTwoZero
09-11-2003, 05:04 AM
Hi,

I am just wondering, is any visual basic functions has a limitation of parameters you can pass.

For example:

Private CreateReport(ByVal ID, bayval tID .......) as boolean

.. The Code

end function

Thanks

gundavarapu
09-11-2003, 05:22 AM
I think its 225/255 (not sure)

but if you use ParamArray, then you can have upto 32767 parameters

BravoTwoZero
09-11-2003, 05:29 AM
Thank you Gundavarapu. That was very helpful. I have just passed 60 parameter and after that each time I tried to send another parameter my code is becoming red!!! Any thoughts on that???

gundavarapu
09-11-2003, 06:01 AM
So 60 is the limit :). But you can use paramarray.

But, it is not advisable to have that many paramaters in a single sub. you can always break it into sub modules :)

BravoTwoZero
09-11-2003, 07:08 AM
I do need to pass all this parameter because this sub function creating html page. So I need to display all.

reboot
09-11-2003, 07:27 AM
That's pretty bad design....

BravoTwoZero
09-11-2003, 07:33 AM
I know... but lession has been learned and I can assure that that won't be happening again....can you suggest how could I improve this code? displaying all the parameter?

passel
09-11-2003, 08:51 AM
I know... but lession has been learned and I can assure that that won't be happening again....can you suggest how could I improve this code? displaying all the parameter?

Start dividing your related parameters into groups. Define a user defined type (udt) for each group. Create variables of those types,
pack them with the data, and pass them to the sub/function.

Of course, depending on how your program is structure, and how
many areas this function could be called from, it would make just as
much sense to define all the "parameters" in the declarations area of a
.bas module, along with the function, and just set the "parameters" data, and then call the function. In this case, the data is just "public"
data visible and modifiable by all the code, which is usually considered
not the best design either, but then you wouldn't be passing any data
as parameters, but "passing" it through the use of shared variables.

Unfortunately, this adds a lot of code everywhere in order to set the
data, before calling the sub/function.

You could use a hybrid solution. You could have the data defined as
private in the .bas module, and provide two or more subs to set the
data. In this case, you would divide the parameters up, and put some
in the first call, the others in the second call (and expand the number
of subs as required).

Let's assume they would all fit in two sub calls.
The first call would populate (cache) it's parameters in the local private
data. The second call would do the work, using parameters passed to it,
and "parameters" from the local "cached" data.

Not good designs, but should be workable to get around your present
situation.

BravoTwoZero
09-11-2003, 09:04 AM
Thank you Passel for your recommendations. I am originally a vb developer and the company I worked for previously sometime work doesnot involved much vb and again my current company involved with VB a lot. It just on and off situation. I am just coming back to VB slowly and I have got very good several visual basic books in my home library. I intent to use them fully and just need to refresh my memory.

Cheers

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum