litlmike Posted May 5, 2008 Share Posted May 5, 2008 (edited) I have an issue that I can think of solving in 1 or 2 ways. 1) Flip a 2-Dimensional array and problem solved, or 2) Loop through the array 'backwards'. For instance, if I want to reverse the data in a 2-dimensional Array, or in other words, flip the data in the array upside down. So if the array has 30 elements in the 1st dimension, and those elements read [30, 29, 28 ... 1]; then I want those 30 elements to now read [1 ... 28, 29, 30]. Likewise, if the 2nd dimension reads [A, B, C ... Z], then it should be flipped to read [Z ... C, B, A]. But, I don't know of any way to accomplish this. The other way I can think of doing it is to loop through the array 'backwards', starting with the last element and ending with the first. I was wondering what the AutoIt community would think is the better solution, and give me an idea of the best way to do this? At the bottom of the post, I have included a reproducer of the project I am working on. Normally I use this Psuedo-Model to Loop through a 2-D array. For $xCC=0 To UBound($aTableData,2)-1 $Row=1 For $iCC=1 To UBound($aTableData)-1 ;~ ;Write Data to Xls. _ExcelWriteCell($oExcel, $aTableData[$iCC][$xCC], $Row, $Column) $Row+=1 Next $Column+=1 Next expandcollapse popup;;;;;;;;;;;;;;;;;;;;;;;;;Declare Stuff;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #include <IE.au3> #include <ExcelCOM_UDF.au3> #include <Array.au3> $sFilePath = @ScriptDir & "\DA_Data.xls" $sUrl = "about:blank" $oIE = _IECreate($sUrl,1) Global $Row $Column=1 ;;;;;;;;;;;;;;;;;;;;;;;;;End Declare Stuff;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Make the IE Page reproducer Make_IE_Page() ;Get Table Data from Webpage $oTable = _IETableGetCollection ($oIE, 0) $aTableData = _IETableWriteToArray ($oTable, True) ;Make XLS file $oExcel = _ExcelBookNew() ;Put Data into XLS For $xCC=0 To UBound($aTableData,2)-1 $Row=1 For $iCC=1 To UBound($aTableData)-1 ;~ ;Write Data to Xls. _ExcelWriteCell($oExcel, $aTableData[$iCC][$xCC], $Row, $Column) $Row+=1 Next $Column+=1 Next $oExcel.Rows.AutoFit $oExcel.Columns.AutoFit _ExcelBookSaveAs($oExcel, $sFilePath, "xls", 0, 1) Func Make_IE_Page() ;Write HTML $s_HTML1 = '<table border=0 cellpadding=0 cellspacing=2>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Thu, Feb 28</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="33"> 973 <font color="990000">(<strong>4</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Wed, Feb 27</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="30"> 887 <font color="990000">(<strong>11</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Tue, Feb 26</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="39"> 1,146 <font color="990000">(<strong>15</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Mon, Feb 25</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="52"> 1,532 <font color="990000">(<strong>12</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Sun, Feb 24</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="38"> 1,099 <font color="990000">(<strong>9</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Sat, Feb 23</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="38"> 1,117 <font color="990000">(<strong>11</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Fri, Feb 22</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="43"> 1,252 <font color="990000">(<strong>7</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Thu, Feb 21</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="36"> 1,050 <font color="990000">(<strong>14</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Wed, Feb 20</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="33"> 960 <font color="990000">(<strong>7</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Tue, Feb 19</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="41"> 1,208 <font color="990000">(<strong>9</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Mon, Feb 18</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="45"> 1,313 <font color="990000">(<strong>9</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Sun, Feb 17</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="32"> 946 <font color="990000">(<strong>5</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Sat, Feb 16</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="7"> 200 <font color="990000">(<strong>0</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Fri, Feb 15</nobr></td>' ;& _ $s_HTML2 = '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="38"> 1,127 <font color="990000">(<strong>7</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Thu, Feb 14</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="39"> 1,137 <font color="990000">(<strong>10</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Wed, Feb 13</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="37"> 1,086 <font color="990000">(<strong>10</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Tue, Feb 12</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="48"> 1,419 <font color="990000">(<strong>13</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Mon, Feb 11</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="41"> 1,214 <font color="990000">(<strong>10</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Sun, Feb 10</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="200"> 5,860 <font color="990000">(<strong>9</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Sat, Feb 9</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="40"> 1,158 <font color="990000">(<strong>10</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Fri, Feb 8</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="35"> 1,033 <font color="990000">(<strong>5</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Thu, Feb 7</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="45"> 1,317 <font color="990000">(<strong>12</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Wed, Feb 6</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="50"> 1,458 <font color="990000">(<strong>13</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Tue, Feb 5</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="62"> 1,819 <font color="990000">(<strong>11</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Mon, Feb 4</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="43"> 1,249 <font color="990000">(<strong>6</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Sun, Feb 3</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="42"> 1,243 <font color="990000">(<strong>9</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Sat, Feb 2</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="56"> 1,632 <font color="990000">(<strong>5</strong>)</font></td>' & _ '</tr>' & _ '<tr>' & _ '<td align="right" class="smplain"><nobr>Fri, Feb 1</nobr></td>' & _ '<td class="smplain"><img src="images/graph_ht1.gif" align="absmiddle" border="1" height="12" width="52"> 1,537 <font color="990000">(<strong>14</strong>)</font></td>' & _ '</tr>' & _ '</table>' _IEDocWriteHTML( $oIE, $s_HTML1 & $s_HTML2) EndFunc TIA Edited May 5, 2008 by litlmike _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
ChrisL Posted May 5, 2008 Share Posted May 5, 2008 I'm not sure I would see the point in waisting resources flipping the data I would just read it backwards [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
weaponx Posted May 5, 2008 Share Posted May 5, 2008 expandcollapse popup#include <Array.au3> Dim $array[5][2] $array[0][0] = 0 $array[0][1] = "zero" $array[1][0] = 1 $array[1][1] = "one" $array[2][0] = 2 $array[2][1] = "two" $array[3][0] = 3 $array[3][1] = "three" $array[4][0] = 4 $array[4][1] = "four" ;_ArrayDisplay($array) ;Reverse array $array = _Reverse2DArray($array) _ArrayDisplay($array) Func _Reverse2DArray(ByRef $aArray) $rows = Ubound($aArray) $columns = Ubound($aArray, 2) Local $aTemp[$rows][$columns] For $Y = 0 to $rows-1 ConsoleWrite("Row " & $Y & ": ") For $X = 0 to $columns-1 $aTemp[$Y][$X] = $aArray[$rows - $Y - 1][$X] ConsoleWrite("Column " & $X & ": " & $aArray[$Y][$X] & ", ") Next ConsoleWrite(@CRLF) Next Return $aTemp EndFunc Link to comment Share on other sites More sharing options...
litlmike Posted May 5, 2008 Author Share Posted May 5, 2008 expandcollapse popup#include <Array.au3> Dim $array[5][2] $array[0][0] = 0 $array[0][1] = "zero" $array[1][0] = 1 $array[1][1] = "one" $array[2][0] = 2 $array[2][1] = "two" $array[3][0] = 3 $array[3][1] = "three" $array[4][0] = 4 $array[4][1] = "four" ;_ArrayDisplay($array) ;Reverse array $array = _Reverse2DArray($array) _ArrayDisplay($array) Func _Reverse2DArray(ByRef $aArray) $rows = Ubound($aArray) $columns = Ubound($aArray, 2) Local $aTemp[$rows][$columns] For $Y = 0 to $rows-1 ConsoleWrite("Row " & $Y & ": ") For $X = 0 to $columns-1 $aTemp[$Y][$X] = $aArray[$rows - $Y - 1][$X] ConsoleWrite("Column " & $X & ": " & $aArray[$Y][$X] & ", ") Next ConsoleWrite(@CRLF) Next Return $aTemp EndFunc Now that is just lovely. Why is _Reverse2DArray(ByRef $aArray) not in Array.au3? Thanks _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
weaponx Posted May 5, 2008 Share Posted May 5, 2008 (edited) Now that is just lovely. Why is _Reverse2DArray(ByRef $aArray) not in Array.au3?ThanksBecause I just wrote it now? Note: The ByRef isn't actually needed. Edited May 5, 2008 by weaponx Link to comment Share on other sites More sharing options...
litlmike Posted May 5, 2008 Author Share Posted May 5, 2008 Because I just wrote it now? Note: The ByRef isn't actually needed.Lol, that is awesome. What can I do to help us get this into Array.au3? _ArrayPermute()_ArrayUnique()Excel.au3 UDF 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