INPUT Statement
Requests data input from the terminal or from the data stack (see also INPUT@ statement).
Syntax
INPUT variable{,length}{:}{_} {WITH delimMask} {FOR time [THEN statement(s) | ELSE statement(s)]}
Syntax elements
variable A variable or array element to which the value or string entered is assigned.
length The maximum number of characters to be entered, after which the input is automatically completed and a RETURN is executed, unless an underscore (see below) is also used. This is useful when programming fixed length input fields, as no delimiter needs to be entered. The maximum, and default, length is 240 characters.
: Inhibits the output of the carriage return/line feed sequence. The cursor remains positioned after the value is input. This is useful when programming multiple inputs on one line.
_ Valid only with an explicit length. When that number of characters has been input, the program waits for a delimiter (see delimMask). Any other character sounds the terminal bell.
delimMask Specifies a read mask to define input delimiters (maximum 256-characters). When a character in the mask is entered, INPUT returns, setting variable to the characters entered before the delimiter.
If delimMask is used, the default delimiter of RETURN or LINEFEED is overridden. If you want these to be input delimiters, you must include them in delimMask (as CHAR(13) or CHAR(10) respectively). delimMask is specified as a series of concatenated characters (see Examples).
FOR timeOptionally specifies how long the system waits for input before returning. time is specified in tenths of a second as a integer between 1 and 30,000.
-
If time is less than 1 or the FOR clause is omitted, the result is no time-out.
-
For values greater than 30,000, 30,000 is used.
A value of 30,000 corresponds to 50 minutes.
Note
This behaviour can be changed with the INPUTTOUT compatibility option.
statement(s) Either a THEN or ELSE clause (or both). At least one of these must be included if a FOR clause is used. The THEN clause is executed if input is completed within time. The ELSE clause is executed otherwise.
Operation
INPUT displays a prompt character at the user's terminal, as defined by the PROMPT statement (default is a question mark - ?). The user types in a number or a string that is assigned to variable. If just a delimiter is entered, a null string is assigned to variable.
The process first looks at the data stack to see if data is present. Data is placed in the data stack by a DATA statement or by loading the secondary output buffer while in a Proc. If data is present in the stack, the first attribute in the stack is assigned to variable and no prompt is displayed on the terminal.
Case Insensitivity
By default, the characters in delimMask are case sensitive. For a case insensitive match, either include both upper and lower case characters in delimMask or select data case insensitive mode (see Case Sensitivity).
Examples
INPUT VAR
Requests a value for variable VAR.
L=3
INPUT X,L
Requests input for variable X. When three characters have been entered, RETURN is executed automatically.
INPUT Y:
Requests input for variable Y. No RETURN is echoed after the value is entered.
INPUT VAR,2_ FOR 50 ELSE GO 99
Waits five seconds for the user to enter up to two characters followed by a RETURN or LINEFEED. If the five seconds elapse and nothing is input, control transfers to the statement at label 99. The underscore (_) here means that RETURN/linefeed must be entered to validly complete the input.
INPUT STRING,8 WITH "./":CHAR(13) FOR 100 THEN PRINT "STRING WAS INPUT IN TIME" END ELSE PRINT "INPUT TOO SLOW" END
Prompts for a string no longer than 8 characters. If no input has been entered after 10 seconds, the ELSE clause is taken; otherwise, the THEN clause is executed. To terminate input, type a period (.), a slash (/), or a RETURN (CHAR(13)).
INPUT A,1: WITH CHAR(25)
In this example, a single character is required for variable A, terminated by CTRL+Y (CHAR(25)). However, RETURN or LINEFEED are also valid as input (not as delimiters), because the delimiter mask is set to a value other than that for RETURN or LINEFEED (CHAR(13) and CHAR(10) respectively).