INPUT Statement

The INPUT statement requests terminal input from the user or from an attached line and assigns the input to a variable.

Format

INPUT var [= expr] [,length-expr] [, fillchars] [_] [:] [FROM line-expr].

Parameter(s)

var [= expr]

Assigns input data to variable var. If expr is specified, var is initially set to expr and the current value of expr is displayed on the screen as a default value. The user may then modify the default value before pressing ENTER, or accept it by pressing ENTER without modification.

length-expr

An expression, up to 140 characters, to be interpreted as the maximum number of characters to be input from the terminal. When this number of characters is input, the program automatically interprets a carriage return. If length-expr evaluates to 0 or 1, only one character is accepted. A length-expr of 0 differs from a length-expr of 1 in that control characters which are not normally returned may be read. These include BACKSPACE, ENTER, TAB, CTRL+R, etc. If the user does not wish to fill the input field, a carriage return may be entered manually.

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 attached line line-expr. If the line is not attached, a run-time error prints and the mvBASIC Debugger is entered.

Description

The INPUT statement pauses program execution and prompts for a response. Data entered at the terminal becomes the assigned value of the specified variable var.

Use the optional length-expr to specify the maximum length, or number of characters, allowed as input. When the specified number of characters is entered, an automatic carriage return and line feed are executed. An underscore (_) disables the automatic carriage return and line feed, and instead forces a beep to sound if the user tries to exceed the maximum length.

When the maximum length is exceeded, all subsequent characters are ignored except for the standard editing control characters, listed below.

Editing Control Characters

Character

Function

CTRL+H

Erase one character.

CTRL+J

Linefeed.

CTRL+M

Carriage return.

CTRL+R

Redisplay current input field.

CTRL+W

Erase one word.

CTRL+X

Clear entire input.

A fill character may be used to outline the length of the input field for the user. This allows the user to see the length of the input field. If a second character is specified, it is used to fill the unused portion of the field after the user presses ENTER. If a third character is specified, the cursor remains at the end of the formatted field after the excess part of the input field is struck over; otherwise, it returns to the end of the input data. (The actual value of the third character is not significant.)

The INPUT statement causes only the prompt character to be printed on the screen. The default prompt character is a question mark (?), but it may be reassigned with the PROMPT statement, which is described in this section. A PRINT statement must be used before the INPUT statement in order to tell the user what sort of input is required.

Typing ahead is permitted for INPUT statements. This feature allows users who are familiar with the sequence of prompts to save time by entering data at their own pace, before all of the prompts are displayed. Data is accepted as responses to INPUT statements in the order in which they are entered. The TA statement allows the programmer to manipulate the type-ahead feature, and the INPUTIF statement is a special statement which takes input only from the type-ahead buffer.

Example

To ask the user to supply a name, the program might read:

PRINT "ENTER YOUR NAME"

INPUT NAME

If the name cannot exceed 20 characters, the input line might read:

INPUT NAME, 20_

If the user tries to enter more than 20 characters, a beep sounds.

To prompt the user to respond either Y for yes or N for no, the program might read:

PRINT "DO YOU WANT TO EXIT (Y OR N)?"

INPUT ANSWER, 1

The first character the user types is accepted, and the program continues. No carriage return is necessary.

In the next application, a customer is prompted for changes in his billing information. The example also makes use of the PRINT statement with the @ function, generating a formatted screen.

OPEN “CUSTOMERS” TO CUSTFILE ELSE

   ABORT 201, “CUSTOMERS”

END

LOOP

   PRINT @(-1): @(10,10) : "ENTER YOUR ACCOUNT

      NUMBER :  " :

   INPUT ACCT, 6 , "?"_

WHILE NOT(NUM(ACCT)) OR LEN(ACCT)<>6 DO

   PRINT @(0,23) : "PLEASE ENTER A 6-DIGIT

       ACCOUNT NUMBER" :

REPEAT

PRINT @(0,23):@(-4)

READ CUST.REC FROM CUSTFILE,ACCT THEN

   PRINT @(10,11) : "HAS YOUR BILLING CHANGED

       (Y OR N)" :

   INPUT ANSWER,1

   CHANGE = (ANSWER=‘Y’)

END ELSE

   CUST.REC = ""

   CHANGE = 1

END   

IF CHANGE THEN  

   LOOP

      PRINT @(-1) :  

      PRINT @(5,5) : "MODIFY AS NEEDED : " :   

      PRINT @(10,10) : "NAME :  " : @(30,10)  :     

      INPUT NAME = CUST.REC<1> :

      PRINT @(10,12) : "ADDRESS :  " : @(30,12)  :

      INPUT ADDRESS = CUST.REC<2> :

      PRINT @(10,14) : "CITY,STATE,ZIP :  " :

         @(30,14)  :

      INPUT CSZ = CUST.REC<3> :

      PRINT       

      CUST.REC<1> = NAME

      CUST.REC<2> = ADDRESS

      CUST.REC<3> = CSZ

      PRINT @(-1) : @(5,5) : "CURRENT CONTENTS : "

      FOR I = 1 TO 3

         PRINT @(15,10 + 2 * I ) : CUST.REC<I> :

      NEXT I      

      PRINT @(0,23) : "IS THIS CORRECT (Y OR N)?"  :

      INPUT ANSWER,1                       

   UNTIL ANSWER = ‘Y’ DO REPEAT

   WRITE CUST.REC ON CUSTFILE, ACCT       

END

In the preceding example, the INPUT statement is first used to record the customer’s account number. The account number must be a number of 6 digits. For clarification, 6 question marks are printed to the screen after the prompt, and the user may then write over those question marks. Since it is important that the correct account number be entered, the automatic linefeed and carriage return is suppressed with the underscore (_). What the user sees is:

ENTER YOUR ACCOUNT NUMBER: ??????

If the account is already on file, the INPUT statement is next used to find out if the customer's billing information has changed. Since a yes or no answer suffices, only one character is accepted and the automatic linefeed and carriage return is enabled.

The INPUT statement is then used to allow the customer to change his or her billing information. For each field the current contents are printed and the user has the option of accepting it or modifying it. If the correct information is on file, only pressing ENTER is necessary; if the information needs to be adapted, the user may use the backspace key to modify the field before pressing ENTER. For example, for the first such field what the user might see (with user input in bold) is:

MODIFY AS NEEDED:

   NAME: BETSY ROSS_

The prompt, represented here by the underscore, waits at the end of the input field. The customer may now use the backspace key to erase the field and enter a different name, or change the one already on file. When the customer is satisfied with the contents of the NAME field, ENTER can be pressed to record it. This process repeats for each field. At the end of the loop, the modified contents of the array are printed for the user to verify before continuing with the program.

See Also

Statement and Function Reference