Results 1 to 2 of 2

Thread: Oh yeah here's a real question . . .

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263

    Post

    When you want to create a procedure, like a Function, and you want to be able to call that function for as many objects as you want... example:

    Code:
    Sub MySub (Str1 as String, Optional Str2 as String, Optional Str3 as String)
    How do I get the sub to have more than just two optional string variables?

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Try this:

    Option Explicit

    Sub MySub(ByVal NonOptionalString As String, ParamArray OptionalStrings() As Variant)
    Dim Count As Long
    Print "Non Optional String: " & NonOptionalString
    For Count = 0 To UBound(OptionalStrings)
    Print "Optional String " & Count + 1 & ": " & OptionalStrings(Count)
    Next
    End Sub

    Private Sub Form_Load()
    AutoRedraw = True
    Call MySub("Sample", "ABC", "DEF", "GHI", "JKL")
    End Sub


    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: [email protected]
    ICQ: 19552879



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