LInput

From BR Wiki
Jump to navigation Jump to search

The LInput (LI) statement (line input) assigns a value to a string variable by reading an entire line or record from the keyboard, a procedure file (when RUN PROC is in effect), a display file, a communications file or a window file.

Comments and Examples

The LInput statement can be used with a file number of zero (i.e., #0) or without any file number to accept data from the keyboard. See the INPUT statement for a more detailed description of keyboard input.

The LInput statement is like the INPUT statement except that it allows input to only one item which must be a string variable. Also, the input may include commas and all other punctuation, including leading blanks and quotes. Since the INPUT statement uses commas to separate data entries, strings entered through the INPUT statement cannot include commas.

For example, to accept a city and state with INPUT to construct an address line on a mailing label, a program could have the following lines:

00100 PRINT "Enter CITY"
00110 INPUT CITY$
00120 PRINT "Enter STATE"
00130 INPUT STATE$
00140 LINE3$ = CITY$ & ", " & STATE$

This same function could be accomplished using LINPUT as follows:

00100 PRINT "Enter CITY, STATE"
00110 LINPUT LINE3$

Syntax

LINPUT [#{<window number>|<file number>}:] <string variable> [[, WAIT=<seconds>]] [<error condition> <line ref>][,...]

Parameters

The optional "file-num" parameter is an integer or numeric expression that matches this LINPUT statement with a display file (or communications file). If "file-num" is omitted, LINPUT defaults to keyboard input. When specified, the file number must correspond to a display file that has already been opened by an OPEN statement with this same file number.

The "string-var" parameter is required; it represents either an unsubscripted or subscripted string variable.

"WAIT=seconds" specifies the number of seconds the system should wait for operator input before responding with a TIMEOUT error condition. WAIT=0 instructs the system to wait for zero seconds, not to ignore the WAIT instruction. Also, -1 instructs the system to wait forever if necessary.

LINPUT allows error processing with the optional "error-cond line-ref" parameter. See Error Conditions for more information.

Defaults

  1. Accept input from the keyboard or procedure file. (See the RUN command for procedure file input.)
  2. Interrupt the program if an error occurs and "ON error" is not active.

Technical Considerations

  1. Relevant error conditions are: EOF, ERROR, Exit, HELP, IOERR, and SOFLOW.
  2. For processing an entire record, LINPUT is preferred to INPUT unless the fields in the input data are separated by commas.
  3. When merely waiting for any operator response, use LINPUT A$ instead of INPUT A$ to avoid error code 0501.
  4. LINPUT should be used instead of INPUT with EOL=NONE for display files (or communications files). With EOL=NONE, LINPUT will read characters until the maximum string length is reached.
  5. If either EOL=CRLF (the DOS default) or EOL=LF (the Unix / Linux default) is specified in the OPEN statement, LINPUT accepts either CR + LF or just LF as a valid delimiters and removes them from incoming data.
  6. The number of characters that can be entered is limited to the maximum dimensioned length of the string variable.
  7. It is permissible to use LINPUT to input strings longer than or shorter than RECL (regardless of the EOL= parameter) because RECL only affects output.
  8. If a program is loaded from a procedure file and started with the command RUN PROC, all LINPUT statements which expect input from the keyboard are directed by the RUN PROC command to take their input from the next records of the procedure file.
  9. Unlike the INPUT statement, LINPUT does not terminate input when a forward slash (/) is entered at the end of a line.
  10. In terms of keyboard buffering, LINPUT operates the same as INPUT.
  11. See also the INPUT statement and the Communications section.
  12. The WAIT= parameter and TIMEOUT error trap can be used with INPUT/RINPUT statements to force releasing of records. This feature is useful for multi-user situations.WAIT Specifies the number of seconds the system should wait for operator input before responding with a TIMEOUT error condition. NOTE that WAIT=0 instructs the system to wait for zero seconds, not to ignore the WAIT instruction. Also, -1 is a special WAIT value that instructs the system to wait forever, if necessary. Every time the operator presses any key, the clock is reset for WAIT seconds.
00100 INPUT WAIT=10:X$ TIMEOUT 100
00110 RINPUT WAIT=10:X$ TIMEOUT 100
00120 LINPUT WAIT=10:X$ TIMEOUT 100
00130 INPUT FIELDS "10,10,C 10",WAIT=10:X$ TIMEOUT 100
00140 INPUT #11,FIELDS "10,10,C 10",WAIT=10:X$ TIMEOUT 100
00150 RINPUT FIELDS "10,10,C 10",WAIT=10:X$ TIMEOUT 100
00160 INPUT SELECT "10,10,C 10",WAIT=10:X$ TIMEOUT 100
00170 RINPUT #11,SELECT "10,10,C 10",WAIT=10:X$ TIMEOUT 100

The TIMEOUT error condition traps time-out errors ( error code 4145) and specifies the line number of an appropriate error-handling routine.

00100 RELEASE #ITEM:
00110 PRINT "OVER TIME LIMIT"
00120 PRINT "Your hold on inventory items has expired, re-enter order."

Before releasing the record, you may want to go to a routine that warns with a message and a few beeps that the hold on records is about to be released, then gives the operator an opportunity to continue data entry. See the "KSTAT$" function for information on how to use the WAIT parameter with that function.

13.) You can input a string array using LINPUT when using a file for input. Each line in the file is input for each element of the array. The string must be long enough to input each line in the file to avoid string overflow. If there are not enough lines in the file to fill the array, an EOF error is given after whatever lines are available are input.