frank10 Posted February 20, 2006 Posted February 20, 2006 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?
Valuater Posted February 20, 2006 Posted February 20, 2006 move the error check dim $_line = FileReadLine($_file) If @error = -1 Then ExitLoop 8)
greenmachine Posted February 20, 2006 Posted February 20, 2006 move the error checkdim $_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.
frank10 Posted February 20, 2006 Author Posted February 20, 2006 (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 February 20, 2006 by frank10
greenmachine Posted February 20, 2006 Posted February 20, 2006 Correct, if you have one function inside another, you cannot check the @error of the internal function.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now