Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 15,324 times

Related Categories

Optional Arguments in JScript

If you truly want to be able to pass or not pass arguments arbitrarily in Active Server Pages you can revert to JScript, which allows you to pass as few or as many arguments as you like:

<%@language=JScript%>
<%
// Don't declare any arguments in the function declaration:
function SomeArgs() {
var strReturn = new String('');

// Instead, use the intrinsic arguments object to retrieve arguments.
// This loops through the arguments object appending the value of each
// to the result:

for (i=0; i<arguments.length; i++) {
strReturn += arguments[i];
}
return(strReturn);
}

// Pass whatever arguments you like:
Response.Write(SomeArgs('one' , 'two', 'three'));
Response.Write('<br>');
Response.Write(SomeArgs(1, 2, 3, 4, 5, 6, 7, 8));

// Displays this:
// onetwothree
// 12345678
%>

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • YEA!

    Posted by Zangarh on 07 Dec 2001

    This is a great way to improve your ASP coding!

    DON*T USE VBScript :)))

    /Zangarh