VBS does not enable optional parameters with function declaration.
The function declaration in VBS looks like :
[Public | Private] Function name [(arglist)]
[statements]
[name = expression]
[Exit Function]
[statements]
[name = expression]
End Function
The arglist argument has the following syntax and parts:
[ByVal | ByRef] varname[( )]
Function declaration in JScript looks like :
function functionname([argument1 [, argument2 [, ...argumentn]]])
{
statements
}
Where argument1...argumentn are optional, comma-separated list of arguments the function understands. JScript has special array variable called 'arguments'. The variable can retrieve any of the function argument.
arguments[0] ... first argument of the function
arguments[1] ... second argument of the function, etc.
So you can use JScript to do the work :
function sprintf(Templ){
var C = 1;
var Pos = Templ.indexOf("%s");
while(Pos>=0){
Templ = Templ.substr(0, Pos) + arguments[C++] + Templ.substr(Pos+2)
Pos = Templ.indexOf("%s")
}
return Templ;
};
Then you can call the function :
If Err<>0 Then
Response.Write sprintf("The Function raises error %s (%s).", Err.Number, Err.Description)
End If
| |