Reads a single line from an open sequential file and assigns it to a String variable.
Public Function LineInput(ByVal FileNumber As Integer) As String
Exception type | Error number | Condition |
---|---|---|
62 | End of file reached. | |
52 | FileNumber does not exist. |
Data read with LineInput is usually written to a file with Print.
The LineInput function reads from a file one character at a time until it encounters a carriage return (Chr(13)) or carriage returnlinefeed (Chr(13) + Chr(10)) sequence. Carriage returnlinefeed sequences are skipped rather than appended to the character string.
This example uses the LineInput function to read a line from a sequential file and assign it to a variable. This example assumes that TESTFILE
is a text file with a few lines of sample data.
Dim TextLine As String FileOpen(1, "TESTFILE", OpenMode.Input) ' Open file. While Not EOF(1) ' Loop until end of file. TextLine =LineInput(
1)
' Read line into variable. Debug.WriteLine(TextLine) ' Print to the console. End While FileClose(1) ' Close file.
Chr, ChrW Functions | Input Function |