Skip to content

Latest commit

 

History

History
54 lines (36 loc) · 1.73 KB

line-inputstatement.md

File metadata and controls

54 lines (36 loc) · 1.73 KB
title keywords f1_keywords ms.assetid ms.date ms.localizationpriority
Line Input statement (VBA)
vblr6.chm1008962
vblr6.chm1008962
30cfc57e-0d28-b53e-c5cd-0ed99957e25d
12/03/2018
medium

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

[!includeSupport and feedback]