+ Reply to Thread
Results 1 to 5 of 5

Passing an array as argument for custom Function

  1. #1
    Guest

    Passing an array as argument for custom Function

    I am trying to find out how to pass an array as an
    argument for a custom function.
    I have an array colors(1 to 10) and I want to pass the
    whole array into a custom fundtion so I can use the array
    within the function.

    Thanks.

  2. #2
    Dion
    Guest

    RE: Passing an array as argument for custom Function

    Use the ParamArray keyword
    Function zzz(ParamArray myarr())

    "[email protected]" wrote:

    > I am trying to find out how to pass an array as an
    > argument for a custom function.
    > I have an array colors(1 to 10) and I want to pass the
    > whole array into a custom fundtion so I can use the array
    > within the function.
    >
    > Thanks.
    >


  3. #3
    Guest

    RE: Passing an array as argument for custom Function

    And how do I enter the argument when I use the function.
    Can I just do:

    zzz(colors())

    >-----Original Message-----
    >Use the ParamArray keyword
    >Function zzz(ParamArray myarr())
    >
    >"[email protected]" wrote:
    >
    >> I am trying to find out how to pass an array as an
    >> argument for a custom function.
    >> I have an array colors(1 to 10) and I want to pass the
    >> whole array into a custom fundtion so I can use the

    array
    >> within the function.
    >>
    >> Thanks.
    >>

    >.
    >


  4. #4
    Dion
    Guest

    RE: Passing an array as argument for custom Function

    I'm pretty sure you would just pass the name: zzz(colors)

    "[email protected]" wrote:

    > And how do I enter the argument when I use the function.
    > Can I just do:
    >
    > zzz(colors())
    >
    > >-----Original Message-----
    > >Use the ParamArray keyword
    > >Function zzz(ParamArray myarr())
    > >
    > >"[email protected]" wrote:
    > >
    > >> I am trying to find out how to pass an array as an
    > >> argument for a custom function.
    > >> I have an array colors(1 to 10) and I want to pass the
    > >> whole array into a custom fundtion so I can use the

    > array
    > >> within the function.
    > >>
    > >> Thanks.
    > >>

    > >.
    > >

    >


  5. #5
    Guest

    RE: Passing an array as argument for custom Function

    When I do that, it seems to only pass the first item in
    the array.
    For example, lets say I have the following function and
    procedure:

    Sub test()
    Dim colors(1 To 10) As Integer

    For i = 1 To 10
    colors(i) = i + 10
    Next i
    zzz(colors)
    End Sub

    Function zzz(ParamArray myarr() As Variant)
    Range("B1") = myarr(1)
    End Function

    When I use myarr(0) in the zzz function, it works fine,
    but when I try to use myarr(1), I get a "Subscript out of
    range" message.

    >-----Original Message-----
    >I'm pretty sure you would just pass the name: zzz(colors)
    >
    >"[email protected]" wrote:
    >
    >> And how do I enter the argument when I use the function.
    >> Can I just do:
    >>
    >> zzz(colors())
    >>
    >> >-----Original Message-----
    >> >Use the ParamArray keyword
    >> >Function zzz(ParamArray myarr())
    >> >
    >> >"[email protected]" wrote:
    >> >
    >> >> I am trying to find out how to pass an array as an
    >> >> argument for a custom function.
    >> >> I have an array colors(1 to 10) and I want to pass

    the
    >> >> whole array into a custom fundtion so I can use the

    >> array
    >> >> within the function.
    >> >>
    >> >> Thanks.
    >> >>
    >> >.
    >> >

    >>

    >.
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1