Results 1 to 5 of 5

Thread: Dynamic Array

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2016
    Posts
    46

    Dynamic Array

    Hi

    How to create Dynamic array which can have multiple rows & columns

    Thanks

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Dynamic Array

    ??
    Code:
    Dim MyArray() As Long
    
    ReDim MyArray(0 To 10, 0 To 20)
    Note: Any further Redim's are only possible on the last dimension
    Code:
    Dim MyArray() As Long
    ReDim MyArray(0 To 10, 0 To 20)
    ReDim MyArray(0 To 20, 0 To 40) 'Fails!
    ReDim MyArray(0 To 10, 0 To 20, 0 To 30) 'Fails!
    ReDim MyArray(0 To 10, 0 To 40) 'Works!
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Dynamic Array

    Code:
        Dim ar() As Byte
        
        'Create 2 dimensional dynamic array
        ReDim ar(0 To 10, 0 To 10)
        
        ar(2, 2) = 40
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Dynamic Array

    Quote Originally Posted by Zvoni View Post
    Note: Any further Redim's are only possible on the last dimension
    Code:
    Dim MyArray() As Long
    ReDim MyArray(0 To 10, 0 To 20)
    ReDim MyArray(0 To 20, 0 To 40) 'Fails!
    ReDim MyArray(0 To 10, 0 To 20, 0 To 30) 'Fails!
    ReDim MyArray(0 To 10, 0 To 40) 'Works!
    All of that works fine for me. It's only when you use the Preserve keyword that you're limited. A straight-up ReDim totally reinitializes the array.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Dynamic Array

    Really?
    Didn‘t know that, or didn‘t remember anymore.
    been a long time now…..
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

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