If LF+CR+LF, LINE INPUT# Fails to Treat CR+LF as End-of-Line (72682)






This article was previously published under Q72682

SYMPTOMS

If a LINE INPUT# statement reads a linefeed plus carriage return plus linefeed sequence (LF+CR+LF), then LINE INPUT# will not treat the CF+LF as an end-of-line marker, and will continue reading data until it reads CR+LF that does not have a leading linefeed.

STATUS

Microsoft has confirmed this to be a bug in Microsoft QuickBasic versions 2.0, 2.01, 3.0, 4.0, 4.0b, and 4.5 for MS-DOS (buglist4.50, buglist4.00b, buglist4.00, buglist3.00, buglist2.01, buglist2.00); in Microsoft Basic Compiler versions 6.0 and 6.0b for MS-DOS and MS OS/2; and in Microsoft Basic Professional Development System (PDS) versions 7.0 and 7.1 for MS-DOS and MS OS/2. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

Note that LINE INPUT# has no problem treating CR+LF+CR+LF as two (empty) records, as long as no LF leads the sequence.

MORE INFORMATION

The following program demonstrates this problem. After the program writes three lines of data to the file, including two embedded LF+CR+LF sequences, the LINE INPUT# loop only inputs three lines. You might expect LINE INPUT# to separately input the following five strings into text$ in the WHILE...WEND loop:
   hello world
   <LF>
   RING<LF>
   RING
   hello world
				
Instead, the WHILE...WEND cycles just three times, and LINE INPUT# inputs the following three strings into text$:
   hello world
   <lf><cr><lf>RING<lf><cr><lf>RING
   hello world
				

Code Sample

CLS
OPEN "input.tst" FOR OUTPUT AS #1
PRINT #1, "hello world"
PRINT #1, CHR$(10); CHR$(13); CHR$(10); "RING";  ' ";" Concatenates
PRINT #1, CHR$(10); CHR$(13); CHR$(10); "RING"   ' these two lines.
PRINT #1, "hello world"
CLOSE #1

OPEN "input.tst" FOR INPUT AS #1
WHILE NOT EOF(1)
    n = n + 1
    LINE INPUT #1, text$
    PRINT "RECORD #"; n; " LENGTH="; LEN(text$), "CONTENTS:"; text$
WEND
CLOSE #1
				

Modification Type: Minor Last Reviewed: 1/8/2003
Keywords: KB72682