As you say, OPEN for BINARY does not truncate an existing file; if that is a problem you can instead use OPEN for OUTPUT (you can still write 'binary' data: there's not really any difference between a 'binary' file and a 'sequential' file).
That is the main reason why I do not like the fact that, in LB, opening a file in BINARY mode changes the behaviour of PRINT#. If you decide you want to truncate an existing file, so you alter BINARY to OUTPUT (or the opposite), the actual data written to the file may change!
So in LBB PRINT# is unaffected by the mode the file is opened in. If there is no trailing semicolon it appends a CRLF (chr$(13)+chr$(10)) to the data, if there is it doesn't. Fortunately LB is happy to have the semicolon (even with a file opened for BINARY) so it's easy to maintain compatibility.
I would have preferred OPEN for BINARY to be called something like OPEN for MODIFY, because the principal effect is to allow an existing file to be modified. Whether the contents of the file are 'binary' data or not is irrelevant.
Richard. |
|