Previous Section
Cover Page
Table of Contents
Index
Next Section

Section 3 - Editing and Debugging

It is an unfortunate fact of life that humans make mistakes (called bugs in this context) that cause the calculator to halt in mid program because it has been asked to do something impossible or that cause the calculator to give wrong answers. One of the easiest ways to find a bug in a program is to have the calculator execute the program one step at a time so we can see exactly what it is doing. Let's look again at the example BWL2 from Section 2. Put three bowling scores on levels 4, 3 and 2, and 'BWL2' on level 1. Now press LS PRG NXT NXT F3-RUN F1-DBUG. The program name will be taken off the stack and the annunciator HLT will appear at the top of the screen. Now press F2-SST once for each step of the program. Notice that with each press the step being executed is shown in the upper left corner of the screen and the result is shown on the stack. If you find an error and choose not to continue single stepping through the program, press the F6-KILL, to return to normal keyboard commands.

Once an error is found we need to edit our program. Suppose we want to edit BWL2. Enter 'BLW2' on the stack and press LS DA. The program will now show in the command line and you can use the arrow keys to move around the program. A handy thing to remember, especially when you are editing a long program, is that RS DA gets you to the end of the program and RS UA gets you to the beginning of the program. Also, RS LA gets you to the beginning of a line and RS RA gets you to the end of a line. When the cursor is where the changes are needed, you can type in new things and use the backspace or delete keys to remove things. When the editor is entered it is in insert mode. The soft menu key F6-INS toggles between insert mode and overwrite mode. When the menu shows a small square after INS, insert mode is on.

While working in the command line, it is possible to bring up any of the menus that may be useful in writing the program, such as PRG, MTH, etc. To return to the edit commands, press TOOL.

When all the necessary corrections have been made, press ENTER to make the changes permanent and return to normal calculator operation. If you decide you wish to exit without making the changes permanent, press the CANCEL key and the program will be left unaltered.

There are also several editing commands in the menu. Some of these are explained in Appendix L of UG, but several are missing from the appendix and others don't do what the appendix says they do. On the first page of menu commands are moves the cursor to the end of the previous word, moves the cursor to the beginning of the next word, deletes to the end of the previous word, and deletes to the beginning of the next word. F5-DEL L deletes an entire line, and F6-INS was discussed above.

On the second page of menus there are two subdirectories that are very useful. The first is F1-SEARCH. F1-FIND opens a dialog box with a field for the string to be searched for. After entering the target string, F6-OK finds the first occurrence of the string starting at the current cursor position and searching forward. If the string is not found before the end of the file, an error message is displayed. If the string is found, it is highlighted. To find the next occurrence of the string, press F3-NEXT. F2-REPL opens a dialog box with fields for the target string and for the replacement string. After entering the desired strings in these two fields, F6-OK will highlight the first occurrence of the target string (or give error message if it is not found). There are now three choices of how to make the replacement. F4-R makes the replacement and leaves the cursor at that point, F5-R/N will make the replacement and highlight the next occurrence of the target string, F6-ALL will make the replacement for all occurrences of the target string from the current location to the end of the file.

The other subdirectory of interest in the second page of the Edit directory is F2-GOTO. The one command in this subdirectory that is useful in long programs is F1-GOTOL. It will open a dialog box with a field for a line number. When a line number is entered and F6-OK is pressed, the cursor will move to the beginning of the requested line.

On the main keyboard there are also commands to do COPY/CUT/PASTE similar to what is available in most computer text editors. Place the cursor at the beginning of the text to be copied or moved and press RS BEGIN. Move the cursor to the end of the desired text and press RS END. Now press RS COPY or RS CUT, as desired, move the cursor to the point where the text is to be inserted and press RS PASTE.

In some cases (as in Problems 1 and 2 of Exercise Set 2) you may wish to create a new program by making changes to an existing program, but leave the original intact. To do this, press RS and press the menu key for the desired program to put it on the stack, then DA to put it on the command line. Make the necessary changes and press ENTER. The new version is now on the stack and can be saved under a new name, but the original is unaltered.

Previous Section
Cover Page
Table of Contents
Index
Top of Page
Next Section