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.

Here is the syntax of the input command:

INPUT "[text to user]"; [variable] ' Question mark added

or

INPUT "[text to user]", [variable] ' No question mark added

Example:

INPUT "What is your name"; name$

or

INPUT "What is your age", age

When a semicolon (;) is used after the text output to the user, a question mark (?) and '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.BAS

1 ever 2 CLS 3 INPUT "What is your name"; name$ 4 PRINT "Hello, "; name$; "!" 5 INPUT "How old are you"; age 6 INPUT "what is your best computer game?", game$ 7 PRINT " name:"; name$ 8 PRINT " age:"; age; " years old" 9 PRINT "best game:"; game$

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.

Bạn đang đọc truyện trên: AzTruyen.Top