Print # filenumber, [ [{Spc(n)
| Tab(n)}][ expressionlist]
[{; | ,}] ]
- filenumber
- Number used in an
Open statement to open a sequential file. It can be any number of
an open file.
Note: The number sign (#) preceding filenumber is not
optional.
- Spc(n)
- Name of the Basic function
optionally used to insert n spaces into the printed output. Multiple
use is permitted.
- Tab(n)
- Name of the Basic function
optionally used to tab to the nth column before printing expressionlist.
Multiple use is permitted.
- expressionlist
- Numeric and/or
string expressions to be written to the file.
- If you omit
expressionlist, the Print # statement prints a blank line in the file,
but you must include the comma. Because Print # writes an image of
the data to the file, you must delimit the data so it is printed correctly.
If you use commas as delimiters, Print # also writes the blanks between
print fields to the file.
- {;|,}
- Character that determines
the position of the next character printed. A semicolon means the
next character is printed immediately after the last character; a
comma means the next character is printed at the start of the next
print zone. Print zones begin every 14 columns. If neither character
is specified, the next character is printed on the next line.
The
Print # statement usually writes Variant
data to a file the same way it writes any other data type. However,
there are some exceptions:
- If the data being written is a Variant of VarType 0 (Empty), Print
# writes nothing to the file for that data item.
- If the data being written is a Variant of VarType 1 (Null), Print
# writes the literal #NULL# to the file.
- If the data being written is a Variant of VarType 7 (Date), Print
# writes the date to the file using the Short Date format
defined in the WIN.INI file. When either the
date or the time component is missing or zero, Print # writes
only the part provided to the file.
The following example writes data to a test file.
Sub Main
Dim I, FNum, FName ' Declare variables.
For I = 1 To 3
FNum = FreeFile ' Determine next file number.
FName = "TEST" & FNum
Open FName For Output As FNum ' Open file.
Print #I, "This is test #" & I ' Write string to file.
Print #I, "Here is another "; "line"; I
Next I
Close ' Close all files.
End Sub
The following example writes data to a test file and reads it back.
Sub Main()
Dim FileData, Msg, NL ' Declare variables.
NL = Chr(10) ' Define newline.
Open "TESTFILE" For Output As #1 ' Open to write file.
Print #2, "This is a test of the Print # statement."
Print #2, ' Print blank line to file.
Print #2, "Zone 1", "Zone 2" ' Print in two print zones.
Print #2, "With no space between" ; "." ' Print two strings together.
Close
Open "TESTFILE" for Input As #2 ' Open to read file.
Do While Not EOF(2)
Line Input #2, FileData ' Read a line of data.
Msg = Msg & FileData & NL ' Construct message.
MsgBox Msg
Loop
Close ' Close all open files.
MsgBox "Testing Print Statement" ' Display message.
Kill "TESTFILE" ' Remove file from disk.
End Sub