LINE INPUT (file statement) - QB64 Wiki

LINE INPUT (file statement)

From QB64 Wiki

Revision as of 16:44, 25 October 2012 by Clippy (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The LINE INPUT # file statement reads an entire file line as one string variable value.


Syntax:

LINE INPUT #filenumber%, linereturn$


  • Reads a file using the filenumber OPENed in the INPUT (file mode) as one file string value.
  • Returns STRING values so it must use one string variable.
  • 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: 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:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page