Commodore 2001-8 User Manual page 40

Table of Contents

Advertisement

This allows input of data from a pre-eonstructed form on the screen.
INPUT data may be delimited by commas as with the DATA statement. When more fields are provided
than are actually required, BAStC responds with
?EXTRA IGNORED
and takes only those characters it requires to satisfy the INPUT list.
On the other hand, when not enough data is inputted, BASIC witt respond with
1?
and begin blinking the cursor again to get additional input.
If an alphabetic field is encountered during the interpretation of a numeric field, BASIC responds with a:
?REDO FROM START
In PET, if input is fottowed by only a carriage return with no other typing, it is considered by BASIC to be a
termination of the program, same as a stop key. This particular feature is a carryover from the days of
teletype BASIC when this was the most convenient way of terminating a program.
The stop key is not operative while the PET waits for input.
INPUT has a special feature which allows you to indicate to the user what input characters are desired
and in what form they are to be. A literal which follows the input command is printed prior to the time the
carriage return is typed. For example:
10 INPUT "BIRTHDAY"; A
it would print:
BIRTHDAY?
and wait for you to input your birthday in standard numeric form to value A. Here is an example of IN PUT
to calculate the third leg of a right triangle:
10 INPUT "FIRST LEG"; A
20 INPUT "SECOND LEG";B
30IFA=OORB=OTHEN10
40? "THIRD IS"; SOR (A' A
+
B'BI
50 GOTO 10
If you run this program and put in values 3 and 4 respectively, you witt get a 5.
We can change our program to se how to combine values on a single line. We delete line 20, list line 10,
and change it to:
10 INPUT "FIRST LEG, SECOND LEG"; A, B
ThiS change, when you execute it, witt accept values typed as 3, 4. You will see that either form is
acceptable, however, good programming practice protects the user from getting confused as to how
many fields go on a particular line. although it is definitely not good programming practice, it is possible
to mix alpha and numeric values.
10 INPUT "NAME, BIRTHDAY"; A$, A
GET
A major problem with INPUT is that it does not allow real-time programming. All processing comes to a
grinding halt while the user takes his time to enter some characters and strike RETURN. PET BASIC has
been equipped with a special function which will yield one character at a time from the keyboard or tell
if a key has been pressed.
The command is GET. GET is identical in syntax to INPUT. It is possible to specify a list of variables but
36

Advertisement

Table of Contents
loading

This manual is also suitable for:

Pet 2001-8

Table of Contents