Line Input #
 
Reads one line of text from a file

Syntax

Line Input #file number, string_variable

Parameters

file number
file number of an file opened for Input
string_variable
variable to receive the line of text

Description

Reads a line from an open text file (opened for Input through a bound file number) and stores it in a string variable.

A line of text ends at, but does not include the end of line characters. An end of line character may be the LF character (Chr(10)) or the CRLF character pair (Chr(13,10)).

Example

' compile with -lang qb

'$lang: "qb"

Dim Filehandle As Integer
Dim txt As String
    
On Error Goto HandleErrors
    
Filehandle = FreeFile
Open "test_text_file.txt" For Input As #filehandle

If LOF(filehandle) > 0 Then
        Line Input #filehandle, txt
Else
        Goto HandleErrors
End If

Close #filehandle
Print "The first line of test_text_file.txt is:"
Print txt
    
HandleErrors:
Print "Error."
Resume Next



Differences from QB

  • None

See also