OPENUPDATE

Synopsis
OPENUPDATE filename
(OPENUPDATE filename binarymode)
Description

Opens the file named filename for reading and writing. The read and write position is initially set to the end of the old file. Each open file has only one position, for both reading and writing. If a file opened for update is both READER and WRITER at the same time, then SETREADPOS also affects WRITEPOS and vice versa. Also, if you alternate reading and writing the same file, you must SETREADPOS between a write and a read, and SETWRITEPOS between a read and a write.

If the filename input is the reserved word "clipboard, then you can update text data on the clipboard as if it were a file. If the clipboard doesn't contain text when it is opened, then it's treated as if it contained nothing (you start with an empty file). If the clipboard is opened for reading and writing in binary mode, then the clipboard's existing contents are encoded in UTF-8 and you must encode any text that you write in UTF-8. Even in binary mode, only text data can be written to the clipboard.

The optional binarymode input is a boolean value (TRUE or FALSE). If binarymode is FALSE or not given, then the file is opened as a text file. If binarymode is TRUE, then the file is opened as a binary file.

When opening a text file, OPENUPDATE infers the character encoding from the file's Unicode signature, a byte order mark (BOM) that is at the beginning of the file. OPENUPDATE only recognizes two Unicode character encodings: UTF-8 and UTF-16LE. If a Unicode signature is recognized, it is excluded from the characters that are read from the file. If there is no Unicode signature or if the Unicode signature is not recognized, then the file is assumed to be encoded in the system default Windows code page. The character encoding is used both when reading from the file and when writing to the file. In addition, when reading from a text file, the end-of-line sequence is converted from CRLF to LF. When writing to a text file, the end-of-line sequence is converted from LF to CRLF.

When updating a binary file, the data is both read and written as bytes (values from 0 - 255) and no end-of-line sequence conversion is performed. If a Unicode signature is present, it is included in the data that is read from the file as a sequence of bytes.

OPENUPDATE throws an error if no file named filename exists or if the file cannot be opened for reading and writing.

Example
OPENWRITE "example.txt
SETWRITE "example.txt
PRINT "Hello
PRINT [Good Bye]
SETWRITE []
CLOSE "example.txt

OPENUPDATE "example.txt
SETREAD "example.txt
SETREADPOS 0
SHOW READLIST
[Hello]
SETWRITE "example.txt
SETWRITEPOS 7
PRINT [And how are you today]
SETWRITE []
SETREAD "example.txt
SETREADPOS 0
REPEAT 3 [SHOW READLIST]
[Hello]
[And how are you today]

CLOSE "example.txt
See Also
CLOSE

SourceForge.net Logo