Sign in to follow this  
Followers 0
AcidCorps

Combining Arrays into Multi-Dimension

3 posts in this topic

#1 ·  Posted (edited)

I'm trying to get the hang of Multi-Dimension arrays but not having much luck

I have 3 Arrays which I'd like to combine into a single Multi-Dimension array, they all contain the same amount of elements if that makes a difference

Edited by AcidCorps

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm trying to get the hang of Multi-Dimension arrays but not having much luck

I have 3 Arrays which I'd like to combine into a single Multi-Dimension array, they all contain the same amount of elements if that makes a difference

#Include <Array.au3>
Dim $Array0[3], $Array1[3], $Array2[3]
;Value = array.element
;Array0
$Array0[0] = "0.0"
$Array0[1] = "0.1"
$Array0[2] = "0.2"

;Array1
$Array1[0] = "1.0"
$Array1[1] = "1.1"
$Array1[2] = "1.2"

;Array2
$Array2[0] = "2.0"
$Array2[1] = "2.1"
$Array2[2] = "2.2"

Dim $Combo [3][3]
For $y = 0 to 2
     $Combo[0][$y] = $Array0[$y]
Next
For $y = 0 to 2
     $Combo[1][$y] = $Array1[$y]
Next
For $y = 0 to 2
     $Combo[2][$y] = $Array2[$y]
Next
_ArrayDisplay($Combo, "Combined Arrays")

Just one example.

Edited by Paulie

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I'm trying to get the hang of Multi-Dimension arrays but not having much luck

I have 3 Arrays which I'd like to combine into a single Multi-Dimension array, they all contain the same amount of elements if that makes a difference

Paulie's example works fine, and they don't have to be the same number of elements. You could just use Ubound() to find the longest one and use that for your new array's number of rows. Depending on how much logic you want to code into it, you could put together arrays with different numbers of dimensions too, because Ubound($avArray, 0) can be used to determine the number of subscripts (dimensions) and adjust the output accordingly.

If you're going to do a lot of this, it would be better to code a generic function to append the scripts together.

<_<

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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