INPUT statement

Purpose: INPUT gets keyboard input from the user. See also the LINE INPUT statement which allows keyboard input of text containing comma or quotation mark.


Syntax 1:

 INPUT Variable [, Variable, ...]

Parameters:

  • Variable [, Variable, ...] INTEGER, SINGLE, DOUBLE, or STRING, identified using the %, !, #, $ data type identifiers. Multi-dimensional arrays are also allowed as Variables in INPUT.

Syntax 2:

 INPUT "QuotedPrompt", Variable [, Variable, ...]

Parameters:

  • "QuotedPrompt" [OPTIONAL] string literal prompt. A string literal must be used for a prompt string; a string variable can not be used. If a prompt is used it must be followed by a comma.
  • Variable [, Variable, ...] INTEGER, SINGLE, DOUBLE, or STRING, identified using the %, !, #, $ data type identifiers. Multi-dimensional arrays are also allowed as Variables in INPUT.

SCANERROR variable

INPUT returns an error code value to a BCX internal variable named SCANERROR.

Example 1: INPUT without a prompt


 DIM a!,b#,c$,d%,e$[10],f$

 PRINT "Input 1.2,123456.78901234,string,12345,arraystring,this is a string"
 INPUT a!,b#,c$,d%,e$[5],f$
 PRINT "single! ",a!
 PRINT "double# ",b#
 PRINT "string$ ",c$
 PRINT "integer ",d%
 PRINT "array string ",e$[5]
 PRINT "string with spaces",f$

Result

 
 single!  1.2
 double#  123456.78901234
 string$  string
 integer  12345
 array    arraystring
 sstring  this is a string
 

Example 2: INPUT with a prompt


 INPUT "Input 1.2,123456.78901234,string,12345,arraystring,this is a string ",a!,b#,c$,d,e$[5],f$
 PRINT "single! ",a!
 PRINT "double# ",b#
 PRINT "string$ ",c$
 PRINT "integer ",d%
 PRINT "array string ",e$[5]
 PRINT "string with spaces ",f$

Result


 single!  1.2
 double#  123456.78901234
 string$  string
 integer  12345
 array    arraystring
 sstring  this is a string
 

Example 3:


 CLS

 DIM a%
 DIM b!
 DIM c#
 INPUT "Type '1' then press ENTER  ",a%, b!, c#
 ? "====================="
 IF SCANERROR = -1 THEN PRINT "You did not enter enough data"
 ? "====================="
 ? a%
 ? b!
 ? c#
 ?

 INPUT "Now Type '1,2,3,4' then press ENTER  ",a%, b!, c#

 ? "====================="
 IF SCANERROR = 1 THEN PRINT "You entered too much data"
 ? "====================="
 ? a%
 ? b!
 ? c#

 INPUT "Finally, Type '1,2,3' then press ENTER  ",a%, b!, c#

 ? "====================="
 IF SCANERROR = 0 THEN PRINT "No data entry errors detected"
 ? "====================="
 ? a%
 ? b!
 ? c#

Result


 Type '1' then press ENTER  1
 =====================
 You did not enter enough data
 =====================
  1
  0
  0

 Now Type '1,2,3,4' then press ENTER  1,2,3,4
 =====================
 You entered too much data
 =====================
  1
  2
  3
 Finally, Type '1,2,3' then press ENTER  1,2,3
 =====================
 No data entry errors detected
 =====================
  1
  2
  3
 

BCX Console Sample Programs using INPUT statement.

S00.bas, S04.bas, S13.bas, S25.bas, S28.bas, S35.bas, S38.bas, S64.bas, S77.bas, S102.bas, S110.bas, S127.bas, S134.bas