WRITE# statement  

Purpose

Output data to a sequential file in a delimited format.

Syntax

WRITE #filenum&
WRITE #filenum&, [expression [{;|,} expression] ...] [;|,]

filenum&

The file number used when the file or device was opened.

expression

A numeric or a string expression representing the data to be written to the file or device.  

Remarks

WRITE# is similar to PRINT#, except WRITE# inserts a comma in the output file between each expression. It encloses string data within quotation marks, and adds no leading or trailing spaces around numeric values.

WRITE# is the preferred method of writing data to a sequential file, since it formats the output to be readable by the INPUT# statement.  In other words, INPUT# respects the delimiter characters that separate items in a line of text, as created by WRITE#.

WRITE# with a file number and a comma but no expressions, outputs a carriage return to the file.

To read a delimited file without regard to the delimiter characters, use the LINE INPUT# statement.

Restrictions

For best results, strings should not contain quotation marks, as these may interfere with the expected output format.

Each expression in the WRITE# statement must be separated from other expressions by a comma or semicolon.  If you include a trailing comma or semicolon, the final carriage return / line feed is suppressed and replaced with a comma delimiter.  This allows you to append data to the sequential record by executing another WRITE statement.

See also

GET, GET$, INPUT#, LINE INPUT#, OPEN, PRINT#, PUT, PUT$, SETEOF

Example

' Open a sequential output file and write to it

OPEN "FILE.TXT" FOR OUTPUT AS #1

WRITE #1, "TEST"

z& = -12345&

info1$ = "Do not covet"

info2$ = "thy neighbors ox"

WRITE #1, z&, info1$, info2$

WRITE #1, "TEST"

CLOSE #1

Result

"TEST"

-12345,"Do not covet","thy neighbors ox"

"TEST"