In VBScript, you can't. There isn't any support for the Optional keyword in
the procedure definition. If there were, you would code something like:
Sub MySub(arg1, arg2, Optional arg3, arg4)
where arg3 and arg4 would be optional.
The best you can do in VBScript is use an array for optional arguments. the
downside is that you lose IntelliSense in VID.
Sub MySub(arg1, arg2, optionarry)
where you call it like this:
MySub(var1, "value2", array(empty,"arg4))
Example:
mysub "case1",array(empty,"c")
mysub "case2",array()
mysub "case3",array("b")
wscript.quit
sub mysub(arg1, optionarray)
if ubound(optionarray) = -1 then
msgbox arg1 & " " & "no optional args"
elseif ubound(optionarray) = 1 then
if not isempty(optionarray(0)) then
msgbox arg1 & " " & optionarray(0)
end if
if not isempty(optionarray(1)) then
msgbox arg1 & " " & optionarray(1)
end if
elseif ubound(optionarray) = 0 then
if not isempty(optionarray(0)) then
msgbox arg1 & " " & optionarray(0)
end if
end if
end sub
--
Michael Harris
I've been searching and searching but can't find it anywhere:
"How do I create a procedure that can take a variable list of arguments"
Something like:
sub dumptext( byval strText, byval blnBold)
...code...
end sub
sub dumptext( byval strText)
dumptext( strText, FALSE)
end sub
However, the above doesn't work, so how /is/ it done in VBScript?
Many thanks in advance,
Eli-Jean Leyssens