INPUT |
![]() ![]() ![]() |
The INPUT statement enables entry of data from the keyboard or from previously stored DATA statements.
Format
INPUT var {, length} {_} {:} {TIMEOUT wait} {HIDDEN} {UPCASE} {THEN statement(s)} {ELSE statement(s)}
where
The optional THEN and ELSE clauses used with TIMEOUT allow a program to determine whether the input timed out. Successful input executes the THEN clause. A timeout will execute the ELSE clause.
The INPUT statement reads data from the DATA queue or, if there is no stored data, from the keyboard.
Keyboard Input
When taking input from the keyboard, the current prompt character will be displayed prior to reading data. The values stored for printing characters are the ASCII characters associated with the key. Non-printing characters result in other stored character values.
If no length expression is included, data characters are stored until the return key is pressed.
If length is specified, up to that number of characters may be entered after which input is automatically terminated as though the return key had been pressed, any subsequent key entries being retained for the next INPUT statement. The return key is not stored as part of the input data.
The optional underscore component of the statement suppresses the automatic input termination when length characters have been entered. Any number of characters may be entered but only length characters will be displayed.
The optional colon causes the carriage return and line feed output when the return key is used or on reaching the input length limit to be suppressed.
The INPUT statement recognises the backspace key, allowing this to be used to correct data entry errors. The terminfo system allows the code sent by the backspace key to be redefined from its default char(8). If an alternative, single byte definition is used, INPUT will honour this, otherwise char(8) is used as the backspace.
DATA Queue Input
Where the data queue is not empty, the INPUT statement reads the item at the head of this queue, copying it verbatim to var with no processing of any embedded control characters. The length expression is ignored. The item is displayed as though it had been typed.
Testing for Input
The INPUT statement may be used to test whether there are characters waiting to be read from the keyboard or the data queue by using a negative length value. For example, the statement
INPUT S, -1
will set S to 1 if there is data waiting, 0 if no data is waiting.
Use of Pipes
QM recognises input from pipes as a special case. Programs that process data from a pipe can read the data using the same QMBasic statements and functions as for keyboard input. If the end of the data is reached, a subsequent INPUT will return a null string. The STATUS() function will return ER$EOF.
Examples
INPUT ACCOUNT.NO, 10
This statement reads data into ACCOUNT.NO with a maximum length of 10 characters.
DISPLAY @(0,24) :"Continue?" : INPUT S:
This program fragment displays a query message on the bottom line of the screen and reads a response. Note the trailing colon in the INPUT statement to suppress the line feed which would cause the screen to roll up as output was to the bottom line of the display. |