Sign in to follow this  
Followers 0
tolyasher

Qustion about FileReadLine

4 posts in this topic

I have small question related to code below:

Code 1 (This code is working properly):

While 1

Local $LineRead = FileReadLine($hFile)

If (@error = -1) Then ExitLoop

ConsoleWrite( " " & @error & @CRLF)

ConsoleWrite( " " & $LineRead & @CRLF)

WEnd

Code 2 ( I see that '@error = -1' in the Console but this code is never stop):

While 1

Local $LineRead = FileReadLine($hFile)

ConsoleWrite( " " & @error & @CRLF)

If (@error = -1) Then ExitLoop

ConsoleWrite( " " & $LineRead & @CRLF)

WEnd

Why?

Thanks in advance!

Share this post


Link to post
Share on other sites



The value of @error is set to 0 when a function is called. So, you are evaluating ConsoleWrite's @error value on the second code.

Try this:

While 1
Local $LineRead = FileReadLine($hFile)
$error = @error
ConsoleWrite( " " & $error & @CRLF)
If ($error = -1) Then ExitLoop 
ConsoleWrite( " " & $LineRead & @CRLF) 
WEnd

Share this post


Link to post
Share on other sites

The value of @error is set to 0 when a function is called. So, you are evaluating ConsoleWrite's @error value on the second code.

Try this:

While 1
Local $LineRead = FileReadLine($hFile)
$error = @error
ConsoleWrite( " " & $error & @CRLF)
If ($error = -1) Then ExitLoop 
ConsoleWrite( " " & $LineRead & @CRLF) 
WEnd

Thank you very much. I thought that "ConsoleWrite" do not affect error flag because it do not described in the AutoIT Help

Share this post


Link to post
Share on other sites

There are several undocumented changes to @error. A few scripts even started reading these values before, but it's not a good idea.

Share this post


Link to post
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
Sign in to follow this  
Followers 0