6. Functions

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

6.1 Left$(string A$, integer N)

Returns a string consisting of the first N characters of string A$. If N is less than or equal to zero, returns an empty string. If N is greater than the length of A$, returns a string equal to A$.

6.2 Right$(string A$, integer N)

Returns a string consisting of the last N characters of string A$. If N is less than or equal to zero, returns an empty string. If N is greater than the length of A$, returns a string equal to A$.

6.3 Mid$(string A$, integer P, integer N)

Returns a string consisting of the N characters of string A$ starting at position P within the string. Note that the first character is 0, so Mid$(A$, 0, N) is equivalent to Left$(A$, N) If N is less than or equal to zero, returns an empty string. If N is greater than the length of A$, returns a string equal to A$. Returns an error if P < 0, otherwise truncates the result if A$ isn't long enough.

6.4 Len(string A$)

Returns the length of A$.

6.5 Asc(string A$)

Returns the ascii code for the first character of A$.

6.6 Char$(integer N)

Returns a string consisting of the single character whose ascii code is N. Note that if N is outside the range 0 to 255, this function returns a string consisting of the character whose ascii code is N modulo 256.

6.7 Eval(string A$)

Evaluates the expression in string A$. If the expression is followed by extra characters, then the extra characters are ignored. If the expression is not complete, an error is thrown. For instance, eval("a+b ignored") will evaluate a+b. But eval("a+") will cause an error.

6.8 Val(string a$)

Evaluates the number in string A$. If the number is followed by extra characters, then the extra characters are ignored. Like eval, if the number is incomplete, an error is thrown. This can only happen if the number has an exponenet (i.e. is like 3.7e32) but there are no digits following the e.

6.9 Width()

Returns the width of the screen.

6.10 Height()

Returns the height of the screen.

6.11 Sin(floating theta)

Returns sin(theta) where theta is in radians.

6.12 Cos(floating theta)

Returns cos(theta) where theta is in radians.

6.13 Tan(floating theta)

Returns tan(theta) where theta is in radians.

6.14 ArcSin(floating x)

Returns inverse sin(x).

6.15 ArcCos(floating x)

Returns inverse cos(x).

6.16 ArcTan(floating x)

Returns inverse tan(x).

6.17 Log(floating x)

Returns the natural logarithm of x.

6.18 Exp(floating x)

Returns e to the power x.

6.19 Abs(floating or integer x)

Returns the absolute value of x i.e. x if x >= 0, -x if x < 0.

6.20 Int(floating x)

Returns the integral part of x. If x > 0, int(x) <= x. If x < 0, int(x) >= x.

6.21 Sign(floating or integer x)

Returns 1 if x is positive, 0 if x is 0 and -1 if x is negative.

6.22 KeyDown(integer x)

Allows a program to determine the state of the various buttons on the Palm. x must be in the range 1 to 10. If the appropriate key is pressed KeyDown, returns 1, else it returns 0. The numbers 1 to 10 correspond to the following keys:

1: Power key (note that since this causes an interrupt, this value is not useful)
2: Page up key
3: Page down key
4: App #1, typically calendar
5: App #2, typically address list
6: App #3, typically todo list
7: App #4, typically memo pad
8: Button on cradle
9: Antenna key
10: Contrast key

6.23 Rnd()

Returns a pseudo random number in the range 0 to 1. Note that the procedure randomize can be used to set the key. If you do not call randomize, note that the key will always be initialized to 0 when you start Palm Basic, so the sequence will always be the same.

6.24 Time()

N.B. For these following functions to exist, you must have Palm Basic v1.0 build 2 or later. Check the build number in the about box - if you do not have the latest build, download it here.

Returns the number of seconds since 12:00A.M. on January 1, 1904. Note that this number will actually appear as a large negative number. It is not suggested that you use this value directly; rather you can pass it to the following time-related functions, or you can subtract one time from another to get an elapsed time:

t = time()
rem long loop
for a = 1 to 1000 next a print "The long loop took "time() - t1" seconds"

6.25 Seconds(integer t)

Used to convert the return value from time() into seconds, minutes, hours etc. Returns the number of seconds (0-59) elapsed in the current minute.

6.26 Minutes(integer t)

Used to convert the return value from time() into seconds, minutes, hours etc. Returns the number of minutes (0-59) elapsed in the current hour.

6.27 Hours(integer t)

Used to convert the return value from time() into seconds, minutes, hours etc. Returns the number of hours (0-23) elapsed in the current day.

6.28 Days(integer t)

Used to convert the return value from time() into seconds, minutes, hours etc. Returns the day of the month (1-31).

6.29 Months(integer t)

Used to convert the return value from time() into seconds, minutes, hours etc. Returns the month (1-12).

6.30 Years(integer t)

Used to convert the return value from time() into seconds, minutes, hours etc. Returns the year (1904-2040).

6.31 Weekday(integer t)

Used to convert the return value from time() into seconds, minutes, hours etc. Returns the day of the week (0-6) where 0 is Sunday.