Write # Statement

Writes non-formatted data to a sequential file.

Syntax

Write #filenumber, [outputlist]

The Write # statement syntax has the following parts:

Part Description
filenumber Required. Any valid file number.
outputlist Optional. One or more comma-delimited numeric expressions or string expressions to write to a file.


Remarks

Data written with Write # is usually read from a file with Input #.
If you omit outputlist and include a comma after filenumber, a blank line is printed to the file. Multiple expressions can be separated with a space, a semicolon, or a comma. A space has the same effect as a semicolon.
When Write # is used to write data to a file, several universal assumptions are followed so the data can always be read and correctly interpreted using Input #, regardless of local settings:

Unlike the Print # statement, the Write # statement inserts commas between items and quotation marks around strings as they are written to the file. You don't have to put explicit delimiters in the list. Write # inserts a newline character, that is, a carriage return–linefeed (Chr(13) + Chr(10)), after it has written the final character in outputlist to the file.

Example

In this example the the Write # statement is used to write non-formatted data to a sequential file.

Open "TESTFILE" For Output As #1  ' Opens file for writing.
Write #1, "Hello World", 234      ' Writes comma-delimited data.
Write #1,                         ' Writes a blank line.

Dim MyBool, MyDate, MyNull
' Assigns values of Boolean, Date, Null types.
MyBool = False
MyDate = #February 12, 1969# MyNull = Null ' Boolean data gets written as #TRUE# or #FALSE#. Date data is written ' using the universal date format, for instance, #1994-07-13# ' for July 13, 1994. Null values are written as #NULL#.
Write #1, MyBool ; " - logical" Write #1, MyDate ; " - Date" Write #1, MyNull ; " - Null" Close #1 ' Closes file.

See Also

Writing Data to a File, Input # Statement, Open Statement, Print # Statement