SmallBASIC GuideThe language | Programming Tips | Commands | System | Graphics & Sound | Miscellaneous | File system | Mathematics | 2D Algebra | Strings | Console | Glossary |
Function: FRE (x) Returns system information Where x: QB-standard:
0 free memory
-1 largest block of integers
-2 free stack
-3 largest free block
Our standard (it is optional for now):
-10 total physical memory
-11 used physical memory
-12 free physical memory
Optional-set #1:
-13 shared memory size
-14 buffers
-15 cached
-16 total virtual memory size
-17 used virtual memory
-18 free virtual memory
Optional-set #2:
-40 battery voltage * 1000
-41 battery percent
-42 critical voltage value (*1000)
-43 warning voltage value (*1000)
The optional values will returns 0 if are not supported.
Command: RTE [info [, ...]] Creates a Run-Time-Error. The parameters will be displayed on error-line.
Function: TICKS 0 Returns the system-ticks. The tick value is depended on operating system.
Function: TICKSPERSEC 0 Returns the number of ticks per second
Function: TIMER 0 Returns the number of seconds from midnight
Function: TIME 0 Returns the current time as string "HH:MM:SS"
Command: TIMEHMS hms | timer, BYREF h, BYREF m, BYREF s Converts a time-value to hours, minutes and seconds integer values
Function: DATE 0 Returns the current day as string "DD/MM/YYYY"
Function: JULIAN (dmy | (d,m,y)) Returns the Julian date. (dates must be greater than 1/1/100 AD) Example:
PRINT Julian(DATE)
PRINT Julian(31, 12, 2001)

Command: DATEDMY dmy | julian_date, BYREF d, BYREF m, BYREF y Returns the day, month and the year as integers.
Function: WEEKDAY (dmy | (d,m,y) | julian_date) Returns the day of the week (0 = Sunday)
PRINT WeekDay(DATE)
PRINT WeekDay(Julian(31, 12, 2001))
PRINT WeekDay(31, 12, 2001)

Function: DATEFMT (format, dmy | (d,m,y) | julian_date) Returns formatted date string Format:
D one or two digits of Day
DD 2-digit day
DDD 3-char day name
DDDD full day name
M 1 or 2 digits of month
MM 2-digit month
MMM 3-char month name
MMMM full month name
YY 2-digit year (2K)
YYYY 4-digit year
PRINT DATEFMT("ddd dd, mm/yy", "23/11/2001")
REM prints "Fri 23, 11/01"

Command: DELAY ms Delay for a specified amount of milliseconds. This 'delay' is also depended to system clock.
Command: SORT array [USE cmpfunc] Sorts an array. The cmpfunc (if its specified) it takes 2 vars to compare. cmpfunc must returns -1 if x < y, +1 if x > y, 0 if x = y
FUNC qscmp(x,y)
IF x=y
    qscmp=0
ELIF x>y
    qscmp=1
ELSE
    qscmp=-1
ENDIF
END
...
DIM A(5)
FOR i=0 TO 5
    A(i)=RND
NEXT
SORT A USE qscmp(x,y)

Command: SEARCH A, key, BYREF ridx [USE cmpfunc] Scans an array for the key. If key is not found the SEARCH command returns (in ridx) the value (LBOUND(A)-1). In default-base arrays that means -1. The cmpfunc (if its specified) it takes 2 vars to compare. It must return 0 if x = y; non-zero if x <> y
FUNC cmp(x,y)
  cmp=!(x=y)
END
...
DIM A(5)
FOR i=0 TO 5
    A(i)=5-i
NEXT
SEARCH A, 4, r USE cmp(x,y)
PRINT r:REM prints 1
PRINT A(r): REM prints 4

Command: CHAIN file Transfers control to another SmallBASIC program. file - A string expression that follows OS file naming conventions; The file must be a SmallBASIC source code file.
CHAIN "PROG2.BAS"

Command: EXEC file Transfers control to another program This routine works like CHAIN with the exception the file can be any executable file. EXEC never returns
Command: ENVIRON "expr"
Command: ENV "expr" Adds a variable to or deletes a variable from the current environment variable-table. If name already exists in the environment table, its current setting is replaced with the new setting. If name does not exist, the new variable is added. PalmOS, SB emulates environment variables.
Function: ENV ("var")
Function: ENVIRON ("var") Returns the value of a specified entry in the current environment table. If the parameter is empty ("") then returns an array of the environment variables (in var=value form) PalmOS, SB emulates environment variables.
Command: RUN cmdstr Loads a secondary copy of system's shell and, executes an program, or an shell command. After the specified shell command or program terminates, control is returned to the line following the RUN command. PalmOS, The 'cmdstr' is the Creator-ID. PalmOS, The RUN never returns.
Function: RUN ("command") RUN() is the function version of the RUN command. The difference is that, the RUN() returns a string with the output of the 'command' as an array of strings (each text-line is one element). PalmOS, The RUN() does not supported. Windows, The stdout and stderr are separated! First is the stdout output and following the stderr.
Command: TRON 0
Command: TROFF 0 TRACE ON/OFF. When trace mechanism is ON, the SB displays each line number as the program is executed
Command: LOGPRINT ... PRINT to SB's logfile. The syntax is the same with the PRINT command.
Function: MALLOC (size)
Function: BALLOC (size) Allocates a memory block. *, The variable can be freed by using ERASE.
Function: VADR (var) Returns the memory address of the variable's data.
Function: PEEK[16|32] (addr) Returns the byte, word or dword at a specified memory address.
Command: POKE[16|32] addr, value Writes a specified byte, word or dword at a specified memory address.
Command: USRCALL addr Transfers control to an assembly language subroutine. The USRCALL is equal to:
void (*f)(void);
f = (void (*)(void)) addr;
f();

Command: BCOPY src_addr, dst_addr, length Copies a memory block from 'src_addr' to 'dst_addr'
Command: BLOAD filename[, address] Loads a specified memory image file into memory.
Command: BSAVE filename, address, length Copies a specified portion of memory to a specified file.
Command: STKDUMP 0 Displays the SB's internal executor's stack *, For debug purposes; it is not supported on "limited" OSes.