Write# (statement)


Write [#]filenumber [,expressionlist]


Writes a list of expressions to a given sequential file.


The file referenced by filenumber must be opened in either Output or Append mode.

The filenumber parameter is an Integer used by the Basic Control Engine to refer to the open fileā€”the number passed to the Open statement.

The following table summarizes how variables of different types are written:


Data Type



Any numeric type

Written as text. There is no leading space, and the period is always used as the decimal separator.



Written as text, enclosed within quotes.



No data is written.



Written as #NULL#.



Written as #TRUE# or #FALSE#.



Written using the universal date format:



User-defined errors

Written as #ERROR ErrorNumber#, where ErrorNumber is the value of the user-defined error. The word ERROR is not translated.


The Write statement outputs variables separated with commas. After writing each expression in the list, Write outputs an end-of-line.

The Write statement can only be used with files opened in Output or Append mode.


This example opens a file for sequential write, then writes ten records into the file with the values 10...50. Then the file is closed and reopened for read, and the records are read with the Input statement. The results are displayed in a dialog box.

Sub Main()

  Open "test.dat" For Output Access Write As #1

  For x = 1 To 10

    r% = x * 10

    Write #1,x,r%

  Next x


  msg1 = ""

  Open "test.dat" For Input Access Read As #1

  For x = 1 To 10

    Input #1,a%,b%

    msg1 = msg1 & "Record " & a% & ": " & b% & Basic.Eoln$

  Next x

  MsgBox msg1


End Sub

See Also

Open (statement); Put (statement); Print# (statement).

More information