Sign in to follow this  
Followers 0
Mison

How to declare a multidimensional array, dynamically?

4 posts in this topic

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 ;)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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 ...
 

Share this post


Link to post
Share on other sites

Thanks MvGulik. Just as I thought.

Would you mind if I use your code for my future project? Credit will be given, of course. :D


Hi ;)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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 ...
 

Share this post


Link to post
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
Sign in to follow this  
Followers 0