snomy Posted November 21, 2007 Share Posted November 21, 2007 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!!!!!!!!!!!! Link to comment Share on other sites More sharing options...
SadBunny Posted November 21, 2007 Share Posted November 21, 2007 (edited) 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. 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... Edited November 21, 2007 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
BrettF Posted November 21, 2007 Share Posted November 21, 2007 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) Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now