Page 1 of 1

Additional Returnvalues with File-Commands

Posted: Wed Jul 28, 2004 9:59 am
by freedimension
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.

Posted: Wed Jul 28, 2004 11:18 am
by IceSoft
@Fred
I belive "a missing return status" is more a BUG as a wish.
Please move it to the BUG list. Thanks!

Re: Additional Returnvalues with File-Commands

Posted: Wed Jul 28, 2004 12:00 pm
by PB
> 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:

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