QuickBASIC 3

Share Embed Donate


Short Description

Download QuickBASIC 3...

Description

QuickBASIC 3.0 The QuickBASIC 3.0 database, Copyright (C) 1987 by Peter Norton Computing, Inc., was written by Craig Stinson, Burton L. Alperson, Brad Kingsbury, John Socha, and Peter Norton.

2

Naredbe po nameni Control program flow ---------------------------------DO...LOOP Begin Definition of DO/LOOP Loop END Terminate Program EXIT Exit Multiline Function, Loop, or Subprogram FOR...NEXT Begin Definition of FOR/NEXT Loop GOSUB Execute Subroutine GOTO Unconditional Branch IF Conditional Branch ON...GOSUB Branch to nth Item in Subroutine List ON...GOTO Branch to nth Item in Line List SELECT CASE Case Structure SLEEP Suspends execution of the calling program STOP Halt Program SYSTEM Return to Operating System WEND End Definition of WHILE/WEND Loop WHILE Begin Definition of WHILE/WEND Loop Declare constants and variables ---------------------------------$DYNAMIC Declare Arrays Dynamic $STATIC Declare Arrays Static COMMON Pass Variables to CHAINed Program or Subprogram CONST Declare Symbolic Constant(s) DATA Store Constant(s) for Retrieval via READ DEFDBL Define Variable(s) as Double Precision DEFINT Define Variable(s) as Integer DEFSNG Define Variable(s) as Single Precision DEFSTR Define Variable(s) as String DIM Dimension Array(s) ERASE Reset Static Array or Deallocate Dynamic Array LET Assignment OPTION BASE Set Minimum Array Subscript READ Assign DATA Items to Variables REDIM Redimension Array REM Comment or Metacommand RESTORE Reset DATA Item Pointer SHARED Declare Global Variables SWAP Exchange the Values of Two Variables TYPE Defines a data type containing one or more elements Define and call Basic procedures ---------------------------------ANY Clause As part of a procedure declaration, disables type checking CALL Invoke Subprogram or Assembly Subroutine CALL ABSOLUTE Invoke Subprogram or Assembly Subroutine CALLS Invoke Subprogram or Assembly Subroutine CHAIN Transfer to Another Program DECLARE Declares references to procedures and functions FUNCTION Declares the function RETURN Return from Subroutine RUN Execute Program STATIC Declare Local Variable(s) SUB...END SUB Define Subprogram Device input/output ---------------------------------CLOSE Close File or Device CLS Clear Screen CSRLIN Line Position of Cursor INKEY$ Most Recent Character at Keyboard INP Read from an I/O Port INPUT Get Input from Keyboard INPUT$ Read Specified Number of Characters IOCTL Send Control String to Device Driver IOCTL$ Read Control String from Device Driver KEY Set or Display Soft Keys LINE INPUT Read Line from Keyboard, Ignoring Delimiters LOC Current File Position LOCATE Position the Cursor

3

LPOS LPRINT LPRINT USING OPEN "COM... OUT POS PRINT PRINT USING RESET SCREEN SPC TAB VIEW PRINT WAIT WIDTH WRITE

Current Position of Print Head Output to LPT1: Formatted Output to LPT1: Open a Communications File Send Byte to Output Port Current Cursor Column Position Display on Screen Formatted Screen Display Close All Disk Files Character at Specified Location (Function) Skip n Spaces in a PRINT statement Tab to a Specified Position Set Screen Text Window Wait for Port Status Set Output Width Output to Screen

Display graphic images ---------------------------------CIRCLE Draw Ellipse on Screen COLOR Set Foreground, Background, and Border Colors DRAW Draw Object GET Read Points from Screen (Graphics) LINE Draw Line or Box PAINT Fill an Area with a Pattern or Color PALETTE Change Color in the Palette PALETTE USING Change Many Colors in the Palette PCOPY Copy Screen Page PMAP Map Physical Coordinates to World POINT Attribute or Value at Screen Location PRESET Draw Point on Screen PSET Draw Point on Screen PUT Plot Array Image on Screen (Graphics) SCREEN Set Screen Attributes (Statement) VIEW Define Screen Window WINDOW Redefine Screen Coordinates DOS file system commands ---------------------------------CHDIR Change Directory ENVIRON Modify Environment Table ENVIRON$ Environment Table Entry FILES Display File Directory KILL Delete File(s) MKDIR Create Subdirectory NAME Rename File RMDIR Remove Subdirectory SHELL Execute DOS Command File input/output ---------------------------------BINARY Used in an OPEN statement to specify binary file mode. BLOAD Load Binary (Memory Image) File BSAVE Save a Binary (Memory Image) File CLOSE Close File or Device EOF End of File Status FIELD Allocate Space for Random File Variables FILEATTR Returns information about an open file FREEFILE Returns the next free BASIC file number GET Read Random File into Buffer (File I/O) INPUT # Get Input from Sequential File or Device INPUT$ Read Specified Number of Characters KILL Delete File(s) LINE INPUT# Read Line from File, Ignoring Delimiters LOC Current File Position LOCK Control File or Record Access LOF Length of File LSET Left-Justify Data in Field Variable NAME Rename File OPEN Allow File or Device I/O PRINT # Output to Sequential File PRINT # USING Formatted Output to File PUT Write Record from Random Buffer to File (File I/O) RSET Right-Justify Data in Field Variable SEEK Function that returns the current file position UNLOCK Remove File or Record Access Lock

4

WRITE #

Output to Sequential File

Menage memory ---------------------------------BLOAD Load Binary (Memory Image) File BSAVE Save a Binary (Memory Image) File CLEAR Close Files, Reset Variables, Set Stack Space DEF SEG Define Segment FRE Available Memory PEEK Value at Specified Address POKE Write Byte to Memory SADD String Address VARPTR Offset of Variable or Offset of File Buffer VARPTR$ Offset of Variable, in Character Form Manipulate strings ---------------------------------ASC ASCII Value of First Character CHR$ Convert ASCII Code to Character CVD Convert String to Double-Precision CVDMBF MBF Double-Precision String to IEEE (QB87 only) CVI Convert String to Integer CVS Convert String to Single Precision CVSMBF MBF Single-Precision String to IEEE (QB87 only) HEX$ Hexadecimal Value, as String INSTR Find Substring LCASE$ Returns a string with all letters in lower-case LEFT$ Substring at Left LEN Length of String LSET Left-Justify Data in Field Variable LTRIM$ Returns a copy of a string with leading spaces removed MID$ Assign Substring (Statement) MID$ Substring in Middle (Function) MKD$ Convert Double-Precision to String MKDMBF$ IEEE Double-Precision to MBF String (QB87 only) MKI$ Convert Integer to String MKS$ Convert Single-Precision to String MKSMBF$ IEEE Single-Precision to MBF String (QB87 only) OCT$ Octal Value, as String RIGHT$ Substring at Right RSET Right-Justify Data in Field Variable RTRIM$ Returns a string with trailing (right-hand) spaces removed SPACE$ String of n Spaces STR$ String Representation of Numeric Expression STRING$ String of Specified Length and Character UCASE$ Returns a string expression with all letters in uppercase VAL Numeric Value of a String Perform mathematical calculations ---------------------------------ABS Absolute Value ATN Arctangent CDBL Convert to Double Precision CINT Convert to Integer CLNG Converts long (4-byte) integer by rounding the fractional part of the expression COS Cosine CSNG Convert to Single Precision DEF FN Define Function EXP Exponent (Natural) FIX Truncate to Integer INT Next Lower Integer LBOUND Lower Bound of Array Dimension LOG Natural Logarithm RANDOMIZE Reseed Random Number Generator RND Random Number SGN Sign of Number SIN Sine SQR Square Root TAN Tangent UBOUND Upper Bound of Array Dimension Set traps for events and errors ---------------------------------COM(n) Enable/Disable Comm Port Trapping ERDEV Critical Error Code

5

ERDEV$ ERL ERR ERROR KEY(n) ON COM ON ERROR ON KEY ON PEN ON PLAY(n) ON STRIG(n) ON TIMER PEN PEN PLAY RESUME STRIG STRIG TIMER

Device Causing Critical Error Line Number of Most Recent Error Error Number Force Error Enable/Disable Key Trapping Trap for Communications Activity Enable Error Trapping Trap for Keypress Trap for Light Pen Activity Trap for Background Music Remaining Trap for Specified Joystick Button Trap for Elapsed Time Enable/Disable Pen Read and Trap (Statement) Light Pen Status (Function) Enable/Disable Music Trap (Statement) Continue after Error Trap Enable/Disable the STRIG Function (Statement) Status of Joystick Buttons (Function) Enable/Disable Timer Trap (Statement)

Time ---------------------------------DATE$ Get or Set System Date TIME$ Get System Time (Function) TIME$ Set System Time (Statement) TIMER Enable/Disable Timer Trap (Statement) TIMER Number of Seconds since Midnight (Function) Sound ---------------------------------BEEP Beep the Speaker PLAY Enable/Disable Music Trap (Statement) PLAY Number of Notes in Background Buffer (Function) PLAY Play Music (Statement) SOUND Sound the Speaker Ostalo ---------------------------------$INCLUDE Include File COMMAND$ Get Command Line TROFF Trace Off TRON Trace On

6

1

BASIC

Language $DYNAMIC

Declare Arrays Dynamic

REM $DYNAMIC Makes the default array allocation dynamic. -------------------------------------------------------------------------Notes:

$DYNAMIC makes all subsequent arrays dynamic except for those that are implicitly DIMensioned (i.e. used without a DIM statement). Implicitly DIMensioned arrays are always static.

See Also: $STATIC DIM ERASE FRE

$INCLUDE

Include File

REM $INCLUDE: filespec Causes compilation to branch to a specified text file, then return to the main file when the end of the $INCLUDE file has been reached. filespec

A string literal that follows DOS file-naming conventions. The argument must be enclosed within single quote marks.

----------------------------------------------------------------------Notes:

If the include file was created with the BASIC Interpreter, it must be saved in ASCII format. The include file must not contain END statements. Variables in the $INCLUDE file must be consistent with those in the main program.

$STATIC

Declare Arrays Static

REM $STATIC Makes the default array allocation static. ----------------------------------------------------------------------Notes:

$STATIC makes all subsequent arrays static, including those that are DIMensioned with variable subscripts.

See Also: $STATIC DIM ERASE FRE

7

'

Comment ' [remark] Adds explanatory text to a program listing. remark

Commentary text, ignored by BASIC.

----------------------------------------------------------------------Notes:

BASIC does not execute comments, but a program may branch to a statement beginning with '. Execution will then continue with the first executable statement thereafter. Any program statements following a comment, in the same logical line, are ignored by BASIC. ' can be used to add a comment at the end of an existing program statement (BASIC ignores everything following the ' character). Exception: ' cannot be used in this manner in a DATA statement (because BASIC would treat the ' as part of the DATA).

See Also: REM

ABS

Absolute Value

y = ABS(numexpr) Returns the absolute value of an expression. numexpr

ANY Clause

A numeric expression.

(QuickBasic 4.5)

variable AS ANY When used as the variable type in an AS type clause that is part of a procedure declaration, ANY disables type checking for that parameter. See Also: DECLARE

ASC

ASCII Value of First Character

y = ASC(stringexpr) Returns the ASCII value of the first character of a string expression. stringexpr

A string expression.

----------------------------------------------------------------------Notes:

If the argument is a null string, ASC returns an Illegal Function Call error.

See Also: CHR$ ASCII Table

ATN

Arctangent

y = ATN(numexpr) Returns, in radians, the angle whose tangent is numexpr. numexpr

A numeric expression.

-----------------------------------------------------------------------

8

Notes:

If the argument is a double-precision expression, ATN returns a double-precision value. Otherwise single precision is returned.

See Also: COS SIN TAN

BEEP

Beep the Speaker

BEEP Sounds the speaker at 800 Hz for a quarter of a second (equivalent to PRINT CHR$(7)). BLOAD

Load Binary (Memory Image) File

BLOAD filespec [,offset] Loads a specified memory image file into memory. filespec offset

A string expression that follows DOS file naming conventions; may include any device, except "KYBD:". A single-precision expression in the range 0 to 1048575 (2^20-1). Specifies the offset at which filespec is loaded. Defaults to the offset found in filespec when the image was BSAVEd.

----------------------------------------------------------------------Notes:

The segment into which the file is BLOADed is that specified by the most recent DEF SEG statement. You will not be warned if a BLOAD is about to overwrite DOS or any other sensitive area of memory.

See Also: BSAVE DEF SEG

BINARY Keyword

(QuickBasic 4.5) BINARY is used in an OPEN statement to specify binary file mode. In binary mode, you may read or write information to any byte position in the file using GET or PUT statements. See Also: OPEN PUT GET

BSAVE

Save a Binary (Memory Image) File

BSAVE filespec,offset,length Copies a specified portion of memory to a specified file. filespec

A string expression that follows DOS file naming conventions; may include a device name and path.

offset

A single-precision expression in the range 0 to 1048575 (2^20-1). Specifies the offset from which the memory image will be saved.

length

An integer expression in the range 1 to 65535. Specifies the number of bytes to be saved.

----------------------------------------------------------------------Notes:

The segment from which the BSAVE is made is that specified by the most recent DEF SEG statement.

See Also: BLOAD DEF SEG

9

CALL

Invoke Subprogram or Assembly Subroutine

CALL procname [(parmlist)] Transfers control to a subprogram or assembly language subroutine. procname

Specifies the subprogram or assembly routine to be called. The first 31 characters are significant. If name is an assembly language subroutine, it must be a PUBLIC symbol and must not contain '$' or '_' characters.

parmlist

Specifies one subprogram or commas. Array name followed

or more parameters to be passed to the routine. Parameters must be separated by parameters should be specified by the array by empty parentheses.

----------------------------------------------------------------------Notes:

CALL passes unsegmented addresses of parameters. To pass segmented addresses, use CALLS. Note the following differences between QuickBASIC and interpreted BASIC: 1.

QuickBASIC uses 4-byte string descriptors, while interpreted BASIC uses 3-byte descriptors. An assembly subroutine that uses string arguments may therefore need to be modified if it was originally written to run with an interpreted program.

2.

The QuickBASIC CALL statement calls subroutines by name; interpreted BASIC's CALL statement calls subroutines by offset address. To call a subroutine by address in QuickBASIC, use CALL ABSOLUTE.

See Also: CALL ABSOLUTE CALLS

CALL ABSOLUTE

Invoke Subprogram or Assembly Subroutine

CALL ABSOLUTE ([arglist,]intvar) Transfers control and (optionally) passes parameters to an assembly language subroutine. arglist

Specifies one or more parameters to be passed to the subroutine. Parameters must be separated by commas. Array parameters should be specified by the array name followed by empty parentheses.

intvar

An integer variable. Specifies the address of the subroutine as an offset within the current code segment.

----------------------------------------------------------------------Notes:

Your program should execute a DEF SEG statement before calling the subroutine to ensure the code segment is correct (or put the subroutine in DGROUP). QuickBASIC uses 4-byte string descriptors, while interpreted BASIC uses 3-byte descriptors. An assembly subroutine that uses string arguments may therefore need to be modified if it was originally written to run with an interpreted program.

See Also: CALL CALLS

CALLS

Invoke Subprogram or Assembly Subroutine

CALLS name [(arglist)] Transfers control and (optionally) passes parameters to a subprogram or an assembly language subroutine.

10

name

arglist

Specifies the subprogram or subroutine to be called. The first 31 characters are significant. If name is an assembly language subroutine, it must be a PUBLIC symbol and must not contain '$' or '_' characters. Specifies one subprogram or commas. Array name followed

or more parameters to be passed to the subroutine. Parameters must be separated by parameters should be specified by the array by empty parentheses.

----------------------------------------------------------------------Notes:

CALLS passes segmented addresses of parameters. To pass unsegmented addresses, use CALL. Note the following differences between QuickBASIC and interpreted BASIC: 1.

QuickBASIC uses 4-byte string descriptors, while interpreted BASIC uses 3-byte descriptors. An assembly subroutine that uses string arguments may therefore need to be modified if it was originally written to run with an interpreted program.

2.

The QuickBASIC CALL statement calls subroutines by name; interpreted BASIC's CALL statement calls subroutines by offset address. To call a subroutine by address in QuickBASIC, use CALL ABSOLUTE.

See Also: CALL ABSOLUTE CALL

CDBL

Convert to Double Precision

y = CDBL(numexpr) Converts any numeric expression to double precision. numexpr

A numeric expression.

See Also: CINT CSNG

CHAIN

Transfer to Another Program

CHAIN filespec Transfers control to another program. filespec

A string expression that follows DOS file naming conventions; If no extension is supplied, an extension of .EXE is assumed.

----------------------------------------------------------------------Notes:

If the calling program and the chained-to program are both compiled with the default library, BRUN20.LIB, variables may be passed to the chained-to program via COMMON, and files opened by the calling program remain open to the CHAINed program. The alternate library, BCOM20.LIB does not support COMMON, and in programs compiled with BCOM20.LIB, a CHAIN statement is equivalent to a RUN statement (i.e., open files are closed before the CHAINed program is executed). Note the following differences between QuickBASIC and the BASIC interpreter: 1.

The interpreter assumes a .BAS extension for the chained-to filespec; QuickBASIC assumes .EXE. The only explicit filespec extension allowed in QuickBASIC is .EXE.

11

2.

QuickBASIC does not support the ALL, MERGE, DELETE, and line options of the interpreted BASIC CHAIN statement.

See Also: COMMON

CHDIR

Change Directory

CHDIR pathspec Changes the current directory. pathspec

A string expression, of 128 or fewer characters, that follows DOS path naming conventions.

-------------------------------------------------------------------------Notes:

This procedure is equivalent to DOS's CHDIR command.

See Also: MKDIR RMDIR

CHR$

Convert ASCII Code to Character

s$ = CHR$(code) Returns the character whose ASCII value is specified. code

A numeric expression in the range 0 to 255.

See Also: ASC STR$ ASCII Table

CINT

Convert to Integer

y = CINT(numexpr) Converts a numeric expression to an integer, by rounding. numexpr

A numeric expression in the range -32768 to 32767.

See Also: CDBL CSNG FIX INT

CIRCLE

Draw Ellipse on Screen

CIRCLE [STEP] (x,y), radius [,[color] [,[start],[end][,aspect]]] Draws an ellipse on the screen. STEP

x,y radius

If included, coordinates are relative to last graphics point referenced (LPR). If omitted, coordinates are absolute. The center (column, row) of the ellipse in pixels. Length, in pixels, of the major axis (the radius, in the case of a circle).

color

Color in which the ellipse is drawn. Defaults to 3 in medium resolution, 1 in high resolution.

start

Starting angle of arc, in radians. Defaults to 0.

end aspect

Ending angle of arc, in radians. Defaults to 2.. Ratio, in pixels, of the x radius to the y radius. Defaults to 5/6 in medium resolution, 5/12 in high resolution; these values generate a circle on the CGA.

-------------------------------------------------------------------------Notes:

12

Omitting start and end will draw a complete circle.

If negative values for start and end are given, the end points of the resulting arc are connected to the center point, thus creating pie-chart wedges. After a CIRCLE statement has been executed, the "last point referenced" (LPR) is the center of the ellipse. See Also: LINE

CLEAR

Close Files, Reset Variables, Set Stack Space

CLEAR [,,stack] Closes all files, clears all COMMON variables, resets all numeric variables to 0 and all string variables to null, releases all disk buffers, resets the stack, and optionally specifies the size of the stack. stack

Specifies, in bytes, the size of QuickBASIC's stack. The default is 768 bytes; the minimum is 512 bytes.

----------------------------------------------------------------------Notes:

CLEAR destroys pending return addresses left on the stack by GOSUB, FOR/NEXT, and WHILE/WEND. CLEAR does not affect symbolic constants. QuickBASIC's CLEAR differs from the Interpreter's in two ways: 1.

The Interpreter's CLEAR statement destroys all DEF FN and DEFtype statements. QB's does not.

2.

The interpreter's default stack is 512 bytes. QB's is 768.

See Also: ERASE

CLNG

a conversion function that converts a numeric expression to a long (4-byte) integer by rounding the fractional part of the expression (QuickBasic 4.5) CLNG(numeric-expression) If numeric-expression is not in the range -2,147,483,648 to 2,147,483,647, the function produces an error message that reads "Overflow." Example: The following example shows how CLNG rounds before converting the number: A=32767.45 B=32767.55 PRINT CLNG(A); CLNG(B) Sample Output 32767

32768

See Also: CINT CSNG CDBL

CLOSE

Close File or Device

CLOSE [[#] filenum [,[#] filenum]...]

13

Closes one or more files or devices and terminates the association between a file or device and its number. filenum

The number under which a file was OPENed.

---------------------------------------------------------------------Notes:

If no filenum is supplied, all open files and devices are CLOSEd. If the device or file was OPENed for sequential output, CLOSE writes the final buffer to the device or file. CLEAR, END, NEW, RESET, and SYSTEM automatically close all open files and devices.

See Also: END OPEN STOP

CLS

Clear Screen

CLS [0 | 1 | 2] Clears the screen, as described below, and returns the cursor to the Home position (row 1, column 1). 0

CLS 0 clears all text and graphics.

1

CLS 1 clears just the graphics viewport, if a VIEW statement has been issued. If no VIEW statement has been issued, CLS 1 clears the entire screen.

2

CLS 2 clears just the text window. The bottom screen line (line 25 or line 43) is left unchanged.

---------------------------------------------------------------------Notes:

CLS with no argument clears the entire screen, unless a VIEW statement has been used to create a viewport in graphics mode--in which case CLS clears only the current viewport. CLS resets the "last point referenced" (LPR) so that the next graphics command that uses the STEP option references the center of the screen. In text mode, CLS clears the active page to the background color. In graphics mode, CLS clears the entire screen buffer to the background color. Other ways to clear the screen include SCREEN, WIDTH, and Ctrl-Home.

See Also: COLOR SCREEN VIEW

COLOR

Set Foreground, Background, and Border Colors

COLOR [foreground] [,[background] [,border]] COLOR [background] [,[palette] COLOR [foreground] [,[background]]

' Screen mode 0 ' Screen mode 1 ' Screen modes 7-10

Specifies foreground, background, and border colors in text mode (SCREEN mode 0); in medium-resolution graphics mode (SCREEN mode 1), specifies palette and background color; in screen modes 7 through 10, specifies foreground and background colors. May not be used in SCREEN mode 2 (high-resolution graphics).

14

foreground

An integer expression; selects the foreground color. For SCREEN mode 0, this value must be in the range 0 to 31; for SCREEN modes 7-10, this value must be in the range 1-15.

background

An integer expression; selects the background color. For

SCREEN mode 0, this value must be in the range 0 to 7; for SCREEN modes 1-10, this value must be in the range 0 to 63. palette

An integer expression, selecting one of two color palettes (see below).

border

An integer expression; must be in the range 0 to 15. Selects the color of the border. Color values

Value 0 1 2 3 4 5 6 7

Value 8 9 10 11 12 13 14 15

Color Black Blue Green Cyan Red Magenta Brown White

Color Gray Light blue Light green Light cyan Light red Light magenta Yellow Bright white

Add 16 to a value to produce its blinking equivalent. Foreground attributes for the Monochrome Display Adapter Value 0 1 2-7 8 9 10-15 16 17 18-23 24 25 26-31

Foreground Attribute Black Underlined White Black Underlined high intensity High-intensity white Black Underlined black Blink Black Blinking underlined high intensity Blinking high intensity

Background values in the range 0 to 6 produce a black background, while a value of 7 produces a white background. If the background and foreground are the same, then the characters will be invisible. The following is a list of legal values for each of the SCREEN modes: SCREEN 0 The The The

(Text mode) foreground color must be in the range 0 to 31. background color must be in the range 0 to 7. border color must be in the range 0 to 15.

The default color for background and border is black. SCREEN 1 (Medium-resolution graphics mode) The background color must be in the range 0 to 15. Even numbers for palette will select Palette 0, whereas odd number will select Palette 1. Palettes Color 0 1 2 3

Palette 0 Current background Green Red Brown

Palette 1 Current background Cyan Magenta White

SCREEN 2 (High-resolution graphics mode) Calling COLOR when in this mode will result in a runtime error. SCREEN 7 and 8 The foreground color must be in the range 1 to 15. The background color must be in the range 0 to 15.

15

EGA only. The colors are dependent on the current palette selected (See PALETTE statement). SCREEN 9 The foreground color must be in the range 1 to 15 for EGAs with more than 64K. If the EGA only has 64K, the foreground color must be in the range 1 to 3. The background color must be in the range 0 to 63. EGA only. The colors are dependent on the current palette selected (See PALETTE statement). SCREEN 10 The foreground color must be in the range 1 to 3. The values are as follows: 1 = Black; 2 = Blink; and 3 = High Intensity. The background color must be in the range 0 to 8. EGA only. The colors are dependent on the current palette selected (See PALETTE statement). -------------------------------------------------------------------------Notes:

In text mode (SCREEN mode 0), the COLOR statement specifies the foreground, background, and border colors. Omitted parameters retain former values. The default is white foreground (7), black background (0), and black border (0). The border parameter is ignored on the Monochrome Display Adapter. In medium-resolution graphics mode (SCREEN mode 1), the COLOR statement doesn't actually specify the foreground color. Instead it specifies the background color and one of two three-color palettes. Foreground colors are selected from the current palette via the PSET, PRESET, LINE, CIRCLE, PAINT, VIEW, and DRAW statements. Either the background parameter or the palette parameter (but not both) may be omitted; omitted parameters retain former values. The COLOR statement may not be used in high-resolution graphics mode (SCREEN mode 2). The border option cannot be used with an Enhanced Graphics Adapter (EGA) with an Enhanced Color Display.

See Also: PALETTE SCREEN (Statement)

COM(n)

Enable/Disable Comm Port Trapping

COM(n) {ON | OFF | STOP} Enables the trapping of communications activity via ON COM(n). n ON OFF STOP

Must be 1, for COM1:, or 2, for COM2:. Causes QB to check for communications activity. Causes QB not to check for communications activity. This is the default condition. Also disables trapping, but QB continues checking for activity at the specified communications port. If such activity occurs, a subsequent COM(n) ON results in an immediate trap (provided an ON COM(n) statement with a nonzero line number has been executed).

---------------------------------------------------------------------Notes:

16

If the "Checking Between Statements" option is in effect, QB checks for communication activity after each statement.

If the "Event Trapping" option is selected, QB checks after each new program line. If neither option is selected, no trapping takes place. For command-line compilation, /v enables checking after each statement, and /w enables checking after each new line. If neither switch is used, no trapping takes place. See Also: ON COM Switches and Options

COMMAND$

Get Command Line

s$ = COMMAND$ Returns the command-line parameter(s) supplied when a QuickBASIC program is invoked. ---------------------------------------------------------------------Notes:

Returns everything that was typed on the command line when the program was executed, except the program name and any redirection or piping commands. The function strips any leading white-space characters and converts all lowercase characters to upper case. The maximum length of the command line is 127 characters.

COMMON

Pass Variables to CHAINed Program or Subprogram

COMMON [SHARED] [/blockname/] varlist Passes variables to a chained-to program or a subprogram. SHARED

An optional attribute. The COMMON statement must appear in both the calling program and the chained-to program or subprogram--unless the subprogram is in the same module as the calling program and the SHARED attribute is used in the calling program's COMMON statement.

blockname

Any valid BASIC identifier; the first 31 characters are significant. Allows you to name a group of common variables. A group of variables passed with a blockname is called a named COMMON block; variables passed without a blockname are called a blank COMMON block.

varlist

One or more scalar or array variables to be shared with a chained-to program or a subprogram.

---------------------------------------------------------------------Notes:

The order in which variables appear in varlist is significant, not the names of the variables. To avoid type mismatches and other calamities, it's advisable to put all shared variables in a COMMON statement in a separate file, then $INCLUDE that file in both the calling program and any chained-to programs or subprograms. The COMMON statement must appear before any executable statements. Nonexecutable statements are CONST, DATA, COMMON, DEFtype, DIM (for static arrays), OPTION BASE, comments, and metacommands. If a static array is to be passed to a chained-to program or subprogram, its DIM statement must appear before the COMMON statement. The DIM statement must use integerconstant subscripts. If a dynamic array is to be passed, it must be DIMmed or REDIMmed after the COMMON statement. When passing a named COMMON block to a program in the user library, the calling program may not redefine the block to

17

a larger size. Blank COMMON blocks may be resized. When COMMON is used with CHAIN and compilation is done outside the QuickBASIC environment, the BRUN20.EXE library (QB's default) must be used. See Also: CALL CHAIN SUB...END SUB

CONST

Declare Symbolic Constant(s)

CONST name = expr [,name = expr...] Declares one or more symbolic constants. name

An identifier that follows the rules for naming BASIC variables. A type character (%, #, !, or $) may be included in the declaration, but the type character does not have to be used in statements that reference the constant.

expr

An expression consisting of literals, with or without operators, only. The exponentiation operator may not be used, nor may any intrinsic function.

----------------------------------------------------------------------Notes:

Symbolic constants produce more efficient code than do constant values assigned to variables. Symbolic constants are global. If a type character is not included in the constant name, the compiler evaluates the expression and assigns the most compact possible data type to the constant. DEFtype statements do not affect symbolic constants. Symbolic constants must be defined before they're referenced.

COS

Cosine

y = COS(numexpr) Returns the cosine of the angle whose value, in radians, is expressed in numexpr. numexpr

A numeric expression. If numexpr is a double-precision expression, COS returns a double-precision value. Otherwise single precision is returned.

See Also: ATN SIN TAN

CSNG

Convert to Single Precision

y = CSNG(numexpr) Converts any numeric expression to single precision. numexpr

A numeric expression.

See Also: CDBL CINT

CSRLIN

Line Position of Cursor

y = CSRLIN Returns the row number of the current cursor location on the current screen page.

18

---------------------------------------------------------------------Notes:

To get the current column position, use POS. To set the cursor position, use LOCATE.

See Also: LOCATE POS

CVD

Convert String to Double-Precision

y# = CVD(8-byte-string) Converts an eight-byte string expression to a double-precision number. ---------------------------------------------------------------------Notes:

A double-precision real number must be converted to a string (via MKD$) before being stored in a random access file. To retrieve such a number, first assign it to a file buffer field (with GET), then use CVD.

See Also: GET (File I/O) CVI CVS MKD$ MKI$ MKS$

CVDMBF

MBF Double-Precision String to IEEE

QB87 only

y! = CVSMBF(8-byte-string) Converts a string representation of a double-precision number in Microsoft Binary Format to an IEEE-format real. ---------------------------------------------------------------------Notes:

The IEEE format for real numbers offers more accuracy and range than the Microsoft Binary Format. But the IEEE format is supported only by the QB87 version of the compiler, and programs compiled with QB87 run only on machines equipped with 8087 or 80287 coprocessors. An alternative to converting MBF data with CVSMBF and CVDMBF is to compile the program with the /MBF commandline switch. This option converts numbers as they're read from a random file, then reconverts them before writing them back to the file.

See Also: CVS CVSMBF GET (File I/O) MKDMBF$ MKSMBF$

CVI

Convert String to Integer

y% = CVI(2-byte-string) Converts a two-byte string expression to an integer. ---------------------------------------------------------------------Notes:

An integer must be converted to a string (via MKI$) before being stored in a random access file. To retrieve it, first assign it to a file buffer field (with GET), then use CVI.

See Also: CVD CVS GET (File I/O) MKD$ MKI$ MKS$

CVS

Convert String to Single Precision

y! = CVS(4-byte-string) Converts a four-byte string expression to a single-precision number. ---------------------------------------------------------------------Notes:

A single-precision real number must be converted to a string (via MKS$) before being stored in a random access

19

file. To retrieve such a number, first assign it to a file buffer field (with GET), then use CVS. See Also: CVD CVI GET (File I/O) MKD$ MKS$ MKI$

CVSMBF

MBF Single-Precision String to IEEE

QB87 only

y! = CVSMBF(4-byte-string) Converts a string representation of a single-precision number in Microsoft Binary Format to an IEEE-format real. ---------------------------------------------------------------------Notes:

The IEEE format for real numbers offers more accuracy and range than the Microsoft Binary Format. But the IEEE format is supported only by the QB87 version of the compiler, and programs compiled with QB87 run only on machines equipped with 8087 or 80287 coprocessors. An alternative to converting MBF data with CVSMBF and CVDMBF is to compile the program with the /MBF commandline switch. This option converts numbers as they're read from a random file, then reconverts them before writing them back to the file.

See Also: CVS CVDMBF MKDMBF$ MKSMBF$

DATA

Store Constant(s) for Retrieval via READ

DATA constant1 [,constant2]... Stores one or more constants, of any type, for subsequent access via READ statements. ---------------------------------------------------------------------Notes:

DATA statements are nonexecutable statements that supply a stream of data constants for use by READ statements. All the items supplied by all the DATA statements in a program make up one continuous string of information that is accessed in order by your program's READ statements. Use RESTORE to reset the pointer to the first item in a specified DATA statement. You may put as many constants (expressions are not allowed) in a single DATA statement as will fit on one line, and your program may have any number of DATA statements, positioned anywhere in the program. String constants in DATA statements do not need to be surrounded by quote marks, unless they contain quote marks themselves, or colons, or commas, or significant leading or trailing blanks. If you wish to add a comment at the right side of a DATA statement, use :REM. An apostrophe (single quote) will be treated as part of a DATA item.

See Also: READ RESTORE

DATE$

Get or Set System Date

s$ = DATE$ DATE$ = stringexpr

' Get the system date ' Set the system date

Gets or Sets the current system date. stringexpr

20

A string expression in either of the following forms (but slash characters may be substituted for the hyphens):

"mm-dd-yy" "mm-dd-yyyy" ------------------------------------------------------------------------Notes:

If DATE$ is being assigned a value, then the system date is set, else the system date is retrieved. The system date retrieved is formatted as: "mm-dd-yyyy" If the year is expressed in two digits, instead of four, the twentieth century is assumed. If the month is expressed as a single digit, a leading zero is assumed. The year portion of the date must be in the range 1980 to 2099. This statement resets the AT system date in nonvolatile memory when QuickBasic is run under DOS 3.3.

See Also: TIME$

DECLARE - a non-executable statement that declares references to BASIC procedures and invokes argument type checking (QuickBasic 4.5)

DECLARE {FUNCTION | SUB } name [([parameterlist])] Argument name

Description The procedure's name. The name is limited to 40 characters. FUNCTION names can end in one of the type-declaration characters (%, &, !, #, or $) to indicate the type of value returned.

parameterlist

A list of parameters indicating the number and type of arguments used when calling the procedure. Syntax is shown below. Only the number and type of the arguments are significant.

For calls within BASIC, the DECLARE statement is required only if you call SUB procedures without the CALL keyword, or if you invoke a FUNCTION defined in another module. A DECLARE statement also causes the compiler to check the number and type of arguments used to invoke the procedure. QuickBASIC automatically generates DECLARE statements when you save your program while working in the environment. The DECLARE statement can appear only in module-level code (not in a SUB or FUNCTION) and affects the entire module. The parameterlist serves as a prototype for checking the number and type of the arguments in SUB and FUNCTION calls. It has the following syntax: variable[AS type][,variable[AS type]]... A variable is any valid BASIC variable name. If the variable is an array, it may be followed by the number of dimensions in parentheses: DECLARE SUB DisplayText (A(2) AS STRING) DIM Text$(100,5) . . . CALL DisplayText(Text$()) The number of dimensions is optional. The type is either INTEGER, LONG, SINGLE, DOUBLE, STRING, or a user-defined type. Again, only the number and types of arguments are significant.

21

Note: You cannot have fixed-length strings in DECLARE statements because only variable-length strings can be passed to SUB and FUNCTION procedures. Fixed-length strings can appear in an argument list but are converted to variable-length strings before being passed. A variable's type can also be indicated by including an explicit type character ( %, &, !, #, or $) or by relying on the default type. The form of the parameter list determines whether or not argument checking is done, as shown in the following list: Declaration

Meaning

DECLARE SUB First

You may only omit the parentheses if the SUB or FUNCTION is separately compiled. No argument checking is done.

DECLARE SUB First ()

First has no parameters. Arguments in a CALL to First are flagged as an error. An empty parameter list indicates that the SUB or FUNCTION has no parameters.

DECLARE SUB First (X AS LONG)

First has one long-integer parameter. The number and type of the arguments in each CALL or invocation are checked when the parameter list appears in the DECLARE.

Other Uses of the DECLARE Keyword: DECLARE can also be used to declare references to procedures written in other programming languages, such as C Example: DECL_EX.BAS the DECLARE View window menu's Open

is a program file in the subdirectory ADVR_EX that illustrates statement for BASIC procedures. To look at the program in the and, optionally, to run it, load the program using the File Program command.

In the program, use of the DECLARE statement allows a SUB to be invoked without using the CALL keyword. See Also: FUNCTION SUB CALL

DEF FN

Define Function

1. DEF FNname[(parmlist)] = expression 2. DEF FNname[(parmlist)] . . [statements] . [EXIT DEF] FNname = expression END DEF Defines a user function. name

A valid variable name, of the same type as expression.

parmlist

One or more formal parameters for the function. Each must be a valid variable name. Parameters are passed by value.

expression

An expression, of the same type as name, that defines the value returned by the function.

---------------------------------------------------------------------Notes:

22

For numeric functions, the precision specified by name determines the precision returned by the function.

Functions must be defined before they are called. They may not be defined within IF/THEN/ELSE, FOR/NEXT, WHILE/WEND, or SUB/END SUB blocks, and they may not be defined in terms of themselves. In the multi-line syntax, expression defines the value returned by the function. The optional EXIT DEF statement can be used to exit the function but does not define the end of the function. Variables in a multiline function definition are global unless declared in a STATIC statement. See Also: STATIC

DEF SEG

Define Segment

DEF SEG [=segment] Specifies the segment address from which arguments to BLOAD, BSAVE, CALL ABSOLUTE, PEEK, and POKE will be offset. segment

A numeric expression in the range 0 to 65535.

---------------------------------------------------------------------Notes:

DEFDBL

DEF SEG defaults to BASIC's data segment (DS). A DEF SEG statement with no argument returns the DEF SEG address to this default value.

Define Variable(s) as Double Precision

DEFDBL letter[-letter] [,letter [-letter]]... Declares one or more variables to be double precision. ---------------------------------------------------------------------Notes:

All variable names beginning with any of the specified letters (case-insensitive) will be double precision, unless a type-identifier character (%, !, or $) is used to override the DEFDBL declaration. The DEFDBL declaration must be read by the compiler before any statements in which the declared variables are assigned or used. The compiler reads from beginning to end, without regard for execution path. You cannot avoid a DEFDBL declaration by direction the execution path around it. DEFDBL statements do not affect symbolic constants.

See Also: DEFINT DEFSNG DEFSTR

DEFINT

Define Variable(s) as Integer

DEFINT letter[-letter] [,letter [-letter]]... Declares one or more variables to be of type integer. ---------------------------------------------------------------------Notes:

All variable names beginning with any of the specified letters (case-insensitive) will be integer, unless a typeidentifier character (#, !, or $) is used to override the DEFINT declaration. The DEFINT declaration must be read by the compiler before any statements in which the declared variables are

23

assigned or used. The compiler reads from beginning to end, without regard for execution path. You cannot avoid a DEFINT declaration by direction the execution path around it. DEFINT statements do not affect symbolic constants. See Also: DEFDBL DEFSNG DEFSTR

DEFSNG

Define Variable(s) as Single Precision

DEFSNG letter[-letter] [,letter [-letter]]... Declares one or more variables to be of type single precision. ---------------------------------------------------------------------Notes:

All variable names beginning with any of the specified letters (case-insensitive) will be single precision, unless a type-identifier character (%, #, or $) is used to override the DEFSNG declaration. The DEFSNG declaration must be read by the compiler before any statements in which the declared variables are assigned or used. The compiler reads from beginning to end, without regard for execution path. You cannot avoid a DEFSNG declaration by direction the execution path around it. DEFSNG statements do not affect symbolic constants.

See Also: DEFDBL DEFINT DEFSTR

DEFSTR

Define Variable(s) as String

DEFSTR letter[-letter] [,letter [-letter]]... Declares one or more variables to be of type string. ---------------------------------------------------------------------Notes:

All variable names beginning with any of the specified letters (case-insensitive) will be strings, unless a typeidentifier character (%, #, or !) is used to override the DEFSTR declaration. The DEFSTR declaration must be read by the compiler before any statements in which the declared variables are assigned or used. The compiler reads from beginning to end, without regard for execution path. You cannot avoid a DEFSTR declaration by direction the execution path around it. DEFSTR statements do not affect symbolic constants.

See Also: DEFDBL DEFINT DEFSNG

DIM

Dimension Array(s)

DIM [SHARED] variable(subscripts)[,variable(subscripts)]... Defines the maximum subscript numbers for and allocates storage for one or more arrays. SHARED

24

An optional attribute. Arrays DIMensioned in a main program as SHARED may be shared with all subprograms that are compiled with that main program.

---------------------------------------------------------------------Notes:

Arrays with a maximum subscript of 10 may be used without a DIM statement. Arrays with subscripts larger than 10 must be DIMensioned before they are used. The first element of an array is element 0, unless the OPTION BASE statement has been used to change the starting element from 0 to 1. Static arrays may not be redimensioned. Dynamic arrays may be redimensioned after an ERASE statement or by means of a REDIM statement. A DIM for a dynamic array is an executable statement and must appear after any COMMON statements. The compiler does not perform bounds checking on array usage unless the program is compiled with the /d (debug) option. The maximum number that can be DIMensioned in a DIM statement is 63.

See Also: ERASE OPTION BASE REDIM

DO

Begin Definition of DO/LOOP Loop

1. DO . . [statements] . . [EXIT DO] LOOP [{WHILE | UNTIL} expression] 2. DO [{WHILE | UNTIL} expression] . . [statements] . . [EXIT DO] LOOP Begins the definition of a DO/LOOP loop. expression

A numeric expression. Nonzero values are equivalent to TRUE, while zero values are equivalent to FALSE.

WHILE

Causes execution of the loop as long as expression is TRUE.

UNTIL

Causes execution of the loop as long as expression is FALSE.

EXIT DO LOOP

An optional means to escape from the loop before its termination. Terminates the loop construct.

----------------------------------------------------------------------Notes:

DO...LOOP is a general-purpose looping construct. The optional termination test may be supplied at either the beginning or the end. If no test is supplied, EXIT DO is the only way to break out of the loop.

See Also: FOR LOOP NEXT WEND WHILE

DRAW

Draw Object

DRAW string

25

Draws an object according to instructions specified as a string expression. string

A string expression containing commands in the BASIC graphics definition language.

Graphics Definition Language In the movement instructions below, n specifies a distance to move. The number of pixels moved is equal to n multiplied by the current scaling factor, which is set by the S command. Un

Move up.

Dn

Move down.

Ln

Move left.

Rn

Move right.

En

Move diagonally up and right.

Fn

Move diagonally down and right.

Gn

Move diagonally down and left.

Hn

Move diagonally up and left.

Mx,y

Move to coordinate x,y. If x is preceded by a + or -, the movement is relative to the last point referenced (LPR).

B

A prefix command. Next movement command moves but doesn't plot.

N

A prefix command. Next movement command moves, but returns immediately to previous point.

An

Set angle. n may be 0, for 0 degrees; 1, for 90 degrees; 2, for 180 degrees; or 3, for 270 degrees. Rotated figures are rescaled to adjust to the CGA's 4/3 aspect ratio.

TAn

Turn angle. n may range from -360 degrees to +360 degrees. Positive values cause counterclockwise rotation; negative values cause clockwise rotation.

Cn

Set color to n. The default color for medium-resolution is 3; high-resolution default color is 1. See PALETTE for a list of legal colors.

Sn

Set scale factor. n may range from 1 to 255. The scaling factor used is n/4. The default for n is 4.

Ppaint,boundary Fill figure color to paint, stopping at areas of color boundary. See PALETTE for a list of legal colors. "=" + VARPTR$(var) Get argument from variable. May be used to supply arguments to any of the foregoing commands. "X" + VARPTR$(stringvar) Execute command sequence stored in a string variable. This command allows you to call graphics-language subroutines. ------------------------------------------------------------------------Notes:

To get arguments or instructions from variables, you must use VARPTR$(var) or VARPTR$(stringvar). QuickBASIC does not support the =variable; and Xstringvar formulations available with the Interpreter. Spaces between or within instructions are insignificant. Semicolons may be used between commands to enhance readability. The drawing begins at the last point referenced (LPR) and

26

LPR is updated as the object is being drawn. See Also: PALETTE SCREEN (Statement) VARPTR$

END

Terminate Program

END Terminates execution of a program, closes all files opened by the program, and returns control to the operating system. ---------------------------------------------------------------------Notes:

END as the last (highest-numbered) instruction in a program is optional. END returns control to DOS.

See Also: STOP

ENVIRON

Modify Environment Table

ENVIRON stringexpr Adds a statement to or deletes a statement from the current environment table. stringexpr

A string expression of the form "name = parameter".

---------------------------------------------------------------------Notes:

If name already current setting does not exist, the environment

exists in the environment table, its is replaced with the new setting. If name the new statement is added at the end of table.

To delete an entry from the environment table, make parameter a semicolon (i.e. "name = ;"). parameter is case-sensitive. The new environment variable added, deleted, or modified by this procedure will only take effect for SHELLed copies of COMMAND.COM that are activated after this statement. After the program exits, the environment table will be exactly the same as before the program executed, no matter what changes were made with ENVIRON. See Also: ENVIRON$ SHELL

ENVIRON$

Environment Table Entry

s$ = ENVIRON$({parm | n}) Returns the value of a specified entry in the current environment table. parm n

A string expression specifying an environment parameter. An integer expression in the range 1 to 255 specifying the nth entry in the environment table.

---------------------------------------------------------------------Notes:

ENVIRON$ is case-sensitive, so if parm does not exactly match a name in the environment table, the function returns a null string. If the argument is given as n, then ENVIRON$ returns the nth entry in the table. Unless the table has been modified since bootup, the first entry will be COMSPEC, the second

27

will be PATH (if a PATH command has been issued), and the third will be PROMPT (if a PROMPT command has been issued). See Also: ENVIRON

EOF

End of File Status

y = EOF(filenum) Checks for end of file. filenum

The number under which the file was OPENed.

---------------------------------------------------------------------Notes:

If the end of the file has been reached, EOF returns -1 (true); otherwise, it returns 0 (false). If filenum refers to a random-access file, a -1 means the last GET statement did not read an entire record. If filenum refers to a communications file opened in binary mode, a -1 means the input queue is empty. If filenum refers to a communications file opened in ASCII mode, a -1 means a Ctrl-Z has been read.

ERASE

Reset Static Array or Deallocate Dynamic Array

ERASE arrayname[,arrayname]... Resets or deallocates one or more arrays. arrayname

The name of an array variable (do not include parentheses).

---------------------------------------------------------------------Notes:

ERASE resets all elements of a static numeric array to 0 and all elements of a static string array to null. ERASE deallocates storage for a dynamic array, allowing storage to be reallocated by means of DIM or REDIM. Static arrays may not be reDIMensioned.

See Also: CLEAR DIM REDIM $STATIC $DYNAMIC

ERDEV

Critical Error Code

y = ERDEV Returns the error status of a device error. The low-order byte will contain the INT 24h error code. The high-order byte will contain the bits 15, 14, 13, 3, 2, 1, and 0 of the device attribute word. ---------------------------------------------------------------------Notes:

ERDEV is a read-only variable.

See Also: ERDEV$

ERDEV$

Device Causing Critical Error

s$ = ERDEV$ Returns the name of the device that has caused an INT 24h (critical error). ----------------------------------------------------------------------

28

Notes:

If the device is eight-bit device ERDEV$ returns a drive letter and

a character device, ERDEV$ returns the name. If the device is a block device, two-character string consisting of the a colon.

ERDEV$ is a read-only variable. See Also: ERDEV

ERL

Line Number of Most Recent Error

y = ERL Returns the program line number at which the most recent error occurred. ---------------------------------------------------------------------Notes:

If an error occurs on an unnumbered program line, then ERL returns the last line number before the program line that caused the error. If no line numbers are used at all, ERL returns 0. If the error occurs in an unnumbered program line, ERL returns the last line number before the label.

See Also: ERR ERROR ON ERROR RESUME

ERR

Error Number

y = ERR Returns the error number of the most recent runtime error. ---------------------------------------------------------------------Notes:

If no error has occurred, ERR returns 0.

See Also: ERL ERROR ON ERROR RESUME

ERROR

Force Error

ERROR n Produces error number n. n

An integer expression in the range 0 to 255.

---------------------------------------------------------------------Notes:

If n is not one of BASIC's standard error numbers, and no ON ERROR routine is in use, ERROR n stops program execution and produces an "Unprintable error" error message. If an ON ERROR routine is in effect, an ERROR n statement is trapped in the normal way, whether or not the number is one of BASIC's error numbers. If you are using a nonstandard error number, Microsoft recommends that you use the highest available number, to maintain compatibility with future releases of QuickBASIC. This statement is provided as an aid in debugging errortrapping routines.

See Also: ERL ERR ON ERROR RESUME

29

EXIT

Exit Multiline Function, Loop, or Subprogram

EXIT {DEF | DO | FOR | SUB} Exits a multiline function definition, a DO loop, a FOR loop, or a subprogram. ---------------------------------------------------------------------Notes:

The construct definition is not ENDed by the EXIT statement. An END statement is still required. Premature exit from a nested DO or FOR loop transfers control to the immediately enclosing loop.

See Also: DEF FN DO FOR SUB...END SUB

EXP

Exponent (Natural)

y = EXP(numexpr) Returns e (the base of natural logarithms) to the power of numexpr. numexpr

A numeric expression less than or equal to 88.02969.

---------------------------------------------------------------------Notes:

If x is a double-precision variable or constant, EXP is calculated in double precision. Otherwise it is calculated in single precision. The value of e is approximately 2.718282.

See Also: LOG

FIELD

Allocate Space for Random File Variables

FIELD [#]filenum, fieldwidth AS stringvar [,fieldwidth AS stringvar]... Allocates storage for any number of string variables, each of specified character width, to be used in conjunction with a specified random file buffer. filenum fieldwidth stringvar

The number under which the file was OPENed. The number of character positions to be allotted to stringvar. A string variable to be used for random access.

---------------------------------------------------------------------Notes:

Once the random file has been FIELDed, data may be extracted from the random file buffer after a GET statement or placed into the buffer in preparation for a PUT statement. A string variable defined by means of the FIELD statement points to a specified position in the random file buffer. It should not thereafter be used as an INPUT variable or on the left side of an assignment statement. Doing either of these things will point the variable name into the string space and remove it from the file buffer. Multiple field definitions for a given random file buffer are permitted. Each new FIELD statement starts again at the first character position of the buffer, and all FIELD statements for a given random file are in effect simultaneously. All FIELD definitions are removed when a file is CLOSEd. QuickBASIC resets all FIELDed variables to null when the

30

associated file is CLOSEd or RESET. (In interpreted BASIC, such variables retain their last assigned values.) See Also: GET (File I/O) LSET PUT (File I/O) RSET

FILEATTR

a file I/O function that returns information about an open file (QuickBasic 4.5)

FILEATTR(filenumber,attribute) - filenumber is the number of an open file - attribute, a numeric expression that with a value of 1 or 2, indicates the type of information to return about the file (see Details ). Details: Argument filenumber

Description The number of an open file. This is the same number used in the OPEN statement. You can use a numeric expression as long as it evaluates to the number of an open file.

attribute

Indicates the type of information to return. When attribute is 1, FILEATTR returns a code indicating a file's mode (see below). When attribute is 2, FILEATTR returns the file's DOS file handle.

The table below lists the return values and corresponding file modes when the value of attribute is 1. Return Value 1 2 4 8 32

Mode INPUT OUTPUT RANDOM APPEND BINARY

Example: The following example opens two files and prints out the DOS file handles and modes returned by FILEATTR: OPEN "tempfile.dat" FOR APPEND AS #1 OPEN "tempfl2.dat" FOR RANDOM AS #2 PRINT "Number Handle Mode" PRINT TAB(2);1;TAB(10);FILEATTR(1,2);TAB(15);FILEATTR(1,1) PRINT TAB(2);2;TAB(10);FILEATTR(2,2);TAB(15);FILEATTR(2,1) END Sample Output Number Handle Mode 1 5 8 2 6 4 See Also: OPEN

FILES

Display File Directory

FILES [filespec] Displays a directory listing, including all filenames, the name of the directory, and the amount of free space. filespec

A string expression that follows DOS file naming conventions. Can contain the wild-card characters * and ?. Defaults to *.*.

----------------------------------------------------------------------

31

Notes:

If the filespec argument is omitted, FILES lists all the files in the current directory. No matter what the contents of filespec, the output of the FILES statement always includes a header consisting of the full pathname of the current directory.

FIX

Truncate to Integer

y = FIX(numexpr) Truncates, without rounding, any numeric expression to an integer. numexpr

A numeric expression.

See Also: CINT INT

FOR

Begin Definition of FOR/NEXT Loop

FOR counter = start TO end [STEP increment] . . [statements] . [EXIT FOR] NEXT [counter [,counter...]] Begins the definition of a FOR/NEXT loop. counter

start end increment

A numeric variable to be used as the loop counter. All numeric types are allowed, but the loop executes fastest if counter is an integer variable. A numeric expression; the starting value of counter. A numeric expression; the ending value of counter. A numeric expression; the value by which counter is incremented or decremented with each iteration of the loop. Defaults to +1.

---------------------------------------------------------------------Notes:

BASIC begins processing of the FOR/NEXT block by setting counter equal to start. Then, if increment is positive and counter is not greater than end, the statements between the FOR statement and the NEXT statement are executed. When the NEXT statement is encountered, counter is increased by increment, and the process is repeated. Execution passes to the statement following the NEXT statement if counter is greater than end. If increment is negative, execution of the FOR/NEXT loop is terminated whenever counter becomes less than end. If increment is 0, execution of the FOR/NEXT loop continues until Ctrl-Break is pressed (unless one of the repeated instructions itself increments counter). Note that changes made within the FOR/NEXT loop to counter affect the number of times the loop instructions are executed; changes made to start, end, and increment, however, do not have this effect. There must be one and only one NEXT statement for each FOR statement. Inclusion of counter in the NEXT statement is optional; if counter is omitted, its value is assumed to be that of counter in the most recent FOR statement. FOR/NEXT loops may be nested within one another. Each FOR must be given a unique counter value and each nested FOR must have its NEXT statement appear within the enclosing FOR-NEXT block.

32

Nested loops that have a common termination point may use a single NEXT statement with values of counter matching the values for each FOR statement. The loop is skipped completely if start is greater than end and increment is positive, or start is less than end and increment is negative. See Also: DO LOOP NEXT WEND WHILE

FRE

Available Memory

y = FRE({strexpr | numexpr}) Returns the number of bytes available in QuickBASIC's string space; optionally forces a defragmentation of the string space. strexpr

A dummy argument; the actual value is inconsequential. FRE(strexpr) causes QuickBASIC to clean house on its string data space, then report the amount of free space available.

numexpr

A dummy argument. If numexpr = -1, QuickBASIC reports the size in bytes of the largest free LNA (large numeric array) entry. If any other value is used, QuickBASIC omits the housecleaning step and reports the amount of free space available.

FREEFILE FREEFILE

a file I/O function that returns the next free BASIC file number

(QuickBasic 4.5)

You can use this function to avoid having SUB or FUNCTION procedures use file numbers that are already in use. Example: The example below uses FREEFILE to obtain a file number for opening a file: INPUT "Enter file name ", Filename$ Filenum = FREEFILE OPEN Filename$ FOR OUTPUT AS Filenum PRINT Filename$;" opened as File #"; Filenum Sample Output Enter file name: DATA.DAT DATA.DAT opened as File # 1 See Also: OPEN

FUNCTION...END FUNCTION

(QuickBasic 4.5)

a non-executable statement that declares the name, the parameters, and the code that form the body of a FUNCTION procedure FUNCTION name [(parameterlist)][STATIC] [statements] name = expression [statements] END FUNCTION - name, which follows the same rules as are used for naming BASIC variables, determines the data type the function returns - (parameterlist) is one or more variables, separated by commas, that will be passed to the function when it is called - expression is the return value of the function

33

- Use of the keyword STATIC is a Details: Part name

Detail

Description The name of the function. FUNCTION names follow the same rules as BASIC variable names and can include a type-declaration character (%, &, !, #, or $). Note that the type of the name determines the type of value the function returns. For example, to create a function that returns a string, you would include a dollar sign in the name or give it a name defined as a string name by a DEFSTR statement.

parameterlist

The list of variables, separated by commas, passed to the FUNCTION. The parameters are passed by reference, so any change to a parameter's value inside the function changes its value in the calling program.

STATIC

Indicates that the function's local variables are to be saved between calls. Without STATIC, the local variables are allocated each time the function is invoked, and the variables' values are lost when the function returns to the calling program. The STATIC attribute does not affect variables that are used in a FUNCTION but declared outside the FUNCTION in DIM or COMMON statements using the SHARED attribute.

expression

The return value of the function. A FUNCTION returns a value by assigning a value to the function name. If no value is assigned to the FUNCTION name, the FUNCTION returns a default value: a numeric function returns a value of zero, and a string function returns the null string ("").

A parameterlist has the following syntax: variable[( )][AS type][,variable[()][AS type]] A variable is any valid BASIC variable. The optional type can be either INTEGER, LONG, SINGLE, DOUBLE, STRING, or a user-defined type. Earlier versions of BASIC required the number of dimensions in parentheses after an array name. The number of dimensions is no longer required. Only the parentheses are required to indicate the parameter is an array. For example, the following statement indicates that both Keywords$ and KeywordTypes are arrays: FUNCTION ParseLine(Keywords$(),KeywordTypes()) A FUNCTION procedure is like a SUB procedure: it can accept parameters, perform a series of statements, and change the values of its parameters. Unlike a SUB, a FUNCTION is used in an expression in the same manner as a BASIC intrinsic function. Like SUB procedures, FUNCTION procedures use local variables. Any variable not in the parameter list is local to the FUNCTION unless it is declared as a shared variable in a SHARED statement, or unless the variable appears in a DIM or COMMON statement with the SHARED attribute. To return a value from a function, assign the value to the function name. For example, in a function named BinarySearch, you might assign the value of the constant FALSE to the name to indicate the value was not found: FUNCTION BinarySearch(...) CONST FALSE=0 . . . ' Value not found. Return a value of FALSE. IF Lower>Upper THEN

34

BinarySearch=FALSE EXIT FUNCTION END IF

. . . END FUNCTION

Using the STATIC keyword slightly increases execution speed. STATIC is not usually used with recursive FUNCTION procedures. See the examples below. The EXIT FUNCTION statement provides an alternative exit from a FUNCTION. See the EXIT statement. Because BASIC may rearrange arithmetic expressions to attain greater efficiency, avoid using FUNCTION procedures that change program variables in arithmetic expressions. Also avoid using FUNCTION procedures that perform I/O in I/O statements. QuickBASIC FUNCTION procedures are recursive--they can call themselves to perform a given task. See the second example below. Examples: FUNC_EX.BAS is a program file in the subdirectory ADVR_EX that illustrates the use of the FUNCTION statement. To look at the program in the View window and, optionally, to run the program, load FUNC_EX.BAS using the File menu's Open Program command. The program uses a recursive function (a function that calls itself) to find the length of a string. See Also: DECLARE STATIC statement DEF FN SUB

GET

Read Random File into Buffer

File I/O

GET [#]filenum [,recnum] Transfers a record from a specified random access file into the associated random file buffer. filenum recnum

The number under which the file was OPENed. A numeric expression in the range 1 to 16,777,215, specifying the number of the record to be transferred. Defaults to the next record, or record 1 (if no previous record has been read).

---------------------------------------------------------------------Notes:

After a record has been transferred from disk to the random file buffer, its data may be accessed via INPUT #, LINE INPUT #, or references to variables defined in a FIELD statement. If the file associated with filenum is a communications file, then recnum specifies the number of bytes to read.

See Also: OPEN PUT (File I/O)

GET

Read Points from Screen

Graphics

GET (x1,y1)-(x2,y2),arrayname Copies attributes from a specified rectangle within the screen buffer into a specified array. x1,y1

Upper left corner of the rectangle to be copied.

x2,y2

Lower right corner of the rectangle to be copied.

arrayname

The name of a numeric array.

35

---------------------------------------------------------------------Notes:

To determine how large the array must be, use the following formula: 4+INT(((x2-x1+1)*bitsperpixel+7)/8)*((y2-y1)+1) where bitsperpixel relates to screen mode as follows: Mode SCREEN SCREEN SCREEN SCREEN SCREEN

Bitsperpixel 2 1 4 4 2 (EGA memory = 64K) 4 (EGA memory > 64K) SCREEN 10 2 1 2 7 8 9

The amount of memory allocated per array element is as follows: Integer: Single-precision: Double-precision:

2 bytes per element 4 bytes per element 8 bytes per element

The first two bytes returned by the GET statement indicate the horizontal dimension of the screen rectangle, in bits; the second two bytes indicate the vertical dimension. The remainder of the data returned by GET are the attributes for each pixel in the rectangle. See Also: PUT (Graphics)

GOSUB

Execute Subroutine

GOSUB {linenum1 | linelabel1} . . [statements] . RETURN [{linenum2 | linelabel2}] Causes program execution to branch to the specified line number or line label; when the RETURN statement is encountered, execution branches to the statement immediately following the most recent GOSUB statement--or to a specified line number or line label. ---------------------------------------------------------------------Notes:

If RETURN linenumber2 or linelabel2 is used, the return must be made to a statement in the calling routine--i.e., the main program or the subroutine from which the current subroutine was called. Subroutines may be called any number of times, from any number of different points in a program. They may be nested, and they may have multiple RETURN statements.

See Also: DEF FN RETURN SUB...END SUB

GOTO

Unconditional Branch

GOTO {linenum | linelabel} Causes program execution to branch to a specified line. ---------------------------------------------------------------------Notes:

See Also: EXIT

36

The target of the GOTO must be at the same program level. That is, you cannot GOTO a subprogram, subroutine, or multiline function definition.

HEX$

Hexadecimal Value, as String

s$ = HEX$(numexpr) Returns, as a string, the hexadecimal value of its argument. -------------------------------------------------------------------------numexpr Notes:

A numeric expression in the range -32768 to 32767. If numexpr is negative, HEX$ returns a two's complement value. Any fractional portion of numexpr is rounded before creation of the string.

See Also: OCT$

IF

Conditional Branch

1. Block syntax IF expression THEN statement1 [statement2] . . . [ELSEIF expression THEN statement10 [statement11] . . . [ELSE statement15 [statement16]] . . . ENDIF 2. Single-line syntax (three variants) IF expression THEN statement1 [ELSE statement2] Causes QuickBASIC to make a decision based on the value of an expression. expression

A numeric expression; 0 is equivalent to FALSE, while all other values are equivalent to TRUE.

statement

Any legal statement. The single-line mode's statement can be just a line number or line label. This is equivalent to a GOTO statement with the specified label.

---------------------------------------------------------------------Notes:

Each expression in the IF/ELSEIF construct is tested in order. As soon as an expression is found to be TRUE, then its corresponding statements are executed. If no expressions are TRUE, then the statements following the ELSE keyword are executed. If ELSE is not specified, then execution continues with the statement following the ENDIF or the single-line IF statement. The only difference between QuickBASIC's one-line construct and that of interpreted BASIC is that QuickBASIC allows the use of labels as well as numbered lines. In the block construct, the following rules apply:

37

IF, ELSE, ELSEIF, and ENDIF must all be the first keywords on their respective lines. THEN must be the last keyword on its line; if anything other than a comment follows on the same line with THEN, QuickBASIC thinks it's reading a single-line IF/THEN/ELSE construct. IF blocks may be nested. Do not put a colon before the ELSE keyword. See Also: ON...GOTO ON...GOSUB SELECT

INKEY$

Most Recent Character at Keyboard

s$ = INKEY$ Returns, without echo, the character most recently entered into the keyboard buffer, or a null string if no character is pending. ---------------------------------------------------------------------Notes:

The system variable INKEY$ must be assigned to an ordinary string variable before it can be used in a BASIC statement. If the most recent character is one of the 255 IBM ASCII characters, INKEY$ returns that character only. If the most recent character is a "special" character--a function key or a cursor keypress, for example--INKEY$ returns a two-byte string; the first byte is 00h, and the second byte is the extended code corresponding to the key pressed. If a key defined with the KEY statement is pressed, then INKEY$ will return with the sequence of characters mapped to the key as if the characters had been entered independently. Cursor control keys, such as TAB and BACKSPACE, will be returned to INKEY$ without processing (in "raw" mode). The following keys have special functions and will not be returned through INKEY$: Ctrl-Break Ctrl-Alt-Del Ctrl-NumLock Shift-PrtScrn

Terminates the program unless the Keyboard break option in the Options menu was turned off. Resets the computer system. Suspends the system. Prints the current screen display.

See Also: INPUT INPUT # INPUT$ LINE INPUT LINE INPUT # Keyboard Codes

INP

Read from an I/O Port

y = INP(port) Returns a byte from a specified I/O port. port

A numeric expression in the range 0 to 65535, specifying the port to read.

See Also: OUT

INPUT

Get Input from Keyboard

INPUT[;]["prompt" {; | ,}] variable [,variable]... Assigns input from the keyboard to one or more string or numeric

38

variables. ;

prompt variable

If a semicolon is included directly after the INPUT keyword, QuickBASIC does not issue a carriage return/line feed after receiving the user's input. A string constant supplying a prompt to guide the user. The name of a variable (string or numeric) that will receive input.

---------------------------------------------------------------------Notes:

A prompt may be included in the INPUT statement to guide the user; if included, it must be a string constant, enclosed within quote marks. If a prompt is included, it must be followed by either a semicolon or a comma (outside the quotes, before the first variable name). If it's followed by a semicolon, QuickBASIC displays a question mark after the prompt string. If it's followed by a comma, QuickBASIC suppresses the question mark. If no prompt is included, QuickBASIC displays a question mark. If more than one variable is included in the INPUT statement, the user must enter values for all variables, separated by commas. If only one variable is included in the INPUT statement, the user has the option of simply pressing the Enter key; QuickBASIC interprets that action as 0 (for numeric variables) or null (for string variables). If the user enters too few or too many values in response to an INPUT statement, QuickBASIC displays a ?Redo from Start error message; no values are assigned to variables until satisfactory input is received. If the user enters a comma in response to an INPUT statement, BASIC displays a ?Redo from Start error message. You can avoid this irritation by using LINE INPUT, instead of INPUT. Input for a string variable need not be enclosed in quote marks. String input that is enclosed within quotes is handled as though it were not (QuickBASIC ignores the quotes). Input to a numeric variable must be numeric. Editing keystrokes are active during response to INPUT. To receive such keystrokes as part of an input string, use INKEY$.

See Also: INKEY$ INPUT # INPUT$ LINE INPUT LINE INPUT #

INPUT #

Get Input from Sequential File or Device

INPUT #filenum, variable [,variable]... Receives input from a sequential file or device and assigns it to one or more numeric or string variables. filenum

variable

The number under which the input file was OPENed. It may refer to a disk file, a communications file, or the keyboard (KYBD:). The name of a variable (string or numeric) that will receive input.

----------------------------------------------------------------------

39

Notes:

The input data must match in type the variable(s) in the INPUT # statement. String input need not be enclosed within quote marks, unless it contains one or more line feeds or carriage returns or a significant quote mark or comma. When receiving string input, QuickBASIC looks for the first character other than a space, line feed, or carriage return. If that character is a quote mark, QuickBASIC considers the string to be everything from the character following the quote mark up to the next quote mark. If the first character is not a quote mark, QuickBASIC terminates the string when it encounters a line feed, a carriage return, or a comma--or when it has received 255 characters. When receiving numeric input, QuickBASIC ignores leading carriage returns, line feeds, and spaces, and it terminates the input when it encounters a carriage return, a line feed, or a comma.

See Also: INKEY$ INPUT INPUT$ LINE INPUT LINE INPUT #

INPUT$

Read Specified Number of Characters

INPUT$(n [,[#]filenum]) Returns a specified number of characters from a specified sequential file or device, or from the keyboard. n filenum

The number of characters to be read. Must be in the range 1 to 255. The number under which the input file was OPENed. If omitted, the characters are read from the standard input device (the keyboard, by default). Characters input from the keyboard are not echoed to the screen.

----------------------------------------------------------------------Notes:

The INPUT$ function terminates when the specified number of characters have been received. It is not necessary to press Enter. INPUT$ doesn't allow the inputting of certain special key combinations (for example, function and cursor keys). These keys will return CHR$(0). Use INKEY$ to get around this limitation.

See Also: INKEY$ INPUT INPUT # LINE INPUT LINE INPUT #

INSTR

Find Substring

INSTR([start,] stringexp1,stringexp2) Returns the character position within a string at which a substring is found. stringexp1

The string to be scanned.

stringexp2

The substring to be searched for.

start

A numeric expression in the range 1 to 255; an optional offset from which to start searching.

---------------------------------------------------------------------Notes:

40

If start is specified, BASIC begins searching at the character at offset start (The first character in the string is at offset 1). Whether or not start is specified, INSTR returns the position at which stringexp2 is found-relative to the first character in the string (not to

start). If stringexp1 is null or if start is greater than LEN(stringexp1), INSTR returns 0. If stringexp2 is null, then INSTR returns 1 (if start was specified, then INSTR returns start.

INT

Next Lower Integer

y = INT(numexpr) Returns the largest integer value less than its argument. numexpr

A numeric expression.

---------------------------------------------------------------------Notes:

INT rounds everything down to the next lowest integer. Compare this with CINT, which rounds in the conventional manner, and FIX, which simply truncates.

See Also: CINT FIX

IOCTL

Send Control String to Device Driver

IOCTL[#]filenum,stringexpr Sends a command string of up to 255 characters to a specified device driver. filenum stringexpr

The number under which the device driver was OPENed. A string expression of up to 255 characters; can include multiple commands separated by semicolons.

See Also: IOCTL$

IOCTL$

Read Control String from Device Driver

s$ = IOCTL$([#]filenum) Reads a control string from a specified device driver. filenum

The number under which the device driver was OPENed.

See Also: IOCTL

KEY

Set or Display Soft Keys

KEY {ON | OFF | LIST} KEY n, strexpr KEY n, CHR$(KBflag) + CHR$(scancode) Controls the display and contents of the function keys F1 through F10; allows trapping of any scan code in any shift state. ON

KEY ON enables the display, on line 25, of current function key settings. Only the first six character assigned to each function key are displayed. If the screen is in an 80-column display mode, all ten function keys are displayed; if it's in a 40-column mode, the first five are displayed. KEY ON is the default setting in BASIC.

OFF

KEY OFF removes the function key display from line 25, making line 25 available for other purposes. With KEY OFF in effect, a LOCATE 25,n can be used to display other text at the bottom of the screen. Line 25 does not scroll, but it is erased by a CLS statement.

41

LIST n, strexpr

KEY LIST displays the current soft key definitions on screen. KEY n, strexpr assigns the string expression strexpr to function key n. n is a numeric expression in the range 1 to 10. Only the first 15 characters of strexpr are significant. A null string strexpr deactivates the associated function key.

n, CHR$(KBflag) + CHR$(scancode) The statement KEY n, CHR$(KBflag) + CHR$(scancode) enables your program to trap specified Ctrl keys, Alt keys, and Shifted keys. n is a numeric expression in the range 15 to 20 (up to six traps may be in effect at once). KBflag, which must be expressed in hexadecimal, specifies the shift state of the key to be trapped, and scancode specifies which alphanumeric key is to be trapped. The following options are available for KBflag: &H40 &H20 &H08 &H04 &H02 &H01 &H00

Caps Lock active Num Lock active Alt key pressed Ctrl key pressed Left Shift key pressed Right Shift key pressed Caps Lock inactive, Num Lock inactive

These options may be used in additive fashion, to trap combinations of shift states. For example, CHR$(&H08+&H02+&H01) would catch the combination of the Alt key with either (or both) Shift keys. Trapped keys do not enter the BIOS keyboard buffer. Therefore, if either Ctrl-Break or Ctrl-Alt-Del is trapped, there will be no way (other than powering down) to break out of an infinite loop. See Also: KEY(n) ON KEY

KEY(n)

Enable/Disable Key Trapping

KEY(n) {ON | OFF | STOP} Enables or disables the trapping of a specified key via ON KEY(n). n

A numeric expression in the range 1 to 20, specifying the key to trap, as follows: 1-10,30,31 11 12 13 14 15-25

ON

OFF STOP

Function keys F1 through F10, F11, F12 Cursor Up Cursor Left Cursor Right Cursor Down Keys defined via KEY n, CHR$(KBflag) + CHR$(scancode)

KEY(n) ON activates trapping. If an ON KEY(n) GOSUB statement has been executed, QuickBASIC checks before executing each statement to see if the specified key has been pressed. If it has, QuickBASIC performs the indicated GOSUB. KEY(n) OFF deactivates trapping. KEY(n) STOP also deactivates trapping, but QuickBASIC continues checking to see if the specified key has been pressed. If it has been pressed, a subsequent KEY(n) ON results in an immediate trap (provided an ON KEY(n) statement with a nonzero line number has been executed).

----------------------------------------------------------------------Notes:

42

If the "Checking Between Statements" option is in effect,

QB checks for communication activity after each statement. If the "Event Trapping" option is selected, QB checks after each new program line. If neither option is selected, no trapping takes place. For command-line compilation, /v enables checking after each statement, and /w enables checking after each new line. If neither switch is used, no trapping takes place. See Also: ON KEY

KILL

Delete File(s)

KILL filespec Deletes one or more files from disk. filespec

A string expression that follows DOS file naming conventions.

----------------------------------------------------------------------Notes:

Currently open files may not be deleted via KILL. This command is equivalent to DOS's DEL (ERASE) command.

See Also: RMDIR

LBOUND

Lower Bound of Array Dimension

LBOUND(array[,dimension]) Returns the lowest subscript for a given dimension of a given array. array dimension

The name of an array. The number of a dimension. The first dimension of an array is 1, the second is 2, and so on. For one-dimensional arrays, this argument can be omitted.

See Also: UBOUND

LCASE$ a string processing function that returns a string expression with all letters in lower-case (QuickBasic 4.5)

LCASE$(stringexpression) - stringexpression may be a string constant, string variable, or string expression. It may refer to a fixed- or variable-length string. The LCASE$ function takes a string variable, string constant, or string expression as its single argument. LCASE$ works with both variable- and fixed-length strings. LCASE$ and UCASE$ are helpful in string comparison operations where tests need to be case insensitive. Example: This example converts uppercase characters in a string to lowercase. ' Program to convert to lowercase. CLS ' Clear screen READ Word$ PRINT LCASE$(Word$); DATA "THIS IS THE STRING in lower case."

43

Sample Output this is the string in lower case. See Also: UCASE$

LEFT$

Substring at Left

s$ = LEFT$(stringexpr,n) Returns the leftmost n characters of a string. stringexpr n

A string expression. A numeric expression in the range 0 to 32767.

---------------------------------------------------------------------Notes:

If n is larger than LEN(stringepxr), LEFT$ returns the entire string. If n is 0, LEFT$ returns a null string.

See Also: MID$ (Function) RIGHT$

LEN

Length of String

y = LEN(stringexpr) Returns the number of characters in a string, including blanks and nonprinting characters. stringexpr

LET

A string expression.

Assignment

[LET] variable = expression Assigns the value of an expression to a variable. variable expression

A valid variable name. The value assigned to variable. expression and variable must match in type.

---------------------------------------------------------------------Notes:

LINE

The keyword LET is optional.

Draw Line or Box

LINE [[STEP] (x1,y1)] - [STEP] (x2,y2) [,[color] [,B[F]]] [,style] Draws a line or a box at specified coordinates, in a specified color. STEP

44

If included, coordinates are relative to last graphics point referenced. If omitted, coordinates are absolute.

x1,y1 x2,y2

If ,B option is used, x1,y1 and x2,y2 are corner coordinates of a rectangular box; otherwise x1,y1 and x2,y2 are end points of a line.

color

Specifies color to use . Defaults to 3 in medium resolution, 1 in high resolution.

B

Tells BASIC to draw a rectangular box instead of a line.

F

Tells BASIC to fill the box.

style

Allows you to draw a broken (dashed) line or box (see below).

---------------------------------------------------------------------Notes:

If STEP is included with x2,y2 but not x1,y1, then x2 and y2 are measured relative to the absolute coordinate pair (x1,y1). QuickBASIC treats style as a 16-bit integer mask, plotting the 1 bits and skipping the 0 bits, and repeating the pattern as many times as necessary to create the specified line. Thus a style value of 43690 (AAAAh, 1010101010101010b) would produce an evenly dotted line or box, with every other pixel plotted. Note that QuickBASIC ignores the "off" pixels; it does not plot them in the background color.

LINE INPUT

Read Line from Keyboard, Ignoring Delimiters

LINE INPUT[;]["prompt";] stringvar Assigns a line of keyboard input (up to 255 characters) to a string variable. ;

prompt stringvar

If a semicolon is included directly after the INPUT keyword, QuickBASIC does not issue a carriage return/line feed after receiving the user's input. A string constant supplying a prompt to guide the user. The name of a string variable that will receive input.

---------------------------------------------------------------------Notes:

LINE INPUT does not automatically display a question mark. If you want a question mark, include it within a prompt string. Unlike INPUT, LINE INPUT ignores all delimiters. Everything entered at the keyboard, including quote marks and commas, is treated as part of the input string.

See Also: INKEY$ INPUT$ INPUT INPUT # LINE INPUT #

LINE INPUT#

Read Line from File, Ignoring Delimiters

LINE INPUT # filenum, stringvar Assigns a line of input (up to 255 characters) from a sequential file or device to a string variable. filenum stringvar

The number under which the file was opened. The name of a string variable that will receive input.

---------------------------------------------------------------------Notes:

LINE INPUT # treats all commas and quote marks as part of the input string. Input is terminated by a carriage return-line feed pair (the carriage return and line feed are included in the string variable assignment).

See Also: INKEY$ INPUT$ INPUT INPUT # LINE INPUT

LOC

Current File Position

y = LOC(filenum) Returns the record number last read from or written to a specified (open) file.

45

filenum

The number under which the file was OPENed.

---------------------------------------------------------------------Notes:

When a sequential file is opened for input, the first sector is automatically read, so LOC(filenum) for a newly opened sequential file returns 1. LOC(filenum) for a sequential file opened for OUTPUT or APPEND returns the current byte position divided by 128. If filenum specifies a communications file, LOC returns the number of characters waiting in the communications buffer. If that number is larger than 255, LOC returns 255.

LOCATE

Position the Cursor

LOCATE [row][,[col][,[cursor][,[start][,stop]]]] Sets the size and position of the cursor. row

A numeric expression in the range 1 to 25. Sets the row position of the cursor.

col

A numeric expression in the range 1 to 40 or 1 to 80. Sets the column position of the cursor.

cursor start stop

A numeric expression. If 1, the cursor is visible; if 0, the cursor is invisible. A numeric expression in the range 0 to 31. Sets the starting scan line for the cursor. A numeric expression in the range 0 to 31. Sets the ending scan line for the cursor. If start is specified and stop is not, stop assumes the value of start.

---------------------------------------------------------------------Notes:

Cursor scan lines are numbered from 0 (top) to 7 (CGA) or 13 (MDA). If stop is less than start, a two-part (wraparound) cursor results. If the softkey display on line 25 has been turned off (via KEY OFF), you may write to line 25 by means of LOCATE. Line 25 does not scroll in any case. Any argument to LOCATE may be omitted. Omitted arguments retain former values.

See Also: CSRLIN POS

LOCK

Control File or Record Access

LOCK [#] filenum [,{record | [start] TO end}] . . [statements] . UNLOCK [#] filenum [,{record | [start] TO end}] Make a specified record range or an entire file inaccessible to other users. filenum record start end

46

The number under which the file was OPENed. The number of a record to be LOCKed or UNLOCKed. The number of the first record to be LOCKed or UNLOCKed. The number of the last record to be LOCKed or UNLOCKed.

----------------------------------------------------------------------Notes:

If the file specified by filenum has been opened for random access, you may lock either a single record number (with the record argument) or a range of record numbers. If you specify a range and omit the start argument, all records from the beginning of the file to end are locked. If the file specified by filenum was opened for sequential input or output, the entire file is locked. LOCK requires DOS 3.0 or later and SHARE.EXE. It is important to UNLOCK all LOCKed records before closing the file.

LOF

Length of File

y = LOF(filenum) Returns the length, in bytes, of a specified file. filenum

The number under which the file was OPENed.

---------------------------------------------------------------------Notes:

LOG

If filenum specifies a communications file, LOF returns the amount of free space in the communications buffer.

Natural Logarithm

y = LOG(n) Returns the natural logarithm of a number. n

A numeric expression greater than 0.

----------------------------------------------------------------------Notes:

If the argument is a double-precision value, LOG is calculated in double precision; otherwise, it is calculated in single precision.

See Also: EXP

LOOP

End Definition of DO/LOOP Loop

1. DO . . [statements] . . [EXIT DO] LOOP [{WHILE | UNTIL} expression] 2. DO [{WHILE | UNTIL} expression] . . [statements] . . [EXIT DO] LOOP Ends the definition of a DO/LOOP loop. expression WHILE

A numeric expression. Nonzero values are equivalent to TRUE, while zero values are equivalent to FALSE. Causes execution of the loop as long as expression is TRUE.

47

UNTIL EXIT DO LOOP

Causes execution of the loop as long as expression is FALSE. An optional means to escape from the loop before its termination. Terminates the loop construct.

----------------------------------------------------------------------Notes:

DO...LOOP is a general-purpose looping construct. The optional termination test may be supplied at either the beginning or the end. If no test is supplied, EXIT DO is the only way to break out of the loop.

See Also: DO FOR NEXT WEND WHILE

LPOS

Current Position of Print Head

y = LPOS(n) Returns the position of the print head within the printer buffer. n

Specifies the printer. The following values are allowed: 1 2 3

LPT1: LPT2: LPT3:

See Also: POS

LPRINT

Output to LPT1:

LPRINT [exprlist] [; | ,] Prints one or more numeric or string expressions at LPT1:. exprlist

;

Numeric and/or string expressions to print. Each expression must be separated from the one after it by either a comma or a semicolon. If included at the end of the statement, suppresses the usual carriage return and line feed.

---------------------------------------------------------------------Notes:

LPRINT with no argument sends a carriage return-line feed pair. QuickBASIC divides the output field into zones of 14 character positions. If an expression is followed by a comma, QuickBASIC prints the next expression at the beginning of the next zone. If an expression is followed by a semicolon or space character, QuickBASIC prints the next expression directly after the previous one. If the last expression in the list to be displayed is followed by a comma, a semicolon, SPC, or TAB, QuickBASIC spaces appropriately and suppresses the carriage returnline feed pair. Otherwise, QuickBASIC issues a carriage return and line feed after executing an LPRINT statement. QuickBASIC assumes a maximum line length of 80 characters, unless a different value has been specified by means of a WIDTH "LPT1:" statement. QuickBASIC sends a carriage return-line feed pair when the maximum line length has been reached. Therefore, for example, if you LPRINT an 80character string (and do not follow the string expression with a semicolon), you will get two carriage return-line feed pairs.

See Also: PRINT

48

LPRINT USING

Formatted Output to LPT1:

LPRINT USING formatstr; exprlist [; | ,] Prints one or more string or numeric expressions, in a specified format, at LPT1:. formatstr

A string variable or constant specifying the format in which the data is to be printed (see below).

exprlist

Numeric and/or string expressions to print. Each expression must be separated from the one after it by either a comma or a semicolon.

;

If included at the end of the statement, suppresses the usual carriage return and line feed.

Formatting options: The following symbols may be used in formatstr: Symbol

\

Meaning

!

Print only the first character of a string expression.

\

Print only the first n characters of a string expression, where n is the number of spaces between the two backslashes. If n is larger than the number of characters in the string expression, BASIC pads the string expression on the right with space characters.

&

Print a string expression without reformatting it.

.

Specifies the position of the decimal point in a numeric expression. A place-holder. If the numeric expression has more digits to the right of the decimal point than the format string has #s, BASIC rounds. If the numeric expression has more digits to the left of the decimal point than the format string has #s, BASIC prints all the digits to the left of the decimal point and also prints a percent sign (%) to the left of the number. If the numeric expression has fewer digits to the left of the decimal point than the format string has #s, BASIC right-justifies the number; that is, it pads the number on the left with spaces. (But if there are any #s to the left of the decimal point in the format string, QuickBASIC always prints at least one digit--a 0 if necessary--to the left of the decimal point.)

#

+

Print a plus or minus sign, as appropriate, to the left of the number. The sign is always printed immediately to the left of the number.

-

Print a minus sign immediately to the right of a negative number (the minus sign should appear after the place holders in the format string).

$$

Print a dollar sign immediately to the left of the number. The double dollar sign also acts as a place holder for two additional digits to the left of the decimal point, one of which is the dollar sign itself. The dollar sign cannot be prefixed to a number printed in exponential format.

**

Fill any leading spaces with asterisks. The double asterisk also acts as a place holder for two additional digits to the left of the decimal point.

**$

Print a dollar sign immediately to the left of the number, and fill any remaining leading spaces with asterisks. The combination of two asterisks and a dollar sign also acts as a place holder for three additional digits, one of which is the dollar sign.

49

^^^^

Print a number in exponential format. The four carets should appear after all place holders in the format string.

_

Print next character as a literal. The combination _#, for example, allows you to include a number sign as a literal in your numeric format.

[other]

Characters other than the foregoing may be included as literals in the format string. Thus, for example, a single dollar sign may be positioned to the left of a series of place holders (#s) to achieve vertically aligned dollar signs, and space characters may be placed at the right side of the format string to achieve horizontal separation between a series of numbers.

---------------------------------------------------------------------Notes:

QuickBASIC sends a carriage return-line feed pair after the last expression to be printed, unless that expression is followed by a semicolon. QuickBASIC assumes a maximum line length of unless a different value has been specified WIDTH "LPT1:" statement. QuickBASIC sends a return-line feed pair when the maximum line been reached.

80 characters, by means of a carriage length has

Double-precision numbers in IEEE format may have threedigit exponents. To print numbers with three-digit exponents, use five carets instead of four.

LSET

Left-Justify Data in Field Variable

LSET fieldvar = stringexpr Left-justifies string data in a specified field of the random buffer, in preparation for a PUT statement. Or left-justifies string data in an ordinary string variable. fieldvar stringexpr

A valid string variable name; specifies the variable into which stringexpr is to be left-justified. A string expression.

---------------------------------------------------------------------Notes:

If LEN(stringexpr) is less than LEN(fieldvar), fieldvar is padded on the right with space characters.

See Also: MKD$ MKI$ MKS$ PUT (File I/O) RSET

LTRIM$ a function that returns a copy of a string with leading spaces removed (QuickBasic 4.5)

LTRIM$(stringexpression) The stringexpression can be any string expression. Example: This example copies a file to a new file, removing all leading and trailing spaces. ----- Note ----To run this example, you must supply the name of an existing text file. ---------------CLS ' Clear screen ' Get the file names. INPUT "Enter input file name:", InFile$ INPUT "Enter output file name:", OutFile$

50

OPEN InFile$ FOR INPUT AS #1 OPEN OutFile$ FOR OUTPUT AS #2 ' Read, trim, and write each line. DO WHILE NOT EOF(1) LINE INPUT #1, LineIn$ ' Remove leading and trailing blanks. LineIn$ = LTRIM$(RTRIM$(LineIn$)) PRINT #2, LineIn$ LOOP CLOSE #1, #2 END See Also: RTRIM$

MID$

Substring in Middle

Function

s$ = MID$(stringexpr,n[,length]) Returns a specified number of characters from a specified string, beginning at a specified character position. stringexpr n

length

A string expression. A numeric expression in the range 1 to 32767;, specifies the character position from which the substring is to be extracted. A numeric expression in the range 0 to 32767; specifies the number of characters to return.

---------------------------------------------------------------------Notes:

If length is omitted, MID$ returns all the characters in the string beginning at character n. MID$ may also be used as a statement.

See Also: LEFT$ MID$ (Statement) RIGHT$

MID$

Assign Substring

Statement

MID$(stringvar,n[,length]) = stringexpr Assigns all or some of a string expression to a string variable, beginning at a specified character position within the string variable. stringvar

The string variable whose characters will be replaced.

n

A numeric expression in the range 1 to 255, specifying the position within stringvar where the character replacement is to begin.

length

A numeric expression in the range 0 to 255, specifying the number of characters from stringexpr that will be used. If length is omitted, all of stringexpr is used.

stringexpr

The string expression supplying replacement characters for stringvar.

---------------------------------------------------------------------Notes:

In the syntax shown above, the characters in stringexpr replace length characters in stringvar, beginning at character n. In no case will the length of stringvar increase as a result of a MID$ statement. For example, if stringvar is seven characters long, and n is 3 and length is 6, only

51

the first five characters of stringexpr will be assigned to stringvar. See Also: MID$ (Function)

MKD$

Convert Double-Precision to String

s$ = MKD$(doubleexpr) Converts a double-precision expression into an 8-byte string, so that it may be LSET or RSET into a random file buffer. doubleexpr

A double-precision expression.

See Also: CVD CVI CVS MKI$ MKS$

MKDIR

Create Subdirectory

MKDIR pathname Creates a new subdirectory. pathname

A string expression, of 128 or fewer characters, that follows DOS path naming conventions.

See Also: CHDIR RMDIR

MKDMBF$

IEEE Double-Precision to MBF String

QB87 only

MKDMBF$(doubleexpr) Converts a IEEE-format double-precision expression into an 8-byte Microsoft Binary Format string, so that it may be LSET or RSET into a random file buffer. doubleexpr

MKI$

A double-precision expression.

Convert Integer to String

s$ = MKI$(intexpr) Converts an integer expression into a 2-byte string, so that it may be LSET or RSET into a random file buffer. intexpr

An integer expression.

See Also: CVD CVI CVS MKD$ MKS$

MKS$

Convert Single-Precision to String

MKS$(singleexpr) Converts a single-precision expression into a 4-byte string, so that it may be LSET or RSET into a random file buffer. singleexpr

A single-precision expression.

See Also: CVD CVI CVS MKD$ MKI$

MKSMBF$

IEEE Single-Precision to MBF String

QB87 only

MKDMBF$(singleexpr) Converts a IEEE-format double-precision expression into an 8-byte Microsoft Binary Format string, so that it may be LSET or RSET into a random file buffer.

52

singleexpr

NAME

A single-precision expression.

Rename File

NAME oldname AS newname Renames a disk file. oldname

A string expression following the DOS file-naming conventions. Must name an existing file.

newname

A string expression following the DOS file-naming conventions. May not name an existing file.

----------------------------------------------------------------------Notes:

NEXT

A file may be moved from one directory to another as a result of NAME, but it may not be moved from one disk to another.

End Definition of FOR/NEXT Loop

FOR counter = start TO end [STEP increment] . . [statements] . NEXT [counter [,counter...]] Terminates the definition of a FOR/NEXT loop. counter

start end increment

A numeric variable to be used as the loop counter. All numeric types are allowed, but the loop executes fastest if counter is an integer variable. A numeric expression; the starting value of counter. A numeric expression; the ending value of counter. A numeric expression; the value by which counter is incremented or decremented with each iteration of the loop. Defaults to +1.

---------------------------------------------------------------------Notes:

BASIC begins processing of the FOR/NEXT block by setting counter equal to start. Then, if increment is positive and counter is less than end, the statements between the FOR statement and the NEXT statement are executed. When the NEXT statement is encountered, counter is increased by increment, and the process is repeated. Execution passes to the statement following the NEXT statement if counter is equal to or greater than end. If increment is negative, execution of the FOR/NEXT loop is terminated whenever counter becomes equal to or less than end. If increment is 0, execution of the FOR/NEXT loop continues until Ctrl-Break is pressed (unless one of the repeated instructions itself increments counter). Note that changes made within the FOR/NEXT loop to counter affect the number of times the loop instructions are executed; changes made to start, end, and increment, however, do not have this effect. There must be one and only one NEXT statement for each FOR statement. Inclusion of counter in the NEXT statement is optional; if counter is omitted, its value is assumed to be that of counter in the most recent FOR statement. FOR/NEXT loops may be nested within one another. Each FOR must be given a unique counter value and each nested FOR

53

must have its NEXT statement appear within the enclosing FOR-NEXT block. Nested loops that have a common termination point may use a single NEXT statement with values of counter matching the values for each FOR statement. See Also: DO FOR LOOP WEND WHILE

OCT$

Octal Value, as String

s$ = OCT$(numexpr) Returns, as a string, the octal value of its decimal argument. numexpr

A numeric expression in the range -32768 to 65535.

See Also: HEX$

ON COM

Trap for Communications Activity

ON COM(n) GOSUB {linenum | linelabel} Specifies a subroutine to which QuickBASIC will branch if it detects activity at a specified communications port. The trap must also be turned on by means of a COM(n) ON statement. n

A numeric expression. Must be either 1, for COM1:, or 2, for COM2:.

linenum

The first line of a communications-handling subroutine. Setting linenum to 0 disables trapping.

linelabel

A label identifying the first line of a communicationshandling subroutine.

----------------------------------------------------------------------Notes:

{linenum | linelabel} must be defined at the main program level. With communications trapping in effect, QuickBASIC checks for data at the specified communications port. When activity is detected, QuickBASIC branches to the specified subroutine and temporarily suspends trapping (by means of an implicit COM(n) STOP statement). Trapping automatically resumes when a RETURN from the communications-handling subroutine is executed (unless the communications-handling routine explicitly performs a COM(n) OFF or COM(n) STOP). All event trapping is temporarily disabled when QuickBASIC is executing an error-handling routine (established via an ON ERROR statement). If the "Checking Between Statements" option is in effect, QB checks for communication activity after each statement. If the "Event Trapping" option is selected, QB checks after each new program line. If neither option is selected, no trapping takes place. For command-line compilation, /v enables checking after each statement, and /w enables checking after each new line. If neither switch is used, no trapping takes place.

See Also: COM(n)

ON ERROR

Enable Error Trapping

ON ERROR GOTO {linenum | linelabel} Enables the trapping of error conditions and specifies the beginning

54

line of an error-trapping routine. linenum linelabel

The first line of an error-handling routine. Setting linenum to 0 disables trapping. A label identifying the first line of an error-handling routine.

---------------------------------------------------------------------Notes:

{linenum | linelabel} must be defined at the main program level. It is recommended that an ON ERROR GOTO 0 statement be included within an error-handling routine to handle unidentifiable error conditions. While an error-handling routine is being executed, error trapping (and all other event trapping) is disabled. If an error occurs during this time, QuickBASIC halts program execution and displays an error message. An error-handling routine must end with a RESUME statement. When compiling a QuickBASIC program that uses ON ERROR and RESUME, you must use the On Error (/e) and Resume Next (/x) compile options.

See Also: ERL ERR ERROR RESUME

ON KEY

Trap for Keypress

ON KEY(n) GOSUB {linenum | linelabel} Establishes a subroutine to which QuickBASIC will branch if it detects a specified keypress. The trap must also be turned on by means of a KEY(n) ON statement. n

A numeric expression in the range 1 to 20.

linenum

The first line of a keypress-handling subroutine. Setting linenum to 0 disables trapping.

linelabel

A label identifying the first line of a keypress-handling routine.

---------------------------------------------------------------------Notes:

{linenum | linelabel} must be defined at the main program level. The following keys may be trapped: 1-10 11 12 13 14 15-20

Function keys F1 through F10 Cursor Up Cursor Left Cursor Right Cursor Down Keys defined via KEY n, CHR$(KBflag)+CHR$(scancode)

When the keypress is detected, QuickBASIC branches to the specified subroutine and temporarily suspends trapping (by means of an implicit KEY(n) STOP statement). Trapping automatically resumes when a RETURN from the handling subroutine is executed (unless the handler explicitly performs a KEY(n) OFF or KEY(n) STOP). The key that produced the trap may not be determined by means of INPUT$ or INKEY$. All event trapping is temporarily disabled when QuickBASIC is executing an error-handling routine (established via an

55

ON ERROR statement). ON KEY may be used to trap Ctrl-Break and Ctrl-Alt-Del, thereby preventing a user from breaking out of a program. If the "Checking Between Statements" option is in effect, QB checks after each statement. If the "Event Trapping" option is selected, QB checks after each new program line. If neither option is selected, no trapping takes place. For command-line compilation, /v enables checking after each statement, and /w enables checking after each new line. If neither switch is used, no trapping takes place. See Also: KEY(n)

ON PEN

Trap for Light Pen Activity

ON PEN GOSUB {linenum | linelabel} Establishes a subroutine to which QuickBASIC will branch if it detects light pen activity. The trap must also be turned on by means of a PEN ON statement. linenum

The first line of a pen-handling subroutine. Setting linenum to 0 disables trapping.

linelabel

A label identifying the first line of a pen-handling routine.

---------------------------------------------------------------------Notes:

{linenum | linelabel} must be defined at the main program level. When activity is detected, QuickBASIC branches to the specified subroutine and temporarily suspends trapping (by means of an implicit PEN STOP statement). Trapping automatically resumes when a RETURN from the handling subroutine is executed (unless the handler explicitly performs a PEN OFF or PEN STOP). All event trapping is temporarily disabled when QuickBASIC is executing an error-handling routine (established via an ON ERROR statement). If the "Checking Between Statements" option is in effect, QB checks after each statement. If the "Event Trapping" option is selected, QB checks after each new program line. If neither option is selected, no trapping takes place. For command-line compilation, /v enables checking after each statement, and /w enables checking after each new line. If neither switch is used, no trapping takes place.

See Also: PEN (Statement)

ON PLAY(n)

Trap for Background Music Remaining

ON PLAY(queuelimit) GOSUB {linenum | linelabel} Establishes a subroutine to which QuickBASIC will branch if fewer than a specified number of notes remain in the background music buffer. T he trap must also be turned on by means of a PLAY ON statement. queuelimit

56

An integer expression in the range 1 to 32 specifying the number of notes to be trapped.

linenum

The first line of a music-handling subroutine. Setting linenum to 0 disables trapping.

linelabel

A label identifying the first line of a music-handling routine.

----------------------------------------------------------------------Notes:

{linenum | linelabel} must be defined at the main program level. With trapping in effect, and when QuickBASIC is executing music in the background mode, when the number of notes remaining is fewer than queuelimit, QuickBASIC branches to the specified subroutine and temporarily suspends trapping (by means of an implicit PLAY STOP statement). Trapping automatically resumes when a RETURN from the handling subroutine is executed (unless the handler explicitly performs a PLAY OFF or PLAY STOP). All event trapping is temporarily disabled when QuickBASIC is executing an error-handling routine (established via an ON ERROR statement).

See Also: PLAY (Event Trap)

ON STRIG(n)

Trap for Specified Joystick Button

ON STRIG(n) GOSUB {linenum | linelabel} Establishes a subroutine to which QuickBASIC will branch if a specified joystick button is pressed. The trap must also be turned on by means of a STRIG(n) ON statement. n

A numeric expression indicating the button to be trapped. Must be 0, 2, 4, or 6. The meaning of n is as follows: 0 2 4 6

linenum linelabel

button button button button

A1 B1 A2 B2

The first line of the joystick-handling subroutine. Setting linenum to 0 disables trapping. A label identifying the first line of a joystick-handling routine.

----------------------------------------------------------------------Notes:

{linenum | linelabel} must be defined at the main program level. With trapping in effect, QuickBASIC checks to see if the specified joystick button has been pressed. When the button has been pressed, QuickBASIC branches to the specified subroutine and temporarily suspends trapping (by means of an implicit STRIG(n) STOP statement). Trapping automatically resumes when a RETURN from the handling subroutine is executed (unless the handler explicitly performs a STRIG(n) OFF or STRIG(n) STOP). Downstrokes that cause joystick button trapping do not set functions STRIG(0), STRIG(2), STRIG(4), or STRIG(6). All event trapping is temporarily disabled when QuickBASIC is executing an error-handling routine (established via an ON ERROR statement). If the "Checking Between Statements" option is in effect, QB checks after each statement. If the "Event Trapping" option is selected, QB checks after each new program line. If neither option is selected, no trapping takes place. For command-line compilation, /v enables checking after each statement, and /w enables checking after each new line. If neither switch is used, no trapping takes place.

See Also: STRIG (Statement) STRIG (Function)

57

ON TIMER

Trap for Elapsed Time

ON TIMER(n) GOSUB {linenum | linelabel} Establishes a subroutine to which QuickBASIC will branch if a specified number of seconds have passed. The trap must also be turned on by means of a TIMER ON statement. n

A numeric expression in the range 1 to 86,400 (1 second to 24 hours).

linenum

The first line of a timer-handling subroutine. Setting linenum to 0 disables trapping.

linelabel

A label identifying the first line of a timer-handling routine.

----------------------------------------------------------------------Notes:

{linenum | linelabel} must be defined at the main program level. With trapping in effect, QuickBASIC checks to see if the specified number of seconds have elapsed. When the specified amount of time has passed, QuickBASIC branches to the specified subroutine and temporarily suspends trapping (by means of an implicit TIMER STOP statement). Trapping automatically resumes when a RETURN from the handling subroutine is executed (unless the handler explicitly performs a TIMER OFF or TIMER STOP). All event trapping is temporarily disabled when QuickBASIC is executing an error-handling routine (established via an ON ERROR statement). If the "Checking Between Statements" option is in effect, QB checks after each statement. If the "Event Trapping" option is selected, QB checks after each new program line. If neither option is selected, no trapping takes place. For command-line compilation, /v enables checking after each statement, and /w enables checking after each new line. If neither switch is used, no trapping takes place.

See Also: TIMER (Statement)

ON...GOSUB

Branch to nth Item in Subroutine List

ON n GOSUB {linenum | linelabel}, [,{linenum | linelabel}]... Causes QuickBASIC to branch to one of a list of subroutine starting lines. n

linenum linelabel

A numeric variable in the range 0 to 255. Upon execution of the ON...GOSUB statement, QuickBASIC branches to the nth item in the list of line numbers that follows the keyword GOSUB. The first line number of a subroutine. A label identifying the first line of a subroutine.

----------------------------------------------------------------------Notes:

If n is a noninteger numeric value, QuickBASIC rounds n. If n is 0 or larger than the number of items in the subroutine list, QuickBASIC continues with the next executable statement. If n is negative or larger than 255, an Illegal Function Call error occurs.

58

See Also: ON...GOTO

ON...GOTO

Branch to nth Item in Line List

ON n GOTO {linenum | linelabel}, [,{linenum | linelabel}]... Causes QuickBASIC to branch to one of a list of line numbers and/or line labels. n

linenum linelabel

A numeric variable in the range 0 to 255. Upon execution of the ON...GOTO statement, QuickBASIC branches to the nth item in the list of line numbers/line labels that follows the keyword GOTO. A valid line number. A valid line label.

----------------------------------------------------------------------Notes:

If n is a noninteger numeric value, QuickBASIC rounds n. If n is 0 or larger than the number of items in the line list, QuickBASIC continues with the next executable statement. If n is negative or larger than 255, an Illegal Function Call error occurs.

See Also: ON...GOSUB

OPEN

Allow File or Device I/O

(1) OPEN filespec [FOR mode] [ACCESS access] [lock] AS [#]filenum [LEN=recl] or (2) OPEN mode2, [#]filenum, filespec [,recl] Makes a file or device available for sequential input, sequential output, or random access (either input or output). filespec filenum mode

A string expression that follows DOS file naming conventions. An integer expression in the range 1 to 255. (Syntax 1) One of the following (default is RANDOM): INPUT OUTPUT APPEND RANDOM

access

Sequential input Sequential output Sequential output, beginning at current EOF Random input/output

If included, must be one of the following: READ WRITE READ WRITE

lock

File is opened for reading only. File is opened for writing only. File is opened for both reading and writing.

If included, must be one of the following: SHARED Any process may read from or write to the file. LOCK READ No other process is granted read access to the file. LOCK WRITE No other process is granted write access to the file. LOCK READ WRITE No other process is granted either read or write access to the file.

recl

An integer expression in the range 1 to 32767. Sets the record length for random files and the capacity of the I/O buffer for sequential files. Defaults to 128.

59

mode2

(Syntax 2) A string expression that must evaluate to one of the following: I O A R

Sequential input Sequential output Sequential output at EOF Random input/output

---------------------------------------------------------------------Notes:

If a file is opened in RANDOM mode with no ACCESS code specified, QuickBASIC tries to open it for read/write access. If permission is denied, it then tries write-only access, then read-only access. The read/write access code can be specified only for files opened for APPEND in RANDOM mode. The OPEN statement has additional optional arguments when the device being opened is COM1: or COM2:. See OPEN COM... Opening an existing file for sequential output destroys the current file contents; to add to the current file, open it for APPEND (the APPEND mode may be used only for sequential disk files). A file that is already open may not be opened for sequential output or append. Opening a nonexistent file for APPEND is equivalent to opening it for OUTPUT. Disk files and printers may be opened for either sequential or random access. All other standard devices may be opened only for sequential access.

See Also: OPEN "COM...

OPEN "COM...

Open a Communications File

OPEN "COMn: [speed] [,parity] [,data] [,stop] [,RS] [,CS[m]] [,DS[m]] [,CD[m]] [,LF] [,BIN] [,ASC]" [FOR mode] AS [#]filenum [LEN=num] Opens a communications device for input and output via GET and PUT. Required arguments: n filenum

A numeric expression. Must be either 1, for COM1:, or 2, for COM2:. An asynchronous adapter must be installed. An integer expression specifying a valid file number.

Optional arguments (all must be constants): speed

Transfer rate, in bits per second. Default: 300. Other legal values: 75, 110, 150, 600, 1200, 1800, 2400, 4800, and 9600.

parity

Type of parity checking, if any. Default: E, for EVEN. Other legal values: S (SPACE), O (ODD), M (MARK), and N (NONE). parity must be set to N if data is set to 8.

data

Number of data bits to be transmitted. Default: 7. Other legal values: 5, 6, and 8.

stop

Number of stop bits. Must be 1 or 2. Default: 2, for 75 and 110 bps; 1, for all other transmission rates.

RS

CSm

60

If included, suppresses RTS (Request to Send). If not included, OPEN "COM..." automatically turns the RTS line on. If included, controls CTS (Clear to Send). m specifies, in

milliseconds, the delay before a timeout occurs. Default: 1000. Acceptable values: 0 to 65535. If m is 0, the CS argument is ignored. If RTS is suppressed via the RS parameter, the default CS time is 0 milliseconds. DSm

If included, controls DSR (Data Set Ready). m specifies, in milliseconds, the delay before a timeout occurs; acceptable values are 0 to 65535. Default: 1000. If m is 0, the DS argument is ignored.

CDm

If included, controls CD (Carrier Detect). m specifies, in milliseconds, the delay before a timeout occurs; acceptable values are 65535. Default: 0. If m is 0, the CD argument is ignored.

LF

If included, sends a line feed after each carriage return.

LEN=num

If included, num specifies the maximum number of bytes that can be read from the communications buffer via GET or PUT. Default: 128.

BIN

Opens the device in binary mode. This argument overrides an LF argument.

ASC

Opens the device in ASCII mode. Tabs are converted to spaces, carriage returns are issued at the end of each line, Ctrl-Z is read as EOF, and XON/XOFF is enabled.

FOR mode

mode may be OUTPUT, for sequential output, or INPUT, for sequential input. If this argument is omitted, the device is opened for random access (input and output).

----------------------------------------------------------------------Notes:

The speed, parity, data, and stop arguments must be presented in that order. Use commas as placeholders for omitted arguments. The remaining arguments--RS, CS, DS, CD, LF, BIN, and ASC may be specified in any order. Communications devices are opened in binary mode by default, unless an ASC argument is included in the OPEN COM statement.

See Also: COM(n) ON COM

OPTION BASE

Set Minimum Array Subscript

OPTION BASE n Specifies whether the lowest subscript in all arrays used in a program is 0 or 1. n

Must be 0 or 1. The default is 0.

---------------------------------------------------------------------Notes:

The OPTION BASE statement, if used, must be executed before any arrays are defined or used. Only one OPTION BASE statement per compilation is allowed.

See Also: LBOUND UBOUND

OUT

Send Byte to Output Port

OUT port,data Sends one byte of data to a specified output port. port

An integer expression in the range 0 to 65535; specifies the port number.

61

data

An integer expression in the range 0 to 255; specifies the data byte.

See Also: INP

PAINT

Fill an Area with a Pattern or Color

PAINT [STEP] (x,y) [[,color] [,boundary] [,background]] Fills an enclosed area on the graphics screen with a specific color or pattern. STEP

x,y color

boundary

background

If included, coordinates are relative to last graphics point referenced (LPR). If omitted, coordinates are absolute. Screen coordinate (column, row) within the area that is to be filled. A numeric or string expression. If numeric, specifies color to fill area with; if string, specifies a bit pattern to fill the area with. If this argument is omitted, the foreground color will be used. The color of the border of the area to be filled. PAINT stops filling when it reaches this color. If this argument is omitted, then color will be used. A string expression specifying the background tile slice to skip when checking for termination of the boundary. This allows you to repaint an already painted area.

-------------------------------------------------------------------------Notes:

If color is a string expression, each character (8 bits) in the string represents one scan line. Each character therefore represents the status of 4 pixels in mediumresolution and 8 pixels in high-resolution. The string can be from 1 to 64 bytes long (thus allowing 1 to 64 scan lines vertically). Ensure that the area to be filled is completely enclosed, or else "leaking" may destroy the entire drawing. background is used to determine the stop condition when filling an already painted area. If an existing pixel is encountered that agrees with the corresponding bit in background, then filling doesn't stop.

See Also: CIRCLE DRAW

PALETTE

Change Color in the Palette

PALETTE [attribute, color] Changes a color in the palette. This statement can be used only with the Enhanced Graphics Adapter (EGA). attribute color

Represents a color in the palette. The range of values depends on the screen mode (see below). Actual display color. The range of values depends on the screen mode (see below). Attribute and Color Ranges

Mode 0

1

62

Monitor Mono/MDA Mono/EGA Color/CGA Color/EGA Color/CGA Color/EGA

Attribute N/A 0-15 N/A 0-31 N/A 0-3

Color N/A 0-2 0-31 0-15 0-3 0-15

2

Color/CGA Color/EGA Color/EGA Color/EGA EGA (64K) EGA (>64K) Mono/EGA

7 8 9 10

N/A 0-1 0-15 0-15 0-3 0-15 0-3

0-1 0-15 0-15 0-15 0-15 0-63 0-8

-------------------------------------------------------------------------Notes:

If no arguments are specified, then the palette is set to its predefined default colors. Changing the palette will affect the current screen colors immediately. Text or graphics on the screen will not be destroyed.

See Also: COLOR DRAW PALETTE USING SCREEN (Statement)

PALETTE USING

Change Many Colors in the Palette

PALETTE USING intarray (arrayindex) Changes many colors in the palette in a single statement. This statement can be used only with the Enhanced Graphics Adapter (EGA). intarray arrayindex

An integer array that containing the new colors in the palette. The array must consist of at least 16 elements. The starting index of intarray of where the new colors begin. Most of the time this value will be 0. Attribute and Color Ranges

Mode 0

Monitor Mono/MDA Mono/EGA Color/CGA Color/EGA Color/CGA Color/EGA Color/CGA Color/EGA Color/EGA Color/EGA EGA (64K) EGA (>64K) Mono/EGA

1 2 7 8 9 10

Attribute N/A 0-15 N/A 0-31 N/A 0-3 N/A 0-1 0-15 0-15 0-3 0-15 0-3

Color N/A 0-2 0-31 0-15 0-3 0-15 0-1 0-15 0-15 0-15 0-15 0-63 0-8

-------------------------------------------------------------------------Notes:

If the value of an array entry is -1, then the paired attribute is not affected. Any other negative value is illegal. Changing the palette will affect the current screen colors immediately. Text or graphics on the screen will not be destroyed.

See Also: COLOR DRAW PALETTE SCREEN (Statement)

PCOPY

Copy Screen Page

PCOPY sourcepg,destpg Copies one screen page to another. sourcepg

An integer expression in the current range of video page options. Specifies the source page.

destpg

An integer expression in the current range of video page options. Specifies the destination page.

63

PEEK

Value at Specified Address

y = PEEK(n) Returns the byte at a specified memory offset within the current segment. n

A single-precision expression in the range 0 to 1,048,575.

---------------------------------------------------------------------Notes:

n specifies a decimal offset within the segment specified by the most recent DEF SEG statement. If there has been no DEF SEG statement, the offset is within QuickBASIC's data segment.

See Also: DEF SEG POKE

PEN

Light Pen Status

Function

y = PEN(n) Returns information about the status of the light pen. For the PEN function to be available, a PEN ON statement must first be executed. n

A numeric expression in the range 0 to 9; specifies the kind of information to be returned. Options are as follows: 0 1 2 3 4 5 6 7 8 9

Returns -1 if light pen has been down since last PEN function; otherwise returns 0. Returns x coordinate of location where pen was most recently activated. Returns y coordinate of location where pen was most recently activated. Returns -1 if pen switch is currently down; otherwise returns 0. Returns x coordinate of last known valid pen location. Returns y coordinate of last known valid pen location. Returns row position of location where pen was most recently activated. Returns column position of location where pen was most recently activated. Returns row position of last known valid pen location. Returns column position of last known valid pen location.

See Also: PEN (statement)

PEN

Enable/Disable Pen Read and Trap

Statement

PEN {ON | OFF | STOP} Enables or disables the PEN function (which returns light pen status information. Also enables or disables trapping of light pen activity. ON

Enables reading of the light pen status, via the PEN function, and causes QuickBASIC to check for light pen activity.

OFF

Disables reading of the light pen status and causes QuickBASIC not to check for light pen activity. This is the default condition.

STOP

Disables reading of the light pen status and deactivates trapping, but QuickBASIC continues checking to see if the pen has been activated. If it has, a subsequent PEN ON results in an immediate trap (provided an ON PEN statement with a nonzero line number has been executed).

-----------------------------------------------------------------------

64

Notes:

If the "Checking Between Statements" option QB checks for light pen activity after each the "Event Trapping" option is selected, QB each new program line. If neither option is trapping takes place.

is in effect, statement. If checks after selected, no

For command-line compilation, /v enables checking after each statement, and /w enables checking after each new line. If neither switch is used, no trapping takes place. See Also: ON PEN PEN (Function)

PLAY

Enable/Disable Music Trap

Statement

PLAY {ON | OFF | STOP} Enables or disables the ON PLAY trap. ON

PLAY ON enables checking of the background music buffer.

OFF

PLAY OFF disables checking of the background music buffer. This is the default condition.

STOP

PLAY STOP inhibits trapping. QuickBASIC continues checking the buffer, and if the notes remaining are fewer than specified in the ON PLAY statement, a subsequent PLAY ON results in an immediate trap.

----------------------------------------------------------------------Notes:

If the "Checking Between Statements" option is in effect, QB checks for communication activity after each statement. If the "Event Trapping" option is selected, QB checks after each new program line. If neither option is selected, no trapping takes place. For command-line compilation, /v enables checking after each statement, and /w enables checking after each new line. If neither switch is used, no trapping takes place.

See Also: ON PLAY(n) Play (Function)

PLAY

Number of Notes in Background Buffer

Function

y = PLAY(n) Returns the number of notes remaining in the background music buffer. n

PLAY

A dummy; can be any value.

Play Music

Statement

PLAY string Plays a melody according to instructions specified as a string expression. string

A string expression containing one or more commands in the BASIC tune definition language.

Tune Definition Language A to G Nn

#, +, -

Name of a note to play. Case is not significant. Number of a note to play. Notes are numbered from 1, corresponding to the lowest C on a piano, to 84, corresponding to the highest B on a piano. A value of 0 for n specifies a rest. Sharps and flats. The equivalent symbols # and + tell

65

BASIC to raise the specified note by a half step. The symbol - tells BASIC to lower the specified note by a half step. Only those sharps and flats that correspond to black keys on a piano are valid; i.e., E# and B# are not valid notes. Append these symbols to the notes. On

Octave (register) in which to play a letter-named note. Octaves are numbered from 0 (lowest) to 6. The lowest note in each octave is C. The default is octave 4.

Ln

Duration of note, as a reciprocal (but see MS, ML, and MN, below). A value of 4 indicates a quarter note, a value of 16 indicates a sixteenth note, and so on. All values from 1 through 64 are valid. An L command affects all notes that follow, until the next L command. But you may also specify a duration value in conjunction with a note name or number--as, for example, D#4 (a D-sharp quarter note); a duration specified in this manner affects only the note with which it is associated.

Pn

A rest (pause) of specified duration. specified in the same manner as for a reciprocal. To generate a rest in the you may simply indicate a note number

The duration is note--i.e., as a current value of L, of 0.

.

Appended to a note name or number, or a rest, a dot (period) extends the current duration of the note (or rest) by one half. You may have more than one dot after a note or rest.

Tn

Tempo, specified as a number of quarter notes per minute. Values of 32 to 255 are valid; the default is 120.

>A to >G

Increment the octave value by 1 and play the named note. The octave value stays at the increased level. If the current octave is 6, > has no effect.

?

NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN SUB ESC FS GS RS US

| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

Dec 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

Hex 40h 41h 42h 43h 44h 45h 46h 47h 48h 49h 4Ah 4Bh 4Ch 4Dh 4Eh 4Fh 50h 51h 52h 53h 54h 55h 56h 57h 58h 59h 5Ah 5Bh 5Ch 5Dh 5Eh 5Fh 60h 61h 62h 63h 64h 65h 66h 67h 68h 69h 6Ah 6Bh 6Ch 6Dh 6Eh 6Fh 70h 71h 72h 73h 74h 75h 76h 77h 78h 79h 7Ah 7Bh 7Ch 7Dh 7Eh 7Fh

Char @ | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | [ | \ | ] | ^ | _ | ` | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | { | | | } | ~ | . |

Dec 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191

Hex 80h 81h 82h 83h 84h 85h 86h 87h 88h 89h 8Ah 8Bh 8Ch 8Dh 8Eh 8Fh 90h 91h 92h 93h 94h 95h 96h 97h 98h 99h 9Ah 9Bh 9Ch 9Dh 9Eh 9Fh A0h A1h A2h A3h A4h A5h A6h A7h A8h A9h AAh ABh ACh ADh AEh AFh B0h B1h B2h B3h B4h B5h B6h B7h B8h B9h BAh BBh BCh BDh BEh BFh

Char . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | # | # | # | | | | | | | | | + | + | | | | | + | + | + | + | + |

Dec 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255

Hex C0h C1h C2h C3h C4h C5h C6h C7h C8h C9h CAh CBh CCh CDh CEh CFh D0h D1h D2h D3h D4h D5h D6h D7h D8h D9h DAh DBh DCh DDh DEh DFh E0h E1h E2h E3h E4h E5h E6h E7h E8h E9h EAh EBh ECh EDh EEh EFh F0h F1h F2h F3h F4h F5h F6h F7h F8h F9h FAh FBh FCh FDh FEh FFh

Char + | + + + | + + + + + + + + + # # # # # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Line-Drawing Chars 218 196 194 191 +----------------+ 179 | 197 | | 179 | \ | | 195 |----------+-----| 180 | | | +----------------+ 192 196 193 217

201 205 203 187 +----------------+ 186 | 206 | | 186 | \ | | 204 |----------+-----| 185 | | | +----------------+ 200 205 202 188

213 205 209 184 +----------------+ 179 | 216 | | 179 | \ | | 198 -----------+-----| 181 | | | +----------------+ 212 205 207 190

214 196 210 183 +----------------+ 186 | 215 | | 186 | \ | | 199 -----------+-----| 182 | | | +----------------+ 211 196 208 189

Special Characters ---------------------------------- Arrows ---------------------------------. . . .

30 31 16 17

. . . .

24 25 26 27

. .

18 23

.

29

----------------------------- Block Characters ----------------------------# 176 # - 219 # 221 # 177 # - 220 # 222 # 178 # - 223 ----------------------- Foreign-Language Characters -----------------------131 132 133 160 134

. . . . .

.

142

.

143

145

.

.

146

135

.

.

128

| | | | | | | | |

136 137 138 130

. . . .

140 139 141 161

. . . .

.

144

| | | | | | | | |

147 148 149 162

. . . .

.

153

164

.

.

165

225

.

| | | | | | | | |

150 129 151 163

. . . .

152

.

.

154

-------------------- Miscellaneous Language Characters --------------------. . . .

155 156 157 159

. .

166 167

. . . .

168 173 174 175

. . . .

19 20 21 158

------------------------ Math and Greek Characters ------------------------. . . . . . . . . . . . . . . . . .

143 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 236

244 . | 179 . 245

. .

224 225

. . . . . . .

235 233 230 227 229 231 237

.

226

.

228

. .

232 234

alpha beta gamma delta theta mu pi sigma tau phi omega

105

Color Chart Number I R G B ------ --- --- --- --0 0 0 0 0 1 0 0 0 1 2 0 0 1 0 3 0 0 1 1 4 0 1 0 0 5 0 1 0 1 6 0 1 1 0 7 0 1 1 1 8 9 10 11 12 13 14 15

1 1 1 1 1 1 1 1

0 0 0 0 1 1 1 1

0 0 1 1 0 0 1 1

0 1 0 1 0 1 0 1

Monochrome ---------Black Underlined

Color ----Black Blue Green Cyan Red Violet Brown White

White Brt Underline

Bright White

Grey Bright Bright Bright Bright Bright Yellow Bright

Blue Green Cyan Red Violet White

Background ---------Sample Sample Sample Sample Sample Sample Sample Sample

Foreground ---------Sample Sample Sample Sample Sample Sample Sample Sample

Sample Sample Sample Sample Sample Sample Sample Sample

Sample Sample Sample Sample Sample Sample Sample Sample

-------------------------------------------------------------------------Notes:

Background colors 8 through 15 are the same color as 0 through 7, but blinking rather than steady. Character attributes contain both a foreground and a background color, and are calculated as follows: attribute = 256 * background + foreground

Keyboard Codes This table lists (in decimal notation) the values that are placed in the keyboard buffer by all the possible keystrokes and two-keystroke combinations on the 83/84-key and 101/102-key keyboards. These are the values returned (as strings) by the INKEY$ function. Keystroke Esc 1 2 3 4 5 6 7 8 9 0 = Backspace Tab q w e r t y u i o p [ ] Enter Ctrl a

106

83/84-Key[1] Keyboard 027 049 050 051 052 053 054 055 056 057 048 045 061 008 009 113 119 101 114 116 121 117 105 111 112 091 093 013 ** 097

101/102-Key Keyboard[2] same same same same same same same same same same same same same same same same same same same same same same same same same same same same ** same

s d f g h j k l ; ' ` Shift \ z x c v b n m , . / Gray * Alt Space Caps Lock F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Num Lock Scroll Lock White Home White Up Arrow White PgUp Gray White Left Arrow Center Key White Right Arrow Gray + White End White Down Arrow White PgDn White Ins White Del SysReq Key 45 [3] Enter (number keypad) Gray / PrtSc Pause Gray Home Gray Up Arrow Gray Page Up Gray Left Arrow Gray Right Arrow Gray End Gray Down Arrow Gray Page Down Gray Insert Gray Delete Shift Esc ! @ # $

000 000 000 000 000 000 000 000 000 000 no no 000 000 000 000 000 000 000 000 000 000 no no no no no no no no no no no no no no no no

115 100 102 103 104 106 107 108 059 039 096 ** 092 122 120 099 118 98 110 109 044 046 047 042 ** 032 ** 059 060 061 062 063 064 065 066 067 068 key key ** ** 071 072 073 045 075 -077 043 079 080 081 082 083 key key key key key key key key key key key key key key key key

same same same same same same same same same same same ** same same same same same same same same same same same same ** same ** same same same same same same same same same same 000 133 000 134 ** ** same same same same same 000 076 same same same same same same same ** 092 000 013 000 047 ** ** 071 072 073 075 077 079 080 081 082 083

027 033 064 035 036

same same same same same

107

% ^ & * (white) ( ) _ + (white) Shift Backspace Shift Tab (Backtab) Q W E R T Y U I O P { } Shift Enter Shift Ctrl A S D F G H J K L : " ~ | Z X C V B N M < > ? Shift Gray * Shift Alt Shift Space Shift Caps Lock Shift F1 Shift F2 Shift F3 Shift F4 Shift F5 Shift F6 Shift F7 Shift F8 Shift F9 Shift F10 Shift F11 Shift F12 Shift Num Lock Shift Scroll Lock Shift 7 (number pad) Shift 8 (number pad) Shift 9 (number pad) Shift Gray Shift 4 (number pad) Shift 5 (number pad) Shift 6 (number pad) Shift Gray + Shift 1 (number pad) Shift 2 (number pad) Shift 3 (number pad)

108

000

000 000 000 000 000 000 000 000 000 000 no no

037 094 038 042 040 041 095 043 008 015 081 087 069 082 084 089 085 073 079 080 123 125 013 ** 065 083 068 070 071 072 074 075 076 058 034 126 124 090 088 067 086 066 078 077 060 062 063 ** ** 032 ** 084 085 086 087 088 089 090 091 092 093 key key ** ** 055 056 057 045 052 053 054 043 049 050 051

same same same same same same same same same same same same same same same same same same same same same same same ** same same same same same same same same same same same same same same same same same same same same same same same 042 ** same ** same same same same same same same same same same 000 135 000 136 ** ** same same same same same same same same same same same

Shift Shift Shift Shift Shift Shift Shift Shift Shift Shift Shift Shift Shift Shift Shift Shift Shift Shift Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl

0 (number pad) . (number pad) SysReq Key 45 [3] Enter (number pad) Gray / PrtSc Pause Gray Home Gray Up Arrow Gray Page Up Gray Left Arrow Gray Right Arrow Gray End Gray Down Arrow Gray Page Down Gray Insert Gray Delete

Esc 1 2 (NUL) 3 4 5 6 (RS) 7 8 9 0 = Backspace (DEL) Tab q (DC1) w (ETB) e (ENQ) r (DC2) t (DC4) y (EM) u (NAK) i (HT) o (SI) p (DEL) [ (ESC) ] (GS) Enter (LF) a (SOH) s (DC3) d (EOT) f (ACK) g (BEL) h (Backspace) j (LF) k (VT) l (FF) ; ' ` Shift \ (FS) z (SUB) x (CAN) c (ETX) v (SYN) b (STX) n (SO) m (CR) , . / Gray * Alt Space Caps Lock F1

048 046 key key key key key key key key key key key key key key key key

same same ** 124 000 013 000 047 ** ** 071 072 073 075 077 079 080 081 082 083

027 -000 003 ---030 ----031 -127 -017 023 005 018 020 025 021 009 015 016 027 029 010 001 019 004 006 007 008 010 011 012 ---** 028 026 024 003 022 002 014 013 ----** 032 -000 094

same -same ---same ----same -same 148 same same same same same same same same same same same same same same same same same same same same same same ---** same same same same same same same same ---000 150 ** same -same

no no no no no no no no no no no no no no no no

109

Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Ctrl Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt

110

F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Num Lock Scroll Lock White Home White Up Arrow White PgUp Gray White Left Arrow 5 (number pad) White Right Arrow Gray + White End White Down Arrow White PgDn White Ins White Del SysReq Key 45 [3] Enter (number pad) / (number pad) PrtSc Break Gray Home Gray Up Arrow Gray Page Up Gray Left Arrow Gray Right Arrow Gray End Gray Down Arrow Gray Page Down Gray Insert Gray Delete

Esc 1 2 3 4 5 6 7 8 9 0 = Backspace Tab q w e r t y u i o p [ ] Enter Ctrl a s d f

000 000 000 000 000 000 000 000 000 no no 000 000 000 000 000 000 no no no no no no no no no no no no no no no no 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000

000 000 000 000

095 096 097 098 099 100 101 102 103 key key --119 -132 -115 -116 -117 -118 --key key key key key key key key key key key key key key key key

same same same same same same same same same 000 137 000 138 --same 000 141 same 000 142 same 000 143 same 000 144 same 000 145 same 000 146 000 147 ** -000 010 000 149 114 000 000 119 141 132 115 116 117 145 118 146 147

-120 121 122 123 124 125 126 127 128 129 130 131 --016 017 018 019 020 021 022 023 024 025 ---** 030 031 032 033

000 001 same same same same same same same same same same same same 000 014 000 165 same same same same same same same same same same 000 026 000 027 000 028 ** same same same same

Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt Alt

g h j k l ; ' ` Shift \ z x c v b n m , . / Gray * Space Caps Lock F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Num Lock Scroll Lock Gray Gray + 7 (number pad) 8 (number pad) 9 (number pad) 4 (number pad) 5 (number pad) 6 (number pad) 1 (number pad) 2 (number pad) 3 (number pad) Del SysReq Key 45 [3] Enter (number pad) / (number pad) PrtSc Pause Gray Home Gray Up Arrow Gray Page Up Gray Left Arrow Gray Right Arrow Gray End Gray Down Arrow Gray Page Down Gray Insert Gray Delete

000 000 000 000 000

000 000 000 000 000 000 000

000 000 000 000 000 000 000 000 000 000 no no

no no no no no no no no no no no no no no no

034 035 036 037 038 ---** -044 045 046 047 048 049 050 ----032 ** 104 105 106 107 108 109 110 111 112 113 key key ** ** --# # # # # # # # # -key key key -key key key key key key key key key key key key

same same same same same 000 039 000 040 000 041 ** 000 043 same same same same same same same 000 051 000 052 000 053 000 055 same ** same same same same same same same same same same 000 139 000 140 ** ** 000 074 000 078 # # # # # # # # # -** -000 166 000 164 ** ** 000 151 000 152 000 153 000 155 000 157 000 159 000 160 000 161 000 162 000 163

-------------------------------------------------------------------------Footnotes [1]

The 83-key and 84-key keyboards are the original PC keyboard and the original-layout AT keyboard, respectively.

[2]

The 101/102-key keyboard is the current IBM standard ("Enhanced") keyboard.

111

[3]

112

In the United States, the 101/102-key keyboard is shipped with 101 keys. Overseas versions have an additional key sandwiched between the left Shift key and the Z key. This additional key is identified by IBM (and in this table) as "Key 45."

[**]

Keys and key combinations marked ** are used by the ROM BIOS but do not put values into the keyboard buffer.

[--]

Keys and key combinations marked -- are ignored by the ROM BIOS.

Sadržaj Naredbe po nameni .................................................................3 BASIC .............................................................................7 Language .........................................................................7 $DYNAMIC Declare Arrays Dynamic ..................................7 $INCLUDE Include File ............................................7 $STATIC Declare Arrays Static ...................................7 ' Comment .................................................8 ABS Absolute Value ..........................................8 ANY Clause Disables type checking ..................................8 ASC ASCII Value of First Character ..........................8 ATN Arctangent ..............................................8 BEEP Beep the Speaker ........................................9 BINARY Keyword Used in an OPEN statement to specify binary file mode ...9 BSAVE Save a Binary (Memory Image) File .......................9 CALL Invoke Subprogram or Assembly Subroutine ...............10 CALL ABSOLUTE Invoke Subprogram or Assembly Subroutine ...............10 CALLS Invoke Subprogram or Assembly Subroutine ...............10 CDBL Convert to Double Precision ............................11 CHAIN Transfer to Another Program ............................11 CHDIR Change Directory .......................................12 CHR$ Convert ASCII Code to Character ........................12 CINT Convert to Integer .....................................12 CIRCLE Draw Ellipse on Screen .................................12 CLEAR Close Files, Reset Variables, Set Stack Space ..........13 CLNG Converts long (4-byte) integer by rounding .............13 CLOSE Close File or Device ...................................13 CLS Clear Screen ...........................................14 COLOR Set Foreground, Background, and Border Colors ..........14 COM(n) Enable/Disable Comm Port Trapping ......................16 COMMAND$ Get Command Line .......................................17 COMMON Pass Variables to CHAINed Program or Subprogram ........17 CONST Declare Symbolic Constant(s) ...........................18 COS Cosine .................................................18 CSNG Convert to Single Precision ............................18 CSRLIN Line Position of Cursor ................................18 CVD Convert String to Double-Precision .....................19 CVDMBF MBF Double-Precision String to IEEE (QB87 only) ........19 CVI Convert String to Integer ..............................19 CVS Convert String to Single Precision .....................19 CVSMBF MBF Single-Precision String to IEEE (QB87 only) ........20 DATA Store Constant(s) for Retrieval via READ ...............20 DATE$ Get or Set System Date .................................20 DECLARE Declares references to procedures and functions ........21 DEF FN Define Function ........................................22 DEF SEG Define Segment .........................................23 DEFDBL Define Variable(s) as Double Precision .................23 DEFINT Define Variable(s) as Integer ..........................23 DEFSNG Define Variable(s) as Single Precision .................24 DEFSTR Define Variable(s) as String ...........................24 DIM Dimension Array(s) .....................................24 DO Begin Definition of DO/LOOP Loop .......................25 DRAW Draw Object ............................................25 END Terminate Program ......................................27 ENVIRON Modify Environment Table ...............................27 ENVIRON$ Environment Table Entry ................................27 EOF End of File Status .....................................28 ERASE Reset Static Array or Deallocate Dynamic Array .........28 ERDEV Critical Error Code ....................................28 ERDEV$ Device Causing Critical Error ..........................28 ERL Line Number of Most Recent Error .......................29 ERR Error Number ...........................................29 ERROR Force Error ............................................29 EXIT Exit Multiline Function, Loop, or Subprogram ...........30 EXP Exponent (Natural) .....................................30 FIELD Allocate Space for Random File Variables ...............30 FILEATTR Returns information about an open file .................31 FILES Display File Directory .................................31 FIX Truncate to Integer ....................................32 FOR Begin Definition of FOR/NEXT Loop ......................32

113

FRE FREEFILE FUNCTION GET GET GOSUB GOTO HEX$ IF INKEY$ INP INPUT INPUT # INPUT$ INSTR INT IOCTL IOCTL$ KEY KEY(n) KILL LBOUND LCASE$ LEFT$ LEN LET LINE LINE INPUT LINE INPUT# LOC LOCATE LOCK LOF LOG LOOP LPOS LPRINT LPRINT USING LSET LTRIM$ MID$ MID$ MKD$ MKDIR MKDMBF$ MKI$ MKS$ MKSMBF$ NAME NEXT OCT$ ON COM ON ERROR ON KEY ON PEN ON PLAY(n) ON STRIG(n) ON TIMER ON...GOSUB ON...GOTO OPEN OPEN "COM... OPTION BASE OUT PAINT PALETTE PALETTE USING PCOPY PEEK PEN PEN PLAY PLAY PLAY PMAP POINT

114

Available Memory .......................................33 Returns the next free BASIC file number ................33 Declares the function ..................................33 Read Random File into Buffer (File I/O) ................35 Read Points from Screen (Graphics) .....................35 Execute Subroutine .....................................36 Unconditional Branch ...................................36 Hexadecimal Value, as String ...........................37 Conditional Branch .....................................37 Most Recent Character at Keyboard ......................38 Read from an I/O Port ..................................38 Get Input from Keyboard ................................38 Get Input from Sequential File or Device ...............39 Read Specified Number of Characters ....................40 Find Substring .........................................40 Next Lower Integer .....................................41 Send Control String to Device Driver ...................41 Read Control String from Device Driver .................41 Set or Display Soft Keys ...............................41 Enable/Disable Key Trapping ............................42 Delete File(s) .........................................43 Lower Bound of Array Dimension .........................43 Returns a string with all letters in lower-case ........43 Substring at Left ......................................44 Length of String .......................................44 Assignment .............................................44 Draw Line or Box .......................................44 Read Line from Keyboard, Ignoring Delimiters ...........45 Read Line from File, Ignoring Delimiters ...............45 Current File Position ..................................45 Position the Cursor ....................................46 Control File or Record Access ..........................46 Length of File .........................................47 Natural Logarithm ......................................47 End Definition of DO/LOOP Loop .........................47 Current Position of Print Head .........................48 Output to LPT1: ........................................48 Formatted Output to LPT1: ..............................49 Left-Justify Data in Field Variable ....................50 Returns a copy of a string with leading spaces removed .50 Substring in Middle (Function) .........................51 Assign Substring (Statement) ...........................51 Convert Double-Precision to String .....................52 Create Subdirectory ....................................52 IEEE Double-Precision to MBF String (QB87 only) ........52 Convert Integer to String ..............................52 Convert Single-Precision to String .....................52 IEEE Single-Precision to MBF String (QB87 only) ........52 Rename File ............................................53 End Definition of FOR/NEXT Loop ........................53 Octal Value, as String .................................54 Trap for Communications Activity .......................54 Enable Error Trapping ..................................54 Trap for Keypress ......................................55 Trap for Light Pen Activity ............................56 Trap for Background Music Remaining ....................56 Trap for Specified Joystick Button .....................57 Trap for Elapsed Time ..................................58 Branch to nth Item in Subroutine List ..................58 Branch to nth Item in Line List ........................59 Allow File or Device I/O ...............................59 Open a Communications File .............................60 Set Minimum Array Subscript ............................61 Send Byte to Output Port ...............................61 Fill an Area with a Pattern or Color ...................62 Change Color in the Palette ............................62 Change Many Colors in the Palette ......................63 Copy Screen Page .......................................63 Value at Specified Address .............................64 Light Pen Status (Function) ............................64 Enable/Disable Pen Read and Trap (Statement) ...........64 Enable/Disable Music Trap (Statement) ..................65 Number of Notes in Background Buffer (Function) ........65 Play Music (Statement) .................................65 Map Physical Coordinates to World ......................67 Attribute or Value at Screen Location ..................67

POKE POS PRESET PRINT PRINT # PRINT # USING PRINT USING PSET PUT PUT RANDOMIZE READ REDIM REM RESET RESTORE RESUME RETURN RIGHT$ RMDIR RND RSET RTRIM$ RUN SADD SCREEN SCREEN SEEK SELECT CASE SGN SHARED SHELL SIN SLEEP SOUND SPACE$ SPC SQR STATIC STICK STOP STR$ STRIG STRIG STRING$ SUB...END SUB SWAP SYSTEM TAB TAN TYPE TIME$ TIME$ TIMER TIMER TROFF TRON UBOUND UCASE$ UNLOCK VAL VARPTR VARPTR$ VIEW VIEW PRINT WAIT WEND WHILE WIDTH WINDOW WRITE WRITE #

Write Byte to Memory ...................................67 Current Cursor Column Position .........................67 Draw Point on Screen ...................................68 Display on Screen ......................................68 Output to Sequential File ..............................68 Formatted Output to File ...............................69 Formatted Screen Display ...............................70 Draw Point on Screen ...................................72 Write Record from Random Buffer to File (File I/O) .....72 Plot Array Image on Screen (Graphics) ..................73 Reseed Random Number Generator .........................73 Assign DATA Items to Variables .........................73 Redimension Array ......................................74 Comment or Metacommand .................................74 Close All Disk Files ...................................75 Reset DATA Item Pointer ................................75 Continue after Error Trap ..............................75 Return from Subroutine .................................75 Substring at Right .....................................76 Remove Subdirectory ....................................76 Random Number ..........................................76 Right-Justify Data in Field Variable ...................76 Rreturns a string with right-hand spaces removed .......77 Execute Program ........................................77 String Address .........................................78 Character at Specified Location (Function) .............78 Set Screen Attributes (Statement) ......................78 Returns the current file position ......................79 Case Structure .........................................80 Sign of Number .........................................81 Declare Global Variables ...............................81 Execute DOS Command ....................................81 Sine ...................................................82 Suspends execution of the calling program ..............82 Sound the Speaker ......................................82 String of n Spaces .....................................83 Skip n Spaces in a PRINT statement .....................83 Square Root ............................................83 Declare Local Variable(s) ..............................83 Joystick Coordinates ...................................84 Halt Program ...........................................84 String Representation of Numeric Expression ............84 Enable/Disable the STRIG Function (Statement) ..........84 Status of Joystick Buttons (Function) ..................84 String of Specified Length and Character ...............85 Define Subprogram ......................................85 Exchange the Values of Two Variables ...................86 Return to Operating System .............................86 Tab to a Specified Position ............................86 Tangent ................................................86 Declaration that defines a data type ...................87 Get System Time (Function) .............................87 Set System Time (Statement) ............................87 Number of Seconds since Midnight (Function) ............88 Enable/Disable Timer Trap (Statement) ..................88 Trace Off ..............................................88 Trace On ...............................................88 Upper Bound of Array Dimension .........................88 Returns a string with all letters in uppercase .........89 Remove File or Record Access Lock ......................89 Numeric Value of a String ..............................89 Offset of Variable or Offset of File Buffer ............90 Offset of Variable, in Character Form ..................90 Define Screen Window ...................................90 Set Screen Text Window .................................91 Wait for Port Status ...................................91 End Definition of WHILE/WEND Loop ......................92 Begin Definition of WHILE/WEND Loop ....................92 Set Output Width .......................................93 Redefine Screen Coordinates ............................93 Output to Screen .......................................93 Output to Sequential File ..............................94

Operators .......................................................................94 Precedence Operator Precedence in BASIC ...........................94 ^ Exponentiation .........................................95

115

* / + \ MOD = < > = NOT AND OR XOR EQV IMP

Multiplication .........................................95 Division ...............................................95 Addition and Concatenation .............................95 Subtraction and Negation ...............................96 Integer Division .......................................96 Modulo Arithmetic ......................................96 Equal to/Assignment ....................................96 Not Equal to ...........................................97 Less than ..............................................97 Greater than ...........................................97 Less than or Equal to ..................................98 Greater than or Equal to ...............................98 Logical NOT ............................................98 Logical AND ............................................98 Logical OR .............................................99 Logical Exclusive OR ...................................99 Equivalence ............................................99 Implication ...........................................100

Data Types .....................................................................100 Switches and Options ...........................................................100 Type Conversions ...............................................................102 Reserved Words .................................................................102 Runtime Errors .................................................................103 Tables ..........................................................................104 ASCII Chart ....................................................................104 Line-Drawing Chars .............................................................105 Special Characters .............................................................105 Color Chart ....................................................................106 Keyboard Codes .................................................................106 Sadržaj .........................................................................113

116

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF