The old 2d Array chestnut

Recommended Posts

hi

lets say i want to create a 2d array, such as this:

test1, apple

test2, banana

test3, cherry

i know the array size beforehand is [2][3].

i want to then extract each row item and print it to the screen in a msgbox say....

1st time: test1

2nd time: apple

3rd time: test2

4th: banana

etc etc.....

so i need two bits of help here, one is how to create the array, which i have done here, please check and comment:

Dim \$arGrid[\$i][\$j] = [["test1", "test2", "test3"], ["apple", "banana", "cherry"]]

then i need the while loop (i presume to extract in the method as above)

can you help? or point me to some good information to understand the 2d array? thanks!!!!!!!!!!!!

Share on other sites

I wrote a quick example for you:

```Dim \$arGrid[2][3] = [["test1", "test2", "test3"], ["apple", "banana", "cherry"]]

; show all columns per row:
For \$x = 0 To UBound(\$arGrid,1)-1; <-- dimension 1
For \$y = 0 To UBound(\$arGrid,2)-1; <-- dimension 2
MsgBox(0,"Array element "&\$x&","&\$y,\$arGrid[\$x][\$y])
Next
Next

; show all rows per column:
For \$y = 0 To UBound(\$arGrid,2)-1; <-- dimension 2
For \$x = 0 To UBound(\$arGrid,1)-1; <-- dimension 1
MsgBox(0,"Array element "&\$x&","&\$y,\$arGrid[\$x][\$y])
Next
Next```
/edit: fixed dimension comments in second part :">

Note the difference between the two parts. The latter seems to be what you mean, though reorganizing your array in 3x2 and using the first type seems more intuitive for your example.

test1 - test2 - test3

apple - banana - cherry

My suggestion:

test1 - apple

test2 - banana

test3 - cherry

But this ofcourse all depends on the actual data you were going to organize...

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share on other sites

Edited you example...

```Dim \$arGrid[2][3] = [["test1", "test2", "test3"], ["apple", "banana", "cherry"]]
\$msg = ""
; show all rows per column:
For \$y = 0 To UBound(\$arGrid,2)-1; <-- dimension 2
For \$x = 0 To UBound(\$arGrid,1)-1; <-- dimension 1
\$msg &= "["&\$x&"]["&\$y&"] = " & \$arGrid[\$x][\$y] & @CRLF
Next
Next
MsgBox (0, "", \$msg)```

Create an account

Register a new account