+ Reply to Thread
Results 1 to 6 of 6

Excel vba - passing a 3-dimensional array to a subroutine

  1. #1

    Excel vba - passing a 3-dimensional array to a subroutine

    Hello,

    I'm having trouble getting the syntax right for passing a 3-dimensional
    array to a subroutine.
    The array in question in originally defined as
    dim variable() as single

    Later...

    ReDim variable(x,y,z) (through a series of For statements)

    and later still....

    Subroutine is called (subroutine needs a specific component of array)
    A function would work for me as well.

    Hope someone can help...

    joran6


  2. #2
    Zack Barresse
    Guest

    Re: Excel vba - passing a 3-dimensional array to a subroutine

    Hi joran6,

    Try dimming the variable as "Dim Variable" instead and leave it as a Variant
    type.

    --
    Regards,
    Zack Barresse, aka firefytr
    To email, remove NOSPAM



    <[email protected]> wrote in message
    news:[email protected]...
    > Hello,
    >
    > I'm having trouble getting the syntax right for passing a 3-dimensional
    > array to a subroutine.
    > The array in question in originally defined as
    > dim variable() as single
    >
    > Later...
    >
    > ReDim variable(x,y,z) (through a series of For statements)
    >
    > and later still....
    >
    > Subroutine is called (subroutine needs a specific component of array)
    > A function would work for me as well.
    >
    > Hope someone can help...
    >
    > joran6
    >




  3. #3

    Re: Excel vba - passing a 3-dimensional array to a subroutine

    as shown, the variable is defined as
    dim variable as single


  4. #4
    Zack Barresse
    Guest

    Re: Excel vba - passing a 3-dimensional array to a subroutine

    Did you try the Variant like I showed? You could also try posting all of
    your code.

    --
    Regards,
    Zack Barresse, aka firefytr
    To email, remove NOSPAM


    <[email protected]> wrote in message
    news:[email protected]...
    > as shown, the variable is defined as
    > dim variable as single
    >




  5. #5
    Tom Ogilvy
    Guest

    Re: Excel vba - passing a 3-dimensional array to a subroutine

    Sub Main()
    Dim variable() As Single

    x = 10
    y = 3
    z = 3
    ReDim variable(1 To x, 1 To y, 1 To z)
    For i = 1 To x
    For j = 1 To y
    For k = 1 To z
    variable(i, j, k) = i * j * k * Rnd()
    Next k, j, i
    Dummy variable
    End Sub

    Sub Dummy(v() As Single)
    MsgBox v(UBound(v, 1), UBound(v, 2), _
    UBound(v, 3))
    End Sub


    works fine for me as an illustration. What do you mean by needs a component?

    --
    Regards,
    Tom Ogilvy

    "[email protected]" wrote:

    > as shown, the variable is defined as
    > dim variable as single
    >
    >


  6. #6

    Re: Excel vba - passing a 3-dimensional array to a subroutine

    Thanks, Tom!

    You've shown me everything I needed.


+ 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