Controlling Program Input and Output: Bonus Chapter 7
Controlling Program Input and Output: Bonus Chapter 7
rogram input is information that the program requests from the program user. Program output is information passed from the program back to the program user. This chapter tells you how to get a program to shuttle information back and forth between the program and the program user. The Program I/O menu, which houses the input and output commands, is available only when youre using the Program editor to create a new program or to edit an existing program. A picture of the Program I/O menu appears in Figure B7-1. Creating and editing programs are explained in Chapters B5 and B6.
64
user for the value of only one variable and allows the program to briefly describe the variable it is requesting. The Prompt command asks the user for the value of one or more variables, but does not allow for a description of the variable other than its name.
65
66
The first picture in Figure B7-4 shows an example of a program that displays the text PRESS ENTER TO CONTINUE in two ways. The first Disp command displays the whole text, in spite of the fact that it contains more than 16 characters. The next two Disp commands break the text into two parts, each of which contains less than 16 characters. The output of the program in the first picture in Figure B7-4 is shown in the second picture in Figure B7-4. The ellipsis at the end of the second line in this picture indicates that the calculator could not display the whole line. (The calculator does not understand wrap around.) And worse than that, you cannot use ~|} to see what comes after that ellipsis. The remaining lines of this picture illustrate the solution to this problem. When programming the calculator to output text, limit all text items to 16 characters. A space counts as one character. If necessary, break the text into two or more text items that are consecutively displayed.
67
The Disp command followed by an empty text item can be used to make a program skip a line on the Home screen, as in the fifth line of the program in the first picture in Figure B7-5.
68
the PlotsOff command turns off all stat plots and the FnOff command turns off all functions in the Y= editor. The FnOn 1,2 command turns on the first two functions in the Y= editor so that only these two functions are graphed. The ZStandard command tells the calculator to graph these two functions in the standard viewing window where 10 x 10 and 10 y 10. The Input command, because it isnt followed be a variable, tells the calculator to graph these two functions. When the program in the first picture in Figure B7-7 reaches the Input command, it displays the graph of the first two functions housed in the Y= editor, places the free moving cursor at the center of the graph, and displays the coordinates of the cursor, provided that CoordOn is selected in the Format menu. You can use the ~|} to move the cursor, but it doesnt trace the graph in this program, as in the second picture in Figure B7-7. After a program graphs functions using the Input command, the program user will see a moving, broken vertical line in the upperright corner of the graph, as is illustrated in the second picture in Figure B7-7. This indicates that the program user must press in order to tell the program that he or she is finished looking at the graph. If you dont think that the program user will realize that he or she must do so, then before the Input command, have your program tell the user to press after viewing the graph. The next section tells you how to do so. When a program user presses after viewing the graphs displayed by the Input command, control will be returned to the program. If the Input command was the last command in the program, then control will be returned to the calculator where the user can, if desired, use any of the techniques discussed in Parts IV and V to investigate the graph. If the Input command was not the last command in the program, then the program will continue by executing the next command in the program. In the program illustrated in Figure B7-7, when the program user presses after viewing the graph, the program calls and executes program WHATEVER. Commands such as PlotsOff, FnOff, and ZStandard can be entered in your program from the Catalog menu.
69
Housekeeping Issues
Because programs display their output on the Home screen, it is a good idea to have your program clear the Home screen before the output is displayed. This is done by inserting the ClrHome I/O command in the program before the commands used to display the output, as in the program in the first picture in Figure B7-5. When the Disp I/O command is used to display the program output, it isnt necessary to clear the Home screen at the end of the program. After the program is executed, the calculator uses the next available line on the Home screen to evaluate any arithmetic expressions or to execute any commands you enter. However, when the Output I/O command is used to display program output, it is wise to have the program end by clearing the Home screen. Clearing the Home screen is necessary in this situation because the calculator may type over the Output item when you use it to evaluate an arithmetic expression or execute a command after exiting the program, as in Figure B7-8. This figure shows what happens when you use the calculator after executing the program in Figure B7-6.
Because you want to give the program user a chance to view any output before clearing the Home screen from a program, place the Pause control command before the ClrHome I/O command in the program. (The Pause control command is discussed in Chapter B6.) Better yet, put the CLRHOME program in the first picture in Figure B7-9 on your calculator, and have your program call it whenever you want your program to allow the program user to view the program output before the program clears the Home screen. Calling an external program from within a program is discussed in Chapter B6. The second picture in Figure B7-9 illustrates what happens when the prgm CLRHOME command is placed at the end of a program like that
70
shown in Figure B7-6: The program invites the user to press , and when the user does so, the program clears the Home screen.
Figure B7-9: Using the CLRHOME program to clear the Home screen.