Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

arbitrary number of arguments?

Status
Not open for further replies.

jemminger

Programmer
Jun 25, 2001
3,453
US
Hello,

Is it possible to make a vbscript function that accepts an arbitrary number of arguments?

for example, in javascript you can make a function foo():
[tt]
function foo() {
for (x = 0; x < arguments.length; x++)
alert(&quot;argument[&quot; + x + &quot;] = &quot; + arguments[x]);
}
[/tt]
and call it with any number of arguments:
[tt]
foo();
foo('a');
foo('do','re','mi');
[/tt]

is there a vbscript equivalent?

=========================================================
if (!succeed) try();
-jeff
 
I don't think you can do it but that problem can be bypassed by a trick I used before :
1) store all the params you want in a single string separating them by &quot;|&quot;, &quot;#&quot;, or any char you ar sure not to find in them.
2) store the result string
- in an hidden input if your vbs runs under html or
- in a global variable if your vbs runs alone.
3) In the beginning of your function, use the &quot;split&quot; function to separate and count the parameters you received. Water is not bad as long as it stays out human body ;-)
 
Hi Targol,

Thanks for the reply - I had the same idea just after posting this, and that's exactly how I ended up solving it.
=========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top