INPUT, INPUTDW

INPUT, INPUTDW

Top  Previous  Next

 

The INPUT statement enables entry of data from the keyboard or from previously stored DATA statements. The INPUTDW statement is identical except that it limits data length based on display width.

 

 

Format

 

INPUT var {= default}{, length {, fill}} {_} {:} {modes}

{THEN statement(s)}

{ELSE statement(s)}

 

where

 

varis the variable in which the data is to be stored.

 

defaultis the default value to be used if the user enters a null response. This option provides compatibility with other multivalue products. To avoid a syntactic ambiguity, the default must be enclosed in round brackets if it is an expression.

 

lengthis the maximum number of characters to be allowed. In the INPUTDW statement, this is the maximum display width of the entered data.

 

fillis a Pick style fill expression. The first character will be used to fill any spare space in the input field to make the field width it clear to the user. The second character will be used to fill unused space after input is completed. If the fill string is only one character, spaces will be used. The third character, if present causes the cursor to be left at the end of the input field instead of the default action of leaving it after the last character of the entered data string. The fill option cannot be used with HIDDEN.

 

modesare any combination of the following keywords:
HIDDENechoes characters back to the screen as asterisks for password type fields.
NO.ECHOSuppresses echo of input data.
NO.ENCODINGSuppresses decode of encoded input when the terminal is set to operate in UTF-8 mode. Use of this mode will also suppress encoding of data echoed back to the terminal.
TIMEOUT waitSets a timeout period in seconds. If input is not received in this time, the INPUT terminates, leaving var unchanged. The keywords FOR or WAITING can be used in place of TIMEOUT for compatibility with other environments.
UPCASEconverts input data to uppercase.

 

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. For the INPUTDW statement, the length value specifies the maximum allowed display width of the data. If a double width character is entered when the remaining display width is one, the character is ignored and the operation continues to wait for a further character.

 

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 prompt character is not displayed. Unless the NO.ECHO.DATA mode of the $MODE compiler directive or the NO.ECHO.DATA setting of the OPTION command is enabled, 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.

 

 

See also:

KEYREADY()