Jump to content

Recommended Posts

Posted

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!

Posted

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
Posted

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...