Page 159 - The Ultimate Palm Robot
P. 159
Color profile: Generic CMYK printer profile
Composite Default screen
Bots / The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 6
142 The Ultimate Palm Robot
Cut or Delete button from the toolbar. Cut removes a block from the program
but saves a copy so that you can paste it into the program. Delete permanently
removes the block from the program.
NOTE: Be careful when cutting or deleting If, Else, For, and While blocks or
their corresponding End block. You must delete both the block and its
corresponding End block. If you delete one and not the other, your program
cannot be translated.
When you cut a program block, the block is placed into a paste buffer. To
paste the block to a new location, click an existing component in the
workspace to select the block and then choose Edit | Paste or click the corre-
sponding Paste button. The new block will be pasted into the program follow-
ing the selected block.
You can also copy program blocks and paste copies of them to new loca-
tions in the program. Ablock is copied by selecting a block and then choosing
Edit | Copy or by clicking the Copy toolbar button.
Creating a Subroutine, Function, or Method
When you’re creating programs with the PRP, you may sometimes need to
perform the same sequence of actions, or perform the same calculation, sev-
eral times within the program. Rather than adding the same components over
and over again to the program, you can create a subroutine to do this for you.
We are using the term subroutine as a generic term to mean any number of
program structures, depending on the software language. Basic does not have
formal subroutines, but we can simulate them using language features. TEA
has subroutines and functions; functions return a value to the caller and sub-
routines do not. Java uses the term method to mean some code that one can call;
methods may or may not return values.
To add a subroutine to a program, choose Edit | Add Subroutine. The PRP
will add a Subroutine and EndSubroutine block to the workspace. If you
decide later that you want to delete the subroutine, select the Subroutine
block and choose Edit | Delete Subroutine. In Figure 6-7, you can see a version
of the program we created at the start of this chapter, but now it uses sub-
routines.
P:\010Comp\Bots\880-6\ch06.vp
Monday, May 12, 2003 1:06:25 PM