Consulting

Results 1 to 9 of 9

Thread: Solved: Multidimensional Array

  1. #1
    VBAX Mentor asingh's Avatar
    Joined
    Jul 2005
    Posts
    307
    Location

    Solved: Multidimensional Array

    Hi,

    How do I declare a multidimensional array [2--way] in VBA..??

    thanks..

    asingh

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Depends upon how you want to populate it.

    You can dimension it in the declaration

    [vba]
    Dim ary(1 To 3, 1 To 5)
    [/vba]

    or just declare it as variant and redim later

    [vba]
    Dim ary

    ReDim ary(1 To 3, 1 To 5)
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    You can also declare it as a specific datatype in the Dim statement, or declare as a variant and then specify the type in the Redim. You cannot however declare an array as one type in the Dim statement and then change type in the Redim.
    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    Or you could define a UDT then declare an array as that (saves memory)
    2+2=9 ... (My Arithmetic Is Mental)

  5. #5
    Currently just for interests sake, what's a UDT?

  6. #6
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    It's a User Defined Type. And while you could do that, I don't know why you would in most cases.
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Nor I. They are a good idea that has been badly implemented, so personally I avoid them. I would use a class over a UDT every time.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Likewise, though I believe the VB.Net and VB 2005 implementation of them (structures) is much better.
    Regards,
    Rory

    Microsoft MVP - Excel

  9. #9
    VBAX Mentor asingh's Avatar
    Joined
    Jul 2005
    Posts
    307
    Location
    thanks...all...!

    regards, asingh

Posting Permissions

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