Alandor Posted October 19, 2004 Posted October 19, 2004 (edited) I would like to know if this is normal, becausse I can't understand why it gets me some error. The error consist in the writed file not being closed. And not only that, the file is increasing its size at a high speed with "blank" lines. I think it enter in a endless loop. I tried with While 1 (like the manual example) and with all I know it could be, but the error still there. Could this be a bug ?? The part of code that generate the error is this: If FileExists ($samurizeConfigFile) Then $ficheroLectura = FileOpen($samurizeConfigFile, 0) $ficheroEscritura = FileOpen($samurizeConfigFile & ".bak.ini", 2) Do $linea = FileReadLine($ficheroLectura) If $linea = "AlertValue=00:00:00" Then $linea = "AlertValue=" & $horas & ":" & $minutos & ":" & $segundos FileWriteLine($ficheroEscritura, $linea & @CRLF) Until @error = -1 FileClose($ficheroLectura) FileClose($ficheroEscritura) EndIf Thanx, - Alandor - Edited October 19, 2004 by Alandor
Alandor Posted October 19, 2004 Author Posted October 19, 2004 (edited) This is strange, with the while: While 1 $linea = FileReadLine($ficheroLectura) If $linea = "AlertValue=00:00:00" Then $linea = "AlertValue=" & $horas & ":" & $minutos & ":" & $segundos FileWriteLine($ficheroEscritura, $linea) WEnd I got the same error, but I tried a Do Until 1 instead of the other both and It works, what causes the error ?? Do $linea = FileReadLine($ficheroLectura) If $linea = "AlertValue=00:00:00" Then $linea = "AlertValue=" & $horas & ":" & $minutos & ":" & $segundos FileWriteLine($ficheroEscritura, $linea) Until 1 Sorry, I talked before contrast it. With this last it only repeat the secuence of commands once. This is going to get me crazy......... What can I do ?? Edited October 19, 2004 by Alandor
Valik Posted October 19, 2004 Posted October 19, 2004 You never actually check to see if you are reaching EOF. Thus, you are writing a blank string, which combined with the automatically appended CRLF of FileWriteLine(), you are in an infinite loop of writing blank lines. You have to check @error immediately after calling FileReadLine() and if it is set, then exit from the loop.
Alandor Posted October 20, 2004 Author Posted October 20, 2004 Thanx for your help. Mmmmm, then the @error macro has to be checked inmediately after the function that change its value is called. I didn't knew that. Thanx. However, Is it possible to check the EOF from another way ?? I don't like too much the use of a exit Loop call, It seems to me very unclean in the main code (just like a basic goto call). Is there another way more cleaner ?? Thanx again for your help - Alandor -
Valik Posted October 20, 2004 Posted October 20, 2004 ExitLoop isn't even on the same planet as goto unless you're using it to jump out of multiple nested loops, in which case, it gets to be hard to follow (But still, nowhere near goto). With a call to ExitLoop, you always know that code execution will resume at the end of the loop its breaking out of, not in some arbitrary place 300 lines later, if even in the same file.
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