# input statement

The input statement temporarily suspends execution of the program
 until a response is provided from the keyboard, and then assigns that response to a specified
 variable.

## Syntax

```
 input {@(col.exp,{row.exp}):} var{= val.exp} {,length.exp} {,fill.exp} {:|mask} {_}
{for time.exp{then|else statement.block}}
```

 Note the following information:

- The trailing colon and mask cannot be used together.

- The colon and the underscore can be reversed in the syntax with no difference in the results.

## mvBase compatibility mode only Syntax

```
 input {@(col.exp,{row.exp}):} var{= val.exp} {,length.exp} {,fill.exp} {:} {_}
 {on timeout statement.block}}
```

## Parameter(s)

| : | Suppresses the CR/LF after input has been completed. |
| --- | --- |
| =val.exp | Sets a default value for the input field. This value displays within the input field and the user can edit this value as need be. If no editing is performed, then the default value is accepted as if the user had typed that value at the keyboard. |
| length.exp | Specifies the number of characters of input to accept. When the number of characters have been entered, the input instruction terminates exactly as though the operator had pressed Enter. |
| fill.exp | Specifies to perform a background fill within the input field. The first character of this expression indicates the prompt background fill character. This character is used to help the user see the length of a prompt. The second character, if present, indicates the overstrike character used to fill in any spaces when the input is accepted. After input is accepted, the cursor is placed at the end of the entered data unless a third fill character is specified.In this case, the cursor is moved to the end of the input field. fill.exp is ignored if no length.exp is specified. |
| _ | Outputs a beep to the terminal for each character typed that exceeds the specified maximum length. Echoing of characters to the screen is suppressed for the extra characters and pressing Enter is required for acceptance. Only the number of characters less than or equal to the length expression are accepted. |
| for time.exp | Maximum time that the system waits for input before returning to the FlashBASIC or BASIC program until any of the events below occur: When a valid termination occurs. The then clause is taken. When no carriage return is entered, even though input continues, and no valid termination occurs within the specified time. The variable contains all characters entered until the time expired. If no characters are in the type-ahead buffer, variable is null. Upon time-out, the else clause is taken. When not enough characters are entered to satisfy the length requirement within the allocated time, the else clause is taken. WARNING—For Windows, this expression is not supported for pib 0 or RPC processes. |
| on timeout | This clause is only available when running in mvBase Compatibility Mode. The timeout value is set up from a prior TIMEOUT statement. When no input occurs for the timeout value specified, the statement block following the on timeout clause is executed. |
| col.exp | In the input @ form, specifies the screen column address from which the input of data from the terminal is prompted. |
| row.exp | In the input @ form, specifies the screen row address from which the input of data from the terminal is prompted. |
| mask | In the input @ form, mask is used to verify and reformat the actual entry of the data. Any valid format string can be specified. The input is verified against the mask and, if acceptable, is assigned to the variable. Data is input and verified according to the mask, then stripped of its output characteristics and stored in internal format. For example, if the mask contains a decimal digit specification and/or a scaling factor, then numeric checking is performed. If the mask contains a length specification, then length checking is performed. |

## Description

*col.exp* and *row.exp* must evaluate to valid screen
 addresses.

The input received is assigned to the specified variable after performing the optional
 mask() function. The mask can contain any valid mask
 described under masking except for masks beginning with a `c`. If the
 variable already has a value, and the @() function has been
 specified, the current value of the variable displays as the default at the
 specified cursor address. Pressing Enter accepts the default.

A *length.exp* of 0 is allowed.

- When there is no stacked data, a single character will be read from the terminal. Control characters are allowed.

- When there is stacked data, one character will be read from the stack.

This syntax is more consistent with other implementations of D3. This
 suppresses the automatic carriage return after single-character input (that is,
 holds the cursor position).

If the input data value is incompatible with the optionally-specified *mask*
 expression, the statement prompts again for input. mask()
 functions can be any combination of conversions, pattern-matching operators, or text
 justification.

When an input statement is executed, a prompt character displays, followed by
the cursor. If the @() function is used, the prompt
displays preceding the location specified by @(). Unless the prompt character has been changed with the prompt statement, the default prompt character is the ?.

*time.exp* is represented in tenths of a second, as a positive integer from 1
 through 32767. Depending on the implementation, there can be significant
 restrictions on the admissible values for *time.exp*.

- If time.exp is 0 and there are characters in the input buffer, these characters are returned immediately when a valid termination criterion is met and the then clause is taken.

- If time.exp is 0 and there is no character waiting in the input buffer, the input statement returns immediately and the else clause is taken.

- If time.exp is negative, no time-out is in effect.

 Some implementations round *time.exp* to the nearest second.

The then clause is taken if valid
input is completed within the allocated time. The else clause is taken if there is no input, insufficient input, or when
a noncarriage-return terminated input occurs in the allocated time.

Note: On some UNIX implementations, the *time.exp*, if not null, is rounded up to
 the nearest second.

Due to the way UNIX schedules processes, there is no
guarantee that, in case of a time-out, the process activates at exactly
the specified time. There can be significant differences if the system
is heavily loaded.

There are some limitations on the types of numeric expressions used to designate the
 *length.exp*. For example, the statement input x,2*3 does
 not work, whereas the statement input x,(2*3) works.

The input x,0 suppresses the prompt character
and allows the input of certain control characters that were previously
blocked, such as CTRL+X. Carriage return and linefeed return char(13) and char(10), respectively. CTRL+S and CTRL+Q are used for flow control and return
no value unless xonoff is disabled.

## Example(s)

`answer` is the
first character entered from the keyboard. No Enter is required.

```

 print ’are you sure? ’:
 input answer
 if answer[1,1]=’y’ then goto 100
 print ’are you sure? ’:
 input answer,1:
```

```

 input x,0
 x = seq(x)
```
These two lines perform exactly the same as:

```

 in x
```
Using 0 as a length expression is valid.

```

 input x for 50 else stop
```
Wait 5 seconds for input. If there is no input, terminated
by a carriage return, the program stops.

```

 input x for 0 then print x else x = 0
```
The time-out value equal to 0 means read characters without
waiting. If there is any, the then clause is taken,
otherwise the else clause is taken.

```

 print "Enter Cost ":
 input @(5,5):cost "r2$"
```
Example A and Example B use masking. The previous mask `"r2$"` right justifies,
 uses two decimal places, and puts a `$` on the left of the forced
 numeric entry.

- Example A: A colon underscore ":_" is used.

- Example B: An underscore colon "_:" is used. Both are valid.

 **Example A**

```
print @(5,5):"Name: ":
input name.new = item<3>, 20 ,"_ " :_
item<3> = name.new
```

 **Example B**

```
print @(5,5):"Name: ":
input name.new = item<3>, 20 ,"_ " _:
item<3> = name.new
```
This displays a prompt for a name on a formatted screen. The data to be edited displays as though
 the user already typed it in a field of 20 underscores (the first character in
 *fill.exp*). As the user edits the data (when backspace is
 used), underscores replace any erased data. When complete, the user must press Enter
 or LINEFEED. The data is then repainted and the underscores are replaced with spaces
 (the second character of *fill.exp*).

## See also

- [: relational operator](https://d3codex.com/pickbasic-flashbasic/colon-relational-operator/)
- [@() function](https://d3codex.com/pickbasic-flashbasic/at-parenthesis-function/)
- [get statement](https://d3codex.com/pickbasic-flashbasic/get-statement/)
- [in statement](https://d3codex.com/pickbasic-flashbasic/in-statement/)
- [inputctrl statement](https://d3codex.com/pickbasic-flashbasic/inputctrl-statement/)
- [inputnull statement](https://d3codex.com/pickbasic-flashbasic/inputnull-statement/)
- [inputtrap...gosub statement](https://d3codex.com/pickbasic-flashbasic/inputtrap-gosub-statement/)
- [Masking](https://d3codex.com/pickbasic-flashbasic/masking/)
- [statement blocks](https://d3codex.com/pickbasic-flashbasic/statement-blocks/)
- [Statements and functions](https://d3codex.com/pickbasic-flashbasic/statements-and-functions/)
- [then/else statement blocks](https://d3codex.com/pickbasic-flashbasic/then-else-statement-blocks/)
- [u6070 user exit](https://d3codex.com/access/u6070-user-exit/)
- [u7070 user exit](https://d3codex.com/access/u7070-user-exit/)

---
Source: https://d3codex.com/pickbasic-flashbasic/input-statement/ - part of the D3Codex reference.
