Purpose
Reads a line from a sequential text file into a variable.
Syntax
Line Input [#] filenum, var_name
filenum is an integer value, indicating the number of an open file.
var_name is the name of a string variable.
Description
The Line Input statement reads an entire line from a text file, and stores the results in a string variable. The text file must already be open, in Input mode.
The Line Input statement treats each line of the file as one long string. If each line of a file contains a comma-separated list of expressions, and you want to read each expression into a separate variable, use the Input # statement instead of Line Input.
Example
The following program opens an existing text file, reads the contents of the text file one line at a time, and copies the contents of the file to a separate text file.
Dim str As String
Open File "original.txt" For Input As #1
Open File "copy.txt" For Output As #2
Do While Not EOF(1)
Line Input #1, str
If Not EOF(1) Then
Print #2, str
End If
Loop
Close File #1
Close File #2
See Also:
Input # statement, Open File statement, Print # statement