LINE INPUT (file statement) - QB64 Wiki

LINE INPUT (file statement)

From QB64 Wiki

Jump to: navigation, search

The LINE INPUT # file statement reads an entire file line as one string variable value. BINARY mode is faster than INPUT mode for strings.


LINE INPUT #filenumber&, textlinereturn$


  • filenumber is the INTEGER number of the file previously opened AS.
  • Statement STRING variable returns text line of the file being read ending at CRLF characters.


  • Reads a file using the filenumber OPENed in the INPUT (file mode) or GL BINARY file mode as one file line text string.
  • Can be used with EOF to count the number of lines of data (records) in a file using a loop.
  • Use the EOF function to avoid going past the end of a file and creating an error.
  • LINE INPUT # can even retain the original quotation marks in text.
  • Note: QB64 will NOT remove CHR$(0) from the end of LINE INPUT # string return values like Qbasic did.
  • NOTE: LINE INPUT will work faster in BINARY mode than INPUT mode or even faster using BINARY mode with GET# in QB64!


  • If QB64 or QB 4.5 give "Input past End of file" errors, check for CHR$(26) in the files being read!
  • Warning! Files must exist to open them in INPUT mode! Use _FILEEXISTS to avoid program errors!

Example: Finding the number of filenames listed in a file to dimension an array to hold them.

REDIM FileArray$(100) 'create dynamic array SHELL _HIDE "DIR /B *.* > D0S-DATA.INF" IF _FILEEXISTS("D0S-DATA.INF") THEN OPEN "D0S-DATA.INF" FOR INPUT AS #1 DO UNTIL EOF(1) LINE INPUT #1, file$ 'read entire text file line filecount% = filecount% + 1 LOOP CLOSE #1 END IF REDIM FileArray$(filecount%) PRINT filecount%

See also:

Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
Personal tools