INPUT - QB64 Wiki

INPUT

From QB64 Wiki

Jump to: navigation, search

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


Syntax:

INPUT [;] "[Question or statement text]"{,|;} variable[, ...]
INPUT ; variable[, ...]


Parameters:

  • semicolon after the INPUT keyword keeps the entry on the same row after enter is pressed and prevents screen roll.
  • The quoted text or question MUST be a literal string created by the programmer if used. Quoted text cannot use variables!
  • Quotation marks are required except when a semicolon follows INPUT. A question mark will appear before entry cursor.
  • semicolon immediately after the text statement will display a ? mark with a space after it. Use a comma for input statements.
  • variable type determines the allowable numerical value entries in QB64. Text numerical entries limited to D, E, &H, &O or &B.


Usage:

  • QB64 will not return Redo from start errors as user input is limited to input within the scope of the variable type used.
Text entries can use any entry including numerical. QB64 will ignore commas in single variable text entries!
Numerical entries can use numbers only up to the input variable's numerical TYPE limit.
INTEGER, LONG, and _INTEGER64 entries will ignore decimal points entered and will use all numbers.
  • INPUT is capable of returning more than one variable value by separating input variables with commas in the statement.
The program user will have to know to separate each entry value with a comma when they use it.
String and numerical variables can both be used in multiple entry requests separated by commas.
QB64 will allow comma separated entries to not be entered by the user without error!
  • Use LINE INPUT for text input entries that may contain commas such as address or name entries!
  • The user must press enter for the INPUT procedure to end. Multiple entries can be skipped.
  • Will accept the scientific notation letter D or E inside of SINGLE or DOUBLE numerical values.
  • Numerical entries starting with &H, &O and &B can be made also.
  • INPUT removes all leading or trailing spaces in a string value entry. QB64 does NOT remove those spaces!
  • The statement stops a program until enter is pressed. Not good in programs using a mouse (see INKEY$ loops).
  • Use _DEST _CONSOLE before INPUT statements to be used in a console window.


Example 1: Using a variable in an input text message using PRINT. INPUT text 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.


Example 2: 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.


Example 3: 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:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
Views
Personal tools