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

The INPUT # file or port statement reads sequential data using one variable or a comma separated list of matching variable types.


INPUT #fileNumber&, variable1[, variable2, …, variableN]




Writes new data to a text file sequentially and reads it back to the program screen.

filename$ = "testfile.dat" 
x = 1: y = 2: z$ = "Three" 

OPEN filename$ FOR OUTPUT AS #1 'opens and clears an existing file or creates new empty file 
WRITE #1, x, y, z$ 

PRINT "File created with data. Press a key!" 
K$ = INPUT$(1) 'press a key 

OPEN filename$ FOR INPUT AS #2 'opens a file to read it 
INPUT #2, a, b, c$ 

PRINT a, b, c$ 
WRITE a, b, c$


 1           2          Three

Screen output: PRINT string values will not display enclosing quotes. WRITE screen displays will.


File content: WRITE (file statement) string values will include quotation marks, but they are not required to read the file value as a string.

Commas inside of string values will not affect the INPUT value as those commas are not WRITE (file statement) separators.

x$ = "Hello, how are you?"
y$ = "I'm fine."

OPEN "testinp.dat" FOR OUTPUT AS #1
WRITE #1, x$, y$

OPEN "testinp.dat" FOR INPUT AS #1

INPUT #1, a$, b$

PRINT a$, b$ 
WRITE a$, b$ 

Hello, how are you?        I'm fine. 
"Hello, how are you?","I'm fine."

"Hello, how are you?","I'm fine."

File content: Commas inside of strings delimited with quotes will be ignored. WRITE (file statement) will always enclose string values in quotes.

See Also