Jump to content
Sign in to follow this  

@error & End Of File

Recommended Posts

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.")

; 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 
       ;other simple code, then paste the line, with CTRL-V:



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


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

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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...