5. Procedures

This documents all the procedures currently in Palm Basic. They are (roughly) organised into functional groups.

5.1 Print

This is the most complex procedure in Palm Basic. A print statement consists of a sequence of expressions, commas and semicolons. An expression is evaluated, and the corresponding integer, floating point number or string is printed at the current text position. A comma moves the text position to the next tab stop. There are four tab stops per screen width. A semicolon has no effect, and can usually be omitted except as the last element of the sequence. If the expression does not end in a comma or a semicolon, the current text position is moved to the next line. If the current text position is off the screen when characters have to be printed, the screen is scrolled vertically until the current text position is on the screen.
Examples:
Print "hello"
Print a,,b
Print "hello";
Print

5.2 Let

Let defines this statement as an assignment statement. It is always optional.

5.3 Goto

Goto label. Execution continues at the statement after the named label.
Note that it is possible to use goto to leave a control structure (if...then, for...next or do...loop) either forwards or backwards. It is not possible to use goto to enter a control loop. This will cause an error when execution reaches the terminating statement of the control loop.

5.4 Gosub

Gosub label. Execution continues at the statement after the named label. When execution reaches a return statement, control resumes at the statement following the gosub statement.

5.5 Return

See gosub.

5.6 Input

An Input statement consists of a sequence of constant strings, commas, semicolons, variable names and array elements. A constant string is displayed. A comma moves the text position to the next tab stop (see Print above). A semicolon has no effect, and can usually be omitted except as the last element of the sequence. A variable name or array elements causes a cursor to be displayed at the current text position. The user of the program can then enter any characters. When they enter the return character, the text is read and used to alter the value of the variable. If the variable is numeric, the text is processed as a number and the value is placed in that variable (see the function val for the precise rules as to how this is done). (Note that if the user enters a floating point number and the variable is an integer, the number will be converted to an integer (see the function int for precise rules as to how this is done). If the variable is a string, the text is placed into that variable without alteration.

5.7 Dim

Dim array_name(size ,size ,size ...), array_name(size, ...)
Create one or more arrays of one or more dimensions. Note that you cannot create the same array more than once.

5.8 Rem

Rem text
Ignore the rest of this line (including colons and what follows them). Used for inserting comments (rem-arks) into programs.

5.9 End

Stops program execution. This is equivalent to reaching the end of the program.

5.10 Clear

Delete all variables and arrays.

5.11 Cls

Clear the screen, and restore the text position to the top left.

5.12 TextPos

TextPos x, y
Set the current text position to (x,y). Note that 0 <= x < width and 0 <= y < height or an error will be thrown.

5.13 TextMode

TextMode n
n must be 1, 2, 3 or 4. Affects how text is drawn by the print and input procedures.
  • 1: Draw characters normally
  • 2: Erase characters (draw in white)
  • 3: Draw white characters on a black background
  • 4: Invert characters
  • 5.14 DrawLine

    DrawLine x1, y1, x2, y2
    Draw a line from (x1, y1) to (x2, y2). Note that coordinates are based from the top left.

    5.15 EraseLine

    EraseLine x1, y1, x2, y2
    Erase (draw in white) a line from (x1, y1) to (x2, y2).

    5.16 InvertLine

    InvertLine x1, y1, x2, y2
    Invert all pixels on a line from (x1, y1) to (x2, y2).

    5.17 GrayLine

    GrayLine x1, y1, x2, y2
    Draw a gray line from (x1, y1) to (x2, y2). This in fact draws every other pixel on the line.

    5.18 DrawRect

    DrawRect x1, y1, width, height ,radius
    Draw a solid rectangle with top left (x1, y1), width width and height height. If the fifth argument is given, the corners of the rectangle are rounded with the specified radius.

    5.19 EraseRect

    EraseRect x1, y1, width, height ,radius
    Draw a solid rectangle with top left (x1, y1), width width and height height. If the fifth argument is given, the corners of the rectangle are rounded with the specified radius.

    5.20 InvertRect

    InvertRect x1, y1, width, height ,radius
    Invert all pixels in a solid rectangle with top left (x1, y1), width width and height height. If the fifth argument is given, the corners of the rectangle are rounded with the specified radius.

    5.21 DrawFrame

    DrawFrame x1, y1, width, height
    Draw a frame around the rectangle with top left (x1, y1), width width and height height. Note that this means that DrawRect 1,1,10,10 will draw a rectangle starting at (0,0) and finishing at (12,12).

    5.22 EraseFrame

    EraseFrame x1, y1, width, height
    The same as DrawFrame, except that the pixels are erased (drawn in white).

    5.23 InvertFrame

    InvertFrame x1, y1, width, height
    The same as DrawFrame, except that the pixels are inverted.

    5.24 GrayFrame

    EraseFrame x1, y1, width, height
    The same as DrawFrame, except that only every other pixel is drawn.

    5.25 Randomize

    Randomize n Sets the seed for the pseudo random number generator. If n is given, it is used. This is perhaps most useful if you want to ensure that a sequence of calls to rnd() always produces the same results. If n is omitted, the current time is used to try to generate apparently random behavior in subsequent calls to rnd().