LineInput Function |
Microsoft.VisualBasic.FileSystem
LineInput( filenumber )
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
Data is read into a buffer one character at a time until a line feed or carriage -return sequence (either Chr(13) or 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)
You use the LineInput function to read data from text files. To write data back to this type of file, use the PrintLine function.
The VB.NET LineInput function corresponds directly to the VB 6 LineInput statement, with the following differences:
The VB 6 LineInput statement 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 line read is the return value of the function.
The first argument of the VB 6 LineInput statement, filenumber , could be preceded by the # symbol. In VB.NET, this format is not supported.