TECHNICAL NOTES

INPUT - By Example

A program has many parts. A part common to most sophicated programs is prompting the user for the inputs required for the program to do its job. Simple programs may start assuming that the proper information is on the stack when the program is executed. An example is a program called 'M^YR'. This is a calendar program that displays a calendar assuming that the month (number 1 thru 12) is on level two and the year (1993 for example) is on level one. This is the ultimate in simplicity - once you know the program and have run it a couple of times. The name of the program also contains the instructions on how to run it. The abbreviation YR identifies it in you mind. The letter M is associated with year as month. Most programs do not lend themselves to such simplicity. What you will normally use is a prompting display that also sets up the calculator to receive the inputs. You will also want to provide simple instructions to the user as to what to do. All of these things are taken care of by the INPUT command. This five letter command does so much it requires a few examples to illustrate.

In a program INPUT looks like this:

<< . . . "prompt-string" "command-line" INPUT . . . >>

This is one of two variations. Let's explore this two string version first.

The INPUT command causes the program to stop running. It displays the the prompt-string and starts the command line with the command-line string. The user is expected to respond by pressing one or more keys followed by ENTER. Since the command line is activated by INPUT any keys that you normally press apply. Pressing TAN will place the function in the command line, pressing ON will clear the command line. Pressing ENTER will terminate the command line and place the command-string PLUS your keystrokes on level one AS A TEXT STRING. This string is called the result string. Let's see how this works with a simple program.

INPUT may be entered in a program by pressing: SX - PRG, CTRL, NXT; GX - PRG, NXT, IN.

1. DISPLAY THE INPUT PROMPT-STRING AS A SIMPLE MESSAGE.

2. DISPLAY THE LONGEST ONE LINE MESSAGE POSSIBLE USING INPUT

3. DISPLAY THE LONGEST MESSAGE POSSIBLE USING INPUT

4. DISPLAY A NICE HAPPY BIRTHDAY MESSAGE FOR WILLIAM

5. COMPUTE THE AREA OF A CIRCLE PROMPTING FOR RADIUS

6. CALCULATE THE FREQUENCY ERROR IN PARTS PER MILLION FOR A MEASURED CLOCK CRYSTAL

7. USE QUAD TO SOLVE FOR THE ROOTS OF A QUADRATIC EQUATION

8. PRELOAD A CHOICE THAT IS USED OFTEN. PURGE FILE? Y OR N?

9. REWRITE 'IN7' TO REPEAT THE QUESTION FOR ANYTHING EXCEPT Y OR N

10. REWRITE 'IN8' TO MEET ALL INPUT POSSIBILITIES


CONCLUSION

Programs that provide a quality user interface that allows for every possible situation are difficult to write. This brief handout gives examples of the the essential elements of the INPUT acommand. Refer to your owners manual for additional details. Often a complex user interface is called an "engine". It is a "front end" program that presents menus, dialog boxes, or multiple choices from lists. These programs are the type found on professional application cards. For the average programmer, INPUT, provides an efficient means for many applications.


EPILOG

The Purge File? problem above has many solutions. Here is one that that does not use INPUT.

'NY?' << 0 WHILE DROP "     Purge File?" CLLCD 3 DISP "Press N or Y" 7 DISP 
          DO UNTIL KEY END DUP { 32 52 } SWAP POS 0 SAME REPEAT END "File " SWAP IF 32 
          SAME THEN "Saved" ELSE "Purged" END + >>
          185.5 Bytes  # 27E8h

HOME WORK PROBLEM

Write a program that displays a list A thru U in three columns. Put a function such as SIN, COS, etc next to the letter. Selecting the key should execute the function. Use the KEY command to provide the input. "NY' may be used as an example. Is there a better choice than KEY ? What is happing to the battery if a key is not pressed ?

Back to Technical Notes Index