Page 207 - The Ultimate Palm Robot
P. 207
Color profile: Generic CMYK printer profile
Composite Default screen
Bots / The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 7
190 The Ultimate Palm Robot
frame(1, 2, 30, 55, 45, 2);
text(5, 32, "Enter Name");
waitp(1);
x = penx();
y = peny();
if (x>2 && x<55 && y>30 && y<45) {
name = gets("Enter your name");
if (name != "") {
mymsg = "Hello, " + name;
}
}
}
}
Let’s go over this program quickly. Every PocketC program starts with the
name of the program as a C++ style comment. The name must end in .c or .pc
so that PocketC can recognize it as source code.
Every program must also have a single main( ) function. As with other C
source code, the main( ) function is the starting point for the program. Also,
you can have additional functions in your source code, either before or after
the main( ) function.
Inside the main( ) function, the code declares some variables and then
turns the graphics form on. The title( ) function changes the title of the graphics
form. Then we go into the primary loop. Within the loop, the clearg( ) function
clears the graphics form.
The code draws the message to the form using the text( ) function, and then
creates a pseudo button using the frame( ) and text( ) functions. Don’t worry
that you need to do this for every program. There are several add-on libraries
available at www.orbworks.com that provide functions for creating form con-
trols. We only chose to do it this way for simplicity. If you plan to pursue
PocketC programming, you should definitely check out the add-on libraries
at OrbWorks.
The program waits for a pen event with the waitp( ) function. When this
function returns, the x and y screen coordinates of the pen click can be ob-
tained with the penx( ) and peny( ) functions. If the x and y coordinates are
within the bounds of the pseudo button, the code displays a dialog box that
asks the user to enter a name. If the name is non-empty, the message is changed.
When the loop starts over, the screen is cleared and the current message is dis-
played.
P:\010Comp\Bots\880-6\ch07.vp
Monday, May 12, 2003 4:29:28 PM