-
How can I make sString default to "HI" if that argument is ommited? The only way I can think of right now is placing this in the TryThis sub.
if sString = "" then sString = "HI"
Code:
Private Sub TryThis(Optional sString as String)
if sString = "" then sString = "HI"
-
if ismissing(sstring) then sstring = "HI"
-
IsMissing only works on optional Variant arguments. The way you have your code, all you have to do is add = "defaultvalue" to the arg declaration as follows:
Code:
Private Sub TryThis(Optional sString As String = "HI")
'sString now defaults to "HI" if no value is passed.
End Sub
-
It's a good habit to set default values, rather than use IsMissing. It's more organized and you don't have to worry about Variants.
-
Many Vb functions reads variants to allow the user to pass many different datatypes. It's not very effective but on the other hand it's userfriendly. Depends how you want it.
-
Thanks everyone but I think pvb provided what I need.