Last modified on 6 December 2013, at 04:43

QBasic/Basic Input

The INPUT command is used to gather input from the user. This section will attempt to teach you how to gather input upon request from the user. For real-time input, see QBasic/Advanced Input.

Here is the syntax of the input command:

INPUT "[text to user]"; [variable] ' Prints questionmark before prompt
or
INPUT "[text to user]", [variable] ' No additional question mark

Example:

INPUT "What is your name"; NAME$
INPUT "What is your age"; age

When an semicolon (;) is used between the text to the user and the variable, a question mark and a space are added to the output. When a comma (,) is used no question mark is added.

If a string is specified (eg 'name$'), anything the user enters before pressing the 'return' key will be accepted. If a numeric variable (eg 'age') is specified, the user must enter a number (if any non-numeric key is entered, the error message "Redo from start" will be output and the INPUT command rerun)

6INPUT.BASEdit

CLS
INPUT "What is your name"; NAME$
PRINT "Hello, "; NAME$; "! ";
INPUT "How old are you"; age
PRINT "The user, "; NAME$; " is "; age; " years old"

Please note: In the PRINT command, the ';' function 'concatenates' (joins) the contents of the string variables with the text between the quotes (" "). Note the use of spaces so that the final printed text reads properly.

If a numerical variables is specified within the PRINT command, an additional space is automatically added both before and after the number.

See also LINE INPUT command to read a line of text from a file (and place the result in a string variable) or to input a series of variables (in which case any commas found will be treated as delimiters between fields).