INPUTIF Statement

The INPUTIF statement captures input from the type-ahead buffer and assigns the input to a variable.

Format

INPUTIF var [= expr] [,length-expr] [,fillchars] [_ ]

[:] [FROM line-expr]

   THEN/ELSE statement

END

Parameter(s)

var [= expr]

Assigns input data to variable var. If expr is specified, var is initially set to the value of expr, and characters in the type-ahead buffer are appended to that value.

length-expr

An expression, up to 140 characters, to be interpreted as the maximum number of characters to assign to var.

fillchars

An expression evaluating to a string of one, two, or three characters. The first character is taken as a background mask for the input field, and the second is used as an overstrike filler for portions of the field left unwritten. The cursor returns to the end of the input data unless there is a third fill character, in which case the cursor remains at the end of the formatted field.

_

An underscore specifies that a carriage return must be entered by the user, even if the input length equals length-expr. If the user tries to exceed the maximum length, a bell rings.

:

A colon suppresses the automatic line feed and carriage return when the value is input.

FROM line-expr

Take the input from the type-ahead of the attached line line-expr. If the line is not attached, a run-time error is printed and the mvBASIC Debugger is entered.

THEN statements

Executes statements if the type-ahead buffer is not empty.

ELSE statements

Executes statements if the type-ahead buffer is empty.

Description

The INPUTIF statement checks the type-ahead buffer, and if it is non-null, assigns the variable var initially with the contents of the type-ahead buffer and executes the THEN part of the statement. Unless a maximum length (length-expr) has been specified with no underscore (_), pressing ENTER is necessary. If there is no data in the type-ahead buffer, the variable is not assigned and the ELSE part of the statement is executed.

If the type-ahead buffer is empty, the variable is not assigned and the user is not prompted. However, if the type-ahead buffer is not empty, but a carriage return is required to complete the input, the user is prompted with the type-ahead buffer input.

The INPUTIF statement includes many features reflecting those of the standard INPUT statement. See INPUT Statement for more information.

The type-ahead feature can be controlled with the TA statement. The TA statement has options to turn on or off type-ahead and to clear the type-ahead buffer. Furthermore, the intrinsic function TA returns the number of characters in the type-ahead buffer.

See TA Statement for more information.

Example

To assign the variable TYPEA with the current contents of the type-ahead buffer and print "TYPE AHEAD EMPTY" if no data is received, the code would read:

INPUTIF TYPEA ELSE

   PRINT "TYPE AHEAD EMPTY"

END

In the next application a requested calculation may take several minutes to complete. The user is allowed to use the ESCAPE key to exit from the program, and the INPUTIF statement is repeated at every iteration to see if ESCAPE was entered in the type-ahead buffer.

PRINT "ENTER <ESC> TO EXIT."

LOOP

   .

   .

   .

   LOOP

      INPUTIF STOPVAR,1 :  THEN         

         IF STOPVAR = CHAR(27) THEN       

            GOSUB EXIT                   

         END

         TA.EMPTY = 0                  

      END ELSE

         TA.EMPTY = 1                

      END

   UNTIL TA.EMPTY DO REPEAT              

   .

   .

   .

UNTIL ...DO REPEAT

See Also

Statement and Function Reference