﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
2242	_FileWriteFromArray is incapable of writing only the zeroth element	BrewManNH	guinness	"In the File.au3 UDF, the function _FileWriteFromArray can't be used to write only the zeroth [0] of an array due to the way it is written. It has the capability to write any other single element, such as [1] or [2], but you can't output to a file the first element.

There is a simple fix for it, but it would be a script breaking change if applied.

{{{
; <<< default value for $I_Ubound changed to -1 instead of 0 >>>
Func _FileWriteFromArray($File, $a_Array, $i_Base = 0, $i_UBound = -1, $s_Delim = ""|"")
	; Check if we have a valid array as input
	If Not IsArray($a_Array) Then Return SetError(2, 0, 0)
	Local $iDims = UBound($a_Array, 0)
	If $iDims > 2 Then Return SetError(4, 0, 0)

	; determine last entry
	Local $last = UBound($a_Array) - 1
; <<< This line changed to look for the value of $i_Ubound < 0 instead of $i_Ubound < 1 >>>
	If $i_UBound < 0 Or $i_UBound > $last Then $i_UBound = $last
	If $i_Base < 0 Or $i_Base > $last Then $i_Base = 0

	; Open output file for overwrite by default, or use input file handle if passed
	Local $hFile
	If IsString($File) Then
		$hFile = FileOpen($File, $FO_OVERWRITE)
	Else
		$hFile = $File
	EndIf
	If $hFile = -1 Then Return SetError(1, 0, 0)

	; Write array data to file
	Local $ErrorSav = 0
	Switch $iDims
		Case 1
			For $x = $i_Base To $i_UBound
				If FileWrite($hFile, $a_Array[$x] & @CRLF) = 0 Then
					$ErrorSav = 3
					ExitLoop
				EndIf
			Next
		Case 2
			Local $s_Temp
			For $x = $i_Base To $i_UBound
				$s_Temp = $a_Array[$x][0]
				For $y = 1 To $iDims - 1
					$s_Temp &= $s_Delim & $a_Array[$x][$y]
				Next
				If FileWrite($hFile, $s_Temp & @CRLF) = 0 Then
					$ErrorSav = 3
					ExitLoop
				EndIf
			Next
	EndSwitch

	; Close file only if specified by a string path
	If IsString($File) Then FileClose($hFile)

	; Return results
	If $ErrorSav Then Return SetError($ErrorSav, 0, 0)
	Return 1
EndFunc   ;==>_FileWriteFromArray
}}}

It's only 2 values in 2 lines that need to be changed, but would result in it being a script breaking change due to this."	Bug	closed	3.3.9.5	Standard UDFs	3.3.8.1	None	Fixed		
