<< Click to Display Table of Contents >> Print # (statement) |
Print #FileNumber, [Expression]
Writes data to a file.
FileNumber is a number assigned to a file by Open statement.
Expression consists of the characters to be written.
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., Print #1,).
See also: Open, Print, Seek, Write #
Example:
This example writes data to a test file and then reads it back in.
Sub Main
Dim FileData, Msg, NL
NL = Chr(10) ' Chr(10)=New line
Open "TESTFILE" For Output As #1 ' Create file
Print #1, "This is a test for the Print # statement"
Print #1, "Line 2"
Print #1, "Line 3"
Close ' Close all files
Open "TESTFILE" for Input As #2 ' Open file
Do While Not EOF(2)
Line Input #2, FileData ' Read lines
Msg = Msg & FileData & NL
MsgBox Msg
Loop
Close ' Close all files
Kill "TESTFILE" ' Delete file
End Sub