dxt Posted September 25, 2010 Share Posted September 25, 2010 I have an array like Global $a[2][2] = [[1,2],[3,4]] and I want to pass the first element [1,2] to a function I tried f($a[0]) Func f(ByRef $ar) ConsoleWrite($ar[0] & @CR) EndFunc and it complains that $a[0] has incorrect number of subscripts. So obviously you can't do this. Is there a way to accomplish this? It is the same as trying $b = $a[0]; Link to comment Share on other sites More sharing options...
taietel Posted September 25, 2010 Share Posted September 25, 2010 Something like this?: Global $a[2][2] = [[1,2],[3,4]] f($a) Func f(ByRef $ar) For $i=0 to UBound($ar)-1 ConsoleWrite($ar[$i][0]&$ar[$i][1]&@CRLF) Next EndFunc Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 25, 2010 Share Posted September 25, 2010 The first element is $a[0][0] and it contains 1. The last element is [1][1] and it contains 4. You must provide a value for every index on every reference (two in this case). You can't reference the entire single row with $a[0] One way to display it might be: Global $aArray[2][2] = [[1,2],[3,4]] For $r = 0 To UBound($aArray) - 1 For $c = 0 To UBound($aArray, 2) - 1 ConsoleWrite("$aArray[" & $r & "][" & $c & "] = " & $aArray[$r][$c] & @LF) Next Next 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 Link to comment Share on other sites More sharing options...
dxt Posted September 25, 2010 Author Share Posted September 25, 2010 Something like this?: Global $a[2][2] = [[1,2],[3,4]] f($a) Func f(ByRef $ar) For $i=0 to UBound($ar)-1 ConsoleWrite($ar[$i][0]&$ar[$i][1]&@CRLF) Next EndFunc Ok, so I guess you can't reference a row. I guess the equivalent, but more bulky, would be f($a, 0) Func f(ByRef $ar, $index) etc ... Link to comment Share on other sites More sharing options...
czardas Posted September 25, 2010 Share Posted September 25, 2010 (edited) To add to the good advise already mentioned above: on some rare occasions it may make sense to store an entire row as a string. The string may need to be expanded, depending on what it is you need it for.Local $as_Rows[2] = ["A,B", "C,D"] ; The 2D array represented as a one dimensional array of strings. $as_SelectedRow = StringSplit($as_Rows[0], ",", 2) ; Select and split the first row. => $as_Rows[0] MsgBox(0,"", "1st row - 1st element = " & $as_SelectedRow[0] & @CRLF & "1st row - 2nd element = " & $as_SelectedRow[1])In most cases there is no benefit to doing this, however it can be a viable solution to certain types of problem. Edited September 25, 2010 by czardas operator64 ArrayWorkshop 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