QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

See OPEN.

The INPUT file mode in an OPEN statement opens an existing file for INPUT (file statement).

Syntax

OPEN fileName$ FOR INPUT AS #filenumber%

Example(s)

Avoiding an INPUT mode or INPUT (file statement) read error using a FileExist function. QB64 can use the _FILEEXISTS function.


 DIM Fdata$(100)
 INPUT "Enter data file name: ", datafile$
 IF _FILEEXISTS(datafile$) THEN
    D% = FREEFILE: count = 0
    OPEN datafile$ FOR INPUT AS #D%
    DO UNTIL EOF(D%)
     count = count + 1
     LINE INPUT #D%, Fdata$(count)
     IF count = 100 THEN EXIT DO  ' don't exceed array size!
    LOOP
  CLOSE #D%
 ELSE : PRINT "File not found!"
 END IF

Explanation: The _FILEEXISTS function is used before OPEN datafile$ FOR INPUT AS #D%, which would generate an error in case the file didn’t exist.

See Also