
Question on the Function Argument List
I had an example I forgot to include (duh!)...
tstFunct 1,2,3
tstFunct 1,null,null
tstFunct 1,2,null
tstFunct null,2,null
tstFunct 1,null,3
tstFunct 1,empty,empty
tstFunct 1,2,empty
tstFunct empty,2,empty
tstFunct 1,empty,3
Function tstFunct (Var1, Var2, Var3)
msgbox typename(var1) & " " _
& typename(var2) & " " _
& typename(var3) & vbcrlf _
& IsNull(var1) & " " _
& IsNull(var2) & " " _
& IsNull(var3) & vbcrlf _
& IsEmpty(var1) & " " _
& IsEmpty(var2) & " " _
& IsEmpty(var3)
if isnull(var2) then
var2 = "some default"
msgbox "ver2 defaulted to " & var2
end if
End Function
So any argument that tests as IsNull or IsEmpty (depending on which convention you adopt) would be assigned a default value locally (within the function).
--
Michael Harris
You can use an array with empty or null elements for "optional" arguments (as Thomas pointed out) or you can simply pass empty/null "placeholder" values, but you still have to account for all of the arguments.
As of the current version of VBScript (5.0), the necessary Optional keyword and IsMissing() function aren't supported to get true optional arguments. Nor is the (somewhat related) ParamArray keyword). Maybe (hint, hint,..) on a future release?
--
Michael Harris
Is it possible to make some variables being passed to a function through an
argument list to be optional?
For Example here is the function
Function tstFunct (Var1, Var2, Var3)
'Manipulate Variables
End Function
I keep getting errors when I try and call the function by passing only the
first variable.
tstFunct Var1
I realize that it would not be possible to have Var2 optional and make Var3
Required. I would though like to make Var2 and Var3 optional.
Any Ideas?