The Basics of Programming

Built in functions

The BASIC language has a wide range of built-in functions to manipulate numbers and strings. You can use functions almost anywhere from within your program where an expression is required for input to other statements and functions.

Number Functions

ABS(n) - Absolute value. Returns the absolute and positive value of the number n. e.g. ABS(70) = 70, ABS(-33) = 33.
ASC(x$) - Returns ASCII code of first character in the string.
ATN(n) - Arctangent. Returns to arctangent of number n, where n is in Radians. Result is in the range -PI/2 to PI/2 radians.
CBDL(n) - Converts number to a double-precision value.
CINT(n) - Converts number to an integer by rounding the fractional portion (n = -32768 to 32767).
CLNG(n) - Converts number to a long integer value.
COS(n) - Cosine. Returns the cosine of value n, which is in radians.
CSNG(n) - Converts number to a single-precision number.
CSRLIN - Returns line of the the pen.
CVI(2-byte-string) - Convert numeric string value to a short integer.
CVL(4-byte-string) - Convert numeric string value to a long integer.
CVS(4-byte-string) - Convert numeric string value to a single precision number.
CVD(8-byte-string) - Convert numeric string value to a double precision number.
EOF(filenumber) - Checks end of file condition. Returns true (-1) if end of file reached.
ERR - Returns last error number. See ON ERROR statement.
ERL - Returns line number of statement where error occured. See ON ERROR statement.
EXP(n) - Natural logarithm. Returns e^n where e is 2.7182818284590.
FIX(n) - Returns truncated integer part of number n. Same as INT but no rounding.
FRE(n) - Returns amount of free memory. If n=-1, returns total free memory, if n=-2, returns free stack space, if n is other, returns free memory in data segment.
INT(n) - Returns largest integer which is <= n.
LBOUND(array-name[,dim]) - Returns lowest index of the array or a specific dimentision of an array. Usually 0 or 1.
UBOUND(array-name[,dim]) - Returns highest index of the array or a specific dimentision of an array.
LOC(filenumber) - Returns record number of last record read or written to file.
LOF(filenumber) - Returns length of the file in bytes.
LOG(n) - Return natural logarithm (e) of number n.
LPOS(n) - Returns current position of print head on printer buffer. n is a dummy argument.
MENU(n) - Returns number of the last menu item selected.
MOUSE(n) - Returns status of mount button if n=0. If n=2 to 5 then returns current, starting and end position of the mouse cursor.
OBJECT.VX(obj-id) - Returns velocity of an object in x direction (horiz).
OBJECT.VY(obj-id) - Returns velocity of an object in y direction (vert).
OBJECT.X(obj-id) - Returns x position of an object.
OBJECT.Y(obj-id) - Returns y position of an object.
PEEK(address) - Returns a one byte integer from a memory location.
PEEKL(address) - Returns a long integer word from a memory location.
PEEKW(address) - Returns a short integer word from a memory location.
POINT(x,y) - Returns the colour id of a point on current window.
POS(x) - Returns column number of pen in current window.
RND([x]) - Returns a random number between 0 and 1 (if x<0 then restarts same sequence; x=0 repears the last number; x>0, generates next number in sequence (default)).
SGN(n) - Returns value of n relative to zero. If n<0 then returns -1, if n=0 then returns 0, if n>0 then returns 1.
SIN(n) - Returns the sine of n, where n is in radians.
SQR(n) - Returns the square root of n.
STICK(n) - Returns direction of joystick. If n=0, returns X direction for Joy A, if n=1, returns Y direction for Joy B, if n=2, return X direction for Joy B, if n=3 then returns Y direction for Joy B.
STRIG(n) - Returns status of button on joystick. If n=0 returns 1 if button on Joy A was pressed recently, if n=1 returns 1 if button on Joy A is currently pressed, If n=2 returns -1 if button on Joy B was pressed recently, if n=3 returns -1 if button on Joy B is currently pressed.
TAN(n) - Returns tangent of n, where n is in radians.
VAL(x$) - Returns the numeric value of the string.
VARPTR(var-name) - Returns the address of the first byte of the variable.
WINDOW(n) - Returns information about a window e.g. id, width, height, position, colours.

String Functions

CHR$(n) - Returns the character equivalent of the ASCII value n.
DATE$ - Returns the current date (format is mm-dd-yyyy).
HEX$(n) - Returns the hexadecimal value of the decimal value n.
INKEY$ - Returns a one character string of the character read from the keyboard.
INPUT$(x [,]#]filenumber) - Returns a string of x characters from a file of filenumber.
INSTR([i,] X$, Y$) - Returns the position of string Y$ within string X$, starting from position I.
LEFT$(X$, I) - Returns the I number of characters from the left side of string X$.
LEN(X$) - Returns the number of characters in string X$.
MID$(X$, start, len) - Returns the middle characters of X$ starting at position 'start', of 'len' characters long.
MKI$(n) - Converts short integer to a 2-byte string.
MKL$(n) - Converts a long integer to a 4-byte string.
MKS$(n) - Converts a single precision number to a 4-byte string.
MKD$(n) - Converts a double precision number to a 8-byte string.
OCT$(n) - Returns octal value as a string, of decimal value n.
RIGHT$(X$, I) - Returns right most I characters of string X$.
SADD(X$) - Returns the address of the first byte of the string X$.
SPACE$(n) - Returns a string of n space characters. Similar to SPC().
STR$(n) - Converts the number n to a string equivalent.
STRING$(I, [J | X$]) - Returns a string of length I of ASCII code J or character in X$.
TIME$ - Returns the current time (format: hh:mm:ss).
TRANSLATE$(X$) - Translates english words into phonemes to be used by SAY statement.
UCASE$(X$) - Converts string to upper case letters.

Print Functions

PTAB(n) - Moves print position to pixel n (0-32767).
SPC(n) - Prints n number of spaces.
TAB(n) - Tabulates to nth column.

ACE Basic Functions

ALLOC( bytes, type) - Allocates bytes of member in Chip(0), Fast(1) or Public (2), adding 3 will clear memory too. Returns start address.
ARG$(n) - Returns the argument from the command line of nth item in argument list.
ARGCOUNT - Returns number of arguments in command line.
BIN$(n) - Returns the binary string equivalent of the decimal number n.
CSTR(addr) - Coerces a long integer address into a string.
DAY - Returns day of the week as a number (0=Sunday, 6=Saturday)
FILEBOX$(title, dir) - Invokes a file requester and returns path of file.
HANDLE(filenum) - Returns a pointer to a dos file handle for use with dos functions.
HEADING - Returns turtle's current eading in degrees (0-359)
IFF(channel, n) - Returns information about the IFF graphics file with given channel (1-255). Info req n=0-4.
INPUTBOX(prompt, title, default, xpos, ypos) - Displays a requester and returns a long integer value.
INPUTBOX$(prompt, title, default, xpos, ypos) - Displays a requester and returns a string.
MSGBOX(message, text1, text2) - Displays a system requester with one or two buttons using text1, text2.
POTX(n) - Returns potentiometer reading from joystick or device in game port. n=0 or 1.
POTY(n) = Returns potentiometer reading from joystick or device in game port. n=0 or 1.
SAY(n) - Returns true or false if there is active speech (n=0), returns width of mouth (n=1), returns height of mount (n=2).
SCREEN(n) - Returns information about the current screen (n=0-6)
SERIAL(channel, n) - Returns information from a serial port (channel = 1-255, n=0-12).
SHL(n, m) - Shift to the left the value n by m bit positions.
SHR(n, m) - Shift to the right the value n by m bit positions.
SIZEOF(ident) - Returns size of variable, array or structure in bytes.
TIMER - Returns the number of seconds since midnight.
XCOR - Returns current turtle x co-ords.
YCOR - Returns current turtle y co-ords.