Consulting

Results 1 to 5 of 5

Thread: I know they all are criminals(a specific datatype) But dont know how many?

  1. #1

    I know they all are criminals(a specific datatype) But dont know how many?

    How to pass a dynamic array of “strings” to a function as an argument?

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Guessing a bit here, but if you mean the number of strings you want to pass is dynamic, try ParamArray. See vba help and not that it must be the last arg and a variant.
    Sub exa()
        Call test("one")
        Call test("One", "Two")
    End Sub
        
    Function test(ParamArray MyStrings() As Variant)
    Dim i As Long
        
        For i = LBound(MyStrings) To UBound(MyStrings)
            MsgBox MyStrings(i)
        Next
    End Function
    Hope that helps,

    Mark

  3. #3
    We can't specify the datatype here. Because It will create complexities in Validations. Thank you.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Worksheet function or VBA function?

    Paul

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I think he wants to pass a dynamic array to a sub as a By Ref.
    ie.
    [vba]
    Sub SomeSub()
    Dim SomeDynamicArray as String
    MySub SomeDynamicArray
    End Sub

    Sub MySub(MyArray)
    Do Something with MyArray 'SomeDynamicArray
    End Sub
    [/vba]

Posting Permissions

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