CitectVBA Programming Reference > CitectVBA Function Reference > String Functions > Line Input #

Line Input #

Line Input # statement reads a single line from an open sequential file and assigns it to a String variable.

The required FileNum argument is a system reference number associated with an open file. The required VarName is the name of the variable where the file data is read (copied) to.

Note: The number sign (# ) preceding FileNum is not optional.

The Line Input # statement reads from a file one character at a time until it encounters a carriage return (Chr(13)) or carriage return-linefeed (Chr(13) + Chr(10)) sequence. Carriage return - linefeed sequences are skipped rather than appended to the character string.

Note: The file system keeps track of all open files and the current position of access within every file. Every statement or function that accesses the data within a file, alters the current position within that file. The Loc function can be used to determine the current position within an open file.

Data read with the Line Input # statement has usually been written to a file with the Print # statement.


Line Input # FileNum, VarName


An Integer or numeric expression representing any valid number in the range 1 to 511 inclusive, which is referenced by the file system to be associated with an open file.


A string representing a valid variable name.

Related Functions

Get # | GetAttr | Input | Print # | Put # | Write #


Dim strTextLine As String
Dim intFileNum As Integer
Open "c:\TEST.txt" For Input As #intFileNum intFileNum = FreeFile 'retrieve next free file number
Do While Not EOF(intFileNum) ' Loop until end of file.
Line Input #intFileNum, strTextLine ' Read line into variable.
Print TextLine ' Print line.
Close #intFileNum