Modify

Opened 14 years ago

Closed 14 years ago

#2150 closed Bug (Duplicate)

_FileWriteFromArray() 2d array bug

Reported by: i2c Owned by:
Milestone: Component: Standard UDFs
Version: 3.3.8.0 Severity: None
Keywords: _FileWriteFromArray Cc:

Description

Dim $aArray[2][2] = [[1, 2],[3, 4]]
_FileWriteFromArray(@ScriptDir & "\aArray.txt", $aArray, 0, 0, "|")
C:\Program Files (x86)\AutoIt3\Include\File.au3 (272) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$s_Temp &= $s_Delim & $a_Array[$x][$y]
$s_Temp &= $s_Delim & ^ ERROR

Line 271 to 274 of File.au3:

For $y = 1 To $iDims
					$s_Temp &= $s_Delim & $a_Array[$x][$y]
				Next

In case we want to write a 2d array to a file, we already know, that we have 2 dimensions at this point cause the dimension count is saved in $iDims. It's not necessary to run this for loop cause $y can only be 1 furthermore $iDims is 2 so we will run into an error.

Solution:

For $y = 1 To $iDims - 1
					$s_Temp &= $s_Delim & $a_Array[$x][$y]
				Next

or better remove the loop and do the following

 For $x = $i_Base To $i_UBound
                $s_Temp = $a_Array[$x][0] & $s_Delim & $a_Array[$x][1]
                If FileWrite($hFile, $s_Temp & @CRLF) = 0 Then

Attachments (0)

Change History (2)

comment:2 by Valik, 14 years ago

Resolution: Duplicate
Status: newclosed

Closing as a duplicate of #2125.

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.