FOpen

FOpen filename$, fopenmode$, filenumber%

Opens the file whose name is specified in the parameter filename$.

In place of filenumber% you write a number for the file (which must be an integer value >= 1).
In subsequent nuBASIC statements you use this number when referring to the file.
It is possible to have several files open at once, but each must have a different file number.

The parameter fopenmode$ is a string that specifies the kind of access that is requested for the file, as follows:
  • "r" Opens for reading. If the file does not exist or cannot be found, the FOpen call fails.
  • "w" Opens an empty file for writing. If the given file exists, its contents are destroyed
  • "a" Opens for writing at the end of the file (appending) without removing the end-of-file (EOF) marker before new data is written to the file. Creates the file if it does not exist
  • "r+" Opens for both reading and writing. The file must exist.
  • "w+" Opens an empty file for both reading and writing. If the file exists, its contents are destroyed.
  • "a+" Opens for reading and appending. The appending operation includes the removal of the EOF marker before new data is written to the file. The EOF marker is not restored after writing is complete. Creates the file if it does not exist.
When a file is opened by using the "a" access type or the "a+" access type, all write operations occur at the end of the file.
The file pointer can be repositioned by using Seek, but is always moved back to the end of the file before any write operation is carried out. Therefore, existing data cannot be overwritten.
The "a" mode does not remove the EOF marker before it appends to the file.
After appending has occurred the "a+" mode does remove the EOF marker. The "a+" mode is required for appending to a stream file that is terminated with the CTRL+Z EOF marker.
When the "r+", "w+", or "a+" access type is specified, both reading and writing are allowed (the file is said to be open for "update"). However, when you switch from reading to writing, the Input operation must encounter an EOF marker.
If there is no EOF, you must use an intervening call to a file positioning function.
The file positioning function is Seek. When you switch from writing to reading, you must use an intervening call to either Flush or to a file positioning function.

See also Open
Comments