Generated by TXTS2HTM.BAT, (c) John Paul Jones, 2000
QBasic Statements: BLOAD Statement BEEP Statement BSAVE Statement COM Statement COLOR Statement CALL Statement CHAIN Statement CALL ABSOLUTE Statement CHDIR Statement CONST Statement COMMON Statement CIRCLE Statement CLEAR Statement CLNG Statement CLOSE Statement CLS Statement DIM Statement DATE$ Statement DATA Statement DECLARE Statement DO WHILE Statement DO UNTIL Statement DEF FN Statement DEF SEG Statement DRAW Statement DEFDBL Statement DEFINT Statement DEFLNG Statement DEFSNG Statement DEFSTR Statement ENVIRON Statement END Statement ERASE Statement EXIT Statement ERROR Statement FOR Statement FILES Statement FUNCTION Statement FIELD Statement GOTO Statement GET Statement (File I/O) GET Statement (Graphics) GOSUB Statement INPUT# Statement INPUT Statement IF Statement IOCTL Statement KILL Statement KEY Statement KEY(n) Statements LINE INPUT Statement LPRINT USING Statement LINE Statement LET Statement LOCATE Statement LPRINT Statement LOCK Statement LSET Statement MID$ Statement MKDIR Statement NAME Statement ON ERROR Statement ON EVENT Statement OPEN Statement OUT Statement OPTION BASE Statement ON expression Statement PSET Statement PRINT Statement PRINT USING Statement POKE Statement PRESET Statement PCOPY Statement PAINT Statement PEN Statement PUT Statement (File) PUT Statement (Graphics) PLAY Statement PALETTE Statement PLAY Statements (Event Trapping) READ Statement REM Statement RMDIR Statement RUN Statement RESET Statement RETURN Statement RSET Statement RESUME Statement REDIM Statement RESTORE Statement RANDOMIZE Statement SELECT CASE Statement SYSTEM Statement SLEEP Statement SOUND Statement STOP Statement STATIC Statement SHELL Statement SEEK Statement SHARED Statement SCREEN Statement SWAP Statement SUB Statement STRIG Statement TYPE Statement TRON Statement TIME$ Statement TIMER Statement TROFF Statement UNLOCK Statement VIEW Statement VIEW PRINT Statement WRITE Statement WIDTH Statement WHILE WEND Statement WINDOW Statement WAIT Statement QBasic Functions: ASC Function ATN Function ABS Function CHR$ Function COMMAND$ Function CINT Function CDBL Function COS Function CSNG Function CLNG Function CVD Function CSRLIN Function CVDMBF Function CVI Function CVL Function CVS Function DATE$ Function EOF Function ERR Function ERL Function EXP Function ERDEV Function ERDEV$ Function FIX Function FRE Function FREEFILE Function FILEATTR Function HEX$ Function INSTR Function INPUT$ Function INT Function INKEY$ Function INP Function IOCTL$ Function LTRIM$ Function LCASE$ Function LEFT$ Function LEN Function LOF Function LBOUND Function LOG Function LOC Function LPOS Function MID$ Function MKD$ Function MKDMBF$ Function MKI$ Function MKL$ Function MKS$ Function MKSMBF$ Function OCT$ Function POS Function PEEK Function PMAP Function POINT Function PEN Function PLAY Function RTRIM$ Function RND Function RIGHT$ Function SEEK Function SGN Function STRING$ Function STR$ Function SPACE$ Function SPC Function SQR Function SIN Function STICK Function STRIG Function SCREEN Function TAN Function TAB Function TIME$ Function TIMER Function UBOUND Function UCASE$ Function VAL Function VARSEG Function VARPTR Function VARPTR$ Function
BLOAD Statement BLOAD Statement --------------- Loads memory image file created by BSAVE statement into memory at the specified location Usage: BLOAD filename[,offset] * offset is the optional offset from the start of the data segment (or last DEF SEG)), indicating where the image is to be loaded. * filename is a string expression that specifies the file containing the image to load. * BLOAD and BSAVE work together to provide you with a quick and convenient way to load array values or graphics images. * Do not use BLOAD with files created by BASICA, QBASIC and BASICA store items differently in memory. Example: 'Create an array called sales DIM sales (1 TO 500) 'Set the segment address to the start of SALES DEF SEG = VARSEG(sales(1)) 'Load the array using BLOAD BLOAD "SALES.DAT", VARPTR(sales(1)) 'Return the the BASIC data segment DEF SEG Related functions: VARPTR, VARSEG Related Statements: BSAVE, DEF SEG BEEP Statement BEEP statement -------------- Sounds the computers built-in speaker. Usage: BEEP BSAVE Statement BSAVE statement --------------- Copies the contents of a memory region to an output file or device. Usage: BSAVE filename, offset, length * filename is a string expression that specifies the file or device to which memory will be transfered. * offset is the location within the current segment of thefirst byte you want to copy. * length is the number of bytes to copy (from 0 to 65,535). * BSAVE performs a byte-by-byte copy. If you save the memory contents to a file, you can later use BLOAD to restore the memory image. Example: 'Create an array with 500 elements 'Initialize the array with values from 1 through 500 DIM sales(1 TO 500) FOR i = 1 TO 500 sales(i) = i NET i 'Set the segment address to the start of sales DEF SEG = VARSEG(sales(1)) 'Save the array using BSAVE BSAVE "SALES.DAT", VARPTR(sales(1)), 2000 'Return the Basic data segment DEF SEG Related functions: VARPTR, VARSEG Related statements: BLOAD, DEF SEG COM Statement COM Statement ------------- Enables or disables data communications eveent trapping on the specified port. Usage: COM(n) ON or COM(n) OFF or COMn) STOP Notes: * n is the comunications port number (1 or 2). * COM ON enables communications event trapping. If a character arrives at the port, your program will execute the subroutine defined by the ON COM statement. * COM OFF disables communications event trapping. Characters arriving at the port are ignored. * COM STOP prevents event trapping until the program executes a COM ON statement. Events are processed once trapping is enabled. Example: ON COM(1) GOSUB ComHandler COM(1) ON Related statements: ON event GOSUB COLOR Statement COLOR Statement --------------- Sets the screen color. Usage: COLOR[foreground][,background][,border]] (screen mode 0) COLOR[background][,palette] (screen mode 1) COLOR [foreground][,background] (screen modes 7-10) COLOR [foreground] (screen modes 4, 12, 13) Notes: * The COLOR statement allows you to set text foreground and background colors as well as color pallette in graphics mode. * See the SCREEN statement for specifics on each screen mode. * In screen mode 0, you can set the text foreground color to one of 16 colors (0 through 15). To use the blinking version of the color, add value 16 to the color, yeilding a value in the range of 16 to 31. The background screen border must be a color value from 0 to 15. * In screen mode 1, you can specify a palette value in the range 0 through 255. The palette determines which of two sets of colors to use for graphics display. * In screen modes 7 through 10, the foreground color is an attribute number and the background color is a color number. * Int screen modes 4, 12, and 13, the foreground color is an attribute number. You cannot specify a background color. Example: SCREEN 0 FOR fcolor = 0 TO 31 COLOR fcolor PRINT "Current color is"; fcolor INPUT dummy$ NEXT fcolor Related functions: POINT, SCREEN Related statements: CIRCLE, DRAW, LINE, PAINT PALETTE, PALETTE USING, PRESET, PSET, SCREEN CALL Statement CALL Statement -------------- Transfers control to a Basic subprogram. Usage: CALL subprogram_name[(argument_list)] or subprogram_name[argument_list] * subprogram_name is the name of a Basic subprogram crated using a SUB statement. * argument_list is a list of parameters seperated by comas. The subprogram can change the values of the parameters. * You can call subprograms with or without the CALL keyword If you omit CALL, do not pace the arguments within parentheses. Also, if ou omit CALL, you must use the DECLARE statement. If you omit a declaration, QBasic willsupply it automatically. * To prevent a subprogram from changing a parameter's value, simply put the parameter in parentheses: CALL TEST (a, b, (c)) * In this case, the subprogram can change the values of the parameters 'a' and 'b' but not 'c'. Example: DECLARE SUB SwapVal (a, b) a = 1 b = 2 Call SwapVal(a, b) PRINT a; b END SUB SwapVal(x, y) temp = x x = y y = temp END SUB Output of this program: 2 1 Related statements: CALL ABSOLUTE, CHAIN, DECLARE CHAIN Statement CHAIN Statement --------------- Transfers control from one QBASIC program to another. Usage: CHAIN filename Notes: * filename is a character string containing the filename of the program to which control is to be passes. * To exchange information between chained programs, you must use the COMMON statement. * After you transfer control to another program using CHAIN, the program that called CHAIN does not resume control when the chained program completes. Example: CHAIN "TEST.BAS" Related statements: CALL, COMMON, RUN CALLABSO Statement CALL ABSOLUTE Statement ----------------------- Transfers control to a machine language subroutine. Usage: CALL ABSOLUTE ([parameter_list,]offset) Notes: * parameter_list is an optional list of parameters seperated by comas. * offset is the location within the current code segment of the start procedure. Example: 'Create a machine-language procedure and 'call it using CALL ABSOLUTE 'Array to store machine code DIM Asmroutine(1 TO 6) AS INTEGER 'Data that makes up machine-code routine DATA &H55 : 'PUSH BP DATA &H8B, &HEC : 'MOV BP, SP DATA &HB4, 2 : 'MOV AH, 2 DATA &HB2, 65 : 'MOV DL, 65 DATA &HCD, &H21 : 'INT 21H DATA &H5D : 'POP BP DATA &HCB, 0 : 'RET 'Get array offset offset = VARPTR(asmroutine(1)) 'Change the segment to the start of the array DEF SEG = VARSEG(asmroutine(1)) 'Fill the array with machine code FOR i = 0 TO 11 READ asmcode POKE (offset + i), asmcode NEXT i 'Call the routine and restore the segment CALL ABSOLUTE(VARPTR(asmroutine(1)) DEF SEG Related Statements: CALL CHDIR Statement CHDIR Statement ---------------- Changes the default directory for the specified drive. Usage: CHDIR directory_name Notes: * directory_name is a string expression containing the desired directory name. It must have fewer than 64 characters * To change the default directory for a drive other than the current drive, precede the pathname with a disk drive letter and colon. * CHDIR does not change the default drive. Example: 'Change the current directory in drive C to \DOS CHDIR "C:\DOS" Related statements: FILES, MKDIR, RMDIR CONST Statement CONST Statement --------------- Defines a symbolic constant. Usage: CONST symbol_name = expression[,symbol_name = expression]... Notes: * constants allow programs to use symbolic names in place of numeric or string values. * symbol_name is the name the constant will have throughout the program. You cannot change the value of a constant once you've defined it. * expression is a numeric or string expression assigned to the constant. You cannot use variables or functions in the expression. * Constants defined in a subprogram or function are local to that subprogram or function. Example: CONST true = 1 CONST daysperweek = 7 'Use of constant in array declaration DIM Days(daysperweek) COMMON Statement COMMON Statement ---------------- Defines variables as global within a module or between chained programs. Usage: COMMON [SHARED]variable_list CIRCLE Statement CIRCLE Statement ---------------- Drawa a circle or ellipse with the specified radius and center. Usage: CIRCLE[STEP](x,y),radius[,[color][,[start_angle] [,[end_angle][,aspect_ratio]]]] Notes: * STEP is an optional keyword that tells CIRCLE that the x and y values are offsets from the current graphics cursor * x,y are the coordinates of the circle's center * radius is the radius of the circle in the current coordinate system. * color is the border color for the circle. The circle is not filled. * start_angle is the starting angle in radians for the arc. The default is 0. * end_angle is the ending angle in radians for the arc. The default is 2 pi. * aspect_ratio is the ratio of the length of the y axis to the length of the x axis. By changing the aspect ratio, you can create ellipses. Example: 'Fill the screen with random circles SCREEN 1 FOR i = 1 TO 100 x = INT(320 * RND) y = INT(200 * RND) RADIUS = INT(100 * RND) CIRCLE (x,y), RADIUS NEXT i SCREEN 0 Related functions: POINT Related statements: COLOR, DRAW, LINE, PAINT, PRESET, PSET, SCREEN CLEAR Statement CLEAR Statement --------------- Initializes all program variables, closes all files, and optionally defines the stack size. Usage: CLEAR [,,stack_size] Notes: * CLEAR loses all open files, sets numeric variables and arrays to 0, and sets all string variables to zero length. * If your program uses recursion or performs several levels of subroutine calls, you might need to increase your program's stack size * stack_size is the size of the stack in bytes. You must precede the stack size with two commas shown. * The default stack size is 2048 bytes * Do not execute CLEAR within a subroutine Example: 'Initialize variables and create a stack of 4096 bytes CLEAR , , 4096 Related functions: FRE Related statements: ERASE CLNG Statement CLNG Statement -------------- Rounds a numeric expression to a long (4-byte) integer. Usage: CLNG(numeric_expression) Notes: * numeric_expression must evaluate to a value in the range -2,147,483,648 through 2,147,483,647. If the result is outside this range, a runtime error occurs. Example: PRINT CLNG(338457.8) PRINT CLNG(2147358.28) Output: 338458 2147358 Related functions: CDBL, CINT, CSNG CLOSE Statement CLOSE Statement --------------- Close one or more files or devices opened by the OPEN statement. Usage: CLOSE[[#]file_number[,[#]file_number]... Notes: * file_number is the file number assigned to the file or device in its OPEN statement. * You can specify more than one file number in a single CLOSE statement. * Once you close a file number, you cannot use the file number for read or write operations until you open a new file. * The CLEAR, END, RESET, RUN, and SYSTEM statements close your files automatically. * CLOSE with no arguments closes all OPEN files and deviices. Example: OPEN "TEST.DAT" FOR OUTPUT AS #1 PRINT "This is a test." CLOSE #1 Related statements: OPEN, RESET CLS Statement CLS Statement ------------- Clears the screen display. Usage: CLS[{0|1|2}] Notes: * Depending on the region of the screen that you want to clear, CLS gives you four options: Statement Result CLS Clears text or graphics viewport CLS 0 Clears entire screen of text and graphics CLS 1 Clears only the graphics viewport CLS 2 Clears only the text viewport, leaving the bottom line unchanged. Example: CLS Related statements: VIEW, VIEW PRINT, WINDOW DIM Statement DIM Statement ------------- Declares an array variable and allocates storage. Usage: DIM[SHARED]variable_name[(subscripts)][AS type][,variable_name[(subscripts)][AS type]... Notes: * The SHARED keyword allows subprograms and functions to share the same variable without passing the variable as a parameter. * variable_name is the name of the array. * subscripts is the dimensions of the array. If you have not previously defined an array in a DIM statement, you can assign a value to an element that has subscript ranging from 0 to 10. You can change the lower and upper bounds as shown here: DIM a(0 TO 8) 'a(0) to a(8) DIM b(1 TO 10) 'b(1) to b(10) * If you specify only one subscript, QBasic assumes that it is the upper bound and uses 0 for the lower bound unless you include an OPTION BASE statement. * For multidimensional arrays, simply seperate the subscripts of each array dimension with commas: DIM (box(3,3) DIM (bigbox(1 TO 10, 1 TO 10) * The maximum number of array dimensions is 60. * Valid types include INTEGER, LONG, SINGLE, DOUBLE, STRING, and user defined types. Example: DIM a(25 TO 100) AS INTEGER DIM b(1 TO 10, 1 TO 5) AS DOUBLE TYPE Schedule day AS STRING * 10 hours AS INTEGER END TYPE DIM workday AS Schedule Related functions: LBOUND, UBOUND Related statements: ERASE. OPTION BASE, REDIM DATE$ Statement DATE$ Statement --------------- Sets the system date. Usage: DATE$ = string_expression Notes: * string_expression is a string expression containing the desired date in the form "mm-dd-yyyy", where yyyy is the year 1980 through 2099. * If you specify only the last two digits of the year, DATE$ assumes that the first two digits are 19. Example: DATE$ = "12-25-89" DATA Statement DATA Statement -------------- Stores numeric and string constants to be read by the READ statement. Usage: DATA constant[,constant]... Notes: * READ statements access DATA statements in the order the data segments appear in the program. The RESTORE statement allows your program to reread DATA statements as necessary. * The type of variable in a READ statement must match the type of the constant in the DATA statement. * You can only use one data statement at the module level, never in a procedure. Example: DATA 1, .2345, "TEST", 98765 READ a%, b#, c$, d$ PRINT a%, b#, c$, d$ Output: 1 2,2345 TEST 98765 Related statements: READ, RESTORE DECLARE Statement DECLARE Statement ----------------- Declares a procedure and directs QBasic to perform type checking for each paramenter. Usage: DECLARE {FUNCTION|SUB} procedure_name [(argument_list])] Notes: * DECLARE directs QBasic to ensure that the types of parameters passed to a procedure match the types that the procedure expects. * DECLARE is needed only when you don't use the CALL statement. * The keyword FUNCTION indicates that the procedure is a function; likewise, SUB indicates a subprogram. * procedure_name is the name of the function or subprogram. * argument_list is an optional list of parameters seperated by commas. For compiler type checking, specify argument as follows: variavle_name [AS type] * Valid types include INTEGER, LONG, SINGLE, DOUBLE, STRING, ANY or a user-defined type. Example: See CALL Related statements: CALL, FUNCTION, SUB DOWHILE Statement DO WHILE Statement ------------------ Repeats a set of nstructions while a condition is true. Usage: DO WHILE Boolean_expression statements LOOP or DO statements LOOP WHILE Boolean_expression Notes: * Boolean_expression is an expression that evaluates to true or false. * The first form of the statement first tests the Boolean expression. If the expression is true, QBasic executes the statements within the loop until the expression becomes false. * The second form of the statement fist executes the statements within the loop and then tests the boolean expression. If the expression is true, QBasic repeats the statements; otherwise, execution continues at the first statement after the loop. Example: i = 0 DO WHILE i < 100 PRINT i i = i + 1 LOOP Related statements: DO UNTIL, EXIT, FOR, WHILE/WEND DOUNTIL Statement DO UNTIL Statement ------------------ Repeats a set of instrictions until a condition becomes true. Usage: DO UNTIL Boolean_expression statements LOOP or DO statements LOOP UNTIL Boolean_expression Notes: * Boolean_expression is an expression that evaluates to true or false. * The forst form of the syatement first tests the Boolean expression. If the expression is true, QBasic skips the statements within the loop and continues execution at the first statement that follows the loop. * The second form of the statement first performs the statements within the loop and then tests the Boolean expression. If the Boolean express- sion is false, QBasic repeats the statements in the loop; if the expression is true, QBasic continues execution at the forst statement that follows the loop. Example: i = 0 DO PRINT i i = i + 1 LOOP UNTIL 1 = 100 Related statements: DO WHILE, EXIT, FOR, WHILE/WEND DEFFN Statement DEF FN Statement ---------------- Defines a function. Usage: DEF FNname [(argument_list)] = expression or DEF FNname [argument_list)] . . . FNname = expression . . . END DEF Notes: * Function names must begin with FN and can contain up to 40 characters. The function name indicates the value type the function returns: Function name Returns FNday$ string FNcount% integer FNaverage# single precision value * For a function to return a value, the function must assign its result to the function name. * argument_list is a list of parameters to the function seperated by commas as follows: arument_name [AS type] * You cannot use a function before your program defines it, nor can you use DEF FN functions recursively. Example: DEFSEG Statement DEF SEG Statement ----------------- Sets the current segment address for susequent PEEK functions and BLOAD, BSAVE, CALL ABSOLUTE, and POKE statements. Usage: DEF SEG [= address] Notes: * address is an integer expression in the range 0 through 65,535. If you omit address, QBasic uses the Basic data segment. Example: See CALL ABSOLUTE statement Related functions: PEEK Related statements: BLOAD, BSAVE, CALL ABSOLUTE, POKE DRAW Statement DRAW Statement -------------- Draws an object specified in a string expression. Usage: DRAW string_expression Notes: * DRAW uses a string containing graphics commands to draw an object. The string can contain cursor, color, and scaling commands. * Cursor movement commands are as follows: Command Description Command Description U(n) Up n untis G(n) Down & left n units D(n) Down n units H(n) Up & left n units L(n) Left n units M[{-|+}]xy moves to x,y (If R(n) Right n units you precede x,y E(n) Up & right n with a minus or units plus sign, movement F(n) Down & right is relative to the n units current position of the cursor.) If you omit n, the cursor moves 1 unit. * DRAW allows you to precede the cursor movement functions with B and N: Command Description B Move but do not draw points N Move but return to original position once drawn * Angle, color, and scaling commands are as follows: Command Description A rotation Set rotation angle in the degrees: 0=0 degrees, 1 = 90 degrees, 2 = 180 degrees, 3 = 270 degrees TA degree Turn angle (-360 degrees through 360 degrees) C color Set color S n Set scale factor for units (The default is 4, 1 pixel) P color, Paint the interior of the object color; border the color of the border must be border. Example: 'Draw a box & fill it in SCREEN 1 DRAW "C3" DRAW "L20U20R20D20" ' draw box DRAW "BH10" ' move into box DRAW "P2,3" ' paint box Related funtions: POINT Related statements: CIRCLE, COLOR, LINE, PAINT, PSET, PRESET, SCREEN DEFDBL Statement DEFDBL Statement ---------------- Defines the default data type as double-precision for variables whose names begin with a letter in the specified range. Usage: DEFDBL letter[-last_letter][,letter[-last_letter]... Notes: * letter and last_letter are a range of letters to associate with a type. QBasic does not distinguish between uppercase and lowercase variables. * If a variable name has the suffix %, &, !, or $, the data type associated with the suffix takes precedence over the default type statement. Example: DEFDBL A-J Related statements: DEFINT, DEFLNG, DEFSNG, DEFSTR DEFINT Statement DEFINT Statement ---------------- Defines the default data type as an integer for a variable whose names begin with a letter. Usage: DEFINT letter[-last_letter][,letter[-last_letter]]... Notes: * See DEFDBL Example DEFINT X-Z Related statements: DEFDBL, DEFLNG, DEFSNG, DEFSTR DEFLNG Statement DEFLNG Statement ---------------- Defines the default data type as long for variables whose names begin with a letter in a specified range. Usage: DEFLNG letter[-last_letter][,letter[-last_letter]]... Notes: * See DEFDBL Example: DEFINT X-Z Related statements: DEFDBL, DEFLNG, DEFSNG, DEFSTR DEFSNG Statement DEFSNG Statement ---------------- Defines the default data type as single-precision for variables whose names begin with a letter in the specified range. Usage: DEFSNG letter[-last_letter][,letter[-last_letter]]... Notes: * See DEFDBL Example: DEFSNG T-W Related statements: DEFDBL, DEFINT, DEFLNG, DEFSTR DEFSTR Statement DEFSTR Statement ---------------- Defines the default data type as string for variables whose names begin with a letter in the specified range. Usage: DEFSTR letter[-last_letter][,letter[-last_letter]]... Notes: * See DEFDBL Example: DEFSNG T-W Related statements: DEFDBL, DEFINT, DEFLNG, DEFSNG ENVIRON Statement ENVIRON Statement ----------------- Cahnges an existing entry or places a new entry in the MS-DOS environment. Usage: ENVIRON string_expression Notes: * The ENVIRON statement expects a string expression of the same form as the MS-DOS SET command. * The chsnges to the environment table is valid only for the life of the program. * You cannot increase the size of the MS-DOS environment in QBasic. To make space in the DOS environment for use by QBasic programs, create a dummy entry with the DOS SET command Then erase the contents of the entry in a QBasic program to make room for new or changed variables. Example: ENVIRON "PROGRAM=TEST" PRINT ENVIRON$("PROGRAM") Output: TEST Related functions: ENVIRON$ * The environment variable entry will last only as the QBasic program is running, not when you exit from the program to DOS. END Statement END Statement ------------- Ends a Qasic program. Usage: END * END by itself ends program and closes all files. * The END statement is also used with DEF FN, fUNCTION, IF, SELECT CASE, SUB, TYPE. Tose forms of END are discussed in relation to the ppropriate statements. Example: FOR i = 1 TO 10 PRINT i NEXT i END Related statements: DEF FN, FUNCTION, IF, SELECT CASE, SUB, TYPE ERASE Statement ERASE Statement --------------- Reinitializes the elements of a static array or deallocates dynamic arrays. Usage: ERASE array[,array]... Notes: * array is the number of the array to reinitialize or deallocate. * For static numeric arrays, ERASE sets each element to zero. For static string arrays, ERASE sets each element to null. * For dynamic arrays, ERASE frees the memory used by the specified arrays. Example: DIM a(100) FOR i = 1 TO 100 a(i) = i NEXT i ERASE a ' Reinitialize A FOR i = 1 TO 100 PRINT a(i) NEXT i Related functions: FRE Related statements: CLEAR, DIM, REDIM EXIT Statement EXIT Statements --------------- Exit a DO or FOR loop, function, or subprogram. Usage: EXIT DEF or EXIT DO or EXIT FOR or EXIT FUNCTION or EXIT SUB Notes: * FOR DO and FOR loops, execution continues at the first statement following the loop. * For functions and subprograms, execution continues at the statement following the statement that called the function or sub- routine. Example: J = 30 FOR i = 1 TO 50 IF i = j THEN EXIT FOR END IF NEXT i PRINT "Ending value is"; i Output: Ending value is 30 Related statements: DEF FN, DO UNTIL, DO WHILE, FOR, FUNCTION, SUB ERROR Statement ERROR Statement --------------- Simulates an occurance of the error number specified. Allows a program to define its error codes. Usage: ERROR numeric_expression Notes: * numeric expression is an integer value in the range 1 to 255. * See the ERR function for a list of pre- defined error status codes. To define your own error code, use an undefined error value. * The ERROR statement assigns the error value specified to ERR and passes control to the error handler. Example: ON ERROR GOTO HANDLER 'Test error handler with error 222 ERROR 222 EndTest: END Handler: PRINT "In error handler with error; ERR RESUME EndTest Related functions: ERDEV, ERDEV$, ERL, ERR Related statements: ON ERROR GOTO, RESUME FOR Statement FOR Statement ------------- Repeats a given set of instructions a specific number of times. Usage: FOR control_variable=start_value TO end_value [STEP increment] . . NEXT [control_variable[,control_variable]...] Notes: * control_variable is the variable that FOR increments with each iteration of the loop. It controls whether or not QBasic continues the loop. * start_value is the initial value that QBasic assigns to the control variable. * increment is the amount that QBasic adds to the control variable with each iteration of the loop. The increment can be a positive or negative value. * The NEXT statement directs QBasic to increment te control variable and test whether it is greater than the end value. If you omit increment, the default increment is 1. Example: FOR i = 1 TO 10 PRINT "i="; i NEXT i FOR i = 1 TO 10 FOR j = 1 TO 10 PRINT i; "*"; j; "="; i * j NEXT j NEXT i Related statements: DO UNTIL, DO WHILE, EXIT, WHILE/WEND FILES Statement FILES Statement --------------- Displays the names of files in the current or specified directory. Usage: FILES[string_expression] Notes: * string_expression is a string expression that contains an MS_DOS file specification of the files to isplay. * If you omit a file specification, FILES displays the files in the current directory. Example: FILES FILES ".BAS" FILES "A:" Related statements: CHDIR, KILL, NAME FUNCTION Statement FUNCTION Statement ------------------ Declares a user-defined function. Usage: FUNCTION function_name[(arguments)][STATIC] Notes: * function_name is the name of the user- defined function. The name can end with a type-declaration character (%, &, !, #, or $) to indicate the type of value it returns. * arguments is an optional list of parame- ters, seperated by commas, to be passed to the function. * The STATIC keyword directs QBasic to save the values of the function's local variables between function calls. * For a function to return a value, the fuction must at some point assign an expression to the function name. Example: FUNCTION Min% (a AS INTEGER, b AS INTEGER) IF (a < b) THEN Min% = a ELSE Min% = b END IF END FUNCTION PRINT "Min of 5 and 3 is; Min%(5, 3) Related statements: DECLARE, DEF FN, SUB, STATIC FIELD Statement FIELD Statement --------------- Allocates space for variables in a random-access file buffer. Usage: FIELD [#]file_number, width AS str_variable... Notes: * width is the number of characters in the field. * str_variable is the name of a string variable to be used when reading from or writing to the file. * A variable name that appears in a FIELD statement should not appear in an INPUT statement on the left side of an assignment operator. If it does, the variable will no longer reference the random- access file buffer. * Using record variables is usually more convenient than using the FIELD statement. Example: OPEN "RANDOM.DAT" FOR RANDOM AS #1 LEN=80 FIELD #1, 76 AS name$, 4 AS salary$ Related statements: GET, LSET, OPEN, PUT, RSET GOTO Statement GOTO Statement -------------- Branches to the specified line number or label. syntax: GOTO location Notes: * location is the line number or label at which execution is to continue. * Early vrsions of Basic did not have DO loops, ELSE clauses or IF statements, or SELECT CASE statements. So GOTO was used to implement these constructs. To improve your your program's reliability and simplify debugging, restrict the use of GOTO. Example: i = 0 Start: PRINT "i ="; i INPUT "Again"; reply$ IF reply$="N" THEN END ELSE i = i + 1 END IF GOTO Start Related statements: DO UNTIL, DO WHILE, SELECT CASE GET Statement GET Statement ------------- Reads a record from a random-access file or binary disk file. Usage: GET [#]file_number[,[record_number][,variable]] GET-G Statement GET Statement (Graphics) ------------- Stores a graphics screen image in an array. Usage: GET [STEP](xleft,ytop)-[STEP](xright, ybottom), array[(index)] Notes: * The keyword STEP indicates that the coordinates are offsets relative to the last point plotted. * array is the name of the array in which GET should store the image. * index is the array index at which storage of the graphics image begins. * GET stores the screen image in the specified rectangle. * To calculate the number of bytes required, use the formula: 4 + INT(((xright - xleft + 1) * (bits_perpiixel/planes) + 7)/8) * planes * (ybottom - ytop + 1) * The number of bits per pixel and the number of planes depends on the current screen. Example: GET (10,20)-20,50), dog Related statements: PUT (Graphics), SCREEN GOSUB Statement GOSUB Statement --------------- Directs execution to continue at a Basic subroutine. Usage: GOSUB location Notes: * location is either a line number or label at which execution should continue. * Use a RETURN statement to end a subroutine. * GOSUB is the older method of executing subroutines. QBasic typically uses SUB and ALL instead. * The label is an identifier with a colon at the end, e.g., Handler: Related statements: IN event GOSUB, ON expression RETURN, SUB INPUT# Statement INPUT # Statement ----------------- Usage: INPUT #file_number, variables Notes: * file_number is the number assigned to the file in its OPEN statement * variables is the list of variables in which to store data from the file Example: OPEN "SALARY.DAT" FOR INPUT AS #1 DO WHILE NOT EOF(1) INPUT #1, ename$, salary PRINT ename$, salary LOOP CLOSE #1 Related functions: INPUT$ Related statements: INPUT #; LINE INPUT INPUT Statement INPUT Statement --------------- Gets keyboard input. Usage: INPUT[;]["prompt"{;|,}]variables Notes: * A semicolon immediately after INPUT directs QBasic to leave the cursor on the same line after the user presses Enter. * prompt is the optional prompt INPUT displays on the screen. * A semicolon after the prompt directs INPUT to display a question mark after the prompt. * A comma after the prompt directs INPUT to suppress the question mark. * variables is the list of variables to input. Seperate multiple variables with commas. * If you enter a type other than the expected variable type, or enter too many or too few values, INPUT displays the message 'Redo from start', and you must reenter the data. * The user must seperate multiple entries with commas. Example: 'Question mark. INPUT "Enter your name and age"; uname$, age PRINT uname$, age 'No question mark INPUT "Enter your name and age", uname$, age PRINT uname$, age Related functions: INPUT$ Related statements: INPUT #; LINE INPUT IF Statement IF Statement ------------ Provides conditional execution on the evaluation of an expression. Usage; IF expression THEN true_statement[ELSE false_statement] or IF expression THEN [true_statements] ELSEIF expression THEN [true_ststatements]] . . [ELSE [false_statements]] END IF Notes: * The first form of the statement allows you to execute a single statement if the expression is true and a different statement if the expression is false. * The second form of the statement allows you to execute a series of statements if the expression is true and a different set if the expression is false. Also, this syntax allows you to test for a series of different conditions, one after another. Example: F (a > b) THEn max = a SLSE max = b IF (a > max) THEN CALL BigValue(a) IF (day$ = "MONDAY") THEN CALL Meetings CALL Dinners ELSE CALL Gym END IF IF (DAY$ = "MONDAY" THEN CALL Meetings ELSEIF (DAY$ = "ThURSDAY") THEN CALL Tickets ELSEIF (DAY$ = "FRIDAY") THEN CALL Theatre END IF Related statements: ON expression, SELECT CASE IOCTL Statement IOCTL Statement --------------- Transmits a device control string to a device driver. Use: IOCTL [#]file_number, control_string Notes: * file_number is the file number assigned to the device in its OPEN statement. * control_string is a string expression that specifies the command sent to the device. * For inormation on device control string commands, refer to your hardware manual. Related functions: IOCTL$ KILL Statement KILL Statement -------------- Deletes a file from disk. Usage: KILL file_specification * file_specification is a string expression specifying the line to delete. The string can contain the MS-DOS wildcard characters ? and *. Example: KILL "TEST.DAT" KILL "*.TMP" Related statements: FILES KEY Statement KEY Statement ------------- Assign string values to the function keys F1 through F12. Optionally, display values of each key. Usage: KEY function_key, string_expression or KEY LIST or KEY ON or KEY OFF Notes: * function_key is the number of the desired function key. 1 cooresonds to F1; 10 cooresponds to F10. Use 30 and 31 to rep- resent keys F1 and F12. * string_expression is a string of up to 15 characters that you want to assign to the function key. * Once you assign a string to a key, QBasic substitutes the string each time the user presses the cooresponding function key. * KEY LIST displays the entire 15-character assignment for each key. * KEY ON displays accross the bottom of the screen the first six letters of the stings assigned to keys F1 through F10. * KEY OFF erases the display of the key assignments from the screen. Example: 'Assign a stin to F1 KEY 1, "F1 function key" 'Display the key assignment KEY ON INPUT "Press the F1 key"; x$ PRINT x$ KEYN Statement KEY(n) Statements ----------------- Enable or diable software trapping of specific keys. Use: KEY(n) ON or KEY(n) OFF or KEY(n) STOP Notes: * n is the number associated with a function key, a direction key, or a user-defined key: Value of n Meaning 1 to 10 Function keys F1 to F10 11 Up arrow key 12 Left arrow key 13 Right arrow key 14 Down arrow key 15 to 25 User-defined keys 30 and 31 F11 and F12 keys * KEY(n) ON enables keyboard event trapping for specified key, KEY(n) OFF disables keyboard event trapping for specified key. QBasic does not queue events that occur. * KEY(n) STOP inhibits event trapping for the specified key--events are processed once trapping is enabled. LINEINPU Statement LINE INPUT Statement -------------------- Reads a string of up to 255 characters Usage: LINE INPUT [;]["prompt";]string_variable or LINE INPUT [#]file_number, string_variable Notes: * Although the INPUT statement interprets a comma as a seperator between two entries, the LINE INPUT statement does not. The LINE INPUT statement reads all characters up to the carriage return and assigns them to a string variable. * If present, the semicolon immediately following the key- word INPUT directs LINE INPUT to leave the cursor on the same line after the user presses Enter. * prompt is an optional message that directs the user to enter data * string_variable is the string variable to which LINE INPUT assigns the information entered * file_number is the file number assigned to the file in its OPEN statement Example: LINE INPUT "Enter last name, first name, MI: "; fullname$ PRINT fullname$ Related functions: INPUT$ Related statements: INPUT, INPUT # LPRINTUS Statement LPRINT USING Statement ---------------------- Prints formatted output on the printer LPT1. Usage: LPRINT USING format_string; output_list[{|,}] Notes: * format_string is the output format. See PRINT USING for a list of ofrmatting characters. * output_list is a list of numeric and string expressions to be printed. Expressions must be seperaed by commas or semicolons. * A semicolon following the output list leaves the print head at the next character position. A comma leaves the print head at the next print zone. Print zones are 14 characters in length. Omitting a semicolon or comma causes the printer to advance to the beginning of the next line. Example: See PRINT USING Related statements: LPRING, PRINT USING, WIDTH LINE Statement LINE Statement -------------- Draws a lone or box on the screen. Usage: LINE [STEP](x1,y1)]-[STEP](x2,y2)[,[color][,[B[F]][,linestyle]]] Notes: * LINE draws either a line using the coordinate pairs (x1,y1) and (x2,y2) as endpoints or a box with (x1,y1) as one corner and [x2,y2) as the opposite corner. * The keyword STEP directs LINE to use the coord- inates as an offset from the last point plotted as opposed to physical coordinates. * color is the line or box color * B directs LINE to draw a box rather than a line * F directs LINE to fill the box with the specified color. * linestyle is a 16-bit value whose bits determine whether or not pixels are drawn. By changing this value, you change the style of ines on your screen. Example: 'Fill the screen with random boxes SCREEN 1 FOR i = 1 TO 1000 x1 = RND * 320 y1 = RND * 200 x2 = RND * 320 y2 = RND * 200 scolor = RND * 4 LINE(x1,y1)-(x2,y2),scolor, BF NEXT i Related functions: POINT Related statements: CIRCLE, COLOR, DRAW, PAINT, PSET, PRESET, SCREEN LET Statement LET Statement ------------- Assigns a value to a variable. Usage: [LET] variable = expression Notes: * LET is an optonal keyword used in assignment statements. Example: LET a = 5 'equivalent assignment without LET a = 5 LOCATE Statement LOCATE Statement ---------------- Moves the cursor to the specified position on the screen and, optionally, sets the cursor size. Sytax: LOCATE[row][,[column][,[visible][,[scan_start][,scan_stop]]]] Notes: * row is the number of the desired row * column is the number of the desired column * visible, when 1, causes the cursor to be displayed. When 0, it causes the cursor to be hidden. * scan_start is an integer specifying the first cursor scan line. * scan_stop is an integer specifying the last cursor scan line. * By changing the cursor scan lines, you can change the cursor size. Example: CLS FOR i = 5 TO 20 LOCATE, i, i PRINT Location is"; i; i NEXT i Related functions: CSRLIN, POS LPRINT Statement LPRINT Statement ---------------- Prints on the printer LPT1. Usage: LPRINT[output_list][{;|,}] Notes: * output_list is a list of numeric and string expressions to be printed. Expressions must be seperated by commas or semicolons. See PRINT USING to see a list of formatting characters. * A semicolon following the output list leaaves the print head at the next character position. A comma leaves the print head at the next print zone, where a print zone is 14 characters in length. Omitting a semicolon or comma causes the print head to advance to the next line's beginning. Example: LPRINT "This is on line 1" LPRINT "This is on"; LPRINT " line 2" Output: This is on line 1 This is on line 2 Related statements: LPRINT USING, WIDTH LOCK Statement LOCK Statement -------------- Prevents access to all or specific portions of a file by network programs. Usage: LOCK([#]file_number[,{record|[start] TO end}] Notes: * For random-access files, LOCK locks the specified record or range of records. For binary files, LOCK locks specified byte or range of bytes. For sequential files, LOCK locks the entire file. * To use LOCK, you should first run SHARE.EXE--an MS-DOS program that supports file sharing and locking. Example: INPUT "enter record number to update"; rec LOCK #1, rec ' restricted access emp.name$ = "SMITH" PUT #1, rec UNLOCK rec 'allow access LSET Statement LSET Statement -------------- Moves data into a random-access file buffer, assigns a variabble of one record type to a variable of a different record type, or left justifies the value of a string variable. Usage: LSET string_variable = string_expression or LSET record_variable1 = record_variable2 Notes: * string_variable is either a random access file field or a string variable. * string_expression is any string expression. * record_variable1 and record_variable2 are user-defined record variables. Example: salary = 77000 LSET e$ = MKS$(salary) PUT #1 Related statments: RSET MID$ Statement MID$ Statement -------------- Replaces a portion of a string with another string. Usage: MID$(string_variable, start_offset[,num_char]) = string_expression MKDIR Statement MKDIR Statement --------------- Creates a specified MS-DOS directory. Usage: MKDIR directory_name Example: ON ERROR GOTO CheckExists MKDIR "TSTDIR" PRINT "Directory TSTDIR created." Done: CheckExists: IF ERR = 75 THEN PRINT "Directory TSTDIR already exists." RESUME Done END IF ON ERROR GOTO 0 Related statements: CHDIR, RMDIR NAME Statement NAME Statement -------------- Renames a file or directory on disk. Usage: NAME oldfile_name, AS newfile_name ONERROR Statement ON ERROR GOTO Statement ----------------------- Enables error handling and specifies the first line of the error handler. Usage: ON ERROR GOTO location Notes: * See ERR for a list of possible errors. * location is the line number or label of the handler. A line number of 0 disables error handling. * IF error handling is diabled, an error results in an eror meassage and program termination. Example: ON ERROR GOTO Handler OPEN "NOFILE.DAT" FOR INPUT AS #1 PRINT "File opened." CLOSE #1 Done: END Handler: IF ERR = 53 THEN PRINT "File not found." END IF RESUME Done Related functions: ERDEV, ERDEV$, ERL, ERR Related statements: ERROR, RESUME ONEVENT Statement ON event GOSUB Statements ------------------------- Specify the first line of an event trapping subroutine Usage: ON COM(n) GOSUB location or ON KEY(n) GOSUB location or ON PEN GOSUB location or ON PLAY(aueuesize) GOSUB location or ON STRIG(n) GOSUB location or ON TIMER n) GOSUB location Notes: * The ON COM(n) GOSUB statement branches to the subroutine whenever characters are recieved at the specified serial port. * The ON KEY(n) GOSUB statement branches to the subroutine whenever the key assocoated with the specified number is pressed. * These statements do not enable event trapping but only associate a subroutine with an event. * The ON TIMER(n) GOSUB statement branches to the subroutine whenever specified number of seconds have elapsed. The number of seconds must be in the range 1 through 86,400. Example: ON KEY(10) GOSUB DisplayHelp KEY(10) ON PRINT "Press F10 for help" DO INPUT "Enter name"; n$ PRINT n$ LOOP UNTIL n$ = "QUIT"END DisplayHelp: PRINT "Type QUIT at name prompt." RETURN OPEN Statement OPEN Statement -------------- Opens a file or device for input or output. Use: OPEN filename [FOR access_mode] [ACCESS network_access] [lock_type] AS [#]file_number [LEN=record_length] or OPEN mode, [#]file_number, filename][, record_length] or OPEN "COMn: basic_com com_specifics" [FOR access_mode] AS [#]file_number [LEN=record_length] * filename is a string expression containing the name of the file or device to open. * access_mode specifies how the file is to be used: INPUT, OUTPUT, APPEND, RANDOM, or BINARY. The default is RANDOM * network_access gives more detail on how the file is to be used in shared-file network environments: READ, WRITE, or READ WRITE * lock_type is the type of file locking used in shared_file envoronments: SHARED, LOCK READ, LOCK WRITE, or LOCK READ WRITE * file_number is the integer number to associate with the file for read, write, and close operations * record_length is the number of bytes in each record. For sequential files, the default is 512; for RANDOM ACCESS files, the default is 128; for communications, default is 128. Value cannot exceed 32,767. * mode is used for older Basic programs. It is a single letter string that specifies the access mode. Option Mode A Append B Binary I Input O Output R Random * n is the number of the communications port to open, either 2 or 1. * basic_com represents the basic data-communications parameters, seperated by commas, in the following form: [baud],[[parity[,[databits][,stopbits]]]] * baud is baud rate of the device used: 75, 110, 150, 300, 600, 1200, 1800, 2400, 4800, 9600, or 19200 * databits is the number of bits in each data word: 5, 6, 7, or 8. The sum of parity bits and data bits must be less than or equal to 8. If the parity is set to O (odd) or E (even), one bit is used for parity. If parity is set to N (none), no bits are used for parity. * stopbits is the number of bits for each word: 1, 1.5, or 2. * com_specifics is a list of data-communications specifics, seperated by commas: ASC Opens device in ASCII mode BIN Opens device in binary mode CD(milliseconds) Specifies carrier-detect timeout CS(milliseconds) Specifies clear-to-send timeout DS(milliseconds) Specifies data-set-ready timeout LF Sends linefeed after each carriage return OP(milliseconds Specifies OPEN statement timeout period RB(bytes) Specifies the size of the recieve buffer RS Suppresses detection of request to send (RTS) TB(bytes) Specifies the size of the transmit buffer Example: OPEN "TEST.DAT" FOR INPUT AS #1 f% = FREEFILE OPEN "NEW.DAT" FOR RANDOM AS f% LEN = 80 OPEN "COM1:4800, E, 7, 1, BIN" AS #2 Related functions: FREEFILE Related statemnents: CLOSE OUT Statement OUT Statement ------------- Sends a byte to a specific port. OUT port_number, byte_value * port_number is an integer expression in the range 0 through 65,535 that identifies the port. * byte_value is an integer expression in the range 0 through 255 to send to the port. Example: See INP Related functions: INP OPTIONBA Statement OPTION BASE Statement --------------------- Sets the default lower array bound. Syntax: OPTION BASE {0|1} Notes: * If you don't specify a default lower bound, QBasic uses 0. * You can specify only one OPTION BASE statement per module. * For more flexibility, use the TO clause in the DIM statement. ONEXPRES Statement ON expression Statements ------------------------ Branch to one of several locations based on the result of an expression. Syntax: ON numeric_expression GOSUB location[,location]... or ON numeric_expression GOTO location[,location[,location]... Notes: * numeric_expression is any mumeric expression in the range 0 through 255. If necessary, QBasic rounds the expression to an integer value. * location is the list of line numbers or labels to which control should branch. If the result of the numeric expression is 1, control branches to the first location. If the expression is 2, control branches to the second location, and so on. If the alue does not have a coorsponding label, the program continues at the next statement. Example: FOR i = 1 TO 3 ON i GOSUB One, Two, Three NEXT i END One: PRINT "In One" RETURN Two: PRINT "In two" RETURN Three: PRINT "In Three" RETURN Related statements: DO UNTIL, DO WHILE, GOSUB, GOTO PSET Statement PSET Statement -------------- Draws a pixel at the specified location on screen. Usage: PSET [STEP](x,y)[,color] Notes: * The keyword STEP indicates that xa and y are offsets from the last point drawn, not absolute coordinates. * color is the desired pixel color. If you omit color, PSET usees the current foreground color. * If the coordinates are outside the current viewport, no point is drawn. Example: CLS SCREEN 1 DO PSET (160,100), 0 quad% = INT(RND(1) * 4) randX% = INT (RND(1) * 10) ' rand num for col movement randY% = INT [RND(1) * 10) ' rand num for row movement IF quad% = 0 OR quad% = 3 THEN 'normal movement is to right; randX% = -randX% ' reverse x value to move left END IF FOR i% = 1 TO 20 PSET STEP(-randX% * i%, randY% * i%) ' draw dot FOR j% = 1 TO DELAY% 'delay loop NEXT j% PRESET STEP(0, 0) 'erase dot NEXT i% LOOP UNTIL INKEY$ <> "" PRINT Statement PRINT Statement --------------- Writes to screen or sequential file. Use: PRINT [#file_number,][output_list][{;|,}] Notes: * file_number is the number of the file to which output is written. If you omit it, QBasic writes the data to the screen. * output_list is a list of one or more expressions to output. The expressions can be string or numeric. * If a semicolon ends the PRINT statement, the next PRINT statement continues on the same line in the next character position. if instead a comma ends the line, the next PRINT statement continues on the same line in the next print zone. Print zones are 14 characters in length. If neither a semicolon or comma is used to end the line, the next PRINT statement begins on the next line. * If no expression follows the PRINT command, a blank line is printed to screen or to the designated sequential file. Example: PRINT "Hello, World!" Related statements: LPRINT, LPRINT USING, PRINT USING PRINTUSE Statement PRINT USING Statement --------------------- Writes formatted output to screen or a file. Usage: PRINT [#]file_number,] USING format_list; output_list[{;|,}] POKE Statement POKE Statement -------------- Places a byte in the specified memory location. Use: POKE offset, byte_value * offset is the offset--range 0 to 65,535-- within the current segment where you want to place the byte. * byte_value is the value (range 0 to 255) to poke into memory. * The DEF SEG statement determines the current segment. 'Fill CGA screen with ASCII 251 (û symbol) DEF SEG = &HB800 FOR i = 0 TO 3999 IF i MOD 2 = 0 THEN POKE i, 251 ' check mark or radical symbol ELSE POKE i, 7 ' display attribute END IF NEXT i DEF SEG Related statements: PEEK Related functions: DEF SEG PRESET Statement PRESET Statement ---------------- Draws a pixel at the specified screen coordinates. Use: PRESET [STEP](x,y)[,color] * The keyword STEP indicates that x and y are offsets from the last point drawn, as opposed to actual coordinates. * PRESET is similar to PSET, except that if you omit color, PRESET uses the background color. * If the coordinates are outside the current viewport, nothing is drawn. Related functions: POINT Related statements: CIRCLE, COLOR, DRAW, LINE, PAINT, PSET PCOPY Statement PCOPY Statement --------------- Copies one video display page to another. Syntax: PCOPY source_page, target_page Notes: * source_page is an integer expression that specifies the video display page to be copied. * target_page is an integer expression that specifies the video display page to which the source page is to be copied.. * The number of video display pages available is dependent on the video memory size and video display mode. Example: 'Copy video page 1 to page 3 PCOPY 1, 3 PAINT Statement PAINT Statement --------------- Fills a graphics screen image with the specified color or pattern. Syntax: PAINT[STEP](x,y)[,[{color|tile)][,bordercolor][,background]]] PUTFILE Statement PUT Statement (File I/O) ------------- Writes a random-access file buffer or record variable to a file. Syntax: PUT [#]file_number[,record_number][,variable]] Notes: * file_number is the file number assigned to the file in its OPEN statement. * record_number is the record number (from 1 through 2,147,483,647) in a random-access file or the byte offset in a binary file. * variable is a variable containing the fields of the record. Example: TYPE Employee ename AS STRING * 20 salary AS SINGLE END TYPE DIM emp AS Employee OPEN "SALARY.DAT" FOR RANDOM AS #1 LEN=LEN(emp) emp.ename = "Parrish" em.salary = 50000 PUT #1, 1, emp CLOSE #1 Related functions: CVD, CDVMBF, CVI, CVL, CVS CVSMBF, MKD$, MKDMBF$, MKI$, MKL$, MKS$ Related statements: GET, LSET, OPEN, RSET PEN Statement PEN Statements -------------- Enable or disable light pen event trapping. Syntax: PEN ON or PEN OFF or PEN STOP Notes: * The PEN ON statement enables light pen event trapping. * The PEN OFF statement disables light pen event trapping. * The PEN STOP statement temporarily suspends light pen trapping. All light pen events occuring during this period are processed after event trapping is enabled. Example: ON PEN GOSUB Handler PEN ON Related functions: PEN Related statements: ON event GOSUB PUTGRAPH Statement PUT Statement (Graphics) ------------------------ Displays a graphics image on the screen. Syntax: PUT [STEP](x,y),array[(index)][,display_verb] Notes: * The keyword STEP indicates that x and y are offsets from the last point drawn, as opposed to physical coordinates. * array is the name of the array containing the image to display. * index is the index where the graphics image begins in the array. * display_verb indicates how the image is displayed: PSET Colors remain uncahnged PRESET Colors are inverted AND A logical AND with an existing image in the same location. OR A logical OR with an existing image in the same location. XOR An exclusive OR of an existing image on the screen (useful for animation) Example: SCREEN 1 DIM box(1 TO 200) x1 = 0 x2 = 10 y1 = 0 y2 = 10 LINE (x1,y1)-(x2,y2),2,BF ' create a box GET (x1,y1)-(x2,y2), box ' save image FOR i = 1 TO 10000 PUT (x1,y1),box,XOR ' Move box around x1 = RND * 300 ' screen randomly y1 = RND * 180 PUT (x1,y1),box NEXT i Related statements: GET(Graphics), SCREEN PLAY Statement PLAY Statement -------------- Plays the tune specified by a string expression. Syntax: PLAY string_expression * string_expression is a string expression that contains one or more of the following commands: Octave commands: > Increases octave by 1 to a maximum of 6 < Decreases octave by 1 to a minumum of 0 O level Sets the current octave; level must be 0 through 6. Default is 4. Duration commands: L notetype Sets the length of each note from 1 to 64; 1 is the whole, 2 is half, and so on. Default is 4. ML Sets music legatto MN Seys music normal MS Sets music staccato. Mode Commands: MF Sets music to foreground. This is the default. MB Sets music to background. Up to 32 notes can play as the program executes. Temp Commands: P duration Specifies a pause from 1 to 64; 1 is whole, 2 is half, and so on. T notes Sets the tempo from 32 to 255. Default is 120. Tone Commands: A-G Playes the note specified. N note Plays a note from 0 to 84; 0 is a rest. Suffix commands: # or + Turns a note into sharp. - Turns a note into a flat . Plays the note 3/2 as long as specified. * The string expression "X+VARPTR$(_string) executes the music substring _string. Example: ' Play scale in 7 different octaves scale$ = "CDEFGAB" PLAY "L16" FOR i = 0 TO 6 PLAY "0" + STR$(i) PLAY "X" + VARPTR$(scale$) NEXT i Related functions: PLAY Related statements: ON event GOSUB, PLAY(Event Trapping), SOUND PALETTE Statement PALETTE Statement ----------------- Change one or more colors in the color palette. Syntax: PALETTE[change_color, new_color] or PALETTE USING array[(index)] Notes: * change_color is the attribute to change. * new_color is the new color to assign to the attribute. * array is an array of color numbers to assign to the attributes available in the current screen mode. * index is the index of the first element in the array to use in setting the palette. * If you omit all arguments, PALETTE will restore the default color values. Example: PALETTE 0, 1 Related statements: COLOR, SCREEN PLAYEVEN Statement PLAY Statements (Event Trapping) -------------------------------- Enable or disable paly event trapping. Syntax: PLAY ON or PLAY OFF or PLAY STOP Notes: * PLAY ON enables play event trapping * PLAY OFF disables play event trapping. All events that occur are ignored. * PLAY STOP temporarily suspends play event trapping. All play events are processed after play event trapping is enabled. Example: ON PLAY GOSUB Handler PLAY ON Related functions: PLAY Related statements: ON event GOSUB, PLAY READ Statement READ Statement -------------- Reads values from a data list and assigns them to variables. Usage: READ variable_list Notes: * variable_list is a list of variables seperated by commas. READ and DATA statements work hand in hand to assign values to these variables. Example: READ n$, age, salary READ address$ DATA "Kellie", 21, 500 DATA "Las Vegas", Nevada" PRINT n$, age, salary PRINT address$ Related statements: DATA, RESTORE REM Statement REM statement ------------- Allows explanatory comments or remmarks on a program line. Syntax REM comment Notes: * comment is any text * QBasic ignores comment lines unless they contain compiler directives. * QBasic supports the use of a single quotation mark (') instead of a REM statement. * The REM statement must exist on a seperate line and cannot be appended at the end of another QBasic statement, unless the colon is used as a command seperator. Example: REM This is a comment 'This is a comment, too. END ' This is also a comment. RMDIR Statement RMDIR Statement --------------- Removes the specified subdirectory. Usage: RMDIR directory_name Notes: * directory_name is a string expression containing the name of the directory to delete. * RMDIR works like the MS-DOS RMDIR command. It cannot delete the current directory or a directory containing files. Example: RMDIR "A:\TEST" Related statements: CHDIR, MKDIR RUN Statement RUN Statement ------------- Runs the program currently in memory or an existing program from disk. Use: RUN[line_number] or RUN[file_name] Notes: * line_number is a line number in the current program at which execution should begin. * file_name is a string expression containing the name of a file to executes. QBasic assumes a BAS extension. * RUN closes all files and erases all variables. To share variables, use the CHAIN statement. Example: RUN "FILENAME" Related statements: CHAIN RESET Statement RESET Statement --------------- Writes on disk any data still in the file buffers and closes all disk files. Use: RESET * Reset closes all open fils at once. Use the CLOSE statement to close files individually. Example: RESET Related statements: CLOSE, OPEN RETURN Statement RETURN Statement ---------------- Returns control from a subroutine to the calling procedure. Use: RETURN [location] * location is the line number or label at which execution should resume. If you omit location, execution resumes at the line following the GOSUB statement or, for event handling, at the line at which an event occured. Example: GOSUB One GOSUB Two END One: PRINT "In One" RETURN Two: PRINT "In Two" RETURN Related statements: GOSUB, ON event GOSUB RSET Statement RSET Statement -------------- Moves data into a random-access file buffer or right justifies the value of a string variable. RSET string_variable = string_expression * string_variable is either a random-access file variable or a string variable. * For random-access file variables, RSET assigns a record variable of one type to another. * For string variables, RSET right-justifies the string. Example: DIM n AS STRING * 10 PRINT "ABCDE" RSET n = "ABCDE" PRINT n Output: ABCDE ABCDE Related statements: FIELD, LSET RESUME Statement RESUME Statement ---------------- Continues program execution from an error-trapping handler. Usage: RESUME[location] or RESUME NEXT Notes: * location is the line number or label at which execution should resume. If you specify 0 or omit location, execution continues at the statement causing the error. * The keyword NEXT continues execution at the statement immediately following the statement causing the error. Example: ON ERROR GOTO Handler OPEN "A:TEST.DAT" FOR INPUT AS #1 ' code END Handler: PRINT "Place disk containing TEST.DAT" PRINT "in drive A: Press Enter." INPUT dummy$ RESUME Related statements: ERROR, ON ERROR GOTO REDIM Statement REDIM Statement --------------- Cahnges the size of a dynamic array. Use: REDIM [Shared] arra(subscripts) AS tpename] [,array(subscripts)[AS typename]]... Notes: * You can change the size of an array but not the number of dimensions or the data type. * The keyword SHARED indicates that the array can be used by all proceedures in the module. * array is the name of an array to resize * subscripts specifies the array subscripts in the form [lowerbound TO] upperbound * typename is the array type: INTEGER, LONG, SINGLE, STRING, or user-defined type. * REDIM erase the array's previous values Example: '$DYNAMIC DIM box (1 TO 100) 'statements REDIM box (1 TO 200) Related statements: DIM, ERASE RESTORE Statement RESTORE Statement ----------------- Allow READ to reuse a prevoiusly read DATA statement. Use: RESTORE [location] * location is the line number or label of the DATA statement to read next. If you omit location, the next READ uses the first DATA statement in the program. Example: FOR i = 1 TO 5 READ a%, b%, c% PRINT a%, b%, c% RESTORE NEXT i DATA 1, 2, 3 Related statements: DATA, READ RANDOMIZ Statement RANDOMIZE Statement ------------------- Initializes the random number generator Use: RANDOMIZE[seed] * seed is an integer expression that initializes the random number generator. If you omit seed, your program will prompt the user to enter it. Example: ' print 50 random numers using ten ' different seeds FOR i = 1 TO 10 PRINT "Seed"; RANDIMIZE i FOR j = 1 TO 5 PRINT RND NEXT j NEXT i Related functions: RND, TIMER SELECTCA Statement SELECT CASE Statement --------------------- Evaluates an expression and executes the corresponding block of statements. Usage: SELECT CASE test_expression CASE match_expression [statements] CASE match_expression [statements]] . . . [CASE ELSE [default statements]] END SELECT Notes: * The SELET CASE statement evaluates an expression and searches the list of possible ceses for a match. If a match is found, QBasic executes the statements for that case. * test_expression is a string or numeric expression to evaluate and compare to the possible cases. * match_expression is an expression to match test_expresion. It can have the form: expression[,expresion]... If any of the expressions listed match test_expression, statements executes. * match-expression can also take the form of expresion TO expression which provides a range of possible values to match. * Lastly, match expression can have the form IS relation_operator expression where relation_operator is <,>,<=,<=,=,or <> * statements is the list of statements that execute for a matching case. * default_statements is the list of statements that execute if no matching expression is found. These statements are associated with the CASE_ELSE clause. * After the statments within a matching case execute, the program continues execution at the first statement following the END SELECT statement. Example: FOR i = 1 TO 5 SELECT CASE i CASE 1 PRINT "One" CASE 2, 3 PRINT "Two or Three" CASE IS = 4 PRINT "Four" CASE ELSE PRINT "Five" END SELECT NEXT i Output: One Two or Three Two or Three Four Five Related statements: IF SYSTEM Statement SYSTEM Statement ---------------- Ends the program and returns control to the operating system. Suntax: SYSTEM Notes: * SYSTEM closes all open files and ends the program's execution. * If SYSTEM is not used to end a QBasic program, QBasic.EXE remains active and no other programs can be executed without user interaction. Example: SYSTEM SLEEP Statement SLEEP Statement --------------- Suspends program execution for the specified length of time. Usage: SLEEP [seconds] Notes: * seconds is the number of seconds the program will be suspended. * The program remains suspended until the user presses a key or the specified number of seconds expires. * If seconds is omitted or is less than one, the program suspends indefinately until the user presses a key or an event currently bing trapped occurs. Example: SLEEP 10 SOUND Statement SOUND Statement --------------- Generates a sound from the computer's speaker. Usage: SOUND frequency, duration Notes: * frequency is an integer expression (from 37 to 32,535) that specifies the sound's frequency in hertz. * duration is an unsigned integer expression from 0 through 65,535 that specifies the length of the sound in clock tics. A clock tick occurs 18.2 times per second. Example: FOR i = 37 TO 3000 PRINT i SOUND 1, 1 NEXT i Related functions: PLAY Related statements: BEEP, PLAY STOP Statement STOP Statement -------------- Ends the program at any point. Usage: STOP Example: Handler: PRINT "Failed to open file." STOP Related statements: SYSTEM STATIC Statement STATIC Statement ---------------- Makes the specified variable local to a subprogram or function and preserves the variable's value between calls. Use: STATIC[AS typename][,varible[AS typename]]... * variable is the name of the variable to make static. * typename is the variable type (INTEGER, LONG, SINGLE, DOUBLE, STRING, or user defined type. Example: CALL Test CALL Test END SUB Test STATIC a AS INTEGER PRINT a a = a + 1 END SUB Output: 0 1 Related statements: COMMON, SHARED SHELL Statement SHELL Statement --------------- Exits program temporarily to execute an MS-DOS command or batch file. Use: SHELL [MS-DOS_comand] * MS-DOS command is a string expression that specifies the command to run. When the MS-DOS command is done, the program proceeds. * QBASIC creates its own copy of the environment, so environment variables created before the program runs may not be accesible to the SHELL command. * If you omit the MS-DOS_command, SHELL displays the MS-DOS prompt, To return to the program, use the MS-DOS EXIT command. Example: SHELL "DIR /W" ' Display directory listing SHELL ' MS-DOS prompt SEEK Statement SEEK Statement -------------- Sets the file pointer position for the next read or write operation. Use: SEEK [#]file_number, position * file_number is the file number assigned to the file in its OPEN statement. * position is the desired record number in a random-access file or the byte offset in a binary or sequencial file. It must be n the range 1 to 2,147,483,647. Example: OPEN "SALARY.DAT" FOR RANDOM AS #1 LEN = 80 SEEK #1, 5 ' move pointer to record 5 Related functions: LOC, SEEK Related functions: GET(File I/O), OPEN, PUT SHARED Statement SHARED Statement ---------------- Gives a subprogram or function access to module-level variables. Use: SHARED variable[AS typename][,variable[AS typename]]... * By default, a subprogram or function has access to a variable only if you pass the variable as a parameter. * variable is the name of the module-level variable to share. * typename is the variable type, e.g., INTEGER Example: DIM AS INTEGER a = 5 CALL TEST END SUB Test SHARED a AS INTEGER PRINT "Value of variable a is"; a END SUB Related statements: DIM SCREEN Statement SCREEN Statement ---------------- Defines the screen characteristics. Use: SCREEN [screen_mode][,coloroff][,[active_page][,visual_page]]] * screen mode is an integer expression that specifies the mode of operation: Value Mode Adapter 0 Text CGA,EGA,VGA 1 320 x 200 graphics CGA,EGA,VGA,MCGA 2 640 x 200 graphics EGA,VGA 3 720 x 348 graphics Hercules* 4 640 x 400 graphics Olivetti, AT&T 6300 7 320 x 200 graphics EGA,VGA 8 640 x 200 graphics EGA,VGA 9 640 x 350 graphics EGA,VGA 10 640 x 350 graphics EGA,VGA 11 640 x 480 graphics VGA,MCGA 13 320 x 200 graphics VGA,MCGA (*The Hercules driver MSHERC.COM must be loaded for screen mode 3) * color_off is a numeric expression. When true, it disables color on composite monitors. It is ignored in screen modes 2 and up. * active_page is the video display page which text output and graphics commands write. * visual_page is the video display page that appears on your screen. * visual_page is the video display page that appears on your screen. Examople: SCREEN 1 '320 x 200 graphics LINE (10,10)-(20,20), , B Related functions: POINT Related statements: CIRCLE, COLOR, DRAW, GET(Graphics) LINE, PAINT, PALETTE USING, PRESET, PSET, PUT(Graphics) VIEW, WINDOW SWAP Statement SWAP Statement -------------- Syntax: SWAP variable1, variable2 Notes: * variable1 and variable2 must be the same type. Example: a = 1 b = 2 SWAP a, b PRINT a, b Output from running this program: 2 1 SUB Statement SUB Statement ------------- Declares a Basic subprogram. Syntax: SUB subprogram_name[(parameter_list)][STATIC] . . . END SUB Notes: * subprogram_name is the base name of the subprogram (up to 40 characters). * parameter_list is a list of parameters in the following form: variable[()][AS typename][,variable[()][AS typename]].... * The keyword STATIC directs QBasic to retain the value of the subprogram's local variables between calls. Example: CALL Test (1, 5.5, "TEST") END SUB Test (a AS INTEGER, b AS SINGLE, c AS STRING) PRINT a, b, c END SUB Related statements: CALL, DECLARE, END, EXIT, GOSUB STRIG Statement STRIG Statement --------------- Enable or disable joystick trapping. Syntax: STRIG(button) ON or STRIG(button) OFF or STRIG(button) STOP * button is a numeric expression that specifies which joystick button to trap: Value Traps 0 Lower button on joystick A 1 Lower button on joystick B 4 Upper button on joystick A 6 Upper button on joystick B * STRIG(button) ON enables joystick trapping for the specified button. * STRIG(button) OFF disables joystick trapping for the specified button. (All events are ignored) * STRIG(button) STOP temporarily disables joystick trapping for the specified button. Events are processed once trapping is enabled. Example: ON STRIG(0) GOSUB Handler STRIG(0) ON Related functions: STRIG Related statements: ON event GOSUB TYPE Statement TYPE Statement -------------- Creates a user-defined type Use: TYPE user_typename element_name AS tpename . . . END TYPE Notes: * user_typename is the name of the user-defined type * element_name is the name of an element in a record * typename is the element's type; INTEGER, LONG, SINGLE, DOUBLE, fixed-length string (e.g., STRING * 4), or another user defined type. * TYPE creates a template for futyre variable declarations. To create a variable of this type, you must use DIM, REDIM, COMMON, STATIC, or SHARED Example: TYPE Employee ename AS STRING * 20 salary AS SINGLE END TYPE DIM emp AS Employee emp.ename = "Stephanie" emp.salary = 30000 PRINT emp.name, emp, salary Output of running this program: Stephanie 30000 Related statements: COMMON, DIM, REDIM, SHARED, STATIC TRON Statement TRON Statement -------------- Enables tracing of statements. Use: TRON * See TROFF Example: TRON Related statements: TROFF TIME$ Statement TIME$ statement --------------- Sets the system time. Syntax: TIME$ = string_expression Notes: * string_expression is a string expression containing the desired time in the form "hh:mm:ss" where hh is the hour (0 through 23), mm is the minutes (0 through 59), and ss is the seconds (0 through 59). Example: TIME$ = "12" TIME$ = "12:30" Related functions: DATE$, TIME$ Related statements: DATE$ TIMER Statement TIMER Statement --------------- Enable or disable timer event trapping. Syntax: TIMER ON or TIMER OFF or TIMER STOP Notes: * TIMER ON enables timer event trapping. * TIMER OFF disables timer event trapping. Timer events that occur are ignored. * TIMER STOP temporarily suspends timer event trapping. Example: ON TIMER(10) GOSUB Handler TIMER ON DO LOOP UNTIL INKEY$ <> "" END Handler: PRINT TIME$ RETURN Related statements: ON event GOSUB TROFF Statement TROFF Statement --------------- Disables tracing of statements. Syntax: TROFF * TROFF and TRON are debugging tools used by older Basic systems. Example: TROFF Related statements: TRON UNLOCK Statement UNLOCK Statement ---------------- Unlocks portions of a shared file for access by other network programs. Use: UNLOCK[#]file_number[,{record | [start] TO end}] * record is an integer value that specifies a single record to release in a random-access file or a single byte to unlock in a binary file. * start and end are integer values that specify the range of record numbers or bytes to unlock. Example: OPEN "SHARED.DAT" FOR RANDOM AS #1 LOCK #1, 1 TO 10 'do file update operations UNLOCK #1, 1 TO 10 CLOSE #1 Related statements: LOCK VIEW Statement VIEW Statement -------------- Defines the screen coordinates within which graphics can be displayed. Use: VIEW [[SCREEN](x1,y1)-(x2,y2)[,fill_color][,border_present]]] * VIEW allows you to restrict graphics output to specific coordinates on the screen. Coordinates outside this range are not drawn. * The keyword SCREEN states that graphics coordinates are relative to the screen, not the viewport. * x1 and y1 are the coordinates of one corner of the viewport; x2 and y2 are the coordinates of the opposite corner. * fill_color specifies the color with which to fill the viewport. * bordr_present is any numeric expression that, when present, directs VIEE to draw a border around the viewport. * If you omit all arguments, VIEW sets the viewport to the entire screen. * The SCREEN and RUN statements set the viewport back to the entire screen. Example: SCREEN 1 VIEW (0,0)-(20-20),1,2 LINE (10,10)-(100,100) Related staatements: CLS, SCREEn, WINDOW VIEWPRIN Statement VIEW PRINT statement -------------------- Defines the text mode scrolling region. Use: VIEW PRINT[top_row TO bottom_row] * top_row and bottom_row are integer values specifying the top and bottom rows of the text mode scrolling region. * If you omit all arguments, VIEW PRINT sets the scrolling region to the entire screen. Example: CLS VIEW PRINT 5 TO 10 FOR i = 1 TO 100 PRINT i, i, i, i NEXT i Related statements: CLS, LOCATE, PRINT WRITE Statement WRITE Statement --------------- Writes data to the screen or a sequencial file. Usage: WRITE[[#]file_number,]expression_list Notes: * file_number is the file number assigned to the file in its OPEN statement. If you omit file_number, QBasic writes the data to the screen. * expression_list is a list of one or more variables or expressions seperated by commas. * WRITE places a comma between each expression in the file: the PRINT statement does not. Example: OPEN "TEST.DAT" FOR OUTPUT AS #1 WRITE #1, "TEST",5, 3.21, "END" CLOSE #1 Running this program produces the following result in TEST.DAT: "TEST", 5,3.21."END" Related statements: PRINT WIDTH Statement WIDTH Statement --------------- Sets the number of columns on the screen or other device or sets the width of a file. Usage: WIDTH [columns][,lines] or WIDTH #file_number, columns or WIDTH device_name, columns or WIDTH LPRINT columns Notes: * columns is the number of columns. The value must be 40 or 80 for the screen. * lines is the number of rows of text that appear on the screen. The value can be 25, 30, 43, 50, or 60, dpending on your display adapter and current screen mode. * file_number is the file number assigned to the file in its OPEN statement. * device_name is a string expression that contains the name od the desired device. * The keyword LPRINT sets the number of columns for the printer. * After you specify a width for a device, output statements automatically wrap output to the next line when the width is exceeded. Example: 'EGA monitor WIDTH 80, 43 FOR i = 1 TO 100 PRINT i NEXT i Related statements: LPRINT, LPRINT USING, PRINT, PRINT USING, SCREEN WHILEWEN Statement WHILE/WEND Statement -------------------- Repeats a set o instructions as long as a specified condition is true. Usage: WHILE condition statements WEND Notes: * condition is a Boolean expression. As long as the expression is true, QBasic executes the statements within the loop. * statements is any list of statements. * WHILE/WEND is an older looping consruct. The use of DO is prefered. WINDOW Statement WINDOW Statement ---------------- Defines the logical coordinates for the current veiwport. Usage: WINDOW [[SCREEN] (x1,y1)-(x2,y2)] Notes: * The keyword SCREEN inverts the screen's coordinate system such that y values increase in value from top to bottom of the screen. * The coordinates x1,y1 and x2,y2 specify the logical coordinates of the viewport. Example: SCREEN 1 WINDOW (0,0)-(50,50) LINE (10,10)-(40,40),2,8 Related statements: CLS, SCREEN, VIEW WAIT Statement WAIT Statement -------------- Suspends program execution until the specified pattern is read from the input port. Usage: WAIT pprt_number, AND_expression[,XOR_expression] Notes: * port_number is an integer expression (from 0 to 255) that identifies the port. * AND_expression is an integer expression that WAIT combines with the port value using an AND operation. * XOR_expression is an integer expression that WAIT combines with the port value using an XOR operation. * Data from the specified port is first combined with XOR_expression if suppied. The result is then combined with AND_expression . If the result is zero, WAIT continues reading the port values; otherwise, QBasic execuutes the next statement. Example: WAIT 45, 64 ASC Function ASC Function ------------ Returns the numeric ASCII code value for the first character in a string expression. Usage: ASC(string_expression) Notes: * string_expression is any string expression. Example: stringvar$ = "ABC" PRINT ASC(stringvar$) PRINT ASC("abc") Running this program will produce the following display: 65 97 Related functions: CHR$ ATN Function ATN Function ------------ Returns the arctangent of the specified value. Usage: ATN(numeric_expression) Notes: * numeric_expression is the value for which you want to find the arctangent * You can express an angle in either degrees or radians. ATN returns an angle in radians. To convert radians to degrees, use the following expression: degrees = radians * (180/3.141593) Example: value = TAN(.7854) 'Tangent of pi/4 PRINT "Arctangent is:"; ATN(value) Output: Arctangent is .7854 Related functions: COS; SIN; TAN ABS Function ABS Function ------------ Returns the absolute value of a numeric expression. Usage; ABS(numeric_expression) Notes: * numeric_expression is any numeric expression. * ABS always returns a positive value, regardless of whether the result of the expression is positive or negative. * ABS returns a value of the same type as numeric_expression (integer, long integer, double-precision, and so on). Example: PRINT "Absolute value of -3 * 5 is"; ABS(-3 * 5) PRINT "Absolute value of 3 * 5 is"; ABS(3 * 5) Running this program produces the following display: Absolute value of -3 * 5 is 15 Absolute value of 3 * 5 is 15 CHR$ Function CHR$ Function ------------- Returns a one-character string containing the character that corresponds to the specified ASCII value. Usage: CHR$(ascii_value) Notes: * ascii_value is the ASCII code of the desired character * CHR$ is commonly used to sound the computer bell (CHR$(7)). * The standard ASCII values range from 0 to 127. IBM clones and IBM PCs support extended ASCII characters from 128 to 255. Example: 'Display the ASCII and extended ASCII character sets FOR i 0 TO 255 PRINT i; CHR$(i) NEXT i Related functions: ASC COMMAND$ Function COMMAND$ Function ----------------- Returns the command to be used to invoke the program. Usage: COMMAND$ Notes: * This is a QuickBasic command and won't work with QBasic. * COMMAND$ does not return the name of the program in the command line. Example: ' Check to make sure user actually entered something Line$ = COMMAND$ Length = LEN(line$) IF Length = 0 THEN PRINT "Invalid Syntax." BEEP END END IF 'Get the first replaceable parameter FOR I TO Length Char$ = MId(Line$,1,1) IF (Char$<>" " AND CHar$<>(9) AND Char$<>",") THEN IF First = 0 THEN Build$ = Build$ + Char$ ELSE First = 1 END IF NEXT I PRINT Build$ CINT Function CINT Function ------------- Rounds a numeric expression to an integer value. Usage: CINT(numeric_expression) Notes: * numeric_expression must result in a value in the range -32,768 through 32,767. If the expression is outside this range, a runtime error occurs. * CINT rounds; it does not truncate. Example: PRINT CINT(34.51) PRINT CINT(34.49) Output of this program: 35 34 Related functions: CDBL, CLNG, CSNG CDBL Function CDBL Function ------------- Converts a numeric expression to a double-precision value. Usage: CDBL(numeric_expression) Notes: * numeric_expression is any numeric expression. * Using CDBL is equivalent to assigning the expression to a double-precision variable. * Single-precision values have 7 significant digits. Double-precision values have 15 significant digits. Example: PRINT 5 /6 PRInT CDBL(5 / 6) Output of this program: .8333333 .8333333333333334 Related functions: CINT, CLNG, CSNG COS Function COS Function ------------ Returns the cosine of the specified angle. Usage: COS(angle) CSNG Function CSNG Function ------------- Converts a numeric expression to a single-precision value. Usage: CSNG(numeric_expression) CLNG Function CLNG Function ------------- Rounds a numeric expression to a long (4-byte) integer. Usage: CLNG (numeric_expression) Notes: * numeric_expression must evaluate to a value in the range -2,147,483,648 to 2,147,483,647. If the result is outside this range, a runtime error will occur. Example: CVD Function CVD Function ------------ Converts an eight-byte string (created by MKD$) to a double precision value. Usage: CVD(eight_byte_string) Example: OPEN "PAYROLL.DAT" FOR RANDOM AS #3 LEN = 35 FIELD #3,27 AS name$, 8 AS salary$ GET #3, 1 PRINT "EMPLOYEE: "; name$ PRINT "SALARY $: "; CVD(salary$) CLOSE #3 CSRLIN Function CSRLIN Function --------------- Returns the current cursor row number. Usage: CSRLIN CVDMBF Function CDVMBF Function --------------- Converts an eight-byte string containing a double-precision calue (created by MKDMBF$) from Microsoft binary format to IEEE format. Usage: CVDMBF(eight_byte_string) CVI Function CVI Function ------------ Converts 2-byte string (created by MKI$) to an integer value. Usage: CVI(two_byte_string) Example: See CVD CVL Function CVL Function ------------ Converts a 4-byte string (created by MKL$) to a long integer. Usage: CVL(four-byte-string) Example: See CVD CVS Function CVS Function ------------ Converts a 4-byte string (created by MKS$) to a single-precisio, value. Usage: CVL(four_byte_string) DATE$ Function DATE$ Function -------------- Returns a ten-character string containing the current system date in the form mm-dd-yyyy. Usage: DATE$ Example PRINT DATE$ Running this program on January 14, 2004, produces the following output: 01-14-2004 Related statements: DATE$, TIME$ EOF Function EOF Function ------------ Tests for the end-of-file condition Usage: EOF(file_number) Notes: * EOF returns true if the end of the file associated with the file number specified has been reached; otherwise, EOF returns false. * file_number is the number assigned to the file in its OPEN statement. Example: OPEN "\CONFIG.SYS" FO INPUT AS #1 DO UNTIL EOF(1) LINE INPUT #1, fdata$ PRINT fdata$ LOOP CLOSE #1 Related functions: LOC; LOF Related statements: CLOSE; OPEN ERR Function ERR Function ------------ Returns the error code for the last error that occured. Usage: ERR Notes: Error Description Error Description Code Code 1 Next without FOR 6 Overflow 2 Syntax error 7 Out of memory 3 RETURN without 8 Label not defined GOSUB 4 Out of DATA 9 Subscript out of range 5 Illegal function call 10 Duplicate definition 11 Division by zero 50 FIELD overflow 12 Illegal in direct 51 Internal error mode 13 Type mismatch 52 FIELD overflow 14 Out of string space 53 File not found 16 String formula too 54 Bad file mode complex 17 Cannot continue 55 File already open 18 Function not defined 56 Field statement active 19 No RESUME 57 Device I/O error 20 RESUME without error 58 File already exists 24 Device timeout 61 Disk full 25 Device fault 62 Input past end of file 26 FOR without NEXT 63 Bad record number 27 Out of paper 64 Bad file name 29 WHILE without WEND 67 Too many files 30 WEND without WHILE 68 Device unavailable 33 Duplicate label 70 Permission denied 35 Subprogram not 71 Disk not ready defined 37 Argument-count 72 Disk media error mismatch 38 Array not defined 74 Rename accross disks 39 CASE-ELSE expected 75 PATH/FILE access error 40 Variable required 76 Path not found Example: See ERL Related functions: ERDEV, ERDEV$, ERL Relatd statements: ERROR, ON ERROR GOTO, RESUME ERL Function ERL Function ------------ Returns the line number of the statement that caused the error or the closest line number before the error-causing statement. Usage: ERL Notes: * ERL returns only line numbers. It does not return line labels. If you are not using line numbers, ERL returns 0. Example: 1010 PRINT "Error processing at line"; ERL 1020 PRINT "Error number" ERR 1030 RESUME Running this program produces the following display: Error processing at line 100 Error number 11 Related functions: ERDEV, ERDEV$, ERR Related statements: ERROR, ON ERROR GOTO, RESUME EXP Function EXP Function ------------ Returns e raised to a psecified power where e is the base of natural logarithms. Usage: EXP(numeric_expression) ERDEV Function ERDEV Function -------------- Returns an integer error code from the last device that declared an error. Usage: ERDEV Notes: * The MS-DOS critical error handler sets the value for ERDEV. The lower byte contains the MS-DOS error code (0 to 12). The upper byte contains device attribute information. Example: ON ERROR GOTO Handler . . . Handler: PRINT "Error accessing device "; ERDEV$ PRINT "Error status code "; ERDEV Related functions: ERDEV$. ERL, ERR Related statements: ERROR, ON ERROR GOTO, RESUME ERDEV$ Function ERDEV$ Function --------------- Returns the line number of the statement causing the error or the closest line number before the error-causing statement. Notes: * The MS-DOS critical error handler sets the value for ERDEV$. Example: See ERDEV Related functions: ERDEV, ERL, ERR Related statements: ERROR, ON ERROR GOTO, RESUME FIX Function FIX Function ------------ Returns the integer portion of a floating-point expression. Usage: FIX(numeric_expression) Notes: * numeric_expression is any numeric expression. Example: PRINT FIX(-10.99) PRINT FIX(-10.1) Output: -10 -10 Related functions: INT FRE Function FRE Function ------------ Returns the amount of available stack space, string space, or memory. Usage: FRE(numeric_expression) or FRE(string_expression) Notes: * If the argument to FRE is -1, FRE returns the sizes in bytes of the largest array you can create. If the argument is -2, FRE returns the available stack space. For any other numeric argument, FRE returns the amount of available string space. * If the argument to FRE is a string expression, FRE compacts the free string space into a single block and then re- turns the available string space. Example: PRINT "String space"; FRE("") PRINT "Stack space "; FRE(-2) PRINT "Array space "; FRE(-1) Output: String space 48460 Stack space 784 Array space 184092 Related statements: CLEAR, ERASE FREEFILE Function FREEFILE Function ---------------- Returns the next available Basic file number. Usage: FREEFILE Notes: * FREEFILE obviates the need to hard code file numbers, and consequently, avoids the danger of using a file number already in use. Example: FileNum = FREEFILE OPEN "TEST.DAT" FOR INPUT AS FileNum CLOE FileNum Related statements: OPEN FILEATTR Function FILEATTR Function ----------------- Returns either the file mode or the MS-DOS file hanfle for an open file. Usage: FILEATTR(file_number, file_info) Notes: * file_number is the file number assigned to the file in its OPEN statement. * file_info dictates the information FILEATTR returns. IF 1, FILEATTR returns access mode: Value Mode ------------- 1 Input 2 Output 4 Random 8 Append 32 Binary * If file_info is 2, FILEATTR returns MS-DOS file handle. HEX$ Function HEX$ Function ------------- Returns a character string containing the hexadecimal representation of a value. Usage: HEX$(numeric_expression) Notes: * Hexadecimal notation is the base 16 numbering system. It uses the numbers 1 through 9 and letters A through F. To store the hexadeximal representation of a number, you must use a string variable. Example: 'Display octal, decimal, and hex values from 0 to 255 FOR i = 0 TO 255 PRINT OCT$(i), i, HEX$(i) NEXT i Related functions: OCT$ INSTR Function INSTR Function -------------- Returns the location of the first occurance of a string within another string. Usage: INSTR([startposition], searchstring, substring) Notes: * INSTR returns the character position of substring within searchstring * startposition is the character position within searchstring where the search should begin. If you omit startposition, INSTR begins at position 1. * If INSTR locates the substring, it returns an index to the starting character. Otherwise, INSTR returns 0. Example: PRINT "RING in SUBSTRING", INSTR("SUBSTRING", "RING") PRINT "X in STRING", INSTR("STRING", "X") Output: RING in SUBSTRING 6 X in STRING 0 Related functions: LEFT$; LEN; MID$;, RIGHT$ Related statements: MID$ INPUT$ Function INPUT$ Function --------------- Reads the specified number of characters from a file or the keyboard. Usage: INPUT$(num_charaters[,[#]file_number]) Notes: * num_characters is the number of characters for INPUT$ to read. It must be less than or equal to the record length of the file, which is 128 by default. * file_number is the number assigned to the file in its OPEN statement. If you omit a file number, INPUT$ reads from the keyboard. Example: 'Display a file in upper case OPEN "\CONFIG.SYS" OR INPUT AS #1 DO WHILE NOT EOF(1) char$ = INPUT$(1,1) PRINT UCASE$(char$); LOOP CLOSE #1 Related statements: INPUT; INPUT #, LINE INPUT INT Function INT Function ------------ Returns the next integer value smaller than or equal to the specified numeric expression. Usage: INT(numeric_expression) Notes: * numeric_expression is any numeric expression. Example: PRINT INT(99.8), INT(99.1), INT(-99.2) Output: 99 99 -100 Related functions: FIX INKEY$ Function INKEY$ Function --------------- Reads a character from the keyboard. Usage: INKEY$ Notes: * INKEY$ returns a null string if no character is present, a 1-byte string for standard keys, and a 2-byte string for extended keys. * For extended keys, the first character is a null character (ASCII 0) and the second is the keyboard scan code. * INKEY$ does not echo the character to the screen. Example: PRINT "Press a series of keys - F10 to stop" DO DO k$ = INKEY$ LOOP WHILE k$ = "" IF LEN(k$) = 1 THEN PRINT "Letter", k$ ELSE PRINT "Scan code", ASC(MID$(k$,2,1)) END IF LOOP UNTIL MID$(k$,2,1) = CHR$(68) 'F10 scan code INP Function INP Function ------------ Returns a byte read from an I/O port. Use: INP(port_number) Notes: * port_number is the number associated with the desired port. It must be in the range 0 through 65,535. Example: 'Turn on speaker through port 97 saveval = INP(97) OUT 97, saveval + 3 DO LOOP WHILE INKEY$ = "" OUT 97, saveval Related statements: OUT IOCTL$ Function IOCTL$ Function --------------- Returns a control string from a device driver. Use: IOCTL$([#]file_number) Notes: * file_number is the file number assigned to the device in its OPEN statement. * The information IOCTL$ returns is device dependent. See your hardware documentation for more information. Related statements: IOCTL LTRIM$ Function LTRIM$ Function --------------- Removes the leading blank characters from a string expression. Usage: LTRIM$(string_expression) Notes: * string_expression is any string expression. Example: PRINT LTRIM$(" Trim test") Output: Trim test Related functions: RTRIM$ LCASE$ Function LCASE$ Function --------------- Returns a character string with all letters in the specified string expression in lowercase characters. Usage: LCASE$(string_expression) Notes: * string_expression is any string expression. Example: INPUT "Enter a string"; S$ PRINT LCASE$(S$) Related functions: UCASE$ LEFT$ Function LEFT$ Function -------------- Eturns the specified number of characters beginning from the leftmost character of a string. Usage: LEFT$(string_expression,num_char) Notes: * string_expression is any string expression. * num_char is the number of characters to extrat from the string. It must be in the range 0 through 32,767. Example: s$ = "TEST STRING" FOR i = 1 TO LEN(s$) PRINT LEFT$(s$,i) NEXT i Related functions: INSTR, LEN, MID$, RIGHT$ Related statements: MID$ LEN Function LEN Function ------------ Returns the number of characters in a string or the number of bytes used to store a variable. Usage: LEN(string_expression) or LEN(variable Notes: * string_expression is any string expression. * variable is any variable of a type other than STRING. Example: DIM x AS INTEGER a$ = "13 CHARACTERS" PRINT a$, LEN(a$) PRINT "Integer"; LEN(x), "Long"; LEN(y) Output: 13 CHARACTERS 13 Integer 2 Long 4 Related functions: INSTR, LEFT$, MID$, RIGHT$ Related statements: MID$ LOF Function LOF Function ------------ Returns the number of bytes in a file. Usage: LOF(file_number) Notes: * file_number is the file number assigned to the file in its OPEN statement. * You cannot use LOF with devices. Example: OPEN "\CONFIG.SYS" FOR INPUT AS #1 PRINT "File size in bytes is"; LOF(1) CLOSE #1 LBOUND Function LBOUND Function --------------- Returns the lowest array subscript for the specified array dimension. Usage: LBOUND(array_name)[,dimension] Notes: * array_name is the name of the array of interest. * dimension is an integer value specifying the dimension of interest in a multi- dimensional array. Example: DIM a(50 TO 100) AS INTEGER DIM box(1 TO 3, 3 TO 6) AS INTEGER PRINT LBOUND(a) PRINT LBOUND(box, 1), LBOUND(box, 2) Output: 50 1 3 Related functions: UBOUND Related statements: DIM LOG Function LOG Function ------------ Returns the natural logarithm of a numeric expression. Usage: LOG(numeric_expression) Notes: * numeric_expression is any numeric expression greater than 0. * The natural logarithm is the logarithm to the base e. Example: PRINT LOG(1), LOG(EXP(1)) Output: 0 1 Related functions: EXP LOC Function LOC Function ------------ Returns the current offset or record number within a file. Usage: LOC(file_number) Notes: * file_number is the file number assigned in the file's OPEN statement. * For binary files, LOC returns the current byte offset in the file. For random access files, LOC returns the current record number. For a sequencial file, LOC returns the current offset, divided by 128. For a COM device, LOC returns the number of bytes in the input queune. Example: IF LOC(<) < 100 THEN CALL ReadIt(salary) Related functions: SEEK Related statements: SEEK LPOS Function LPOS Function ------------- Returns the current position of the printer head wirhin a print buffer. Usage: LPOS(printer_number) Notes: * printer number is the number of the printer of interest, where 1 is LPt1, 2 is LPT2,etc. * Not all printers uspport LPOS MID$ Function MID$ Function ------------- Returns a substring of a string expression that begins at the specified offset location. Usage: MID$(string_expression, start_offset[,length]) Notes: * sting_expression is any string expression * start_offset is the position of the first character of the subtring * length is the number of characters in the substring. If you omit length, MID$ returns all characters from the start_offset through the end of the string. Example: a$ = "ABCDEFGHI" PRINT MID$(A$, 1, 5) PRINT MID$(A$, 6) Output: ABCDE FGHI Related functions: INSTR; LEFT$; LEN; RIGHT$ Related statements: MID$ MKD$ Function MKD$ Function ------------- Converts a double-precision value to an 8-byte string for output to a random-access file by PUT. Useage: MKD$(numeric_expression) MKDMBF$ Function MKDMBF$ Function ---------------- Converts a double-precision value stored in IEEE format to an 8-byte string containing the value in Microsoft binary format for output to a random-access file by PUT. Syntax: MKDMBF$(numeric_expression) MKI$ Function MKI$ Function ------------- Converts an integer value to a 2-byte string for output to a random-access file by PUT. Syntax: MKI$(numeric_expression) MKL$ Function MKL$ Function ------------- Converts a long integer value to a 4-byte string for output to a random-access file by PUT. Syntax: MKL$(numeric_expression) * numeric_expression is a long integer numeric expression. MKS$ Function MKS$ Function ------------- Convers a single-precision value to a 4-byte string for output to a random_access file by PUT. Syntax: MKS$(numeric_expression) MKSMBF$ Function MKSMBF$ Function ---------------- Converts a single-precision value stored in IEEE format to a 4-byte string containing the value in Microsoft binary format for output to a random_access file by PUT. Syntax: MKSMBF$(numeric_expression) OCT$ Function OCT$ Function ------------- Returns a string ontaining the octal representation of an integer expression. Usage: OCT$(numeric_expression) Notes: * Octal is the base-8 numbring system. * numeric_expression is any numeric expression. Example: See HEX$ Related funtions: HEX$ POS Function POS Function ------------ Returns the cursor column position. Usage: POS(dummy_argument) Notes: * POS does not use the parameter dummy_argument. Example: FOR i = 1 TO 100 IF (POS(0) > 50) THEN PRINT i ELSE PRINT i; ' same line END IF NEXT i Related functions: CSRLN, LPOS Related statements: LOCATE PEEK Function PEEK Function ------------- Returns the byte stored at a specific memory offset. Use: PEEK(offset) * offset is an integer expression--range 0 through 65,535) that specifies an offset within the current default segment as defined by the DEF SEG statement. Example: 'Save the screens contents DIM screensave(3999) AS INTEGER DEF SEG = &HB800 FOR i 0 TO 3999 screensave(i) = PEEK(i) NEXT i DEF SEG Related statements: DEF SEG, POKE PMAP Function PMAP Function ------------- Maps a physical coordinate to a logical coordinate defined by the WINDOW statement or vice versa. Syntax: PMAP(coordinate,mapping) POINT Function POINT Function -------------- Returns a pixel's color or coordinates. Syntax: POINT(x,y) or POINT(mapping) PEN Function PEN Function ------------- Returns light pen coordinates. Syntax: PEN(numeric_expression) Notes: * numeric_expression is an integer value In the range 0 to 9) that specifies the information PEN returns: 0 -1 if pen used since last call; otherwise, 0 1 The x pixel coordinate where pen was last pressed 2 The y pixel coordinate where pen was last pressed 3 Current usage: -1 if down, 0 if up 4 The last known x pixel value 5 The last known y pixel value 6 Character row where pen was last pressed 7 Character column where pen was last pressed 8 The last known character row 9 The last known character column * PEN does not work when a mouse driver is active. Example: row% = PEN(6) colun% = PEN(7) PLAY Function PLAY Function ------------- Returns the number of notes in the background music queune. Syntax: PLAY(dummy_argument) * Dummy_argument is any numeric argument. It distinquishes the PLAY function from the PLAY statement. * PLAY returns 0 when music is in foreground mode. Example: notes% = PLAY(0) Related statements: ON event GOSUB, PLAY, PLAY (Event Trapping), SOUND RTRIM$ Function RTRIM$ Function --------------- Removes trailing spaces from a string expression. Usage: RTRIM$(string_expression) Notes: * string_expression is any string expression Example: a$ = "AAAA " b$ = "BBBB" PRINT RTRIM$(a$); b$ Running this program produces the following display: AAAABBBB Related functions: LTRIM$ RND Function RND Function ------------ Returns a single random number between 0 and 1. Use: RND[(numeric_expression)] Notes: * numeric_expression specifies how RND generates the next random number: Value Generates ------------------------------------------------- Less than zero The same number for any given numeric_expression Equal to 0 The last number generated Greater than zero The next ramdom number * If you omit numeric_expression, RND generates the next number in the sequence. Example: 'Print ten random numbers FOR i = 1 TO 10 PRINT INT(RND * 10)) NEXT i Related statements: RANDOMIZE RIGHT$ Function RIGHT$ Function --------------- Returns the specified number of characters from the rightmost characters in a string. Usage: RIGHT$(string_expression, num_char) Notes: * string_expression is any string expression. * num_char is the number of characters to return. If num_char exceedes the length of the string, RIGHT$ returns the entire string. Example: A$ = "ABCDEFGHIJ" FOR I 1 TO 10 PRINT RIGHT$(A$, I) NEXT I Related functions: INSTR, LEFT$, LEN, MID$ SEEK Function SEEK Function ------------- Returns the current file pointer position. Usage: SEEK(file_number) Notes: * file_number is the file number assigned to the file in its OPEN statement. * For random-access files, SEEK returns a record number in the range 1 through 2,147,483,647. For binary and sequencial files, SEEK returns the current byte offset. Example: position = SEEK(1) Related functions: LOC Related statements: OPEN, SEEK SGN Function SGN Function ------------ Returns a value indicating the sign of an expression. Usage: SGN(numeric_expression) * If the alue of the expression is negative, SGN returns -1. If the value is positive, SGN will return 1. If the value is 0, SGN returns 0. Example: PRINT SGN(-6) PRINT SGN(0) PRINT SGN(12) Output: -1 0 1 STRING$ Function STRING$ Function ---------------- Returns a string containing the specified number of occurances of a character. Use: STRING$(num_char, ascii_character) or STRING$(num_char, string_expression) Notes: * num_char is the desired number of occurances of a character. * ascii_character is the ASCII code of the character. * string_expression is any string expression. If you provide a string, STRING$ uses the first character of the string. Example: a$ = STRING$(20, 64) PRINT a$ STR$ Function STR$ Function ------------- Returns the string representation of a numeric expression. Use: STR$(numeric_expression) Notes: * numeric_expression is any numeric expression Example: x$ = STR$(4.2892) PRINT x$ Related functions: VAL SPACE$ Function SPACE$ Function --------------- Returns a string containing the specified number of spaces. Use: SPACE$(num_spaces) Notes: * num_spaces is an integer expression from 0 up to 32,767. Example: FOR i = 0 TO 3 PRINT SPACE$(i); i NEXT i Output: 0 1 2 3 Related functions: SPC, TAB SPC Function SPC Function ------------ Skips the specified number of spaces in a PRINT or LPRINT statement. Use: SPC(num_spaces) Notes: * num_spaces is an nteger value no larger than 32,767. Example: FOR i = 0 TO 5 PRINT SPC(i); i NEXT i Related functions: SPACES$, TAB SQR Function SQR Function ------------ Returns the square root of an expression Use: SQR(numeric_expression) Notes: * numeric_expression is any non-negative numeric expression. Example: FOR i = 0 TO 100 PRINT i, SQR(i) NEXT i SIN Function SIN Function ------------ Returns the sine of the specified angle. Use: SIN(angle) * angle is a numeric expression that specifies an angle in radians. * Angles can be expressed in radians or degrees. QBasic supports only radians. To convert from degrees to radians, use the equation: radians = 3.141593 * (degrees / 180) Example: pi = 3.141593 PRINT "Sine of pi", SIN(pi) Related statements: ATN, COS, TAN STICK Function STICK Function -------------- Returns a joystick's x or y coordinate. Use: STICK(numeric_expression) Notes: * numeric_expression is an unsigned integer in the range 0 through 3 that specifies the desired value: 0 x coordinate of joystick A 1 y coordinate of joystick A 2 x coordinate of joystick B 3 y coordinate of joystick B * x and y coordinates can range from 1 to 200 Example: x% = STICK(0) y% = STICK(1) STRIG Function STRIG Function -------------- Returns the value of the joystick trigger. Use: STRIG(numeric_expression) * numeric_expression is an unsigned integer from 0 through 7 to specify the type of information desired: Value Condition 0 lower joystick A button pressed since last STRIG(0) 1 lower joystick A button currently pressed 2 lower joystick B button pressed since last STRIG(2) 3 lower joystick B button currently pressed 4 upper joystick A button pressed since last STRIG(4) 5 upper joystick A button currently pressed 6 upper joystick B button pressed since last STRIG(6) 7 upper joystick B button currently pressed * If the specified condition is true, STRIG returns -1, else STRIG returns 0. Example: ' wait for user to press lower button of joystick A DO LOOP UNTIL STRIG(0) Related statements: ON event GOSUB; STRIG SCREEN Function SCREEN Function --------------- Returns the character or the color attribute for the character at the specified row and column. Use: SCREEN(row,column[get_color]) * row and column are the coordinates of the character * get_color is a numeric expression. If get_color is 1, SCREEN returns the color of the character. If get_color is 0 or is omitted, SCREEN returns the ASCII alue of the character at the specified location. Example: DIM scr(1 TO 25, 1 TO 80) AS INTEGER 'Store current screen contents FOR row = 1 TO 25 FOR column = 1 TO 80 scr(row, column) = SCREEN(row, column) NEXT column NEXT row TAN Function TAN Function ------------ Returns the tangent of a specified angle. Usage: TAN(angle) Notes: * angle is a numeric expression that evaluates to an angle in radians. * The QBasic trigonometric routines support only radians, not degrees, to express an angle. To convert from degrees to radians use: radians = 3.141593 * (degrees / 180) Example: pi = 3.141593 PRINT TAN(pi / 4) Related functions: ATN, COS, SIN TAB Function TAB Function ------------ Moves the print position to the specified column. Usage: TAB(column) Notes: * column is the desired tab column. If the current position is beyond the specified column, TAB moves to the column on the next line. Example: For i = 1 TO 10 PRINT TAB(i); i NEXT i Related Functions: SPC TIME$ Function TIME$ Function -------------- Returns the current time in an eight character string of the form hh:mm:ss. Usage: TIME$ Example: PRINT TIME$ Example output: 12:00:00 Related functions: DATE$ Related statements: DATE$, TIME$ TIMER Function TIMER Function -------------- Returns the number of seconds since midnight. Syntax: TIMER Notes: * You can use TIMER with RANDOMIZE to seed the random number generator. Example: RANDOMIZE TIMER UBOUND Function UBOUND Function --------------- Returns the highest array subscript for the specified array dimension. Usage: UBOUND(array_name[,dimension]) Notes: * array_name is the name of the array of interest. * dimension is an integer value specifying the dimension of interest in a multi- dimensional array. The default is 1. Example: DIM a(1 TO 5, 1 TO 10, 1 TO 25) PRONT UBOUND(a), UBOUND(a, 2), UBOUND(a, 3) Output: 5 10 25 Related functions: LBOUND Related statements: DIM, OPTION BASE, REDIM UCASE$ Function UCASE$ Function --------------- Returns a character string with letters in the specified string in uppercase. Usage: UCASE$(string_expression) * string_expression is any string expression. Example: a$ = cZcd$F PRINT UCASE(a$) Output: CZCD$F Related functions: LCASE$ VAL Function VAL Function ------------ Converts a string representation of a numeric value to the actual numeric value. Usage: VAL(string_expression) Notes: * string_expression is the string representation of a numeric value. * VAL stops at the first character it cannot recognize as part of a number. Valid characters are 0 through 9, the period, the minus sign, and the plus sign. Example: PRINT VAL("33.44") PRINT VAL("88k") Output: 33.44 88 Related functions: STR$ VARSEG Function VARSEG Function --------------- Returns a variable's segment in memory. Use: VARSEG(variable) * variable is the name of any variable in the program. Example: See CALL ABSOLUTE Related functions: VARPTR Related statements: DEF SEG VARPTR Function VARPTR Function --------------- Returns a variable's offset in memory. Use: VARPTR(variable) * variable is the name of any variable in the program. * QBasic does not guarantee that a variable will reside in the same memory location throughout the program execution. So use VARPTR immediately before any code that uses the offset value. Example: See CALL ABSOLUTE Related functions: VARSEG Related statements: DEF SEG VARPTR$ Function VARPTR$ Function ---------------- Returns a string representation of a variable's offset for use in the PLAY and DRAW statements. Use: VARPTR$(string_variable) * string_variable is a string variable containing DRAW or PLAY commands. * QBasic does not guarantee that a variable will reside in the same memory location throughout the program execution. So use VARPTR immediately before any code that uses the offset value. Example: scale$ = "CDEFGAB" PLAY "X" + VARPTR$(scale$) Related statements: DRAW, PLAY