Sign in to follow this  
Followers 0
RickB75

Simple 2d array question

3 posts in this topic

I'm drawing a blank here. I know how to do this overly simple thing but for the life of me, I can't get it to work correctly. I want to create a 2d array and then do a loop and using _arrayadd, add data to it in the correct columns. 

My example script

#include <Array.au3>


Local $aBlank[1][1]


For $i = 0 To 10 -1

    $colzero = "aa"& $i
    $colone = "bb" & $i

_ArrayAdd($aBlank,$colzero)
_ArrayAdd($aBlank,$colone,1)

Next

_ArrayDisplay($aBlank)

Why can't I get  the 2nd Arrayadd to work correctly???  I know this is something simple that I'm overlooking but right now I can't see the forest for the trees :) 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

_ArrayAdd is just going to add another row to a 2d array.  Looking at the parameters you can add values to the columns using a delimiter in the $sValue parameter.

Quote

_ArrayAdd ( ByRef $aArray, $vValue [, $iStart = 0 [, $sDelim_Item = "|" [, $sDelim_Row = @CRLF [, $iForce = $ARRAYFILL_FORCE_DEFAULT]]]] )

#include <Array.au3>

Local $aBlank[1][2]

For $i = 0 To 10 - 1
    Local $sValue = "aa" & $i & "|" & "bb" & $i

    _ArrayAdd($aBlank, $sValue)
Next

_ArrayDisplay($aBlank)

Also, the main reason why yours didn't add to the column is because you declared the array with only 1 column.

Edited by InunoTaishou

Share this post


Link to post
Share on other sites

Bingo!!! Thank you @InunoTaishou for your help. Thats exactly what I was looking for.  Great explanation also. I was thinking [0][0] was to start at zero in both columns. I completly forgot that [1] was telling it where to start at in the array and [2] is how many columns I want. 

 

Thank you!!!! 

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