Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: passing array as parameter to a subroutine problem

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Singapore
    Posts
    77
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I met the case that array parameter passing failed.
    My testing code is as following:
    Option Base 1
    Sub test(ParamArray array1() As Variant)
    MsgBox "Ubound(array1) is " & UBound(array1)
    End Sub

    Sub main()
    Dim array2(2) As String
    array2(1) = "ABC"
    array2(2) = "BCD"
    MsgBox "Ubound(array2) is " & UBound(array2())
    test(array2)
    End Sub

    I run subroutine main. The result is that:
    Ubound(array2) is 2
    Ubound(array1) is 0

    Seems that array2 is not passed to subroutine test.
    Could you help me with it?
    Regards
    XJ

  2. #2
    New Member
    Join Date
    May 2002
    Location
    Western Australia
    Posts
    25
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    It works this way..

    Sub test(array1() As String)
    MsgBox "Ubound(array1) is " & UBound(array1)
    End Sub

    Sub main()
    Dim array2(2) As String
    array2(1) = "ABC"
    array2(2) = "BCD"
    MsgBox "Ubound(array2) is " & UBound(array2())
    Call test(array2)
    End Sub

    Regards, Trevor

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Singapore
    Posts
    77
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thx
    Regards
    XJ

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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