Line Input# (statement)

Syntax Line Input [#] filenumber,variable
Description Reads an entire line into the given variable.
Comments The filenumber parameter is a number that is used to refer to the open file¾the number passed to the Open statement. The filenumber must reference a file opened in Input mode. The file is read up to the next end-of-line, but the end-of-line character(s) is (are) not returned in the string. The file pointer is positioned after the terminating end-of-line.
The variable parameter is any string or variant variable reference. This statement will automatically declare the variable if the specified variable has not yet been used or dimensioned. This statement recognizes either a single line feed or a carriage-return/line-feed pair as the end-of-line delimiter.
Example This example reads five lines of the autoexec.bat file and displays them in a dialog box.
Const crlf = Chr$(13) + Chr$(10)
                           
Sub Main()
  file$ = "c:\autoexec.bat"
  Open file$ For Input As #1
  msg1 = ""
  For x = 1 To 5
    Line Input #1,lin$
    msg1 = msg1 & lin$ & crlf
  Next x
  MsgBox "The first 5 lines of '" & file$ & "' are:" & crlf & crlf & msg1
End Sub
See Also Open (statement); Get (statement); Input# (statement); Input, Input$ (functions).