LINE INPUT
Jump to navigation
Jump to search
![]() |
![]() |
![]() |
![]() |
Description
- Retrieves a line of data from an open file or other device up to the next carriage return or at the end of the file. The line of data is assigned to var$. Use line input when you need to read text with embedded commas. (This differs from the INPUT statement, which uses the comma as a delimiter.)
Syntax
- line input #handle, var$
Hints
- It looks for carriage return character, that is CHR$(13).
- It works if lines are delimited with CHR$(13) or CHR$(13)+CHR$(10) (CR LF pair, standard under Windows.)
- If you ever find UNIX-style text file (with "line feed" character (CHR$(10) ) only), it will try to read whole file.
- If you are getting unexpected results or errors, check your line endings.
Example
' Often, a line of information in a data file is separated by commas into fields. ' Comma separated data is accessed with the INPUT statement, with each statement ' retrieving the information up to the next comma - or the end-of-line. ' To retrieve that whole line from the file, including the embedded commas, use ' the LINE INPUT statement. ' Write a line of data with embedded commas to a disk file. open "Mems.txt" for output as #1 #1 "William Shakespeare, Stratford-upon-Avon, Warwickshire, England" close #1 print "As read by INPUT:" open "Mems.txt" for input as #1 while not(eof(#1)) input #1, member$ print member$ wend close #1 print print "As read by LINE INPUT:" open "Mems.txt" for input as #1 while not(eof(#1)) line input #1, member$ print member$ wend close #1 end
Useful Procedures
' Place a useful function or sub using this keyword here