quickbasic 3

116
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.

Upload: garneli

Post on 29-Mar-2015

374 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: QuickBASIC 3

QuickBASIC 3.0The 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.

Page 2: QuickBASIC 3

2

Page 3: QuickBASIC 3

3

Naredbe po nameniControl program flow----------------------------------DO...LOOP Begin Definition of DO/LOOP LoopEND Terminate ProgramEXIT Exit Multiline Function, Loop, or SubprogramFOR...NEXT Begin Definition of FOR/NEXT LoopGOSUB Execute SubroutineGOTO Unconditional BranchIF Conditional BranchON...GOSUB Branch to nth Item in Subroutine ListON...GOTO Branch to nth Item in Line ListSELECT CASE Case StructureSLEEP Suspends execution of the calling programSTOP Halt ProgramSYSTEM Return to Operating SystemWEND End Definition of WHILE/WEND LoopWHILE Begin Definition of WHILE/WEND Loop

Declare constants and variables----------------------------------$DYNAMIC Declare Arrays Dynamic$STATIC Declare Arrays StaticCOMMON Pass Variables to CHAINed Program or SubprogramCONST Declare Symbolic Constant(s)DATA Store Constant(s) for Retrieval via READDEFDBL Define Variable(s) as Double PrecisionDEFINT Define Variable(s) as IntegerDEFSNG Define Variable(s) as Single PrecisionDEFSTR Define Variable(s) as StringDIM Dimension Array(s)ERASE Reset Static Array or Deallocate Dynamic ArrayLET AssignmentOPTION BASE Set Minimum Array SubscriptREAD Assign DATA Items to VariablesREDIM Redimension ArrayREM Comment or MetacommandRESTORE Reset DATA Item PointerSHARED Declare Global VariablesSWAP Exchange the Values of Two VariablesTYPE Defines a data type containing one or more elements

Define and call Basic procedures----------------------------------ANY Clause As part of a procedure declaration, disables type checkingCALL Invoke Subprogram or Assembly SubroutineCALL ABSOLUTE Invoke Subprogram or Assembly SubroutineCALLS Invoke Subprogram or Assembly SubroutineCHAIN Transfer to Another ProgramDECLARE Declares references to procedures and functionsFUNCTION Declares the functionRETURN Return from SubroutineRUN Execute ProgramSTATIC Declare Local Variable(s)SUB...END SUB Define Subprogram

Device input/output----------------------------------CLOSE Close File or DeviceCLS Clear ScreenCSRLIN Line Position of CursorINKEY$ Most Recent Character at KeyboardINP Read from an I/O PortINPUT Get Input from KeyboardINPUT$ Read Specified Number of CharactersIOCTL Send Control String to Device DriverIOCTL$ Read Control String from Device DriverKEY Set or Display Soft KeysLINE INPUT Read Line from Keyboard, Ignoring DelimitersLOC Current File PositionLOCATE Position the Cursor

Page 4: QuickBASIC 3

4

LPOS Current Position of Print HeadLPRINT Output to LPT1:LPRINT USING Formatted Output to LPT1:OPEN "COM... Open a Communications FileOUT Send Byte to Output PortPOS Current Cursor Column PositionPRINT Display on ScreenPRINT USING Formatted Screen DisplayRESET Close All Disk FilesSCREEN Character at Specified Location (Function)SPC Skip n Spaces in a PRINT statementTAB Tab to a Specified PositionVIEW PRINT Set Screen Text WindowWAIT Wait for Port StatusWIDTH Set Output WidthWRITE Output to Screen

Display graphic images----------------------------------CIRCLE Draw Ellipse on ScreenCOLOR Set Foreground, Background, and Border ColorsDRAW Draw ObjectGET Read Points from Screen (Graphics)LINE Draw Line or BoxPAINT Fill an Area with a Pattern or ColorPALETTE Change Color in the PalettePALETTE USING Change Many Colors in the PalettePCOPY Copy Screen PagePMAP Map Physical Coordinates to WorldPOINT Attribute or Value at Screen LocationPRESET Draw Point on ScreenPSET Draw Point on ScreenPUT Plot Array Image on Screen (Graphics)SCREEN Set Screen Attributes (Statement)VIEW Define Screen WindowWINDOW Redefine Screen Coordinates

DOS file system commands----------------------------------CHDIR Change DirectoryENVIRON Modify Environment TableENVIRON$ Environment Table EntryFILES Display File DirectoryKILL Delete File(s)MKDIR Create SubdirectoryNAME Rename FileRMDIR Remove SubdirectorySHELL Execute DOS Command

File input/output----------------------------------BINARY Used in an OPEN statement to specify binary file mode.BLOAD Load Binary (Memory Image) FileBSAVE Save a Binary (Memory Image) FileCLOSE Close File or DeviceEOF End of File StatusFIELD Allocate Space for Random File VariablesFILEATTR Returns information about an open fileFREEFILE Returns the next free BASIC file numberGET Read Random File into Buffer (File I/O)INPUT # Get Input from Sequential File or DeviceINPUT$ Read Specified Number of CharactersKILL Delete File(s)LINE INPUT# Read Line from File, Ignoring DelimitersLOC Current File PositionLOCK Control File or Record AccessLOF Length of FileLSET Left-Justify Data in Field VariableNAME Rename FileOPEN Allow File or Device I/OPRINT # Output to Sequential FilePRINT # USING Formatted Output to FilePUT Write Record from Random Buffer to File (File I/O)RSET Right-Justify Data in Field VariableSEEK Function that returns the current file positionUNLOCK Remove File or Record Access Lock

Page 5: QuickBASIC 3

5

WRITE # Output to Sequential File

Menage memory----------------------------------BLOAD Load Binary (Memory Image) FileBSAVE Save a Binary (Memory Image) FileCLEAR Close Files, Reset Variables, Set Stack SpaceDEF SEG Define SegmentFRE Available MemoryPEEK Value at Specified AddressPOKE Write Byte to MemorySADD String AddressVARPTR Offset of Variable or Offset of File BufferVARPTR$ Offset of Variable, in Character Form

Manipulate strings----------------------------------ASC ASCII Value of First CharacterCHR$ Convert ASCII Code to CharacterCVD Convert String to Double-PrecisionCVDMBF MBF Double-Precision String to IEEE (QB87 only)CVI Convert String to IntegerCVS Convert String to Single PrecisionCVSMBF MBF Single-Precision String to IEEE (QB87 only)HEX$ Hexadecimal Value, as StringINSTR Find SubstringLCASE$ Returns a string with all letters in lower-caseLEFT$ Substring at LeftLEN Length of StringLSET Left-Justify Data in Field VariableLTRIM$ Returns a copy of a string with leading spaces removedMID$ Assign Substring (Statement)MID$ Substring in Middle (Function)MKD$ Convert Double-Precision to StringMKDMBF$ IEEE Double-Precision to MBF String (QB87 only)MKI$ Convert Integer to StringMKS$ Convert Single-Precision to StringMKSMBF$ IEEE Single-Precision to MBF String (QB87 only)OCT$ Octal Value, as StringRIGHT$ Substring at RightRSET Right-Justify Data in Field VariableRTRIM$ Returns a string with trailing (right-hand) spaces removedSPACE$ String of n SpacesSTR$ String Representation of Numeric ExpressionSTRING$ String of Specified Length and CharacterUCASE$ Returns a string expression with all letters in uppercaseVAL Numeric Value of a String

Perform mathematical calculations----------------------------------ABS Absolute ValueATN ArctangentCDBL Convert to Double PrecisionCINT Convert to IntegerCLNG Converts long (4-byte) integer by rounding the fractional part ofthe expressionCOS CosineCSNG Convert to Single PrecisionDEF FN Define FunctionEXP Exponent (Natural)FIX Truncate to IntegerINT Next Lower IntegerLBOUND Lower Bound of Array DimensionLOG Natural LogarithmRANDOMIZE Reseed Random Number GeneratorRND Random NumberSGN Sign of NumberSIN SineSQR Square RootTAN TangentUBOUND Upper Bound of Array Dimension

Set traps for events and errors----------------------------------COM(n) Enable/Disable Comm Port TrappingERDEV Critical Error Code

Page 6: QuickBASIC 3

6

ERDEV$ Device Causing Critical ErrorERL Line Number of Most Recent ErrorERR Error NumberERROR Force ErrorKEY(n) Enable/Disable Key TrappingON COM Trap for Communications ActivityON ERROR Enable Error TrappingON KEY Trap for KeypressON PEN Trap for Light Pen ActivityON PLAY(n) Trap for Background Music RemainingON STRIG(n) Trap for Specified Joystick ButtonON TIMER Trap for Elapsed TimePEN Enable/Disable Pen Read and Trap (Statement)PEN Light Pen Status (Function)PLAY Enable/Disable Music Trap (Statement)RESUME Continue after Error TrapSTRIG Enable/Disable the STRIG Function (Statement)STRIG Status of Joystick Buttons (Function)TIMER Enable/Disable Timer Trap (Statement)

Time----------------------------------DATE$ Get or Set System DateTIME$ 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 SpeakerPLAY Enable/Disable Music Trap (Statement)PLAY Number of Notes in Background Buffer (Function)PLAY Play Music (Statement)SOUND Sound the Speaker

Ostalo----------------------------------$INCLUDE Include FileCOMMAND$ Get Command LineTROFF Trace OffTRON Trace On

Page 7: QuickBASIC 3

7

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

1

Page 8: QuickBASIC 3

8

' 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 A numeric expression.

ANY Clause(QuickBasic 4.5)

variable AS ANY

When used as the variable type in an AS type clause that is partof a procedure declaration, ANY disables type checking for thatparameter.

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.

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

Page 9: QuickBASIC 3

9

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 A string expression that follows DOS file naming conventions; may include any device, except "KYBD:".

offset 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. Inbinary mode, you may read or write information to any byte position inthe 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

Page 10: QuickBASIC 3

10

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 or more parameters to be passed to the subprogram or routine. Parameters must be separated by commas. Array parameters should be specified by the array name followed 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.

Page 11: QuickBASIC 3

11

name 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.

arglist Specifies one or more parameters to be passed to the subprogram or subroutine. Parameters must be separated by commas. Array parameters should be specified by the array name followed 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.

Page 12: QuickBASIC 3

12

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 If included, coordinates are relative to last graphics point referenced (LPR). If omitted, coordinates are absolute.

x,y The center (column, row) of the ellipse in pixels.

radius 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 Ending angle of arc, in radians. Defaults to 2..

aspect 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: Omitting start and end will draw a complete circle.

Page 13: QuickBASIC 3

13

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 CLNGa conversion function that converts a numeric expression to a long (4-byte) integerby 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 to2,147,483,647, the function produces an error message that reads"Overflow."

Example:

The following example shows how CLNG rounds before convertingthe number:

A=32767.45B=32767.55PRINT CLNG(A); CLNG(B)

Sample Output

32767 32768

See Also: CINT CSNG CDBL

CLOSE Close File or Device

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

Page 14: QuickBASIC 3

14

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]] ' Screen mode 0 COLOR [background] [,[palette] ' Screen mode 1 COLOR [foreground] [,[background]] ' 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).

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

Page 15: QuickBASIC 3

15

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 Color Value Color 0 Black 8 Gray 1 Blue 9 Light blue 2 Green 10 Light green 3 Cyan 11 Light cyan 4 Red 12 Light red 5 Magenta 13 Light magenta 6 Brown 14 Yellow 7 White 15 Bright white

Add 16 to a value to produce its blinking equivalent.

Foreground attributes for the Monochrome Display Adapter

Value Foreground Attribute 0 Black 1 Underlined 2-7 White 8 Black 9 Underlined high intensity 10-15 High-intensity white 16 Black 17 Underlined black 18-23 Blink 24 Black 25 Blinking underlined high intensity 26-31 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 (Text mode) The foreground color must be in the range 0 to 31. The background color must be in the range 0 to 7. The 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 Palette 0 Palette 1 0 Current background Current background 1 Green Cyan 2 Red Magenta 3 Brown 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.

Page 16: QuickBASIC 3

16

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 Must be 1, for COM1:, or 2, for COM2:.

ON Causes QB to check for communications activity.

OFF Causes QB not to check for communications activity. This is the default condition.

STOP 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: If the "Checking Between Statements" option is in effect, QB checks for communication activity after each statement.

Page 17: QuickBASIC 3

17

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 integer- constant 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

Page 18: QuickBASIC 3

18

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.

Page 19: QuickBASIC 3

19

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

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 command- line 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

Page 20: QuickBASIC 3

20

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 command- line 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$ ' Get the system date DATE$ = stringexpr ' Set the system date

Gets or Sets the current system date.

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

Page 21: QuickBASIC 3

21

"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 invokesargument type checking

(QuickBasic 4.5)

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

Argument Description name 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 youcall SUB procedures without the CALL keyword, or if you invoke aFUNCTION defined in another module.

A DECLARE statement also causes the compiler to check the number andtype of arguments used to invoke the procedure. QuickBASICautomatically generates DECLARE statements when you save your programwhile working in the environment. The DECLARE statement can appearonly in module-level code (not in a SUB or FUNCTION) and affects theentire module.

The parameterlist serves as a prototype for checking the numberand type of the arguments in SUB and FUNCTION calls. It has thefollowing syntax:

variable[AS type][,variable[AS type]]...

A variable is any valid BASIC variable name. If the variable is anarray, 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 auser-defined type. Again, only the number and types of arguments aresignificant.

Page 22: QuickBASIC 3

22

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 typecharacter ( %, &, !, #, or $) or by relying on the default type.

The form of the parameter list determines whether or not argumentchecking 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 declarereferences to procedures written in other programming languages, such as C

Example:

DECL_EX.BAS is a program file in the subdirectory ADVR_EX that illustratesthe DECLARE statement for BASIC procedures. To look at the program in theView window and, optionally, to run it, load the program using the Filemenu's Open Program command.

In the program, use of the DECLARE statement allows a SUB to be invokedwithout 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: For numeric functions, the precision specified by name determines the precision returned by the function.

Page 23: QuickBASIC 3

23

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: 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. DEFDBL 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 type- identifier 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

Page 24: QuickBASIC 3

24

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 type- identifier 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 An optional attribute. Arrays DIMensioned in a main program as SHARED may be shared with all subprograms that are compiled with that main program.

Page 25: QuickBASIC 3

25

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

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 An optional means to escape from the loop before its termination.

LOOP 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

Page 26: QuickBASIC 3

26

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

Page 27: QuickBASIC 3

27

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 exists in the environment table, its current setting is replaced with the new setting. If name does not exist, the new statement is added at the end of the environment 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 A string expression specifying an environment parameter.

n 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

Page 28: QuickBASIC 3

28

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).

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

Page 29: QuickBASIC 3

29

Notes: If the device is a character device, ERDEV$ returns the eight-bit device name. If the device is a block device, ERDEV$ returns a two-character string consisting of the drive letter and 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 ErrorERROR 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 error- trapping routines.

See Also: ERL ERR ON ERROR RESUME

Page 30: QuickBASIC 3

30

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 The number under which the file was OPENed.

fieldwidth The number of character positions to be allotted to stringvar.

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

Page 31: QuickBASIC 3

31

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 Description filenumber 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 modeswhen the value of attribute is 1.

Return Value Mode 1 INPUT 2 OUTPUT 4 RANDOM 8 APPEND 32 BINARY

Example:

The following example opens two files and prints out the DOS filehandles and modes returned by FILEATTR:

OPEN "tempfile.dat" FOR APPEND AS #1OPEN "tempfl2.dat" FOR RANDOM AS #2PRINT "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 DirectoryFILES [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 *.*.

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

Page 32: QuickBASIC 3

32

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 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.

start A numeric expression; the starting value of counter.

end A numeric expression; the ending value of counter.

increment 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.

Page 33: QuickBASIC 3

33

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 a file I/O function that returns the next free BASIC file number(QuickBasic 4.5)

FREEFILE

You can use this function to avoid having SUB or FUNCTION procedures usefile numbers that are already in use.

Example:

The example below uses FREEFILE to obtain a file number foropening a file:

INPUT "Enter file name ", Filename$Filenum = FREEFILEOPEN Filename$ FOR OUTPUT AS FilenumPRINT 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 codethat 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

Page 34: QuickBASIC 3

34

- Use of the keyword STATIC is a �Detail�

Details: Part Description name 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 beeither INTEGER, LONG, SINGLE, DOUBLE, STRING, or a user-defined type.

Earlier versions of BASIC required the number of dimensions inparentheses after an array name. The number of dimensions is no longerrequired. Only the parentheses are required to indicate the parameteris an array. For example, the following statement indicates that bothKeywords$ and KeywordTypes are arrays:

FUNCTION ParseLine(Keywords$(),KeywordTypes())

A FUNCTION procedure is like a SUB procedure: it can acceptparameters, perform a series of statements, and change the values ofits parameters. Unlike a SUB, a FUNCTION is used in an expression inthe 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 FUNCTIONunless it is declared as a shared variable in a SHARED statement,or unless the variable appears in a DIM or COMMON statementwith the SHARED attribute.

To return a value from a function, assign the value to the functionname. For example, in a function named BinarySearch, you mightassign the value of the constant FALSE to the name to indicatethe value was not found:

FUNCTION BinarySearch(...) CONST FALSE=0 . . .

' Value not found. Return a value of FALSE.

IF Lower>Upper THEN

Page 35: QuickBASIC 3

35

BinarySearch=FALSE EXIT FUNCTION END IF . . . END FUNCTION

Using the STATIC keyword slightly increases execution speed. STATIC isnot usually used with recursive FUNCTION procedures. See the examplesbelow.

The EXIT FUNCTION statement provides an alternative exit from aFUNCTION. See the EXIT statement.

Because BASIC may rearrange arithmetic expressions to attain greaterefficiency, avoid using FUNCTION procedures that change programvariables in arithmetic expressions. Also avoid using FUNCTIONprocedures that perform I/O in I/O statements.

QuickBASIC FUNCTION procedures are recursive--they can callthemselves to perform a given task. See the second example below.

Examples:

FUNC_EX.BAS is a program file in the subdirectory ADVR_EX that illustratesthe use of the FUNCTION statement. To look at the program in the View windowand, optionally, to run the program, load FUNC_EX.BAS using the File menu'sOpen Program command.

The program uses a recursive function (a function that calls itself) tofind 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 The number under which the file was OPENed.

recnum 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.

Page 36: QuickBASIC 3

36

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

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 Bitsperpixel SCREEN 1 2 SCREEN 2 1 SCREEN 7 4 SCREEN 8 4 SCREEN 9 2 (EGA memory = 64K) 4 (EGA memory > 64K) SCREEN 10 2

The amount of memory allocated per array element is as follows:

Integer: 2 bytes per element Single-precision: 4 bytes per element Double-precision: 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: The target of the GOTO must be at the same program level. That is, you cannot GOTO a subprogram, subroutine, or multiline function definition.

See Also: EXIT

Page 37: QuickBASIC 3

37

HEX$ Hexadecimal Value, as String

s$ = HEX$(numexpr)

Returns, as a string, the hexadecimal value of its argument.

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

numexpr A numeric expression in the range -32768 to 32767.

Notes: 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:

Page 38: QuickBASIC 3

38

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 Keyboards$ = 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 Terminates the program unless the Keyboard break option in the Options menu was turned off. Ctrl-Alt-Del Resets the computer system. Ctrl-NumLock Suspends the system. Shift-PrtScrn 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

Page 39: QuickBASIC 3

39

variables.

; 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.

prompt A string constant supplying a prompt to guide the user.

variable 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 The number under which the input file was OPENed. It may refer to a disk file, a communications file, or the keyboard (KYBD:).

variable The name of a variable (string or numeric) that will receive input.

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

Page 40: QuickBASIC 3

40

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 The number of characters to be read. Must be in the range 1 to 255.

filenum 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: 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

Page 41: QuickBASIC 3

41

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 The number under which the device driver was OPENed.

stringexpr 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.

Page 42: QuickBASIC 3

42

LIST KEY LIST displays the current soft key definitions on screen.

n, strexpr 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 Caps Lock active &H20 Num Lock active &H08 Alt key pressed &H04 Ctrl key pressed &H02 Left Shift key pressed &H01 Right Shift key pressed &H00 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 Function keys F1 through F10, F11, F12 11 Cursor Up 12 Cursor Left 13 Cursor Right 14 Cursor Down 15-25 Keys defined via KEY n, CHR$(KBflag) + CHR$(scancode)

ON 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.

OFF KEY(n) OFF deactivates trapping.

STOP 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: If the "Checking Between Statements" option is in effect,

Page 43: QuickBASIC 3

43

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 The name of an array.

dimension 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 operationswhere tests need to be case insensitive.

Example:

This example converts uppercase characters in a string to lowercase.

' Program to convert to lowercase.CLS ' Clear screenREAD Word$PRINT LCASE$(Word$);DATA "THIS IS THE STRING in lower case."

Page 44: QuickBASIC 3

44

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 A string expression.

n 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 A string expression. LET Assignment

[LET] variable = expression

Assigns the value of an expression to a variable.

variable A valid variable name.

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

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

Notes: The keyword LET is optional. LINE 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 If included, coordinates are relative to last graphics point referenced. If omitted, coordinates are absolute.

x1,y1 If ,B option is used, x1,y1 and x2,y2 are corner x2,y2 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.

Page 45: QuickBASIC 3

45

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.

; 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.

prompt A string constant supplying a prompt to guide the user.

stringvar 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 The number under which the file was opened.

stringvar 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.

Page 46: QuickBASIC 3

46

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 A numeric expression. If 1, the cursor is visible; if 0, the cursor is invisible.

start A numeric expression in the range 0 to 31. Sets the starting scan line for the cursor.

stop 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 The number under which the file was OPENed.

record The number of a record to be LOCKed or UNLOCKed.

start The number of the first record to be LOCKed or UNLOCKed.

end The number of the last record to be LOCKed or UNLOCKed.

Page 47: QuickBASIC 3

47

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

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: If filenum specifies a communications file, LOF returns the amount of free space in the communications buffer. LOG 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 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.

Page 48: QuickBASIC 3

48

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

EXIT DO An optional means to escape from the loop before its termination.

LOOP 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 LPT1: 2 LPT2: 3 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 return- line 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 80- character string (and do not follow the string expression with a semicolon), you will get two carriage return-line feed pairs.

See Also: PRINT

Page 49: QuickBASIC 3

49

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.

Page 50: QuickBASIC 3

50

^^^^ 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 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.

Double-precision numbers in IEEE format may have three- digit 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 A valid string variable name; specifies the variable into which stringexpr is to be left-justified.

stringexpr 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 andtrailing 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$

Page 51: QuickBASIC 3

51

OPEN InFile$ FOR INPUT AS #1OPEN 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 A string expression.

n A numeric expression in the range 1 to 32767;, specifies the character position from which the substring is to be extracted.

length 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

Page 52: QuickBASIC 3

52

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 A double-precision expression. MKI$ 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.

Page 53: QuickBASIC 3

53

singleexpr A single-precision expression. NAME 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: 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. NEXT 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 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.

start A numeric expression; the starting value of counter.

end A numeric expression; the ending value of counter.

increment 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

Page 54: QuickBASIC 3

54

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 communications- handling 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

Page 55: QuickBASIC 3

55

line of an error-trapping routine.

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

linelabel 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 Function keys F1 through F10 11 Cursor Up 12 Cursor Left 13 Cursor Right 14 Cursor Down 15-20 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

Page 56: QuickBASIC 3

56

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 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.

Page 57: QuickBASIC 3

57

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

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 button A1 2 button B1 4 button A2 6 button B2

linenum The first line of the joystick-handling subroutine. Setting linenum to 0 disables trapping.

linelabel 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)

Page 58: QuickBASIC 3

58

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 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.

linenum The first line number of a subroutine.

linelabel 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.

Page 59: QuickBASIC 3

59

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 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.

linenum A valid line number.

linelabel 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 A string expression that follows DOS file naming conventions.

filenum An integer expression in the range 1 to 255.

mode (Syntax 1) One of the following (default is RANDOM):

INPUT Sequential input OUTPUT Sequential output APPEND Sequential output, beginning at current EOF RANDOM Random input/output

access If included, must be one of the following:

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

lock 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.

Page 60: QuickBASIC 3

60

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

I Sequential input O Sequential output A Sequential output at EOF R 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 A numeric expression. Must be either 1, for COM1:, or 2, for COM2:. An asynchronous adapter must be installed.

filenum 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 If included, suppresses RTS (Request to Send). If not included, OPEN "COM..." automatically turns the RTS line on.

CSm If included, controls CTS (Clear to Send). m specifies, in

Page 61: QuickBASIC 3

61

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.

Page 62: QuickBASIC 3

62

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 If included, coordinates are relative to last graphics point referenced (LPR). If omitted, coordinates are absolute.

x,y Screen coordinate (column, row) within the area that is to be filled.

color 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.

boundary 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.

background 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 medium- resolution 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 Represents a color in the palette. The range of values depends on the screen mode (see below).

color Actual display color. The range of values depends on the screen mode (see below).

Attribute and Color Ranges

Mode Monitor Attribute Color 0 Mono/MDA N/A N/A Mono/EGA 0-15 0-2 Color/CGA N/A 0-31 Color/EGA 0-31 0-15 1 Color/CGA N/A 0-3 Color/EGA 0-3 0-15

Page 63: QuickBASIC 3

63

2 Color/CGA N/A 0-1 Color/EGA 0-1 0-15 7 Color/EGA 0-15 0-15 8 Color/EGA 0-15 0-15 9 EGA (64K) 0-3 0-15 EGA (>64K) 0-15 0-63 10 Mono/EGA 0-3 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 An integer array that containing the new colors in the palette. The array must consist of at least 16 elements.

arrayindex 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 Monitor Attribute Color 0 Mono/MDA N/A N/A Mono/EGA 0-15 0-2 Color/CGA N/A 0-31 Color/EGA 0-31 0-15 1 Color/CGA N/A 0-3 Color/EGA 0-3 0-15 2 Color/CGA N/A 0-1 Color/EGA 0-1 0-15 7 Color/EGA 0-15 0-15 8 Color/EGA 0-15 0-15 9 EGA (64K) 0-3 0-15 EGA (>64K) 0-15 0-63 10 Mono/EGA 0-3 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.

Page 64: QuickBASIC 3

64

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 Returns -1 if light pen has been down since last PEN function; otherwise returns 0. 1 Returns x coordinate of location where pen was most recently activated. 2 Returns y coordinate of location where pen was most recently activated. 3 Returns -1 if pen switch is currently down; otherwise returns 0. 4 Returns x coordinate of last known valid pen location. 5 Returns y coordinate of last known valid pen location. 6 Returns row position of location where pen was most recently activated. 7 Returns column position of location where pen was most recently activated. 8 Returns row position of last known valid pen location. 9 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).

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

Page 65: QuickBASIC 3

65

Notes: If the "Checking Between Statements" option is in effect, QB checks for light pen 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 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 A dummy; can be any value. PLAY 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 Name of a note to play. Case is not significant.

Nn 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

Page 66: QuickBASIC 3

66

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. The duration is specified in the same manner as for a note--i.e., as a reciprocal. To generate a rest in the current value of L, you may simply indicate a note number 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.

<A to <G Decrement the octave value by 1 and play the named note. The octave value stays at the decreased level. If the current octave is 0, < has no effect.

MF Run music in foreground.

MB Run music in background. Other program statements may be executed while music is running. Up to 32 notes may be held in the background music buffer at any time.

ML Music legato: Notes are played for their full specified duration.

MS Music staccato: Notes are played for 3/4 of their specified duration.

MN Music normal: Notes are played for 7/8 of their specified duration. This mode is default.

"=" + 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 "subtunes."

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

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.

Page 67: QuickBASIC 3

67

See Also: BEEP ON PLAY(n) PLAY (Event Trap) SOUND PMAP Map Physical Coordinates to World

y = PMAP(expr,function)

Converts a specified physical x or y coordinate to its world coordinate value, as defined by the WINDOW statement; or vice versa.

expr Specifies the x or y coordinate to be converted.

function A value in the range 0 to 3; specifies what the PMAP function is to do, as follows:

0 Maps world coordinate x to physical coordinate x 1 Maps world coordinate y to physical coordinate y 2 Maps physical coordinate x to world coordinate x 3 Maps physical coordinate y to world coordinate y

See Also: WINDOW POINT Attribute or Value at Screen Location

y = POINT({x,y | n})

Returns the attribute of a specified screen coordinate or coordinate information about the current screen location.

x,y Screen coordinates. POINT(x,y) returns the attribute of the screen location specified by the two arguments. The screen coordinates must be given in absolute form (STEP is not allowed). If either coordinate is out of range, POINT returns -1.

n Must be 0, 1, 2, or 3. POINT(n) returns the following information about the current screen location:

If n = 0 the current physical x coordinate. If n = 1 the current physical y coordinate. If n = 2 the current world x coordinate, if WINDOW is active; otherwise, the current physical x coordinate. If n = 3 the current world y coordinate, if WINDOW is active; otherwise, the current physical y coordinate. POKE Write Byte to Memory

POKE address,byte

Writes a specified byte at a specified memory offset within the current segment.

address A numeric expression in the range 0 to 1048575; 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.

byte A numeric expression in the range 0 to 255; specifies the data to be written at offset address.

See Also: PEEK POS Current Cursor Column Position

y = POS(column)

Returns the column position of the current cursor location.

column A dummy. Any numeric or string expression may be used.

See Also: CSRLIN LPOS

Page 68: QuickBASIC 3

68

PRESET Draw Point on Screen

PRESET [STEP] (x,y) [,color]

Plots a point at a specified screen location.

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

x,y Screen coordinates.

color Specifies the attribute of the point to be plotted. If color is omitted, the point is plotted in the background color.

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

Notes: PSET is exactly the same statement, except that it plots by default in the current foreground color.

See Also: PSET PRINT Display on Screen

PRINT [exprlist][{, | ;}]

Displays one or more numeric or string expressions on screen.

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: QuickBASIC divides the screen into zones of 14 character positions. If an expression is followed by a comma, QuickBASIC displays the next expression at the beginning of the next screen zone. If an expression is followed by a semicolon or space character, QuickBASIC displayed the next expression directly after the last expression.

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 its usual carriage return-line feed pair. Otherwise, QuickBASIC issues a carriage return and line feed after executing a PRINT statement.

QuickBASIC also issues a carriage return and line feed if the display of a list of expressions reaches the character position specified by the most recent WIDTH statement (or column 80, if no WIDTH statement has been executed).

Numbers are always followed by a space on the right. Positive numbers are preceded by a space, and negative numbers are preceded by a minus sign.

If no list of expressions is supplied, PRINT just issues a carriage return and line feed.

Note that QuickBASIC does not allow the use of ? as a synonym for PRINT.

See Also: LPRINT PRINT # PRINT USING PRINT # USING PRINT # Output to Sequential File

Page 69: QuickBASIC 3

69

PRINT #filenum, [exprlist] [;]

Writes to a specified disk file an image of what would be displayed on screen by a corresponding PRINT statement.

filenum The number under which the file was opened for output.

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: PRINT # outputs exactly the same characters that would appear on screen in response to a PRINT statement. Commas between expressions, for example, result in the insertion of space.

If an expression to be output contains significant quote marks or commas, you should surround it with quote marks by means of CHR$(34); otherwise, when you input these fields, QuickBASIC will interpret the significant commas or quotes as delimiters.

See Also: PRINT PRINT # USING PRINT # USING Formatted Output to File PRINT #filenum, USING strexpr; exprlist[;]

Writes to a specified disk file an image of what would be displayed on screen by a corresponding PRINT USING statement.

filenum The number under which the file was OPENed.

strexpr 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 strexpr:

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, QuickBASIC 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, QuickBASIC rounds. If the numeric expression has more digits to the left of the decimal point than the format string has #s, QuickBASIC 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

Page 70: QuickBASIC 3

70

expression has fewer digits to the left of the decimal point than the format string has #s, QuickBASIC 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.

^^^^ 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: PRINT # USING outputs exactly the same characters that would appear on screen in response to a PRINT USING statement. Commas between expressions, for example, result in the insertion of space.

If an expression to be output contains significant quote marks or commas, you should surround it with quote marks by means of CHR$(34); otherwise, when you input these fields, QuickBASIC will interpret the significant commas or quotes as delimiters.

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

See Also: PRINT USING PRINT USING Formatted Screen Display

PRINT USING strexpr; exprlist [;]

Displays one or more string or numeric expressions, in a specified format, on screen.

Page 71: QuickBASIC 3

71

strexpr 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 strexpr:

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, QuickBASIC 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, QuickBASIC rounds. If the numeric expression has more digits to the left of the decimal point than the format string has #s, QuickBASIC 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, QuickBASIC 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.

^^^^ 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.

Page 72: QuickBASIC 3

72

[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 in a PRINT USING statement, unless the expression is followed by a semicolon.

QuickBASIC assumes a maximum line length of 80 characters, unless a different value has been specified by means of a WIDTH statement. QuickBASIC sends a carriage return-line feed pair when the maximum line length has been reached.

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

See Also: LPRINT LPRINT USING PRINT PRINT # PRINT # USING PSET Draw Point on Screen

PSET [STEP] (x,y) [,color]

Plots a point at a specified screen location.

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

x,y Screen coordinates.

color Specifies the attribute of the point to be plotted. If color is omitted, the point is plotted in the current foreground color.

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

Notes: PRESET is exactly the same statement, except that it plots by default in the background color.

See Also: PRESET PUT Write Record from Random Buffer to File File I/O

PUT [#]filenum [,number]

Writes a specified record from a specified random file buffer to disk.

filenum The number under which the file was OPENed.

number A numeric expression in the range 1 to 16 megabytes, specifying the number of the record to be transferred. Defaults to the next record, or record 1 (if no previous record has been PUT).

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

Notes: If filenum specifies a communications device, number specifies the number of bytes to write; number in this case may not exceed the value of LEN given when the communications device was OPENed.

See Also: GET (File I/O)

Page 73: QuickBASIC 3

73

PUT Plot Array Image on Screen Graphics

PUT (x,y), array [,action]

Transfers data from a numeric array to a specified location within the (graphics) screen buffer.

x,y The coordinates of the upper left corner of the screen area that will receive the array image.

array A numeric array.

action An optional argument that allows you to control the interaction of the incoming data with the data currently in the screen buffer. Must be one of the following:

PSET Replaces each screen location with data from the array.

PRESET Replaces current screen values with values that are complementary to those held in the array. In medium resolution, a value of 0 in the array plots an attribute of 3, and vice versa. A value of 1 in the array plots an attribute of 2, and vice versa. In high resolution, a value of 0 in the array plots an attribute of 1, and vice versa.

XOR Array values are XORed with current screen values. This is the default action.

OR Array values are ORed with current screen values.

AND Array values are ANDed with current screen values.

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

Notes: Coordinates outside the current screen or window will produce a runtime error when PUT is executed.

See Also: GET (Graphics) RANDOMIZE Reseed Random Number Generator

RANDOMIZE [expression] or RANDOMIZE TIMER

Supplies a new seed for the pseudo-random number generator.

expression A numeric expression; a seed for the random number generator.

TIMER If the keyword TIMER is supplied as argument, QuickBASIC gets a new seed from the internal clock.

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

Notes: If no argument is given, QuickBASIC prompts for a number between -32768 and 32767. Each random number seed produces a unique sequence of random numbers, but the same seed always produces the same sequence. READ Assign DATA Items to Variables

READ variable [,variable]...

Assigns values in DATA items to specified variables.

variable A numeric or string variable, or an array element.

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

Page 74: QuickBASIC 3

74

Notes: A single READ statement can assign multiple DATA items to multiple variables; or several READ statements can assign the same DATA item to several variables.

Unless a RESTORE statement is executed, QuickBASIC moves to the next DATA item with each READ assignment. If QuickBASIC runs out of DATA items to READ, an Out of Data error occurs.

If the variable and the data item do not match in type, a Syntax Error occurs.

See Also: DATA RESTORE REDIM Redimension Array REDIM [SHARED] arrayname(subscripts) [arrayname(subscripts)...]

Changes the size of the dimensions in one or more dynamic arrays.

arrayname The name of a dynamic array.

subscripts The new dimensions of an array.

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

Notes: Only dynamic arrays may be REDIMensioned. To declare an array dynamic, use a variable in its original DIM statement, or use the $DYNAMIC metacommand.

The size of array dimensions may be changed via REDIM, but the number of dimensions may not.

When REDIM is executed, all array elements are reinitialized to 0 (numeric) and null (string).

See Also: DIM ERASE REM Comment or Metacommand

REM [remark] or REM $METACOMMAND: argument

Adds explanatory commentary to a program listing or issues a compiler metacommand.

remark Commentary text, ignored by QuickBASIC.

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

Notes: QuickBASIC does not execute REM statements, but a program may branch to a REM statement; execution continues with the first executable statement following the REM.

A REM statement must be the last statement in a program line (QuickBASIC ignores everything after the REM keyword).

A single quote mark (apostrophe) can is equivalent to REM, with the following exceptions:

A single quote can be used to attach a comment at the end of an existing program statement. A REM comment cannot written this way; it must be in a program statement by itself.

A single quote cannot be used before a metastatement.

See Also: $DYNAMIC $INCLUDE $STATIC '

Page 75: QuickBASIC 3

75

RESET Close All Disk Files

RESET

Closes all disk files and flushes all buffers.

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

Notes: The difference between RESET and CLOSE (with no file numbers) is that CLOSE closes both disk files and other I/O devices; RESET closes disk files only.

See Also: CLOSE RESTORE Reset DATA Item Pointer

RESTORE [{linenum | linelabel}]

Resets the DATA item pointer to the first item in the first DATA statement or to the first DATA item in a specified DATA statement.

linenum A program line number.

linelabel A valid line label.

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

Notes: If the statement at {linenum | linelabel} is not a DATA statement, BASIC RESTOREs to the first following DATA statement. RESUME Continue after Error Trap RESUME [0] or RESUME NEXT or RESUME {linenum | linelabel}

Allows program execution to continue after an ON ERROR GOTO routine has run.

0 RESUME by itself or with the optional dummy argument 0 causes the program to continue from the line that produced the error.

NEXT RESUME NEXT causes program execution to continue at the line following the line that produced the error.

linenum RESUME {linenum | linelabel} causes program execution to linelabel continue at a specified line number.

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

Notes: All ON ERROR GOTO routines must end with some form of RESUME statement.

A RESUME that is not part of an error trapping routine produces a RESUME without Error error.

See Also: ON ERROR RETURN Return from Subroutine RETURN [{linenum | linelabel}]

Transfers program execution from a subroutine to the line following the GOSUB, or to another specified line.

linenum A program line number.

linelabel A valid line label.

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

Page 76: QuickBASIC 3

76

Notes: {linenum | linelabel}, if used, must refer to a line at the same program level from which the subroutine was called.

See Also: GOSUB RIGHT$ Substring at Right

RIGHT$(strexpr,n)

Returns the rightmost n characters of a string.

strexpr A string expression.

n A numeric expression.

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

Notes: If n is larger than LEN(strexpr), RIGHT$ returns all of strexpr.

If n is 0, RIGHT$ returns a null string.

See Also: LEFT$ MID$ (Function) RMDIR Remove Subdirectory

RMDIR pathname

Removes a specified subdirectory.

pathname A string expression, of 127 or fewer characters, that follows DOS path-naming conventions.

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

Notes: The specified subdirectory must be empty.

See Also: CHDIR MKDIR RND Random Number

y = RND[(n)]

Generates a single-precision random number in the range of 0 to 1.

n A numeric expression.

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

Notes: If n is omitted or is positive, RND returns the next random number in the current sequence.

If n is 0, RND returns the last (most recent) random number in the current sequence.

If n is negative, BASIC uses n to reseed the random number function. The first number in the reseeded random number series is returned.

See Also: RANDOMIZE RSET Right-Justify Data in Field Variable

RSET fieldvar = strexpr

Right-justifies string data in a specified field of the random buffer, in preparation for a PUT statement. Or right-justifies string data in an ordinary string variable.

Page 77: QuickBASIC 3

77

fieldvar A variable defined in a FIELD statement; specifies the variable into which strexpr is to be right-justified.

strexpr A string expression.

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

Notes: If LEN(strexpr) is less than LEN(fieldvar), then fieldvar is padded on the left with space characters.

See Also: LSET PUT (File I/O)

RTRIM$ Rreturns a string with trailing (right-hand) spaces removed(QuickBasic 4.5)

RTRIM$(stringexpression)

The stringexpression can be any string expression.

The RTRIM$ function works with both fixed- and variable-length stringvariables.

Example:

This example shows the effects of RTRIM$ on fixed- and variable-lengthstrings.

DIM FixStr AS STRING * 10CLS ' Clear screenPRINT " 1 2"PRINT "12345678901234567890"FixStr = "Twine"PRINT FixStr + "*"PRINT RTRIM$(FixStr) + "*"VarStr$ = "Braided" + SPACE$(10)PRINT VarStr$ + "*"PRINT RTRIM$(VarStr$) + "*"

Output

1 212345678901234567890Twine *Twine*Braided *Braided*

See Also: LTRIM$

RUN Execute Program

RUN [{linenum | filespec}]

Executes the current program from the beginning or from a specified line number; or loads a program from disk and runs it.

linenum A program line number.

filespec A string expression that follows DOS file naming conventions.

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

Notes: If no argument is given, Quick BASIC begins execution at the lowest numbered line. This line must be part of the main program (not in a subprogram or multiline function). Program execution may be started from a specified line number, but not from a specified alphanumeric label.

If a program is run from disk (RUN filespec), QuickBASIC first erases the program currently in memory. It also closes any files left open by the current program (the

Page 78: QuickBASIC 3

78

Interpreter's ,R option is not supported by QuickBASIC).

See Also: CHAIN SADD String Address

SADD(strexpr)

Returns the address of a string expression.

strexpr A string expression.

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

Notes: Strings may be relocated in memory during program execution, as a result of house-cleaning, opening or closing of files, or allocation of string variables.

See Also: FRE PEEK POKE VARPTR VARPTR$

SCREEN Character at Specified Location Function

y = SCREEN(row,column[,z])

Returns the ASCII or color information about a specified screen location.

row,col Absolute coordinates of a screen location.

z If omitted or 0, SCREEN returns the ASCII value of the character at row,col.

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

Notes: The z argument is valid only in text mode. SCREEN Set Screen Attributes Statement

SCREEN [mode][,[colorflag]][,[apage]][,[vpage]]

Sets screen parameters for use by subsequent statements.

mode A numeric expression. Must be 0, 1, 2, 7, 8, 9, or 10. See table below.

colorflag A numeric expression. Turns color on or off for composite monitors (color is always on for RGB monitors). In text mode, a zero value turns color off; a nonzero value turns color on. Works the opposite way in medium-resolution graphics mode: A zero value turns color on, while a nonzero value turns color off. In screen mode 2, colorflag is irrelevant.

apage An integer expression specifying the active screen page (the page written to by statements that output to the screen). Valid only in screen modes 0, 7, 8, 9, and 10. Legal values depend on screen mode (see table below).

vpage An integer expression specifying the visual screen page (the page displayed on screen; may be different from the active page). Valid only in screen modes 0, 7, 8, 9, and 10. Legal values depend on screen mode (see table below).

Screen modes:

------------------------------------------------------------------------SCREEN 0 | 40 x 25 text | 16 colors, 2 attributes (CGA) | MDA, CGA, EGA | 80 x 25 text | 16 colors, 16 attributes (EGA |----------+--------------+-------------------------------+--------------SCREEN 1 | 320 x 200 | 16 colors, 4 attributes | CGA, EGA | 40 x 25 text | |

Page 79: QuickBASIC 3

79

----------+--------------+-------------------------------+--------------SCREEN 2 | 640 x 200 | 16 colors, 2 attributes | CGA, EGA | 80 x 25 text | |----------+--------------+-------------------------------+--------------SCREEN 7 | 320 x 200 | 16 colors, 16 attributes | EGA only | 40 x 25 text | 2 pages if 64K on EGA | | | 4 pages if 128K on EGA | | | 8 pages if 256K on EGA |----------+--------------+-------------------------------+--------------SCREEN 8 | 640 x 200 | 16 colors, 16 attributes | EGA only | 80 x 25 text | 1 page if 64K on EGA | | | 2 pages if 128K on EGA | | | 4 pages if 256K on EGA |----------+--------------+-------------------------------+--------------SCREEN 9 | 640 x 350 | 16 colors, 16 attributes | EGA only | 80 x 25 text | if >64K on EGA; | | in 8 x 14 | 16 colors, 4 attributes | | matrix | if 64K on EGA; | | | 2 pages if 256K on EGA |----------+--------------+-------------------------------+--------------SCREEN 10 | 640 x 350 | 9 pseudo colors, 4 attributes | EGA only | 80 x 25 text | 2 pages if 256K on EGA | | in 8 x 14 | | | matrix | |------------------------------------------------------------------------

Notes: All arguments are optional; omitted parameters retain former values.

All display pages share a single cursor. Therefore, it's advisable to save cursor position (with POS and CSRLIN) when switching pages.

If a valid SCREEN statement results in a new display mode, BASIC erases the screen and sets colors to white (foreground) on black (background and border). If a SCREEN statement does not produce a new display mode, BASIC does not erase the screen.

See Also: COLOR PALETTE PALETTE USING SEEK a file I/O function that returns the current file position

(QuickBasic 4.5)

SEEK(filenumber)

- filenumber is the number of an open random-access, sequential, or binary file. If random-access, the number returned by the SEEK function is a relative record number. If sequential or binary, it is a relative byte number

The filenumber is the number used in the OPEN statement to open the file.SEEK returns a value in the range 1 to 2,147,483,647 (equivalent to 2^31 -1).

SEEK returns the number of the next record read or written when used onRANDOM mode files. For files opened in BINARY, OUTPUT, APPEND, or INPUTmode, SEEK returns the byte position in the file where the next operationis to take place. The first byte in a file is 1.

When used on a device that does not support SEEK, the function returns zero.The BASIC devices (SCRN:, CONS:, KYBD:, COMn:, and LPTn:) do not supportSEEK.

The following code fragment prints a message indicating whether the lastread or write was done in the first, second, or final third of the file:

SELECT CASE (SEEK(1)) CASE IS < .333*LOF(1) PRINT "In first third of file." CASE .333*LOF(1) TO .667*LOF(1) PRINT "In second third of file." CASE IS >= .667*LOF(1) PRINT "In last third of file." CASE ELSE

Page 80: QuickBASIC 3

80

END SELECT

Example:

See the �SEEK statement programming example�, which uses both the SEEKfunction and the SEEK statement.

See Also: OPEN GET(File I/O) PUT(File I/O) SEEK statement

SELECT CASE Case Structure

SELECT CASE expression CASE testlist . . statements . [CASE testlist . . statements .] [CASE ELSE . . statements .] END SELECT

Compares an expression against one or more values and directs execution flow in accordance with the result.

expression An expression of any type.

testlist A comma-delimited list of expressions (see further description, below) that test the value of expression.

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

Notes: The elements of a given testlist argument are implicitly ORed. Therefore, the statements following CASE testlist are executed if any member of testlist is true. Following execution of those statements, control passes to the first statement following END SELECT.

The SELECT CASE structure may include any number of CASE testlist clauses but must include at least one. All CASE testlist clauses must appear before the optional CASE ELSE clause.

The statements following CASE ELSE are executed if all elements in all CASE testlist clauses are false.

The testlist argument may include the following kinds of tests: equality, inequality, greater than, less than, and range. Examples of each are as follows:

CASE 100 CASE IS = 100 CASE IS <> "Yomama" CASE IS > -5 CASE IS < 2E15 CASE 5 TO 10

Note that the = operator is optional for the equality test, and that the keyword IS must be used before any relational operator. In the range test, the smaller of the two values must appear before the keyword TO.

The SELECT CASE structure is equivalent to a set of nested IF/THEN/ELSE statements but produces more readable source code.

Page 81: QuickBASIC 3

81

SGN Sign of Number

y = SGN(numexpr)

Returns the sign of its numeric argument.

numexpr A numeric expression.

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

Notes: If numexpr is positive, SGN(numexpr) returns 1.

If numexpr is 0, SGN(numexpr) returns 0.

If numexpr is negative, SGN(numexpr) returns -1. SHARED Declare Global Variables SHARED varlist

Declares one or more variables in a subprogram global.

varlist A comma-delimited list of valid variable and/or array names; array names should be followed by empty parentheses.

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

Notes: The SHARED statement may be used only within a subprogram, and makes main program variables available only to the current subprogram.

The SHARED attribute, in contrast, may be used in a COMMON or DIM statement at the main program level to make variables accessible by all subprograms in a module.

The SHARED statement does not make variables available to library routines or subprograms compiled separately.

See Also: COMMON DIM SUB...END SUB SHELL Execute DOS Command

SHELL [commandstr]

Loads a secondary copy of COMMAND.COM and, optionally, executes an .EXE, .COM, or .BAT program, or an internal DOS command.

commandstr A string expression. If omitted, SHELL leaves the user at the DOS command prompt. To return to the QuickBASIC program, the user types EXIT.

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

Notes: If the SHELLed program is a batch file, its last statement should be EXIT.

Parameters may be passed to the SHELLed program in the usual DOS fashion. Any words in commandstr that are separated from the program name by one or more spaces are considered parameters for the SHELLed program.

It is not advisable to run TSR programs via SHELL. They may cause a crash on return to QuickBASIC.

After the specified DOS command or program terminates, control is returned to the line following the SHELL statement.

Page 82: QuickBASIC 3

82

SIN Sine

y = SIN(numexpr)

Returns the sine of the angle whose value, in radians, is expressed in numexpr.

numexpr A numeric expression.

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

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

SLEEP A control flow statement that suspends execution of the calling program(QuickBasic 4.5)

SLEEP [seconds]

- If the argument is omitted, the program is suspended until a key is pressed or an enabled event occurs - If the optional seconds argument is used, the program will stay suspended until the number of seconds elapses, a key is pressed, or an enabled event occurs, whichever happens first.

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

Notes: An event (such as ON COM or ON TIMER) cannot interrupt a SLEEP suspension unless its trapping is active when the event occurs. This means that trapping must have been initialized with an ON event statement, turned on with an event ON statement, and not have been disabled with an event OFF statement or an event STOP statement.

Example:

The following program suspends execution for 10 seconds. There is noON event statement, so the only way to interrupt the suspension before10 seconds have passed is to press a key.

CLS 'Clear the screenPRINT "Taking a 10 second nap..."SLEEP 10PRINT "Awake!"END

See Also: WAIT

SOUND Sound the Speaker

SOUND freq,duration

Sounds the speaker at a specified frequency for a specified length of time.

freq A numeric expression in the range 37 to 32767; specifies, in Hertz, the frequency (pitch) of the tone to be sounded.

duration A numeric expression in the range 0 to 65535. Specifies the length of time the tone is to be sounded, in units of clock ticks. Each clock tick is 1/18.2 (0.054945054) of a second.

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

Notes: QuickBASIC continues program execution while a tone is being sounded, unless a second SOUND statement is encountered--in which case, QuickBASIC waits until the first tone is finished, then begins executing the second SOUND statement. The MB parameter of the PLAY statement, however, can be used to enable buffering of SOUND statements.

Page 83: QuickBASIC 3

83

See Also: PLAY (Statement) SPACE$ String of n Spaces

s$ = SPACE$(n)

Returns a string consisting of a specified number of space characters.

n A numeric expression in the range 0 to 32767.

See Also: LSET PRINT USING RSET SPC STRING$ TAB SPC Skip n Spaces in a PRINT statement

PRINT SPC(n)

Skips a specified number of spaces in a PRINT, LPRINT, or PRINT # statement. n A numeric expression in the range 0 to 32767.

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

Notes: If n is larger than the width of the output device (as defined by WIDTH), QuickBASIC skips n MOD width spaces.

If the SPC function is used at the end of a list of items to print, QuickBASIC behaves as though the PRINT statement were terminated with a semicolon; it suppresses the usual carriage return and line feed.

See Also: SPACE$ TAB WIDTH SQR Square Root

y = SQR(n)

Returns the square root of a number.

n A positive numeric expression.

STATIC Declare Local Variable(s)

STATIC varlist

Declares one or more function or subprogram variables as local and memory-based (as opposed to stack-based).

varlist A comma-delimited list of valid variable and/or array names. Array names must be followed by an integer enclosed within parentheses; the integer specifies the number of dimensions in the array.

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

Notes: The STATIC statement may be used only within multiline function definitions and subprograms.

Variables used within multiline function definitions are global by default. Variables used within subprograms are local by default.

A STATIC variable is a local variable whose value doesn't change between subprogram CALLs. Ordinary local variables are reinitialized with each CALL. To guarantee that a variable's value will not change between CALLs, declare the variable STATIC.

The STATIC statement should not be confused with the STATIC attribute of the SUB statement (which indicates that a subprogram is nonrecursive) or the $STATIC

Page 84: QuickBASIC 3

84

metacommand (which statically allocates memory for arrays).

See Also: DEF FN SHARED SUB...END SUB STICK Joystick Coordinates

y = STICK(n)

Returns the x or y coordinate for joystick A or B.

n A numeric expression in the range 0 to 3. Determines what kind of information is returned, as follows:

0 Returns x coordinate of joystick A. A STICK(0) call must be performed before STICK(1), STICK(2), or STICK(3) can be used. 1 Returns the y coordinate of joystick A. 2 Returns the x coordinate of joystick B. 3 Returns the y coordinate of joystick B. STOP Halt Program

STOP

Stops program interruption and returns control to DOS or QuickBASIC.

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

Notes: There is no CONT statement in QuickBASIC. Therefore STOP is equivalent to END. STR$ String Representation of Numeric Expression

s$ = STR$(numexpr)

Returns the character representation of a number.

numexpr A numeric expression. If numexpr is positive, the string includes a leading space character (to accommodate a plus sign).

See Also: VAL STRIG Enable/Disable the STRIG Function Statement

STRIG {ON | OFF | STOP}

Enables or disables the use of the STRIG(n) function.

ON STRIG ON enables joystick trapping.

OFF STRIG OFF disables joystick trapping.

STOP STRIG STOP inhibits trapping. QuickBASIC continues checking the joysticks, however, and if an event occurs, a subsequent STRIG ON results in an immediate trap.

See Also: STRIG (Function) STRIG Status of Joystick Buttons Function

STRIG(n)

Returns status information about the joystick buttons.

n A numeric expression in the range 0 to 3. Determines the kind of information returned, as follows:

Page 85: QuickBASIC 3

85

0 Returns -1 if button A has been pressed since the most recent STRIG(0) call; otherwise, returns 0. 1 Returns -1 if button A is currently pressed; otherwise returns 0. 2 Returns -1 if button B has been pressed since the most recent STRIG(2) call; otherwise returns 0. 3 Returns -1 if button B is currently pressed; otherwise returns 0.

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

Notes: A STRIG ON statement must be executed before the STRIG(n) function can be used.

See Also: STICK STRIG (Statement) STRING$ String of Specified Length and Character

s$ = STRING$(m,n) or s$ = STRING$(m,stringexpr)

Returns a string of specified length, whose characters all have the same specified ASCII value.

m A numeric expression; specifies the length of the string.

n A numeric expression in the range 0 to 255; specifies the ASCII value of the character to be returned m times.

stringexpr A string expression. STRING$(m,stringexpr) returns the first character of stringexpr m times. SUB...END SUB Define Subprogram

SUB globalname [(parmlist)] STATIC . . . [EXIT SUB] . . . END SUB

Defines a subprogram.

globalname A variable name of 31 or fewer characters. globalname may not appear in any other SUB statement in the same program or in the user library.

parmlist One or more simple variables or arrays passed as parameters when the subprogram is CALLed. Names of array variables must be followed by an integer enclosed in parentheses; the integer specifies the number of dimensions in the array. Parameters are passed by reference.

STATIC Indicates that the subprogram is nonrecursive. QuickBASIC 3.0 does not support recursive subprograms, so the STATIC attribute is mandatory.

EXIT SUB Provides optional exit from within a subprogram.

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

Notes: Variables used within subprograms are local unless declared otherwise by means of a SHARED statement. Nevertheless, when a subprogram is exited and later reentered, the value of a local variable may have changed. To guarantee that a variable's value will not change between subprogram CALLs, declare the variable STATIC by means of a STATIC statement (not to be confused with the STATIC attribute of the SUB statement).

Page 86: QuickBASIC 3

86

You may not enter or exit a subprogram by means of GOSUB, GOTO, or RETURN.

See Also: CALL SHARED STATIC SWAP Exchange the Values of Two Variables

SWAP var1,var2

Exchanges the values of two variables. The arguments may be variables of any type, but they must match in type. SYSTEM Return to Operating System

SYSTEM

Closes all open files and returns control to DOS (for standalone EXE programs) or to QuickBASIC (for programs compiled and run from within QB).

See Also: END STOP TAB Tab to a Specified Position

PRINT TAB(column)

Moves to a specified print position. May be used in conjunction with PRINT, LPRINT, and PRINT #.

column A numeric expression.

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

Notes: If the current print (or screen) position is already to the right of column, TAB moves to position column on the next line.

If column is larger than the width of output device, TAB(column) moves to column MOD width.

If column is less than 1, TAB(column) is treated as TAB(1).

If the TAB function comes at the end of a list of data items in a PRINT statement, BASIC behaves as if the PRINT statement were terminated by a semicolon; it suppresses the usual carriage return and line feed.

See Also: SPACE$ SPC TAN Tangent

y = TAN(numexpr)

Returns the tangent of the angle whose value, in radians, is expressed in numexpr.

numexpr A numeric expression.

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

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

If TAN overflows, execution is halted, unless the error is trapped by an error-handling routine.

Page 87: QuickBASIC 3

87

TYPE A BASIC declaration that defines a data type containing one or more elements (QuickBasic 4.5)

TYPE usertype elementname AS typename [elementname AS typename] . . .

END TYPE

- usertype is a name that will identify the user-defined type. Use BASIC variable naming rules to coin this name. - elementname will identify this element of the user-defined type. Use BASIC variable naming rules. Cannot be the name of an array. - typename is INTEGER, LONG, SINGLE, DOUBLE, STRING*n (fixed-length string), or another user-defined type.

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

Note: Strings in user types must be fixed-length strings. String lengths are indicated by an asterisk and a numeric constant. For example, the following line defines an element named Keyword in a user-defined type as a string with length 40:

Keyword AS STRING * 40

A user-defined type must be declared in a TYPE declaration beforeit can be used in the program. Although a user-defined type can onlybe declared in the module-level code, you may declare a variable tobe of a user-defined type anywhere in the module, even in a SUBor FUNCTION.

Use the DIM, REDIM, COMMON, STATIC, or SHARED statements to declare avariable to be of a user-defined type.

Example:

TYPE_EX.BAS is a program file in the subdirectory ADVR_EX that illustratesthe TYPE...END TYPE statement. To look at the program in the View windowand, optionally, to run it, load the program using the File menu's OpenProgram command.

The program simulates a deck of cards by using a user-defined type. Theprogram builds a deck of cards (an array of user-defined type Card),shuffles the deck, and displays the first five cards. TIME$ Get System Time Functions$ = TIME$

Returns the current system time, as an eight-character string in the form hh:mm:ss. TIME$ Set System Time Statement

TIME$ = stringexpr

Sets the current system time.

stringexpr A string expression in the form "hh" or "hh:mm" or "hh:mm:ss". Leading 0s may be omitted in any of the three fields.

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

Notes: This command resets the AT system clock in nonvolatile memory when QuickBASIC is run under DOS 3.3.

See Also: TIME$ (Function)

Page 88: QuickBASIC 3

88

TIMER Number of Seconds since Midnight Function

y = TIMER

Returns, in single-precision, the number of seconds that have elapsed since midnight. TIMER Enable/Disable Timer Trap Statement

TIMER {ON | OFF | STOP}

Enables or disables event trapping via ON TIMER.

ON Causes QB to check the timer.

OFF Causes QB not to check the timer. This is the default condition.

STOP Also disables trapping, but QB continues checking. If the specified amount of time has elapsed, a subsequent TIMER ON results in an immediate trap (provided an ON TIMER statement with a nonzero line number has been executed).

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

Notes: 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: ON TIMER TROFF Trace Off

TROFF

Turns off trace mode.

See Also: TRON TRON Trace On TRON

Turns on trace mode.

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

Notes: In trace mode, QuickBASIC produces an animated trace, highlighting each program statement in reverse video as it's executed.

See Also: TROFF UBOUND Upper Bound of Array Dimension y = UBOUND(array[,dimension])

Returns the highest subscript for a given dimension of a given array.

array The name of an array.

dimension 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.

Page 89: QuickBASIC 3

89

See Also: LBOUND OPTION BASE UCASE$ a string processing function that returns a string expression with all letters in uppercase

(QuickBasic 4.5)

UCASE$(stringexpression)

Example:

UCASE_EX.BAS is a program file in the subdirectory ADVR_EX that illustratesthe UCASE$ function. To look at the program in the View window and,optionally, to run it, load it using the File menu's Open Program command.

The program contains a FUNCTION, YesQues, that returns a Boolean valuedepending on how the user responds. The FUNCTION YesQues uses UCASE$to make a case-insensitive test of the user's response.

See Also: LCASE$

UNLOCK Remove File or Record Access Lock

LOCK [#] filenum [,{record | [start] TO end}] . . [statements] . UNLOCK [#] filenum [,{record | [start] TO end}]

Removes a previously set file or record lock.

filenum The number under which the file was OPENed.

record The number of a record to be LOCKed or UNLOCKed.

start The number of the first record to be LOCKed or UNLOCKed.

end 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.

See Also: LOCK VAL Numeric Value of a String y = VAL(stringexpr)

Returns the numeric value represented by a string expression.

stringexpr A string expression.

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

Notes: VAL attempts to extract a number from the first characters of its argument. In doing so, it ignores leading blanks, tabs, and line feeds, and treats a single hyphen as signifying negation. For example, VAL(" -32 Main Street") returns -32.

Page 90: QuickBASIC 3

90

If the first character in the argument (or the first character following all space and tab characters) is a letter, VAL returns 0. Thus, for example, VAL("Yomama") returns 0.

See Also: ASC STR$ VARPTR Offset of Variable or Offset of File Buffer

VARPTR(variable) or VARPTR(#filenum)

Returns the offset address of a variable, or of a file I/O buffer, within the current data segment.

variable The name of a string or numeric variable, or an array element.

filenum The number under which a file was OPENed.

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

Notes: The offset returned is a single-precision value in the range 0 to 1048575. For variables, the offset is that of the first byte associated with the specified variable.

If the variable has not yet been used in an assignment statement, an Illegal Function Call error results.

When using VARPTR with array variables, be aware that array variables are moved in memory every time a new nonarray variable is assigned.

See Also: VARPTR$ VARPTR$ Offset of Variable, in Character Form

VARPTR$(variable)

Returns, in a character format, the offset address of a specified variable in the current data segment.

variable The name of a string or numeric variable, or an array element.

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

Notes: A three-byte string is returned. The first byte reports the variable type, the second reports the low-order portion of the variable address, and the third reports the high-order portion of the variable address. The type byte is coded as follows:

2 Integer 3 String 4 Single-precision 8 Double-precision

When using VARPTR$ with array variables, be aware that array variables are moved in memory every time a new nonarray variable is assigned.

See Also: VARPTR VIEW Define Screen Window

VIEW [[SCREEN][(x1,y1)-(x2,y2)[,[color][,[border]]]]]

Defines a screen subset, or viewport.

SCREEN If omitted, the coordinates of all subsequent graphics

Page 91: QuickBASIC 3

91

statements are measured relative to the defined viewport, whose upper left corner becomes 0,0. If included, 0,0 is still the upper left corner of the screen, but only those points that fall within the defined viewport are visible.

x1,y1,x2,y2 Corner coordinates of the viewport.

color If included, QuickBASIC fills the viewport with the specified color. Allowed values are 0 to 3 in medium resolution, 0-1 in high resolution.

border If included, QuickBASIC draws a border, in a specified color, around the defined viewport. Allowed values are 0 to 3 in medium resolution, 0-1 in high resolution.

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

Notes: QuickBASIC sorts the coordinates x1, x2, y1, and y2, so that the lower value of x and the lower value of y specify the upper left corner, regardless of how the coordinates are presented; i.e., VIEW (280,120)-(140,180) would be equivalent to VIEW (140,120)-(280,180).

VIEW with no argument redefines the viewport to the full screen.

Multiple viewports may be defined, but only the most recent definition is active.

A defined viewport is disabled by a RUN statement or a change in SCREEN attributes.

With a viewport in effect, CLS clears only the viewport, not the entire screen.

See Also: WINDOW VIEW PRINT Set Screen Text Window

VIEW PRINT [top TO bottom]

Sets the top and bottom boundaries of the screen text window.

top The top line of the screen text window. Defaults to 1.

bottom The bottom line of the screen text window. Defaults to 25.

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

Notes: VIEW PRINT limits scrolling and cursor movement to the area defined by top and bottom. WAIT Wait for Port Status

WAIT port, n[,m]

Suspends program execution until a specified bit pattern appears at a specified port address.

port A numeric expression in the range 0 to 65535; specifies the I/O port to test.

n,m Integer expressions in the range 0 to 255; they supply the test. m defaults to 0.

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

Notes: QuickBASIC gets the value at port, XORs it with m, then ANDs it with n. If the result is zero, the process is repeated. If the result is nonzero, program execution continues with the next statement.

To test for a 1 at a particular bit position in port, m

Page 92: QuickBASIC 3

92

should be omitted and n should have a 1 at the position in question. To test for a 0 in port, both n and m should have a 1 in the position in question.

Note that the test is considered positive if any nonzero value is returned. Therefore, to test for multiple bit positions, use multiple WAIT statements.

Warning: If port never develops a nonzero value, WAIT can put your system into an infinite loop. WEND End Definition of WHILE/WEND Loop

WHILE expression . . [statements] .

WEND

Terminates the definition of a WHILE/WEND loop.

expression A numeric expression.

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

Notes: QuickBASIC starts by evaluating expression. If expression is nonzero (true), the next statement is executed. If expression is zero (false), control passes to the first statement following the next WEND statement.

When QuickBASIC encounters the WEND statement, it reevaluates the expression argument to the most recent WHILE. If that argument is still nonzero (true), the process is repeated; otherwise, execution continues at the next statement.

WHILE-WEND loops may be nested to any level of complexity, but there must be a WEND for each WHILE.

See Also: DO FOR LOOP NEXT WHILE WHILE Begin Definition of WHILE/WEND Loop

WHILE expression . . [statements] . WEND

Begins the definition of a WHILE/WEND loop.

expression A numeric expression.

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

Notes: QuickBASIC starts by evaluating expression. If expression is nonzero (true), the next statement is executed. If expression is zero (false), control passes to the first statement following the next WEND statement.

When QuickBASIC encounters the WEND statement, it reevaluates the expression argument to the most recent WHILE. If that argument is still nonzero (true), the process is repeated; otherwise, execution continues at the next statement.

WHILE-WEND loops may be nested to any level of complexity, but there must be a WEND for each WHILE.

See Also: DO FOR LOOP NEXT WEND

Page 93: QuickBASIC 3

93

WIDTH Set Output Width

WIDTH [{#filenum | device},] width[,lines] or WIDTH LPRINT width

Sets the maximum width for a specified output device; QuickBASIC sends a carriage return to the device when the specified width has been reached.

width A numeric expression in the range 0 to 255. A value of 0 is equivalent to a value of 1.

device A string expression. Legal values are "SCRN:", "LPT1:", "LPT2:", "LPT3:", "COM1:", "COM2:", and their lowercase equivalents.

filenum A numeric expression in the range 1 to 15; specifies a file opened for output.

lines A numeric expression; must be either 25 or 43. This argument is valid only if device is "SCRN" or if the {#filenum | device} argument is omitted. lines allows you to specify 43-line screen mode on systems equipped with an EGA.

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

Notes: WIDTH size and WIDTH "SCRN:" size both set the screen width. In this case, size must be either 40 or 80 (only 80 is allowed on the IBM Monochrome Display).

WIDTH LPRINT width sets the width of all subsequent LPRINT output. WINDOW Redefine Screen Coordinates

WINDOW [[SCREEN](x1,y1)-(x2,y2)]

Specifies "world" coordinates for the screen.

SCREEN If omitted, x1,y1 and x2,y2 specify the upper left and lower right corners of the world space, respectively. If included, x1,y1 and x2,y2 specify the lower left and upper right corners of the world space, respectively.

x1,y1,x2,y2 The corner coordinates of the world space.

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

Notes: The WINDOW statement allows you to redefine the corners of the display screen as a pair of "world" coordinates. Because objects plotted by subsequent graphics statements are still plotted in the standard "physical" coordinates, the WINDOW statement provides a way of scaling, rotating, and/or transposing such objects.

BASIC sorts the coordinates so that the lower of x1 and y1 will be treated as x1 and the lower of y1 and y2 will be treated as y1, regardless of how the coordinates are presented. Thus WINDOW (280,120)-(140,180) would be equivalent to WINDOW (140,120)-(280,180).

A world space defined by WINDOW is disabled by a RUN statement, a change in SCREEN attributes, or a WINDOW statement with no arguments.

See Also: VIEW WRITE Output to Screen

WRITE [exprlist]

Displays numeric or string expressions on screen.

Page 94: QuickBASIC 3

94

exprlist Numeric or string expressions separated by commas or semicolons. QuickBASIC outputs a carriage return and line feed at the end of the list. If no items are included, a blank line is displayed.

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

Notes: Either semicolons or commas may be used as delimiters in exprlist (it makes no difference).

WRITE differs from PRINT in the following ways:

When the data items are displayed, each is separated from the one before it by a comma.

String expressions are displayed enclosed in quote marks.

Positive numbers are not preceded by blanks.

See Also: PRINT WRITE # WRITE # Output to Sequential File

WRITE #filenum,exprlist

Outputs one or more numeric or string expressions on screen.

exprlist Numeric or string expressions separated by commas or semicolons. QuickBASIC outputs a carriage return and line feed at the end of the list. If no items are included, a blank line is displayed.

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

Notes: Either semicolons or commas may be used as delimiters in exprlist (it makes no difference).

WRITE # differs from PRINT # in the following ways:

When the data items are displayed, each is separated from the one before it by a comma.

String expressions are output enclosed in quote marks.

Positive numbers are not preceded by blanks.

See Also: PRINT # WRITE

Operators Precedence Operator Precedence in BASIC

Operator Precedence

Highest: ^ - (negation) * / \ MOD + - = <> < > <= >= NOT AND OR XOR EQV Lowest: IMP

Operators have an inherent precedence. In the absence of explicit

Page 95: QuickBASIC 3

95

grouping (through parentheses), an expression is evaluated in the order dictated by this inherent precedence. Operators of the same precedence level are evaluated in left-to-right order.

All function calls in an expression are evaluated before any operators.

^ Exponentiation

exp1 ^ exp2

The ^ operator performs exponentiation. If the expression involves operands of more than one precision, all operands are converted to the same level--that of the highest-precision operand in the expression-- before the expression is evaluated.

exp1,exp2 Any numeric expression.

See Also: * - / \ MOD + Precedence * Multiplication

exp1 * exp2

The * operator performs multiplication. If the expression involves operands of more than one precision, all operands are converted to the same level--that of the highest-precision operand in the expression-- before the expression is evaluated.

exp1,exp2 Any numeric expression.

See Also: ^^ - / \ MOD + Precedence / Division

exp1 / exp2

The / operator performs floating-point division. If the expression involves operands of more than one precision, all operands are converted to the same level--that of the highest-precision operand in the expression--before the expression is evaluated.

exp1 Any numeric expression.

exp2 Any numeric expression that does not evalute to 0.

See Also: ^^ - * \ MOD + Precedence + Addition and Concatenation

Addition

exp1 + exp2

The + operator performs addition. If the expression involves operands of more than one precision, all operands are converted to the same level--that of the highest-precision operand in the expression--before the expression is evaluated.

exp1,exp2 Any numeric expression.

Concatenation

str1 + str2

The + operator also performs concatenation on string expressions. The result is a string composed of str1 followed by str2.

str1,str2 Any string expression.

Page 96: QuickBASIC 3

96

See Also: ^^ - * / \ MOD Precedence - Subtraction and Negation

Subtraction

exp1 - exp2

The - operator performs subtraction. If the expression involves operands of more than one precision, all operands are converted to the same level--that of the highest-precision operand in the expression-- before the expression is evaluated.

exp1,exp2 Any numeric expression.

Negation

- exp1

As a unary operator (placed before a single numeric expression), - performs negation; that is, it reverse the sign of its operand.

exp1 Any numeric expression.

See Also: ^^ * / \ MOD + Precedence \ Integer Division exp1 \ exp2

The \ operator performs integer division. The operands are rounded (not truncated) to integers before the division is performed, and the result is truncated (not rounded) to an integer. The operands must round to integers in the range -32768 through 32767.

exp1,exp2 Any numeric expression.

See Also: ^^ - * / \ MOD + Precedence MOD Modulo Arithmetic exp1 MOD exp2

The MOD operator performs modulo arithmetic. That is, it performs an integer division on its two operands (see \) and returns the remainder. The result is an integer.

exp1,exp2 Any numeric expression.

See Also: ^^ - * / \ MOD + Precedence = Equal to/Assignment

Equal to

exp1 = exp2

The = operator is a relational operator. If exp1 has the same value as exp2, the result of exp1 = exp2 is -1; otherwise the result is 0. In IF statements, BASIC regards 0 as equivalent to FALSE and all nonzero values as equivalent to TRUE.

exp1,exp2 Any numeric or string expression, but exp1 and exp2 must either both be numeric or both be strings; otherwise a Type Mismatch error occurs.

Assignment

Page 97: QuickBASIC 3

97

[LET] var = exp1

As an assignment operator, = stores the value of exp1 in variable var. The keyword LET is optional (and is usually omitted).

var A legal variable name, of any type.

exp1 Any numeric expression, but exp1 and exp2 must either both be numeric or both be strings; otherwise a Type Mismatch error occurs.

See Also: <> < > <= >= Precedence <> Not Equal to

exp1 <> exp2

The <> operator is a relational operator. If exp1 has a value different from that of exp2, the result of exp1 <> exp2 is -1; otherwise the result is 0. In IF statements, BASIC regards 0 as equivalent to FALSE and all nonzero values as equivalent to TRUE.

exp1,exp2 Any numeric or string expression, but exp1 and exp2 must either both be numeric or both be strings; otherwise a Type Mismatch error occurs.

See Also: = < > <= >= Precedence < Less than exp1 < exp2

The operator < is a relational operator. If the value of exp1 is less than that of exp2, the result of exp1 < exp2 is -1; otherwise the result is 0. In IF statements, BASIC regards 0 as equivalent to FALSE and all nonzero values as equivalent to TRUE.

If the operands are string expressions, BASIC compares the ASCII values of the first character in each expression. If the first characters have the same ASCII value, BASIC then evaluates the second characters, and so on. If one string terminates before the other, and the characters in each string are identical to that point, the shorter string is considered "less" than the longer one.

exp1,exp2 Any numeric or string expression, but exp1 and exp2 must either both be numeric or both be strings; otherwise a Type Mismatch error occurs.

See Also: = <> > <= >= Precedence > Greater than

exp1 > exp2

The > operator is a relational operator. If the value of exp1 is greater than that of exp2, the result of exp1 > exp2 is -1; otherwise the result is 0. In IF statements, BASIC regards 0 as equivalent to FALSE and all nonzero values as equivalent to TRUE.

If the operands are string expressions, BASIC compares the ASCII values of the first character in each expression. If the first characters have the same ASCII value, BASIC then evaluates the second characters, and so on. If one string terminates before the other, and the characters in each string are identical to that point, the shorter string is considered "less" than the longer one.

exp1,exp2 Any numeric or string expression, but exp1 and exp2 must either both be numeric or both be strings; otherwise a Type Mismatch error occurs.

Page 98: QuickBASIC 3

98

<= Less than or Equal to

exp1 <= exp2

The <= operator is a relational operator. If the value of exp1 is either less than that of exp2 or equal to that of exp2, the result of exp1 <= exp2 is -1; otherwise the result is 0. In IF statements, BASIC regards 0 as equivalent to FALSE and all nonzero values as equivalent to TRUE.

If the operands are string expressions, BASIC compares the ASCII values of the first character in each expression. If the first characters have the same ASCII value, BASIC then evaluates the second characters, and so on. If one string terminates before the other, and the characters in each string are identical to that point, the shorter string is considered "less" than the longer one.

exp1,exp2 Any numeric or string expression, but exp1 and exp2 must either both be numeric or both be strings; otherwise a Type Mismatch error occurs.

See Also: = <> < > >= Precedence >= Greater than or Equal to

exp1 >= exp2

The >= operator is a relational operator. If the value of exp1 is greater than that of exp2, the result of exp1 < exp2 is -1; otherwise the result is 0. In IF statements, BASIC regards 0 as equivalent to FALSE and all nonzero values as equivalent to TRUE.

If the operands are string expressions, BASIC compares the ASCII values of the first character in each expression. If the first characters have the same ASCII value, BASIC then evaluates the second characters, and so on. If one string terminates before the other, and the characters in each string are identical to that point, the shorter string is considered "less" than the longer one.

exp1,exp2 Any numeric or string expression, but exp1 and exp2 must either both be numeric or both be strings; otherwise a Type Mismatch error occurs.

See Also: = <> < > <= Precedence NOT Logical NOT

NOT exp1

NOT is a logical operator. BASIC converts the operand to an integer (the result of this conversion must lie within the range -32768 to 32767, or else an Overflow error occurs), then complements each bit of the result. That is, each resulting 1 bit becomes a 0 bit, and each resulting 0 bit becomes a 1 bit. The result is an integer.

Bitwise truth table for NOT:

exp1 NOT exp1 1 0 0 1

exp1 Any expression that produces a numeric result. This includes Boolean expressions, where a TRUE result is evaluated as -1 and a FALSE result is evaluated as 0.

See Also: AND OR XOR EQV IMP Precedence AND Logical AND

exp1 AND exp2

Page 99: QuickBASIC 3

99

AND is a logical operator. BASIC converts each operand to an integer (each operand must yield an integer in the range -32768 to 32767, or else an Overflow error occurs), then performs a bitwise comparison of the results, according to the truth table below:

exp1 exp2 exp1 AND exp2 1 1 1 1 0 0 0 1 0 0 0 0

The result is an integer.

exp1,exp2 Any expression that produces a numeric result. This includes Boolean expressions, where a TRUE result is evaluated as -1 and a FALSE result is evaluated as 0.

See Also: NOT OR XOR EQV IMP Precedence OR Logical OR

exp1 OR exp2

OR is a logical operator. BASIC converts each operand to an integer (each operand must yield an integer in the range -32768 to 32767, or else an Overflow error occurs), then performs a bitwise comparison of the results, according to the truth table below:

exp1 exp2 exp1 OR exp2 1 1 1 1 0 1 0 1 1 0 0 0

The result is an integer.

exp1,exp2 Any expression that produces a numeric result. This includes Boolean expressions, where a TRUE result is evaluated as -1 and a FALSE result is evaluated as 0.

See Also: NOT AND XOR EQV IMP Precedence XOR Logical Exclusive OR exp1 XOR exp2

XOR is a logical operator. BASIC converts each operand to an integer (each operand must yield an integer in the range -32768 to 32767, or else an Overflow error occurs), then performs a bitwise comparison of the results, according to the truth table below:

exp1 exp2 exp1 XOR exp2 1 1 0 1 0 1 0 1 1 0 0 0

The result is an integer.

exp1,exp2 Any expression that produces a numeric result. This includes Boolean expressions, where a TRUE result is evaluated as -1 and a FALSE result is evaluated as 0.

See Also: NOT AND OR EQV IMP Precedence EQV Equivalence

exp1 EQV exp2

EQV is a logical operator. BASIC converts each operand to an integer (each operand must yield an integer in the range -32768 to 32767, or

Page 100: QuickBASIC 3

100

else an Overflow error occurs), then performs a bitwise comparison of the results, according to the truth table below:

exp1 exp2 exp1 EQV exp2 1 1 1 1 0 0 0 1 0 0 0 1

The result is an integer.

exp1,exp2 Any expression that produces a numeric result. This includes Boolean expressions, where a TRUE result is evaluated as -1 and a FALSE result is evaluated as 0.

See Also: NOT AND OR XOR IMP Precedence IMP Implication

exp1 IMP exp2

IMP is a logical operator. BASIC converts each operand to an integer (each operand must yield an integer in the range -32768 to 32767, or else an Overflow error occurs), then performs a bitwise comparison of the results, according to the truth table below:

exp1 exp2 exp1 IMP exp2 1 1 1 1 0 0 0 1 1 0 0 1

The result is an integer.

exp1,exp2 Any expression that produces a numeric result. This includes Boolean expressions, where a TRUE result is evaluated as -1 and a FALSE result is evaluated as 0.

See Also: NOT AND OR XOR EQV Precedence

Data Types BASIC Data Types

Declaration Type Character * Range Accuracy Storage Integer % -32768 to 32767 Perfect 2 bytes Single precision ! 10E-38 to 10E38 6 digits 4 bytes Double precision # 10D-38 to 10D38 16 digits 8 bytes String $ See below

* Variables may also be typed by means of BASIC's DEFtype statements: DEFINT, DEFSNG, DEFDBL, and DEFSTR. Variables that are not explicitly typed are treated as single precision.

String storage: 4 bytes for descriptor, 1 byte for string back pointer, and 1 byte for each character in the string.

Switches and Options Command-Line Switches and Compiler Options

Command-line syntax:

QB [source] [/b] [/g] [/llibrary]] [c:buffsize] [options] [/cmdstring]

source A source code file that's loaded when QB is invoked.

Page 101: QuickBASIC 3

101

/b Turns off the color burst. For use with composite displays attached to CGAs.

/g Turns off snow suppression. Produces faster screen update, but may also produce snow. Has no effect on screens attached to Monochrome Display Adapters or EGAs.

/llibrary Loads a specified user library. The argument library defaults to USERLIB.EXE.

c:buffsize Specifies the size, in bytes, of the buffer for receiving communications data. Default: 256 bytes, maximum: 32767 bytes. The transmit buffer is fixed at 128 bytes.

options Specifies one or more compiler options. See below.

/cmdstring Passes arguments at run time to a memory-compiled program. Everything from /cmd to the carriage return is accessible via the COMMAND$ function.

Compiler options

/d Debug. Generates code that checks for arithmetic overflow, array bounds, RETURNs without GOSUBs, and Ctrl-Break. Also produces line number references for runtime errors and enables the use of TRON and TROFF.

/e On Error. For use when the program includes one or more ON ERROR GOTO linenumber constructions.

/MBF Microsoft Binary Format. Designed to be used with the math coprocessor version of QuickBASIC, /MBF reads data in files stored via previous versions of BASIC and converts it from Microsoft Binary Format to IEEE floating-point format. The files are converted as they are read in, and reconverted to MBF as they are written back to disk. An alternative to the use of CVSMBF and CVDMBF, the /MBF option allows you to preserve your original data files, so they may be accessed on machines without coprocessors.

/o Obj(BCOM.LIB). Produces an object file linked with selected routines from BCOM.LIB, instead of with BRUN.LIB. Programs compiled in this manner are likely to use less RAM and run faster, but take up more disk space. CHAIN and COMMON are not supported by BCOM.LIB. For more information, see Appendix D of the QuickBASIC manual.

/q Speed. Optimizes for fast execution at the expense of program size.

/r Arrays in Row Order. Instructs the compiler to store arrays in row order, so that, for example, ARRAY(2,1) would be followed by ARRAY(2,2) instead of by ARRAY(3,1). The compiler's (and the interpreter's) default storage is in column order.

/s Turns off the Minimize String Data option. By default, the compiler references duplicate string literals at the same memory location, in order to minimize storage requirements. That requires it to keep all strings in memory throughout compilation. Some programs with large numbers of strings may cause memory overflow errors as a result. The /s option turns off this default.

/v Checking Between Statements. Enables event trapping, with checking after each statement instead of after each program line.

/w Event Trapping. Enables event trapping, with checking after each program line.

/x Resume Next. For use with programs that contain one or more RESUME, RESUME NEXT, or RESUME 0 statements.

Page 102: QuickBASIC 3

102

Type Conversions How BASIC converts data from one precision to another

1. If a variable of one type is assigned to a variable of another, the data takes on the precision of the target variable.

2. When a higher-precision value (constant or variable) is assigned to a variable of lower precision, the value is rounded, rather than truncated.

3. When a lower-precision value (constant or variable) is assigned to a higher-precision variable, its accuracy is limited to that of the lower-precision value.

4. When an expression is evaluated, all operands are converted to the same level of precision--that of the highest-precision operand in the expression.

See Also: Data Types

Reserved Words ABS DATA GOTO$ MKDIR RANDOM SWAP ACCESS DATE$ HEX$ MKDMBF$ RANDOMIZE SYSTEM AND DO IF MKI$ READ TAB APPEND DEF FN IMP MKS$ REDIM TAN AS DEF SEG INKEY$ MKSMBF$ REM THEN ASC DEF USR INP MOD RENUM TIME$ ATN DEFDBL INPUT MOTOR RESET TIMER AUTO DEFINT INPUT# NAME RESTORE TO BASE DEFSNG INPUT$ NEW RESUME TROFF BEEP DEFSTR INSTR NEXT RETURN TRON BLOAD DELETE INT NOISE* RIGHT$ UBOUND BSAVE DIM IOCTL NOT RMDIR UNLOCK CALL DO* IOCTL$ NULL* RND UNTIL CALLS DRAW KEY OCT$ RSET USING CASE EDIT KILL OFF RUN USR CDBL ELSE LBOUND ON SADD USR0 CHAIN ELSEIF LCOPY OPEN SAVE USR1 CHDIR END LEFT$ OPEN COM SCREEN USR2 CHR$ ENVIRON LEN OPTION SEG USR3 CINT ENVIRON$ LET OR SELECT USR4 CIRCLE EOF LINE OUT SGN USR5 CLEAR EQV LIST OUTPUT SHARED USR6 CLOSE ERASE LLIST PAINT SHELL USR7 CLS ERDEV LOAD PALETTE USING SIN USR8 COLOR ERDEV$ LOC PEEK SOUND USR9 COM ERL LOCAL PEN SPACE VAL COMMAND$ ERR LOCATE PLAY SPACE$ VARPTR COMMON ERROR LOCK PMAP SPC VARPTR$ CONST EXIT LOF POINT SQR VIEW CONT EXP LOG POKE STATIC WAIT COS FIELD LOOP POS STEP WEND CSNG FILES LPOS PRESET STICK WHILE CSRLIN FIX LPRINT PRINT STOP WIDTH CVD FOR LPRINT# PRINT# STRIG WINDOW CVDMBF FRE LSET PRINT# USING STR$ WRITE CVSMBF GET MERGE PSET STRING$ WRITE# CVI GO MID$ PUT SUB XOR CVS GOSUB MKD$

* Reserved for future versions .

Page 103: QuickBASIC 3

103

Runtime Errors1 (not defined)2 Syntax error3 RETURN without GOSUB4 Out of data5 Illegal function call6 Overflow7 Out of memory8 (not defined)9 Subscript out of range10 Redimensioned array11 Division by zero12 (not defined)13 Type mismatch14 Out of string space15 (not defined)16 String formula too complex17 (not defined)18 (not defined)19 No RESUME20 RESUME without error21 (not defined)22 (not defined)23 (not defined)24 Device timeout25 (not defined)26 (not defined)27 (not defined)28 (not defined)29 (not defined)30 (not defined)31 (not defined)32 (not defined)33 (not defined)34 (not defined)35 (not defined)36 (not defined)37 (not defined)38 (not defined)

39 CASE ELSE expected40 (not defined)41 (not defined)42 (not defined)43 (not defined)44 (not defined)45 (not defined)46 (not defined)47 (not defined)48 (not defined)49 (not defined)50 FIELD overflow51 Internal error52 Bad file number53 File not found54 Bad file mode55 File already open56 (not defined)57 Device I/O error58 File already exists59 (not defined)60 (not defined)61 Disk full62 Input past end63 Bad record number64 Bad file name65 (not defined)66 (not defined)67 Too many files68 Device unavailable69 (not defined)70 Permission denied71 Disk not ready72 Disk media error73 (not defined)74 Rename across disks75 Path/file access error76 Path not found

Page 104: QuickBASIC 3

104

Tables

ASCII Chart Dec Hex Char Dec Hex Char Dec Hex Char Dec Hex Char 0 00h NUL | 64 40h @ | 128 80h . | 192 C0h + 1 01h . SOH | 65 41h A | 129 81h . | 193 C1h - 2 02h . STX | 66 42h B | 130 82h . | 194 C2h - 3 03h . ETX | 67 43h C | 131 83h . | 195 C3h | 4 04h . EOT | 68 44h D | 132 84h . | 196 C4h - 5 05h . ENQ | 69 45h E | 133 85h . | 197 C5h + 6 06h . ACK | 70 46h F | 134 86h . | 198 C6h - 7 07h . BEL | 71 47h G | 135 87h . | 199 C7h - 8 08h . BS | 72 48h H | 136 88h . | 200 C8h + 9 09h . HT | 73 49h I | 137 89h . | 201 C9h + 10 0Ah . LF | 74 4Ah J | 138 8Ah . | 202 CAh - 11 0Bh . VT | 75 4Bh K | 139 8Bh . | 203 CBh - 12 0Ch . FF | 76 4Ch L | 140 8Ch . | 204 CCh | 13 0Dh . CR | 77 4Dh M | 141 8Dh . | 205 CDh - 14 0Eh . SO | 78 4Eh N | 142 8Eh . | 206 CEh + 15 0Fh . SI | 79 4Fh O | 143 8Fh . | 207 CFh - 16 10h . DLE | 80 50h P | 144 90h . | 208 D0h - 17 11h . DC1 | 81 51h Q | 145 91h . | 209 D1h - 18 12h . DC2 | 82 52h R | 146 92h . | 210 D2h - 19 13h . DC3 | 83 53h S | 147 93h . | 211 D3h + 20 14h . DC4 | 84 54h T | 148 94h . | 212 D4h + 21 15h . NAK | 85 55h U | 149 95h . | 213 D5h + 22 16h . SYN | 86 56h V | 150 96h . | 214 D6h + 23 17h . ETB | 87 57h W | 151 97h . | 215 D7h + 24 18h . CAN | 88 58h X | 152 98h . | 216 D8h + 25 19h . | 89 59h Y | 153 99h . | 217 D9h + 26 1Ah . SUB | 90 5Ah Z | 154 9Ah . | 218 DAh + 27 1Bh . ESC | 91 5Bh [ | 155 9Bh . | 219 DBh # 28 1Ch . FS | 92 5Ch \ | 156 9Ch . | 220 DCh # 29 1Dh . GS | 93 5Dh ] | 157 9Dh . | 221 DDh # 30 1Eh . RS | 94 5Eh ^ | 158 9Eh . | 222 DEh # 31 1Fh . US | 95 5Fh _ | 159 9Fh . | 223 DFh # 32 20h | 96 60h ` | 160 A0h . | 224 E0h . 33 21h ! | 97 61h a | 161 A1h . | 225 E1h . 34 22h " | 98 62h b | 162 A2h . | 226 E2h . 35 23h # | 99 63h c | 163 A3h . | 227 E3h . 36 24h $ | 100 64h d | 164 A4h . | 228 E4h . 37 25h % | 101 65h e | 165 A5h . | 229 E5h . 38 26h & | 102 66h f | 166 A6h . | 230 E6h . 39 27h ' | 103 67h g | 167 A7h . | 231 E7h . 40 28h ( | 104 68h h | 168 A8h . | 232 E8h . 41 29h ) | 105 69h i | 169 A9h . | 233 E9h . 42 2Ah * | 106 6Ah j | 170 AAh . | 234 EAh . 43 2Bh + | 107 6Bh k | 171 ABh . | 235 EBh . 44 2Ch , | 108 6Ch l | 172 ACh . | 236 ECh . 45 2Dh - | 109 6Dh m | 173 ADh . | 237 EDh . 46 2Eh . | 110 6Eh n | 174 AEh . | 238 EEh . 47 2Fh / | 111 6Fh o | 175 AFh . | 239 EFh . 48 30h 0 | 112 70h p | 176 B0h # | 240 F0h . 49 31h 1 | 113 71h q | 177 B1h # | 241 F1h . 50 32h 2 | 114 72h r | 178 B2h # | 242 F2h . 51 33h 3 | 115 73h s | 179 B3h | | 243 F3h . 52 34h 4 | 116 74h t | 180 B4h | | 244 F4h . 53 35h 5 | 117 75h u | 181 B5h | | 245 F5h . 54 36h 6 | 118 76h v | 182 B6h | | 246 F6h . 55 37h 7 | 119 77h w | 183 B7h + | 247 F7h . 56 38h 8 | 120 78h x | 184 B8h + | 248 F8h . 57 39h 9 | 121 79h y | 185 B9h | | 249 F9h . 58 3Ah : | 122 7Ah z | 186 BAh | | 250 FAh . 59 3Bh ; | 123 7Bh { | 187 BBh + | 251 FBh . 60 3Ch < | 124 7Ch | | 188 BCh + | 252 FCh . 61 3Dh = | 125 7Dh } | 189 BDh + | 253 FDh . 62 3Eh > | 126 7Eh ~ | 190 BEh + | 254 FEh . 63 3Fh ? | 127 7Fh . | 191 BFh + | 255 FFh

2

Page 105: QuickBASIC 3

105

Line-Drawing Chars 218 196 194 191 201 205 203 187 +----------------+ +----------------+ 179 | 197 | | 179 186 | 206 | | 186 | \ | | | \ | | 195 |----------+-----| 180 204 |----------+-----| 185 | | | | | | +----------------+ +----------------+ 192 196 193 217 200 205 202 188

213 205 209 184 214 196 210 183 +----------------+ +----------------+ 179 | 216 | | 179 186 | 215 | | 186 | \ | | | \ | | 198 -----------+-----| 181 199 -----------+-----| 182 | | | | | | +----------------+ +----------------+ 212 205 207 190 211 196 208 189

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

. 30 . 24 . 18 . 31 . 25 . 23 . 16 . 26 . 17 . 27 . 29

----------------------------- Block Characters ----------------------------- - # 176 # - 219 # 221 # 177 # - 220 # 222 # 178 # - 223 - ----------------------- Foreign-Language Characters ------------------------

131 . | 136 . | 147 . | 150 . 132 . . 142 | 137 . | 148 . . 153 | 129 . . 154 133 . | 138 . | 149 . | 151 . 160 . | 130 . . 144 | 162 . | 163 . 134 . . 143 | | | | 140 . | 164 . . 165 | 152 . 145 . . 146 | 139 . | | | 141 . | 225 . | 135 . . 128 | 161 . | |

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

. 155 . 166 . 168 . 19 . 156 . 167 . 173 . 20 . 157 . 174 . 21 . 159 . 175 . 158

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

. 143 . 224 alpha . 238 . 225 beta . 239 . 226 gamma . 240 . 235 delta . 241 . 233 theta . 242 244 . 230 mu . 243 . . 227 pi . 244 | 179 . 229 . 228 sigma . 245 . . 231 tau . 246 245 . 237 . 232 phi . 247 . 234 omega . 248 . 249 . 250 . 251 . 252 . 253 . 236

Page 106: QuickBASIC 3

106

Color Chart Number I R G B Monochrome Color Background Foreground ------ --- --- --- --- ---------- ----- ---------- ---------- 0 0 0 0 0 Black Black Sample Sample 1 0 0 0 1 Underlined Blue Sample Sample 2 0 0 1 0 Green Sample Sample 3 0 0 1 1 Cyan Sample Sample 4 0 1 0 0 Red Sample Sample 5 0 1 0 1 Violet Sample Sample 6 0 1 1 0 Brown Sample Sample 7 0 1 1 1 White White Sample Sample

8 1 0 0 0 Grey Sample Sample 9 1 0 0 1 Brt Underline Bright Blue Sample Sample 10 1 0 1 0 Bright Green Sample Sample 11 1 0 1 1 Bright Cyan Sample Sample 12 1 1 0 0 Bright Red Sample Sample 13 1 1 0 1 Bright Violet Sample Sample 14 1 1 1 0 Yellow Sample Sample 15 1 1 1 1 Bright White Bright White 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.

83/84-Key[1] 101/102-Key Keystroke Keyboard Keyboard[2] Esc 027 same 1 049 same 2 050 same 3 051 same 4 052 same 5 053 same 6 054 same 7 055 same 8 056 same 9 057 same 0 048 same - 045 same = 061 same Backspace 008 same Tab 009 same q 113 same w 119 same e 101 same r 114 same t 116 same y 121 same u 117 same i 105 same o 111 same p 112 same [ 091 same ] 093 same Enter 013 same Ctrl ** ** a 097 same

Page 107: QuickBASIC 3

107

s 115 same d 100 same f 102 same g 103 same h 104 same j 106 same k 107 same l 108 same ; 059 same ' 039 same ` 096 same Shift ** ** \ 092 same z 122 same x 120 same c 099 same v 118 same b 98 same n 110 same m 109 same , 044 same . 046 same / 047 same Gray * 042 same Alt ** ** Space 032 same Caps Lock ** ** F1 000 059 same F2 000 060 same F3 000 061 same F4 000 062 same F5 000 063 same F6 000 064 same F7 000 065 same F8 000 066 same F9 000 067 same F10 000 068 same F11 no key 000 133 F12 no key 000 134 Num Lock ** ** Scroll Lock ** ** White Home 000 071 same White Up Arrow 000 072 same White PgUp 000 073 same Gray - 045 same White Left Arrow 000 075 same Center Key -- 000 076 White Right Arrow 000 077 same Gray + 043 same White End 000 079 same White Down Arrow 000 080 same White PgDn 000 081 same White Ins 000 082 same White Del 000 083 same SysReq no key ** Key 45 [3] no key 092 Enter (number keypad) no key 000 013 Gray / no key 000 047 PrtSc no key ** Pause no key ** Gray Home no key 071 Gray Up Arrow no key 072 Gray Page Up no key 073 Gray Left Arrow no key 075 Gray Right Arrow no key 077 Gray End no key 079 Gray Down Arrow no key 080 Gray Page Down no key 081 Gray Insert no key 082 Gray Delete no key 083

Shift Esc 027 same ! 033 same @ 064 same # 035 same $ 036 same

Page 108: QuickBASIC 3

108

% 037 same ^ 094 same & 038 same * (white) 042 same ( 040 same ) 041 same _ 095 same + (white) 043 same Shift Backspace 008 same Shift Tab (Backtab) 000 015 same Q 081 same W 087 same E 069 same R 082 same T 084 same Y 089 same U 085 same I 073 same O 079 same P 080 same { 123 same } 125 same Shift Enter 013 same Shift Ctrl ** ** A 065 same S 083 same D 068 same F 070 same G 071 same H 072 same J 074 same K 075 same L 076 same : 058 same " 034 same ~ 126 same | 124 same Z 090 same X 088 same C 067 same V 086 same B 066 same N 078 same M 077 same < 060 same > 062 same ? 063 same Shift Gray * ** 042 Shift Alt ** ** Shift Space 032 same Shift Caps Lock ** ** Shift F1 000 084 same Shift F2 000 085 same Shift F3 000 086 same Shift F4 000 087 same Shift F5 000 088 same Shift F6 000 089 same Shift F7 000 090 same Shift F8 000 091 same Shift F9 000 092 same Shift F10 000 093 same Shift F11 no key 000 135 Shift F12 no key 000 136 Shift Num Lock ** ** Shift Scroll Lock ** ** Shift 7 (number pad) 055 same Shift 8 (number pad) 056 same Shift 9 (number pad) 057 same Shift Gray - 045 same Shift 4 (number pad) 052 same Shift 5 (number pad) 053 same Shift 6 (number pad) 054 same Shift Gray + 043 same Shift 1 (number pad) 049 same Shift 2 (number pad) 050 same Shift 3 (number pad) 051 same

Page 109: QuickBASIC 3

109

Shift 0 (number pad) 048 same Shift . (number pad) 046 same Shift SysReq no key ** Shift Key 45 [3] no key 124 Shift Enter (number pad) no key 000 013 Shift Gray / no key 000 047 Shift PrtSc no key ** Shift Pause no key ** Shift Gray Home no key 071 Shift Gray Up Arrow no key 072 Shift Gray Page Up no key 073 Shift Gray Left Arrow no key 075 Shift Gray Right Arrow no key 077 Shift Gray End no key 079 Shift Gray Down Arrow no key 080 Shift Gray Page Down no key 081 Shift Gray Insert no key 082 Shift Gray Delete no key 083

Ctrl Esc 027 same Ctrl 1 -- -- Ctrl 2 (NUL) 000 003 same Ctrl 3 -- -- Ctrl 4 -- -- Ctrl 5 -- -- Ctrl 6 (RS) 030 same Ctrl 7 -- -- Ctrl 8 -- -- Ctrl 9 -- -- Ctrl 0 -- -- Ctrl - 031 same Ctrl = -- -- Ctrl Backspace (DEL) 127 same Ctrl Tab -- 148 Ctrl q (DC1) 017 same Ctrl w (ETB) 023 same Ctrl e (ENQ) 005 same Ctrl r (DC2) 018 same Ctrl t (DC4) 020 same Ctrl y (EM) 025 same Ctrl u (NAK) 021 same Ctrl i (HT) 009 same Ctrl o (SI) 015 same Ctrl p (DEL) 016 same Ctrl [ (ESC) 027 same Ctrl ] (GS) 029 same Ctrl Enter (LF) 010 same Ctrl a (SOH) 001 same Ctrl s (DC3) 019 same Ctrl d (EOT) 004 same Ctrl f (ACK) 006 same Ctrl g (BEL) 007 same Ctrl h (Backspace) 008 same Ctrl j (LF) 010 same Ctrl k (VT) 011 same Ctrl l (FF) 012 same Ctrl ; -- -- Ctrl ' -- -- Ctrl ` -- -- Ctrl Shift ** ** Ctrl \ (FS) 028 same Ctrl z (SUB) 026 same Ctrl x (CAN) 024 same Ctrl c (ETX) 003 same Ctrl v (SYN) 022 same Ctrl b (STX) 002 same Ctrl n (SO) 014 same Ctrl m (CR) 013 same Ctrl , -- -- Ctrl . -- -- Ctrl / -- -- Ctrl Gray * -- 000 150 Ctrl Alt ** ** Ctrl Space 032 same Ctrl Caps Lock -- -- Ctrl F1 000 094 same

Page 110: QuickBASIC 3

110

Ctrl F2 000 095 same Ctrl F3 000 096 same Ctrl F4 000 097 same Ctrl F5 000 098 same Ctrl F6 000 099 same Ctrl F7 000 100 same Ctrl F8 000 101 same Ctrl F9 000 102 same Ctrl F10 000 103 same Ctrl F11 no key 000 137 Ctrl F12 no key 000 138 Ctrl Num Lock -- -- Ctrl Scroll Lock -- -- Ctrl White Home 000 119 same Ctrl White Up Arrow -- 000 141 Ctrl White PgUp 000 132 same Ctrl Gray - -- 000 142 Ctrl White Left Arrow 000 115 same Ctrl 5 (number pad) -- 000 143 Ctrl White Right Arrow 000 116 same Ctrl Gray + -- 000 144 Ctrl White End 000 117 same Ctrl White Down Arrow -- 000 145 Ctrl White PgDn 000 118 same Ctrl White Ins -- 000 146 Ctrl White Del -- 000 147 Ctrl SysReq no key ** Ctrl Key 45 [3] no key -- Ctrl Enter (number pad) no key 000 010 Ctrl / (number pad) no key 000 149 Ctrl PrtSc no key 114 Ctrl Break no key 000 000 Ctrl Gray Home no key 119 Ctrl Gray Up Arrow no key 141 Ctrl Gray Page Up no key 132 Ctrl Gray Left Arrow no key 115 Ctrl Gray Right Arrow no key 116 Ctrl Gray End no key 117 Ctrl Gray Down Arrow no key 145 Ctrl Gray Page Down no key 118 Ctrl Gray Insert no key 146 Ctrl Gray Delete no key 147

Alt Esc -- 000 001 Alt 1 000 120 same Alt 2 000 121 same Alt 3 000 122 same Alt 4 000 123 same Alt 5 000 124 same Alt 6 000 125 same Alt 7 000 126 same Alt 8 000 127 same Alt 9 000 128 same Alt 0 000 129 same Alt - 000 130 same Alt = 000 131 same Alt Backspace -- 000 014 Alt Tab -- 000 165 Alt q 000 016 same Alt w 000 017 same Alt e 000 018 same Alt r 000 019 same Alt t 000 020 same Alt y 000 021 same Alt u 000 022 same Alt i 000 023 same Alt o 000 024 same Alt p 000 025 same Alt [ -- 000 026 Alt ] -- 000 027 Alt Enter -- 000 028 Alt Ctrl ** ** Alt a 000 030 same Alt s 000 031 same Alt d 000 032 same Alt f 000 033 same

Page 111: QuickBASIC 3

111

Alt g 000 034 same Alt h 000 035 same Alt j 000 036 same Alt k 000 037 same Alt l 000 038 same Alt ; -- 000 039 Alt ' -- 000 040 Alt ` -- 000 041 Alt Shift ** ** Alt \ -- 000 043 Alt z 000 044 same Alt x 000 045 same Alt c 000 046 same Alt v 000 047 same Alt b 000 048 same Alt n 000 049 same Alt m 000 050 same Alt , -- 000 051 Alt . -- 000 052 Alt / -- 000 053 Alt Gray * -- 000 055 Alt Space 032 same Alt Caps Lock ** ** Alt F1 000 104 same Alt F2 000 105 same Alt F3 000 106 same Alt F4 000 107 same Alt F5 000 108 same Alt F6 000 109 same Alt F7 000 110 same Alt F8 000 111 same Alt F9 000 112 same Alt F10 000 113 same Alt F11 no key 000 139 Alt F12 no key 000 140 Alt Num Lock ** ** Alt Scroll Lock ** ** Alt Gray - -- 000 074 Alt Gray + -- 000 078 Alt 7 (number pad) # # Alt 8 (number pad) # # Alt 9 (number pad) # # Alt 4 (number pad) # # Alt 5 (number pad) # # Alt 6 (number pad) # # Alt 1 (number pad) # # Alt 2 (number pad) # # Alt 3 (number pad) # # Alt Del -- -- Alt SysReq no key ** Alt Key 45 [3] no key -- Alt Enter (number pad) no key 000 166 Alt / (number pad) -- 000 164 Alt PrtSc no key ** Alt Pause no key ** Alt Gray Home no key 000 151 Alt Gray Up Arrow no key 000 152 Alt Gray Page Up no key 000 153 Alt Gray Left Arrow no key 000 155 Alt Gray Right Arrow no key 000 157 Alt Gray End no key 000 159 Alt Gray Down Arrow no key 000 160 Alt Gray Page Down no key 000 161 Alt Gray Insert no key 000 162 Alt Gray Delete no key 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.

Page 112: QuickBASIC 3

112

[3] 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.

Page 113: QuickBASIC 3

113

SadržajNaredbe po nameni .................................................................3

BASIC .............................................................................7

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

Page 114: QuickBASIC 3

114

FRE Available Memory.......................................33FREEFILE Returns the next free BASIC file number................33FUNCTION Declares the function..................................33GET Read Random File into Buffer (File I/O)................35GET Read Points from Screen (Graphics).....................35GOSUB Execute Subroutine.....................................36GOTO Unconditional Branch...................................36HEX$ Hexadecimal Value, as String...........................37IF Conditional Branch.....................................37INKEY$ Most Recent Character at Keyboard......................38INP Read from an I/O Port..................................38INPUT Get Input from Keyboard................................38INPUT # Get Input from Sequential File or Device...............39INPUT$ Read Specified Number of Characters....................40INSTR Find Substring.........................................40INT Next Lower Integer.....................................41IOCTL Send Control String to Device Driver...................41IOCTL$ Read Control String from Device Driver.................41KEY Set or Display Soft Keys...............................41KEY(n) Enable/Disable Key Trapping............................42KILL Delete File(s).........................................43LBOUND Lower Bound of Array Dimension.........................43LCASE$ Returns a string with all letters in lower-case........43LEFT$ Substring at Left......................................44LEN Length of String.......................................44LET Assignment.............................................44LINE Draw Line or Box.......................................44LINE INPUT Read Line from Keyboard, Ignoring Delimiters...........45LINE INPUT# Read Line from File, Ignoring Delimiters...............45LOC Current File Position..................................45LOCATE Position the Cursor....................................46LOCK Control File or Record Access..........................46LOF Length of File.........................................47LOG Natural Logarithm......................................47LOOP End Definition of DO/LOOP Loop.........................47LPOS Current Position of Print Head.........................48LPRINT Output to LPT1:........................................48LPRINT USING Formatted Output to LPT1:..............................49LSET Left-Justify Data in Field Variable....................50LTRIM$ Returns a copy of a string with leading spaces removed.50MID$ Substring in Middle (Function).........................51MID$ Assign Substring (Statement)...........................51MKD$ Convert Double-Precision to String.....................52MKDIR Create Subdirectory....................................52MKDMBF$ IEEE Double-Precision to MBF String (QB87 only)........52MKI$ Convert Integer to String..............................52MKS$ Convert Single-Precision to String.....................52MKSMBF$ IEEE Single-Precision to MBF String (QB87 only)........52NAME Rename File............................................53NEXT End Definition of FOR/NEXT Loop........................53OCT$ Octal Value, as String.................................54ON COM Trap for Communications Activity.......................54ON ERROR Enable Error Trapping..................................54ON KEY Trap for Keypress......................................55ON PEN Trap for Light Pen Activity............................56ON PLAY(n) Trap for Background Music Remaining....................56ON STRIG(n) Trap for Specified Joystick Button.....................57ON TIMER Trap for Elapsed Time..................................58ON...GOSUB Branch to nth Item in Subroutine List..................58ON...GOTO Branch to nth Item in Line List........................59OPEN Allow File or Device I/O...............................59OPEN "COM... Open a Communications File.............................60OPTION BASE Set Minimum Array Subscript............................61OUT Send Byte to Output Port...............................61PAINT Fill an Area with a Pattern or Color...................62PALETTE Change Color in the Palette............................62PALETTE USING Change Many Colors in the Palette......................63PCOPY Copy Screen Page.......................................63PEEK Value at Specified Address.............................64PEN Light Pen Status (Function)............................64PEN Enable/Disable Pen Read and Trap (Statement)...........64PLAY Enable/Disable Music Trap (Statement)..................65PLAY Number of Notes in Background Buffer (Function)........65PLAY Play Music (Statement).................................65PMAP Map Physical Coordinates to World......................67POINT Attribute or Value at Screen Location..................67

Page 115: QuickBASIC 3

115

POKE Write Byte to Memory...................................67POS Current Cursor Column Position.........................67PRESET Draw Point on Screen...................................68PRINT Display on Screen......................................68PRINT # Output to Sequential File..............................68PRINT # USING Formatted Output to File...............................69PRINT USING Formatted Screen Display...............................70PSET Draw Point on Screen...................................72PUT Write Record from Random Buffer to File (File I/O).....72PUT Plot Array Image on Screen (Graphics)..................73RANDOMIZE Reseed Random Number Generator.........................73READ Assign DATA Items to Variables.........................73REDIM Redimension Array......................................74REM Comment or Metacommand.................................74RESET Close All Disk Files...................................75RESTORE Reset DATA Item Pointer................................75RESUME Continue after Error Trap..............................75RETURN Return from Subroutine.................................75RIGHT$ Substring at Right.....................................76RMDIR Remove Subdirectory....................................76RND Random Number..........................................76RSET Right-Justify Data in Field Variable...................76RTRIM$ Rreturns a string with right-hand spaces removed.......77RUN Execute Program........................................77SADD String Address.........................................78SCREEN Character at Specified Location (Function).............78SCREEN Set Screen Attributes (Statement)......................78SEEK Returns the current file position......................79SELECT CASE Case Structure.........................................80SGN Sign of Number.........................................81SHARED Declare Global Variables...............................81SHELL Execute DOS Command....................................81SIN Sine...................................................82SLEEP Suspends execution of the calling program..............82SOUND Sound the Speaker......................................82SPACE$ String of n Spaces.....................................83SPC Skip n Spaces in a PRINT statement.....................83SQR Square Root............................................83STATIC Declare Local Variable(s)..............................83STICK Joystick Coordinates...................................84STOP Halt Program...........................................84STR$ String Representation of Numeric Expression............84STRIG Enable/Disable the STRIG Function (Statement)..........84STRIG Status of Joystick Buttons (Function)..................84STRING$ String of Specified Length and Character...............85SUB...END SUB Define Subprogram......................................85SWAP Exchange the Values of Two Variables...................86SYSTEM Return to Operating System.............................86TAB Tab to a Specified Position............................86TAN Tangent................................................86TYPE Declaration that defines a data type...................87TIME$ Get System Time (Function).............................87TIME$ Set System Time (Statement)............................87TIMER Number of Seconds since Midnight (Function)............88TIMER Enable/Disable Timer Trap (Statement)..................88TROFF Trace Off..............................................88TRON Trace On...............................................88UBOUND Upper Bound of Array Dimension.........................88UCASE$ Returns a string with all letters in uppercase.........89UNLOCK Remove File or Record Access Lock......................89VAL Numeric Value of a String..............................89VARPTR Offset of Variable or Offset of File Buffer............90VARPTR$ Offset of Variable, in Character Form..................90VIEW Define Screen Window...................................90VIEW PRINT Set Screen Text Window.................................91WAIT Wait for Port Status...................................91WEND End Definition of WHILE/WEND Loop......................92WHILE Begin Definition of WHILE/WEND Loop....................92WIDTH Set Output Width.......................................93WINDOW Redefine Screen Coordinates............................93WRITE Output to Screen.......................................93WRITE # Output to Sequential File..............................94

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

Page 116: QuickBASIC 3

116

* Multiplication.........................................95/ Division...............................................95+ Addition and Concatenation.............................95- Subtraction and Negation...............................96\ Integer Division.......................................96MOD 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...............................98NOT Logical NOT............................................98AND Logical AND............................................98OR Logical OR.............................................99XOR Logical Exclusive OR...................................99EQV Equivalence............................................99IMP 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