Print # (statement)

<< 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,).

Formatting the output

The expression to be written can optionally be formatted in the following way:

[ [{ Spc(n)|Tab(n) }] [Expression] [{ ;|, .]]

Spc(n)        Writes n space characters in front of Expression.

Tab(n)        Writes Expression in column n.

;        Causes the next character to directly follow.

,        Causes the next character to be written at the beginning of the next print zone. Print zones start in every 14th column position.

If neither ; nor , is specified, the next character will be written in a new line.

Date/time values are output in the short date/time format.

The value Empty (Variant with VarType 0) creates an empty output.

The value Null (Variant with VarType 1) creates the output #NULL#.

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