The EXPORT command for
the variable RADIUS must
appear before the heading
of the function where
RADIUS is assigned. After
you execute this program,
a new variable named RADIUS appears on the USER
GETRADIUS section of the Vars menu.
The programming environment for the HP39gII is highly
structured. You can define your own functions in a
program, and data can be passed to a function using
parameters. Functions can return a value (using the
RETURN statement) or not. When a program is executed
from Home, the program will return the value returned by
the last statement that was executed.
Furthermore, functions can be defined in a program and
exported for use by other programs in the same way that
this is done for variables. This feature makes the HP39gII
an incredibly powerful programming platform.
In this section, we will create a small set of programs,
each illustrating some aspect of programming on the HP
39gII. Each of these programs will be used as a building
block for a custom app described in the next section, App
Here is a program that defines a function called
ROLLDIE that simulates the rolling of a single die,
returning a random integer between 1 and whatever
number is passed into the function:
First, create a new program named ROLLDIE. Then
enter the program.
RETURN 1 + FLOOR(N*RANDOM);
The first line is the heading of the function. Execution of
the RETURN statement causes a random integer from 1 to
N to be calculated and returned as the result of the
function. Note that execution of a RETURN command
causes execution of the function to terminate.