LineInput Function

   
LineInput Function

Class

Microsoft.VisualBasic.FileSystem

Syntax

 LineInput(   filenumber   ) 
filenumber (required; Integer)

Any valid file number

Return Value

A String containing the line read from the file

Description

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) 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.

Example

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 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.

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net