CitectVBA Programming Reference > CitectVBA Function Reference > File I/O Functions > Write #

Write #

Write # statement writes data to a Sequential file opened in output or append mode and reads that data from a list of variables.

The Write # statement has two parameters FileNum and VarList. The required FileNum argument is the associated file number used in the Open statement when the file was opened. The required VarList argument is a comma delimited list of variables that are assigned values read from the file.

Note: The file system keeps track of all open files and the current position of access within every file. Every statement or function that accesses the data within a file, alters the current position within that file. The Loc function can be used to determine the current position within an open file.

Data written to a file with the Write # statement is usually read with the Input # statement.

Note: When saving data to a file for future reading with the Input # statement, use the Write # statement instead of the Print # statement to write the data to the file. Using Write # properly delimits each separate data field , so it can be read back in using Input #. Using Write # also formats the data in a manner that will allow correct read operations in most locales.


Write #FileNum, VarList


An Integer or numeric expression representing any valid number in the range 1 to 511 inclusive, which is referenced by the file system to be associated with an open file.


A predefined valid CitectVBA variable name or comma delimited list of valid variable names.

Related Functions

Get # | GetAttr | Input | Line Input # | Print # | Put #


Dim strFileContents As String
Dim strTemp As String
Dim strString As String
Dim intFileNum as Integer
Dim intNumber as Integer
intFileNum = FreeFile 'retrieve next free file number
Open "c:\test.txt" For Output As #intFileNum ' open file.
Write #intFileNum, "This is a test of the Write # statement."
Close #intFileNum