Any valid file number
A String containing the line read from the file
Assigns a single line from a sequential file opened in Input mode to a string variable
Rules at a Glance
Data is read into a buffer one character at a time until a line feed or carriage-return sequence (either
Chr(13)+Chr(10)) is encountered. When this happens, all the characters in the buffer are returned as a string, without the carriage-return sequence, and the buffer is cleared.
After reading a line, the file pointer advances to the first character after the end of the line or to the end-of-file marker.
The following code reads all of the lines in a text file and sends them to the Output window:
Dim fr As Integer = FreeFile( ) Dim sLine As String FileOpen(fr, "c:\data.txt", OpenMode.Input, OpenAccess.Read) Do While Not EOF(fr) Console.WriteLine(LineInput(fr)) Loop FileClose(fr)
Programming Tips and Gotchas
You use the LineInput function to read data from text files. To write data back to this type of file, use the PrintLine function.
VB.NET/VB 6 Differences
The VB.NET LineInput function corresponds
directly to the VB 6
LineInput statement, with the
The VB 6
LineInputstatement has a second argument,
varname, which is the variable to receive the line read by the function. It is not supported by the VB.NET LineInput function, since the ...