Archive: FileWrite throws arbitrary error


FileWrite throws arbitrary error
I have opened a file like so:

FileOpen $4 "$EXEDIR\${NAME}.log" w
No problem there. But when I write a line to the file, it indeed writes the line, but throws an error flag.


${time::GetLocalTime} $R0
FileWrite $4 "$R0 This is some note $\n"
So the open/append and writing works, but IfErrors is set for some reason. I tried IfErrors after "time", but that wasn't it. Ideas?

Are you sure it's not time::GetLocalTime that sets the error flag? You should always call ClearErrors before calling the instruction that you wish to test with IfErrors.


Yes. I am entirely sure. I broke the lines apart with IfErrors, and time did not throw a flag (and IfErrors performs ClearErrors)


Well, FileWrite only sets the error flag if the handle is invalid or WriteFile returns an error code. So, unless time corrupts $4 or something else sets the error flag, there's a disk error and that's very unlikely. Can you attach the script?


Sure. But it is a long script. Btw, I opened the file using a function, and write to it outside of the function. I doubt that matters but who knows, I've managed to corrupt the stack with execdos.


I don't see any FileWrite accompanied with IfErrors in that script.


Check procedure ReadINI.

I wanted to put in FileWrites all throughout it, but it kept of throwing errors there. I removed all the FileWrites and substituted MessageBoxes.


I can't see in that script if you've really used ClearErrors and IfErrors correctly and there's something else. That's not the script that reproduces the problem. And if it is, then the problem is that you don't have ClearErrors before FileWrite.