Johnny
asked on
assigning default value if not passed to public sub
i have a sub that sends an email i want to know how to assing a value to it if its not pased ie
Public Sub SendEmail(ByVal Mail_To As String)
oMsg.To = Mail_To ' ' if Mail_To is null/empty then use pern@dragonsworkshop.com
.......
the suib works fine if i pass it but i want to not HAVE to pass a few values
thx
Johnny
aka Pern
Public Sub SendEmail(ByVal Mail_To As String)
oMsg.To = Mail_To ' ' if Mail_To is null/empty then use pern@dragonsworkshop.com
.......
the suib works fine if i pass it but i want to not HAVE to pass a few values
thx
Johnny
aka Pern
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or you can force the function to take only non null parameter value as the following
Public Sub SendEmail(ByVal Mail_To As String)
If IsNothing( Mail_To ) Then
Throw New ArgumentNullException( "Mail_To" )
End If
oMsg.To = Mail_To
.......
And overload the function, like so
Public Sub SendEmail()
SendEmail( "pern@dragonsworkshop.com" )
End Sub
This is C# style :o)
Public Sub SendEmail(ByVal Mail_To As String)
If IsNothing( Mail_To ) Then
Throw New ArgumentNullException( "Mail_To" )
End If
oMsg.To = Mail_To
.......
And overload the function, like so
Public Sub SendEmail()
SendEmail( "pern@dragonsworkshop.com"
End Sub
This is C# style :o)
ASKER
Thanks thats what i was looking for
Public Sub SendEmail(Optional ByVal Mail_To As String = "pern@dragonsworkshop.com"
End Sub
Any parameters that follow Mail_To must also be declared as Optional as well.
~IM