Sign in to follow this  
Followers 0
frank10

@error & End Of File

5 posts in this topic

I made a function to read each line of a file and when I reach EOF, it should exit the func, BUT @error never goes to -1, it stays always equal to 0. Why?

dim $_file = FileOpen("H:\Temp\testFireLinks.txt", 0)

If $_file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    return;Exit
EndIf


; Read in lines of text until the EOF is reached
While 1
    
    dim $_line = FileReadLine($_file)
        
       ;I put the line read to the clipboard, to use later
    ClipPut( $_line ) 
        
    If @error = -1 Then 
        ExitLoop
    EndIf
     
       ;other simple code, then paste the line, with CTRL-V:
    Send('^v')

Wend

FileClose($_file)

Any ideas?

Share this post


Link to post
Share on other sites



move the error check

dim $_line = FileReadLine($_file)

If @error = -1 Then ExitLoop

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

move the error check

dim $_line = FileReadLine($_file)

If @error = -1 Then ExitLoop

8)

The above code is correct - the reason is because @error is reset to 0 every time a function is called. In the original code, ClipPut is being tested for @error status, not the FileReadLine.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Oh thank you, now it's clear.

So if I made this (I originally thought it to shrink the code) :

ClipPut( FileReadLine($_file) )

I guess I cannot check the @error of File.

So the only way to go is as you told me before, is it true?

Edited by frank10

Share this post


Link to post
Share on other sites

Correct, if you have one function inside another, you cannot check the @error of the internal function.

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