According to GPIs post in the German Board:
It seems that all the WriteXXX()-Functions don't return an errorcode or something like that. Therefore you can't react adequately to failures (for example a full disc).
Additionaly you could add ReturnValues to the CloseFile()-Procedure
0 - no Error
1 - Couldn't write - disc full
2 - File writeprotected
3 - etc.
This way you could also check the process of file creation and writing at the end.
Additional Returnvalues with File-Commands
-
- Enthusiast
- Posts: 613
- Joined: Tue May 06, 2003 2:50 pm
- Location: Germany
- Contact:
Re: Additional Returnvalues with File-Commands
> It seems that all the WriteXXX()-Functions don't return an errorcode
That's because OpenFile and CreateFile do the checking... they must return
non-zero before you can start writing with WriteXXX().
> Therefore you can't react adequately to failures (for example a full disc)
"Disk full" is the only error that can occur after an initial successful check.
The other ones you specified (write-protected, etc) get checked beforehand.
Here's an example of a way to check if WriteStringN() worked. All it does is
check the filesize before and after each write, and if the size is the same,
then obviously the write failed:
That's because OpenFile and CreateFile do the checking... they must return
non-zero before you can start writing with WriteXXX().
> Therefore you can't react adequately to failures (for example a full disc)
"Disk full" is the only error that can occur after an initial successful check.
The other ones you specified (write-protected, etc) get checked beforehand.
Here's an example of a way to check if WriteStringN() worked. All it does is
check the filesize before and after each write, and if the size is the same,
then obviously the write failed:
Code: Select all
Procedure CheckWriteStringN(string$)
a=Lof() : WriteStringN(string$)
If Lof()<>a : b=#TRUE : EndIf
ProcedureReturn b
EndProcedure
If CreateFile(0,"c:\test.txt")<>0
For r=1 To 10
If CheckWriteStringN(Str(r))=#FALSE
Debug "Write failed!"
Break ; Exit For/Next loop.
EndIf
Next
CloseFile(0)
EndIf