Writing to a File
You must open files to use them in your program.
After you open the files, you may want to put information
into them. In this section, we will discuss about
the statements that can be used to write to sequential
files.
Print # Statement
It writes data to a sequential file only.
Print #filenumber, [outputlist]
The outputlist argument settings are:
[{Spc(n) | Tab[(n)]}] [expression] [charpos]
Mode |
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 nextprint zone. |
expression |
Numeric expressions
or string expressions to print. |
charpos |
Specifies the
insertion point for the next character. Use
a semicolon to position the insertion point
immediately after the last character displayed.
|
You can use either Spc() or tab(), but not both
together. |
The following code segment shows how to use the Print
# statement:
Private Sub Command1_Click()
Dim intCounter As Integer
Dim intFNum As Integer
intFNum = FreeFile
Open "C:\Print.txt"
For intCounter = 1 To 5
Print
# intFNum, intCounter;
Next intCounter
Close # intFNum
End Sub
|
If you want to print values one
after another on the same line, you can include
a semicolon after the Print statement. |
The above code segment opens a file named "Print.txt"
and writes the value of the intCounter to the file.
Finally, the code closes the file with the Close statement.
|