4 Interaction between Programs and Forms
This syntax first outputs the prompt (either a ? or the prompt specified in the syntax) to the current output field and increments the output field pointer. The cursor then moves to the current tab field. When the user presses RETURN, the contents of the current field is input and the input field pointer is incremented. If more than one input item is in the item list, the next prompt (if any) is output. The output field pointer is incremented and the cursor moves to the next tab field. The input field pointer is incremented when an item is input to the program.
For example, assume the following form is used. The field following NAME is an input field. The field following SOCIAL SECURITY NUMBER is an output field.
NAME
SOCIAL SECURITY NUMBER ____________
Before the form is used, the input field pointer (IF#) is 1 and the output field pointer (OF#) is 1. The statement INPUT Name$ causes the form to appear as follows:
NAME
SOCIAL SECURITY NUMBER ? ____________
That is, the prompt (?) is output to the output field number 1 and the cursor appears in input field number 1. IF #=1, OF#=2. The user types in a name and presses RETURN.
NAME JOHN DOE
SOCIAL SECURITY NUMBER ? ____________
In this case, variable Name$ equals JOHN DOE, IF#=2 and OF#=2.
If the program attempted to output the social security number, an error would result because OF# is greater than the number of output fields.
If no parameters are specified in the INPUT statement, it will put the program in the input state and wait for RETURN to be pressed. No prompt is output. The input field pointer is not incremented. The INPUT statement should be followed by an ENTER statement in order for the program to receive the data input.
For example, assume a program uses the following form:
NAME
SOCIAL SECURITY NUMBER ____________
Before the form is used, IF#=1 and OF#=1.
When INPUT is executed, the cursor appears and the program waits for the user to enter a name and press RETURN.
NAME JOHN DOE
SOCIAL SECURITY NUMBER ____________
The IF#=1 and OF#=1, however, the program does not know the name that was entered.
ENTER inputs data from the display and continues program execution. The ENTER statement inputs the value of the current input field to the input list. The input field pointer is incremented. If there is more than one item in the input list, the next value, now pointed to by the input field pointer is the input and the input field pointer is again incremented.
For example, assume that this sequence is executed while the previous form is active:
300 INPUT 310 ENTER Name$Before INPUT is executed, IF#=1 and OF#=1.
NAME JOHN DOE
SOCIAL SECURITY NUMBER ____________
After ENTER is executed, IF#=2, OF#=1 and Name$=JOHN DOE. But if the form appeared as follows immediately before the ENTER statement was executed (the input field is blank):
NAME
SOCIAL SECURITY NUMBER ____________
Then after the ENTER statement is executed IF#=2, OF#=1 and Name$=" " (equal number of blanks as in the field).
PRINT print list
Each statement outputs to the current output field and increments the output pointer. If more than one item is in the list, the next item is output to the current output field and the output field pointer is incremented.
For example, assume that after the name is input, the program outputs the social security number. If an INPUT Name$ is used to input the name, the form looks as follows:
NAME JOHN DOE
SOCIAL SECURITY NUMBER ? ____________
Since IF#=2 and OF#=2, you cannot use the DISP statement here. But, if the INPUT with no prompt is used, the form looks as follows:
NAME JOHN DOE
SOCIAL SECURITY NUMBER ____________
Since IF#=2 and OF#=1, the program can use the DISP statement.
160 DISP "111-11-1111"
NAME JOHN DOE
SOCIAL SECURITY NUMBER 111-11-111
Now IF#=2 and OF#=2.
Moves the cursor to the first unprotected line following the form before outputting the display list. The output field pointer is not incremented.
Using the same example form shown previously, assume a program does not have a social security number for the name given, and wants the user to type in a number. The program can use LDISP.
300 LDISP "Please type in the social code."NAME JOHN DOE
SOCIAL SECURITY NUMBER ____________
Please type in the social security code. -
After LDISP is executed, IF#=2 and OF#=1.
The LENTER statement immediately inputs the current line on the display and continues program execution. If the cursor is in the form, an error occurs. Execution of LENTER does not affect the field pointers.
When executed, LINPUT moves the cursor to the first unprotected line following the form and outputs a line-output prompt. The entire line is returned when RETURN is pressed. The input field pointer is not incremented.
In the two previous examples, you saw how one statement, LDISP, would output without affecting the form or form pointers and how another statement, LENTER, would input. Instead of using these two statements, the program could use LINPUT.
Assume the form and display looks as follows:
NAME JOHN DOE
SOCIAL SECURITY NUMBER ____________
Now, IF#=2 and OF#=1.
The program executes the following statement.
100 LINPUT "please type in the social security code.",Ssnum$The form and display become:
NAME JOHN DOE
SOCIAL SECURITY NUMBER ____________
Please type in the social security code. -
Because a comma followed the prompt in the statement, the cursor moves to the next line. The user types in a number and presses RETURN. The IF#=2 and OF#=1.
If a semicolon (;) follows the LINPUT prompt, the cursor remains on the same line as the prompt. Then when RETURN is pressed, the entire line, including the prompt, is assigned to Ssnum$.