Write # (statement)

<< Click to Display Table of Contents >>

Write # (statement)

Write #FileNumber, [Expression]

Writes data to a file.

The file must have been already opened with the Open statement in Output or Append mode.

FileNumber is the number assigned to the file by the Open statement.

Expression consists of one or more elements to output.

If Expression is omitted, an empty line is output. Please note that in this case you still need to add a trailing comma to the command (e.g., Write #1,).

See also: Open, Seek, Print #

Example:

Sub Main

 Open "TESTFILE" For Output As #1   ' Create file

 userData1$ = InputBox("Enter one text line.")

 userData2$ = InputBox("Enter one more text line.")

 Write #1, userData1, userData2     ' Write data

 Close #1

 Open "TESTFILE" for Input As #2    ' Open file

 Print "File contents:"

 Do While Not EOF(2)

         Line Input #2, FileData        ' Read line

         Print FileData

 Loop

 Close #2                           ' Close file

 Kill "TESTFILE"                    ' Delete file

End Sub