Turbo Basic Commands

Command Syntax Description
ABS(numeric expression) y = ABS(x) Returns the absolute value of a numeric expression.
ASC(string expression) y = ASC(x$) Returns the ASCII code of the first character in a string.
ATN(numeric expression) y = ATN(x) Returns the arctangent (inverse tangent) of a numeric expression in radians.
BEEP BEEP [count] Emits a beep sound through the speaker.
BINS(numeric expression) y$ = BINS(x) Returns the binary string representation of a number.
BLOAD filespec [address] BLOAD "filename.ext" [address] Loads a file created with BSAVE into memory.
BSAVE filespec, address, length BSAVE "filename.ext", address, length Saves a range of memory to a file.
CALL procedurename (argument list) CALL ProcName(var1, var2, ...) Calls a procedure (subprogram).
CALL ABSOLUTE address (parameter list) CALL ABSOLUTE address (param1, param2, ...) Calls an assembly language routine at a specific address.
CALL INTERRUPT interrupt_number (parameter list) CALL INTERRUPT interrupt_number (param1, param2, ...) Calls a system interrupt.
CDBL(numeric expression) y# = CDBL(x) Converts a numeric expression to double-precision floating-point.
CEIL(numeric expression) y = CEIL(x) Returns the smallest integer greater than or equal to the argument.
CHAIN filespec CHAIN "filename.ext" Loads and executes another Turbo Basic program in chain mode.
CHDIR path CHDIR "path" Changes the current directory (same as DOS CD command).
CHR$(integer expression) y$ = CHR$(x) Returns a one-character string based on the ASCII code.
CINT(numeric expression) y = CINT(x) Converts a numeric expression to an integer by rounding.
CLEAR CLEAR Clears variable memory, turns off event trapping, and resets array and string memory.
CLOSE [filenum] CLOSE [filenum] Closes a file or device.
CLS CLS Clears the screen.
COLOR [foreground] [background] [border] COLOR [foreground] [background] [border] Sets the colors for text mode.
COLOR [background] [palette], COLOR [foreground] [background] COLOR [background] [palette], COLOR [foreground] [background] Sets the colors for graphics mode.
COMMON variable (variable...) COMMON var1, var2, ... Declares variables to be shared with a chained program.
COS(numeric expression) y# = COS(x) Returns the cosine of an angle in radians.
CSNG(numeric expression) y! = CSNG(x) Converts a numeric expression to single-precision floating-point.
CSRLIN y = CSRLIN Returns the current vertical cursor position (row number).
CVI(string), CVL(string), CVS(string), CVD(string) y = CVI(x$), y = CVL(x$), y! = CVS(x$), y# = CVD(x$) Converts string data read from random files to numeric form.
CYMD(string), CVMS(string) y# = CYMD(x$), y! = CVMS(x$) Converts string data read from Microsoft format random files to numeric form.
DATA constant (constant...) DATA value1, value2, ... Declares constants for use with the READ statement.
DATES DATES = "mm-dd-yy", y$ = DATES Sets or retrieves the system date.
DECR variable [size] DECR var [size] Decrements a variable by a specified amount (defaults to 1).
DEF FN identifier (argument list) = expression DEF FN FuncName(arg1, arg2, ...) = expression Defines a single-line function.
DEF FN identifier (argument list) DEF FN FuncName(arg1, arg2, ...) Defines a multi-line function.
DEFINT letter range (letter range...) DEFINT A-Z Declares variables beginning with specified letters as integers.
DEFLNG letter range (letter range...) DEFLNG A-Z Declares variables beginning with specified letters as long integers.
DEFSNG letter range (letter range...) DEFSNG A-Z Declares variables beginning with specified letters as single-precision floating-point.
DEFDBL letter range (letter range...) DEFDBL A-Z Declares variables beginning with specified letters as double-precision floating-point.
DEFSTR letter range (letter range...) DEFSTR A-Z Declares variables beginning with specified letters as strings.
DEF SEG [numeric expression] DEF SEG [segment] Defines the data segment for use with BLOAD, BSAVE, CALL ABSOLUTE, PEEK, and POKE.
DELAY seconds DELAY seconds Pauses program execution for a specified number of seconds.
DIM arrayname (subscripts) (arrayname (subscripts)...) DIM array1(10), array2(10, 10) Declares arrays.
DO [WHILE/UNTIL expression] DO [WHILE/UNTIL expression] Begins a DO/LOOP loop.
DRAW string expression DRAW "commands" Draws shapes on the graphics screen using a string of commands.
END [DEF/IF/SELECT/SUB] END [DEF/IF/SELECT/SUB] Terminates program execution or a structured block.
ENDMEM y = ENDMEM Returns the address of the end of physical memory.
ENVIRON string expression ENVIRON "parameter=value" Modifies the environment table.
ENVIRONS string expression y$ = ENVIRONS(x$) Retrieves a parameter from the environment table.
EOF(filenum) y = EOF(filenum) Returns TRUE if the end of file has been reached.
ERADR y = ERADR Returns the address of the most recent error.
ERASE arrayname (arrayname...) ERASE array1, array2, ... Deletes dynamic arrays and resets static arrays.
ERDEV, ERDEVS y = ERDEV, y$ = ERDEVS Returns device driver error information.
ERL, ERR y = ERL, y = ERR Returns the line number and error code of the most recent error.
ERROR errcode ERROR errcode Simulates a run-time error.
EXIT [SELECT/DEF/FOR/DO/WHILE/SUB] EXIT [SELECT/DEF/FOR/DO/WHILE/SUB] Exits a structured block prematurely.
EXP(numeric expression) y# = EXP(x) Returns e raised to the power of x.
EXP2(numeric expression) y# = EXP2(x) Returns 2 raised to the power of x.
EXP10(numeric expression) y# = EXP10(x) Returns 10 raised to the power of x.
FIELD filenum, width AS stringvar (width AS stringvar...) FIELD filenum, 10 AS str1$, 20 AS str2$, ... Defines field variables for a random file buffer.
FILES filespec FILES "filename.ext" Displays the directory contents (like DOS DIR command).
FIX(numeric expression) y = FIX(x) Truncates a numeric expression to an integer.
FOR variable = start TO end [STEP step] FOR i = 1 TO 10 STEP 2 Begins a FOR/NEXT loop.
FRE(integer expression) y = FRE(x) Returns the amount of free memory available to your program.
GET filenum, recordnumber GET filenum, recordnumber Reads a record from a random file.
GET (x1, y1) - (x2, y2), array GET (x1, y1) - (x2, y2), buffer() Reads a portion of the graphics screen into an array.
GETS(filenum, number_of_bytes) y$ = GETS(filenum, number_of_bytes) Reads a specified number of bytes from a binary file.
GOSUB label GOSUB label Calls a subroutine.
GOTO label GOTO label Jumps unconditionally to a specified line.
HEX$(numeric expression) y$ = HEX$(x) Returns the hexadecimal string representation of a number.
IF expression THEN statement(s) [ELSE statement(s)] IF x > 10 THEN PRINT "Greater than 10" ELSE PRINT "Less than or equal to 10" Tests a condition and executes statements based on the result.
IF expression THEN IF expression THEN Begins an IF block.
INCR variable [size] INCR var [size] Increments a variable by a specified amount (defaults to 1).
INKEY$ y$ = INKEY$ Reads a keystroke from the keyboard without echoing it.
INP(port) y = INP(port) Reads a byte from an I/O port.
INPUT [prompt string;] variable (variable...) INPUT "Enter your name: "; name$ Prompts the user for input and assigns it to variables.
INPUT # filenum, variable (variable...) INPUT # filenum, var1, var2, ... Reads data from a sequential file into variables.
INPUTS(filenum, number_of_characters) y$ = INPUTS(filenum, number_of_characters) Reads a specified number of characters from the keyboard or a file.
INSTAT y = INSTAT Returns the keyboard status.
INSTR [start, ] target string, pattern string y = INSTR(1, "Hello World", "World") Searches for a pattern within a string.
INT(numeric expression) y = INT(x) Returns the largest integer less than or equal to the argument.
IOCTL filenum, string expression IOCTL filenum, string$ Sends data to a device driver.
IOCTLS(filenum) y$ = IOCTLS(filenum) Reads data from a device driver.
KEY ON/OFF/LIST KEY ON/OFF/LIST Turns function key display on/off or lists current definitions.
KEY n, string expression KEY 1, "PRINT \"Hello\"" Defines the contents of a function key.
KEY(n) ON/OFF/STOP KEY(10) ON/OFF/STOP Turns trapping for a specific key on/off or stops trapping.
KILL filespec KILL "filename.ext" Deletes a file (like DOS DEL command).
LBOUND(arrayname, dimension) y = LBOUND(array, 1) Returns the lowest possible subscript for a specified dimension of an array.
LCASES(string expression) y$ = LCASES(x$) Converts a string to lowercase.
LEFT$(string expression, n) y$ = LEFT$("Hello World", 5) Returns the leftmost n characters of a string.
LEN(string expression) y = LEN(x$) Returns the length of a string.
LET variable = expression LET x = 10 Assigns a value to a variable (LET is optional).
LINE (x1, y1) - (x2, y2) [color] [pattern] LINE (10, 10) - (50, 50), 3, &HAAAA Draws a line or box on the graphics screen.
LINE INPUT [prompt string;] string variable LINE INPUT "Enter your address: "; address$ Reads a line of text from the keyboard, ignoring delimiters.
LINE INPUT # filenum, string variable LINE INPUT # filenum, str$ Reads a line of text from a sequential file, ignoring delimiters.
LOC(filenum) y = LOC(filenum) Returns the current file position.
LOCAL variable (variable...) LOCAL var1, var2, ... Declares local variables within a procedure or function.
LOCATE row, column [cursor] [start] [stop] LOCATE 10, 20, 1, 0, 7 Positions the cursor on the screen and defines its shape.
LOF(filenum) y = LOF(filenum) Returns the length of a file in bytes.
LOG(numeric expression) y# = LOG(x) Returns the natural logarithm (base e) of a number.
LOG2(numeric expression) y# = LOG2(x) Returns the logarithm of a number to the base 2.
LOG10(numeric expression) y# = LOG10(x) Returns the logarithm of a number to the base 10.
LPOS(filenum) y = LPOS(filenum) Returns the current printer buffer position.
LPRINT expression list LPRINT "Hello World" Sends data to the printer.
LPRINT USING format string, expression list LPRINT USING "\ ##.##", value Sends formatted data to the printer.
LSET fieldvar = string expression LSET field$ = "Hello" Moves string data into a random file buffer, left-justifying.
MEMSET address MEMSET address Declares the upper memory limit.
MID$(string expression, start, length) y$ = MID$("Hello World", 7, 5) Returns a substring from a string.
MID$(string variable, start, length) = replacement string MID$(str$, 7, 5) = "World" Replaces characters in a string.
MKDIR path MKDIR "path" Creates a subdirectory (like DOS MKDIR command).
MKIS(integer expression), MKLS(long integer expression), MKS$(single-precision expression), MKD$(double-precision expression) y$ = MKIS(x), y$ = MKLS(x), y$ = MKS$(x), y$ = MKD$(x) Converts numeric data to strings for random file output.
MKMDS(single-precision expression), MKMS$(double-precision expression) y$ = MKMDS(x!), y$ = MKMS$(x#) Converts numeric data to Microsoft format strings for random file output.
MTIMER y = MTIMER, MTIMER Resets or returns the micro-timer value.
NAME filespec AS filespec2 NAME "filename1.ext" AS "filename2.ext" Renames a file (like DOS REN command).
OCTS(integer expression) y$ = OCTS(x) Returns the octal string representation of a number.
ON COM(n) GOSUB label ON COM(1) GOSUB CommHandler Declares a subroutine to handle serial port events.
ON ERROR GOTO label ON ERROR GOTO ErrorHandler Specifies an error-handling routine.
ON/GOSUB expression, label (label...) ON x GOSUB Label1, Label2, ... Calls one of several subroutines based on the value of an expression.
ON/GOTO expression, label (label...) ON x GOTO Label1, Label2, ... Jumps to one of several lines based on the value of an expression.
ON KEY(n) GOSUB label ON KEY(10) GOSUB KeyHandler Declares a subroutine to handle a specific key press.
ON PEN GOSUB label ON PEN GOSUB PenHandler Declares a subroutine to handle light pen events.
ON PLAY notecount GOSUB label ON PLAY 10 GOSUB MusicHandler Declares a subroutine to handle background music buffer events.
ON STRIG(n) GOSUB label ON STRIG(1) GOSUB JoystickHandler Declares a subroutine to handle joystick button events.
ON TIMER seconds GOSUB label ON TIMER 60 GOSUB TimerHandler Declares a subroutine to handle timer events.
OPEN filespec FOR mode AS filenum [LEN = recordsize] OPEN "filename.ext" FOR RANDOM AS #1 LEN = 100 Opens a file or device for reading or writing.
OPEN COM(n) [baud, parity, data, stop] AS filenum [option block] OPEN COM(1) 9600, "E", 8, 1 AS #1 Opens and configures a communications port.
OPTION BASE integer expression OPTION BASE 1 Sets the minimum value for array subscripts.
OUT port, value OUT port, value Writes a byte to an I/O port.
PAINT (x, y) [color] [boundary] [background] PAINT (10, 10), 3, 1, "pattern$" Fills an enclosed area on the graphics screen with a color or pattern.
PALETTE attribute, color PALETTE 1, 3 Changes the color in the palette at a specific attribute.
PALETTE USING integer arrayname, array index PALETTE USING colorArray(), 0 Changes the entire palette using an integer array.
PEEK(offset) y = PEEK(offset) Returns the byte stored at a specified memory location.
PEN ON/OFF/STOP PEN ON/OFF/STOP Turns light pen event checking on/off or stops trapping.
PEN(option) y = PEN(option) Returns light pen status information.
PLAY string expression PLAY "O3G F# G A" Plays music using a string of commands.
PLAY ON/OFF/STOP PLAY ON/OFF/STOP Turns background music buffer checking on/off or stops trapping.
PMAP(coordinate, option) y = PMAP(x, 1) Maps physical coordinates to world coordinates or vice versa.
POINT (x, y) y = POINT(x, y) Returns the color attribute of a pixel.
POINT(option) y = POINT(option) Returns LPR information.
POKE offset, value POKE offset, value Writes a byte to a specified memory location.
POS(filenum) y = POS(filenum) Returns the current horizontal cursor position (column number).
PRESET (x, y) [color] PRESET (10, 10), 3 Plots a point on the graphics screen, turning off the pixel.
PRINT expression list PRINT "Hello World", 10, 20 Sends data to the screen.
PRINT USING format string, expression list PRINT USING "##.##", value Sends formatted data to the screen.
PRINT # filenum, [USING format string] expression list PRINT # filenum, "Hello World", 10, 20 Writes formatted data to a file.
PUT filenum, recordnumber PUT filenum, recordnumber Writes a record to a random file.
PUT (x1, y1) - (x2, y2), array [option] PUT (10, 10) - (50, 50), buffer(), PSET Copies the contents of a numeric array to the graphics screen.
PUTS(filenum, string expression) PUTS(filenum, string$) Writes a string to a binary file.
RANDOMIZE [numeric expression] RANDOMIZE TIMER Seeds the random number generator.
READ variable (variable...) READ var1, var2, ... Reads values from DATA statements into variables.
REG register, value REG 0, 1000 Sets the value of a register in the register buffer.
REG(register) y = REG(0) Returns the value of a register in the register buffer.
REM comment REM This is a comment Adds a comment to a line of code.
RESET RESET Closes all open files and devices.
RESTORE [label] RESTORE Resets the DATA statement pointer.
RESUME [0/NEXT/label] RESUME NEXT Restarts program execution after an error.
RETURN [label] RETURN Returns from a subroutine.
RIGHTS(string expression, n) y$ = RIGHTS("Hello World", 5) Returns the rightmost n characters of a string.
RMDIR path RMDIR "path" Removes a directory (like DOS RMDIR command).
RND [(numeric expression)] y# = RND Returns a random number.
RSET fieldvar = string expression RSET field$ = "Hello" Moves string data into a random file buffer, right-justifying.
RUN [filespec] RUN "filename.ext" Restarts the current program or loads and executes another program.
SCREEN mode [color/mono] [page] [opage] SCREEN 1, 0, 1, 0 Sets the screen display mode.
SCREEN row, column [option] y = SCREEN(1, 1) Returns the ASCII code of the character at a specific row and column.
SEEK filenum, position SEEK filenum, position Sets the file pointer position in a binary file.
SELECT CASE expression SELECT CASE x Begins a SELECT CASE block.
SGN(numeric expression) y = SGN(x) Returns the sign of a numeric expression.
SHARED variable (variable...) SHARED var1, var2, ... Declares shared (global) variables within a procedure or function.
SHELL parameter string SHELL "command.com" Loads and executes a child process.
SIN(numeric expression) y# = SIN(x) Returns the sine of an angle in radians.
SOUND frequency, duration SOUND 1000, 1 Generates a tone of a specified frequency and duration.
SPACES(count) y$ = SPACES(10) Returns a string consisting of spaces.
SPC(n) PRINT SPC(10), "Hello" Inserts spaces in PRINT statements.
SQR(numeric expression) y# = SQR(x) Returns the square root of a number.
STATIC variable (variable...) STATIC var1, var2, ...
STATIC variable (variable...) STATIC var1, var2, ... Declares static variables within a procedure or function.
STICK(option) y = STICK(option) Returns joystick position information.
STOP STOP Halts program execution.
STR$(numeric expression) y$ = STR$(x) Returns the string representation of a number.
STRIG ON/OFF/STOP STRIG ON/OFF/STOP Turns joystick button event checking on/off or stops trapping.
STRIG(option) y = STRIG(option) Returns joystick button status information.
STRINGS(count, value/string expression) y$ = STRINGS(10, "") Returns a string consisting of multiple copies of a character.
SUB procedurename (parameter list) [STATIC/DYNAMIC/INLINE] SUB ProcName(var1, var2, ...) Defines a procedure (subprogram).
SWAP variable1, variable2 SWAP x, y Exchanges the values of two variables.
SYSTEM SYSTEM Terminates program execution.
TAB(n) PRINT TAB(10), "Hello" Moves the print position to a specified column.
TAN(numeric expression) y# = TAN(x) Returns the tangent of an angle in radians.
TIMES TIMES = "hh:mm:ss", y$ = TIMES Sets or retrieves the system time.
TIMER y! = TIMER Returns the number of seconds since midnight.
TIMER ON/OFF/STOP TIMER ON/OFF/STOP Turns timer event checking on/off or stops trapping.
TRON/TROFF TRON/TROFF Turns tracing on/off.
UBOUND(arrayname, dimension) y = UBOUND(array, 1) Returns the highest possible subscript for a specified dimension of an array.
UCASES(string expression) y$ = UCASES(x$) Converts a string to uppercase.
VAL(string expression) y = VAL(x$) Returns the numeric value of a string.
VARPTR(variable) y = VARPTR(x) Returns the offset address of a variable.
VARPTRS(variable) y$ = VARPTRS(x) Returns a pointer to a variable in string form.
VARSEG(variable) y = VARSEG(x) Returns the segment address of a variable.
VIEW [(SCREEN) (x1, y1) - (x2, y2) [color] [boundary]] VIEW (10, 10) - (50, 50), 3, 1 Defines the active area (viewport) on the graphics screen.
WAIT port, mask WAIT port, mask Waits for a specific hardware status condition.
WHILE expression WHILE expression Begins a WHILE/WEND loop.
WIDTH [device name/filenum], size WIDTH "LPT1:", 132 Sets the logical line width for a device.
WINDOW [(SCREEN) (x1, y1) - (x2, y2)] WINDOW (0, 0) - (639, 199) Defines the graphics coordinate system.
WRITE # filenum, expression list WRITE # filenum, "Hello", 10, 20 Writes comma-delimited data to a sequential file.
WRITE expression list WRITE "Hello", 10, 20 Sends comma-delimited data to the screen.

Metastatements

Metastatement Syntax Description
$COM n, size $COM 1, 256 Allocates space for the serial port receive buffer.
$DYNAMIC $DYNAMIC Declares the default array allocation type to be dynamic.
$EVENT ON/OFF $EVENT ON/OFF Controls the generation of event-trapping code.
$IF expression THEN statement(s) [ELSE statement(s)] $ENDIF $IF x > 10 THEN PRINT "Greater than 10" ELSE PRINT "Less than or equal to 10" $ENDIF Defines portions of source code to be compiled or skipped (conditional compilation).
$INCLUDE filespec $INCLUDE "filename.ext" Includes the contents of another file during compilation.
$INLINE code block $INLINE code block Declares a block of inline machine code within a procedure.
$SEGMENT $SEGMENT Declares a new code segment.
$SOUND size $SOUND 256 Declares the capacity of the background music buffer.
$STACK size $STACK 2048 Declares the size of the run-time stack.
$STATIC $STATIC Declares the default array allocation type to be static.