sam71 Posted July 27, 2009 Share Posted July 27, 2009 I'm trying to read the line (index of a 2d array and place it into a 1d array) Any luck someone can help me on this? Thanks Link to comment Share on other sites More sharing options...
enaiman Posted July 27, 2009 Share Posted July 27, 2009 This is the way to go: Dim $array2d[10][10] Dim $array1d[10] For $i = 0 To UBound[$array2d]-1 $array1d[$i] = $array2d[$i] Next SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Richard Robertson Posted July 27, 2009 Share Posted July 27, 2009 (edited) Quick and dirty.Dim $two_d[3][2] = [[0,0],[1,1],[2,2]] Dim $one_d[6] For $i = 0 To 2 $one_d[$i * 2] = $two_d[$i][0] $one_d[$i * 2 + 1] = $two_d[$i][1] NextEdit: Hey enaiman, your method doesn't make the data index accessible. I admit that it does fit the OP vaguely asked for though. Edited July 27, 2009 by Richard Robertson Link to comment Share on other sites More sharing options...
Malkey Posted July 28, 2009 Share Posted July 28, 2009 I'm trying to read the line (index of a 2d array and place it into a 1d array) Any luck someone can help me on this? Thanks Good luck with reading the line. Here is a couple of interruptions of what you could be asking. expandcollapse popup; #include <Array.au3> Local $aArray2d[4][3] = [[0, 0, 0],[1, 1, 1],[2, 2, 2],[3, 3, 3]] ; Index of 2D array in 1D array Local $a1d[12] = [$aArray2d[0][0], $aArray2d[0][1], $aArray2d[0][2], _ $aArray2d[1][0], $aArray2d[1][1], $aArray2d[1][2], _ $aArray2d[2][0], $aArray2d[2][1], $aArray2d[2][2], _ $aArray2d[3][0], $aArray2d[3][1], $aArray2d[3][2]] _ArrayDisplay($a1d, "Index of 2D array in 1D array") ;====================================================================================== ;Copy the contents of 2D array of variables to the contents of a 1D array of variables. Local $aArray1D = _Array2DTo1D($aArray2d) _ArrayDisplay($aArray1D) Func _Array2DTo1D($aTwo_d) If UBound($aTwo_d, 0) <> 2 Then MsgBox(0, "Error", "Array not 2 dimensional") Return EndIf Local $iRow = UBound($aTwo_d) Local $iCol = UBound($aTwo_d, 2) Local $aOne_d[$iRow * $iCol] For $i = 0 To $iRow - 1 For $j = 0 To $iCol - 1 $aOne_d[$i * $iCol + $j] = $aTwo_d[$i][$j] Next Next Return $aOne_d EndFunc ;==>_Array2DTo1D ; 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