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.

The INPUT statement requests a STRING or numerical keyboard entry from the user.

Syntax

INPUT [;] “[Question or statement text]”{, ;} variable[, …]

INPUT ; variable[, …]

Parameter(s)

Description

Example(s)

Using a variable in an input text message using PRINT. INPUT prompts cannot use variables.


INPUT "Enter your name: ", name$
PRINT name$ + " please enter your age: ";: INPUT "", age% 'empty string with comma
PRINT name$ + " how much do you weigh"; : INPUT weight%   'no text adds ? 

Explanation: Use an empty string with a comma to eliminate the question mark that would appear without the string.

How QB64 avoids a Redo from start multiple entry error. Use commas between values.


DO
  INPUT "What is your name, age, and sex(M/F)"; name$, age%, sex$
LOOP UNTIL age%        'loop until age is not 0
IF age% >= 21 THEN PRINT "You can drink beer!" ELSE PRINT "You cannot drink beer yet!"
END 


What is your name, age, and sex(M/F)? Tom,24,M
You can drink beer!

Explanation: Try to enter text for the age value and it will not work. E or D should be allowed as decimal point numerical entries.

Preventing screen roll after an input entry on the bottom 2 screen rows.


SCREEN 12

COLOR 14: LOCATE 29, 2 '          place cursor at beginning of prompt line
PRINT "Enter a name to search for... "; 'print prompt on screen with input to follow
COLOR 15: INPUT ; "", name$ '       get search name from user
LOCATE 29, 2: PRINT SPC(78); '       erase previous prompt
n$ = UCASE$(name$) '                 convert search name to upper case
COLOR 14'                        change foreground color to yellow
LOCATE 29, 2: PRINT "Searching..."; 'print message
SLEEP 


Enter a name to search for... █

Explanation: The red semicolon after INPUT acts like a semicolon after a PRINT, which keeps the print cursor on the same row.

See Also