String Input

The READ, INPUT, DREAD, and INPUTE verbs may be used to request string data from a keyboard, file, or DATA statement and assign it to a string variable or a portion (substring) of it. Except in DATA statements, string constants are entered directly, without quotation marks. Any quotes entered are accepted as part of the string. It is up to the program logic to determine if the input makes sense.

Although PRO/5 does not provide for hexadecimal input it does provide functions ATH() and HTA() to assist in hexadecimal string manipulation.

In the program segment below, line 10 accepts a string from the keyboard into A$. Line 20 replaces the second and third characters of A$ with data entered at the keyboard.

0010 INPUT A$
0020 INPUT A$(2,2)

When accepting data into a substring, the string must be long enough that the reference to the substring is valid. In the example above, A$ must be at least three characters long before line 20, or an !ERROR=47 will occur. If additional data is entered, for example, if more than two characters are typed while line 20 above is executing, the extra data is truncated. If too little data is available, the remainder of the substring is padded with spaces.

String Input Verification

To assist in verifying the validity of string input data, PRO/5 provides string input verification. This feature may be used to impose a minimum and maximum length on the string, and/or branch on special values. The syntax for string verification is as follows:

strvar:({str=lineref {,str=lineref...}}{,len=minlength,maxlength})

The len=minlength,maxlength item must be last if it is included. It imposes length restrictions on the string, causing an !ERROR=48 condition if the actual input does not fall within the specified boundaries. For example, the following statement will accept only string from one to three characters in length.

0010 INPUT A$:(len=1,3)

The str=lineref items, if present, cause special branches to be taken in the event that the input exactly matches a specific string. Only string constants may be used in this context. Variables or other string expressions are not permitted. The comparison is case-sensitive.

The following example branches to line 100 if the input matches "one", to line 200 if the input matches "two", and otherwise completes without error, provided that the input does not exceed five characters in length.

0010 INPUT A$:("one"=0100,"two"=0200,len=0,5)

If the len= option is omitted, the input must match one of the str=lineref items, or an !ERROR=48 occurs.

When performing string input verification, PRO/5 follows this sequence of events:

  1. The input string is obtained.

  2. The input string is assigned to the variable or substring.

  3. Verification checks are performed, not against the variable or substring, but against the original input string.

    This is significant when a substring is being assigned, since the actual input data might not fit. When INPUTE is used, only the final edited string is assigned and verified.