Line Input # statement
Reads a single line from an open sequential file and assigns it to a String variable.
Syntax
Line Input #filenumber, varname
The Line Input # statement syntax has these parts:
Part | Description |
---|---|
filenumber | Required. Any valid file number. |
varname | Required. Valid Variant or String variable name. |
Remarks
Data read with Line Input # is usually written from a file with Print #.
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.
Example
This example uses the Line Input # statement to read a line from a sequential file and assign it to a variable. This example assumes that TESTFILE
is a text file with a few lines of sample data.
Dim TextLine
Open "TESTFILE" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, TextLine ' Read line into variable.
Debug.Print TextLine ' Print to the Immediate window.
Loop
Close #1 ' Close file.
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기