Results 1 to 7 of 7

Thread: Sending Parameters to a sub

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    156

    Arrow

    Is it possible that a sub or a function could handle
    an UNKNOWEN number of parameters .

    like this :

    Call quest(parameter1,parameter2,parameter3,parameter4...)


    private sub quest(???????????????????)

    end sub

    I know that it could be done on C ,using pointers and stuf.
    The MORE I get to know,
    I realize that I know NOTHING !

  2. #2
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    You can send a subroutine an array with an unknown amount of elements

    Code:
    Sub GetArray(Test() as String)
      Dim L as Integer
      For L=Lbound(Test) to Ubound(Test)
        Debug.Print Test(L)
      Next L
    End Sub
    
    'Then call it like this...
    
    Dim ArrayName(12) as String
    GetArray ArrayName()
    Andrew Empson
    vb6(ent) SP4

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    156

    Unhappy well,as far as i know..



    12 is a knoen number ,what would happen if the COM user
    will send 13 parameters ?
    The MORE I get to know,
    I realize that I know NOTHING !

  4. #4
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    Sorry, I just used 12 as an example. It could be 200 if you wanted.
    Andrew Empson
    vb6(ent) SP4

  5. #5
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    You Can Do it but all the arguments have to be variants, use the paramarray keyword, like this

    Code:
    Public Sub MyFunction(ParamArray Arguments())
    Dim i As Integer
    For i = LBound(Arguments) To UBound(Arguments)
        MsgBox Arguments(i)
    Next i
    End Sub
    then you can

    Code:
    MyFunction  "Have", "As", "Many", "Arguments", "As", "You", "Want"

  6. #6
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    Thanks Sam. You learn something new every day.
    Andrew Empson
    vb6(ent) SP4

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    156

    Smile cool

    Very helpfull, this is what i was looking for .
    The MORE I get to know,
    I realize that I know NOTHING !

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