Jump to content

How to address each row of 2d array


Clark
 Share

Recommended Posts

Hi there

I can't find out how to do this in the help.

I read into an array via some SQL. I then want to output the array into Excel using _ExcelWriteArray. _ExcelWriteArray can only write a 1d Array to I am assuming I would need to send it a row of the 2d array at a time.

This is what I have, that fails, as it does not like the way I reference the array variable.

$iRval= _Sql_GetTable2D($hDBHandle,$sSQL,$outArray,$iRows,$iColumns)
if $iRval <> $SQL_OK then
      Msgbox(0 + 16 +262144,"Error","Unable to execute query")
      Exit
EndIf
_ArrayDisplay($outArray)                     ; This displays the array just fine
for $i = 1 to uBound($outArray)
      ExcelPrint($outArray[$i])              ; Autoit does not like the $i
next

This fails on the ExcelPrint line, which calls a function that contains _ExcelWriteArray.

I'm not sure where to go from here.

Link to comment
Share on other sites

I can't find out how to do this in the help.

That's because there is no way to do that. Either address a single item (array[x][y]) or the whole thing ($array).

Create a secondary/temporary loop using a For-loop and UBound(), or use a way to write to Excel without arrays.

Link to comment
Share on other sites

You can use _ExcelWriteSheetFromArray() to write 2D array data. Or do it directly:

Global $aArray[3][3] = [["A1", "B1", "C1"], ["A2", "B2", "C2"], ["A3", "B3", "C3"]]
$oExcel.Activesheet.Range("A1:C3").Value = $aArray

:graduated:

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...