Unlike VB, VBScript does not support the OPTIONAL keyword, so you cannot set up a function to conditionally accept parameters. There are some kludges though, such as:
- pass in a delimited string, with required parameters first, e.g.:
<% function test(foobar) foos = split(foobar,",") response.write foos(0) if ubound(foos)>0 then response.write foos(1) end function test("1,2") test("1") %> |
- pass in empty strings or other token values that tell the sub or function to ignore that value, e.g.:
<% function test(foo,bar) response.write foo if bar <> "" then response.write bar end function test("1","2") test("1","") %> |
JScript, on the other hand, allows you to pass optional arguments, as demonstrated in the following code snippet:
<script language=JScript RUNAT=SERVER> function test(foo,bar) { Response.Write(foo); Response.Write(bar); } test('1','2'); test('1'); </script> |