Description
Writes display-formatted data to a sequential file.
Syntax
Print #filenumber,[outputlist]
The Print # statement syntax has these parts:
Part |
Description |
filenumber |
Any valid file number. |
outputlist |
Expression or list of expressions to print. |
The outputlist argument has the following syntax and parts:
[{Spc(n) | Tab[(n)]}][expression][charpos]
Part |
Description |
Spc(n) |
Used to insert space characters in the output, where n is the number of space characters to insert. |
Tab(n) |
Used to position the insertion point to an absolute column number, where n is the column number. Use Tab with no argument to position the insertion point at the beginning of the next print zone. |
expression |
Numeric or string expressions to print. |
charpos |
Specifies the insertion point for the next character. Use a semicolon to specify the insertion point to be immediately after the last character displayed. Use Tab(n) to position the insertion point to an absolute column number. Use Tab with no argument to position the insertion point at the beginning of the next print zone. If charpos is omitted, the next character is printed on the next line. |
Remarks
If you omit outputlist and include only a list separator after filenumber, a blank line prints to the file. Multiple expressions can be separated with either a space or a semicolon. A space has the same effect as a semicolon.
All data written to the file using Print # is internationally aware; that is, the data is properly formatted (using the appropriate decimal separator) and the keywords are output in the language appropriate for the international locale specified for your system.
For Boolean data, either True or False is printed. The True and False keywords are translated, as appropriate, according to the locale setting specified for your system.
Date data is written to the file using the standard short date format recognized by your system. When either the date or the time component is missing or zero, only the provided part gets written to the file.
Nothing is written to the file if outputlist data is Empty. However, if outputlist data is Null, Null is written to the file. Again, the Null keyword is translated, as appropriate.
For error data, the output appears as Error errorcode. The Error keyword is translated, as appropriate, when written to the file.
Because Print # writes an image of the data to the file, you must delimit the data so it prints correctly. If you use Tab with no arguments to move the print position to the next print zone, Print # also writes the spaces between print fields to the file.
Note
If, at some future time, you want to read the data from a file using the Input # statement, use the Write # statement instead of the Print # statement to write the data to the file. Using Write # ensures the integrity of each separate data field by properly delimiting it, so that it can be read back in using Input #. Using Write # also ensures that it can be correctly read in any locale.
See Also
Open Statement, Print Method, Spc Function, Tab Function, Write # Statement.
Example
This example uses the Print # statement to write data to a file.
Open "TESTFILE" For Output As #1 ' Open file for output. Print #1, "This is a test" ' Print text to file. Print #1, ' Print blank line to file. Print #1, "Zone 1"; Tab ; "Zone 2" ' Print in two print zones. Print #1, "Hello" ; " " ; "World" ' Separate strings with space. Print #1, Spc(5) ; "5 leading spaces " ' Print 5 leading spaces. Print #1, Tab(10) ; "Hello" ' Print word at col 10. ' Assign Boolean, Date, Null and Error values. MyBool = False : MyDate = #February 12, 1969# : MyNull = Null MyError = CVErr(32767) ' True, False, Null and Error are translated using locale settings of ' your system. Date literals are written using standard short date ' format. Print #1, MyBool ; " is a Boolean value" Print #1, MyDate ; " is a date" Print #1, MyNull ; " is a null value" Print #1, MyError ; " is an error value" Close #1 ' Close file.