Sign in to follow this  
Followers 0
jorgepr13

Declaring multi dimentional arrays

8 posts in this topic

#1 ·  Posted (edited)

Is there is a way to do this

$arr[2][2] = [[1, 2], [3, 4]]

but something like this?

$arr[2][2]
$arr[0][2]=[1,2]
$arr[1][2]=[3,4]

because declaring it like this may take a lot of space

$arr[2][2]
$arr[0][0]=1
$arr[0][1]=2
$arr[1][0]=3
$arr[1][1]=4

in the case that you don't want to have all the declarations in the same place that it may look messy and may confuse not knowing in what dimension you are

Edited by jorgepr13

Share this post


Link to post
Share on other sites



No, you can't do it the way you described above.

But if you want to fill the array with ascending numbers (1,2,3,4,5...) you can do it in a loop.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can always do array in arrays, kind of array^2, rather than 2d array

#include <Array.au3>
Dim $aArray1[2] = [1,2]
Dim $aArray2[2] = [3,4]
Dim $aHouser[2] = [$aArray1,$aArray2]
For $i = 0 To UBound ( $aHouser ) - 1
   $currentArray = $aHouser[$i]
   _ArrayDisplay ( $currentArray )
Next

This has the advantage of only needing to know the 1 level of dimensions, as well

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

the ascending/descending numbers are just for example

(sorry if I post it in the wrong place, I found other post with the same title here)

Share this post


Link to post
Share on other sites

Be aware that the Array-in-Array-solution isn't recommended for performance reasons as you can read here at the end of the page.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You can always do array in arrays, kind of array^2, rather than 2d array

#include <Array.au3>
Dim $aArray1[2] = [1,2]
Dim $aArray2[2] = [3,4]
Dim $aHouser[2] = [$aArray1,$aArray2]
For $i = 0 To UBound ( $aHouser ) - 1
$currentArray = $aHouser[$i]
_ArrayDisplay ( $currentArray )
Next

This has the advantage of only needing to know the 1 level of dimensions, as well

will it work for differentiated dimensions?

$arr[4][2]
$arr[0][2]=[1,2]
$arr[1][2]=[3,4]
$arr[2][2]=[1,4]
$arr[3][2]=[5,10]
Edited by jorgepr13

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

do whatever you want, but syntax must look like:

#include <Array.au3>
Dim $aArray1[2] = [1,2]
Dim $aArray2[2] = [3,4]
Dim $aArray3[2] = ["a","b"]
Dim $aArray4[3] = [3,4,5]
Dim $aArray5[2] = [9,10]

Dim $aHouser[5] = [$aArray1,$aArray2,$aArray3,$aArray4,$aArray5]
For $i = 0 To UBound ( $aHouser ) - 1
$currentArray = $aHouser[$i]
_ArrayDisplay ( $currentArray )
Next

edit: for your specific question, i'm thinking no :)

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

You can use the line continuation character ("_") to split long lines, example:

#include <Array.au3>

Local $arr[2][2] = [[1, 2], _
                    [3, 4]]

_ArrayDisplay($arr)
Edited by AdmiralAlkex

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