Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to declare optional arguments in a function in VBScript?

Status
Not open for further replies.

maggiezhao

Programmer
Jan 11, 2003
3
US
The following syntax is wrong, is there anyone know how
to define a function with optioanl arguments and
default arguments?

Function f(str1, optional str2)

End Function

 
You could include the 2 variables and then test for the existence of data in the one you want to be optional. A null value will have to be passed to the optional variable if you don't want to use it. If you include a variable in your function call, you have to fill it with something.

Example:

Dim WshShell
Set WshShell = CreateObject("wscript.shell")
test "try this",null 'try putting a number in place of the null

Function test(opt1, opt2)
If isnull(opt2) Then
MsgBox opt1
Else
Wshshell.Popup opt1,opt2,"Popup"
End if
End function

Dana Hallenbeck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top