GW-BASIC

Online GW-BASIC User's Manual (alphabetical listing): http://hwiegman.home.xs4all.nl/gw-man/index.html

(Direct) Commands

Most (if not all) cases where a line number is needed, a period '.' can be used to specify the current line. The current line is defined as the last line referenced by EDIT, LIST, or an error message.

  • AUTO [line number][,[increment]] — Automatically generate/increment line numbers as code lines are entered, beginning with line number. Both values default to 10.
    • Example: AUTO 100, 50
  • CONT — Continue program execution after a break (Ctrl-Break, STOP, or END)
  • DELETE [line number][-][line number] — Deletes program lines specified by the range.
  • EDIT line number — Displays specified line and places the cursor under the first digit of the line number.
  • [L]LIST [line number][-][line number][,filename] — Lists program lines specified by the range. If filename is not specified, lists the current program. Can be interrupted with Ctrl-Break. LLIST is used for the program in memory to the line printer (don't specify a filename).
  • MERGE filename — Merges lines from the program file specified (saved in ASCII format) with the current program lines (file lines will replace current lines of the same number).
  • NEW — Delete the program currently in memory and clear all variables.
  • ? [expressions][;] — Alias for PRINT
  • RENUM [new][,old][,increment] — Re-number program lines, starting at the old line and continuing until the end of the program. Default new = 10, default old is first line in the program, and the default increment is 10.
  • SAVE "filename"[,A|P] — Saves the program file (overwrites filename if it exists) in a binary format unless the A (for ASCII) argument is provided. The P argument protects the file from later LISTing or editing (intended to create a "delivery" copy).
  • SYSTEM — Exit/quit GW-BASIC (return to DOS). Closes all files.

Math Functions

  • ABS(n) — Absolute value of n
  • EXP(n) — Returns e^n (single-precision unless GW-BASIC option /d used)
  • LOG(n) — Returns natural log of n>0 (single-precision unless GW-BASIC option /d used)
  • SGN(n) — Returns "sign" of value n; -1, 0, or 1 depending on whether n is negative, 0, or positive (respectively).
  • SQR(n) — Returns $\sqrt{n}$ (n is non-negative).

Trig Functions

Angles are specified in radians.

  • ATN(x) — Arctangent of x
  • COS(x) — Cosine of x
  • SIN(x) — Sine of x
  • TAN(x) — Tangent of x

Number Conversion

  • CDBL(n) — Returns n (a numeric value) as a double-precision value
  • CINT(n) — Returns n rounded to nearest integer (see also FIX and INT)
  • CSNG(n) — Returns n (a numeric value) as a single-precision value
  • FIX(n) — Returns n with the fractional (right of the decimal) portion truncated
    • Example: FIX(1.99) returns 1
    • Example; FIX(-3.1) returns -3
  • HEX$(n) — Returns hexidecimal representation (as a string, 0-FFFF) of integer n (2 bytes). If n is negative, the representation is of the 2's complement.
  • INT(n) — Returns integer (whole number) <n (see FIX to simply truncate the decimal portion of a number)
    • Example: INT(1.99) returns 1
    • Example: INT(-3.1) returns -4
  • OCT$(n) — Returns octal representation (as a string) of integer n (2 bytes).
  • STR$(n) — Returns the string representation of the value of n.
  • VAL(x$) — Returns the numerical value of x$.

String Functions

  • ASC(x$) — ASCII decimal of first character of string x$
  • CHR$(n) — Returns the character represented by ASCII value n
  • INSTR([n,]x$,y$) — Sub-string search. Search for the first occurrence of string y$ in x$, and return the position (1 is the first character) at which the string is found. Optionally specify a starting position n (1-255). Returns 0 if:
    • n>LEN(x$),
    • x$ is empty (null), or
    • y$ is not found
  • LEFT$(x$,n) — Returns the n leftmost characters of string x$. If n = 0, an empty (null) string is returned.
  • LEN(x$) — Returns the number of characters (including non-printing characters) in string x$
  • MID$(x$,pos[,len]) — Returns sub-string of up to len characters from x$, starting at character pos (1 is the first character). If len is omitted, acts like RIGHT$. An empty (null) string is returned if pos>LEN(x$) or len is 0.
  • MID$(x$,pos[,len])=string — Replaces sub-string of x$, starting at character pos (1 is the first character), with the characters from the string expression. If len is specified, it is the number of characters from the string expression that are used to replace (not the number of characters in x$ that are being replaced) up to the end of x$. Omitting len means all of the string expression is used in the replacement (again, not increasing the length of x$).
  • RIGHT$(x$,n) — Returns the n rightmost characters of string x$. If n = 0, an empty (null) string is returned.
  • SPACE$(n) — Returns a string of n (0-255) spaces.
  • STRING$(n,char) — Returns a string of n (0-255) characters, where char is either the numeric ASCII code, or a string (first character of the string is used).

Date/Time

  • DATE$ - Variable holding "current" date (can be assigned to using an approved format)
  • TIME$ - Variable holding "current" time (can be assigned to using an approved format)
  • TIMER - Returns single-precision elapsed number of seconds since midnight or system reset.

Data Manipulation

  • BLOAD"filename"[, offset] — Load binary (e.g. image) data into user memory at offset location (see DEF SEG)
  • BSAVE"filename", offset, length — Save portions of user memory (e.g. screen buffer; see DEF SEG) to a file
  • CALL offset[(variables, …)] — Call assembly/machine language subroutine in user memory (see also USR)
  • CLEAR [,[maxProgBytes][,stackSpaceBytes]] — Initializes all numeric vars to 0, all string vars to null, and closes all open files. Optionally also sets data segment memory space (protects user memory) and/or stack space.
  • CVI(x$) — Returns integer represented by the 2-byte "string" x$ (This is related to data serialization for "random access" files; see ASC to get ASCII decimal of a character)
  • CVS(x$) — Returns single-precision value represented by the 4-byte "string" x$ (This is related to data serialization for "random access" files)
  • CVD(x$) — Returns double-precision value represented by the 8-byte "string" x$ (This is related to data serialization for "random access" files)
  • DATA const, … — Stores numeric and string constants that are accessed by READ statements
  • DEF SEG[=address] — Assign the current segment address (0-65535) to be referenced by a subsequent BLOAD, BSAVE, CALL, PEEK, POKE, or USR. Omitting =address restores to the BASIC Data Segment.
  • DEF USRn[=address] — (Where n is 0-9, 0 if omitted) Assigns the starting address (user memory) for an Assembly language subroutine called by the USR function.
  • LSET|RSET p$=string — Prepare string into random access buffer (pointer) p$ (prior to PUT); left- or right-justify (padded with spaces) within the space allocated for the field.
  • MKI$(n) — Returns a 2-byte "string" representing integer n as its bytes (serialization for storage in random access files)
  • MKS$(n) — Returns a 4-byte "string" representing single-precision n as its bytes (serialization for storage in random access files)
  • MKD$(n) — Returns an 8-byte "string" representing double-precision n as its bytes (serialization for storage in random access files)
  • PEEK(offset) — Returns the byte stored at the address offset from base address (set by DEF SEG).
  • POKE offset,byte — Writes the byte for storage to the address offset from base address (set by DEF SEG).
  • READ var, … — Read values from DATA and assign to variables listed (type must agree with the constant value from the DATA list).
  • RESTORE [linenum] — Resets DATA at the specified line number (or first DATA if line number is not specified) for the next READ
  • SWAP var1,var2 — Swap the value of two variables (of the same type).
  • VARPTR(var|#filenum) — Returns the address of the variable or file control block (FCB).
  • VARPTR$(var) — Returns a 3-byte "string" with address information (see documentation) about the variable.

I/O Statements

  • CLOSE [[#]filenumber[,[#]filenumber]…] — Close files associated with each filenumber specified (or all files if no filenumber specified)
  • EOF(filenumber) — Returns -1 (true) if GET is done past the end-of-file (EOF); returns 0 if EOF has not been found.
  • FIELD [#]filenum, numbytes AS var, … — Allocate space for variables (pointers) in a random access file buffer
  • GET [#]filenum[, recordnum] — Read a data record (next record, or the record specified by recordnum) from random access data file. The data record is stored into the variables (pointers) defined by the FIELD call(s) for the filenum.
  • INP(n) — Returns 1 byte read from machine port n (0-65535)
  • [LINE] INPUT[;] [prompt;] var(s) — Prompt user for keyboard input into the specified var(s). A semicolon before the prompt will suppress printing the newline when the user hits Return (next PRINT will be on the same line as the user input). A comma (instead of a semicolon) after the prompt string will suppress the question mark that is appended to the prompt. LINE INPUT doesn't require the user to double quote a string when commas or other special characters are present.
  • [LINE] INPUT# filenum, var, … — Read data from (sequential) file into the specified variables. Numbers are delimited in the stream by space, newline, or comma; Strings are delimited by double-quotes (paired), comma, newline, or 255 characters. LINE INPUT# Reads an entire line (up to 255 characters) without delimiters from the file into a single string variable.
  • INPUT$(n[,[#]filenum)] — Returns n characters read from keyboard or file. Characters are not echoed to the screen. Preferred for communications streams.
  • IOCTL[#]filenum,string — Write "control data" string to device [driver] at filenum.
  • IOCTL$([#]filenum) — Returns "control data" string from device [driver] at filenum.
  • LOC(filenum) — Returns the current "position" in the file (returns 0 if no read or write has been performed):
    • Communication stream — Number of characters waiting to be read (<=255)
    • Random access files — Last record number accessed
    • Sequential files — Number of 128-byte blocks read from, or written to, since file was opened. When file is opened for input, GW-BASIC initially reads the first sector of the file so LOC returns 1.
  • [UN]LOCK [#]filenum [,[recnum] [TO recnum]] — Lock file access (temporarily; use UNLOCK before closing the file) to prevent other processes (network environment) from reading/writing the file. Specifying a range of record numbers can be used to partially restrict a random access file (sequential files are locked in toto). Specifying a single recnum only locks that record; not specifying a recnum before TO assumes recnum 1 as the beginning of the range. UNLOCK must specify the record numbers to unlock (all locked record numbers must eventually be unlocked).
  • LOF(filenum) — Returns the number of bytes allocated to file
  • OPEN "mode",[#]filenum,filename[,recordlength] — Open filename as filenum for access "mode" (follows). Specify recordlength for size of records in random access files (default is 128 bytes).
    • "I" — Sequential input
    • "O" — Sequential output (overwrite)
    • "A" — Sequential output (append)
    • "R" — Random access input/output
  • OPEN filename [FOR mode] [ACCESS access] [lock] AS [#]filenum [LEN=recordlength] — (Alternate syntax) Open filename as filenum in the specified mode (default is RANDOM). Do not double-quote the mode. See documentation for description of ACCESS and lock.
    • mode values:
      • INPUT
      • OUTPUT
      • APPEND
      • RANDOM
    • access values:
      • READ
      • WRITE
      • READ WRITE
    • lock values:
      • SHARED
      • LOCK READ
      • LOCK WRITE
      • LOCK READ WRITE
  • OPEN "COMn:[speed][,parity][,data] [,stop][,RS][,CS[n]][,DS[n]][,CD[n]][,LF] [,PE]" AS [#]filenum [LEN=number] — Allocate a buffer to support RS-232 asynch comms with other computers and peripheral devices. See documentation.
  • OUT port,byte — Writes 1 byte (0-255) to machine port (0-65535)
  • PRINT[#filenum,] [USING formatstring] expression; …[;] — Output list of expressions (space, semicolon, or comma delimited) to display or sequential file. Output a blank line if expressions are omitted. Expressions preceded by the comma delimiter begin at the start of the next 14-char-wide "zone". If the list of expressions ends with a delimiter, the newline is omitted (next PRINT begins where appropriate for the delimiter). Number expressions are always displayed with a following space; positive and negative numbers are displayed with a preceding space or minus sign, respectively. See PRINT USING documentation for explanation of formatstring.
    • SPC(n) — This expression is only valid within a PRINT list to print n (0-255) spaces (with an implied semicolon). See SPACE$ function to return a string of spaces outside of a PRINT statement.
    • TAB(n) — This expression is only valid within a PRINT list to space to column n (1-40|80; going to the next line if the current position is beyond n). TAB has an implied semicolon at the end.
  • PUT[#]filenum[,recnum] — Write data (buffered in memory by FIELD variables, LSET/RSET, PRINT#, or WRITE#) to random access file at recnum (or next available record if recnum not specified).
  • RESET — Close all disk files and write the directory information to diskettes before they are removed from a disk drive.
  • WRITE [#filenum,] expression; … — Like PRINT (see above) except that commas are inserted between display items, strings are double-quoted, and positive numbers do not have a preceding space.

Line printer

  • LPOS(x) — Returns the current position of the line printer print head within the line printer buffer (x is a dummy argument).
  • LPRINT [USING formatstring] expression; …[;] — Print list of expressions (semicolon delimited) to line printer. See PRINT.

Program Flow

  • CALL offset[(variables, …)] — Call assembly/machine language subroutine in user memory (See also USR)
  • CHAIN [MERGE] "filename"[,[line][,[ALL][,DELETE range]]] — Run (possibly overlay) specified program
    • COMMON var, … — Specifies common variables to be passed to a chained program (reset by CLEAR)
  • END — Terminate program execution, close all files, and return to command level
  • FOR var=init TO last [STEP increment] : NEXT [var, …] — Loop (multiple lines between FOR and NEXT allowed)
  • GOSUB linenum — Jump to linenum as a subroutine call
    • RETURN [linenum] — Jump to the statement following the most recent GOSUB call. Specifying a linenum (dangerous) is primarily intended for use with event trapping (see Event handling below).
  • GOTO linenum — Jump to linenum. Execution proceeds at the linenum or the first executable line following linenum.
  • IF expression[,] THEN statement(s)[[,] ELSE statement(s)] — Conditional branching. Must be one line (nesting IF-THEN must fit within the line size requirement). Line numbers can follow THEN or ELSE and act as a GOTO (see next form). ELSE matches closest unmatched THEN.
  • IF expression[,] GOTO linenum[[,] ELSE statement(s)] — Same as above, but only a line number (not statements) follows the GOTO.
  • ON n GOTO|GOSUB linenum,… — A "switch-case" type branching structure. Each linenum listed is the destination when integer n is the corresponding value (>=1). If n is 0 or greater than the number linenums listed, then the program continues to the next statement.
  • RUN [linenum|filename][,R] — Execute a program. Unless filename is specified, runs the program currently in memory from the linenum (if specified) or the first program line. Specifying a filename will close all open data files (unless the "R" argument is provided), deletes the current memory contents and loads/executes the specified program.
  • STOP — Halts program execution and returns to command level. Files remain open (contrast with END). Execution is resumed with CONT.
  • USRn (arg) — Call Assembly language subroutine n (0-9, 0 if omitted) with the specified argument (numeric or string, must be specified even if it's a dummy argument).
  • WHILE condition : WEND — While loop (multiple lines between WHILE and WEND allowed)

Program/data structure

  • DEF FNname[arguments] expression — Define a user function (expression is a single statement)
    • Example: DEF FNAB(X, Y)=X^3/Y^2 {later called:} T=FNAB(R, S)
  • DEFINT letters — Declare variables beginning with letters (range and/or comma-separated) to be of type integer (unless overridden with %,!,#,$)
  • DEFDBL letters — Declare variables beginning with letters (range and/or comma-separated) to be of type double-precision (unless overridden with %,!,#,$)
  • DEFSNG letters — Declare variables beginning with letters (range and/or comma-separated) to be of type single-precision (unless overridden with %,!,#,$)
  • DEFSTR letters — Declare variables beginning with letters (range and/or comma-separated) to be of type string (unless overridden with %,!,#,$)
  • DIM var(last index) — Allocate array size for arrays that need more than the default of 10 elements. Note that the last index is specified (not the total size).
  • ERASE array, … — Deallocates list of arrays. This must be done before re-DIM-ing the arrays.
  • [LET] var=expression — Optional keyword for variable assignments (maintained for backward compatibility with older BASICs)
  • LOAD"filename"[,R] — Load a program file (if extension is omitted from filename, then .BAS is used), deleting all program lines in memory. If R is specified, then all open data files are kept open (and maybe variables are kept? - - documentation is contradictory about this point) and the new program automatically runs. Otherwise, all open files are closed and all variables are deleted. See also RUN.
  • OPTION BASE n — Declare the minimum value (base) for array subscripts; 1 or 0 (default is 0). Declare before define (DIM) or use any arrays.

Event handling

  • COM(n) ON|OFF|STOP — Enable/disable trapping of comm activity (event) to the specified communications adapter (1 or 2)
  • KEY n,CHR$(hex code)+CHR$(scan code) — Define a keystroke (assigned to n; 15-20) to be captured as an ON KEY event.
  • KEY(n) ON|OFF|STOP — Enable/disable key event capture.
    • n = 1-10 — Function keys 1-10
    • n = 11-14 — Cursor keys Up, Right, Left, Down
    • n = 15-20 — User defined keystrokes (see above)
  • ON event GOSUB linenum — Specified an event handler subroutine. If the event is ON (vs OFF or STOP), an occurrence of the event is check before each statement during program execution. Specifying linenum 0 for the GOSUB disables trapping for the event. These are the events trapped by this syntax (see entries for each event for more info):
    • COM(n)
    • KEY(n)
    • PEN
    • PLAY(n)
    • STRIG(n)
    • TIMER(n)
  • ON ERROR GOTO linenum — Enables and specifies an error handling subroutine. A linenum of 0 disables your error handling subroutine (errors will print a message and halt execution). If ON ERROR GOTO 0 is within an error handling subroutine, GW-BASIC will stop and print the error message (recommended for unrecoverable errors).
    • RESUME [0|NEXT|linenum] — Resume program execution after handling an error, i.e. "return" from error handling subroutine. RESUME and RESUME 0 both resume execution at the statement that caused an error. Specifying NEXT resumes execution at the statement immediately after the one that caused the error. Specifying a linenum resumes execution starting at the specified linenum.
  • PEN ON|OFF|STOP — Enable/disable light pen event capture. Performance improvement: turn PEN OFF for programs not using the light pen.
    • PEN(n) — Returns light pen state (e.g. coordinates) depending on the specified value of n (see documentation).
  • PLAY(n) — As a standalone function (n is a dummy argument), returns the number of notes (0-32) currently in the background music queue; 0 if music is not in background. In the context of ON PLAY(n) GOSUB …, an event trap occurs when the background music queue goes from n to n-1 notes.
  • STRIG[(n)] [ON|OFF|STOP] — Enables/disables joystick button press event captures for joystick buttons (as specified by n, see documentation). As a standalone function, returns a button state based on n (0-7; see documentation).
  • TIMER ON|OFF|STOP — Enables/disables a timer (like a stopwatch). ON TIMER(n) event trap occurs when n seconds (1-86400) have elapsed since TIMER ON.
  • WAIT port,andmask[,xormask] - Suspend program execution while monitoring the status of a machine input port, waiting for the port value XOR xormask AND andmask to be true (non-zero).

System/Shell Commands

  • CHDIR "path" — cd to path
  • ENVIRON "string" — Set ENV VARs (only affects the interpreter's environment, e.g. set ENV for child processes).
    • Example: ENVIRON "PATH=A:\"
  • ENVIRON$("var") — Returns the value of ENV "var"
  • FILES "path" — List files like dir (wildcards ? and * allowed)
  • KILL "filename" — Deletes the file (error if file is open)
  • MKDIR "path" — Creates subdirectory
  • NAME oldfile AS newfile — Renames (but does not move) file oldfile with new name. Error if oldfile doesn't exist or newfile already exists.
  • RMDIR "path" — Deletes subdirectory (must be empty)
  • SHELL ["string"] — Executes DOS shell command specified (or, if a string isn't specified, just starts a DOS shell session; use EXIT to return to GW-BASIC).

Graphics Commands

  • BLOAD"filename"[, offset] — Load binary (e.g. image) data into user memory at offset location (see DEF SEG)
  • CIRCLE (xcenter, ycenter), radius[,[color][,[start],[end][,aspect]]] — Draw a circle, ellipse, or arc (start and end angles are in radians)
  • CLS [n] — Clear the screen. If specified, n = 0 means clear all text & graphics; n = 1 means clear only graphics viewport; n = 2 means clear only text window
  • COLOR [option1][, option2] — Set colors/palettes used (options depend on SCREEN being used).
  • CSRLIN — Returns the current line (1 - 25) of the text cursor on the screen
  • DRAW"string" — Draws graphics based on the GML command string.
  • GET (x1,y1)-(x2,y2), array — Store/buffer (into the array) the graphics image data from within the bounding box defined by the diagonal corners (x1,y1) and (x2,y2). See User's Manual entry for array sizing requirements.
  • LINE [(x1,y1)]-(x2,y2) [,[color][,B[F]][,style]] — Draws a line, empty box (B), or filled box (BF). If the first coordinate (x1, y1) is not provided, then the last point referenced (or center of the screen) is used. The style is a 16-bit mask to create dotted-lines (illegal for BF).
  • LOCATE [linenum][,[col][,[visible][,[start] [,stop]]]] — Change the location/state of the cursor. All parameters are optional; omit between commas to leave current value unchanged.
    • linenum — 1-25
    • col — 1-40 or 1-80 (depending on SCREEN resolution)
    • visible — 0 for off, non-zero for on
    • start, stop — 0-31, sets where scan lines start and stop
  • PAINT (x,y)[,fg[,border][,bg]] — Fill an area that contains non-border point (x,y). Will not fill outside of pixels that match the border attribute (which defaults to the foreground attribute). If the foreground is numeric, it specifies a color; otherwise a foreground string (hexidecimal) describes a tiling mask (see documentation).
  • PALETTE [attribute, color] — For EGA capable screens, assigns color number to the attribute number (used when specifying a "color").
  • PALETTE USING array(index) — (Alternate syntax) Assigns colors listed in the array (starting at the specified index) to each palette attribute in order. The array must be dimensioned large enough to hold a color for each palette attribute starting from the given index (e.g. for 16 attributes starting at index 5, the array must be big enough to have subscript 20).
  • PCOPY srcpage,destpage — Copy one screen page to another in all screen modes.
  • PMAP (expression, flag) — Returns a coordinate converted from a logical expression to a physical coordinate, or vice versa, depending on which flag is set:
    • flag = 0 — logical expressions to physical x
    • flag = 1 — logical expressions to physical y
    • flag = 2 — physical expressions to logical x
    • flag = 3 — physical expressions to logical y
  • POINT (x,y) — Returns attribute (color) of pixel at specified coordinate (return -1 if coordinate is out of range)
  • POINT (flag) — Returns value depending on flag:
    • flag = 0 — returns current physical x coordinate
    • flag = 1 — returns current physical y coordinate
    • flag = 2 — returns current logical x coordinate if WINDOW is active; otherwise, it returns current physical x coordinate
    • flag = 3 — returns current logical y coordinate if WINDOW is active; otherwise, it returns current physical y coordinate
  • POS(x) — Returns the column the cursor is at (leftmost is 1). The argument x is a dummy argument.
  • P[RE]SET [STEP](x, y)[,color] — Set a pixel's color at the specified coordinates. STEP is used for relative coordinates.
  • PUT (x,y),array,[,action] — Display at the specified coordinate the graphics image stored in the array by GET. The action token describes how to add the pixels to the screen:
    • PSET — Puts the image on screen verbatim (to how its data is stored)
    • PRESET — Inverse ("negative") image
    • AND — Puts the image masked by an existing image
    • OR — Superimposes (merges) the image onto an existing image
    • XOR — (Default) "Undoes" the existing matching image, i.e. PUT an image in the same place a second time to remove it.
  • SCREEN (line,column[,colorflag]) — Returns the numeric ASCII code for the character located at the specified screen line (row) and column. If the colorflag is specified and true (non-zero), then the color attribute (alpha mode only, see COLOR) of the character at that location is returned instead.
  • SCREEN [mode] [,[colorswitch]][,[apage]][,[vpage]] — Set the specifications for the display screen (see documentation).
  • VIEW [SCREEN] [(x1,y1)-(x2,y2)[,fill][,border]] — Define a physical viewport limit. Resets to whole screen if no arguments specified.
  • VIEW PRINT [topline TO bottomline] — Restricts text output to the specified lines (1-24, line 25 is reserved). If the line arguments are not specified (re)sets the whole screen as the text window.
  • WIDTH [filenum,|"device",] size — Sets the max number of characters per line for the screen, file, or device. The size (0-255) must be 40 or 80 for the screen (also device "SCRN:").
  • WINDOW [SCREEN] [(x1,y1)-(x2,y2)] — Define a "world" boundary for graphics coordinates that can expand beyond the physical screen cooridates. Pan and zoom with the VIEW statement. Omit arguments to disable previous WINDOW statements.

Misc. Statements

  • BEEP — Generate a computer speaker beep (same as Ctrl-G or PRINT CHR$(7))
  • ERROR num — Generates ("throws") error num. Certain values of num are predefined errors.
  • EXTERR(n) — Returns MS-DOS 3.0+ extended error information (returns 0 for MS-DOS <3.0)
    • n = 0 — returns extended error code
    • n = 1 — returns extended error class
    • n = 2 — returns extended error suggested action
    • n = 3 — returns extended error locus
  • FRE(x) — Returns the number of available bytes in allocated string memory. The argument (x) is just a dummy argument, but if the dummy argument is a string (x$), then GW-BASIC first does garbage collection (which could take 60-90 seconds) before returning a value.
  • KEY fn, string — Redefine function key (fn is a number 1-10) to enter string of up to 15 characters. Assigning an empty (null) string disables the function key.
    • KEY LIST — List all 10 key values on the screen. All 15 characters of each value are displayed.
    • KEY ON — Displays F-key "reminders" at bottom of screen (25th line). Only first 6 (of 15) characters of each F-key's string are displayed.
    • KEY OFF — Suppresses display of F-key "reminders" at bottom of screen (25th line).
  • PLAY string — Play music specified by the Music Macro Language (MML; see documentation) string.
  • RANDOMIZE TIMER|expression — (Re-)seed the random number generator. Use RANDOMIZE TIMER for best "randomization".
  • REM [comment] — Comment line. Abbreviated with an apostrophe ', which can also be used after code on a program line (except on a DATA line).
  • RND [(x)] — Return a random number between 0 and 1. If x is 0, last number is repeated. Otherwise, if x>0 or omitted, next number is generated.
  • SOUND freq,ticks — Generate a sound through the speaker. The pitch (freq) is expressed in Hertz, and the duration is expressed in clock ticks (see documentation for reference to notes and tempo conversions).
  • STICK(n) — Returns a joystick coordinate based on n:
    • n = 0 — x coordinate of joystick A. Stores the x and y values for both joysticks for the following three function calls.
    • n = 1 — y coordinate of joystick A.
    • n = 2 — x coordinate of joystick B.
    • n = 3 — y coordinate of joystick B.
  • TRON|TROFF — Enable/disable line number tracing of program execution. Tracing is also disabled during a NEW command.

Misc. Variables

  • ERDEV — Value of device error (See Interrupt 24H)
  • ERDEV$ — Name of device in error (See Interrupt 24H)
  • ERL — Line number where error occurred (65535 in direct mode)
  • ERR — Error code of last error
  • INKEY$ — Next pending character read from the keyboard. Empty string if none, or 1-2 character string (2-character string is extended code which will start with 0).
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License