|
-
Nov 11th, 2000, 10:50 PM
#1
Thread Starter
Addicted Member
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"
-
Nov 12th, 2000, 12:07 AM
#2
if ismissing(sstring) then sstring = "HI"
-
Nov 12th, 2000, 03:00 AM
#3
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
-
Nov 12th, 2000, 11:31 AM
#4
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.
-
Nov 12th, 2000, 11:55 AM
#5
transcendental analytic
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.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 12th, 2000, 07:32 PM
#6
Thread Starter
Addicted Member
Thanks everyone but I think pvb provided what I need.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|