Results 1 to 6 of 6

Thread: Optional

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    247
    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"
    Mako Shark
    Great White

  2. #2
    Guest
    if ismissing(sstring) then sstring = "HI"

  3. #3
    Guest
    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

  4. #4
    Guest
    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.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    247
    Thanks everyone but I think pvb provided what I need.
    Mako Shark
    Great White

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width