HP 3000 Manuals

Input from the Keyboard or Input File [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation


HP Business BASIC/XL Reference Manual

Input from the Keyboard or Input File 

This section describes the use of the ACCEPT, INPUT, LINPUT, and TINPUT
statements.  These statements are defined in chapter 4.  If HP Business
BASIC/XL is running interactively, these statements accept input from a
terminal keyboard.  Each of these statements suspends an executing
program so that you can enter values on the keyboard.

The program is in the input state while it is suspended waiting for
input.  The input state ends when you press RETURN. The input consists of
all characters that you type before pressing RETURN. ACCEPT and TINPUT
optionally allow the programmer to specify the length of the input item.
The program leaves the input state when the designated number of
characters is entered.

If HP Business BASIC/XL is running in a job stream, these statements take
input from the job stream file or an input file.  The input is obtained
from the next record in the appropriate file.

The ACCEPT, INPUT, LINPUT, and TINPUT statements differ in the type of
input that they accept and whether they echo input to the display.
Options are available to print a specific prompt on the terminal, specify
the maximum time allowed for input, monitor the amount of time required
for input, specify the maximum input length, and suppress the line feed
following input.  Table 6-1, Table 6-2, and Table 6-3 present this
information.

          Table 6-1.  Keyboard Input Statements 

-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
|     Statement     |          Acceptable Input          |   Variable(s) to Which Statement   |
|                   |                                    |          Can Assign Input          |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| ACCEPT            | Characters from ASCII or default   | One string variable.               |
|                   | foreign character set.             |                                    |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| INPUT             | List of literals.                  | One or more scalar variables,      |
|                   |                                    | array elements, or arrays.         |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| LINPUT            | String literal.                    | One scalar string variable or      |
|                   |                                    | string array element.              |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| TINPUT            | Literal.                           | One scalar variable or array       |
|                   |                                    | element.                           |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------

          Table 6-2.  Keyboard Input Statements 

----------------------------------------------------------------------------------------------
|                                    |                           |                           |
|             Statement              |   Echo Input to Display   |    Print a Prompt for     |
|                                    |                           |      Terminal Input       |
|                                    |                           |                           |
----------------------------------------------------------------------------------------------
|                                    |                           |                           |
|               ACCEPT               |            No             |            No             |
|                                    |                           |                           |
----------------------------------------------------------------------------------------------
|                                    |                           |                           |
|               INPUT                |            Yes            |            Yes            |
|                                    |                           |                           |
----------------------------------------------------------------------------------------------
|                                    |                           |                           |
|               LINPUT               |            Yes            |            Yes            |
|                                    |                           |                           |
----------------------------------------------------------------------------------------------
|                                    |                           |                           |
|               TINPUT               |            Yes            |            No             |
|                                    |                           |                           |
----------------------------------------------------------------------------------------------

          Table 6-3.  Keyboard Input Statement Options 

-----------------------------------------------------------------------------------------------------
|                   |                   |                   |                   |                   |
|     Statement     |      Specify      |   Monitor Time    |      Specify      |    Suppress LF    |
|                   |   Maximum Input   |   Required for    |   Maximum Input   |     Following     |
|                   |   Time Allowed    |       Input       |      Length       |       Input       |
|                   |                   |                   |                   |                   |
-----------------------------------------------------------------------------------------------------
|                   |                   |                   |                   |                   |
|      ACCEPT       |        Yes        |        Yes        |        Yes        |        Yes        |
|                   |                   |                   |                   |                   |
-----------------------------------------------------------------------------------------------------
|                   |                   |                   |                   |                   |
|       INPUT       |        No         |        No         |        No         |        No         |
|                   |                   |                   |                   |                   |
-----------------------------------------------------------------------------------------------------
|                   |                   |                   |                   |                   |
|      LINPUT       |        No         |        No         |        No         |        No         |
|                   |                   |                   |                   |                   |
-----------------------------------------------------------------------------------------------------
|                   |                   |                   |                   |                   |
|      TINPUT       |        Yes        |        Yes        |        Yes        |        Yes        |
|                   |                   |                   |                   |                   |
-----------------------------------------------------------------------------------------------------

Input Prompt 

This section explains how prompts are displayed when HP Business BASIC/XL
is running interactively.  Input prompts are not displayed if HP Business
BASIC/XL is running in a job stream.

A prompt can be supplied for each input element except within a FOR
clause.  The default prompt is a question mark.

Table 6-4 shows how the prompt option and the separator that follows
affect the cursor position.

          Table 6-4.  Effect of Input Prompt and Separator on Cursor 

------------------------------------------------------------------------------------------------
|              |                           |              |                                    |
|  Is Prompt   |        Prompt that        |  Separator   |     Where HP Business BASIC/XL     |
|  Supplied?   |   HP Business BASIC/XL    |  Following   |       Puts the Cursor After        |
|              |           Uses            |    Prompt    |  Printing the Prompt and Putting   |
|              |                           |              |   the Program in the Input State   |
|              |                           |              |                                    |
------------------------------------------------------------------------------------------------
|              |                           |              |                                    |
|     Yes      | The prompt that was       | ;            | HP Business BASIC/XL does not move |
|              | supplied.                 |              | the cursor.                        |
|              |                           |              |                                    |
------------------------------------------------------------------------------------------------
|              |                           |              |                                    |
|     Yes      | The prompt that was       | ,            | At the beginning of the next line. |
|              | supplied.                 |              |                                    |
|              |                           |              |                                    |
------------------------------------------------------------------------------------------------
|              |                           |              |                                    |
|     Yes      | The prompt that was       | None         | At the beginning of the next line. |
|              | supplied.                 |              |                                    |
|              |                           |              |                                    |
------------------------------------------------------------------------------------------------
|              |                           |              |                                    |
|      No      | Question mark (?).        | Not          | At the beginning of the next line. |
|              |                           | applicable   |                                    |
|              |                           |              |                                    |
------------------------------------------------------------------------------------------------

Interactive Input from a Terminal 

This section explains how to enter input when HP Business BASIC/XL is
running interactively.  The rules for input from a keyboard also apply to
input from an input file.

After the INPUT statement displays a prompt and puts the program into the
input state, you can type values on the terminal keyboard.  Individual
values are separated by commas or semicolons.  If numeric values are
expressed in European format where either a comma or period is the radix
indicator, then input values must be separated with semicolons.

Double quotes surrounding string values are optional.  The string must be
enclosed in quotes if it contains a comma, a semicolon, or leading or
trailing blanks.  Otherwise, these symbols are interpreted as item
separators.  If a string value that is enclosed in quotes contains a
quote, the quote that it contains must be duplicated; for example, the
unquoted string

"Hi," he said.

must be quoted (because it contains a comma), and the quotes that it
contains must be duplicated:

"""Hi,"" he said."

Variable Assignment during Interactive Input 

When you press RETURN, the INPUT statement assigns the values to the
variables specified by the input list.  The first value input is assigned
to the leftmost variable in the input list, the second value to the next
variable, and so on.

If you type more values than the number of variables listed in the input
list, the INPUT statement ignores the extra values.  If you type fewer
values than the number of variables listed in the input list, the INPUT
statement prompts you for more values until values have been assigned to
all variables.  If the input list contains an array reference, you must
input one value for each array element.  If a user prompt is not
specified for the additional variables requiring values, the prompt is
??.

If you input a value that cannot be assigned to its corresponding
variable; for example, you input a string for a numeric variable, the
INPUT statement reprompts you.  Assignments to preceding variables are
not affected.

Job Stream Input 

This section explains how the INPUT statement reads input when HP
Business BASIC/XL is running in a job stream.  The input for an input
statement in a jobstream is either included in the stream file or
obtained from a file specified by a redirection of the interpreter's
input.  The method of redirecting the interpreter's input is discussed at
the beginning of chapter 2.  Here, we discuss the method for including
the input for INPUT statements in a stream file.  The records in the job
stream file immediately following the command that begins program
execution are used to satisfy the input items for the INPUT statement.
The values in the stream file are separated by commas, semicolons, or EOR
marks.  HP Business BASIC/XL suppresses prompts specified in any prompt
option in an INPUT statement when HP Business BASIC/XL is running a
stream job.

Variable Assignment during Job Stream Input 

The INPUT statement assigns the values in the job stream file to the
variables specified in the input list.  The first value in the stream
file record is assigned to the leftmost variable in the input list, the
second value to the next variable, and so on.

If the record in the stream file has more values than the number of
variables in the input list, the additional values are ignored.  If the
record has fewer values than the input list needs, HP Business BASIC/XL
reads the next record to find additional values.  If records or values
are not found, an error occurs.  If the input list contains an array
reference, the record must contain one value for each array element.
Colons in the INPUT statement save unassigned input values or use input
values saved from previous INPUT statements.

If a value in the input file record cannot be assigned to its
corresponding variable, HP Business BASIC/XL aborts the program.  This
occurs if the record contains a string value that is to be assigned to a
numeric variable.

If numeric values are expressed in the format in which a comma is the
radix indicator, then input values must be separated with semicolons or
EOR marks.

The rules for string input from a job stream file are the same as the
rules for string input during an interactive session from a terminal.



MPE/iX 5.0 Documentation