INPUT

Format

INPUT variable1 <--Format 1
INPUT variable1; <--Format 2

Description

This statement will retrieve a line of text from the input buffer and store it in variable1. There are two statement formats. When using Format 1, ASIC will first issue the prompt "?". It will then wait until the user enters a string or number and presses the <enter> or key. The type of data ASIC will expect is dependent on the type of variable1 (integer, decimal, or string). If an integer or decimal is being entered, ASIC will edit the input for validity. If the edit fails ASIC will issue another "?" to the user, and will wait for the number to be retyped. Only when a valid integer has been entered will variable1 be updated, and only then will control return to your ASIC program. Following a successful INPUT, ASIC will generate a carriage return/line feed sequence and advance the cursor to the next line. When using Format 2, ASIC will NOT issue a prompt. It will still edit the user input based on the type of variable. However, if the input is invalid it does not reprompt the user to re-enter the data. Instead, it will set the system ERROR variable to "1" and return control to your ASIC program. The value stored in variable1 will be undefined if the ERROR variable is set! ASIC will issue a carriage return, but it will NOT issue a line feed. Format 2 is useful when you want to use the INPUT statement with it's data edit capabilities in conjunction with a data entry form. In this case, you don't want ASIC to write any prompts to the screen, and you don't want ASIC to scroll the screen.

Example 1

PRINT "Enter a String";
INPUT A$
ASIC will issue the prompt:
    Enter a String?
It will then wait until you enter a string or press enter. If you pressed enter with no characters A$ would contain "" (i.e. its length would equal 0), otherwise A$ would contain the string entered.

Example 2

INPUT I
In this example ASIC will issue the prompt:
    ?

ASIC will then wait for you to enter a valid number. If you enter an invalid number, say "x", ASIC will reissue the "?" prompt and wait for you to retype your input. Once the input has been edited by ASIC, "I" would contain the number entered.

Example 3

LOOP:
PRINT "YOUR CHOICE?";
INPUT A;
IF ERROR=1 THEN
     PRINT "THE NUMBER YOU ENTERED WAS INVALID"
END IF
GOTO LOOP:
This example uses Format 2. Notice that since ASIC will not issue a prompt, we must include the "?" on the PRINT statement or it will not appear on the screen. Also note that errors fall through. If an error is detected the message "THE NUMBER YOU ENTERED WAS INVALID" will be displayed, and the program will branch to the label "LOOP:" to ask for the input again.

See Also

  • INKEY$