Files in RBASIC™

RBASIC files are always text files. To store numeric information, the numbers first need to be converted to a string format (for example using the functions STR$ or FORMAT$). Files can also represent communications ports if a serial port name (i.e. "COM1") is used as a file name.

File commands

OPENREAD

Opens a file for read.

Example:

OPENREAD(file$)

where file$ is "c:\RBasic programs\myscanner\scandata.txt"

OPENWRITE

Opens a file for read or write operations. File write operations append new lines to the file (rather than overwrite existing ones). SETFILEPOS can be used to change the current file pointer.

Example:

OPENWRITE("c:\myfile.txt")

SETFILEPOS

Sets the current file position.

Example:

SETFILEPOS ("c:\myfile.txt",1000)

WRITE

Writes a line to the file at the current file position. The file must be successfully open first using OPENWRITE.

Example:

WRITE ("c:\myfile.txt","this is a new line")

REMOVEFILE

Deletes a file.

Example:

REMOVEFILE("c:\myfile.txt")

CLOSE

Closes a file.

Example:

CLOSE("c:\myfile.txt")

SETFILEPOS

Sets the current file position

Example:

SETFILEPOS ("c:\myfile.txt",1000)

SETUPCOMPORT

Sets parameters of a COM Port

Example:

SETUPCOMPORT("com1","baud=38400 stop=1 parity=N data=8 dtr=on")
SETUPCOMPORT("com1","baud=9600 stop=2 parity=M data=5 dtr=off")

File functions

READ$(file$)

Reads a line from the file$ from the current file position. The file must be already opened for read or write.

Example:

line$=READ$("c:\myfile.txt")

EOF(file$)

Returns the end-of-file status of the file$.

Example:

if EOF("c:\myfile.txt") then GOTO finish