Quote:

be careful when using FreeFileHandle() - don't get caught out by this schoolboy error:
Code:
$fhLogFile=FreeFileHandle()
$fhOutFile=FreeFileHandle()

; Open log file...
If Open($fhLogFile,"c:\temp\log.txt",5) "CANNOT OPEN LOG FILE"+@CRLF Exit @ERROR EndIf

; Open out file...
If Open($fhOutFile,"c:\temp\out.txt",5) "CANNOT OPEN OUT FILE"+@CRLF Exit @ERROR EndIf






Though perhaps not as obvious to some it would not work as Richard wrote it.

BOTH files would have a FreeFile number of 1 which would then cause an error.
$fhLogFile=FreeFileHandle()
$fhOutFile=FreeFileHandle()

Since the call is one right after the other without actually opening any file, they
will both end up having the same value for their var.
 
I would probably close the files in each of the IF blocks, but as in this example it could be closed at the end if you like..

Dim $fhLogFile, $fhOutFile, $RC
; Open log file...
$fhLogFile=FreeFileHandle()
'Value for FREE LOG is: ' + $fhLogFile ?
If Open($fhLogFile,"c:\temp\log.txt",5)=0
$RC=WriteLine($fhLogFile,'Wrting to LOG file okay'+@CRLF+'Freehandle is: '+$fhLogFile)
Else
"CANNOT OPEN LOG FILE"+@CRLF
Exit @ERROR
EndIf

; Open out file...
$fhOutFile=FreeFileHandle()
'Value for FREE OUT File is: ' + $fhOutFile ?
If Open($fhOutFile,"c:\temp\out.txt",5)=0
$RC=WriteLine($fhOutFile,'Wrting to OUT file okay'+@CRLF+'Freehandle is: '+$fhOutFile)
Else
"CANNOT OPEN OUT FILE"+@CRLF
Exit @ERROR
EndIf

$RC=Close($fhLogFile)
$RC=Close($fhOutFile)