Jump to content

How to declare a multidimensional array, dynamically?


Mison
 Share

Recommended Posts

Hi all, I have a question. How to declare an array with multiple array dimension,dynamically? My current implementation is:

#include <Array.au3>

$Array = ArrayCreate(2,2)
_ArrayDisplay($Array)

Func ArrayCreate($dim1=0, $dim2=0, $dim3=0, $dim4=0)
    Local $tempArray[1]
    Switch @NumParams
    Case 1
        ReDim $tempArray [$dim1]
    Case 2
        ReDim $tempArray [$dim1][$dim2]
    Case 3
        ReDim $tempArray [$dim1][$dim2][$dim3]
    Case 4
        ReDim $tempArray [$dim1][$dim2][$dim3][$dim4]
    EndSwitch
    Return $tempArray
EndFunc

And it works pretty well, but could be very long, as the number of dimensions increased. Is there any better way to do it? I'm thinking something like Eval() or Execute(), but they didn't work.

Hi ;)

Link to comment
Share on other sites

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...