home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft_Programmers_Library.7z / MPL / basic / qb45lang.txt < prev    next >
Encoding:
Text File  |  2013-11-08  |  812.4 KB  |  23,403 lines

  1.  Microsoft QuickBASIC: Language Reference
  2.  
  3.  
  4.  ════════════════════════════════════════════════════════════════════════════
  5.  
  6.  
  7.  Microsoft(R) QuickBASIC BASIC: Language Reference
  8.  
  9.  For IBM(R) Personal Computers and Compatibles
  10.  
  11.  
  12.  ════════════════════════════════════════════════════════════════════════════
  13.  
  14.  
  15.  Information in this document is subject to change without notice and does
  16.  not represent a commitment on the part of Microsoft Corporation. The
  17.  software described in this document is furnished under a license agreement
  18.  or nondisclosure agreement. The software may be used or copied only in
  19.  accordance with the terms of the agreement. It is against the law to copy
  20.  the software on any medium except as specifically allowed in the license or
  21.  nondisclosure agreement. No part of this manual may be reproduced or
  22.  transmitted in any form or by any means, electronic or mechanical, including
  23.  photocopying and recording, for any purpose without the express written
  24.  permission of Microsoft.
  25.  
  26.  (C)Copyright Microsoft Corporation 1987, 1988. All rights reserved.
  27.  Simultaneously published in the U.S. and Canada.
  28.  
  29.  Printed and bound in the United States of America. Microsoft, MS, MS-DOS,
  30.  CodeView, and XENIX are registered trademarks of Microsoft Corporation.
  31.  
  32.  AT&T is a registered trademark of American Telephone and Telegraph Company.
  33.  
  34.  Hercules is a registered trademark and InColor is a trademark of Hercules
  35.  Computer Technology.
  36.  
  37.  IBM and PC/AT are registered trademarks and PC/XT is a trademark of
  38.  International Business Machines Corporation.
  39.  
  40.  Intel is a registered trademark of Intel Corporation.
  41.  
  42.  Olivetti is a registered trademark of Ing. C. Olivetti.
  43.  
  44.  Document No. 410700018-450-R00-1188
  45.  
  46.  
  47.  
  48.  ────────────────────────────────────────────────────────────────────────────
  49.  Table of Contents
  50.  
  51.  Introduction
  52.        Document Conventions
  53.        Reference Page Format
  54.  
  55.  PART 1  LANGUAGE FUNDAMENTALS
  56.  
  57.  Chapter 1  Language Elements
  58.        1.1  Character Set
  59.        1.2  The BASIC Program Line
  60.          1.2.1   Using Line Identifiers
  61.          1.2.2   BASIC Statements
  62.          1.2.3   BASIC Line Length
  63.  
  64.  Chapter 2  Data Types
  65.        2.1  Data Types
  66.          2.1.1   Elementary Data Types──String
  67.          2.1.2   Elementary Data Types──Numeric
  68.            2.1.2.1   Integer Numbers
  69.            2.1.2.2   Floating-Point Numbers
  70.          2.1.3   User-Defined Data Types
  71.        2.2  Constants
  72.          2.2.1   Literal Constants
  73.          2.2.2   Symbolic Constants
  74.        2.3  Variables
  75.          2.3.1   Variable Names
  76.          2.3.2   Declaring Variable Types
  77.            2.3.2.1   Type-Declaration Suffix
  78.            2.3.2.2   AS Declaration Statements
  79.            2.3.2.3   DEFtype Declaration Statements
  80.            2.3.2.4   Declaring Array Variables
  81.          2.3.3   Variable Storage Allocation
  82.        2.4  Scope of Variables and Constants
  83.          2.4.1   Global Variables and Constants
  84.          2.4.2   Local Variables and Constants
  85.          2.4.3   Sharing Variables
  86.          2.4.4   DEF FN Functions
  87.          2.4.5   Summary of Scope Rules
  88.        2.5  Static and Dynamic Arrays
  89.        2.6  Automatic and Static Variables
  90.        2.7  Type Conversion
  91.  
  92.  Chapter 3  Expressions and Operators
  93.        3.1  Expressions and Operators Defined
  94.        3.2  Hierarchy of Operations
  95.        3.3  Arithmetic Operators
  96.          3.3.1   Integer Division
  97.          3.3.2   Modulo Arithmetic
  98.          3.3.3   Overflow and Division by Zero
  99.        3.4  Relational Operators
  100.        3.5  Logical Operators
  101.        3.6  Functional Operators
  102.        3.7  String Operators
  103.  
  104.  Chapter 4  Programs and Modules
  105.        4.1  Modules
  106.        4.2  Procedures
  107.          4.2.1   FUNCTION Procedures
  108.          4.2.2   SUB Procedures
  109.          4.2.3   DEF FN Functions
  110.        4.3  Passing by Reference and Passing by Value
  111.        4.4  Recursion
  112.  
  113.  PART 2  STATEMENT AND FUNCTION REFERENCE
  114.  
  115.        ABS Function
  116.        ASC Function
  117.        ATN Function
  118.        BEEP Statement
  119.        BLOAD Statement
  120.        BSAVE Statement
  121.        CALL Statement (BASIC)
  122.        CALL, CALLS Statement (Non-BASIC)
  123.        CALL ABSOLUTE Statement
  124.        CALL INT86OLD Statements
  125.        CALL INTERRUPT Statements
  126.        CDBL Function
  127.        CHAIN Statement
  128.        CHDIR Statement
  129.        CHR$ Function
  130.        CINT Function
  131.        CIRCLE Statement
  132.        CLEAR Statement
  133.        CLNG Function
  134.        CLOSE Statement
  135.        CLS Statement
  136.        COLOR Statement
  137.        COM Statements
  138.        COMMAND$ Function
  139.        COMMON Statement
  140.        CONST Statement
  141.        COS Function
  142.        CSNG Function
  143.        CSRLIN Function
  144.        CVSMBF, CVDMBF Functions
  145.        CVI, CVS, CVL, CVD Functions
  146.        DATA Statement
  147.        DATE$ Function
  148.        DATE$ Statement
  149.        DECLARE Statement (BASIC)
  150.        DECLARE Statement (Non-BASIC)
  151.        DEF FN Statement
  152.        DEF SEG Statement
  153.        DEFtype Statements
  154.        DIM Statement
  155.        DO...LOOP Statement
  156.        DRAW Statement
  157.        END Statement
  158.        ENVIRON Statement
  159.        ENVIRON$ Function
  160.        EOF Function
  161.        ERASE Statement
  162.        ERDEV, ERDEV$ Functions
  163.        ERR, ERL Functions
  164.        ERROR Statement
  165.        EXIT Statement
  166.        EXP Function
  167.        FIELD Statement
  168.        FILEATTR Function
  169.        FILES Statement
  170.        FIX Function
  171.        FOR...NEXT Statement
  172.        FRE Function
  173.        FREEFILE Function
  174.        FUNCTION Statement
  175.        GET Statement──File I/O
  176.        GET Statement──Graphics
  177.        GOSUB...RETURN Statements
  178.        GOTO Statement
  179.        HEX$ Function
  180.        IF...THEN...ELSE Statement
  181.        INKEY$ Function
  182.        INP Function
  183.        INPUT$ Function
  184.        INPUT Statement
  185.        INPUT # Statement
  186.        INSTR Function
  187.        INT Function
  188.        IOCTL$ Function
  189.        IOCTL Statement
  190.        KEY (n) Statements
  191.        KEY Statements
  192.        KILL Statement
  193.        LBOUND Function
  194.        LCASE$ Function
  195.        LEFT$ Function
  196.        LEN Function
  197.        LET Statement
  198.        LINE Statement
  199.        LINE INPUT Statement
  200.        LINE INPUT # Statement
  201.        LOC Function
  202.        LOCATE Statement
  203.        LOCK...UNLOCK Statement
  204.        LOF Function
  205.        LOG Function
  206.        LPOS Function
  207.        LPRINT, LPRINT USING Statements
  208.        LSET Statement
  209.        LTRIM$ Function
  210.        MID$ Function
  211.        MID$ Statement
  212.        MKD$, MKI$, MKL$, MKS$ Functions
  213.        MKDIR Statement
  214.        MKSMBF$, MKDMBF$ Functions
  215.        NAME Statement
  216.        OCT$ Function
  217.        ON ERROR Statement
  218.        ONevent Statements
  219.        ON...GOSUB, ON...GOTO Statement
  220.        ON UEVENT GOSUB Statement
  221.        OPEN Statement
  222.        OPEN COM Statement
  223.        OPTION BASE Statement
  224.        OUT Statement
  225.        PAINT Statement
  226.        PALETTE, PALETTE USING Statements
  227.        PCOPY Statement
  228.        PEEK Function
  229.        PEN Function
  230.        PEN ON, OFF, and STOP Statements
  231.        PLAY Function
  232.        PLAY Statement
  233.        PLAY ON, OFF, and STOP StatementsP
  234.        PMAP Function
  235.        POINT Function
  236.        POKE Statement
  237.        POS Function
  238.        PRESET Statement
  239.        PRINT Statement
  240.        PRINT USING Statement
  241.        PRINT #, PRINT # USING Statements
  242.        PSET Statement
  243.        PUT Statement──File I/O
  244.        PUT Statement──Graphics
  245.        RANDOMIZE Statement
  246.        READ Statement
  247.        REDIM Statement
  248.        REM Statement
  249.        RESET Statement
  250.        RESTORE Statement
  251.        RESUME Statement
  252.        RETURN Statement
  253.        RIGHT$ Function
  254.        RMDIR Statement
  255.        RND Function
  256.        RSET Statement
  257.        RTRIM$ Function
  258.        RUN Statement
  259.        SADD Function
  260.        SCREEN Function
  261.        SCREEN Statement
  262.        SEEK Function
  263.        SEEK Statement
  264.        SELECT CASE Statement
  265.        SETMEM Function
  266.        SGN Function
  267.        SHARED Statement
  268.        SHELL Statement
  269.        SIN Function
  270.        SLEEP Statement
  271.        SOUND Statement
  272.        SPACE$ Function
  273.        SPC Function
  274.        SQR Function
  275.        STATIC Statement
  276.        STICK Function
  277.        STOP Statement
  278.        STR$ Function
  279.        STRIG Function and Statement
  280.        STRIG ON, OFF, and STOP Statements
  281.        STRING$ Function
  282.        SUB Statements
  283.        SWAP Statement
  284.        SYSTEM Statement
  285.        TAB Function
  286.        TAN Function
  287.        TIME$ Function
  288.        TIME$ Statement
  289.        TIMER Function
  290.        TIMER ON, OFF, and STOP Statements
  291.        TRON/TROFF Statements
  292.        TYPE Statement
  293.        UBOUND Function
  294.        UCASE$ Function
  295.        UEVENT Statement
  296.        UNLOCK Statement
  297.        VAL Function
  298.        VARPTR, VARSEG Functions
  299.        VARPTR$ Function
  300.        VIEW Statement
  301.        VIEW PRINT Statement
  302.        WAIT Statement
  303.        WHILE...WEND Statement
  304.        WIDTH Statement
  305.        WINDOW Statement
  306.        WRITE Statement
  307.        WRITE # Statement
  308.  
  309.  Appendix A  Keyboard Scan Codes and ASCII Character Codes
  310.         A.1  Keyboard Scan Codes
  311.         A.2  ASCII Character Codes
  312.  
  313.  Appendix B  Error Messages
  314.         B.1  Error-Message Display
  315.         B.2  Invocation, Compile-Time, and Run-Time Error Messages
  316.         B.3  LINK Error Messages
  317.         B.4  LIB Error Messages
  318.  
  319.  Index
  320.  
  321.  Figures
  322.         2.1  BASIC Numeric Representations
  323.         R.1  WINDOW and WINDOW SCREEN
  324.  
  325.  Tables
  326.         2.1  Types of Numeric Constants
  327.         2.2  Variable-Type Memory Requirements
  328.         3.1  Relational Operators and Their Functions
  329.         3.2  BASIC Logical Operators
  330.         3.3  Values Returned by Logical Operations
  331.         R.1  INT86OLD and INT86XOLD Register Values
  332.         R.2  FILEATTR Mode Codes
  333.         R.3  Values for Bits per Pixel per Plane and for Planes
  334.         R.4  Keyboard Scan Codes
  335.         R.5  SCREEN Color and Attribute Ranges
  336.         R.6  MDPA Screen Modes
  337.         R.7  Hercules Screen Modes
  338.         R.8  CGA Screen Modes
  339.         R.9  EGA Screen Modes
  340.         R.10 Default Attributes: SCREEN 10, Monochrome Display
  341.         R.11 Color Values: SCREEN 10, Monochrome Display
  342.         R.12 VGA Screen Modes
  343.         R.13 MCGA Screen Modes
  344.         R.14 Default Attributes and Colors for SCREEN Modes 1 and 9
  345.         R.15 Default Attributes and Colors for SCREEN Modes 2 and 11
  346.         R.16 Default Attributes and Colors for SCREEN Modes 0, 7, 8, 9,
  347.              12, and 13
  348.  
  349.  
  350.  
  351.  ────────────────────────────────────────────────────────────────────────────
  352.  Introduction
  353.  
  354.    Microsoft(R) QuickBASIC 4.5 is a powerful programming language for either
  355.    commercial applications or quick development of single-use programs.
  356.    QuickBASIC is compatible with BASICA, adding advanced features such as
  357.    user-defined data types and recursive procedures to the elements that have
  358.    traditionally made BASIC an ideal language for new programmers.
  359.  
  360.    The Microsoft BASIC Language Reference describes the QuickBASIC
  361.    programming language. Use this manual as a printed reference guide while
  362.    you are programming to find the syntax or effect of particular statements
  363.    and functions. You can also use this book to explore BASIC by reading
  364.    about unfamiliar statements and trying them in the short example programs
  365.    provided.
  366.  
  367.    The BASIC Language Reference has these parts:
  368.  
  369.    ■ Part 1, "Language Fundamentals," describes the elements of the BASIC
  370.      language: characters, program lines, data types, constants, variables,
  371.      modules, programs, and procedures.
  372.  
  373.    ■ Part 2, "Statement and Function Reference," contains reference material
  374.      on each BASIC statement and function, organized alphabetically.
  375.  
  376.    ■ The appendixes list the keyboard scan and ASCII character codes and
  377.      provide quick reference information on error messages.
  378.  
  379.    This volume is a companion to the other books supplied with QuickBASIC
  380.    Version 4.5. Learning to Use Microsoft QuickBASIC explains how to use the
  381.    QuickBASIC environment and introduces BASIC programming. Programming in
  382.    BASIC contains more advanced programming information.
  383.  
  384.  
  385.  Document Conventions
  386.  
  387.    This manual uses the following typographic conventions:
  388.  
  389.  
  390. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  391.    Example of Convention    Description
  392.    ──────────────────────────────────────────────────────────────────────────
  393.    QB.LIB, ADD.EXE, COPY,   Uppercase (capital) letters indicate file names
  394.    LINK, /X                 and DOS-level commands. Uppercase is also used
  395.                             for command-line options (unless the application
  396.                             accepts only lowercase).
  397.  
  398.    SUB, IF, LOOP, PRINT,    Bold capital letters indicate language-specific
  399.    WHILE, TIME$             keywords with special meaning to Microsoft BASIC.
  400.                             Keywords are a required part of statement syntax,
  401.    Example of Convention    Description
  402.    ──────────────────────────────────────────────────────────────────────────
  403.                            Keywords are a required part of statement syntax,
  404.                             unless they are enclosed in double brackets as
  405.                             explained below. In programs you write, you must
  406.                             enter keywords exactly as shown. However, you can
  407.                             use uppercase letters or lowercase letters.
  408.  
  409.    CALL NewProc(arg1!,      This kind of type is used for program examples,
  410.    var2%)                   program output, and error messages within the
  411.                             text.
  412.  
  413.    ¢INCLUDE: BC.BI          A column of three dots indicates that part of the
  414.      .                      example program has been intentionally omitted.
  415.      .
  416.      .
  417.    CHAIN "PROG1"
  418.    END
  419.  
  420.    ' Make one pass          The apostrophe (single right quotation mark)
  421.                             marks the beginning of a comment in sample
  422.    Example of Convention    Description
  423.    ──────────────────────────────────────────────────────────────────────────
  424.                            marks the beginning of a comment in sample
  425.                             programs.
  426.  
  427.    filespec                 Italic letters indicate placeholders for
  428.                             information you must supply, such as a file name.
  429.                             Italics are also occasionally used in the text
  430.                             for emphasis.
  431.  
  432.    «optional-item»          Items inside chevrons are optional.
  433.  
  434.    {choice1 | choice2}      Braces and a vertical bar indicate a choice among
  435.                             two or more items. You must choose one of the
  436.                             items unless all of the items are also enclosed
  437.                             in double square brackets.
  438.  
  439.    repeating elements...    Three dots following an item indicate that more
  440.                             items having the same form may appear.
  441.  
  442.    ALT+F1                   Capital letters are used for the names of keys
  443.    Example of Convention    Description
  444.    ──────────────────────────────────────────────────────────────────────────
  445.   ALT+F1                   Capital letters are used for the names of keys
  446.                             and key sequences, such as ENTER and CTRL+R.
  447.  
  448.                             A plus (+) indicates a combination of keys. For
  449.                             example, CTRL+E means to hold down the CTRL key
  450.                             while pressing the E key.
  451.  
  452.                             The carriage-return key, sometimes marked with a
  453.                             bent arrow, is referred to as ENTER.
  454.  
  455.                             The cursor movement ("arrow") keys on the numeric
  456.                             keypad are called DIRECTION keys. Individual
  457.                             DIRECTION keys are referred to by the direction
  458.                             of the arrow on the key top (LEFT, RIGHT, UP,
  459.                             DOWN) or the name on the key top (PGUP, PGDN).
  460.  
  461.                             The key names used in this manual correspond to
  462.                             the names on the IBM(R) Personal Computer keys.
  463.                             Other machines may use different names.
  464.    Example of Convention    Description
  465.    ──────────────────────────────────────────────────────────────────────────
  466.                            Other machines may use different names.
  467.  
  468.    "defined term"           Quotation marks usually indicate a new term
  469.                             defined in the text.
  470.  
  471.    Video Graphics Array     Acronyms are usually spelled out the first time
  472.    (VGA)                    they are used.
  473.    ──────────────────────────────────────────────────────────────────────────
  474.  
  475.  
  476.    The syntax below (for the "LOCK...UNLOCK" statements) illustrates many of
  477.    the typographic conventions in this manual:
  478.  
  479.    LOCK«#»filenumber«,{record | «start» TO end }»
  480.    .
  481.    .
  482.    .
  483.    UNLOCK«#»filenumber«,{record | «start» TO end }»
  484.  
  485.  ────────────────────────────────────────────────────────────────────────────
  486.  NOTE
  487.    Throughout this manual, the term "DOS" refers to both the MS-DOS(R) and
  488.    IBM Personal Computer DOS operating systems. The name of a specific
  489.    operating system is used when it is necessary to note features that are
  490.    unique to that system. The term "BASICA" refers to interpreted versions of
  491.    BASIC in general.
  492.  ────────────────────────────────────────────────────────────────────────────
  493.  
  494.  
  495.  Reference Page Format
  496.  
  497.    Each statement and function description in Part 2, "Statement and
  498.    Function Reference," uses the following format:
  499.  
  500. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  501.    Heading                  Function
  502.    ──────────────────────────────────────────────────────────────────────────
  503.    Action                   Summarizes what the statement or function does.
  504.  
  505.    Syntax                   Gives the correct syntax for the statement or
  506.    Heading                  Function
  507.    ──────────────────────────────────────────────────────────────────────────
  508.   Syntax                   Gives the correct syntax for the statement or
  509.                             function.
  510.  
  511.    Remarks                  Describes arguments and options in detail and
  512.                             explains how to use the statement or function.
  513.  
  514.    Differences from BASICA  Optional section that tells whether or not the
  515.                             given statement or function is new, enhanced, or
  516.                             different from the same statement in the
  517.                             Microsoft BASIC 2.0 Interpreter described in the
  518.                             IBM Personal Computer BASICA reference manual.
  519.  
  520.    See Also                 Mentions related statements and functions (also
  521.                             an optional section).
  522.  
  523.    Example                  Gives sample commands, programs, and program
  524.                             segments illustrating the use of the statement or
  525.                             function (also an optional section).
  526.  
  527.    Heading                  Function
  528.    ──────────────────────────────────────────────────────────────────────────
  529. 
  530.    ──────────────────────────────────────────────────────────────────────────
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  ────────────────────────────────────────────────────────────────────────────
  537.  PART 1  LANGUAGE FUNDAMENTALS
  538.  ────────────────────────────────────────────────────────────────────────────
  539.  
  540.    Part 1 describes aspects of the BASIC language. Chapter 1 gives
  541.    information on the BASIC character set and the structure of a BASIC
  542.    program line. Chapter 2 discusses data types, constants, variables, and
  543.    arrays. Chapter 3 talks about BASIC operators and expressions. Chapter
  544.    4 explains how to use modules and procedures in BASIC programming. This
  545.    chapter also describes the relationship between programs and modules and
  546.    discusses the SUB and FUNCTION procedures available in QuickBASIC.
  547.  
  548.  
  549.  
  550.  ────────────────────────────────────────────────────────────────────────────
  551.  Chapter 1   Language Elements
  552.  
  553.        1.1  Character Set
  554.        1.2  The BASIC Program Line
  555.          1.2.1   Using Line Identifiers
  556.          1.2.2   BASIC Statements
  557.          1.2.3   BASIC Line Length
  558.  
  559.    This chapter discusses some of the fundamental elements of the QuickBASIC
  560.    version of the BASIC language. As in virtually all programming languages,
  561.    characters from the BASIC character set form labels, keywords, variables,
  562.    and operators. These then combine to form the statements that make up a
  563.    program.
  564.  
  565.    ■ The BASIC character set and the special meanings of some characters
  566.  
  567.    ■ The format of a line in a BASIC program
  568.  
  569.    ■ Line labels
  570.  
  571.    ■ Executable and nonexecutable statements
  572.  
  573.    ■ Program line length
  574.  
  575.    Chapter 2, "Data Types," and Chapter 3, "Expressions and Operators,"
  576.    discuss other parts of statements, including expressions.
  577.  
  578.  
  579.  1.1  Character Set
  580.  
  581.    The Microsoft BASIC character set consists of alphabetic characters,
  582.    numeric characters, and special characters.
  583.  
  584.    The alphabetic characters in BASIC are the uppercase letters (A-Z) and
  585.    lowercase letters (a-z) of the alphabet.
  586.  
  587.    The BASIC numeric characters are the digits 0-9. The letters A-F and a-f
  588.    can be used as parts of hexadecimal numbers. The characters in Table 1.1
  589.    have special meanings in BASIC statements and expressions.
  590.  
  591.    Table 1.1   BASIC Character Set
  592.  
  593. ╓┌─┌──────────────────┌──────────────────────────────────────────────────────╖
  594.    Character          Name
  595.    ──────────────────────────────────────────────────────────────────────────
  596.    ENTER              Terminates input of a line
  597.                       Blank (or space)
  598.    !                  Exclamation point (single-precision data-type suffix)
  599.    #                  Number sign (double-precision data-type suffix)
  600.    $                  Dollar sign (suffix for string data type)
  601.    %                  Percent (suffix for integer data type)
  602.    &                  Ampersand (suffix for long-integer data type)
  603.    '                  Single quotation mark (apostrophe)
  604.    (                  Left parenthesis
  605.    )                  Right parenthesis
  606.    *                  Asterisk (multiplication symbol)
  607.    +                  Plus sign
  608.    ,                  Comma
  609.    -                  Minus sign
  610.    .                  Period (decimal point)
  611.    Character          Name
  612.    ──────────────────────────────────────────────────────────────────────────
  613.   .                  Period (decimal point)
  614.    /                  Slash (division symbol)
  615.    :                  Colon
  616.    ;                  Semicolon
  617.    <                  Less than
  618.    =                  Equal sign (relational operator or assignment symbol)
  619.    >                  Greater than
  620.    ?                  Question mark
  621.    @                  At symbol
  622.    [                  Left bracket
  623.    ]                  Right bracket
  624.    \                  Backslash (integer division symbol)
  625.    ^                  Up arrow or caret (exponentiation symbol)
  626.    _                  Underscore (line continuation)
  627.    ──────────────────────────────────────────────────────────────────────────
  628.  
  629.  
  630.  
  631.  1.2  The BASIC Program Line
  632.  
  633.    BASIC program lines have the following syntax:
  634.  
  635.    [[line-identifier]] [[statement]] [[: statement]]...[[comment]]
  636.  
  637.  1.2.1  Using Line Identifiers
  638.  
  639.    BASIC supports two types of line-identifiers──line numbers and
  640.    alpha-numeric line labels:
  641.  
  642.    1. A line number may be any combination of digits from 0 to 65,529. The
  643.       following are examples of valid line numbers:
  644.  
  645.       1
  646.       200
  647.       300PRINT "hello"    '300 is the line number.
  648.       65000
  649.  
  650.       Using 0 as a line number is not recommended. Error- and event-trapping
  651.       statements (ON ERROR and ONevent) interpret the presence of line number
  652.       0 to mean that trapping is disabled (stopped). For example, the
  653.       following statement disables error trapping but does not branch to line
  654.       0 if an error occurs:
  655.  
  656.       ON ERROR GOTO 0
  657.  
  658.       In addition, RESUME 0 continues execution on the line where the error
  659.       occurred, not at line number 0.
  660.  
  661.    2. An alphanumeric line label may be any combination of from 1 to 40
  662.       letters and digits, starting with a letter and ending with a colon.
  663.       BASIC keywords are not permitted. The following are valid alphanumeric
  664.       line labels:
  665.  
  666.       Alpha:
  667.       ScreenSub:
  668.       Test3A:
  669.  
  670.       Case is not significant. The following line labels are equivalent:
  671.  
  672.       alpha:
  673.       Alpha:
  674.       ALPHA:
  675.  
  676.    Line numbers and labels may begin in any column, as long as they are the
  677.    first characters other than blanks or tabs on the line. Blanks and tabs
  678.    are also allowed between an alphanumeric label and the colon following it.
  679.    A line can have only one label.
  680.  
  681.    BASIC does not require each line in a source program to have the same type
  682.    of identifier, either a line number or label. You may mix alphanumeric
  683.    labels and line numbers in the same program, and you may use alphanumeric
  684.    labels as objects of any BASIC statement where line numbers are permitted,
  685.    except as the object of an IF...THEN statement. In IF...THEN statements,
  686.    BASIC permits only a line number, unless you explicitly use a GOTO
  687.    statement. For example, the form of the following statement is correct:
  688.  
  689.    IF A = 10 THEN 500
  690.  
  691.    However, if the object of the IF...THEN statement is a line label, a GOTO
  692.    statement is required:
  693.  
  694.    IF A = 10 THEN GOTO IncomeData
  695.  
  696.    If you are trapping errors, the ERL function returns only the last line
  697.    number located before the error. Neither RESUME nor RESUME NEXT requires
  698.    line labels or line numbers. See the entries for ERL and RESUME for more
  699.    information.
  700.  
  701.    Line numbers do not determine the order in which statements are executed
  702.    in QuickBASIC. For example, QuickBASIC executes statements in the
  703.    following program in the order 100, 10, 5:
  704.  
  705.    100 PRINT "The first line executed."
  706.     10 PRINT "The second line executed."
  707.      5 PRINT "The third and final line executed."
  708.  
  709.    Some older BASICs, such as BASICA, would execute the lines in numerical
  710.    order: 5, 10, 100.
  711.  
  712.  1.2.2  BASIC Statements
  713.  
  714.    A BASIC statement is either "executable" or nonexecutable." An executable
  715.    statement advances the flow of a program's logic by telling the program
  716.    what to do next (telling it to read input, write output, add two numbers
  717.    together and store the resulting value in a variable, open a file, branch
  718.    to another part of the program, or take some other action). In contrast, a
  719.    nonexecutable statement does not advance the flow of a program's logic.
  720.    Instead, nonexecutable statements perform tasks such as allocating storage
  721.    for variables, declaring and defining variable types, and designating
  722.    variables to be shared among all the procedures in a source file.
  723.  
  724.    The following BASIC statements are nonexecutable:
  725.  
  726.    ■ COMMON
  727.  
  728.    ■ CONST
  729.  
  730.    ■ DATA
  731.  
  732.    ■ DECLARE
  733.  
  734.    ■ DEFtype
  735.  
  736.    ■ DIM (static arrays only)
  737.  
  738.    ■ OPTION BASE
  739.  
  740.    ■ SHARED
  741.  
  742.    ■ STATIC
  743.  
  744.    ■ TYPE...END TYPE
  745.  
  746.    Another type of nonexecutable statement is a "comment" used to clarify a
  747.    program's operation and purpose. A comment is introduced by the REM
  748.    statement or a single quote character ('). The following lines are
  749.    equivalent:
  750.  
  751.    PRINT "Quantity remaining" : REM Print report label.
  752.    PRINT "Quantity remaining"     ' Print report label.
  753.  
  754.    More than one BASIC statement can be placed on a line, but colons (:) must
  755.    separate statements, as illustrated below:
  756.  
  757.    FOR I=1 TO 5 : PRINT "G'day, mate." : NEXT I
  758.  
  759.  1.2.3  BASIC Line Length
  760.  
  761.    If you enter your programs using QuickBASIC's built-in editor, you are
  762.    limited to lines of 256 characters. The QuickBASIC editor does not
  763.    recognize the underscore character (_) as a line continuation.
  764.  
  765.    If you use your own editor, you may use an underscore as the last
  766.    character to create a program line, like the following, that extends
  767.    across more than one physical line:
  768.  
  769.    IF (TestChar$ = " " OR TestChar$ = ".") AND _
  770.    LineNumber < 23 AND NOT EOF(FileNumber) THEN
  771.  
  772.    When QuickBASIC loads your program, the underscores are removed and the
  773.    continued lines are joined to form a single line. The line-length limit is
  774.    relaxed in this case. Underscores cannot be used to continue DATA or REM
  775.    statements.
  776.  
  777.  
  778.  
  779.  ────────────────────────────────────────────────────────────────────────────
  780.  Chapter 2   Data Types
  781.  
  782.        2.1  Data Types
  783.          2.1.1   Elementary Data Types──String
  784.          2.1.2   Elementary Data Types──Numeric
  785.            2.1.2.1   Integer Numbers
  786.            2.1.2.2   Floating-Point Numbers
  787.          2.1.3   User-Defined Data Types
  788.        2.2  Constants
  789.          2.2.1   Literal Constants
  790.          2.2.2   Symbolic Constants
  791.        2.3  Variables
  792.          2.3.1   Variable Names
  793.          2.3.2   Declaring Variable Types
  794.            2.3.2.1   Type-Declaration Suffix
  795.            2.3.2.2   AS Declaration Statements
  796.            2.3.2.3   DEFtype Declaration Statements
  797.            2.3.2.4   Declaring Array Variables
  798.          2.3.3   Variable Storage Allocation
  799.        2.4  Scope of Variables and Constants
  800.          2.4.1   Global Variables and Constants
  801.          2.4.2   Local Variables and Constants
  802.          2.4.3   Sharing Variables
  803.          2.4.4   DEF FN Functions
  804.          2.4.5   Summary of Scope Rules
  805.        2.5  Static and Dynamic Arrays
  806.        2.6  Automatic and Static Variables
  807.        2.7  Type Conversion
  808.  
  809.    This chapter contains seven sections that provide the following
  810.    information about the data types, constants, and variables in BASIC:
  811.  
  812.    ■ The elementary data types (string and numeric)
  813.  
  814.    ■ The formation of literal and symbolic constants
  815.  
  816.    ■ The rules for naming a BASIC variable and for determining a variable's
  817.      type, and how BASIC allocates variable storage
  818.  
  819.    ■ The scope rules that BASIC follows to decide to which object a variable
  820.      name refers
  821.  
  822.    ■ The difference between static and dynamic arrays
  823.  
  824.    ■ The use of automatic and static variables in SUB and FUNCTION procedures
  825.  
  826.    ■ The conversions from one numeric type to another that BASIC may perform
  827.      when doing calculations
  828.  
  829.  
  830.  2.1  Data Types
  831.  
  832.    Every variable in BASIC has a data type that determines what can be stored
  833.    in the variable. There are two categories of data in BASIC: string data
  834.    and numeric data. Each category includes elementary data types. The next
  835.    section summarizes the elementary data types.
  836.  
  837.  2.1.1  Elementary Data Types──String
  838.  
  839.    The two kinds of strings are as follows:
  840.  
  841.    ■ Variable-length string
  842.  
  843.      A variable-length string is a sequence of up to 32,767 characters. The
  844.      codes for these characters range from 0-127 for American Standard Code
  845.      for Information Interchange (ASCII) characters, and from 128-255 for
  846.      non-ASCII characters (see Appendix A, "Keyboard Scan Codes and ASCII
  847.      Character Codes").
  848.  
  849.    ■ Fixed-length string
  850.  
  851.      A fixed-length string contains a declared number of characters.
  852.      Fixed-length strings can be no longer than 32,767 characters.
  853.      Fixed-length strings, like variable-length strings, contain characters
  854.      with codes ranging from 0-255.
  855.  
  856.  2.1.2  Elementary Data Types──Numeric
  857.  
  858.    BASIC has two types of integers and two types of floating-point values.
  859.    Figure 2.1 shows the internal (memory) formats of these four different
  860.    numeric types. The following table summarizes the types:
  861.  
  862.    Numeric Type             Description
  863.    ──────────────────────────────────────────────────────────────────────────
  864.    Integer (2 bytes)        Integers are stored as signed 16-bit binary
  865.                             numbers ranging in value from -32,768 to +32,767.
  866.  
  867.    Long integer (4 bytes)   "Long" integers are stored as signed 32-bit
  868.                             binary numbers ranging in value from
  869.                             -2,147,483,648 to +2,147,483,647.
  870.  
  871.    Single-precision         "Single-precision" numbers are accurate to seven
  872.    floating point (4 bytes) decimal places, and have ranges of -3.402823E+38
  873.                             to -1.40129E-45 for negative values and
  874.                             1.40129E-45 to 3.402823E+38 for positive values.
  875.  
  876.    Double-precision         "Double-precision" numbers are accurate to 15 or
  877.    floating point (8 bytes) 16 digits and have an extended range:
  878.                             -1.797693134862316E+308 to -4.94065E-324 for
  879.                             negative numbers and 4.94065E-324 to
  880.                             1.797693134862316E+308 for positive values.
  881.    ──────────────────────────────────────────────────────────────────────────
  882.  
  883.    2.1.2.1  Integer Numbers
  884.  
  885.  
  886.       Integer
  887.       1514                     0
  888.      ┌─┬───────────────────────┐
  889.      │ │                       │
  890.      └─┴───────────────────────┘
  891.       │
  892.     sign
  893.  
  894.      Long integer
  895.      31 30                               0
  896.      ┌─┬─────────────────────────────────┐
  897.      │ │                                 │
  898.      └─┴─────────────────────────────────┘
  899.  
  900.      Single-precision real
  901.      31 30  23 22                        0
  902.      ┌─┬─────┬───────────────────────────┐
  903.      │ │     │                           │
  904.      └─┴─────┴───────────────────────────┘
  905.       │ └─┬─┘│└──────────┬──────────────┘
  906.       │   │  │           │
  907.     sign  │Implied    Mantissa
  908.           │  bit
  909.           │
  910.       Exponent
  911.  
  912.      Double Precision real
  913.      63 62   52 51
  914.      ┌─┬───────┬───────────────────────────────────────────────────────┐
  915.      │ │       │                                                       │
  916.      └─┴───────┴───────────────────────────────────────────────────────┘
  917.       │ └─┬───┘│└──────────────────────┬──────────────────────────────┘
  918.       │   │    │                       │
  919.     sign  │Implied                  Mantissa
  920.           │  bit
  921.           │
  922.       Exponent
  923.  
  924.              Figure 2.1 BASIC Numeric Representations
  925.  
  926.    All BASIC integers are represented as two's complement values, the most
  927.    common way of representing integers on a computer. Integers use 16 bits (2
  928.    bytes) and long integers use 32 bits (4 bytes).
  929.  
  930.    In two's complement representation, positive values are represented as
  931.    straightforward binary numbers. For example, BASIC would store an integer
  932.    value of 4 as a sequence of the following 16 bits:
  933.  
  934.    0000000000000100
  935.  
  936.    Negative values are represented as the two's complement of the
  937.    corresponding positive value. To form the two's complement (the negative)
  938.    of the integer value 4, first take the representation above and change all
  939.    ones to zeroes and all zeroes to ones:
  940.  
  941.    1111111111111011
  942.  
  943.    Then add one to the result:
  944.  
  945.    1111111111111100
  946.  
  947.    The final result is how BASIC represents -4 as a binary number.
  948.  
  949.    Because of the way two's complement numbers are formed, every combination
  950.    of bits representing a negative value has a 1 as the leftmost bit.
  951.  
  952.    2.1.2.2  Floating-Point Numbers
  953.  
  954.    QuickBASIC Version 4.5 uses IEEE-format floating-point numbers rather than
  955.    the Microsoft Binary format used in earlier versions. (IEEE is an acronym
  956.    for Institute of Electrical and Electronics Engineers, Inc.) IEEE format
  957.    gives more accurate results and makes it possible to use an 8087 or 80287
  958.    math coprocessor.
  959.  
  960.    Floating-point values are represented in a different format from integers.
  961.    In floating-point format each number consists of three parts: the sign,
  962.    the exponent, and the mantissa. You can think of this format as a
  963.    variation of scientific notation. In scientific notation, the number 1000
  964.    would be represented as 1.0 x 10^3. To save space, you could just remember
  965.    the exponent, 3, and the mantissa, 1.0, and reconstruct the value later by
  966.    raising 10 to the power 3 and multiplying by the mantissa. Floating-point
  967.    notation works by saving just the exponent and the mantissa. The only
  968.    difference from scientific notation is that in this format the exponent
  969.    represents a power of 2, not a power of 10.
  970.  
  971.    In a single-precision number, the sign takes 1 bit, the exponent takes 8
  972.    bits, and the mantissa uses the remaining 23 bits and an additional
  973.    implied bit. Double-precision values occupy 8 bytes or 64 bits: 1 bit for
  974.    the sign, 11 bits for the exponent, and an implied bit and 52 actual bits
  975.    for the mantissa.
  976.  
  977.    The following program (included on the QuickBASIC distribution disks in
  978.    the file FLPT.BAS) can be used to examine the internal format of
  979.    single-precision values:
  980.  
  981.    DECLARE FUNCTION MHex$ (X AS INTEGER)
  982.    ' Display how a given real value is stored in memory.
  983.  
  984.    DEFINT A-Z
  985.    DIM Bytes(3)
  986.    CLS
  987.    PRINT "Internal format of IEEE number (in hexadecimal)"
  988.    PRINT
  989.    DO
  990.  
  991.    ' Get the value.
  992.    INPUT "Enter the value (END to end): ", A$
  993.    IF UCASE$(A$) = "END" THEN EXIT DO
  994.    RealValue! = VAL(A$)
  995.    ' Convert the real value to a long without changing any of
  996.    ' the bits.
  997.    AsLong& = CVL(MKS$(RealValue!))
  998.    ' Make a string of hex digits, and add leading zeroes.
  999.    Strout$ = HEX$(AsLong&)
  1000.    Strout$ = STRING$(8 - LEN(Strout$), "0") + Strout$
  1001.    ' Save the sign bit, and then eliminate it so it doesn't
  1002.    ' affect breaking out the bytes.
  1003.    SignBit&=AsLong& AND &H80000000&
  1004.    AsLong&=AsLong& AND &H7FFFFFFF&
  1005.    ' Split the real value into four separate bytes.
  1006.    ' --the AND removes unwanted bits; dividing by 256 shifts
  1007.    ' the value right 8 bit positions.
  1008.    FOR I = 0 TO 3
  1009.       Bytes(I) = AsLong& AND &HFF&
  1010.       AsLong& = AsLong&  256&
  1011.    NEXT I
  1012.    ' Display how the value appears in memory.
  1013.    PRINT
  1014.    PRINT "Bytes in Memory"
  1015.    PRINT "  High    Low"
  1016.    FOR I = 1 TO 7 STEP 2
  1017.       PRINT " "; MID$(Strout$, I, 2);
  1018.    NEXT I
  1019.    PRINT:PRINT
  1020.    ' Set the value displayed for the sign bit.
  1021.    Sign = ABS(SignBit& <> 0)
  1022.  
  1023.    ' The exponent is the right seven bits of byte 3 and the
  1024.    ' leftmost bit of byte 2. Multiplying by 2 shifts left and
  1025.    ' makes room for the additional bit from byte 2.
  1026.    Exponent = Bytes(3) * 2 + Bytes(2)  128
  1027.  
  1028.    ' The first part of the mantissa is the right seven bits
  1029.    ' of byte 2. The OR operation makes sure the implied bit
  1030.    ' is displayed by setting the leftmost bit.
  1031.    Mant1 = (Bytes(2) OR &H80)
  1032.    PRINT " Bit 31    Bits 30-23  Implied Bit & Bits 22-0"
  1033.    PRINT "Sign Bit  Exponent Bits     Mantissa Bits"
  1034.    PRINT TAB(4); Sign; TAB(17); MHex$(Exponent);
  1035.    PRINT TAB(33); MHex$(Mant1);MHex$(Bytes(1));MHex$(Bytes(0))
  1036.    PRINT
  1037.  
  1038.    LOOP
  1039.  
  1040.    ' MHex$ makes sure we always get two hex digits.
  1041.    FUNCTION MHex$ (X AS INTEGER) STATIC
  1042.       D$ = HEX$(X)
  1043.       IF LEN(D$) < 2 THEN D$ = "0" + D$
  1044.       MHex$ = D$
  1045.    END FUNCTION
  1046.  
  1047.    Output
  1048.  
  1049.    Enter the value (END to end): 4
  1050.  
  1051.    Bytes in Memory
  1052.      High    Low
  1053.      40 80 00 00
  1054.  
  1055.     Bit 31    Bits 30-23  Implied Bit & Bits 22-0
  1056.    Sign Bit  Exponent Bits     Mantissa Bits
  1057.        0           81              800000
  1058.  
  1059.    The program displays the sign, exponent, and mantissa of the
  1060.    single-precision value. The mantissa's implied bit is automatically
  1061.    included. All values are printed out in hexadecimal values (base 16
  1062.    numbers), which are a shorthand way of writing binary numbers. Each
  1063.    hexadecimal digit represents a pattern of 4 bits: 0 hexadecimal represents
  1064.    0000 binary, 8 hexadecimal represents 1000, and F hexadecimal (a digit for
  1065.    the value 15 in decimal) represents 1111.
  1066.  
  1067.    Looking at the output from the program, the decimal value 4 is represented
  1068.    in memory as a series of 4 bytes:
  1069.  
  1070.    40 80 00 00
  1071.  
  1072.    These 4 bytes break down into a single-sign bit of 0, a 1-byte exponent of
  1073.    &H81, and a mantissa of &H800000.
  1074.  
  1075.    The exponent value of &H81 represents a biased exponent, not the true
  1076.    exponent. With a biased exponent, a fixed value (a "bias") is added to the
  1077.    true exponent and the result is stored as part of the number. For
  1078.    single-precision values, the bias is &H7F or 127. Double-precision values
  1079.    use a bias of &H3FF or 1023. Using a biased exponent avoids having to use
  1080.    one of the exponent bits to represent the sign. In the output, 4 is a
  1081.    power of 2, so the true exponent is 2. Adding the bias (&H7F) gives the
  1082.    stored exponent value of &H81.
  1083.  
  1084.    A normalized mantissa refers to a mantissa that is multiplied by 2
  1085.    (shifted to the left) and the exponent decreased until the leftmost bit is
  1086.    a 1. By eliminating leading zeroes from the mantissa, more significant
  1087.    bits can be stored. In memory, the mantissa for a value of 4 is all
  1088.    zeroes. This is so because the mantissa is normalized and the leftmost bit
  1089.    is assumed.
  1090.  
  1091.    Because the mantissa is always normalized, the leftmost bit is always a 1.
  1092.    And because the leftmost bit is always a 1, there is no reason to store it
  1093.    as part of the number. BASIC thus stores 23 bits (number 22 to 0) for the
  1094.    mantissa of a single-precision number but also includes a 24th, implied
  1095.    bit that is always a 1.
  1096.  
  1097.    There is an implied "binary point" (analogous to a decimal point) to the
  1098.    right of the implied bit. The binary point indicates that bits 22 to 0 in
  1099.    the mantissa are really a binary fraction. Thus, in the example, the
  1100.    mantissa is really a single 1 (the implied bit) followed by a zero binary
  1101.    fraction (bits 22 to 0). The mantissa of 1 multiplied by 2 taken to the
  1102.    power of the exponent, 2, is 1 x 2^2, or 4.
  1103.  
  1104.  2.1.3  User-Defined Data Types
  1105.  
  1106.    BASIC lets you define new data types using the TYPE statement. A
  1107.    user-defined type is an aggregate type made up of elementary BASIC types.
  1108.    For example, the following TYPE statement defines a type, SymTabEntry:
  1109.  
  1110.    TYPE SymTabEntry
  1111.       Identifier AS STRING*40
  1112.       LineNumber AS LONG
  1113.       Value      AS LONG
  1114.    END TYPE
  1115.  
  1116.    The new type contains a fixed-length string and two long integers. A
  1117.    variable of a user-defined type occupies only as much storage as the sum
  1118.    of its components. A SymTabEntry takes up 48 bytes: 40 bytes for the
  1119.    fixed-length string and 4 bytes each for the two long integers.
  1120.  
  1121.    You may use any of the BASIC data types (except variable-length strings)
  1122.    in a user-defined type: short and long integers, single- and
  1123.    double-precision floating-point values, and fixed-length strings. However,
  1124.    user-defined types cannot include arrays.
  1125.  
  1126.  
  1127.  2.2  Constants
  1128.  
  1129.    Constants are predefined values that do not change during program
  1130.    execution. There are two general types of constants: literal constants
  1131.    (such as numbers and strings) and symbolic constants.
  1132.  
  1133.  2.2.1  Literal Constants
  1134.  
  1135.    BASIC has two kinds of literal constants: string and numeric. A string
  1136.    constant is a sequence of up to 32,767 alphanumeric characters enclosed by
  1137.    double quotation marks. These alphanumeric characters can be any of the
  1138.    characters (except the double quote character and any carriage-return and
  1139.    line-feed sequences) whose ASCII codes fall within the range 0-255. This
  1140.    range includes both the actual ASCII characters (0-127) and the extended
  1141.    characters (128-255). The following are all valid string constants:
  1142.  
  1143.    "HELLO"
  1144.    "$25,000.000"
  1145.    "Number of Employees"
  1146.  
  1147.    Numeric constants are positive or negative numbers. There are four types
  1148.    of numeric constants: integer, long integer, fixed point, and floating
  1149.    point. Table 2.1 below describes these types and provides examples.
  1150.  
  1151.    Fixed-point and floating-point numeric constants can be either
  1152.    single-precision or double-precision numbers. Single-precision numeric
  1153.    constants are stored with 7 digits of precision (plus the exponent).
  1154.    Double-precision numbers are stored with 15 or 16 digits of precision
  1155.    (plus the exponent).
  1156.  
  1157.    A single-precision constant is any numeric constant that has one of the
  1158.    following properties:
  1159.  
  1160.    ■ Exponential form denoted by "E"
  1161.  
  1162.    ■ A trailing exclamation mark (!)
  1163.  
  1164.    ■ A value containing a decimal point that does not have either a "D" in
  1165.      the exponent or a trailing number sign (#) and that has fewer than 15
  1166.      digits
  1167.  
  1168.    ■ A value without a decimal point that has fewer than 15 digits but cannot
  1169.      be represented as a long-integer value
  1170.  
  1171.    A double-precision constant is any numeric constant that has one of the
  1172.    following properties:
  1173.  
  1174.    ■ Exponential form denoted by "D"
  1175.  
  1176.    ■ A trailing number sign (#)
  1177.  
  1178.    ■ A decimal point, no "E" in the exponent or trailing exclamation mark
  1179.      (!), and more than 15 digits
  1180.  
  1181.    Table 2.1   Types of Numeric Constants
  1182.  
  1183. ╓┌─┌──────────────────┌─────────────────┌──────────────────┌─────────────────╖
  1184.    Type               Subtype           Description        Examples
  1185.    ──────────────────────────────────────────────────────────────────────────
  1186.    Integer            Decimal           One or more        68 +407 -1
  1187.                                         decimal digits
  1188.                                         (0-9) with an
  1189.                                         optional sign
  1190.                                         prefix (+ or -).
  1191.                                         The range for
  1192.                                         integer decimal
  1193.                                         constants is
  1194.                                         -32,768 to
  1195.                                         +32,767.
  1196.  
  1197.    Integer            Hexadecimal       One or more        &H76 &H32F
  1198.                                         hexadecimal digits
  1199.    Type               Subtype           Description        Examples
  1200.    ──────────────────────────────────────────────────────────────────────────
  1201.                                        hexadecimal digits
  1202.                                         (0-9, a-f, or A-F)
  1203.                                         with the prefix &H
  1204.                                         or &h. The range
  1205.                                         for integer
  1206.                                         hexadecimal
  1207.                                         constants is &h0
  1208.                                         to &hFFFF.
  1209.  
  1210.    Integer            Octal             One or more octal  &o347 &1234
  1211.                                         digits (0-7) with
  1212.                                         the prefix &O, &o,
  1213.                                         or &. The range
  1214.                                         for integer octal
  1215.                                         constants is &o0
  1216.                                         to &o177777.
  1217.  
  1218.    Long integer       Decimal           One or more        95000000 -400141
  1219.                                         decimal digits
  1220.    Type               Subtype           Description        Examples
  1221.    ──────────────────────────────────────────────────────────────────────────
  1222.                                        decimal digits
  1223.                                         (0-9) with an
  1224.                                         optional sign
  1225.                                         prefix (+ or -)
  1226.                                         and the suffix &.
  1227.                                         The range for long
  1228.                                         decimal constants
  1229.                                         is -2,147,483,648
  1230.                                         to +2,147,483,647.
  1231.  
  1232.    Long integer       Hexadecimal       One or more        &H0& &H1AAAAA&
  1233.                                         hexadecimal digits
  1234.                                         (0-9, a-f, or A-F)
  1235.                                         with the prefix &H
  1236.                                         or &h and the
  1237.                                         suffix &. The
  1238.                                         range for long
  1239.                                         hexadecimal
  1240.                                         constants is &h0&
  1241.    Type               Subtype           Description        Examples
  1242.    ──────────────────────────────────────────────────────────────────────────
  1243.                                        constants is &h0&
  1244.                                         to &hFFFFFFFF&.
  1245.  
  1246.    Long integer       Octal             One or more octal  &o347& &555577733&
  1247.                                         digits (0-7) with
  1248.                                         the prefix &O, &o,
  1249.                                         or & and the
  1250.                                         suffix &. The
  1251.                                         range for long
  1252.                                         octal constants is
  1253.                                         &o0& to
  1254.                                         &o37777777777&.
  1255.  
  1256.    Fixed point                          Positive or        9.0846
  1257.                                         negative real
  1258.                                         numbers──numbers
  1259.                                         containing decimal
  1260.                                         points.
  1261.  
  1262.    Type               Subtype           Description        Examples
  1263.    ──────────────────────────────────────────────────────────────────────────
  1264. 
  1265.    Floating point     Single precision  Positive or        2235.988E-7 2359E6
  1266.                                         negative numbers
  1267.                                         represented in
  1268.                                         exponential form
  1269.                                         (similar to
  1270.                                         scientific
  1271.                                         notation). A
  1272.                                         single-precision
  1273.                                         floating-point
  1274.                                         constant is an
  1275.                                         optionally signed
  1276.                                         integer or
  1277.                                         fixed-point number
  1278.                                         (the mantissa)
  1279.                                         followed by the
  1280.                                         letter E and an
  1281.                                         optionally signed
  1282.                                         integer (the
  1283.    Type               Subtype           Description        Examples
  1284.    ──────────────────────────────────────────────────────────────────────────
  1285.                                        integer (the
  1286.                                         exponent). The
  1287.                                         constant's value
  1288.                                         is the mantissa
  1289.                                         multiplied by the
  1290.                                         power of ten
  1291.                                         represented by the
  1292.                                         exponent. The
  1293.                                         range for
  1294.                                         single-precision
  1295.                                         constants is
  1296.                                         -3.37E+38 to
  1297.                                         3.37E+38.
  1298.  
  1299.    Floating point     Double precision  Double-precision   4.35D-10
  1300.                                         floating-point
  1301.                                         constants have the
  1302.                                         same form as
  1303.                                         single-precision
  1304.    Type               Subtype           Description        Examples
  1305.    ──────────────────────────────────────────────────────────────────────────
  1306.                                        single-precision
  1307.                                         floating-point
  1308.                                         constants, but use
  1309.                                         D, rather than E,
  1310.                                         to indicate the
  1311.                                         exponent.
  1312.                                         Double-precision
  1313.                                         constants have a
  1314.                                         range of
  1315.                                         -1.67D+308 to
  1316.                                         1.67D+308.
  1317.    ──────────────────────────────────────────────────────────────────────────
  1318.  
  1319.  
  1320.    Numeric constants in BASIC cannot contain commas. The following are
  1321.    examples of numeric constants:
  1322.  
  1323.    Single Precision         Double Precision
  1324.    ──────────────────────────────────────────────────────────────────────────
  1325.    46.8                     345692811.5375901
  1326.    -1.09E-6                 -1.09432D-06
  1327.    3489.0                   3489.0#
  1328.    22!                      987654321.1234567
  1329.    ──────────────────────────────────────────────────────────────────────────
  1330.  
  1331.  2.2.2  Symbolic Constants
  1332.  
  1333.    BASIC provides symbolic constants that can be used in place of numeric or
  1334.    string values. The following fragment declares two symbolic constants and
  1335.    uses one to dimension an array:
  1336.  
  1337.    CONST MAXCHARS%=254, MAXBUF%=MAXCHARS%+1
  1338.    DIM Buffer%(MAXBUF%)
  1339.  
  1340.    The name of a symbolic constant follows the same rules as a BASIC variable
  1341.    name. You may include a type-declaration character (%, #, !, or $) in the
  1342.    name to indicate its type, but this character is not part of the name. For
  1343.    example, after the following declaration, the names N!, N#, N$, N%, and N&
  1344.    cannot be used as variable names because they have the same name as the
  1345.    constant:
  1346.  
  1347.    CONST N=45
  1348.  
  1349.    A constant's type is determined either by an explicit type-declaration
  1350.    character or the type of the expression. Symbolic constants are unaffected
  1351.    by DEFtype statements.
  1352.  
  1353.    If you omit the type-declaration character, the constant is given a type
  1354.    based on the expression. Strings always yield a string constant. With
  1355.    numeric expressions, the expression is evaluated and the constant is given
  1356.    the simplest type that can represent it. For example, if the expression
  1357.    gives a result that can be represented as an integer, the constant is
  1358.    given an integer type.
  1359.  
  1360.    See Section 2.4 below, "Scope of Variables and Constants," for
  1361.    information about the scope of constants. See the entry for CONST in Part
  1362.    2, "Statement and Function Reference," for more information about where
  1363.    and how to use symbolic constants.
  1364.  
  1365.  
  1366.  2.3  Variables
  1367.  
  1368.    A variable is a name that refers to an object──a particular number,
  1369.    string, or record. (A record is a variable declared to be a user-defined
  1370.    type.) Simple variables refer to a single number, string, or record. Array
  1371.    variables refer to a group of objects, all of the same type.
  1372.  
  1373.    A numeric variable, whether simple or array, can be assigned only a
  1374.    numeric value (either integer, long integer, single precision, or double
  1375.    precision); a string variable can be assigned only a character-string
  1376.    value. You can assign one record variable to another only if both
  1377.    variables are the same user-defined type. However, you can always assign
  1378.    individual elements of a record to a variable of the corresponding type.
  1379.  
  1380.    The following list shows some examples of variable assignments:
  1381.  
  1382.    Variable Assignment      Example
  1383.    ──────────────────────────────────────────────────────────────────────────
  1384.    A constant value         A = 4.5
  1385.  
  1386.    The value of another     B$ = "ship of fools" A$ = B$ Profits =
  1387.    string or numeric        NetEarnings
  1388.    variable
  1389.    The value of a record    TYPE EmployeeRec EName AS STRING*25 SocSec AS
  1390.    element                  STRING*9 END TYPE DIM CurrentEmp AS EmployeeRec .
  1391.                             . . OutSocSec$=CurrentEmp.SocSec
  1392.  
  1393.    The value of one record  TYPE FileBuffer EName AS STRING*25 JobClass AS
  1394.    variable to another of   INTEGER END TYPE DIM Buffer1 AS FileBuffer DIM
  1395.    the same type            Buffer2 AS FileBuffer . . . Buffer2=Buffer1
  1396.  
  1397.    The value obtained by    CONST PI = 3.141593 Conversion = 180/PI TempFile$
  1398.    combining other          = FileSpec$+".BAK"
  1399.    variables, constants,
  1400.    and operators
  1401.    ──────────────────────────────────────────────────────────────────────────
  1402.  
  1403.    See Chapter 3, "Expressions and Operators," for more information on the
  1404.    operators used in BASIC for combining variables and constants. In any
  1405.    case, the variable must always match the type of data (numeric or string)
  1406.    assigned to it.
  1407.  
  1408.    Before a variable is assigned a value, its value is assumed to be zero
  1409.    (for numeric variables) or null (for string variables). All fields in a
  1410.    record, including string fields, are initialized to zero.
  1411.  
  1412.  2.3.1  Variable Names
  1413.  
  1414.    A BASIC variable name may contain up to 40 characters. The characters
  1415.    allowed in a variable name are letters, numbers, the decimal point, and
  1416.    the type-declaration characters (%, &, !, #, and $).
  1417.  
  1418.    The first character in a variable name must be a letter. If a variable
  1419.    begins with FN, it is assumed to be a call to a DEF FN function. (As a
  1420.    general rule, the use of a FUNCTION is preferred over a DEF FN.)
  1421.  
  1422.    A variable name cannot be a reserved word, but embedded reserved words are
  1423.    allowed. For example, the following statement is illegal because LOG is a
  1424.    reserved word (BASIC is not case sensitive):
  1425.  
  1426.    Log = 8
  1427.  
  1428.    However, the following statement is legal:
  1429.  
  1430.    TimeLog = 8
  1431.  
  1432.    Reserved words include all BASIC commands, statements, function names, and
  1433.    operator names (see Appendix E, "BASIC Reserved Words," in Programming in
  1434.    BASIC for a complete list of reserved words).
  1435.  
  1436.    Variable names must also be distinct from both SUB and FUNCTION procedure
  1437.    names and symbolic constant (CONST) names.
  1438.  
  1439.  2.3.2  Declaring Variable Types
  1440.  
  1441.    Simple variables can be numeric, string, or record variables. You may
  1442.    specify simple variable types by the use of a type-declaration suffix, in
  1443.    an AS declaration statement, or in a DEFtype declaration statement.
  1444.    Variables may also be declared as arrays.
  1445.  
  1446.    2.3.2.1  Type-Declaration Suffix
  1447.  
  1448.    Append one of the following type-declaration suffixes to the variable
  1449.    name:
  1450.  
  1451.    % & ! # $
  1452.  
  1453.    The dollar sign ($) is the type-declaration character for string
  1454.    variables; that is, it "declares" that the variable represents a string
  1455.    and that you can assign a string constant to it of up to 32,767
  1456.    characters, as in the example below.
  1457.  
  1458.    A$ = "SALES REPORT"
  1459.  
  1460.    Numeric-variable names can declare integer values (denoted by the %
  1461.    suffix), long-integer values (denoted by the & suffix), single-precision
  1462.    values (denoted by the ! suffix), or double-precision values (denoted by
  1463.    the # suffix). Single precision is the default for variables without a
  1464.    type suffix.
  1465.  
  1466.    There is no type-declaration character for a user-defined type.
  1467.  
  1468.    2.3.2.2  AS Declaration Statements
  1469.  
  1470.    Declare the variable in a declaration having the form
  1471.  
  1472.    declare variablename AS type
  1473.  
  1474.    where declare can be either DIM, COMMON, REDIM, SHARED, or STATIC, and
  1475.    type can be either INTEGER, LONG, SINGLE, DOUBLE, STRING, or a
  1476.    user-defined type. For example, the following statement declares the
  1477.    variable A as having a long-integer type:
  1478.  
  1479.    DIM A AS LONG
  1480.  
  1481.    String variables declared in an AS STRING clause can be either
  1482.    variable-length strings or fixed-length strings. Variable-length strings
  1483.    are "expandable": their length depends on the length of any string
  1484.    assigned to them. Fixed-length strings have a constant length, specified
  1485.    by adding * number to the AS STRING clause, where number is the length of
  1486.    the string in bytes. For example:
  1487.  
  1488.    ' String1 can have a variable length:
  1489.    DIM String1 AS STRING
  1490.  
  1491.    ' String2 has a fixed length of 7 bytes:
  1492.    DIM String2 AS STRING*7
  1493.  
  1494.    String1  = "1234567890"
  1495.    String2  = "1234567890"
  1496.    PRINT String1
  1497.    PRINT String2
  1498.  
  1499.    Output
  1500.  
  1501.    1234567890
  1502.    1234567
  1503.  
  1504.    For more on fixed-length and variable-length strings, see Chapter 4,
  1505.    "String Processing," in Programming in BASIC. Declare record variables by
  1506.    using the name of the user type in the AS clause:
  1507.  
  1508.    TYPE InventoryItem
  1509.       Description AS STRING*25
  1510.       Number AS STRING*10
  1511.       Quantity AS LONG
  1512.       OrderPoint AS LONG
  1513.    END TYPE
  1514.    DIM CurrentItem AS InventoryItem, PreviousItem AS InventoryItem
  1515.  
  1516.    Use the format variablename.elementname to refer to individual elements of
  1517.    the new variable, as in the following example:
  1518.  
  1519.    IF CurrentItem.Description = "Ergonomic Desk Chair" THEN
  1520.       PRINT CurrentItem.Number; CurrentItem.Quantity
  1521.    END IF
  1522.  
  1523.    If you declare a variable with an AS clause, every declaration of the
  1524.    variable must use the AS clause. For example, in the following fragment
  1525.    the AS clause is required in the COMMON statement because AS was also used
  1526.    in the DIM statement:
  1527.  
  1528.    CONST MAXEMPLOYEES=250
  1529.    DIM EmpNames(MAXEMPLOYEES) AS STRING
  1530.    COMMON EmpNames() AS STRING
  1531.    .
  1532.    .
  1533.    .
  1534.  
  1535.    2.3.2.3  DEFtype Declaration Statements
  1536.  
  1537.    Use the BASIC statements DEFINT, DEFLNG, DEFSTR, DEFSNG, and DEFDBL to
  1538.    declare the types for certain variable names. By using one of these
  1539.    DEFtype statements, you can specify that all variables starting with a
  1540.    given letter or range of letters are one of the elementary variable types,
  1541.    without using the trailing declaration character.
  1542.  
  1543.    DEFtype statements only affect variable names in the module in which they
  1544.    appear. See the DEFtype statement reference pages in Part 2, "Statement
  1545.    and Function Reference," for more information.
  1546.  
  1547.    The type-declaration suffixes for variable names, the type names accepted
  1548.    in AS type declarations, and the memory (in bytes) required for each
  1549.    variable type to store the variable's value are listed in Table 2.2.
  1550.  
  1551.    Table 2.2   Variable-Type Memory Requirements
  1552.  
  1553. ╓┌─┌──────────────────┌─────────────────┌──────────────────┌─────────────────╖
  1554.                       AS Type           Variable           Size
  1555.    Suffix             Name              Type               of Data
  1556.                       AS Type           Variable           Size
  1557.    Suffix             Name              Type               of Data
  1558.    ──────────────────────────────────────────────────────────────────────────
  1559.    %                  INTEGER           Integer            2
  1560.  
  1561.    &                  LONG              Long integer       4
  1562.  
  1563.    !                  SINGLE            Single precision   4
  1564.  
  1565.    #                  DOUBLE            Double precision   8
  1566.  
  1567.    $                  STRING            Variable-length    Takes 4 bytes for
  1568.                                         string             descriptor, 1 byte
  1569.                                                            for each character
  1570.                                                            in string
  1571.  
  1572.    $                  STRING*num        Fixed-length       Takes num bytes
  1573.                                         string
  1574.    None               Declared          Record variable    Takes as many
  1575.                       user-defined type                    bytes as the
  1576.                                                            individual
  1577.                       AS Type           Variable           Size
  1578.    Suffix             Name              Type               of Data
  1579.    ──────────────────────────────────────────────────────────────────────────
  1580.                                                           individual
  1581.                                                            elements require
  1582.    ──────────────────────────────────────────────────────────────────────────
  1583.  
  1584.  
  1585.    2.3.2.4  Declaring Array Variables
  1586.  
  1587.    An array is a group of objects referenced with the same variable name. The
  1588.    individual values in an array are elements. Array elements are also
  1589.    variables and can be used in any BASIC statement or function that uses
  1590.    variables. You "dimension" an array when you use it the first time or when
  1591.    you declare the name, type, and number of elements in the array.
  1592.  
  1593.    Each element in an array is referred to by an array variable subscripted
  1594.    with an integer or an integer expression. (You may use noninteger numeric
  1595.    expressions as array subscripts; however, they are rounded to integer
  1596.    values.) The name of an array variable has as many subscripts as there are
  1597.    dimensions in the array. For example, V(10) refers to a value in a
  1598.    one-dimensional array, while T$(1,4) refers to a value in a
  1599.    two-dimensional string array.
  1600.  
  1601.    The default upper subscript value for any array dimension is 10. The
  1602.    maximum subscript value and the number of dimensions can be set by using
  1603.    the DIM statement. (See the reference pages for DIM in Part 2, "Statement
  1604.    and Function Reference," for more information.) The maximum number of
  1605.    dimensions for an array is 60. The maximum number of elements per
  1606.    dimension is 32,767.
  1607.  
  1608.    You may have arrays of any simple variable type, including records. To
  1609.    declare an array of records, first declare the data type in a TYPE
  1610.    statement and then dimension the array:
  1611.  
  1612.    TYPE TreeNode
  1613.       LeftPtr AS INTEGER
  1614.       RightPtr AS INTEGER
  1615.       DataField AS STRING*20
  1616.    END TYPE
  1617.    DIM Tree(500) AS TreeNode
  1618.  
  1619.    Each element of the array Tree is a record of type TreeNode. To use a
  1620.    particular element of a record in an array, use form
  1621.    variablename.elementname (dot notation form):
  1622.  
  1623.    CONST MAXEMPLOYEES=500
  1624.  
  1625.    TYPE EmployeeRec
  1626.       EName  AS STRING*25
  1627.       SocSec AS STRING*9
  1628.    END TYPE
  1629.    DIM Employees(MAXEMPLOYEES) AS EmployeeRec
  1630.    .
  1631.    .
  1632.    .
  1633.    PRINT Employees(I).EName;" ";Employees(I).SocSec
  1634.  
  1635.    Array names are distinct from simple variable names. The array variable T
  1636.    and the simple variable T in the following example are two different
  1637.    variables:
  1638.  
  1639.    DIM T(11)
  1640.    T = 2 : T(0) = 1                   'T is simple variable.
  1641.    FOR I% = 0 TO 10                   'T(0) is element of array.
  1642.        T(I% + 1) = T * T(I%)
  1643.    NEXT
  1644.  
  1645.    Array elements, like simple variables, require a certain amount of memory,
  1646.    depending on the variable type. See Table 2.2 for information on the
  1647.    memory requirements for storing individual array elements.
  1648.  
  1649.    To find the total amount of memory required by an array, multiply the
  1650.    number of elements by the bytes per element required for the array type.
  1651.    For example, consider the following two arrays:
  1652.  
  1653.    DIM Array1(1 TO 100) AS INTEGER
  1654.    DIM Array#(-5 TO 5)
  1655.  
  1656.    The first array, Array1, has 100 integer elements, so its values take 200
  1657.    bytes of memory. The second array, Array2, has 11 double-precision
  1658.    elements, so its values require 88 bytes of memory. Because BASIC must
  1659.    store information about the array along with the array's values, arrays
  1660.    take more memory than just the space for the values.
  1661.  
  1662.  2.3.3  Variable Storage Allocation
  1663.  
  1664.    BASIC stores different kinds of variables in different areas in memory.
  1665.    You need to worry about where variables are stored only if you are either
  1666.    doing mixed-language programming or using one of the following BASIC
  1667.    statements or functions:
  1668.  
  1669.    ■ CALL, CALLS (non-BASIC procedures)
  1670.  
  1671.    ■ DECLARE (non-BASIC procedures)
  1672.  
  1673.    ■ SADD
  1674.  
  1675.    ■ SETMEM
  1676.  
  1677.    ■ VARPTR
  1678.  
  1679.    ■ VARSEG
  1680.  
  1681.    ■ VARPTR$
  1682.  
  1683.    BASIC stores variables either in an area called DGROUP or as far objects.
  1684.    (DGROUP is the name of the default data segment, the segment referenced
  1685.    when DEF SEG is used without an address.) Variables stored in DGROUP can
  1686.    be referenced by using near addresses or pointers. A near address consists
  1687.    of a single value or offset from the beginning of a segment or block of
  1688.    memory. Far objects are referenced by using far addresses or pointers. A
  1689.    far address consists of two parts: the starting address of a segment or
  1690.    block of memory and the offset within the segment. See the entries for the
  1691.    statements listed above for information about getting and using far
  1692.    pointers.
  1693.  
  1694.    Whether a variable is stored in DGROUP or as a far object depends first on
  1695.    whether it is a simple variable or an array. All simple variables are
  1696.    stored in DGROUP. Array storage is a little more complex and is slightly
  1697.    different between programs run as .EXE files and programs run within the
  1698.    QuickBASIC environment.
  1699.  
  1700.    In programs run as .EXE files, array variables are stored as follows:
  1701.  
  1702.    ■ All static arrays are stored in DGROUP and can be referenced with near
  1703.      addresses.
  1704.  
  1705.    ■ All dynamic arrays of variable-length strings are also stored in DGROUP
  1706.      and can also be referenced with near addresses.
  1707.  
  1708.    ■ All other dynamic arrays are stored as far objects and require far
  1709.      addresses.
  1710.  
  1711.      See Section 2.5 for a description of static and dynamic arrays. In
  1712.      programs run within the QuickBASIC environment, array variable storage
  1713.      follows these rules:
  1714.  
  1715.    ■ All static arrays in a COMMON block are stored in DGROUP and can be
  1716.      referenced with near addresses.
  1717.  
  1718.    ■ All arrays of variable-length strings are also stored in DGROUP and can
  1719.      also be referenced with near addresses.
  1720.  
  1721.    ■ All other arrays are stored as far objects and require far addresses.
  1722.  
  1723.      Because BASIC attempts to make the most efficient use of memory
  1724.      possible, several different things may cause a variable's memory
  1725.      location to change. These include a reference to a string literal or
  1726.      expression, the invocation of a DEF FN or FUNCTION, the use of a BASIC
  1727.      string or memory-related function, and a reference to an implicitly
  1728.      dimensioned array.
  1729.  
  1730.    To generate accurate results and because BASIC variables may move, use the
  1731.    results of VARPTR, VARSEG, VARTPR$, or SADD immediately after a function
  1732.    call that affects a variable.
  1733.  
  1734.  
  1735.  2.4  Scope of Variables and Constants
  1736.  
  1737.    Any time a variable appears, BASIC follows a set of rules in determining
  1738.    to which object the variable refers. These rules describe a variable's
  1739.    scope──the range of statements over which the variable is defined.
  1740.  
  1741.    The BASICA interpreter has a very simple scope rule: a variable exists
  1742.    when you first use it and persists until the program ends. The scope of a
  1743.    variable is from its first use through the end of the program.
  1744.  
  1745.    In QuickBASIC, you can control the scope of variables and symbolic
  1746.    constants──which helps you write compact, well-defined SUB and FUNCTION
  1747.    procedures that don't interfere with each other. You can also make some
  1748.    variables available to all procedures in a module, and thereby share
  1749.    important data structures among procedures.
  1750.  
  1751.    You may think of variables and constants as having one of two scopes:
  1752.    global or local. Global variables, once declared, may be used anywhere in
  1753.    a module to refer to some single object. Local variables are local to some
  1754.    part of the module, the module-level code or one of the procedures. In
  1755.    addition, variables can be shared in such a way that they aren't quite
  1756.    global, nor are they completely local.
  1757.  
  1758.    The rest of this section discusses global and local scope, and shared
  1759.    variables. The following skeleton of a program is used in this discussion.
  1760.    The program, a main program and two procedures, replaces runs of blanks in
  1761.    a file with tab characters──a simple first step in compressing a file.
  1762.    (The program is included on the QuickBASIC release disks in the file
  1763.    ENTAB.BAS.)
  1764.  
  1765.    DEFINT a-z
  1766.    DECLARE FUNCTION ThisIsATab(Column AS INTEGER)
  1767.  
  1768.    CONST MAXLINE=255, TABSPACE=8
  1769.    CONST NO=0, YES=NOT NO
  1770.    DIM SHARED TabStops(MAXLINE)
  1771.    .
  1772.    .
  1773.    .
  1774.    ' Set the tab positions (uses the global array TabStops).
  1775.    CALL SetTabPos
  1776.    .
  1777.    .
  1778.    .
  1779.          IF ThisIsATab(CurrentColumn) THEN
  1780.             PRINT CHR$(9);
  1781.             LastColumn=CurrentColumn
  1782.          END IF
  1783.    .
  1784.    .
  1785.    .
  1786.  
  1787.    '==================SUB SetTabPos=========================
  1788.    ' Set the tab positions in the array TabStops.
  1789.    '
  1790.    SUB SetTabPos STATIC
  1791.       FOR I=1 TO MAXLINE
  1792.          TabStops(I)=((I MOD TABSPACE)=1)
  1793.       NEXT I
  1794.    END SUB
  1795.  
  1796.    '===============FUNCTION ThisIsATab======================
  1797.    ' Answer the question, "Is this a tab position?"
  1798.    '
  1799.    FUNCTION ThisIsATab(LastColumn AS INTEGER) STATIC
  1800.       IF LastColumn>MAXLINE THEN
  1801.          ThisIsATab=YES
  1802.       ELSE
  1803.          ThisIsATab=TabStops(LastColumn)
  1804.       END IF
  1805.    END FUNCTION
  1806.  
  1807.  2.4.1  Global Variables and Constants
  1808.  
  1809.    Both variables and symbolic constants can be global in BASIC programs. A
  1810.    global variable or global symbolic constant is defined for the entire
  1811.    module. For a variable, the only way to make it global is to declare it in
  1812.    the module-level code with the SHARED attribute in a DIM, REDIM, or COMMON
  1813.    statement. A symbolic constant is a global constant if it is declared in
  1814.    the module-level code using a CONST statement.
  1815.  
  1816.    In the sample program, the array TabStops is a global variable. Because
  1817.    TabStops is declared in a DIM statement with the SHARED attribute, it is
  1818.    shared with every procedure in the module. Notice that both procedures in
  1819.    the program (ThisIsATab and SetTabPos) use TabStops by making a reference
  1820.    to it. Global variables do not require any additional declarations to be
  1821.    used in procedures in the module. Similarly, the symbolic constants
  1822.    MAXLINE and TABSPACE are global constants. If you use the name of a global
  1823.    variable or constant in a procedure, you are referring to the global
  1824.    variable and not a local variable of the same name.
  1825.  
  1826.  ────────────────────────────────────────────────────────────────────────────
  1827.  NOTE
  1828.    The SHARED statement allows procedures to share variables with the
  1829.    module-level code. This is not the same as making the variable global. See
  1830.    Section 2.4.3 below, "Sharing Variables," for more information.
  1831.  ────────────────────────────────────────────────────────────────────────────
  1832.  
  1833.  2.4.2  Local Variables and Constants
  1834.  
  1835.    A local variable or constant exists only within a procedure or the
  1836.    module-level code. If the name of a local variable is used in another
  1837.    procedure in a module, the name represents a different variable and refers
  1838.    to a different object.
  1839.  
  1840.    The sample program ENTAB.BAS above includes many local variables. The
  1841.    variables CurrentColumn and LastColumn are local to the module-level code.
  1842.    The variable I is local to the subprogram SetTabPos. Finally, the variable
  1843.    LastColumn in the parameter list of ThisIsATab can be thought of as a
  1844.    local variable because it is a formal parameter. (Remember, however, that
  1845.    a formal parameter stands for the actual argument passed to the procedure.
  1846.    See Section 4.3, "Passing by Reference and Passing by Value," for
  1847.    additional information.)
  1848.  
  1849.    It is simplest to think of a local variable as any variable that isn't
  1850.    global. Any variable that appears in module-level code or in a procedure
  1851.    is local if it isn't declared in a DIM, REDIM, or COMMON statement with
  1852.    the SHARED attribute. (There is one exception. See Section 2.4.3,
  1853.    "Sharing Variables," below.) Even if a variable appears in one of these
  1854.    statements, you may still use a local variable of the same name in a
  1855.    procedure by declaring the variable in a STATIC statement. If the sample
  1856.    program had a DIM SHARED statement declaring I to be a global variable in
  1857.    the main program, you could make I a local variable in SetTabPos by adding
  1858.    a STATIC statement just after the SUB statement:
  1859.  
  1860.    SUB SetTabPos STATIC
  1861.    STATIC I
  1862.    .
  1863.    .
  1864.    .
  1865.  
  1866.    Any symbolic constant declared inside a SUB or FUNCTION procedure is a
  1867.    local constant. For example, in the following fragment, ENDOFLIST is a
  1868.    local symbolic constant that exists only in the function FindElement:
  1869.    FUNCTION FindElement(X())
  1870.    CONST ENDOFLIST = -32767
  1871.    .
  1872.    .
  1873.    .
  1874.    END FUNCTION
  1875.  
  1876.  ────────────────────────────────────────────────────────────────────────────
  1877.  NOTE
  1878.    The STATIC statement not only declares a variable to be local: it also
  1879.    directs the compiler to save the value of the variable between procedure
  1880.    calls. Do not use STATIC statements in recursive procedures if you do not
  1881.    want a variable's value saved between calls. See Section 2.6, "Automatic
  1882.    and STATIC Variables," for more information.
  1883.  ────────────────────────────────────────────────────────────────────────────
  1884.  
  1885.  2.4.3  Sharing Variables
  1886.  
  1887.    You can share variables among parts of a module without making the
  1888.    variables global by using the SHARED statement. For example, to share
  1889.    TabStops without making it a global variable, you would remove the SHARED
  1890.    attribute in the module-level code and add SHARED statements to the two
  1891.    procedures:
  1892.  
  1893.    DIM TabStops(MAXLINE)
  1894.    .
  1895.    .
  1896.    .
  1897.    SUB SetTabPos STATIC
  1898.    SHARED TabStops()
  1899.    .
  1900.    .
  1901.    .
  1902.    FUNCTION ThisIsATab(LastColumn AS INTEGER) STATIC
  1903.    SHARED TabStops()
  1904.    .
  1905.    .
  1906.    .
  1907.  
  1908.    The SHARED statements indicate that the name TabStops in both procedures
  1909.    refers to the same variable defined at the module level.
  1910.  
  1911.  2.4.4  DEF FN Functions
  1912.  
  1913.    The DEF FN function is an exception to the BASIC scope rules. Every
  1914.    variable in a DEF FN function that isn't in its parameter list is part of
  1915.    the module-level code. To make a variable local to a DEF FN, you must
  1916.    declare the variable in a STATIC statement. The STATIC statement in the
  1917.    following DEF FN function makes the variable I local:
  1918.  
  1919.    CONST NO = 0, YES = NOT NO
  1920.  
  1921.    DEF FNIsThereAZ (A$)
  1922.    STATIC I
  1923.       FOR I = 1 TO LEN(A$)
  1924.          IF UCASE$(MID$(A$, I, 1)) = "Z" THEN
  1925.             FNIsThereAZ = YES
  1926.             EXIT DEF
  1927.          END IF
  1928.       NEXT I
  1929.       FNIsThereAZ = NO
  1930.    END DEF
  1931.  
  1932.    Remember, as a general rule a FUNCTION is preferred over a DEF FN because
  1933.    of the improved portability and increased modularity the FUNCTION
  1934.    provides.
  1935.  
  1936.  2.4.5  Summary of Scope Rules
  1937.  
  1938.    The following list summarizes BASIC's scope rules:
  1939.  
  1940.    ■ A variable declared in a DIM, REDIM, or COMMON statement with the SHARED
  1941.      attribute is a global variable. Any SUB or FUNCTION procedure can refer
  1942.      to the variable.
  1943.  
  1944.    ■ A symbolic constant is global if it is declared in a CONST statement in
  1945.      the module-level code. Symbolic constants declared in a SUB or FUNCTION
  1946.      are local.
  1947.  
  1948.    ■ A variable is a local variable if it appears in a procedure and is not
  1949.      declared as a global variable. You can use the name of a global variable
  1950.      as a local variable in a procedure by declaring it in the procedure with
  1951.      the STATIC statement or by using it as a formal parameter.
  1952.  
  1953.    ■ The SHARED statement lets you share a variable with the module-level
  1954.      code and other procedures with equivalent SHARED statements without
  1955.      making the variable a global variable.
  1956.  
  1957.    ■ All variables in a DEF FN function are part of the module-level code
  1958.      unless they are either explicitly made local in a STATIC statement or
  1959.      are formal parameters.
  1960.  
  1961.  
  1962.  2.5  Static and Dynamic Arrays
  1963.  
  1964.    You can get better control of your program's use of memory by controlling
  1965.    when storage is set aside for arrays. Storage for arrays can be set aside
  1966.    when the program is compiled or when the program is running. Arrays given
  1967.    storage when the program is compiled are static arrays. Dynamic arrays
  1968.    have storage set aside when the program is run. The storage taken by
  1969.    dynamic arrays can be eliminated while the program is not running in order
  1970.    to free memory for other uses. See the entries for DIM, ERASE, and REDIM
  1971.    in Part 2, "Statement and Function Reference," for specific information
  1972.    about manipulating dynamic arrays.
  1973.  
  1974.    How an array is declared can determine whether the array is static or
  1975.    dynamic. By default, arrays dimensioned with constant subscripts or arrays
  1976.    that are implicitly dimensioned are static arrays. Arrays dimensioned with
  1977.    variable subscripts or that are first declared in a COMMON statement are
  1978.    dynamic arrays. In a SUB or FUNCTION not declared static, all arrays are
  1979.    dynamic.
  1980.  
  1981.    You can also use the ¢STATIC and ¢DYNAMIC metacommands to control how
  1982.    array storage is allocated. However, the ¢STATIC metacommand cannot force
  1983.    arays to be static in a procedure not declared static; in such a procedure
  1984.    all arrays are dynamic. See Appendix F, "Metacommands," in Programming in
  1985.    BASIC for more information.
  1986.  
  1987.    In some cases, you can allow more space for strings by replacing static
  1988.    arrays with dynamic arrays. In programs run as .EXE files, the space for
  1989.    static arrays is allocated from DGROUP, an area where strings are stored.
  1990.    On the other hand, dynamic arrays, other than variable-length string
  1991.    arrays, do not take any space in DGROUP; they are stored as far objects
  1992.    and require far addresses.
  1993.  
  1994.  
  1995.  2.6  Automatic and Static Variables
  1996.  
  1997.    BASIC procedures can use both automatic and static variables. Automatic
  1998.    variables are initialized at the start of each call to the FUNCTION or
  1999.    SUB; static variables retain values between calls.
  2000.  
  2001.    You can control whether the default is automatic or static by using or
  2002.    omitting the STATIC keyword in the SUB or FUNCTION statement. If you omit
  2003.    STATIC, then the default for variables is automatic. When you use STATIC,
  2004.    the default for all variables in the procedure is static: the values of
  2005.    the variables are saved between procedure calls.
  2006.  
  2007.    You can make selected variables in a procedure static by making the
  2008.    default automatic (omitting STATIC from the SUB or FUNCTION statement) and
  2009.    using the STATIC statement. The following program uses a FUNCTION that has
  2010.    two static variables: Start% and SaveStr$. The other variables are
  2011.    automatic. The FUNCTION takes a string and returns one token──a string of
  2012.    characters──until the end of the string is reached. On the first call,
  2013.    StrTok$ makes a local copy of the string Srce$ in the static variable
  2014.    SaveStr$. After the first call, StrTok$ returns additional tokens from the
  2015.    string using the static variable Start% to remember where it left off. All
  2016.    of the other variables (BegPos%, Ln%, etc.) are automatic. (This program
  2017.    is included on the QuickBASIC distribution disks under the file name
  2018.    TOKEN.BAS.)
  2019.  
  2020.    DECLARE FUNCTION StrTok$(Source$,Delimiters$)
  2021.  
  2022.    LINE INPUT "Enter string: ",P$
  2023.    ' Set up the characters that separate tokens.
  2024.    Delimiters$=" ,;:().?"+CHR$(9)+CHR$(34)
  2025.    ' Invoke StrTok$ with the string to tokenize.
  2026.    Token$=StrTok$(P$,Delimiters$)
  2027.    WHILE Token$<>""
  2028.       PRINT Token$
  2029.       ' Call StrTok$ with a null string so it knows this
  2030.       ' isn't the first call.
  2031.       Token$=StrTok$("",Delimiters$)
  2032.    WEND
  2033.  
  2034.    FUNCTION StrTok$(Srce$,Delim$)
  2035.    STATIC Start%, SaveStr$
  2036.  
  2037.       ' If first call, make a copy of the string.
  2038.       IF Srce$<>"" THEN
  2039.          Start%=1 : SaveStr$=Srce$
  2040.       END IF
  2041.  
  2042.       BegPos%=Start% : Ln%=LEN(SaveStr$)
  2043.       ' Look for start of a token (character that isn't
  2044.       ' delimiter).
  2045.       WHILE(BegPos%<=Ln% AND INSTR(Delim$,MID$(SaveStr$,BegPos%,1))<>0)
  2046.          BegPos%=BegPos%+1
  2047.       WEND
  2048.       ' Test for token start found.
  2049.       IF BegPos% > Ln% THEN
  2050.          StrTok$="" : EXIT FUNCTION
  2051.       END IF
  2052.       ' Find the end of the token.
  2053.       End%=BegPos%
  2054.       WHILE(End%<=Ln%AND INSTR(Delim$,MID$(SaveStr$,End%,1))=0)
  2055.          End%=End%+1
  2056.       WEND
  2057.  
  2058.    StrTok$=MID$(SaveStr$,BegPos%,End%-BegPos%)
  2059.       ' Set starting point for search for next token.
  2060.       Start%=End%
  2061.  
  2062.    END FUNCTION
  2063.  
  2064.    Output
  2065.  
  2066.    Enter string: Allen spoke: "What's a hacker, anyway?"
  2067.    Allen
  2068.    spoke
  2069.    What's
  2070.    a
  2071.    hacker
  2072.    anyway
  2073.  
  2074.  
  2075.  2.7  Type Conversion
  2076.  
  2077.    When necessary, BASIC converts a numeric constant from one type to
  2078.    another, according to the following rules:
  2079.  
  2080.    ■ If a numeric constant of one type is set equal to a numeric variable of
  2081.      a different type, the numeric constant is stored as the type declared in
  2082.      the variable name, as in the following example:
  2083.  
  2084.      A% = 23.42
  2085.      PRINT A%
  2086.  
  2087.      Output
  2088.  
  2089.      23
  2090.  
  2091.      If a string variable is set equal to a numeric value, or vice versa, an
  2092.      error message is generated that reads Type Mismatch.
  2093.  
  2094.    ■ During expression evaluation, the operands in an arithmetic or
  2095.      relational operation are converted to the same degree of precision, that
  2096.      of the most precise operand, as each operation is performed. Also, the
  2097.      result of an arithmetic operation is returned to the final degree of
  2098.      precision, as in this example:
  2099.  
  2100.      X% = 2 : Y! = 1.5 : Z# = 100
  2101.      A! = X% / Y!
  2102.      PRINT A! * Z#
  2103.  
  2104.      Output
  2105.  
  2106.      133.3333373069763
  2107.  
  2108.      Although the preceding result is displayed in double precision (because
  2109.      of the double-precision variable Z#), it has only single-precision
  2110.      accuracy because the assignment to A! forced the result of X% / Y! to be
  2111.      reduced to single-precision accuracy. This explains the nonsignificant
  2112.      digits (73069763) after the fifth decimal place. Contrast this with the
  2113.      output from the following example in which the intermediate result of X%
  2114.      / Y! is retained in double-precision:
  2115.  
  2116.      X% = 2 : Y# = 1.5 : Z# = 100
  2117.      PRINT X% / Y# * Z#
  2118.  
  2119.      Output
  2120.  
  2121.      133.3333333333333
  2122.  
  2123.    ■ Logical operators such as AND and NOT convert their operands to long
  2124.      integers if necessary. Operands must be in the range -2,147,483,648 to
  2125.      +2,147,483,647 or an Overflow error message is generated. See Chapter
  2126.      3, "Expressions and Operators," for more information on logical
  2127.      operators.
  2128.  
  2129.    ■ When a floating-point value is converted to an integer, the fractional
  2130.      portion is rounded, as in this example:
  2131.  
  2132.      Total% = 55.88
  2133.      PRINT Total%
  2134.  
  2135.      Output
  2136.  
  2137.      56
  2138.  
  2139.  
  2140.  
  2141.  ────────────────────────────────────────────────────────────────────────────
  2142.  Chapter 3   Expressions and Operators
  2143.  
  2144.        3.1  Expressions and Operators Defined
  2145.        3.2  Hierarchy of Operations
  2146.        3.3  Arithmetic Operators
  2147.          3.3.1   Integer Division
  2148.          3.3.2   Modulo Arithmetic
  2149.          3.3.3   Overflow and Division by Zero
  2150.        3.4  Relational Operators
  2151.        3.5  Logical Operators
  2152.        3.6  Functional Operators
  2153.        3.7  String Operators
  2154.  
  2155.    This chapter discusses how to combine, modify, compare, or get information
  2156.    about expressions by using the operators available in BASIC.
  2157.  
  2158.    Anytime you do a calculation or manipulate a string, you are using
  2159.    expressions and operators. This chapter describes how expressions are
  2160.    formed, discusses the order in which BASIC uses operators, and concludes
  2161.    by describing the following five kinds of operators:
  2162.  
  2163.    ■ Arithmetic operators, used to perform calculations
  2164.  
  2165.    ■ Relational operators, used to compare strings and numeric values
  2166.  
  2167.    ■ Logical operators, used to test complex conditions or manipulate
  2168.      individual bits
  2169.  
  2170.    ■ Functional operators, used to supplement simpler operators
  2171.  
  2172.    ■ String operators, used to combine and compare strings
  2173.  
  2174.  
  2175.  3.1  Expressions and Operators Defined
  2176.  
  2177.    An expression can be a string or numeric constant, a variable, or a single
  2178.    value obtained by combining constants, variables, and other expressions
  2179.    with operators. Operators perform mathematical or logical operations on
  2180.    values. The operators provided by BASIC can be divided into five
  2181.    categories, as follows:
  2182.  
  2183.    1. Arithmetic
  2184.  
  2185.    2. Relational
  2186.  
  2187.    3. Logical
  2188.  
  2189.    4. Functional
  2190.  
  2191.    5. String
  2192.  
  2193.  
  2194.  3.2  Hierarchy of Operations
  2195.  
  2196.    The BASIC operators have an order of precedence: when several operations
  2197.    take place within the same program statement, some operations are done
  2198.    before others. Operations are executed in the following order:
  2199.  
  2200.    1. Arithmetic operations
  2201.  
  2202.       a. Exponentiation (^)
  2203.  
  2204.       b. Negation (-)
  2205.  
  2206.       c. Multiplication and division (*,/)
  2207.  
  2208.       d. Integer division (\)
  2209.  
  2210.       e. Modulo arithmetic (MOD)
  2211.  
  2212.       f. Addition and subtraction (+,-)
  2213.  
  2214.    2. Relational operations (=, >, <, <>, <=, >=)
  2215.  
  2216.    3. Logical operations
  2217.  
  2218.       a. NOT
  2219.  
  2220.       b. AND
  2221.  
  2222.       c. OR
  2223.  
  2224.       d. XOR
  2225.  
  2226.       e. EQV
  2227.  
  2228.       f. IMP
  2229.  
  2230.    An exception to the order of operations listed above occurs when an
  2231.    expression has adjacent exponentiation and negation operators. In this
  2232.    case, the negation is done first. For example, the following statement
  2233.    prints the value .0625 (equivalent to 4^-2), not -16 (equivalent to
  2234.    -(4^2)):
  2235.  
  2236.    PRINT 4 ^ - 2
  2237.  
  2238.    If the operations are different and are of the same level, the leftmost
  2239.    one is executed first and the rightmost last, as explained below.
  2240.  
  2241.    A = 3 + 6 / 12 * 3 - 2    'A = 2.5
  2242.  
  2243.    The order of operations in the preceding example is as follows:
  2244.  
  2245.    Operation                Result
  2246.    ──────────────────────────────────────────────────────────────────────────
  2247.    6 / 12                   0.5
  2248.    0.5 * 3                  1.5
  2249.    3 + 1.5                  4.5
  2250.    4.5 - 2                  2.5
  2251.    ──────────────────────────────────────────────────────────────────────────
  2252.  
  2253.    In a series of additions or a series of multiplications, there is no fixed
  2254.    evaluation order. Either 3 + 5 or 5 + 6 may be calculated first in the
  2255.    following statement:
  2256.  
  2257.    C = 3 + 5 + 6
  2258.  
  2259.    Usually this does not cause problems. However, it may cause a problem if
  2260.    you have a series of FUNCTION procedure calls:
  2261.  
  2262.    C = Incr(X) + Decr(X) + F(X)
  2263.  
  2264.    If any of the three FUNCTION procedures modify X or change shared
  2265.    variables, the result depends on the order in which BASIC does the
  2266.    additions. You can avoid the situation by assigning the results of the
  2267.    FUNCTION calls to temporary variables and then performing the addition:
  2268.  
  2269.    T1 = Incr(X) : T2 = Decr(X) : T3 = F(X)
  2270.    C = T1 + T2 + T3
  2271.  
  2272.  
  2273.  3.3  Arithmetic Operators
  2274.  
  2275.    Parentheses change the order in which arithmetic operations are performed.
  2276.    Operations within parentheses are performed first. Inside parentheses, the
  2277.    usual order of operation is maintained. Here are some sample algebraic
  2278.    expressions and their BASIC counterparts:
  2279.  
  2280.    Algebraic Expression     BASIC Expression
  2281.    ──────────────────────────────────────────────────────────────────────────
  2282.    X - Y
  2283.    -----                    (X-Y)/Z
  2284.      Z
  2285.  
  2286.    XZ
  2287.    ---                      X*Y/Z
  2288.     Z
  2289.  
  2290.    X + Y
  2291.    -----                    (X+Y)/Z
  2292.      Z
  2293.  
  2294.    (X<^>2)<^>Y              (X^2)^Y
  2295.  
  2296.    X<^>YZ                   X^(Y*Z)
  2297.  
  2298.    X(-Y)                    X*(-Y)
  2299.    ──────────────────────────────────────────────────────────────────────────
  2300.  
  2301.    :BTGenerally, two consecutive operators must be separated by parentheses.
  2302.    Exceptions to this rule are * - , * +, ^ -, and ^ + . The last expression
  2303.    in the right-hand column above could also be written X*-Y.
  2304.  
  2305.    See the preceding section for information about the order in which
  2306.    arithmetic operations are performed.
  2307.  
  2308.  3.3.1  Integer Division
  2309.  
  2310.    Integer division is denoted by the backslash (\) instead of the forward
  2311.    slash (/), which indicates floating-point division. Before integer
  2312.    division is performed, operands are rounded to integers or long integers,
  2313.    and thus must be greater than -2,147,483,648.5 and less than
  2314.    +2,147,483,647.5. The quotient of an integer division is truncated to an
  2315.    integer, as illustrated below:
  2316.  
  2317.    PRINT 10\4, 10/4, -32768.499\10, -32768.499/10
  2318.  
  2319.    Output
  2320.  
  2321.    2             2.5          -3276         -3276.8499
  2322.  
  2323.  3.3.2  Modulo Arithmetic
  2324.  
  2325.    Modulo arithmetic is denoted by the modulus operator MOD. Modulo
  2326.    arithmetic provides the remainder, rather than the quotient, of an integer
  2327.    division, as in this example:
  2328.  
  2329.    X% = 10.4\4
  2330.    REMAINDER% = INT(10.4) - 4*X%
  2331.    '10\4 = 2, with remainder 2
  2332.    PRINT REMAINDER%, 10.4 MOD 4
  2333.  
  2334.    Output
  2335.  
  2336.    2             2
  2337.  
  2338.  3.3.3  Overflow and Division by Zero
  2339.  
  2340.    Dividing by zero, raising zero to a negative power, and arithmetic
  2341.    overflow produce run-time errors. These errors can be trapped by an
  2342.    error-trapping routine. See Chapter 6, "Error and Event Trapping," in
  2343.    Programming in BASIC for more information about writing error-trapping
  2344.    routines.
  2345.  
  2346.  
  2347.  3.4  Relational Operators
  2348.  
  2349.    Relational operators are used to compare two values, as shown in Table
  2350.    3.1. The result of the comparison is either "true" (nonzero) or "false"
  2351.    (zero). This result can then be used to make a decision regarding program
  2352.    flow. Although BASIC treats any nonzero value as true, true is usually
  2353.    represented by -1.
  2354.  
  2355.    Table 3.1   Relational Operators and Their Functions
  2356.  
  2357.    Operator           Relation Tested                      Expression
  2358.    ──────────────────────────────────────────────────────────────────────────
  2359.    =                  Equality                            X = Y
  2360.    < >                Inequality                           X < > Y
  2361.    <                  Less than                            X < Y
  2362.    >                  Greater than                         X > Y
  2363.    <=                 Less than or equal to                X <= Y
  2364.    =                  Greater than or equal to             X >= Y
  2365.    ──────────────────────────────────────────────────────────────────────────
  2366.  
  2367.    When arithmetic and relational operators are combined in one expression,
  2368.    the arithmetic operations are always done first. For example, the
  2369.    following expression is true if the value of X + Y is less than the value
  2370.    of (T - 1)/Z:
  2371.  
  2372.    X + Y < (T - 1)/Z
  2373.  
  2374.    Be careful using relational operators with single- and double-precision
  2375.    values. Calculations may give extremely close but not identical results.
  2376.    In particular, avoid testing for identity between two values. For example,
  2377.    the PRINT statement in the following IF statement is not executed unless
  2378.    A! is exactly equal to 0.0:
  2379.  
  2380.    IF A! = 0.0 THEN PRINT "Exact result."
  2381.  
  2382.    When A! is an extremely small value, for example 1.0E-23, the PRINT
  2383.    statement is not executed.
  2384.  
  2385.    In addition, a compiled program (an .EXE file) may give different results
  2386.    than the same program run in the QuickBASIC environment. Files with the
  2387.    .EXE extension23 contain more efficient code that may change the way
  2388.    single- and double-precision values are compared. For example, the
  2389.    following fragment prints Equal when run in the environment, but prints
  2390.    Not Equal when compiled:
  2391.  
  2392.    B!=1.0
  2393.    A!=B!/3.0
  2394.    IF A!=B!/3.0 THEN PRINT "Equal" ELSE PRINT "Not Equal"
  2395.  
  2396.    Because the .EXE file version makes more extensive use of a math
  2397.    coprocessor chip (or coprocessor emulation), A! and B!/3.0 are slightly
  2398.    different values.
  2399.  
  2400.    You can avoid problems in comparisons by performing calculations outside
  2401.    comparisons. The following rewritten fragment produces the same results in
  2402.    the environment and as an .EXE file:
  2403.  
  2404.    B!=1.0
  2405.    A!=B!/3.0
  2406.    Tmp!=B!/3.0
  2407.    IF A!=Tmp! THEN PRINT "Equal" ELSE PRINT "Not Equal"
  2408.  
  2409.  
  2410.  3.5  Logical Operators
  2411.  
  2412.    Logical operators perform tests on multiple relations, bit manipulations,
  2413.    or Boolean operations and return a true (nonzero) or false (zero) value to
  2414.    be used in making a decision.
  2415.  
  2416.  ■ Examples
  2417.  
  2418.    IF D < 200 AND F < 4 THEN 80
  2419.  
  2420.    WHILE I > 10 OR K < 0
  2421.    .
  2422.    .
  2423.    .
  2424.    WEND
  2425.  
  2426.    IF NOT P THEN PRINT "Name not found"
  2427.  
  2428.    There are six logical operators in BASIC; they are listed in Table 3.2 in
  2429.    order of precedence:
  2430.  
  2431.    Table 3.2   BASIC Logical Operators
  2432.  
  2433.    Operator                 Meaning
  2434.    ──────────────────────────────────────────────────────────────────────────
  2435.    NOT                      Logical complement
  2436.    AND                      Conjunction
  2437.    OR                       Disjunction (inclusive "or")
  2438.    XOR                      Exclusive "or"
  2439.    EQV                      Equivalence
  2440.    IMP                      Implication
  2441.    ──────────────────────────────────────────────────────────────────────────
  2442.  
  2443.    Each operator returns results as indicated in Table 3.3. A "T" indicates
  2444.    a true value and an "F" indicates a false value. Operators are listed in
  2445.    order of operator precedence.
  2446.  
  2447.    Table 3.3   Values Returned by Logical Operations
  2448.  
  2449.    Values of                  Value Returned by Logical Operator
  2450.                                 X        X        X         X        X
  2451.                       NOT      AND      OR       XOR       EQV      IMP
  2452.    X        Y          X        Y        Y        Y         Y        Y
  2453.    ──────────────────────────────────────────────────────────────────────────
  2454.    T        T          F        T        T        F         T        T
  2455.    T        F          F        F        T        T         F        F
  2456.    F        T          T        F        T        T         F        T
  2457.    F        F          T        F        F        F         T        T
  2458.    ──────────────────────────────────────────────────────────────────────────
  2459.  
  2460.    In an expression, logical operations (also known as Boolean operations)
  2461.    are performed after arithmetic and relational operations. The operands of
  2462.    logical operators must be in the range -2,147,483,648 to +2,147,483,647.
  2463.    Operands are converted to integers (or, if necessary, long integers)
  2464.    before the logical operation is done. (If the operands are not in this
  2465.    range, an error results.) If the operands are either 0 or -1, logical
  2466.    operators return 0 or -1 as the result, as in the following example. (Note
  2467.    the similarity of the output from this program to Table 3.3: "T" becomes
  2468.    -1 and "F" becomes 0.)
  2469.  
  2470.  ■ Example
  2471.  
  2472.    PRINT " X       Y      NOT     AND     OR      ";
  2473.    PRINT "XOR     EQV     IMP"
  2474.    PRINT
  2475.    I = 10 : J = 15
  2476.    X = (I = 10) : Y = (J = 15)  'X is true (-1); Y is true (-1)
  2477.    CALL TruthTable (X,Y)
  2478.    X = (I > 9) : Y = (J > 15)   'X is true (-1); Y is false (0)
  2479.    CALL TruthTable (X,Y)
  2480.    X = (I <> 10) : Y = (J < 16) 'X is false (0); Y is true (-1)
  2481.    CALL TruthTable (X,Y)
  2482.    X = (I < 10) : Y = (J < 15)  'X is false (0); Y is false (0)
  2483.    CALL TruthTable (X,Y)
  2484.    END
  2485.  
  2486.    SUB TruthTable(X,Y) STATIC
  2487.     PRINT X "    " Y "    ";NOT X "   " X AND Y "     " X OR Y;
  2488.     PRINT "    " X XOR Y "    " X EQV Y "    " X IMP Y
  2489.     PRINT
  2490.    END SUB
  2491.  
  2492.    Output
  2493.  
  2494.    X      Y     NOT    AND     OR     XOR    EQV    IMP
  2495.  
  2496.    -1     -1      0     -1     -1      0     -1     -1
  2497.  
  2498.    -1      0      0      0     -1     -1      0      0
  2499.  
  2500.     0     -1     -1      0     -1     -1      0     -1
  2501.  
  2502.     0      0     -1      0      0      0     -1     -1
  2503.  
  2504.    Logical operators compare each bit of the first operand with the
  2505.    corresponding bit in the second operand to compute the bit in the result;
  2506.    in these "bit-wise" comparisons, a 0 bit is equivalent to a "false" value
  2507.    (F) in Table 3.3, while a 1 bit is equivalent to a "true" value (T).
  2508.  
  2509.    It is possible to use logical operators to test bytes for a particular bit
  2510.    pattern. For example, the AND operator can be used to mask all but one of
  2511.    the bits of a status byte, while the OR operator can be used to merge two
  2512.    bytes to create a particular binary value.
  2513.  
  2514.  ■ Example
  2515.  
  2516.    PRINT 63 AND 16
  2517.  
  2518.    PRINT -1 AND 8
  2519.  
  2520.    PRINT 10 OR 9
  2521.  
  2522.    PRINT 10 XOR 10,           'Always 0
  2523.  
  2524.    PRINT NOT 10, NOT 11, NOT 0     'NOT X = -(X + 1)
  2525.  
  2526.    Output
  2527.  
  2528.     16
  2529.     8
  2530.     11
  2531.     0          -11           -12           -1
  2532.  
  2533.    The first PRINT statement uses AND to combine 63 (111111 binary) and 16
  2534.    (10000). When BASIC calculates the result of an AND, it combines the
  2535.    numbers bit by bit, producing a one only when both bits are one. Because
  2536.    the only bit that is a one in both numbers is the fifth bit, only the
  2537.    fifth bit in the result is a one. The result is 16, or 10000 in binary. In
  2538.    the second PRINT statement, the numbers -1 (binary 1111111111111111) and 8
  2539.    (binary 1000) are combined using another AND operation. The only bit that
  2540.    is a one in both numbers is the fourth bit, so the result is 8 decimal or
  2541.    1000 binary. The third PRINT statement uses an OR to combine 10 (binary
  2542.    1010) and 9 (binary 1001). An OR produces a one bit whenever either bit is
  2543.    a one, so the result of the OR in the third PRINT is 11 (binary 1011). The
  2544.    XOR in the fourth PRINT combines the number 10 (1010 binary) with itself.
  2545.    The result is a zero because an XOR produces a one only when either, but
  2546.    not both, bits are one.
  2547.  
  2548.    Performing a NOT on a number changes all one bits to zeros and all zero
  2549.    bits to ones. Because of the way two's complement numbers work, taking the
  2550.    NOT of a value is the same as adding one to the number and then negating
  2551.    the number. In the final PRINT statement, the expression NOT 10 yields a
  2552.    result of -11.
  2553.  
  2554.  
  2555.  3.6  Functional Operators
  2556.  
  2557.    A function is used in an expression to call a predetermined operation to
  2558.    be performed on an operand. For example, SQR is a functional operator used
  2559.    twice in the following assignment statement:
  2560.  
  2561.    A = SQR (20.25) + SQR (37)
  2562.  
  2563.    BASIC incorporates two kinds of functions: intrinsic and user-defined.
  2564.    Many predefined (intrinsic) functions are built into the language.
  2565.    Examples are the SQR (square root) and SIN (sine) functions.
  2566.  
  2567.    You may define your own functions with the FUNCTION...END FUNCTION
  2568.    construction and the older, obsolete DEF FN...END DEF construction. Such
  2569.    functions are defined only for the life of the program (unless they are in
  2570.    a Quick library) and are not part of the BASIC language. In addition to
  2571.    FUNCTION and DEF FN, BASIC allows you to define subprograms with SUB. For
  2572.    more information on defining your own functions and subprograms, see the
  2573.    appropriate entries in Chapter 4, "Programs and Modules," and Part 2,
  2574.    "Statement and Function Reference," in this manual, as well as Chapter 2,
  2575.    "SUB and FUNCTION Procedures," in Programming in BASIC.
  2576.  
  2577.  
  2578.  3.7  String Operators
  2579.  
  2580.    A string expression consists of string constants, string variables, and
  2581.    other string expressions combined by string operators. There are two
  2582.    classes of string operations: concatenation and string function.
  2583.  
  2584.    The act of combining two strings is called concatenation. The plus symbol
  2585.    (+) is the concatenation operator for strings. For example, the following
  2586.    program fragment combines the string variables A$ and B$ to produce the
  2587.    output shown:
  2588.  
  2589.    A$ = "FILE": B$ = "NAME"
  2590.    PRINT A$ + B$
  2591.    PRINT "NEW " + A$ + B$
  2592.  
  2593.    Output
  2594.  
  2595.    FILENAME
  2596.    NEW FILENAME
  2597.  
  2598.    Strings can be compared using the following relational operators (see
  2599.    Table 3.1):
  2600.  
  2601.    < > = < > <= >=
  2602.  
  2603.    Note that these are the same relational operators used with numbers.
  2604.  
  2605.    String comparisons are made by taking corresponding characters from each
  2606.    string and comparing their ASCII codes. If the ASCII codes are the same
  2607.    for all the characters in both strings, the strings are equal. If the
  2608.    ASCII codes differ, the lower code number precedes the higher. If the end
  2609.    of one string is reached during string comparison, the shorter string is
  2610.    smaller if they are equal up to that point. Leading and trailing blanks
  2611.    are significant. The following are examples of true string expressions:
  2612.  
  2613.    "AA" < "AB"
  2614.    "FILENAME" = "FILE"+"NAME"
  2615.    "X&" > "X#"
  2616.    "CL " > "CL"
  2617.    "kg" > "KG"
  2618.    "SMYTH" < "SMYTHE"
  2619.    B$ < "9/12/78"              'where B$ = "8/12/85"
  2620.  
  2621.    String comparisons can be used to test string values or to alphabetize
  2622.    strings. All string constants used in comparison expressions must be
  2623.    enclosed in quotation marks. See Appendix A, "Keyboard Scan Codes and
  2624.    ASCII Character Codes," for more information about the ASCII codes.
  2625.  
  2626.  
  2627.  
  2628.  ────────────────────────────────────────────────────────────────────────────
  2629.  Chapter 4   Programs and Modules
  2630.  
  2631.        4.1  Modules
  2632.        4.2  Procedures
  2633.          4.2.1   FUNCTION Procedures
  2634.          4.2.2   SUB Procedures
  2635.          4.2.3   DEF FN Functions
  2636.        4.3  Passing by Reference and Passing by Value
  2637.        4.4  Recursion
  2638.  
  2639.    This chapter discusses the largest parts of a program──modules and
  2640.    procedures. The chapter describes how modules are organized and how BASIC
  2641.    procedures communicate with other parts of a program.
  2642.  
  2643.    Specifically, the chapter explains how to
  2644.  
  2645.    ■ Organize modules
  2646.  
  2647.    ■ Understand different kinds of QuickBASIC procedures
  2648.  
  2649.    ■ Pass arguments to a procedure
  2650.  
  2651.    ■ Write recursive code
  2652.  
  2653.  
  2654.  4.1  Modules
  2655.  
  2656.    BASIC programs consist of one or more modules. A module is a source file
  2657.    that can be separately compiled. Declarations, executable statements──any
  2658.    BASIC statement──can appear in a module.
  2659.  
  2660.    A module may contain SUB and FUNCTION procedures, as well as code not
  2661.    directly part of a SUB or FUNCTION. Statements that are not part of a SUB
  2662.    or FUNCTION are called module-level code. Module-level code includes
  2663.    declarative statements like DIM and TYPE as well as error- and
  2664.    event-handling code.
  2665.  
  2666.    A program has one special module, the main module. The main module
  2667.    contains the entry point of the program (the place where the program
  2668.    starts running). Each program contains only one main module; module-level
  2669.    code it contains corresponds to what is often called the main program.
  2670.  
  2671.  
  2672.  4.2  Procedures
  2673.  
  2674.    This section discusses the two newer QuickBASIC procedures: FUNCTION
  2675.    procedures and SUB procedures. It also covers the older DEF FN function
  2676.    and compares it with the newer procedures.
  2677.  
  2678.    See Chapter 2, "SUB and FUNCTION Procedures," in Programming in BASIC for
  2679.    examples and information about when to use different kinds of procedures.
  2680.  
  2681.  4.2.1  FUNCTION Procedures
  2682.  
  2683.    FUNCTION procedures provide a powerful alternative to DEF FN functions.
  2684.    Like DEF FN functions, FUNCTION procedures are used in expressions and
  2685.    directly return a single value. There are, however, important differences.
  2686.  
  2687.    FUNCTION procedures pass values by reference, so a FUNCTION procedure can
  2688.    return additional values by changing variables in its argument list. In
  2689.    addition, FUNCTION procedures can be used recursively──a function can call
  2690.    itself (see Section 4.4 below for more information).
  2691.  
  2692.    Unlike DEF FN functions, a FUNCTION procedure may be used outside the
  2693.    module in which it is defined. You must include a DECLARE statement if you
  2694.    use a FUNCTION defined in another module. QuickBASIC automatically
  2695.    generates DECLARE statements for FUNCTION procedures defined and used in
  2696.    the same module. You can also enter the DECLARE yourself:
  2697.  
  2698.    DECLARE FUNCTION Log10(X)
  2699.  
  2700.    INPUT "Enter a number: ",Num
  2701.    PRINT "10 ^ Log10(";Num;") is" 10.0^Log10(Num)
  2702.    END
  2703.    ' Function to find log base 10 of a number using
  2704.    ' BASIC's built-in natural logarithm function.
  2705.    FUNCTION Log10 (X) STATIC
  2706.       Log10=LOG(X)/LOG(10.0)
  2707.    END FUNCTION
  2708.  
  2709.    FUNCTION procedures also differ from DEF FN functions in that they are not
  2710.    part of the module-level code.
  2711.  
  2712.  4.2.2  SUB Procedures
  2713.  
  2714.    Unlike DEF FN functions and FUNCTION procedures, SUB is invoked as a
  2715.    separate statement:
  2716.  
  2717.    ' Print a message in the middle of the screen.
  2718.    CLS
  2719.    CALL PrntMsg(12,40,"Hello!")
  2720.    END
  2721.  
  2722.    ' Print message at the designated row and column.
  2723.    SUB PrntMsg(Row%,Col%,Message$) STATIC
  2724.       ' Save current cursor position.
  2725.       CurRow%=CSRLIN
  2726.       CurCol%=POS(0)
  2727.       ' Print the message at the location.
  2728.       LOCATE Row%,Col% : PRINT Message$;
  2729.       ' Restore cursor location.
  2730.       LOCATE CurRow%,CurCol%
  2731.    END SUB
  2732.  
  2733.    SUB procedures can be used to return multiple values to a calling routine
  2734.    and are not invoked as part of an expression.
  2735.  
  2736.    All SUB arguments are passed by reference. This allows SUB procedures to
  2737.    return values by changing variables in the argument list──the only way a
  2738.    SUB can return a value.
  2739.  
  2740.    You can invoke SUB procedures without using the CALL keyword if the SUB is
  2741.    declared:
  2742.  
  2743.    DECLARE SUB PrntMsg (Row%,Col%,Msg$)
  2744.  
  2745.    ' Print a message in the middle of the screen.
  2746.    CLS
  2747.    PrntMsg 12,40,"Hello!"    'Note the missing parentheses.
  2748.    END
  2749.    .
  2750.    .
  2751.    .
  2752.  
  2753.    SUB procedures can be used recursively──that is, you can write a SUB
  2754.    procedure that calls itself.
  2755.  
  2756.  4.2.3  DEF FN Functions
  2757.  
  2758.    DEF FN functions are always part of a program's module-level code. For
  2759.    this reason, their use is more limited than that of SUB or FUNCTION
  2760.    procedures. Like FUNCTION procedures, DEF FN functions return single
  2761.    values and are used like built-in BASIC functions:
  2762.  
  2763.    ' Function to find log base 10 of a number using
  2764.    ' BASIC's built-in natural logarithm function.
  2765.    DEF FNLog10 (X)
  2766.       FNLog10=LOG(X)/LOG(10.0)
  2767.    END DEF
  2768.  
  2769.    INPUT "Enter a number: ",Num
  2770.    PRINT "10 ^ Log10(";Num;") is" 10.0^FNLog10(Num)
  2771.    END
  2772.  
  2773.    DEF FN function arguments are passed by value (see Section 4.3 below for
  2774.    more information). The name of a DEF FN function always begins with FN. In
  2775.    addition, DEF FN functions cannot be used recursively and must be defined
  2776.    before they are used. DEF FN functions cannot be called from outside the
  2777.    module in which they are defined.
  2778.  
  2779.  
  2780.  4.3  Passing by Reference and Passing by Value
  2781.  
  2782.    BASIC uses two different ways of passing arguments to a procedure. The
  2783.    phrase "passing by reference," used with SUB and FUNCTION procedures,
  2784.    means the address of each argument is passed to the procedure by placing
  2785.    the address on the stack. The phrase "passing by value," used in DEF FN
  2786.    functions, indicates that the value of the argument is placed on the
  2787.    stack, rather than the address. Because the procedure does not have access
  2788.    to the variable when an argument is passed by value, the procedure cannot
  2789.    change the variable's value.
  2790.  
  2791.    Sometimes passing an argument by value to a SUB or FUNCTION is more
  2792.    convenient. You can simulate a pass by value by using an expression in the
  2793.    SUB call or FUNCTION invocation:
  2794.  
  2795.    Xcoordinate=Transform((A#))
  2796.  
  2797.    Because(A#) is an expression, BASIC calculates its value, A#, and passes
  2798.    the address of a temporary location containing the value. An address is
  2799.    still passed, but because it is the address of a temporary location, the
  2800.    action simulates a pass by value.
  2801.  
  2802.  
  2803.  4.4  Recursion
  2804.  
  2805.    QuickBASIC lets you write recursive SUB or FUNCTION procedures (procedures
  2806.    that call themselves). For example, the following program uses a recursive
  2807.    FUNCTION to reverse a string of characters:
  2808.  
  2809.    DECLARE FUNCTION Reverse$ (StringVar$)
  2810.  
  2811.    LINE INPUT "Enter string to reverse: ", X$
  2812.    PRINT Reverse$(X$)
  2813.  
  2814.    END
  2815.  
  2816.    FUNCTION Reverse$ (S$)
  2817.  
  2818.       C$ = MID$(S$, 1, 1)
  2819.       IF C$ = "" THEN
  2820.          ' The first character is null, so return
  2821.          ' null--there's no more string left.
  2822.          Reverse$ = ""
  2823.       ELSE
  2824.          ' The reverse of a nonnull string is the first
  2825.          ' character appended to the reverse of the remaining
  2826.          ' string.
  2827.          Reverse$ = Reverse$(MID$(S$, 2)) + C$
  2828.       END IF
  2829.  
  2830.    END FUNCTION
  2831.  
  2832.    Output
  2833.  
  2834.    Enter string to reverse: abcdefgh...tuvwxyz
  2835.    zyxwvut...hgfedcba
  2836.  
  2837.    Reverse$ reverses a string by first testing for the simplest case──a null
  2838.    string. If the string is null, then a null string is returned. If the
  2839.    string is not null──there are characters──then Reverse$ simplifies the
  2840.    problem. The reverse of a non-null string is the rest of the string (C$)
  2841.    with the first character of the string concatenated to it. So Reverse$
  2842.    calls itself to reverse the rest of the string and when this is done
  2843.    concatenates the first character to the reversed string.
  2844.  
  2845.    Recursion can use a lot of memory because automatic variables inside the
  2846.    FUNCTION or SUB must be saved in order to restart the procedure when the
  2847.    recursive call is finished. Because automatic variables are saved on the
  2848.    stack, you may need to increase the stack size with the CLEAR statement to
  2849.    keep from running out of stack space. Use the FRE function to determine by
  2850.    how many bytes you need to adjust the stack size.
  2851.  
  2852.  
  2853.  
  2854.  ────────────────────────────────────────────────────────────────────────────
  2855.  PART 2  STATEMENT AND FUNCTION REFERENCE
  2856.  ────────────────────────────────────────────────────────────────────────────
  2857.  
  2858.    Part 2 is a dictionary of BASIC statements and functions. Each entry
  2859.    includes information on the statement's action or effect and its syntax.
  2860.    The statement's arguments, options, and typical usage are explained
  2861.    further under "Remarks."
  2862.  
  2863.    The "See Also" sections refer you to related statements. Differences from
  2864.    BASICA are included where appropriate. Finally, a sample program (or a
  2865.    reference to one) is included for each QuickBASIC statement or function so
  2866.    you can see exactly how it works.
  2867.  
  2868.  
  2869.  ────────────────────────────────────────────────────────────────────────────
  2870.  ABS Function
  2871.  ────────────────────────────────────────────────────────────────────────────
  2872.  
  2873.  ■ Action
  2874.  
  2875.    Returns the absolute value of a numeric expression
  2876.  
  2877.  ■ Syntax
  2878.  
  2879.    ABS(numeric-expression)
  2880.  
  2881.  ■ Remarks
  2882.  
  2883.    The absolute value function returns the unsigned magnitude of its
  2884.    argument. For example, ABS(-1) and ABS(1) are both 1.
  2885.  
  2886.  ■ Example
  2887.  
  2888.    The following example finds an approximate value for a cube root. It uses
  2889.    ABS to find the difference between two guesses to see if the current guess
  2890.    is accurate enough.
  2891.  
  2892.    DEFDBL A-Z
  2893.  
  2894.    FUNCTION CubeRoot(Value,Precision) STATIC
  2895.    '  Make the first two guesses.
  2896.       X1=0.0# : X2=Value
  2897.  
  2898.    '  Go until the difference between two guesses is
  2899.    '  less than the required precision.
  2900.  
  2901.       DO UNTIL ABS(X1-X2) < Precision
  2902.          X=(X1+X2)/2.0#
  2903.          ' Adjust the guesses.
  2904.          IF X*X*X-Value < 0.0# THEN
  2905.             X1=X
  2906.          ELSE
  2907.             X2=X
  2908.          END IF
  2909.       LOOP
  2910.       CubeRoot=X
  2911.    END FUNCTION
  2912.  
  2913.    INPUT "Enter a value: ",X
  2914.    PRINT "The cube root is ";CubeRoot(X,.0000001#)
  2915.  
  2916.  ■ Output
  2917.  
  2918.    Enter a value: 27
  2919.    The cube root is  2.999999972060323
  2920.  
  2921.  
  2922.  ────────────────────────────────────────────────────────────────────────────
  2923.  ASC Function
  2924.  ────────────────────────────────────────────────────────────────────────────
  2925.  
  2926.  ■ Action
  2927.  
  2928.    Returns a numeric value that is the ASCII code for the first character in
  2929.    a string expression
  2930.  
  2931.  ■ Syntax
  2932.  
  2933.    ASC(stringexpression)
  2934.  
  2935.  ■ Remarks
  2936.  
  2937.    If stringexpression is null, ASC produces a run-time error message
  2938.    (Illegal function call).
  2939.  
  2940.  ■ See Also
  2941.  
  2942.    CHR$; Appendix A, "Keyboard Scan Codes and ASCII Character Codes"
  2943.  
  2944.  ■ Example
  2945.  
  2946.    The following example uses ASC to calculate a hash value──an index value
  2947.    for a table or file──from a string:
  2948.  
  2949.    CONST HASHTABSIZE=101
  2950.  
  2951.    FUNCTION HashValue(S$,Size) STATIC
  2952.  
  2953.       TmpVal=0
  2954.       FOR I=1 TO LEN(S$)
  2955.          ' Convert the string to a number by summing the values
  2956.          ' of individual letters.
  2957.          TmpVal=TmpVal+ASC(MID$(S$,I,1))
  2958.       NEXT I
  2959.       ' Divide the sum by the size of the table.
  2960.       HashValue=TmpVal MOD Size
  2961.  
  2962.    END FUNCTION
  2963.  
  2964.    INPUT "Enter a name: ",Nm$
  2965.    PRINT "The hash value is ";HashValue(Nm$,HASHTABSIZE)
  2966.  
  2967.  ■ Output
  2968.  
  2969.    Enter a name: Bafflegab
  2970.    The hash value is  66
  2971.  
  2972.  
  2973.  ────────────────────────────────────────────────────────────────────────────
  2974.  ATN Function
  2975.  ────────────────────────────────────────────────────────────────────────────
  2976.  
  2977.  ■ Action
  2978.  
  2979.    Returns the arctangent of a numeric expression (the angle whose tangent is
  2980.    equal to the numeric expression)
  2981.  
  2982.  ■ Syntax
  2983.  
  2984.    ATN(numeric-expression)
  2985.  
  2986.  ■ Remarks
  2987.  
  2988.    The numeric-expression can be of any numeric type.
  2989.  
  2990.    The result is given in radians and is in the range -π/2 to π/2 radians,
  2991.    where π=3.141593. ATN is evaluated by default in single precision unless
  2992.    numeric-expression is a double-precision value. Then ATN is evaluated in
  2993.    double precision.
  2994.  
  2995.  ■ Example
  2996.  
  2997.    The following example first finds the tangent of π/4 and then takes the
  2998.    arctangent of the value. The result is π/4.
  2999.  
  3000.    CONST PI=3.141592653
  3001.  
  3002.    PRINT ATN(TAN(PI/4.0)), PI/4.0
  3003.  
  3004.  ■ Output
  3005.  
  3006.    .78539816325  .78539816325
  3007.  
  3008.  
  3009.  ────────────────────────────────────────────────────────────────────────────
  3010.  BEEP Statement
  3011.  ────────────────────────────────────────────────────────────────────────────
  3012.  
  3013.  ■ Action
  3014.  
  3015.    Sounds the speaker
  3016.  
  3017.  ■ Syntax
  3018.  
  3019.    BEEP
  3020.  
  3021.  ■ Remarks
  3022.  
  3023.    The BEEP statement makes a sound through the loudspeaker. This statement
  3024.    makes the same sound as the following statement:
  3025.  
  3026.    PRINT CHR$(7)
  3027.  
  3028.  ■ Example
  3029.  
  3030.    The following example uses BEEP to indicate an error in the response:
  3031.  
  3032.    DO
  3033.       INPUT "Continue (Y or N)";Response$
  3034.       R$=UCASE$ (MID$ (Response$,1,1))
  3035.       IF R$="Y" OR R$="N" THEN EXIT DO
  3036.       BEEP
  3037.    LOOP
  3038.  
  3039.  
  3040.  ────────────────────────────────────────────────────────────────────────────
  3041.  BLOAD Statement
  3042.  ────────────────────────────────────────────────────────────────────────────
  3043.  
  3044.  ■ Action
  3045.  
  3046.    Loads a memory-image file, created by BSAVE, into memory from an input
  3047.    file or device
  3048.  
  3049.  ■ Syntax
  3050.  
  3051.    BLOAD filespec «,offset»
  3052.  
  3053.  ■ Remarks
  3054.  
  3055.    The BLOAD statement takes the following arguments:
  3056.  
  3057.    Argument                 Description
  3058.    ──────────────────────────────────────────────────────────────────────────
  3059.    filespec                 A string expression containing the file
  3060.                             specification. Input devices other than the
  3061.                             keyboard (KYBD:) are supported.
  3062.  
  3063.    offset                   The offset of the address where loading is to
  3064.                             start.
  3065.    ──────────────────────────────────────────────────────────────────────────
  3066.  
  3067.    The BLOAD statement allows a program or data saved as a memory-image file
  3068.    to be loaded anywhere in memory. A memory-image file is a byte-for-byte
  3069.    copy of what was originally in memory.
  3070.  
  3071.  ────────────────────────────────────────────────────────────────────────────
  3072.  NOTE
  3073.    Programs written in earlier versions of BASIC no longer work if they use
  3074.    VARPTR to access numeric arrays.
  3075.  ────────────────────────────────────────────────────────────────────────────
  3076.  
  3077.    The starting address for loading is determined by the specified offset and
  3078.    the most recent DEF SEG statement. If offset is omitted, the segment
  3079.    address and offset contained in the file (the address used in the BSAVE
  3080.    statement) are used. Thus, the file is loaded at the address used when
  3081.    saving the file.
  3082.  
  3083.    If you supply an offset, the segment address used is the segment set by
  3084.    the most recently executed DEF SEG statement. If there has been no DEF SEG
  3085.    statement, the BASIC data segment (DS) is used as the default.
  3086.  
  3087.    If the offset is a single-precision or double-precision number it is
  3088.    coerced to an integer. If the offset is a negative number in the range -1
  3089.    to -32,768, it is treated as an unsigned 2-byte offset.
  3090.  
  3091.  ────────────────────────────────────────────────────────────────────────────
  3092.  NOTE
  3093.    Because BLOAD does not perform an address-range check, it is possible to
  3094.    load a file anywhere in memory. You must be careful not to write over
  3095.    BASIC or the operating system. Since different screen modes use memory
  3096.    differently, do not load graphic images in a screen mode other than the
  3097.    one used when they were created. Also, because BASIC program code and data
  3098.    items are not always stored in the same locations as they were in BASICA,
  3099.    do not use BLOAD with files created by BASICA programs.
  3100.  ────────────────────────────────────────────────────────────────────────────
  3101.  
  3102.  ■ Differences From Basica
  3103.  
  3104.    BLOAD does not support the cassette device.
  3105.  
  3106.  ■ See Also
  3107.  
  3108.    BSAVE, DEF SEG, VARPTR, VARSEG
  3109.  
  3110.  ■ Example
  3111.  
  3112.    This example uses BLOAD to retrieve a drawing saved in a disk file using
  3113.    BSAVE. See the example for BSAVE to see how the drawing was saved.
  3114.  
  3115.    DIM Cube(1 TO 675)
  3116.  
  3117.    ' Set the screen mode--the mode should be the same as the
  3118.    ' mode used to create the original drawing.
  3119.    SCREEN 1
  3120.  
  3121.    ' Load the drawing into the array Cube.
  3122.    DEF SEG=VARSEG(Cube(1)) ' Get the array's segment.
  3123.    BLOAD "magcube.grh",VARPTR(Cube(1))
  3124.    DEF SEG   ' Restore the default segment.
  3125.    ' Put the drawing on the screen.
  3126.    PUT (80,10),Cube
  3127.  
  3128.  
  3129.  ────────────────────────────────────────────────────────────────────────────
  3130.  BSAVE Statement
  3131.  ────────────────────────────────────────────────────────────────────────────
  3132.  
  3133.  ■ Action
  3134.  
  3135.    Transfers the contents of an area of memory to an output file or device
  3136.  
  3137.  ■ Syntax
  3138.  
  3139.    BSAVE filespec,offset,length
  3140.  
  3141.  ■ Remarks
  3142.  
  3143.    The BSAVE statement has the following arguments:
  3144.  
  3145.    Argument                 Description
  3146.    ──────────────────────────────────────────────────────────────────────────
  3147.    filespec                 A string expression containing the file or device
  3148.                             name. Output devices other than the console
  3149.                             (SCRN: and CONS:) are supported.
  3150.  
  3151.    offset                   The offset of the starting address of the area in
  3152.                             memory to be saved.
  3153.  
  3154.    length                   The number of bytes to save. This is a numeric
  3155.                             expression returning an unsigned integer in the
  3156.                             range 0-65,535.
  3157.    ──────────────────────────────────────────────────────────────────────────
  3158.  
  3159.    The BSAVE statement allows data or programs to be saved as memory-image
  3160.    files on disk. A memory-image file is a byte-for-byte copy of what is in
  3161.    memory along with control information used by BLOAD to load the file.
  3162.  
  3163.  ────────────────────────────────────────────────────────────────────────────
  3164.  NOTE
  3165.    Programs written in earlier versions of BASIC no longer work if they use
  3166.    VARPTR to access numeric arrays.
  3167.  ────────────────────────────────────────────────────────────────────────────
  3168.  
  3169.    The starting address of the area saved is determined by the offset and the
  3170.    most recent DEF SEG statement.
  3171.  
  3172.    If no DEF SEG statement is executed before the BSAVE statement, the
  3173.    program uses the default BASIC data segment (DS). Otherwise, BSAVE begins
  3174.    saving at the address specified by the offset and by the segment set in
  3175.    the most recent DEF SEG statement.
  3176.  
  3177.    If the offset is a single- or double-precision floating-point value, it is
  3178.    coerced to an integer. If the offset is a negative number in the range -1
  3179.    to -32,768, it is treated as an unsigned 2- byte offset.
  3180.  
  3181.  ────────────────────────────────────────────────────────────────────────────
  3182.  NOTE
  3183.    Because different screen modes use memory differently, do not load graphic
  3184.    images in a screen mode other than the one used when the images were
  3185.    created.
  3186.  ────────────────────────────────────────────────────────────────────────────
  3187.  
  3188.  ■ Differences From Basica
  3189.  
  3190.    BSAVE does not support the cassette device.
  3191.  
  3192.  ■ See Also
  3193.  
  3194.    BLOAD
  3195.  
  3196.  ■ Example
  3197.  
  3198.    This example draws a graphic and then saves it as a memory-image file. See
  3199.    the example for the BLOAD statement to see how the file would be
  3200.    retrieved.
  3201.  
  3202.    ' This program draws on the screen, stores the drawing in an
  3203.    ' array, and then saves the drawing in a disk file using BSAVE.
  3204.    '
  3205.    DIM Cube(1 TO 675)
  3206.  
  3207.    SCREEN 1
  3208.    ' Draw a white box.
  3209.    LINE (140,25)-(140+100,125),3,b
  3210.    ' Draw the outline of a magenta cube inside the box.
  3211.    DRAW "C2 BM140,50 M+50,-25 M+50,25 M-50,25"
  3212.    DRAW "M-50,-25 M+0,50 M+50,25 M+50,-25 M+0,-50 BM190,75 M+0,50"
  3213.    ' Save the drawing in the array Cube.
  3214.    GET (140,25)-(240,125),Cube
  3215.    ' Store the drawing in a disk file. Note: 2700 is the number
  3216.    ' of bytes in Cube (4 bytes per array element * 675).
  3217.    DEF SEG=VARSEG(Cube(1)) ' Set segment to array's segment.
  3218.    BSAVE "magcube.grh",VARPTR(Cube(1)),2700
  3219.    DEF SEG   ' Restore BASIC segment.
  3220.  
  3221.  
  3222.  ────────────────────────────────────────────────────────────────────────────
  3223.  CALL Statement (BASIC Procedures)
  3224.  ────────────────────────────────────────────────────────────────────────────
  3225.  
  3226.  ■ Action
  3227.  
  3228.    Transfers control to a BASIC SUB
  3229.  
  3230.  ■ Syntax 1
  3231.  
  3232.    CALL name«( argumentlist )»
  3233.  
  3234.  ■ Syntax 2
  3235.  
  3236.    name« argumentlist »
  3237.  
  3238.  ■ Remarks
  3239.  
  3240.    The CALL statement takes the following arguments:
  3241.  
  3242.    Argument                 Description
  3243.    ──────────────────────────────────────────────────────────────────────────
  3244.    name                     The name, limited to 40 characters, of the BASIC
  3245.                             SUB being called. The name must appear in a SUB
  3246.                             statement if the SUB is in the same module.
  3247.  
  3248.    argumentlist             The variables or constants passed to the
  3249.                             subprogram. Arguments in the list are separated
  3250.                             by commas. Arguments passed by reference can be
  3251.                             changed by the subprogram.
  3252.    ──────────────────────────────────────────────────────────────────────────
  3253.  
  3254.    If the argumentlist includes an array argument, the array is specified by
  3255.    the array name followed by empty parentheses:
  3256.  
  3257.    DIM IntArray(1 TO 20)
  3258.    .
  3259.    .
  3260.    .
  3261.    CALL ShellSort(IntArray())
  3262.  
  3263.    When you use the CALL statement, the CALL keyword is optional. However, if
  3264.    you omit the CALL keyword, you must declare the procedure in a DECLARE
  3265.    statement. Notice also that when you omit the CALL keyword, you also omit
  3266.    the parentheses around the argument list. See Chapter 2 , "SUB and
  3267.    FUNCTION Procedures," in Programming in BASIC for more information.
  3268.  
  3269.    Arguments are passed by reference: the subprogram is given the address of
  3270.    the argument. This allows subprograms to change the argument values. BASIC
  3271.    can also pass arguments by value. The following statement calls a
  3272.    subprogram and passes a single argument by value:
  3273.  
  3274.    CALL SolvePuzzle((StartValue))
  3275.  
  3276.    Because StartValue is in parentheses, BASIC evaluates it as an expression.
  3277.    The result is stored in a temporary location, and the address of the
  3278.    temporary location is passed to the SUB. Any change made by the subprogram
  3279.    SolvePuzzle is made only to the temporary location and not to the
  3280.    variable.
  3281.  
  3282.  ■ See Also
  3283.  
  3284.    CALL, CALLS (Non BASIC); CALL ABSOLUTE; DECLARE (BASIC)
  3285.  
  3286.  ■ Example
  3287.  
  3288.    The program below copies a series of files into a new file, the last file
  3289.    in the series entered from the command line. In the program, the BASIC
  3290.    subprogram PRINTOUT is called after first splitting the command line into
  3291.    separate file names and storing them in the array FILE$. The PRINTOUT
  3292.    subprogram copies the contents of the files to the final file in the list
  3293.    and to the standard output device (default is to your screen).
  3294.  
  3295.    DEFINT A-Z
  3296.    CONST MAXFILES=5, ARRAYDIM=MAXFILES+1
  3297.    DIM File$(1 TO ARRAYDIM)
  3298.    ' Separate command line into arguments.
  3299.    CALL Comline (Numargs,File$(),ARRAYDIM)
  3300.    ' Test for too many or too few files.
  3301.    IF Numargs < 3 OR Numargs >MAXFILES THEN
  3302.      ' Too many or too few files.
  3303.       PRINT "Use more than 3 and fewer than";MAXFILES;"files"
  3304.    ELSE
  3305.      ' Send all files to Printout.
  3306.       CALL Printout(File$(),Numargs)
  3307.    END IF
  3308.    END
  3309.  
  3310.  
  3311.    ' See the example under COMMAND$ for the definition of
  3312.    ' Comline. Comline would appear here.
  3313.  
  3314.    SUB Printout(F$(1),N) STATIC
  3315.       ' Open target file.
  3316.       OPEN F$(N) FOR OUTPUT AS #3
  3317.       ' Loop executes once for each file.
  3318.       ' Copy the first N-1 files onto the Nth file.
  3319.       FOR File = 1 TO N-1
  3320.          OPEN F$(File) FOR INPUT AS #1
  3321.          DO WHILE NOT EOF(1)
  3322.             'Read file.
  3323.             LINE INPUT #1, Temp$
  3324.             'Write data to target file.
  3325.             PRINT #3, Temp$
  3326.             PRINT Temp$                 'Write file to standard
  3327.          LOOP                           'output.
  3328.          CLOSE #1
  3329.        NEXT
  3330.        CLOSE
  3331.    END SUB
  3332.  
  3333.  
  3334.  ────────────────────────────────────────────────────────────────────────────
  3335.  CALL, CALLS Statement (Non-BASIC Procedures)
  3336.  ────────────────────────────────────────────────────────────────────────────
  3337.  
  3338.  ■ Action
  3339.  
  3340.    Transfers control to a procedure written in another language
  3341.  
  3342.  ■ Syntax 1
  3343.  
  3344.    CALL name «(call-argumentlist)»
  3345.  
  3346.  ■ Syntax 2
  3347.  
  3348.    name «call-argumentlist»
  3349.  
  3350.  ■ Syntax 3
  3351.  
  3352.    CALLS name «(calls-argumentlist)»
  3353.  
  3354.  ■ Remarks
  3355.  
  3356.    The following list describes the parts of the CALL statement:
  3357.  
  3358.    Argument                 Description
  3359.    ──────────────────────────────────────────────────────────────────────────
  3360.    name                     The name of the procedure being called. A name is
  3361.                             limited to 40 characters.
  3362.  
  3363.    call-argumentlist        The variables or constants passed to the
  3364.                             procedure. The syntax of a call-argumentlist is
  3365.                             described below.
  3366.  
  3367.    calls-argumentlist       A list containing the variables and constants
  3368.                             that CALLS passes to the procedure. Entries are
  3369.                             separated by commas. Note that these arguments
  3370.                             are passed by reference as far addresses, using
  3371.                             the segment and offset of the variable. You
  3372.                             cannot use BYVAL or SEG in a calls-argumentlist.
  3373.    ──────────────────────────────────────────────────────────────────────────
  3374.  
  3375.    A call-argumentlist has the following syntax:
  3376.  
  3377.    ««{BYVAL|SEG}»argument»«,«{BYVAL|SEG}»argument»...
  3378.  
  3379.    If argument is an array, parentheses are required:
  3380.  
  3381.    ««{BYVAL|SEG}»argument«()»»«,«{BYVAL|SEG}»argument»...
  3382.  
  3383.    Part                     Description
  3384.    ──────────────────────────────────────────────────────────────────────────
  3385.    BYVAL                    Indicates the argument is passed by value, rather
  3386.                             than by near reference (the default)
  3387.  
  3388.    SEG                      Passes the argument as a segmented (far) address
  3389.  
  3390.    argument                 A BASIC variable, array, or constant passed to
  3391.                             the procedure
  3392.    ──────────────────────────────────────────────────────────────────────────
  3393.  
  3394.    CALLS is the same as using CALL with a SEG before each argument: every
  3395.    argument in a CALLS statement is passed as a segmented address.
  3396.  
  3397.  ────────────────────────────────────────────────────────────────────────────
  3398.  NOTE
  3399.    The syntax described above does not correctly invoke a BASIC
  3400.    procedure──only procedures in other languages. See also the separate entry
  3401.    for CALL (BASIC).
  3402.  ────────────────────────────────────────────────────────────────────────────
  3403.  
  3404.    If the argument list of either statement includes an array argument, the
  3405.    array is specified by the array name and a pair of parentheses:
  3406.  
  3407.    DIM IntArray(20) AS INTEGER
  3408.    .
  3409.    .
  3410.    .
  3411.    CALL ShellSort(IntArray() AS INTEGER)
  3412.  
  3413.    When you use the CALL statement, the CALL keyword is optional. However,
  3414.    when you omit CALL, you must declare the procedure in a DECLARE statement.
  3415.    Notice also that when you omit CALL, you also omit the parentheses around
  3416.    the argument list. See Chapter 2, "SUB and FUNCTION Procedures," in
  3417.    Programming in BASIC for more information about invoking procedures
  3418.    without the CALL keyword.
  3419.  
  3420.    The result of the BYVAL keyword differs from BASIC's pass by value:
  3421.  
  3422.    CALL Difference (BYVAL A,(B))
  3423.  
  3424.    For the first argument, only the value of A is passed to Difference. In
  3425.    contrast, (B) is evaluated, a temporary location is created for the value,
  3426.    and the address of the temporary location is passed to Difference. You can
  3427.    use BASIC's pass by value for an argument, but you must write the
  3428.    procedure in the other language so the procedure accepts an address.
  3429.  
  3430.  ────────────────────────────────────────────────────────────────────────────
  3431.  NOTE
  3432.    If name refers to an assembly-language procedure, it must be a PUBLIC name
  3433.    (symbol). PUBLIC names beginning with "$" and "_" may conflict with names
  3434.    used by the BASIC run-time system. Duplicate names cause a linker error
  3435.    message (symbol already defined) to be generated.
  3436.  ────────────────────────────────────────────────────────────────────────────
  3437.  
  3438.    Be careful using the SEG keyword to pass arrays because BASIC may move
  3439.    variables in memory before the called routine begins execution. Anything
  3440.    in an argument list that causes memory movement may create problems. You
  3441.    can safely pass variables using SEG if the CALL statement's argument list
  3442.    contains only simple variables, arithmetic expressions, or arrays indexed
  3443.    without the use of intrinsic or user-defined functions.
  3444.  
  3445.    See Section 2.3.3, "Variable Storage Allocation," for a list of things
  3446.    that cause variable movement and for information about when to use near or
  3447.    far addresses for variables.
  3448.  
  3449.  ■ Differences From Basica
  3450.  
  3451.    Assembly-language programs invoked from BASICA that have string arguments
  3452.    must be changed because the string descriptor is now four bytes long. The
  3453.    four bytes are the low byte and high byte of the length followed by the
  3454.    low byte and high byte of the address.
  3455.  
  3456.    To locate the routine being called, the BASICA CALLS statement uses the
  3457.    segment address defined by the most recently executed DEF SEG statement.
  3458.    There is no need to use DEF SEG with the CALLS statement because all
  3459.    arguments are passed as far (segmented) addresses.
  3460.  
  3461.  ■ See Also
  3462.  
  3463.    CALL (BASIC); DECLARE (BASIC); DECLARE (Non-BASIC)
  3464.  
  3465.  ■ Example
  3466.  
  3467.    See the example for VARPTR.
  3468.  
  3469.  
  3470.  ────────────────────────────────────────────────────────────────────────────
  3471.  CALL ABSOLUTE Statement
  3472.  ────────────────────────────────────────────────────────────────────────────
  3473.  
  3474.  ■ Action
  3475.  
  3476.    Transfers control to a machine-language procedure
  3477.  
  3478.  ■ Syntax
  3479.  
  3480.    CALL ABSOLUTE («argumentlist,»integervariable)
  3481.  
  3482.  ■ Remarks
  3483.  
  3484.    The CALL ABSOLUTE statement takes the following arguments:
  3485.  
  3486.    Argument                 Description
  3487.    ──────────────────────────────────────────────────────────────────────────
  3488.    argumentlist             Optional arguments passed to a machine-language
  3489.                             procedure.
  3490.  
  3491.    integervariable          An integer variable containing a value that is
  3492.                             the offset from the beginning of the current code
  3493.                             segment, set by DEF SEG, to the starting location
  3494.                             of the procedure. The integervariable argument is
  3495.                             not passed to the procedure. Your program may
  3496.                             need to execute a DEF SEG statement before
  3497.                             executing CALL ABSOLUTE to set the code segment
  3498.                             for the called routine.
  3499.  
  3500.                             Using a noninteger value for integervariable
  3501.                             produces unpredictable results.
  3502.    ──────────────────────────────────────────────────────────────────────────
  3503.  
  3504.    Arguments in argumentlist are passed to the machine-language program as
  3505.    offsets (near pointers) from the current data segment. Although arguments
  3506.    are passed as offsets, the machine-language program is invoked with a far
  3507.    call.
  3508.  
  3509.  ────────────────────────────────────────────────────────────────────────────
  3510.  NOTE
  3511.    The CALL ABSOLUTE statement is provided to maintain compatibility with
  3512.    earlier versions of BASIC. Mixed-language programming using the CALL
  3513.    statement extensions and the new DECLARE statement provide a simpler way
  3514.    to use assembly language with BASIC.
  3515.  
  3516.    In order to use CALL ABSOLUTE you must start QuickBASIC with the correct
  3517.    Quick library, link your program with QB.LIB, or use the QB.QLB Quick
  3518.    library. See the disk-contents list for the locations of these files.
  3519.  ────────────────────────────────────────────────────────────────────────────
  3520.  
  3521.  ■ Differences From Basica
  3522.  
  3523.    Assembly-language programs that are invoked from BASICA and that have
  3524.    string arguments must be changed because string descriptors are now four
  3525.    bytes long. The four bytes are the low byte and high byte of the string
  3526.    length followed by the low byte and high byte of the string address.
  3527.  
  3528.  ■ See Also
  3529.  
  3530.    CALL, CALLS (Non-BASIC)
  3531.  
  3532.  ■ Example
  3533.  
  3534.    The following example uses CALL ABSOLUTE to execute a machine-language
  3535.    program stored in an array:
  3536.  
  3537.    CONST nASMBYTES=14
  3538.    ' This program prints a message indicating whether or not
  3539.    ' a math coprocessor is installed.
  3540.    ' It uses a machine-language program stored in an array
  3541.    ' to get the information from the operating system.
  3542.    'AsmBytes is a label; nASMBYTES is a symbolic constant.
  3543.    DEFINT A-Z
  3544.    DIM AsmProg(1 TO (nASMBYTES/2))
  3545.  
  3546.    ' The machine-language program stored as data to read into
  3547.    ' the array.
  3548.    DATA &H55              :'PUSH BP       Save base pointer.
  3549.    DATA &H8B, &HEC        :'MOV  BP,SP    Get our own.
  3550.    DATA &HCD, &H11        :'INT  11H      Make the ROM-BIOS call.
  3551.    DATA &H8B, &H5E, &H06  :'MOV  BX,[BP+6] Get argument address.
  3552.    DATA &H89, &H07        :'MOV  [BX],AX  Save list in argument.
  3553.    DATA &H5D              :'POP  BP       Restore base pointer.
  3554.    DATA &HCA, &H02, &H00  :'RET  2        Pop argument off stack
  3555.                            '              and make far return.
  3556.    ' Get the starting offset of the array.
  3557.    P=VARPTR(AsmProg(1))
  3558.    ' Poke the machine-language program into the array.
  3559.    DEF SEG=VARSEG(AsmProg(1)) ' Change the segment.
  3560.    Restore AsmBytes
  3561.    FOR I=0 TO nASMBYTES-1
  3562.       READ J
  3563.       POKE(P+I),J
  3564.    NEXT I
  3565.  
  3566.    ' Execute the program. The program expects a single integer
  3567.    ' argument.
  3568.    CALL ABSOLUTE(X%,VARPTR(AsmProg(1)))
  3569.    DEF SEG   ' Restore the segment.
  3570.    ' X% now contains bit-encoded equipment list returned by DOS.
  3571.    ' Mask off all but the coprocessor bit (bit 2).
  3572.    CoProcessor=X% AND &H2
  3573.    ' Print the appropriate message.
  3574.    IF CoProcessor=2 THEN
  3575.      PRINT "Math coprocessor present."
  3576.    ELSE
  3577.      PRINT "No math coprocessor."
  3578.    END IF
  3579.    END
  3580.  
  3581.  
  3582.  ────────────────────────────────────────────────────────────────────────────
  3583.  CALL INT86OLD Statements
  3584.  ────────────────────────────────────────────────────────────────────────────
  3585.  
  3586.  ■ Action
  3587.  
  3588.    Allows programs to perform DOS system calls
  3589.  
  3590.  ■ Syntax
  3591.  
  3592.    CALL INT86OLD (int_no,in_array(),out_array())
  3593.    CALL INT86XOLD (int_no,in_array(),out_array())
  3594.  
  3595.  ■ Remarks
  3596.  
  3597.    The CALL INTERRUPT statement provides an easier way to make DOS system
  3598.    calls. See the entry for CALL INTERRUPT for more information. The
  3599.    following list describes the arguments to INT86OLD and INT86XOLD:
  3600.  
  3601.    Argument                 Description
  3602.    ──────────────────────────────────────────────────────────────────────────
  3603.    int_no                   The DOS interrupt to perform. It is an integer
  3604.                             between 0 and 255. See your DOS documentation for
  3605.                             the interrupt numbers.
  3606.  
  3607.    in_array()               An integer array specifying the register values
  3608.                             when the interrupt is performed.
  3609.  
  3610.                             INT86OLD uses an eight-element array, while
  3611.                             INT86XOLD uses a ten-element array. Table R.1
  3612.                             lists the array elements and the corresponding
  3613.                             registers.
  3614.  
  3615.    out_array()              Contains the postinterrupt register values. It
  3616.                             has the same structure as in_array.
  3617.    ──────────────────────────────────────────────────────────────────────────
  3618.  
  3619.    If an error occurs, int_no = -1 and values in out_array are unchanged.
  3620.    Errors are caused by int_no not being in the range 0-255.
  3621.  
  3622.    Table R.1   INT86OLD and INT86XOLD Register Values
  3623.  
  3624.    Array Element            Register
  3625.    ──────────────────────────────────────────────────────────────────────────
  3626.    in_array(x)              AX
  3627.    in_array(x+1)            BX
  3628.    in_array(x+2)            CX
  3629.    in_array(x+3)            DX
  3630.    in_array(x+4)            BP
  3631.    in_array(x+5)            SI
  3632.    in_array(x+6)            DI
  3633.    in_array(x+7)            FLAGS
  3634.    in_array(x+8)           DS
  3635.    in_array(x+9)           ES
  3636.    ──────────────────────────────────────────────────────────────────────────
  3637.  
  3638.    The INT86OLD and INT86XOLD routines alter all registers except BP and DS.
  3639.  
  3640.    INT86OLD and INT86XOLD provide compatibility with older programs using
  3641.    INT86 and INT86X. Like the INT86 and INT86X routines, INT86OLD and
  3642.    INT86XOLD are distributed in a Quick library (QB.QLB) and in a
  3643.    conventional library (QB.LIB) on the distribution disks. The disks also
  3644.    contain a header file (QB.BI) for use with the procedures. See the
  3645.    disk-contents list for specific information.
  3646.  
  3647.    Note that INT86OLD and INT86XOLD do not require the use of VARPTR. Also,
  3648.    the register values are stored in the arrays beginning with the first
  3649.    array element.
  3650.  
  3651.  ■ Example
  3652.  
  3653.    The following example uses INT86OLD to open a file and place some text in
  3654.    it:
  3655.  
  3656.    ' Include header file for INT86OLD, etc.
  3657.    ' ¢INCLUDE:'QB.BI'
  3658.  
  3659.    DIM INARY%(7),OUTARY%(7)          'Define input and output
  3660.                                      'arrays for INT86.
  3661.    '
  3662.    ' Define register-array indices to
  3663.    ' make program easier to understand.
  3664.    CONST AX=0, BX=1, CX=2, DX=3, BP=4, SI=5, DI=6, FL=7
  3665.    '
  3666.    INARY%(AX) = &H3C00               'DOS function to create a file.
  3667.    INARY%(CX) = 0                    'DOS attribute for created file.
  3668.    INARY%(DX) = SADD("FOO.TXT"+CHR$(0))
  3669.                                   'Pointer to file-name string
  3670.                                   'with zero byte termination.
  3671.  
  3672.    CALL INT86OLD(&H21,INARY%(),OUTARY%())
  3673.                                      'Perform the creation.
  3674.    '
  3675.    INARY%(BX) = OUTARY%(AX)   'Move created file handle for write.
  3676.    INARY%(AX) = &H4000
  3677.           'DOS function to write to file.
  3678.    TEXT$ = "hello, world"+CHR$(13)+CHR$(10)
  3679.                                      'Define text to write to file.
  3680.  
  3681.    INARY%(CX) = LEN(TEXT$)       'Get length of text string.
  3682.    INARY%(DX) = SADD(TEXT$)      'Get address of text string.
  3683.    CALL INT86OLD(&H21,INARY%(),OUTARY%())
  3684.                                      'Perform the write.
  3685.    '
  3686.    INARY%(AX) = &H3E00
  3687.           'DOS function to close a file.
  3688.    CALL INT86OLD(&H21,INARY%(),OUTARY%())
  3689.                                      'Perform the close.
  3690.  
  3691.  
  3692.  ────────────────────────────────────────────────────────────────────────────
  3693.  CALL INTERRUPT Statements
  3694.  ────────────────────────────────────────────────────────────────────────────
  3695.  
  3696.  ■ Action
  3697.  
  3698.    Allows BASIC programs to perform DOS system calls
  3699.  
  3700.  ■ Syntax
  3701.  
  3702.    CALL INTERRUPT (interruptnum,inregs,outregs)
  3703.    CALL INTERRUPTX (interruptnum,inregs,outregs)
  3704.  
  3705.  ■ Remarks
  3706.  
  3707.    The following list describes the arguments for the CALL INTERRUPT and CALL
  3708.    INTERRUPTX statements:
  3709.  
  3710.    Argument                 Description
  3711.    ──────────────────────────────────────────────────────────────────────────
  3712.    interruptnum             The DOS interrupt number. It is an integer
  3713.                             between 0 and 255. See your DOS documentation for
  3714.                             information about interrupts.
  3715.  
  3716.    inregs                   The inregs variable contains the register values
  3717.                             used when the interrupt is performed. It is
  3718.                             declared as type RegType. The user-defined type
  3719.                             RegType is described below.
  3720.  
  3721.    outregs                  The outregs variable contains the register values
  3722.                             after the interrupt is performed. It is declared
  3723.                             as type RegType. The user-defined type RegType is
  3724.                             described below.
  3725.    ──────────────────────────────────────────────────────────────────────────
  3726.  
  3727.    The CALL INTERRUPT and CALL INTERRUPTX statements replace the INT86 and
  3728.    INT86X routines used in earlier versions of BASIC. They provide a more
  3729.    convenient way for BASIC programs to use DOS interrupts and services.
  3730.  
  3731.    The register values before and after the interrupt are passed in variables
  3732.    declared as type RegType. The following statement defines the RegType
  3733.    user-defined type:
  3734.  
  3735.    TYPE RegType
  3736.       AX AS INTEGER
  3737.       BX AS INTEGER
  3738.       CX AS INTEGER
  3739.       DX AS INTEGER
  3740.       BP AS INTEGER
  3741.       SI AS INTEGER
  3742.  
  3743.    DI AS INTEGER
  3744.       FLAGS AS INTEGER
  3745.       DS AS INTEGER
  3746.       ES AS INTEGER
  3747.    END TYPE
  3748.  
  3749.    Each element of the type corresponds to a CPU register.
  3750.  
  3751.    INTERRUPTX uses the values in the DS and ES registers. To use the current
  3752.    values of these registers, set the record elements to -1.
  3753.  
  3754.    CALL INTERRUPT and CALL INTERRUPTX are available in a Quick Library
  3755.    (QB.QLB) and in a conventional library (QB.LIB) on your distribution
  3756.    disks. There is also a header file (QB.BI) on the disks with the necessary
  3757.    declarations for using these procedures. See the disk-contents list for
  3758.    specific information.
  3759.  
  3760.    To use CALL INTERRUPT or CALL INTERRUPTX when running a program within the
  3761.    QuickBASIC environment, the Quick library QB.QLB must be loaded with
  3762.    QuickBASIC.
  3763.  
  3764.  ■ Example
  3765.  
  3766.    The following program uses CALL INTERRUPT to change a file's attribute
  3767.    list so the file does not appear when you use the DIR command from DOS:
  3768.  
  3769.    DECLARE SUB TestError (AXReg%, flags%)
  3770.    ' ¢INCLUDE: 'QB.BI'
  3771.  
  3772.    DEFINT A-Z
  3773.    DIM InRegs AS RegType, OutRegs AS RegType
  3774.  
  3775.    ' Get the file name and action to perform.
  3776.    CLS
  3777.    PRINT "Hidden File Program": PRINT
  3778.    INPUT "Enter file name: ", FileName$
  3779.    DO
  3780.       INPUT "Hide or unhide (H or U): ", Action$
  3781.       Action$ = UCASE$(Action$)
  3782.    LOOP WHILE Action$ <> "H" AND Action$ <> "U"
  3783.  
  3784.    ' Tack a null (zero) byte onto the end of the string for the
  3785.    ' DOS function.
  3786.    FileName$ = FileName$ + CHR$(0)
  3787.  
  3788.    ' Get the current file attribute.
  3789.    ' Current attribute comes back in OutRegs.AX.
  3790.    InRegs.ax = &H4300
  3791.    InRegs.dx = SADD(FileName$)
  3792.    CALL INTERRUPT(&H21, InRegs, OutRegs)
  3793.    CALL TestError(OutRegs.ax, OutRegs.flags)
  3794.  
  3795.    ' Change the hidden attribute bit in the old attribute value.
  3796.    IF Action$ = "U" THEN
  3797.       InRegs.cx = OutRegs.cx AND &HFD
  3798.    ELSE
  3799.       InRegs.cx = OutRegs.cx OR &H2
  3800.    END IF
  3801.  
  3802.    ' Set AX to indicate the Change Attribute DOS function.
  3803.    InRegs.ax = &H4301
  3804.    CALL INTERRUPT(&H21, InRegs, OutRegs)
  3805.    CALL TestError(OutRegs.ax, OutRegs.flags)
  3806.  
  3807.    END
  3808.    ' If carry flag set, print error message and end program.
  3809.    SUB TestError (AXReg, flags) STATIC
  3810.       IF (&H1 AND flags) <> 0 THEN
  3811.          ' Get the error number out of AX.
  3812.          SELECT CASE AXReg AND &HF
  3813.             CASE 2
  3814.                PRINT "File not found."
  3815.             CASE 3
  3816.                PRINT "Path not found."
  3817.             CASE 5
  3818.                PRINT "Access denied."
  3819.             CASE ELSE
  3820.                PRINT "Unrecognized error."
  3821.          END SELECT
  3822.          END
  3823.       END IF
  3824.    END SUB
  3825.  
  3826.  
  3827.  ────────────────────────────────────────────────────────────────────────────
  3828.  CDBL Function
  3829.  ────────────────────────────────────────────────────────────────────────────
  3830.  
  3831.  ■ Action
  3832.  
  3833.    Converts a numeric expression to a double-precision number
  3834.  
  3835.  ■ Syntax
  3836.  
  3837.    CDBL(numeric-expression)
  3838.  
  3839.  ■ Remarks
  3840.  
  3841.    The numeric-expression may be any numeric expression. This function has
  3842.    the same effect as assigning the numeric expression to a double-precision
  3843.    variable.
  3844.  
  3845.    Note that the results of CDBL are no more accurate than the original
  3846.    expression. The added digits of precision are not significant unless the
  3847.    expression is calculated with double-precision accuracy.
  3848.  
  3849.  ■ Example
  3850.  
  3851.    The following example demonstrates how the precision of the numeric
  3852.    expression affects the result of using CDBL:
  3853.  
  3854.    X = 7/9
  3855.    X# = 7/9
  3856.    PRINT X
  3857.    'Both X# and CDBL(X) will be accurate to only 7 decimal
  3858.    'places, because 7/9 is evaluated in single precision.
  3859.    PRINT X#
  3860.    PRINT CDBL(X)
  3861.    'Accurate to 15 decimal places.
  3862.    PRINT 7#/9#
  3863.  
  3864.  ■ Output
  3865.  
  3866.     .7777778
  3867.     .7777777910232544
  3868.     .7777777910232544
  3869.     .7777777777777778
  3870.  
  3871.  
  3872.  ────────────────────────────────────────────────────────────────────────────
  3873.  CHAIN Statement
  3874.  ────────────────────────────────────────────────────────────────────────────
  3875.  
  3876.  ■ Action
  3877.  
  3878.    Transfers control from the current program to another program
  3879.  
  3880.  ■ Syntax
  3881.  
  3882.    CHAIN filespec
  3883.  
  3884.  ■ Remarks
  3885.  
  3886.    The filespec is a string expression that identifies the program to which
  3887.    control is passed. The filespec may include a path specification. Programs
  3888.    running within the QuickBASIC environment assume a .BAS extension (if no
  3889.    extension is given) and cannot chain to executable files (files with a
  3890.    .COM or .EXE extension). Programs running outside the QuickBASIC
  3891.    environment assume an .EXE extension and cannot chain to QuickBASIC source
  3892.    files (files with a .BAS extension).
  3893.  
  3894.    You can pass variables between programs using the COMMON statement to set
  3895.    up a blank COMMON block. See the entry for COMMON.
  3896.  
  3897.    If you are compiling a program outside the QuickBASIC environment, note
  3898.    that the BCOM45.LIB library does not support COMMON. There are two ways to
  3899.    use COMMON with chained programs outside the environment:
  3900.  
  3901.    ■ Use the default (BRUN45.EXE) by compiling the programs using the option
  3902.      in the Make EXE dialog box called EXE Requiring BRUN45.EXE.
  3903.  
  3904.    ■ Use BRUN45.LIB by compiling from the command line without the /O option.
  3905.  
  3906.    The behavior of CHAIN and RUN is almost identical. The principal
  3907.    differences are that RUN closes all open files and does not support COMMON
  3908.    data blocks.
  3909.  
  3910.  ────────────────────────────────────────────────────────────────────────────
  3911.  NOTE
  3912.    When programs use BRUN45.LIB, files are left open during chaining unless
  3913.    they are explicitly closed with a CLOSE statement.
  3914.  ────────────────────────────────────────────────────────────────────────────
  3915.  
  3916.  ■ Differences From Basica
  3917.  
  3918.    BASICA assumes the extension .BAS. QuickBASIC assumes an extension of
  3919.    either .BAS or .EXE, depending on whether the program is run within the
  3920.    environment or compiled and run outside the environment. If you omit the
  3921.    file extension, CHAIN works the same in both QuickBASIC and BASICA.
  3922.  
  3923.    BASIC does not support the ALL, MERGE, or DELETE options available in
  3924.    BASICA, nor does it allow you to specify a line number.
  3925.  
  3926.    Without the line-number option, execution always starts at the beginning
  3927.    of the chained-to program. Thus, a chained-to program that chains back to
  3928.    a carelessly written chaining program can cause an endless loop.
  3929.  
  3930.  ■ See Also
  3931.  
  3932.    CALL (BASIC), COMMON, RUN
  3933.  
  3934.  ■ Example
  3935.  
  3936.    See example for the COMMON statement.
  3937.  
  3938.  
  3939.  ────────────────────────────────────────────────────────────────────────────
  3940.  CHDIR Statement
  3941.  ────────────────────────────────────────────────────────────────────────────
  3942.  
  3943.  ■ Action
  3944.  
  3945.    Changes the current default directory for the specified drive
  3946.  
  3947.  ■ Syntax
  3948.  
  3949.    CHDIR pathspec
  3950.  
  3951.  ■ Remarks
  3952.  
  3953.    The pathspec is a string expression identifying the directory that is to
  3954.    become the default directory. The pathspec must have fewer than 64
  3955.    characters. It has the following syntax:
  3956.  
  3957.    «drive:»«\»directory«\directory»...
  3958.  
  3959.    The argument drive: is an optional drive specification. If you omit drive,
  3960.    CHDIR changes the default directory on the current drive.
  3961.  
  3962.    CHDIR differs from the CHDIR command in DOS in two ways:
  3963.  
  3964.    1. The BASIC statement cannot be shortened to CD.
  3965.  
  3966.    2. There is no form of the CHDIR statement that returns the current
  3967.       directory.
  3968.  
  3969.  ────────────────────────────────────────────────────────────────────────────
  3970.    The CHDIR statement changes the default directory but not the default
  3971.    drive. For example, if the default drive is C, then the following CHDIR
  3972.    statement changes the default directory on drive D, but the default drive
  3973.    is still C:
  3974.  ────────────────────────────────────────────────────────────────────────────
  3975.  
  3976.    CHDIR "D:\TMP"
  3977.  
  3978.  ■ See Also
  3979.  
  3980.    MKDIR, RMDIR
  3981.  
  3982.  ■ Examples
  3983.  
  3984.    ' Makes \HOME\SALES the current directory on the default
  3985.    ' drive.
  3986.    CHDIR "\HOME\SALES"
  3987.  
  3988.    'Changes the current directory to USERS on drive B; it does
  3989.    'not, however, change the default drive to B.
  3990.    CHDIR "B:USERS"
  3991.  
  3992.  
  3993.  ────────────────────────────────────────────────────────────────────────────
  3994.  CHR$ Function
  3995.  ────────────────────────────────────────────────────────────────────────────
  3996.  
  3997.  ■ Action
  3998.  
  3999.    Returns a one-character string whose ASCII code is the argument
  4000.  
  4001.  ■ Syntax
  4002.  
  4003.    CHR$(code)
  4004.  
  4005.  ■ Remarks
  4006.  
  4007.    CHR$ is commonly used to send a special character to the screen or
  4008.    printer. For example, you can send a form feed (CHR$(12)) to clear the
  4009.    screen and return the cursor to the home position.
  4010.  
  4011.    CHR$ can also be used to include a double quote (") in a string:
  4012.  
  4013.    Msg$=CHR$(34)+"Quoted string"+CHR$(34)
  4014.  
  4015.    This line adds a double-quote character to the beginning and the end of
  4016.    the string.
  4017.  
  4018.  ■ See Also
  4019.  
  4020.    ASC; Appendix A, "Keyboard Scan Codes and ASCII Character Codes"
  4021.  
  4022.  ■ Example
  4023.  
  4024.    The following example uses CHR$ to display graphics characters in the
  4025.    extended character set:
  4026.  
  4027.    DEFINT A-Z
  4028.    ' Display two double-sided boxes.
  4029.    CALL DBox(5,22,18,40)
  4030.    CALL DBox(1,4,4,50)
  4031.    END
  4032.  
  4033.    ' Subroutine to display boxes on the screen.
  4034.    '
  4035.    ' Parameters
  4036.    '  Urow%, Ucol% : Row and column of upper-left corner.
  4037.    '  Lrow%, Lcol% : Row and column of lower-right corner.
  4038.    ' Use constants for the extended character set graphic
  4039.    ' characters.
  4040.    CONST ULEFTC=201, URIGHTC=187, VERTICAL=186, HORIZONTAL=205
  4041.    CONST LLEFTC=200, LRIGHTC=188
  4042.  
  4043.    SUB DBox (Urow%, Ucol%, Lrow%, Lcol%) STATIC
  4044.  
  4045.       ' Draw top of box, starting with the upper left corner.
  4046.       LOCATE Urow%, Ucol% : PRINT CHR$(ULEFTC);
  4047.       LOCATE ,Ucol%+1 : PRINT STRING$(Lcol%-Ucol%,CHR$(HORIZONTAL));
  4048.       LOCATE ,Lcol% : PRINT CHR$(URIGHTC);
  4049.  
  4050.       ' Draw the body of the box.
  4051.       FOR I=Urow%+1 TO Lrow%-1
  4052.          LOCATE I,Ucol% : PRINT CHR$(VERTICAL);
  4053.          LOCATE  ,Lcol% : PRINT CHR$(VERTICAL);
  4054.       NEXT I
  4055.  
  4056.       ' Draw the bottom of the box.
  4057.       LOCATE Lrow%, Ucol% : PRINT CHR$(LLEFTC);
  4058.       LOCATE ,Ucol%+1 : PRINT STRING$(Lcol%-Ucol%,CHR$(HORIZONTAL));
  4059.       LOCATE ,Lcol% : PRINT CHR$(LRIGHTC);
  4060.  
  4061.    END SUB
  4062.  
  4063.  
  4064.  ────────────────────────────────────────────────────────────────────────────
  4065.  CINT Function
  4066.  ────────────────────────────────────────────────────────────────────────────
  4067.  
  4068.  ■ Action
  4069.  
  4070.    Converts a numeric expression to an integer by rounding the expression's
  4071.    fractional part
  4072.  
  4073.  ■ Syntax
  4074.  
  4075.    CINT(numeric-expression)
  4076.  
  4077.  ■ Remarks
  4078.  
  4079.    If numeric-expression is not in the range -32,768 to 32,767, the function
  4080.    produces a run-time error message that reads Overflow.
  4081.  
  4082.    CINT differs from the FIX and INT functions, which truncate, rather than
  4083.    round, the fractional part. See the example for the INT function for an
  4084.    illustration of the differences among these functions.
  4085.  
  4086.  ■ See Also
  4087.  
  4088.    CDBL, CSNG, FIX, INT
  4089.  
  4090.  ■ Example
  4091.  
  4092.    The following example converts an angle in radians to an angle in degrees
  4093.    and minutes:
  4094.  
  4095.    'Set up constants for converting radians to degrees.
  4096.    CONST PI=3.141593, RADTODEG=180./PI
  4097.    INPUT "Angle in radians = ",Angle  'Get the angle in radians.
  4098.    Angle = Angle * RADTODEG    'Convert radian input to degrees.
  4099.    Min = Angle - INT(Angle)    'Get the fractional part.
  4100.    'Convert fraction to value between 0 and 60.
  4101.    Min = CINT(Min * 60)
  4102.    Angle = INT(Angle)          'Get whole number part.
  4103.    IF Min = 60 THEN       '60 minutes = 1 degree.
  4104.       Angle = Angle + 1
  4105.       Min = 0
  4106.    END IF
  4107.    PRINT "Angle equals" Angle "degrees" Min "minutes"
  4108.  
  4109.  ■ Output
  4110.  
  4111.    Angle in radians = 1.5708
  4112.    Angle equals 90 degrees 0 minutes
  4113.  
  4114.  
  4115.  ────────────────────────────────────────────────────────────────────────────
  4116.  CIRCLE Statement
  4117.  ────────────────────────────────────────────────────────────────────────────
  4118.  
  4119.  ■ Action
  4120.  
  4121.    Draws an ellipse or circle with a specified center and radius
  4122.  
  4123.  ■ Syntax
  4124.  
  4125.    CIRCLE «STEP» (x,y),radius«,«color»«,«start»«,«end»«,aspect»»»»
  4126.  
  4127.  ■ Remarks
  4128.  
  4129.    The following list describes the parts of the CIRCLE statement:
  4130.  
  4131. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  4132.    Part                     Description
  4133.    ──────────────────────────────────────────────────────────────────────────
  4134.    STEP                     The STEP option specifies that x and y are
  4135.                             offsets relative to the current graphics cursor
  4136.                             position.
  4137.  
  4138.    x,y                      The x- and y-coordinates for the center of the
  4139.    Part                     Description
  4140.    ──────────────────────────────────────────────────────────────────────────
  4141.   x,y                      The x- and y-coordinates for the center of the
  4142.                             circle or ellipse.
  4143.  
  4144.    radius                   The radius of the circle or ellipse in the
  4145.                             current coordinate system.
  4146.  
  4147.    color                    The attribute of the desired color. See the
  4148.                             entries for the COLOR and SCREEN statements for
  4149.                             more information. The default color is the
  4150.                             foreground color.
  4151.  
  4152.    start, end               The start and end angles, in radians, for the arc
  4153.                             to draw. The start and end arguments are used to
  4154.                             draw partial circles or ellipses. The arguments
  4155.                             may range in value from -2π radians to 2π
  4156.                             radians, where π = appx. 3.141593. The default
  4157.                             value for start is 0 radians. The default value
  4158.                             for end is 2π radians.
  4159.  
  4160.    Part                     Description
  4161.    ──────────────────────────────────────────────────────────────────────────
  4162. 
  4163.                             If start or end is negative, then CIRCLE draws a
  4164.                             radius to that point on the arc and treats the
  4165.                             angle it were positive.
  4166.  
  4167.                             The start angle can be less than the end angle.
  4168.                             If you specify end but not start, the arc is
  4169.                             drawn from 2π to end; if you specify start but
  4170.                             not end, the statement draws an arc from start to
  4171.                             zero.
  4172.  
  4173.    aspect                   The aspect ratio, or the ratio of the y-radius to
  4174.                             the x-radius. The default value for aspect is the
  4175.                             value required to draw a round circle in the
  4176.                             screen mode. This value is calculated as follows:
  4177.  
  4178.                             4 * (ypixels/xpixels)/3
  4179.  
  4180.                             where xpixels by ypixels is the screen
  4181.    Part                     Description
  4182.    ──────────────────────────────────────────────────────────────────────────
  4183.                            where xpixels by ypixels is the screen
  4184.                             resolution. For example, in screen mode 1, where
  4185.                             the resolution is 320 x 200, the default for
  4186.                             aspect is 4 * (200/320)/3, or 5/6.
  4187.  
  4188.                             If the aspect ratio is less than one, radius is
  4189.                             the x-radius. If aspect is greater than one,
  4190.                             radius is equal to the y-radius.
  4191.    ──────────────────────────────────────────────────────────────────────────
  4192.  
  4193.  
  4194.    To draw a radius to angle 0 (a horizontal line segment to the right), do
  4195.    not give the angle as -0; use a very small nonzero value instead as shown:
  4196.  
  4197.    ' Draws a pie-shaped one-quarter wedge of a circle:
  4198.    SCREEN 2
  4199.    CIRCLE (200,100),60,,-.0001,-1.57
  4200.  
  4201.    You may omit an argument in the middle of the statement, but you must
  4202.    include the argument's commas. In the following statement, the color
  4203.    argument has been omitted:
  4204.  
  4205.    CIRCLE STEP (150,200),94,,0.0,6.28
  4206.  
  4207.    If you omit the last argument, you do not include the commas.
  4208.  
  4209.    The last point that CIRCLE references, after drawing, is the center of the
  4210.    ellipse or circle. You may use coordinates that are outside the screen or
  4211.    viewport.
  4212.  
  4213.    You may show coordinates as absolutes, or you may use the STEP option to
  4214.    show the position of the center point in relation to the previous point of
  4215.    reference. For example, if the previous point of reference is (10,10),
  4216.    then the following statement causes a circle to be drawn with radius 75
  4217.    and center offset 10 from the current x coordinate and 5 from the current
  4218.    y coordinate. The circle's center is (20,15).
  4219.  
  4220.    CIRCLE STEP (10,5), 75
  4221.  
  4222.  ■ Example
  4223.  
  4224.    The following program first draws a circle with the upper left quarter
  4225.    missing. It then uses relative coordinates to position a second circle
  4226.    within the missing quarter circle. Finally, it uses a different aspect
  4227.    ratio to draw a small ellipse inside the small circle.
  4228.  
  4229.    CONST PI=3.141593
  4230.    SCREEN 2
  4231.  
  4232.    ' Draw a circle with the upper-left quarter missing.
  4233.    ' Use negative numbers so radii are drawn.
  4234.    CIRCLE (320,100), 200,, -PI, -PI/2
  4235.  
  4236.    ' Use relative coordinates to draw a circle within the missing
  4237.    ' quarter.
  4238.    CIRCLE STEP (-100,-42),100
  4239.  
  4240.    ' Draw a small ellipse inside the circle.
  4241.    CIRCLE STEP(0,0), 100,,,, 5/25
  4242.  
  4243.    ' Display the drawing until a key is pressed.
  4244.    LOCATE 25,1 : PRINT "Press any key to end.";
  4245.    DO
  4246.    LOOP WHILE INKEY$=""
  4247.  
  4248.  
  4249.  ────────────────────────────────────────────────────────────────────────────
  4250.  CLEAR Statement
  4251.  ────────────────────────────────────────────────────────────────────────────
  4252.  
  4253.  ■ Action
  4254.  
  4255.    Reinitializes all program variables, closes files, and sets the stack size
  4256.  
  4257.  ■ Syntax
  4258.  
  4259.    CLEAR «,,stack»
  4260.  
  4261.  ■ Remarks
  4262.  
  4263.    The CLEAR statement performs the following actions:
  4264.  
  4265.    ■ Closes all files and releases the file buffers
  4266.  
  4267.    ■ Clears all COMMON variables
  4268.  
  4269.    ■ Sets numeric variables and arrays to zero
  4270.  
  4271.    ■ Sets all string variables to null
  4272.  
  4273.    ■ Reinitializes the stack and, optionally, changes its size
  4274.  
  4275.    The stack parameter sets aside stack space for your program. QuickBASIC
  4276.    takes the amount of stack space it requires, adds the number of bytes
  4277.    specified by stack, and sets the stack size to the result.
  4278.  
  4279.  ────────────────────────────────────────────────────────────────────────────
  4280.  NOTE
  4281.    Two commas are used before stack to keep QuickBASIC compatible with
  4282.    BASICA. BASICA included an additional argument that set the size of the
  4283.    data segment. Because QuickBASIC automatically manages the data segment,
  4284.    the first parameter is no longer required .
  4285.  ────────────────────────────────────────────────────────────────────────────
  4286.  
  4287.    If your program has deeply nested subroutines or procedures, or if you use
  4288.    recursive procedures, you may want to use a CLEAR statement to increase
  4289.    the stack size. You may also want to increase the stack size if your
  4290.    procedures have a large number of arguments.
  4291.  
  4292.    Clearing the stack destroys the return addresses placed on the stack
  4293.    during the execution of a GOSUB. This makes it impossible to execute a
  4294.    RETURN statement correctly and produces a RETURN without GOSUB run-time
  4295.    error message. Using a CLEAR statement in a SUB or FUNCTION produces a
  4296.    run-time error message that reads Illegal function call.
  4297.  
  4298.  ■ Differences From Basica
  4299.  
  4300.    BASICA programs using CLEAR may require modification. In BASICA programs,
  4301.    any DEF FN functions or data types declared with DEFtype statements are
  4302.    lost after a CLEAR statement. In compiled programs, this information is
  4303.    not lost because these declarations are fixed at compile time.
  4304.  
  4305.  ■ See Also
  4306.  
  4307.    FRE, SETMEMGT
  4308.  
  4309.  ■ Example
  4310.  
  4311.    The following statement clears all program variables and sets aside 2,000
  4312.    bytes on the stack for the program:
  4313.  
  4314.    CLEAR ,,2000
  4315.  
  4316.  
  4317.  ────────────────────────────────────────────────────────────────────────────
  4318.  CLNG Function
  4319.  ────────────────────────────────────────────────────────────────────────────
  4320.  
  4321.  ■ Action
  4322.  
  4323.    Converts a numeric expression to a long (4-byte) integer by rounding the
  4324.    fractional part of the expression
  4325.  
  4326.  ■ Syntax
  4327.  
  4328.    CLNG(numeric-expression)
  4329.  
  4330.  ■ Remarks
  4331.  
  4332.    If numeric-expression is not in the range -2,147,483,648 to 2,147,483,647,
  4333.    the function produces an error message that reads Overflow.
  4334.  
  4335.  ■ Example
  4336.  
  4337.    The following example shows how CLNG rounds before converting the number:
  4338.  
  4339.    A=32767.45
  4340.    B=32767.55
  4341.    PRINT CLNG(A); CLNG(B)
  4342.  
  4343.  ■ Output
  4344.  
  4345.    32767  32768
  4346.  
  4347.  
  4348.  ────────────────────────────────────────────────────────────────────────────
  4349.  CLOSE Statement
  4350.  ────────────────────────────────────────────────────────────────────────────
  4351.  
  4352.  ■ Action
  4353.  
  4354.    Concludes I/O to a file or device
  4355.  
  4356.  ■ Syntax
  4357.  
  4358.    CLOSE ««#» filenumber «,«#» filenumber»...»
  4359.  
  4360.  ■ Remarks
  4361.  
  4362.    The CLOSE statement complements the OPEN statement.
  4363.  
  4364.    The filenumber is the number under which the file was opened. A CLOSE
  4365.    statement with no arguments closes all open files and devices.
  4366.  
  4367.    The association of a file with a file number ends when a CLOSE statement
  4368.    is executed. You may then reopen the file using the same or a different
  4369.    file number. Once you close a file, you may use that file's number for any
  4370.    unopened file.
  4371.  
  4372.    A CLOSE for a file or device that was opened for sequential output writes
  4373.    the final buffer of output to that file or device.
  4374.  
  4375.    CLOSE releases all buffer space associated with the closed file or files.
  4376.  
  4377.    The CLEAR, END, RESET, RUN, and SYSTEM statements automatically close all
  4378.    files.
  4379.  
  4380.  ■ Example
  4381.  
  4382.    See the example for CALL (BASIC).
  4383.  
  4384.  
  4385.  ────────────────────────────────────────────────────────────────────────────
  4386.  CLS Statement
  4387.  ────────────────────────────────────────────────────────────────────────────
  4388.  
  4389.  ■ Action
  4390.  
  4391.    Clears the screen
  4392.  
  4393.  ■ Syntax
  4394.  
  4395.    CLS «{0 | 1 | 2}»
  4396.  
  4397.  ■ Remarks
  4398.  
  4399.    There are several ways to use the CLS statement, as described in the
  4400.    following list:
  4401.  
  4402.    Statement                Description
  4403.    ──────────────────────────────────────────────────────────────────────────
  4404.    CLS 0                    Clears the screen of all text and graphics.
  4405.  
  4406.    CLS 1                    Clears only the graphics viewport if a VIEW
  4407.                             statement has been executed. Otherwise, CLS 1
  4408.                             clears the entire screen.
  4409.  
  4410.    CLS 2                    Clears only the text viewport, leaving the bottom
  4411.                             screen line (line 25, 30, 43, or 60 depending on
  4412.                             the screen mode) unchanged.
  4413.  
  4414.    CLS                      Clears either the graphics viewport or the text
  4415.                             viewport. If the graphics viewport is active,
  4416.                             then CLS with no argument clears only the
  4417.                             viewport. If the graphics viewport is inactive,
  4418.                             then CLS clears the text viewport and refreshes
  4419.                             the function key display line (the bottom screen
  4420.                             line).
  4421.    ──────────────────────────────────────────────────────────────────────────
  4422.  
  4423.    The CLS statement also returns the cursor to the home position in the top
  4424.    left corner of the screen.
  4425.  
  4426.  ■ See Also
  4427.  
  4428.    VIEW, VIEW PRINT, WINDOW
  4429.  
  4430.  ■ Example
  4431.  
  4432.    The following program draws random circles in a graphics viewport and
  4433.    prints in a text viewport. The graphics viewport is cleared after 30
  4434.    circles have been drawn. The program clears the text viewport after
  4435.    printing to it 45 times.
  4436.  
  4437.    RANDOMIZE TIMER
  4438.    SCREEN 1
  4439.    ' Set up a graphics viewport with a border.
  4440.    VIEW (5,5)-(100,80),3,1
  4441.    ' Set up a text viewport.
  4442.    VIEW PRINT 12 TO 24
  4443.    ' Print a message on the screen outside the text viewport.
  4444.    LOCATE 25,1 : PRINT "Press any key to stop."
  4445.    Count=0
  4446.  
  4447.    DO
  4448.       ' Draw a circle with a random radius.
  4449.       CIRCLE (50,40),INT((35-4)*RND+5),(Count MOD 4)
  4450.       ' Clear the graphics viewport every 30 times.
  4451.       IF (Count MOD 30)=0 THEN CLS 1
  4452.       PRINT "Hello. ";
  4453.       ' Clear the text viewport every 45 times.
  4454.       IF (Count MOD 45)=0 THEN CLS 2
  4455.       Count=Count+1
  4456.    LOOP UNTIL INKEY$<>""
  4457.  
  4458.  
  4459.  ────────────────────────────────────────────────────────────────────────────
  4460.  COLOR Statement
  4461.  ────────────────────────────────────────────────────────────────────────────
  4462.  
  4463.  ■ Action
  4464.  
  4465.    Selects display colors
  4466.  
  4467.  ■ Syntax
  4468.  
  4469.    COLOR «foreground»«,«background»«,border»»         Screen mode 0
  4470.    COLOR «background»«,palette»                       Screen mode 1
  4471.    COLOR «foreground»«,background»                    Screen modes 7-10
  4472.    COLOR «foreground»                                 Screen modes 12-13
  4473.  
  4474.  ■ Remarks
  4475.  
  4476.    With the COLOR statement, you can set the foreground and background colors
  4477.    for the display. In screen mode 0 a border color can also be selected. In
  4478.    screen mode 1 no foreground color can be selected, but one of two
  4479.    four-color palettes can be selected for use with graphics statements. In
  4480.    screen modes 12-13 only the foreground color can be set.
  4481.  
  4482.    The values of foreground in screen modes 7-10, 12, and 13 are attribute
  4483.    numbers (not color numbers) and display the color assigned to that
  4484.    attribute. See the PALETTE statement for a description of attributes.
  4485.  
  4486.    The COLOR statement does not determine the range of available colors. The
  4487.    combination of adapter, display, and the mode set by the SCREEN statement
  4488.    determine the color range. See the SCREEN statement for more information.
  4489.  
  4490.    The different syntaxes and their effects in different screen modes are
  4491.    described below:
  4492.  
  4493. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  4494.    Screen Mode              Description
  4495.    ──────────────────────────────────────────────────────────────────────────
  4496.    Screen Mode              Description
  4497.    ──────────────────────────────────────────────────────────────────────────
  4498.    0                        Modifies the current default text foreground and
  4499.                             background colors and the screen border. The
  4500.                             foreground color must be an integer expression in
  4501.                             the range 0-31. It determines the "foreground"
  4502.                             color in text mode──the default color of text.
  4503.                             Sixteen colors can be selected with the integers
  4504.                             0-15. You can select a blinking version of a
  4505.                             color by adding 16 to the color number. For
  4506.                             example, a blinking color 7 is equal to 7 + 16,
  4507.                             or 23.
  4508.  
  4509.                             The background color is an integer expression in
  4510.                             the range 0-7 and is the color of the background
  4511.                             for each text character. Blinking background
  4512.                             colors are not supported.
  4513.  
  4514.                             The border color──the color used to draw the
  4515.                             screen border──is an integer expression in the
  4516.                             range 0-15. The IBM Enhanced Graphics Adapter
  4517.    Screen Mode              Description
  4518.    ──────────────────────────────────────────────────────────────────────────
  4519.                            range 0-15. The IBM Enhanced Graphics Adapter
  4520.                             (EGA), the IBM Video Graphics Array adapter
  4521.                             (VGA), and the IBM Multicolor Graphics Array
  4522.                             adapter (MCGA) do not support the border
  4523.                             argument.
  4524.  
  4525.    1                        In mode 1, the COLOR statement has a unique
  4526.                             syntax that includes a palette argument that is
  4527.                             an odd or even integer expression in the range 0
  4528.                             to 255. This argument determines which of two
  4529.                             sets of colors to use when displaying particular
  4530.                             color numbers.
  4531.  
  4532.                             The default colors for the palette parameter are
  4533.                             equivalent to the following PALETTE statements on
  4534.                             a system equipped with an EGA:
  4535.  
  4536.                             COLOR ,0     'Same as the next three
  4537.                                          'PALETTE statements.
  4538.    Screen Mode              Description
  4539.    ──────────────────────────────────────────────────────────────────────────
  4540.                                         'PALETTE statements.
  4541.                             PALETTE 1,2  'Attribute 1 = color 2 (green)
  4542.                             PALETTE 2,4  'Attribute 2 = color 4 (red)
  4543.                             PALETTE 3,6  'Attribute 3 = color 6 (yellow)
  4544.  
  4545.                             COLOR ,1     'Same as the next three
  4546.                                          'PALETTE statements.
  4547.                             PALETTE 1,3  'Attribute 1 = color 3 (cyan)
  4548.                             PALETTE 2,5  'Attribute 2 = color 5 (magenta)
  4549.                             PALETTE 3,7  'Attribute 3 = color 7 (white)
  4550.  
  4551.                             Note that in screen mode 1, a COLOR statement
  4552.                             overrides previous PALETTE statements.
  4553.  
  4554.    2                        An Illegal function call message results if COLOR
  4555.                             is used in this mode.
  4556.  
  4557.    7-10                     In these modes, no border color can be specified.
  4558.                             The graphics background is given by the
  4559.    Screen Mode              Description
  4560.    ──────────────────────────────────────────────────────────────────────────
  4561.                            The graphics background is given by the
  4562.                             background color number, which must be in the
  4563.                             range of valid color numbers for the screen mode.
  4564.                             The foreground color argument is the default
  4565.                             line-drawing color. In screen modes 7 to 10
  4566.                             foreground is an attribute number, while
  4567.                             background is a color number. See the SCREEN
  4568.                             statement for more details.
  4569.  
  4570.    11                       Use the PALETTE statement to set color in screen
  4571.                             mode 11.
  4572.  
  4573.    12, 13                   No background color can be specified in these
  4574.                             modes. The foreground argument is the attribute
  4575.                             used for the foreground graphics color. The
  4576.                             attribute must be in the correct range for the
  4577.                             screen mode. See the SCREEN statement for more
  4578.                             information.
  4579.    ──────────────────────────────────────────────────────────────────────────
  4580.    Screen Mode              Description
  4581.    ──────────────────────────────────────────────────────────────────────────
  4582.   ──────────────────────────────────────────────────────────────────────────
  4583.  
  4584.  
  4585.    Arguments that are outside the valid ranges produce error messages that
  4586.    read Illegal function call.
  4587.  
  4588.    The foreground can be the same color as the background, making displayed
  4589.    characters invisible. The default background is black, or color number 0
  4590.    for all display hardware configurations and all screen modes.
  4591.  
  4592.    In screen modes 12 and 13 you can set the background color by assigning a
  4593.    color to attribute 0 with a PALETTE statement. For example, to make the
  4594.    background color 8224 (a light violet), you would use the following
  4595.    PALETTE statement:
  4596.  
  4597.    PALETTE 0,8224
  4598.  
  4599.    In screen mode 11 you can set both the foreground and background color by
  4600.    assigning a color to attribute 0 with a PALETTE statement.
  4601.  
  4602.    With an EGA, VGA, or MCGA installed, the PALETTE statement gives you
  4603.    flexibility in assigning different display colors to the actual
  4604.    color-number ranges for the foreground, background, and border colors
  4605.    discussed above. See the PALETTE statement reference pages for more
  4606.    details.
  4607.  
  4608.  ■ See Also
  4609.  
  4610.    PAINT, PALETTE, SCREEN
  4611.  
  4612.  ■ Examples
  4613.  
  4614.    The following series of examples show COLOR statements and their effects
  4615.    in the various screen modes:
  4616.  
  4617.    SCREEN 0
  4618.    'foreground=1, background=2, border=3
  4619.    COLOR  1, 2, 3
  4620.  
  4621.    SCREEN 1
  4622.    'background=1, even palette number
  4623.    COLOR  1,0
  4624.    'background=2, odd palette number
  4625.    COLOR  2,1
  4626.  
  4627.  
  4628.  ────────────────────────────────────────────────────────────────────────────
  4629.  COM Statements
  4630.  ────────────────────────────────────────────────────────────────────────────
  4631.  
  4632.  ■ Action
  4633.  
  4634.    Enables, disables, or inhibits event trapping of communications activity
  4635.    on a specified port
  4636.  
  4637.  ■ Syntax
  4638.  
  4639.    COM(n) ON
  4640.    COM(n) OFF
  4641.    COM(n) STOP
  4642.  
  4643.  ■ Remarks
  4644.  
  4645.    The parameter n is the number of the communications port; n can be either
  4646.    1 or 2.
  4647.  
  4648.    The COM ON statement enables communications event trapping. If a character
  4649.    arrives at a communications port after a COM ON statement, then the
  4650.    subroutine specified in the ON COM statement is executed.
  4651.  
  4652.    COM OFF disables communications event trapping. No communications trapping
  4653.    takes place until another COM ON statement is executed. Events occurring
  4654.    while trapping is off are ignored.
  4655.  
  4656.    COM STOP inhibits communications event trapping so no trapping takes place
  4657.    until a COM ON statement is executed. Events occurring while trapping is
  4658.    inhibited are remembered and processed when the next COM ON statement is
  4659.    executed.
  4660.  
  4661.    See Chapter 6, "Error and Event Trapping," in Programming in BASIC for an
  4662.    outline of event trapping.
  4663.  
  4664.  ■ See Also
  4665.  
  4666.    ON event
  4667.  
  4668.  ■ Example
  4669.  
  4670.    See the event-trapping examples in Chapter 6, "Error and Event Trapping,"
  4671.    in Programming in BASIC for an illustration of how to do event trapping.
  4672.  
  4673.  
  4674.  ────────────────────────────────────────────────────────────────────────────
  4675.  COMMAND$ Function
  4676.  ────────────────────────────────────────────────────────────────────────────
  4677.  
  4678.  ■ Action
  4679.  
  4680.    Returns the command line used to invoke the program
  4681.  
  4682.  ■ Syntax
  4683.  
  4684.    COMMAND$
  4685.  
  4686.  ■ Remarks
  4687.  
  4688.    The COMMAND$ function returns the complete command line entered after your
  4689.    BASIC program name, including optional parameters. COMMAND$ removes all
  4690.    leading blanks from the command line and converts all letters to uppercase
  4691.    (capital letters). The COMMAND$ function can be used in stand-alone
  4692.    executable files or, if you are executing from the QuickBASIC environment,
  4693.    by using the /CMD command line option or by selecting Modify COMMAND$ on
  4694.    the Run menu.
  4695.  
  4696.  ■ Example
  4697.  
  4698.    The Comline subprogram in the following example breaks the command line
  4699.    into separate arguments and stores them in an array. Each argument is
  4700.    separated from adjoining arguments by one or more blanks or tabs on the
  4701.    command line.
  4702.  
  4703.    ' Default variable type is integer in this module.
  4704.    DEFINT A-Z
  4705.  
  4706.    ' Declare the Comline subprogram, as well as the number and
  4707.    ' type of its parameters.
  4708.    DECLARE SUB Comline(N, A$(),Max)
  4709.  
  4710.    DIM A$(1 TO 15)
  4711.    ' Get what was typed on the command line.
  4712.    CALL Comline(N,A$(),10)
  4713.    ' Print out each part of the command line.
  4714.    PRINT "Number of arguments = ";N
  4715.    PRINT "Arguments are: "
  4716.    FOR I=1 TO N : PRINT A$(I) : NEXT I
  4717.  
  4718.    ' Subroutine to get command line and split into arguments.
  4719.    ' Parameters:  NumArgs : Number of command line args found.
  4720.    '              Args$() : Array in which to return arguments.
  4721.    '              MaxArgs : Maximum number of arguments array
  4722.    '                        can return.
  4723.  
  4724.    SUB Comline(NumArgs,Args$(),MaxArgs) STATIC
  4725.    CONST TRUE=-1, FALSE=0
  4726.  
  4727.       NumArgs=0 : In=FALSE
  4728.    ' Get the command line using the COMMAND$ function.
  4729.       Cl$=COMMAND$
  4730.       L=LEN(Cl$)
  4731.  
  4732.    ' Go through the command line a character at a time.
  4733.       FOR I=1 TO L
  4734.          C$=MID$(Cl$,I,1)
  4735.        'Test for character being a blank or a tab.
  4736.          IF (C$<>" " AND C$<>CHR$(9)) THEN
  4737.        ' Neither blank nor tab.
  4738.        ' Test to see if you're already
  4739.        ' inside an argument.
  4740.             IF NOT In THEN
  4741.          ' You've found the start of a new argument.
  4742.          ' Test for too many arguments.
  4743.                IF NumArgs=MaxArgs THEN EXIT FOR
  4744.                NumArgs=NumArgs+1
  4745.                In=TRUE
  4746.             END IF
  4747.         ' Add the character to the current argument.
  4748.             Args$(NumArgs)=Args$(NumArgs)+C$
  4749.          ELSE
  4750.       ' Found a blank or a tab.
  4751.       ' Set "Not in an argument" flag to FALSE.
  4752.             In=FALSE
  4753.          END IF
  4754.       NEXT I
  4755.  
  4756.    END SUB
  4757.  
  4758.    The following is a sample command line and output for a stand-alone
  4759.    executable file (assumes program name is arg.exe):
  4760.  
  4761.    arg one  two   three    four     five      six
  4762.  
  4763.  ■ Output
  4764.  
  4765.    Number of arguments =  6
  4766.    Arguments are:
  4767.    ONE
  4768.    TWO
  4769.    THREE
  4770.    FOUR
  4771.    FIVE
  4772.    SIX
  4773.  
  4774.  
  4775.  ────────────────────────────────────────────────────────────────────────────
  4776.  COMMON Statement
  4777.  ────────────────────────────────────────────────────────────────────────────
  4778.  
  4779.  ■ Action
  4780.  
  4781.    Defines global variables for sharing between modules or for chaining to
  4782.    another program
  4783.  
  4784.  ■ Syntax
  4785.  
  4786.    COMMON «SHARED»  «/blockname/» variablelist
  4787.  
  4788.  ■ Remarks
  4789.  
  4790.    The following list describes the parts of the COMMON statement:
  4791.  
  4792. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  4793.    Part                     Description
  4794.    ──────────────────────────────────────────────────────────────────────────
  4795.    SHARED                   An optional attribute indicating that the
  4796.                             variables are to be shared with all SUB or
  4797.                             FUNCTION procedures in the module. SHARED can
  4798.                             eliminate the need for a SHARED statement inside
  4799.                             SUB or FUNCTION procedures.
  4800.  
  4801.    blockname                A valid BASIC identifier (up to 40 characters)
  4802.                             used to identify a group of variables. Use a
  4803.                             blockname to share only specific groups of
  4804.                             variables. When a blockname is used, the COMMON
  4805.                             block is a named COMMON block. When blockname is
  4806.                             omitted, the block is a blank COMMON block. Items
  4807.                             in a named COMMON block are not preserved across
  4808.                             a chain to a new program. See "Using Named
  4809.                             COMMON" and "Using COMMON with Chain," below.
  4810.  
  4811.    Part                     Description
  4812.    ──────────────────────────────────────────────────────────────────────────
  4813. 
  4814.    variablelist             A list of variables to be shared between modules
  4815.                             or chained-to programs. The same variable may not
  4816.                             appear in more than one COMMON statement in a
  4817.                             module.
  4818.    ──────────────────────────────────────────────────────────────────────────
  4819.  
  4820.  
  4821.    A variablelist has the following syntax:
  4822.  
  4823.    variable«( )»«AS type»«, variable«( )»«AS type»»...
  4824.  
  4825.    The following list describes the parts of a variablelist:
  4826.  
  4827.    Argument                 Description
  4828.    ──────────────────────────────────────────────────────────────────────────
  4829.    variable                 Any valid BASIC variable name.
  4830.  
  4831.    AS type                  Declares variable to be of type type. The type
  4832.                             may be INTEGER, LONG, SINGLE, DOUBLE, STRING, or
  4833.                             a user-defined type.
  4834.    ──────────────────────────────────────────────────────────────────────────
  4835.  
  4836.  ────────────────────────────────────────────────────────────────────────────
  4837.  NOTE
  4838.    Older versions of BASIC required the number of dimensions to appear after
  4839.    the name of a dynamic array in a COMMON statement. The number of
  4840.    dimensions is no longer required, although QuickBASIC accepts the older
  4841.    syntax to maintain compatibility with earlier versions.
  4842.  ────────────────────────────────────────────────────────────────────────────
  4843.  
  4844.    A COMMON statement establishes storage for variables in a special area
  4845.    that allows them to be shared between modules or with other programs
  4846.    invoked with a CHAIN statement.
  4847.  
  4848.    Because COMMON statements establish global variables for an entire
  4849.    program, they must appear before any executable statements. All statements
  4850.    are executable, except the following:
  4851.  
  4852.    ■ COMMON
  4853.  
  4854.    ■ CONST
  4855.  
  4856.    ■ DATA
  4857.  
  4858.    ■ DECLARE
  4859.  
  4860.    ■ DEFtype
  4861.  
  4862.    ■ DIM (for static arrays)
  4863.  
  4864.    ■ OPTION BASE
  4865.  
  4866.    ■ REM
  4867.  
  4868.    ■ SHARED
  4869.  
  4870.    ■ STATIC
  4871.  
  4872.    ■ TYPE...END TYPE
  4873.  
  4874.    ■ All metacommands
  4875.  
  4876.    Variables in COMMON blocks are matched by position and type, not by name.
  4877.    Thus, variable order is significant in COMMON statements. In the following
  4878.    fragment, it is the order of the variables in the COMMON statements that
  4879.    links the variables, not the names:
  4880.  
  4881.    ' Main program.
  4882.    COMMON A, D, E
  4883.    A = 5 : D = 8 : E = 10
  4884.    .
  4885.    .
  4886.    .
  4887.  
  4888.    ' Common statement in another module.
  4889.    COMMON A, E, D           'A = 5, E = 8, D = 10
  4890.    .
  4891.    .
  4892.    .
  4893.  
  4894.    Both static and dynamic arrays are placed in COMMON by using the array
  4895.    name followed by parentheses. A static array must be dimensioned with
  4896.    integer-constant subscripts in a DIM statement preceding the COMMON
  4897.    statement. A dynamic array must be dimensioned in a later DIM or REDIM
  4898.    statement. The elements of a dynamic array are not allocated in the COMMON
  4899.    block. Only an array descriptor is placed in common. (See Chapter 2,
  4900.    "Data Types," in this manual and Appendix F, "Metacommands," in
  4901.    Programming in BASIC for more information about static and dynamic
  4902.    arrays.)
  4903.  
  4904.    The size of a common area can be different from that in another module or
  4905.    chained program if a blank COMMON block has been used. When a BASIC
  4906.    program shares COMMON blocks with a routine in the user library, the
  4907.    calling program may not redefine the COMMON block to a larger size.
  4908.  
  4909.    Errors caused by mismatched COMMON statements are subtle and difficult to
  4910.    find. An easy way to avoid this problem is to place COMMON declarations in
  4911.    a single "include" file and use the ¢INCLUDE metacommand in each program.
  4912.    See Appendix F, "Metacommands," in Programming in BASIC for a discussion
  4913.    of ¢INCLUDE.
  4914.  
  4915.    The following program fragment shows how to use the ¢INCLUDE metacommand
  4916.    to share a file containing COMMON statements among programs:
  4917.  
  4918.    'This file is menu.bas.
  4919.    '¢INCLUDE:'COMDEF.BI'
  4920.    .
  4921.    .
  4922.    .
  4923.    CHAIN "PROG1"
  4924.    END
  4925.  
  4926.  
  4927.    'This file is prog1.bas.
  4928.    '¢INCLUDE:'COMDEF.BI'
  4929.    .
  4930.    .
  4931.    .
  4932.    END
  4933.  
  4934.  
  4935.    'This file is comdef.bi.
  4936.    DIM A(100),B$(200)
  4937.    COMMON I,J,K,A()
  4938.    COMMON A$,B$(),X,Y,Z
  4939.    'End comdef.bi.
  4940.  
  4941.    The next three sections discuss using named COMMON blocks, using the
  4942.    SHARED keyword, and using COMMON when chaining programs.
  4943.  
  4944.    USING NAMED COMMON
  4945.  
  4946.    A named COMMON block provides a convenient way to group variables so that
  4947.    different modules have access only to the common variables that they need.
  4948.  
  4949.    The following program, which calculates the volume and density of a
  4950.    rectangular prism, uses named COMMON blocks to share different sets of
  4951.    data with two subprograms. The subprogram VOLUME needs to share only the
  4952.    variables representing the lengths of the sides (in COMMON block SIDES).
  4953.    The subprogram DENSITY also needs variables representing the weight (in
  4954.    COMMON block WEIGHT).
  4955.  
  4956.    'Main program.
  4957.    DIM S(3)
  4958.    COMMON /Sides/ S()
  4959.    COMMON /Weight/ C
  4960.  
  4961.    C=52
  4962.    S(1)=3:S(2)=3:S(3)=6
  4963.    CALL Volume
  4964.    CALL Density
  4965.    END
  4966.  
  4967.    'Subprogram VOLUME in a separate module.
  4968.    DIM S(3)
  4969.    COMMON SHARED /Sides/ S()
  4970.  
  4971.    SUB Volume STATIC
  4972.        Vol=S(1)*S(2)*S(3)
  4973.        PRINT "The volume is "; Vol
  4974.    END SUB
  4975.  
  4976.  
  4977.    'Subprogram DENSITY in a separate module.
  4978.    DIM S(3)
  4979.    COMMON SHARED /Sides/ S()
  4980.    COMMON SHARED /Weight/ W
  4981.  
  4982.    SUB Density STATIC
  4983.        Vol=S(1)*S(2)*S(3)
  4984.        Dens=W/Vol
  4985.        PRINT "The density is "; Dens
  4986.    END SUB
  4987.  
  4988.  ────────────────────────────────────────────────────────────────────────────
  4989.  NOTE
  4990.    Named COMMON blocks are not preserved across chained programs. Use blank
  4991.    COMMON blocks to pass variables to a chained program.
  4992.  ────────────────────────────────────────────────────────────────────────────
  4993.  
  4994.    USING COMMON WITH CHAIN
  4995.  
  4996.    The COMMON statement provides the only way to pass the values of variables
  4997.    directly to a chained program. To pass variables, both programs must
  4998.    contain COMMON statements. Remember that variable order and type are
  4999.    significant, not variable names. The order and type of variables must be
  5000.    the same for all COMMON statements communicating between chaining
  5001.    programs.
  5002.  
  5003.    Although the order and type of variables is critical for making sure the
  5004.    right values are passed, the COMMON blocks do not have to be the same
  5005.    size. If the COMMON block in the chained-to program is smaller than the
  5006.    COMMON block in the chaining program, the extra COMMON variables in the
  5007.    chaining program are ignored. If the size of the COMMON block in the
  5008.    chained-to program is larger, then additional COMMON numeric variables are
  5009.    initialized to zero. Additional string variables are initialized to null
  5010.    strings.
  5011.  
  5012.    Static arrays passed in COMMON by the chaining program must be declared as
  5013.    static in the chained-to program. Similarly, dynamic arrays placed in
  5014.    common by the chaining program must be dynamic in the chained-to program.
  5015.  
  5016.  ────────────────────────────────────────────────────────────────────────────
  5017.  NOTE
  5018.    To use COMMON with CHAIN when you are compiling outside the BASIC
  5019.    environment, you must use the BRUN45.EXE module. This module is used when
  5020.    you compile from the command line without the /O option or when you use
  5021.    the option from the Make EXE dialog box called EXE Requiring BRUN45.EXE.
  5022.  ────────────────────────────────────────────────────────────────────────────
  5023.  
  5024.  ■ See Also
  5025.  
  5026.    CALL (BASIC), CHAIN, FUNCTION, SUB
  5027.  
  5028.  ■ Examples
  5029.  
  5030.    The following example uses a COMMON statement to pass variables between
  5031.    two chained programs. The first program reads in a series of numeric
  5032.    values, stores the values in an array, and then chains to the other
  5033.    program. The second program finds and prints the average of the values.
  5034.  
  5035.    DIM Values(1 TO 50)
  5036.    COMMON Values(), NumValues
  5037.  
  5038.    PRINT "Enter values one per line. Enter END to quit."
  5039.    NumValues=0
  5040.    DO
  5041.       INPUT "-> ",N$
  5042.       IF I>=50 OR UCASE$(N$)="END" THEN EXIT DO
  5043.       NumValues=NumValues+1
  5044.       Values(NumValues)=VAL(N$)
  5045.    LOOP
  5046.  
  5047.    CHAIN "average"
  5048.  
  5049.    The program named average appears as follows (notice that average is an
  5050.    entirely separate program):
  5051.  
  5052.    DIM X(1 TO 50)
  5053.    COMMON X(), N
  5054.  
  5055.    IF N>0 THEN
  5056.       Sum=0
  5057.       FOR I=1 TO N
  5058.          Sum=Sum+X(I)
  5059.       NEXT I
  5060.       PRINT "The average of the values is";Sum/N
  5061.    END IF
  5062.  
  5063.  
  5064.  ────────────────────────────────────────────────────────────────────────────
  5065.  CONST Statement
  5066.  ────────────────────────────────────────────────────────────────────────────
  5067.  
  5068.  ■ Action
  5069.  
  5070.    Declares symbolic constants for use in place of numeric or string values
  5071.  
  5072.  ■ Syntax
  5073.  
  5074.    CONST constantname = expression «,constantname = expression»...
  5075.  
  5076.  ■ Remarks
  5077.  
  5078.    Argument                 Description
  5079.    ──────────────────────────────────────────────────────────────────────────
  5080.    constantname             A name following the same rules as a BASIC
  5081.                             variable name. You may add to the name a
  5082.                             type-declaration character (%, &, !, #, or $) to
  5083.                             indicate its type, but this character is not part
  5084.                             of the name.
  5085.  
  5086.    expression               An expression consisting of literals (such as
  5087.                             1.0), other constants, or any of the arithmetic
  5088.                             and logical operators except exponentiation (^).
  5089.                             You may also use a single literal string such as
  5090.                             "Error on input". You cannot use string
  5091.                             concatenation, variables, user-defined functions,
  5092.                             or intrinsic functions like SIN or CHR$ in
  5093.                             expressions assigned to constants.
  5094.    ──────────────────────────────────────────────────────────────────────────
  5095.  
  5096.    If you use a type-declaration character in the name, you may omit the
  5097.    character when the name is used, as shown in the following example:
  5098.  
  5099.    CONST MAXDIM% = 250
  5100.    .
  5101.    .
  5102.    .
  5103.    DIM AccountNames$(MAXDIM)
  5104.  
  5105.    If you omit the type-declaration character, the constant is given a type
  5106.    based on the expression in the CONST statement. Strings always yield a
  5107.    string constant. With numeric expressions, the expression is evaluated and
  5108.    the constant is given the simplest type that can represent the constant.
  5109.    For example, if the expression gives a result that can be represented as
  5110.    an integer, the constant is given an integer type.
  5111.  
  5112.  ────────────────────────────────────────────────────────────────────────────
  5113.  NOTE
  5114.    Names of constants are not affected by DEFtype statements such as DEFINT.
  5115.    A constant's type is determined either by an explicit type-declaration
  5116.    character or by the type of the expression.
  5117.  ────────────────────────────────────────────────────────────────────────────
  5118.  
  5119.    Constants must be defined before they are referenced. The following
  5120.    example produces an error because the constant ONE is not defined before
  5121.    it is used to define TWO (constants are defined from left to right):
  5122.  
  5123.    CONST TWO = ONE + ONE, ONE = 1
  5124.  
  5125.    Constants declared in a SUB or FUNCTION are local to the SUB or FUNCTION.
  5126.    A constant declared outside a procedure is defined throughout the module.
  5127.    You can use constants anywhere that you would use an expression.
  5128.  
  5129.    A common programming practice is to use a statement like the following
  5130.    (recall that any nonzero value represents "true"):
  5131.  
  5132.    TRUE=-1
  5133.  
  5134.    Constants offer several advantages over using variables for constant
  5135.    values:
  5136.  
  5137.    ■ Constants need to be defined only once for an entire module.
  5138.  
  5139.    ■ Constants cannot be inadvertently changed.
  5140.  
  5141.    ■ In stand-alone programs, using constants produces more efficient code
  5142.      than using variables.
  5143.  
  5144.    ■ Constants make programs easier to modify.
  5145.  
  5146.  ■ Examples
  5147.  
  5148.    The following program uses the CONST statement to declare symbolic
  5149.    constants for the ASCII values of nonprinting characters such as tab and
  5150.    line feed:
  5151.  
  5152.    ' This program counts words, lines, and characters.
  5153.    ' A word is any sequence of nonblank characters.
  5154.    DEFINT a-z
  5155.  
  5156.    CONST BLANK = 32, ENDFILE = 26, CR = 13, LF = 10
  5157.    CONST TABC = 9, YES = -1, NO = 0
  5158.  
  5159.    ' Get the file name from the command line.
  5160.    FileName$=COMMAND$
  5161.    IF FileName$="" THEN
  5162.       INPUT "Enter input file name: ",FileName$
  5163.       IF FileName$="" THEN END
  5164.    END IF
  5165.  
  5166.    OPEN FileName$ FOR INPUT AS #1
  5167.  
  5168.    Words=0
  5169.    Lines=0
  5170.    Characters=0
  5171.  
  5172.    ' Set a flag to indicate you're not looking at a
  5173.    ' word, then get the first character from the file.
  5174.    InaWord=NO
  5175.    DO UNTIL EOF(1)
  5176.       C=ASC(INPUT$(1,#1))
  5177.       Characters=Characters+1
  5178.       IF C=BLANK or C=CR or C=LF or C=TABC THEN
  5179.  
  5180.    ' If the character is a blank, carriage return,
  5181.    ' line feed, or tab, you're not in a word.
  5182.          IF C=CR THEN Lines=Lines+1
  5183.          InaWord=NO
  5184.       ELSEIF InaWord=NO THEN
  5185.  
  5186.    ' The character is a printing character,
  5187.    ' so this is the start of a word.
  5188.    ' Count the word and set the flag.
  5189.          InaWord=YES
  5190.          Words=Words+1
  5191.       END IF
  5192.  
  5193.    LOOP
  5194.    PRINT Characters, Words, Lines
  5195.    END
  5196.  
  5197.    Constants also make programs easier to modify. The following program
  5198.    fragment declares a single constant to dimension a series of arrays. To
  5199.    increase or decrease the size of the arrays, it is necessary to change
  5200.    only the value in the CONST statement.
  5201.  
  5202.    CONST MAXCUSTOMERS = 250
  5203.    .
  5204.    .
  5205.    .
  5206.    DIM  AccountNumber$(MAXCUSTOMERS), Balance(MAXCUSTOMERS)
  5207.    DIM  Contact$(MAXCUSTOMERS), PastDueAmount(MAXCUSTOMERS)
  5208.    .
  5209.    .
  5210.    .
  5211.  
  5212.  ────────────────────────────────────────────────────────────────────────────
  5213.  NOTE
  5214.    Using a variable here, instead of a symbolic constant, makes the arrays
  5215.    dynamic arrays. Using a symbolic constant, as in the previous example,
  5216.    declares these arrays as static arrays. See Chapter 2, "Data Types," in
  5217.    this manual and Appendix F, "Metacommands," in Programming in BASIC for
  5218.    more information about static and dynamic arrays.
  5219.  ────────────────────────────────────────────────────────────────────────────
  5220.  
  5221.  
  5222.  ────────────────────────────────────────────────────────────────────────────
  5223.  COS Function
  5224.  ────────────────────────────────────────────────────────────────────────────
  5225.  
  5226.  ■ Action
  5227.  
  5228.    Returns the cosine of an angle given in radians
  5229.  
  5230.  ■ Syntax
  5231.  
  5232.    COS(numeric-expression)
  5233.  
  5234.  ■ Remarks
  5235.  
  5236.    The expression, numeric-expression, can be any numeric type.
  5237.  
  5238.    By default, the cosine is calculated in single precision. If
  5239.    numeric-expression is a double-precision value, the cosine is calculated
  5240.    in double precision.
  5241.  
  5242.    You can convert an angle measurement from degrees to radians by
  5243.    multiplying the degrees by π/180, where π = 3.141593.
  5244.  
  5245.  ■ See Also
  5246.  
  5247.    ATN, SIN, TAN
  5248.  
  5249.  ■ Example
  5250.  
  5251.    The following program plots the graph of the polar equation r = nq for
  5252.    values of n from 0.1-1.1. This program uses the conversion factors x =
  5253.    cos(q) and y = sin(q) to change polar coordinates to Cartesian x,y
  5254.    coordinates. The figure plotted is sometimes known as the Spiral of
  5255.    Archimedes.
  5256.  
  5257.    CONST PI = 3.141593
  5258.    'Gray background.
  5259.    SCREEN 1 : COLOR 7
  5260.    'Define window large enough for biggest spiral.
  5261.    WINDOW (-4,-6)-(8,2)
  5262.    'Draw line from origin to the right.
  5263.    LINE (0,0)-(2.2*PI,0),1
  5264.    'Draw ten spirals.
  5265.    FOR N = 1.1 TO .1 STEP -.1
  5266.       'Plot starting point.
  5267.       PSET (0,0)
  5268.       FOR Angle = 0 TO 2*PI STEP .04
  5269.          'Polar equation for spiral.
  5270.          R = N * Angle
  5271.          'Convert polar coordinates to Cartesian coordinates.
  5272.          X = R * COS(Angle)
  5273.          Y = R * SIN(Angle)
  5274.          'Draw line from previous point to new point.
  5275.          LINE -(X,Y),1
  5276.       NEXT
  5277.    NEXT
  5278.  
  5279.  
  5280.  ────────────────────────────────────────────────────────────────────────────
  5281.  CSNG Function
  5282.  ────────────────────────────────────────────────────────────────────────────
  5283.  
  5284.  ■ Action
  5285.  
  5286.    Converts a numeric expression to a single-precision value
  5287.  
  5288.  ■ Syntax
  5289.  
  5290.    CSNG(numeric-expression)
  5291.  
  5292.  ■ Remarks
  5293.  
  5294.    The CSNG function has the same effect as assigning the numeric-expression
  5295.    to a single-precision variable.
  5296.  
  5297.    CSNG rounds the value, if necessary, before converting it.
  5298.  
  5299.  ■ See Also
  5300.  
  5301.    CDBL, CINT
  5302.  
  5303.  ■ Example
  5304.  
  5305.    The following example shows how CSNG rounds before converting the value:
  5306.  
  5307.    A#=975.3421115#
  5308.    B#=975.3421555#
  5309.    PRINT A#; CSNG(A#); B#; CSNG(B#)
  5310.  
  5311.  ■ Output
  5312.  
  5313.    975.3421115  975.3421  975.3421555  975.3422
  5314.  
  5315.  
  5316.  ────────────────────────────────────────────────────────────────────────────
  5317.  CSRLIN Function
  5318.  ────────────────────────────────────────────────────────────────────────────
  5319.  
  5320.  ■ Action
  5321.  
  5322.    Returns the current line (row) position of the cursor
  5323.  
  5324.  ■ Syntax
  5325.  
  5326.    CSRLIN
  5327.  
  5328.  ■ Remarks
  5329.  
  5330.    To return the current column position, use the POS function.
  5331.  
  5332.  ■ See Also
  5333.  
  5334.    LOCATE, POS
  5335.  
  5336.  ■ Example
  5337.  
  5338.    The following program uses a subprogram that prints a message on the
  5339.    screen without disturbing the current cursor position:
  5340.  
  5341.    ' Move cursor to center of screen, then print message.
  5342.    ' Cursor returned to center of screen.
  5343.       LOCATE 12,40
  5344.       CALL MsgNoMove("A message not to be missed.",9,35)
  5345.       INPUT "Enter anything to end: ",A$
  5346.  
  5347.    ' Print a message without disturbing current
  5348.    ' cursor position.
  5349.    SUB MsgNoMove (Msg$,Row%,Col%) STATIC
  5350.  
  5351.       ' Save the current line.
  5352.       CurRow%=CSRLIN
  5353.       ' Save the current column.
  5354.       CurCol%=POS(0)
  5355.       ' Print the message at the given position.
  5356.       LOCATE Row%,Col% : PRINT Msg$;
  5357.       ' Move the cursor back to original position.
  5358.       LOCATE CurRow%, CurCol%
  5359.  
  5360.    END SUB
  5361.  
  5362.  
  5363.  ────────────────────────────────────────────────────────────────────────────
  5364.  CVSMBF, CVDMBF Functions
  5365.  ────────────────────────────────────────────────────────────────────────────
  5366.  
  5367.  ■ Action
  5368.  
  5369.    Converts strings containing Microsoft Binary format numbers to IEEE-format
  5370.    numbers
  5371.  
  5372.  ■ Syntax
  5373.  
  5374.    CVSMBF (4-byte-string)
  5375.    CVDMBF (8-byte-string)
  5376.  
  5377.  ■ Remarks
  5378.  
  5379.    The CVSMBF and CVDMBF functions allow you to read old random-access files
  5380.    containing real numbers stored as strings in Microsoft Binary format.
  5381.    These functions convert the string read from the old file to an
  5382.    IEEE-format number:
  5383.  
  5384.    Function                 Description
  5385.    ──────────────────────────────────────────────────────────────────────────
  5386.    CVSMBF                   Converts 4-byte-string containing a Microsoft
  5387.                             Binary format number to a single-precision
  5388.                             IEEE-format number.
  5389.  
  5390.    CVDMBF                   Converts 8-byte-string containing a Microsoft
  5391.                             Binary format number to a double-precision
  5392.                             IEEE-format number.
  5393.    ──────────────────────────────────────────────────────────────────────────
  5394.  
  5395.    The example below shows you how to read data from an old file by using
  5396.    CVSMBF and user-defined types for records. See Appendix B, "Differences
  5397.    from Previous Versions of QuickBASIC," in Programming in BASIC for more
  5398.    information about converting old data files.
  5399.  
  5400.  ■ See Also
  5401.  
  5402.    FIELD; MKSMBF$, MKDMBF$
  5403.  
  5404.  ■ Example
  5405.  
  5406.    The following program reads records from a random-access file containing
  5407.    Microsoft Binary format real numbers stored as strings. Each record
  5408.    contains a student's name and a test score.
  5409.  
  5410.    ' Define a user type for the data records.
  5411.    TYPE StudentRec
  5412.       NameField AS STRING*20
  5413.       Score AS STRING*4
  5414.    END TYPE
  5415.  
  5416.    ' Define a variable of the user type.
  5417.    DIM Rec AS StudentRec
  5418.  
  5419.    ' Open the file.
  5420.    OPEN "TESTDAT.DAT" FOR RANDOM AS #1 LEN=LEN(Rec)
  5421.  
  5422.    Max=LOF(1)/LEN(Rec)
  5423.  
  5424.    ' Read and print all of the records.
  5425.    FOR I=1 TO Max
  5426.       ' Read a record into the user-type variable Rec.
  5427.       GET #1,I,Rec
  5428.       ' Convert the score from a string containing a Microsoft
  5429.       ' Binary format number to an IEEE-format number.
  5430.       ScoreOut=CVSMBF(Rec.Score)
  5431.       ' Display the name and score.
  5432.       PRINT Rec.NameField,ScoreOut
  5433.    NEXT I
  5434.  
  5435.    CLOSE #1
  5436.  
  5437.  
  5438.  ────────────────────────────────────────────────────────────────────────────
  5439.  CVI, CVS, CVL, CVD Functions
  5440.  ────────────────────────────────────────────────────────────────────────────
  5441.  
  5442.  ■ Action
  5443.  
  5444.    Converts strings containing numeric values to numbers
  5445.  
  5446.  ■ Syntax
  5447.  
  5448.    CVI(2-byte-string)
  5449.    CVS(4-byte-string)
  5450.    CVL(4-byte-string)
  5451.    CVD(8-byte-string)
  5452.  
  5453.  ■ Remarks
  5454.  
  5455.    CVI, CVS, CVL, and CVD are used with a FIELD statement to read real
  5456.    numbers from a random-access file. The functions take strings defined in
  5457.    the FIELD statement and convert them to a value of the corresponding
  5458.    numeric type. The functions are the inverse of MKI$, MKS$, MKL$, and MKD$:
  5459.  
  5460.    Function                 Description
  5461.    ──────────────────────────────────────────────────────────────────────────
  5462.    CVI                      Converts 2-byte-string created with MKI$ back to
  5463.                             an integer.
  5464.  
  5465.    CVS                      Converts 4-byte-string created with MKS$ back to
  5466.                             a single-precision number.
  5467.  
  5468.    CVL                      Converts 4-byte-string created with MKL$ back to
  5469.                             a long integer.
  5470.  
  5471.    CVD                      Converts 8-byte-string created with MKD$ back to
  5472.                             a double-precision number.
  5473.    ──────────────────────────────────────────────────────────────────────────
  5474.  
  5475.  ────────────────────────────────────────────────────────────────────────────
  5476.  NOTE
  5477.    The new BASIC record variables provide a more efficient and convenient way
  5478.    of reading and writing random-access files. See Chapter 3, "File and
  5479.    Device I/O," in Programming in BASIC for a complete example.
  5480.  ────────────────────────────────────────────────────────────────────────────
  5481.  
  5482.  ■ See Also
  5483.  
  5484.    FIELD; LSET; MKD$, MKI$, MKL$, MKS$
  5485.  
  5486.  ■ Example
  5487.  
  5488.    The following program illustrates the use of MKS$ and CVS:
  5489.  
  5490.    OPEN "ACCOUNT.INF" FOR RANDOM AS #2 LEN = 29
  5491.    FIELD #2, 25 AS Name$, 4 AS Check$
  5492.  
  5493.    Format$ = "$$#####.##"
  5494.    DO
  5495.       PRINT
  5496.       DO
  5497.          INPUT "Enter account # to update: ",Rec%
  5498.          GET #2, Rec%   'Get the record
  5499.          PRINT "This is the account for "; Name$
  5500.          INPUT "Is this the account you wanted"; R$
  5501.       LOOP WHILE UCASE$(MID$(R$,1,1)) <> "Y"
  5502.  
  5503.       'Convert string to single-precision number.
  5504.       Checkamt!  = CVS(Check$)
  5505.       PRINT
  5506.       PRINT "The opening balance for this account is";
  5507.       PRINT USING Format$; Checkamt!
  5508.       PRINT "Enter the checks and cash withdrawals for this"
  5509.       PRINT "account below. Enter 0 when finished."
  5510.  
  5511.       DO
  5512.          INPUT Checkout! : Checkamt! = Checkamt! - Checkout!
  5513.       LOOP UNTIL Checkout! = 0
  5514.  
  5515.       PRINT
  5516.       PRINT "Enter the deposits for this account below."
  5517.       PRINT "Enter 0 when finished."
  5518.  
  5519.       DO
  5520.          INPUT Checkin! : Checkamt! = Checkamt! + Checkin!
  5521.       LOOP UNTIL Checkin! = 0
  5522.  
  5523.       PRINT
  5524.       PRINT "The closing balance for this account is";
  5525.       PRINT USING Format$; Checkamt!
  5526.       'Convert single-precision number to string.
  5527.       LSET Check$ = MKS$(Checkamt!)
  5528.       PUT #2, Rec%   'Store the record.
  5529.       INPUT "Update another"; R$
  5530.  
  5531.    LOOP UNTIL UCASE$(MID$(R$,1,1)) <> "Y"
  5532.    CLOSE #2
  5533.    END
  5534.  
  5535.  
  5536.  ────────────────────────────────────────────────────────────────────────────
  5537.  DATA Statement
  5538.  ────────────────────────────────────────────────────────────────────────────
  5539.  
  5540.  ■ Action
  5541.  
  5542.    Stores the numeric and string constants used by a program's READ
  5543.    statements
  5544.  
  5545.  ■ Syntax
  5546.  
  5547.    DATA constant1 «,constant2»...
  5548.  
  5549.  ■ Remarks
  5550.  
  5551.    The constant1, constant2, and so on in a DATA statement can be any valid
  5552.    numeric or string constant.
  5553.  
  5554.    Names of symbolic constants (defined in a CONST statement) appearing in
  5555.    DATA statements are interpreted as strings, rather than names of
  5556.    constants. For example, in the following program fragment the second data
  5557.    item is a string, "PI", and not the value 3.141593:
  5558.  
  5559.    CONST PI=3.141593
  5560.    .
  5561.    .
  5562.    .
  5563.    DATA 2.20, PI,45,7
  5564.    .
  5565.    .
  5566.    .
  5567.  
  5568.    A DATA statement may contain as many constants as will fit on a line. The
  5569.    constants are separated by commas. You may use any number of DATA
  5570.    statements.
  5571.  
  5572.  ────────────────────────────────────────────────────────────────────────────
  5573.  NOTE
  5574.    String constants in DATA statements require double quotes only if they
  5575.    contain commas, colons, or significant leading or trailing spaces.
  5576.  ────────────────────────────────────────────────────────────────────────────
  5577.  
  5578.    Null data items (indicated by a missing value) can appear in a data list:
  5579.  
  5580.    DATA 1,2,,4,5
  5581.  
  5582.    When a null item is read into a numeric variable, the variable has the
  5583.    value 0. When a null item is read into a string variable, the variable has
  5584.    the null string value ("").
  5585.  
  5586.    When working in the QuickBASIC environment, DATA statements can only be
  5587.    entered in the module-level code. QuickBASIC moves all DATA statements not
  5588.    in the module-level code to the module-level code when it reads a source
  5589.    file. READ statements using the DATA statements can appear anywhere in the
  5590.    program.
  5591.  
  5592.    DATA statements are used in the order in which they appear in the source
  5593.    file. You may think of the items in several DATA statements as one
  5594.    continuous list of items, regardless of how many items are in a statement
  5595.    or where the statement appears in the program.
  5596.  
  5597.    You may reread DATA statements by using the RESTORE statement.
  5598.  
  5599.  ■ See Also
  5600.  
  5601.    READ RESTORE
  5602.  
  5603.  ■ Examples
  5604.  
  5605.    The following example displays the current date by converting the date
  5606.    returned by the DATE$ function:
  5607.  
  5608.    ' Get the date.
  5609.    C$ = DATE$
  5610.    ' Use VAL to split the month off the string returned by
  5611.    ' DATE$.
  5612.    FOR I% = 1 TO VAL(C$)
  5613.        READ Month$
  5614.    NEXT
  5615.    DATA January, February, March, April, May, June, July
  5616.    DATA August, September, October, November, December
  5617.  
  5618.    ' Get the day.
  5619.    Day$ = MID$(C$,4,2)
  5620.    IF LEFT$(Day$,1) = "0" THEN Day$ = RIGHT$(Day$,1)
  5621.    ' Get the year.
  5622.    Year$ = RIGHT$(C$,4)
  5623.  
  5624.    PRINT "Today is " Month$ " " Day$ ", " Year$
  5625.  
  5626.  ■ Output
  5627.  
  5628.    Today is September 21, 1988
  5629.  
  5630.    The following example shows how null data items are handled:
  5631.  
  5632.    DATA abc,,def
  5633.    DATA 1,,2
  5634.    READ A$, B$, C$         'B$ = ""
  5635.    PRINT A$, B$, C$
  5636.    PRINT
  5637.    READ A, B, C            'B = 0
  5638.    PRINT A, B, C
  5639.  
  5640.    OUTPUT
  5641.  
  5642.    abc                    def
  5643.     1            0         2
  5644.  
  5645.  
  5646.  ────────────────────────────────────────────────────────────────────────────
  5647.  DATE$ Function
  5648.  ────────────────────────────────────────────────────────────────────────────
  5649.  
  5650.  ■ Action
  5651.  
  5652.    Returns a string containing the current date
  5653.  
  5654.  ■ Syntax
  5655.  
  5656.    DATE$
  5657.  
  5658.  ■ Remarks
  5659.  
  5660.    The DATE$ function returns a ten-character string in the form mm-dd-yyyy,
  5661.    where mm is the month (01-12), dd is the day (01-31), and yyyy is the year
  5662.    (1980-2099).
  5663.  
  5664.  ■ See Also
  5665.  
  5666.    DATE$ Statement
  5667.  
  5668.  ■ Example
  5669.  
  5670.    Note that the DATE$ function in the following example prints a zero in
  5671.    front of the month:
  5672.  
  5673.    PRINT DATE$
  5674.  
  5675.  ■ Output
  5676.  
  5677.    09-21-88
  5678.  
  5679.  
  5680.  ────────────────────────────────────────────────────────────────────────────
  5681.  DATE$ Statement
  5682.  ────────────────────────────────────────────────────────────────────────────
  5683.  
  5684.  ■ Action
  5685.  
  5686.    Sets the current date
  5687.  
  5688.  ■ Syntax
  5689.  
  5690.    DATE$ = stringexpression
  5691.  
  5692.  ■ Remarks
  5693.  
  5694.    The DATE$ statement is the complement of the DATE$ function.
  5695.  
  5696.    The stringexpression must have one of the following forms, where mm
  5697.    (01-12) and dd (01-31) are the month and day, and yy and yyyy (1980-2099)
  5698.    are the year:
  5699.  
  5700.    mm-dd-yy
  5701.    mm-dd-yyyy
  5702.    mm/dd/yy
  5703.    mm/dd/yyyy
  5704.  
  5705.  ■ Example
  5706.  
  5707.    The following program sets the current date from an input numeric date:
  5708.  
  5709.    PRINT "Enter the date below (default year is 1989)."
  5710.    INPUT "    Month:   ",Month$
  5711.    INPUT "    Date:    ",Day$
  5712.    INPUT "    Year:    ",Year$
  5713.    IF Year$ = "" THEN Year$ = "89"
  5714.    DATE$ = Month$ + "/" + Day$ + "/" + Year$
  5715.  
  5716.  
  5717.  ────────────────────────────────────────────────────────────────────────────
  5718.  DECLARE Statement (BASIC Procedures)
  5719.  ────────────────────────────────────────────────────────────────────────────
  5720.  
  5721.  ■ Action
  5722.  
  5723.    Declares references to BASIC procedures and invokes argument type checking
  5724.  
  5725.  ■ Syntax
  5726.  
  5727.    DECLARE {FUNCTION | SUB } name «(«parameterlist»)»
  5728.  
  5729.  ■ Remarks
  5730.  
  5731.    The DECLARE statement uses the following arguments:
  5732.  
  5733.    Argument                 Description
  5734.    ──────────────────────────────────────────────────────────────────────────
  5735.    name                     The procedure's name. The name is limited to 40
  5736.                             characters. FUNCTION names can end in one of the
  5737.                             type-declaration characters (%, &, !, #, or $) to
  5738.                             indicate the type of value returned.
  5739.  
  5740.    parameterlist            A list of parameters indicating the number and
  5741.                             type of arguments used when calling the
  5742.                             procedure. Syntax is shown below. Only the number
  5743.                             and the type of the arguments are significant.
  5744.    ──────────────────────────────────────────────────────────────────────────
  5745.  
  5746.    For calls within BASIC, the DECLARE statement is required only if you call
  5747.    SUB procedures without the CALL keyword, or if you invoke a FUNCTION
  5748.    defined in another module. See Chapter 2, "SUB and FUNCTION Procedures,"
  5749.    in Programming in BASIC, for more information about invoking subprograms
  5750.    without CALL.
  5751.  
  5752.    A DECLARE statement also causes the compiler to check the number and type
  5753.    of arguments used to invoke the procedure. QuickBASIC automatically
  5754.    generates DECLARE statements when you save your program while you are
  5755.    working in the environment. The DECLARE statement can appear only in
  5756.    module-level code (not in a SUB or FUNCTION) and affects the entire
  5757.    module.
  5758.  
  5759.    The parameterlist serves as a prototype for checking the number and type
  5760.    of the arguments in SUB and FUNCTION calls. It has the following syntax:
  5761.  
  5762.    variable«AS type» «,variable«AS type»»...
  5763.  
  5764.    A variable is any valid BASIC variable name. If the variable is an array,
  5765.    it may be followed by the number of dimensions in parentheses:
  5766.  
  5767.    DECLARE SUB DisplayText (A(2) AS STRING)
  5768.    DIM Text$(100,5)
  5769.    .
  5770.    .
  5771.    .
  5772.    CALL DisplayText(Text$())
  5773.  
  5774.    The number of dimensions is optional.
  5775.  
  5776.    The type is either INTEGER, LONG, SINGLE, DOUBLE, STRING, or a
  5777.    user-defined type. Again, only the number and types of arguments are
  5778.    significant.
  5779.  
  5780.  ────────────────────────────────────────────────────────────────────────────
  5781.  NOTE
  5782.    You cannot have fixed-length strings in DECLARE statements because only
  5783.    variable-length strings can be passed to SUB and FUNCTION procedures.
  5784.    Fixed-length strings can appear in an argument list but are converted to
  5785.    variable-length strings before being passed.
  5786.  ────────────────────────────────────────────────────────────────────────────
  5787.  
  5788.    A variable's type can also be indicated by including an explicit type
  5789.    character (%, &, !, #, or $) or by relying on the default type.
  5790.  
  5791.    The form of the parameter list determines whether or not argument checking
  5792.    is done, as shown in the following list:
  5793.  
  5794.    Declaration                          Meaning
  5795.    ──────────────────────────────────────────────────────────────────────────
  5796.    DECLARE SUB First                    You may only omit the parentheses if
  5797.                                         the SUB or FUNCTION is separately
  5798.                                         compiled. No argument checking is
  5799.                                         done.
  5800.  
  5801.    DECLARE SUB First ()                 First has no parameters. Arguments in
  5802.                                         a CALL to First are flagged as an
  5803.                                         error. An empty parameter list
  5804.                                         indicates that the SUB or FUNCTION
  5805.                                         has no parameters.
  5806.  
  5807.    DECLARE SUB First (X AS LONG)        First has one long-integer parameter.
  5808.                                         The number and type of the arguments
  5809.                                         in each CALL or invocation are
  5810.                                         checked when the parameter list
  5811.                                         appears in the DECLARE.
  5812.    ──────────────────────────────────────────────────────────────────────────
  5813.  
  5814.  ■ See Also
  5815.  
  5816.    CALL, CALLS (Non-BASIC); FUNCTION; SUB
  5817.  
  5818.  ■ Example
  5819.  
  5820.    In the following example, the DECLARE statement allows Sort to be invoked
  5821.    without the CALL keyword:
  5822.  
  5823.    ' Generate 20 random numbers, store them in an array, and sort.
  5824.    ' The sort subprogram is called without the CALL keyword.
  5825.    DECLARE SUB Sort(A(1) AS SINGLE, N AS INTEGER)
  5826.    DIM Array1(1 TO 20)
  5827.  
  5828.    ' Generate 20 random numbers.
  5829.    RANDOMIZE TIMER
  5830.    FOR I=1 TO 20
  5831.       Array1(I)=RND
  5832.    NEXT I
  5833.  
  5834.    ' Sort the array and call Sort without the CALL keyword.
  5835.    ' Notice the absence of parentheses around the arguments in
  5836.    ' the call to Sort.
  5837.    Sort Array1(), 20%
  5838.  
  5839.    ' Print the sorted array.
  5840.    FOR I=1 TO 20
  5841.       PRINT Array1(I)
  5842.    NEXT I
  5843.    END
  5844.  
  5845.    ' Sort subroutine.
  5846.    SUB Sort(A(1), N%) STATIC
  5847.  
  5848.       FOR I= 1 TO N%-1
  5849.          FOR J=I+1 TO N%
  5850.             IF A(I)>A(J) THEN SWAP A(I), A(J)
  5851.          NEXT J
  5852.       NEXT I
  5853.  
  5854.    END SUB
  5855.  
  5856.  
  5857.  ────────────────────────────────────────────────────────────────────────────
  5858.  DECLARE Statement (Non-BASIC Procedures)
  5859.  ────────────────────────────────────────────────────────────────────────────
  5860.  
  5861.  ■ Action
  5862.  
  5863.    Declares calling sequences for external procedures written in other
  5864.    languages
  5865.  
  5866.  ■ Syntax 1
  5867.  
  5868.    DECLARE FUNCTION name «CDECL» «ALIAS "aliasname"»«(«parameterlist»)»
  5869.  
  5870.  ■ Syntax 2
  5871.  
  5872.    DECLARE SUB name «CDECL» «ALIAS "aliasname"»«(«parameterlist»)»
  5873.  
  5874.  ■ Remarks
  5875.  
  5876.    The following list describes the parts of the DECLARE statement:
  5877.  
  5878. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  5879.    Part                     Description
  5880.    ──────────────────────────────────────────────────────────────────────────
  5881.    FUNCTION                 Indicates that the external procedure returns a
  5882.    Part                     Description
  5883.    ──────────────────────────────────────────────────────────────────────────
  5884.    FUNCTION                 Indicates that the external procedure returns a
  5885.                             value and can be used in an expression.
  5886.  
  5887.    SUB                      Indicates that the external procedure is invoked
  5888.                             in the same way as a BASIC SUB.
  5889.  
  5890.    name                     The name used in the BASIC program to invoke the
  5891.                             procedure. Names may have up to 40 characters.
  5892.                             FUNCTION names can include an explicit type
  5893.                             character (%, &, !, #, or $) indicating the type
  5894.                             of value the FUNCTION returns.
  5895.  
  5896.    CDECL                    Indicates that the procedure uses the C-language
  5897.                             argument order. CDECL passes the arguments from
  5898.                             right to left, rather than using the BASIC
  5899.                             convention of left to right.
  5900.  
  5901.                             CDECL also affects the name used in searches of
  5902.                             object files and libraries. If there is no ALIAS
  5903.    Part                     Description
  5904.    ──────────────────────────────────────────────────────────────────────────
  5905.                            object files and libraries. If there is no ALIAS
  5906.                             in the DECLARE, the name of the procedure (name)
  5907.                             is converted to lowercase, the type-declaration
  5908.                             character is removed, and an underscore is added
  5909.                             to the beginning. This becomes the name used when
  5910.                             searching libraries and external files. If CDECL
  5911.                             is used with an ALIAS, the aliasname is used.
  5912.  
  5913.    ALIAS                    Indicates that the procedure has another name in
  5914.                             the .OBJ or library file.
  5915.  
  5916.    aliasname                The name the procedure has in the file or
  5917.                             library.
  5918.    ──────────────────────────────────────────────────────────────────────────
  5919.  
  5920.  
  5921.    A parameterlist has the following syntax:
  5922.  
  5923.    «{BYVAL|SEG}» variable «AS type» «,«{BYVAL|SEG}» variable «AS type»»...
  5924.  
  5925.    The following list describes the parts of a parameterlist:
  5926.  
  5927. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  5928.    Part                     Description
  5929.    ──────────────────────────────────────────────────────────────────────────
  5930.    BYVAL                    BYVAL indicates that the parameter is passed by
  5931.                             value, rather than by reference. Reference is the
  5932.                             default. BYVAL can be used only with INTEGER,
  5933.                             LONG, SINGLE, and DOUBLE parameters.
  5934.  
  5935.                             When BYVAL appears in front of a parameter, the
  5936.                             actual argument is converted to the type
  5937.                             indicated in the DECLARE statement before being
  5938.                             passed.
  5939.  
  5940.    SEG                      Indicates the parameter is passed as a segmented
  5941.                             address (far pointer).
  5942.  
  5943.    variable                 A valid BASIC variable name. Only the variable's
  5944.                             type is significant. If the variable is an array
  5945.    Part                     Description
  5946.    ──────────────────────────────────────────────────────────────────────────
  5947.                            type is significant. If the variable is an array
  5948.                             it may be followed by the number of dimensions in
  5949.                             parentheses (to maintain compatibility with older
  5950.                             versions of BASIC):
  5951.  
  5952.                             DECLARE SUB EigenValue (A(2) AS DOUBLE)
  5953.  
  5954.                             The number of dimensions is optional.
  5955.  
  5956.    AS type                  Indicates the variable's type. The type element
  5957.                             may be either INTEGER, LONG, SINGLE, DOUBLE,
  5958.                             STRING, ANY, or a user type. You can also
  5959.                             indicate the variable's type by including an
  5960.                             explicit type character (%, &, !, #, or $) in the
  5961.                             variable name or by relying on the default type.
  5962.  
  5963.                             When declaring external procedures written in
  5964.                             other languages, you can use the ANY keyword in
  5965.                             the AS clause. ANY overrides type checking for
  5966.    Part                     Description
  5967.    ──────────────────────────────────────────────────────────────────────────
  5968.                            the AS clause. ANY overrides type checking for
  5969.                             that argument. You cannot use ANY with arguments
  5970.                             passed by value.
  5971.    ──────────────────────────────────────────────────────────────────────────
  5972.  
  5973.  
  5974.  ────────────────────────────────────────────────────────────────────────────
  5975.  NOTE
  5976.    When neither BYVAL nor SEG is used, arguments are passed as near addresses
  5977.    (offsets).
  5978.  ────────────────────────────────────────────────────────────────────────────
  5979.  
  5980.    This form of the DECLARE statement lets you reference procedures written
  5981.    in other languages. The DECLARE statement also causes the compiler to
  5982.    check the number and type of arguments used to invoke the procedure. A
  5983.    DECLARE statement can appear only in module-level code and affects the
  5984.    entire source file. The form of the parameter list determines whether or
  5985.    not argument type checking is done:
  5986.  
  5987.    Declaration                          Meaning
  5988.    ──────────────────────────────────────────────────────────────────────────
  5989.    DECLARE SUB First CDECL              No argument checking is done when
  5990.                                         there is no parameter list.
  5991.  
  5992.    DECLARE SUB First CDECL ()           First has no parameters. Arguments in
  5993.                                         a CALL to First are flagged as an
  5994.                                         error. Empty parentheses indicate
  5995.                                         that the SUB or FUNCTION has no
  5996.                                         parameters.
  5997.  
  5998.    DECLARE SUB First CDECL (X AS LONG)  First takes one long integer
  5999.                                         argument. When a parameter list
  6000.                                         appears, the number and type of the
  6001.                                         arguments are checked in each
  6002.                                         invocation.
  6003.    ──────────────────────────────────────────────────────────────────────────
  6004.  
  6005.    A procedure that appears in a DECLARE statement can be invoked without the
  6006.    CALL keyword. See the entry for DECLARE (BASIC) for more information.
  6007.  
  6008.  ────────────────────────────────────────────────────────────────────────────
  6009.  NOTE
  6010.    You cannot have fixed-length strings in DECLARE statements because only
  6011.    variable-length strings can be passed to SUB and FUNCTION procedures.
  6012.    Fixed-length strings can appear in an argument list but are converted to
  6013.    variable-length strings before being passed.
  6014.  ────────────────────────────────────────────────────────────────────────────
  6015.  
  6016.    Be careful when using the SEG keyword to pass arrays because BASIC may
  6017.    move variables in memory before the called routine begins execution.
  6018.    Anything in a CALL statement's argument list that causes memory movement
  6019.    may create problems. You can safely pass variables using SEG if the CALL
  6020.    statement's argument list contains only simple variables, arithmetic
  6021.    expressions, or arrays indexed without the use of intrinsic or
  6022.    user-defined functions.
  6023.  
  6024.    See Section 2.3.3, "Variable Storage Allocation," for a list of things
  6025.    that cause variable movement and for information about when to use near or
  6026.    far addresses for variables.
  6027.  
  6028.  ■ See Also
  6029.  
  6030.    CALL, CALLS (Non-BASIC); DECLARE (BASIC)
  6031.  
  6032.  ■ Example
  6033.  
  6034.    The following example shows a BASIC program that calls a short C function.
  6035.    The C program would be separately compiled and stored in a Quick library
  6036.    or explicitly linked to form the .EXE file.
  6037.  
  6038.    DEFINT a-z
  6039.  
  6040.    ' The function addone uses C argument passing and takes
  6041.    ' a single integer argument passed by value.
  6042.    DECLARE FUNCTION addone CDECL (BYVAL n AS INTEGER)
  6043.  
  6044.    INPUT x
  6045.    y=addone(x)
  6046.    PRINT "x and y are ";x;y
  6047.  
  6048.    END
  6049.  
  6050.    /* C function addone. Returns one more than the value of its
  6051.         integer argument. */
  6052.    int far addone(n)
  6053.    int n;
  6054.    {
  6055.       return(++n);
  6056.    }
  6057.  
  6058.  
  6059.  ────────────────────────────────────────────────────────────────────────────
  6060.  DEF FN Statement
  6061.  ────────────────────────────────────────────────────────────────────────────
  6062.  
  6063.  ■ Action
  6064.  
  6065.    Defines and names a function
  6066.  
  6067.  ■ Syntax 1
  6068.  
  6069.    DEF FNname«(parameterlist)» = expression
  6070.  
  6071.  ■ Syntax 2
  6072.  
  6073.    DEF FNname«(parameterlist)»
  6074.    .
  6075.    .
  6076.    .
  6077.    FNname = expression
  6078.    .
  6079.    .
  6080.    .
  6081.    END DEF
  6082.  
  6083.  ■ Remarks
  6084.  
  6085.    The DEF FN statement takes the following arguments:
  6086.  
  6087. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  6088.    Argument                 Description
  6089.    ──────────────────────────────────────────────────────────────────────────
  6090.    name                     A legal variable name, up to 40 characters long.
  6091.                             This name, combined with FN, is the name of the
  6092.    Argument                 Description
  6093.    ──────────────────────────────────────────────────────────────────────────
  6094.                            This name, combined with FN, is the name of the
  6095.                             function. The name can include an explicit
  6096.                             type-declaration character to indicate the type
  6097.                             of value returned. Names that are the same except
  6098.                             for the type-declaration character are distinct
  6099.                             names. For example, the following are names of
  6100.                             three different DEF FN functions:
  6101.  
  6102.                             FNString$
  6103.  
  6104.                             FNString%
  6105.  
  6106.                             FNString#
  6107.  
  6108.                             To return a value from a DEF FN function, assign
  6109.                             the value to the full function name:
  6110.  
  6111.                             FNString$ = "No answer."
  6112.  
  6113.    Argument                 Description
  6114.    ──────────────────────────────────────────────────────────────────────────
  6115. 
  6116.    parameterlist            A list of variable names, separated by commas.
  6117.                             The syntax is explained below. When the function
  6118.                             is called, BASIC assigns the value of each
  6119.                             argument to its corresponding parameter. Function
  6120.                             arguments are passed by value. DEF FN functions
  6121.                             do not accept arrays, records, or fixed-length
  6122.                             strings as arguments.
  6123.  
  6124.    expression               In both syntaxes, expression is evaluated and the
  6125.                             result is the function's value. In Syntax 1,
  6126.                             expression is the entire body of the function and
  6127.                             is limited to one logical line.
  6128.  
  6129.                             When no expression is assigned to the name, the
  6130.                             default return values are zero for a numeric DEF
  6131.                             FN function, and the null string ("") for a
  6132.                             string DEF FN function.
  6133.    ──────────────────────────────────────────────────────────────────────────
  6134.    Argument                 Description
  6135.    ──────────────────────────────────────────────────────────────────────────
  6136.   ──────────────────────────────────────────────────────────────────────────
  6137.  
  6138.  
  6139.    A parameterlist has the following syntax:
  6140.  
  6141.    variable «AS type» «, variable «AS type»»...
  6142.  
  6143.    A variable is any valid BASIC variable name. The type is INTEGER, LONG,
  6144.    SINGLE, DOUBLE, or STRING. You may also indicate a variable's type by
  6145.    including a type-declaration character (%, &, !, #, or $) in the name.
  6146.  
  6147.  ────────────────────────────────────────────────────────────────────────────
  6148.  NOTE
  6149.    The FUNCTION procedure offers greater flexibility and control than the DEF
  6150.    FN function. See the entry for FUNCTION and Chapter 2, "SUB and FUNCTION
  6151.    Procedures," in Programming in BASIC for more information.
  6152.  ────────────────────────────────────────────────────────────────────────────
  6153.  
  6154.    You must define a DEF FN function with a DEF FN statement before the
  6155.    function is used. Calling a DEF FN function before it is defined produces
  6156.    an error message that reads Function not defined. DEF FN function
  6157.    definitions cannot appear inside other DEF FN definitions. In addition,
  6158.    DEF FN functions cannot be recursive.
  6159.  
  6160.    You must use the EXIT DEF statement to leave a multiline DEF FN early. DEF
  6161.    FN functions can only be used in the module in which they are defined.
  6162.    They cannot be referenced from other modules.
  6163.  
  6164.    A DEF FN function may share variables with the module-level code.
  6165.    Variables not in the parameterlist are global──their values are shared
  6166.    with the calling program. To keep a variable value local to a function
  6167.    definition, declare it in a STATIC statement. See Chapter 2, "Data
  6168.    Types," for a discussion of local and global variables.
  6169.  
  6170.    DEF FN can return either numeric or string values. DEF FN returns a string
  6171.    value if name is a string variable name, and a numeric value if name is a
  6172.    numeric variable name. Assigning a numeric value to a string function name
  6173.    or assigning a string value to a numeric function name produces the error
  6174.    message Type mismatch.
  6175.  
  6176.    If the function is numeric, DEF FNname returns a value with the precision
  6177.    specified by name. For example, if name specifies a double-precision
  6178.    variable, then the value returned by DEF FNname is double precision,
  6179.    regardless of the precision of expression. Because BASIC may rearrange
  6180.    arithmetic expressions for greater efficiency, avoid using DEF FN
  6181.    functions that change program variables in expressions that may be
  6182.    reordered. The following example may give different results:
  6183.  
  6184.    DEF FNShort
  6185.       I=10
  6186.       FNShort=1
  6187.    END DEF
  6188.    I=1 : PRINT FNShort + I + I
  6189.  
  6190.    If BASIC reorders the expression so FNShort is called after calculating
  6191.    (I+I), the result is 3 rather than 21. You can usually avoid this problem
  6192.    by isolating the DEF FN function call:
  6193.  
  6194.    I = 1 : X = FNShort : PRINT X + I + I
  6195.  
  6196.    Doing I/O operations in DEF FN functions used in I/O statements or doing
  6197.    graphics operations in DEF FN functions in graphics statements may cause
  6198.    similar problems.
  6199.  
  6200.  ■ See Also
  6201.  
  6202.    EXIT, FUNCTION, STATIC
  6203.  
  6204.  ■ Example
  6205.  
  6206.    The following example uses a DEF FN function to calculate the factorial of
  6207.    an input number (the factorial of 3 is 3*2*1):
  6208.  
  6209.    DEF FNFactorial#(X)
  6210.       STATIC Tmp#, I
  6211.       Tmp#=1
  6212.       FOR I=2 TO X
  6213.          Tmp#=Tmp#*I
  6214.       NEXT I
  6215.       FNFactorial#=Tmp#
  6216.    END DEF
  6217.  
  6218.    INPUT "Enter a number: ",Num
  6219.    PRINT Num "factorial is" FNFactorial#(Num)
  6220.  
  6221.  ■ Output
  6222.  
  6223.    Enter a number: 3
  6224.     3 factorial is 6
  6225.  
  6226.  
  6227.  ────────────────────────────────────────────────────────────────────────────
  6228.  DEF SEG Statement
  6229.  ────────────────────────────────────────────────────────────────────────────
  6230.  
  6231.  ■ Action
  6232.  
  6233.    Sets the current segment address for a subsequent PEEK function or a
  6234.    BLOAD, BSAVE, CALL ABSOLUTE, or POKE statement
  6235.  
  6236.  ■ Syntax
  6237.  
  6238.    DEF SEG «=address»
  6239.  
  6240.  ■ Remarks
  6241.  
  6242.    For BLOAD, BSAVE, CALL ABSOLUTE, PEEK, and POKE, address is used as the
  6243.    segment. The address is a numeric expression returning an unsigned integer
  6244.    in the range 0-65,535. A value outside this range produces the error
  6245.    message Illegal function call. The previous segment is retained if an
  6246.    error occurs. If you omit address, the BASIC data segment is used.
  6247.  
  6248.    Be sure to separate DEF and SEG with a space. Otherwise, BASIC interprets
  6249.    the statement to mean "assign a value to the variable DEFSEG."
  6250.  
  6251.  ■ Differences From Basica
  6252.  
  6253.    In QuickBASIC, the CALL and CALLS statements do not use the segment
  6254.    address set by DEF SEG.
  6255.  
  6256.  ■ Example
  6257.  
  6258.    The following program uses DEF SEG, PEEK, and POKE statements to turn the
  6259.    CAPS LOCK on and off:
  6260.  
  6261.  ────────────────────────────────────────────────────────────────────────────
  6262.  NOTE
  6263.    This program contains hardware-specific instructions. It works correctly
  6264.    on IBM PC, PC/XT(R), and PC/AT(R) computers.
  6265.  ────────────────────────────────────────────────────────────────────────────
  6266.  
  6267.    DECLARE SUB CapsOn ()
  6268.    DECLARE SUB CapsOff ()
  6269.    DECLARE SUB PrntMsg (R%,C%,M$)
  6270.  
  6271.    CLS
  6272.  
  6273.    ' Turn Caps Lock on.
  6274.    CapsOn
  6275.    PrntMsg 24,1,"<Caps Lock On>"
  6276.  
  6277.    ' Prompt for input to show keyboard has changed.
  6278.    LOCATE 12,10
  6279.    LINE INPUT "Enter a string (all characters are caps): ",S$
  6280.  
  6281.    ' Turn Caps Lock off.
  6282.    CapsOff
  6283.    PrntMsg 24,1,"              "
  6284.  
  6285.    PrntMsg 25,1,"Press any key to continue..."
  6286.    DO WHILE INKEY$="" : LOOP
  6287.    CLS
  6288.    END
  6289.  
  6290.    ' Turn Caps Lock on.
  6291.    SUB CapsOn STATIC
  6292.       ' Set segment to low memory.
  6293.       DEF SEG = 0
  6294.       ' Set Caps Lock on (turn on bit 6 of &H0417).
  6295.       POKE &H0417,PEEK(&H0417) OR &H40
  6296.       ' Restore segment.
  6297.       DEF SEG
  6298.    END SUB
  6299.  
  6300.    ' Turn Caps Lock off.
  6301.    SUB CapsOff STATIC
  6302.       DEF SEG=0
  6303.       ' Set Caps Lock off (turn off bit 6 of &H0417).
  6304.       POKE &H0417,PEEK(&H0417) AND &HBF
  6305.       DEF SEG
  6306.    END SUB
  6307.  
  6308.    ' Print message at Row%, Col% without changing cursor.
  6309.    SUB PrntMsg (Row%, Col%, Message$) STATIC
  6310.       ' Save current cursor position.
  6311.       CurRow%=CSRLIN : CurCol%=POS(0)
  6312.       LOCATE Row%,Col% : PRINT Message$;
  6313.       ' Restore cursor position.
  6314.       LOCATE CurRow%,CurCol%
  6315.    END SUB
  6316.  
  6317.  
  6318.  ────────────────────────────────────────────────────────────────────────────
  6319.  DEFtype Statements
  6320.  ────────────────────────────────────────────────────────────────────────────
  6321.  
  6322.  ■ Action
  6323.  
  6324.    Set the default data type for variables, DEF FN functions, and FUNCTION
  6325.    procedures
  6326.  
  6327.  ■ Syntax
  6328.  
  6329.    DEFINT letterrange «,letterrange»...
  6330.    DEFSNG letterrange «,letterrange»...
  6331.    DEFDBL letterrange «,letterrange»...
  6332.    DEFLNG letterrange «,letterrange»...
  6333.    DEFSTR letterrange «,letterrange»...
  6334.  
  6335.  ■ Remarks
  6336.  
  6337.    The letterrange has the form:
  6338.  
  6339.    letter1«-letter2»
  6340.  
  6341.    where letter1 and letter2 are any of the uppercase or lowercase letters of
  6342.    the alphabet. Names beginning with the letters in letterrange have the
  6343.    type specified by the last three letters of the statement: integer (INT),
  6344.    long integer (LNG), single precision (SNG), double precision (DBL), or
  6345.    string (STR). For example, in the following program fragment, Message is a
  6346.    string variable:
  6347.  
  6348.    DEFSTR A-Q
  6349.    .
  6350.    .
  6351.    .
  6352.    Message="Out of stack space."
  6353.  
  6354.    The case of the letters in letterrange is not significant. All of the
  6355.    following statements are equivalent:
  6356.  
  6357.    DEFINT I-N
  6358.    DEFINT i-n
  6359.    DEFINT i-N
  6360.  
  6361.    A type-declaration character (%, &, !, #, or $) always takes precedence
  6362.    over a DEFtype statement. DEFtype statements do not affect record
  6363.    elements.
  6364.  
  6365.  ────────────────────────────────────────────────────────────────────────────
  6366.  NOTE
  6367.    I!, I#, I&, I$, and I% are all distinct variables, and each may hold a
  6368.    different value.
  6369.  ────────────────────────────────────────────────────────────────────────────
  6370.  
  6371.  ■ Differences From Basica
  6372.  
  6373.    BASICA handles DEFtype statements differently. BASICA scans a statement
  6374.    each time before executing it. If the statement contains a variable
  6375.    without an explicit type (indicated by !, #, &, $, or %), the interpreter
  6376.    uses the current default type.
  6377.  
  6378.    In the example below, when BASICA interprets line 20, it determines that
  6379.    the current default type for variables beginning with I is integer. Line
  6380.    30 changes the default type to single precision. When BASICA loops back to
  6381.    line 20, it rescans the line and uses IFLAG as a single-precision
  6382.    variable.
  6383.  
  6384.    10  DEFINT I
  6385.    20  PRINT IFLAG
  6386.    30  DEFSNG I
  6387.    40  GOTO 20
  6388.  
  6389.    In contrast, QuickBASIC scans the text only once; once a variable appears
  6390.    in a program line, its type cannot be changed.
  6391.  
  6392.  ■ Example
  6393.  
  6394.    See the example for the ABS function.
  6395.  
  6396.  
  6397.  ────────────────────────────────────────────────────────────────────────────
  6398.  DIM Statement
  6399.  ────────────────────────────────────────────────────────────────────────────
  6400.  
  6401.  ■ Action
  6402.  
  6403.    Declares a variable and allocates storage space
  6404.  
  6405.  ■ Syntax
  6406.  
  6407.    DIM «SHARED» variable«(subscripts)»«AS type»«,variable«(subscripts)»«AStype
  6408.  
  6409.  ■ Remarks
  6410.  
  6411.    The following list describes the parts of the DIM statement:
  6412.  
  6413.    Part                     Description
  6414.    ──────────────────────────────────────────────────────────────────────────
  6415.    SHARED                   The optional SHARED attribute allows all
  6416.                             procedures in a module to share arrays and simple
  6417.                             variables. This differs from the SHARED
  6418.                             statement, which affects only variables within a
  6419.                             single SUB or FUNCTION.
  6420.  
  6421.    variable                 A BASIC variable name.
  6422.  
  6423.    subscripts               The dimensions of the array. Multiple dimensions
  6424.                             can be declared. The subscript syntax is
  6425.                             described below.
  6426.  
  6427.    AS type                  Declares variable to be an elementary or
  6428.                             user-defined type. The elementary types are
  6429.                             INTEGER, LONG, SINGLE, DOUBLE, and STRING
  6430.                             (variable or fixed).
  6431.    ──────────────────────────────────────────────────────────────────────────
  6432.  
  6433.    Subscripts in DIM statements have the following form:
  6434.  
  6435.    «lower TO» upper «, «lower TO» upper»...
  6436.  
  6437.    The TO keyword provides a way to indicate both the lower and the upper
  6438.    bounds of an array's subscripts. The following statements are equivalent
  6439.    (if there is no OPTION BASE statement):
  6440.  
  6441.    DIM A(8,3)
  6442.    DIM A(0 TO 8, 0 TO 3)
  6443.    DIM A(8,0 TO 3)
  6444.  
  6445.    With the TO keyword, you are no longer restricted to positive subscripts.
  6446.    You can use TO to specify any range of subscripts from -32,768 to 32,767:
  6447.  
  6448.    DIM A(-4 TO 10)
  6449.    DIM B(-99 TO -5,-3 TO 0)
  6450.  
  6451.    If you use an array in your program without including the array in a DIM
  6452.    statement, the maximum value of each subscript of the array is 10. If you
  6453.    use a subscript that is greater than the specified maximum, an error
  6454.    message appears that says Subscript out of range.
  6455.  
  6456.    The DIM statement initializes all elements of numeric arrays to zero and
  6457.    all the elements of string arrays to null strings. The fields of record
  6458.    variables are initialized to zero, including fixed-string fields. The
  6459.    maximum number of dimensions allowed in a DIM statement is 60.
  6460.  
  6461.    If you try to dimension an array variable with a DIM statement after you
  6462.    have referred to the array, an error message results that reads Array
  6463.    already dimensioned. It is good programming practice to put the required
  6464.    DIM statements at the beginning of a program, outside of any loops.
  6465.  
  6466.    STATIC AND DYNAMIC ARRAYS
  6467.  
  6468.    How you declare an array also determines whether it is static (allocated
  6469.    when the program is translated) or dynamic (allocated when the program is
  6470.    run).
  6471.  
  6472.    ■ An array declared first in a COMMON statement is dynamic.
  6473.  
  6474.    ■ Implicitly dimensioned arrays are static.
  6475.  
  6476.    ■ Arrays dimensioned with numeric constants or CONST statement constants
  6477.      are static.
  6478.  
  6479.    ■ Arrays dimensioned with variables as subscripts are dynamic.
  6480.  
  6481.    The following list shows the different combinations and results:
  6482.  
  6483.    Statement                Result
  6484.    ──────────────────────────────────────────────────────────────────────────
  6485.    DIM A(0 TO 9)            The array A is allocated as a static array if
  6486.                             ¢DYNAMIC is not in effect.
  6487.  
  6488.    DIM A(MAXDIM)            If MAXDIM is defined in a CONST statement, A is a
  6489.                             static array. If MAXDIM is a variable, then the
  6490.                             array is a dynamic array and is only allocated
  6491.                             when the program reaches the DIM statement.
  6492.    ──────────────────────────────────────────────────────────────────────────
  6493.  
  6494.    See Appendix F, "Metacommands," in Programming in BASIC and Chapter 2,
  6495.    "Data Types," in this manual for more information about static and dynamic
  6496.    arrays.
  6497.  
  6498.  ────────────────────────────────────────────────────────────────────────────
  6499.  NOTE
  6500.    If the array size exceeds 64K, if the array is not dynamic, and if the /AH
  6501.    option was not used, you may get an error message that reads Subscript out
  6502.    of range or one that reads Array too big. Reduce the size of the array or
  6503.    make the array dynamic and use the /AH command-line option.
  6504.  ────────────────────────────────────────────────────────────────────────────
  6505.  
  6506.    TYPE DECLARATIONS
  6507.  
  6508.    In addition to declaring the dimensions of an array, the DIM statement may
  6509.    also be used to declare the type of a variable. For example, this
  6510.    statement declares the variable to be an integer, even though there is no
  6511.    type declaration character or DEFINT statement:
  6512.  
  6513.    DIM NumberOfBytes AS INTEGER
  6514.  
  6515.    The DIM statement provides a mechanism for declaring specific variables to
  6516.    be records. In the following example, the variable TopCard is declared as
  6517.    a record variable:
  6518.  
  6519.    TYPE Card
  6520.       Suit AS STRING*9
  6521.       Value AS INTEGER
  6522.    END TYPE
  6523.  
  6524.    DIM TopCard AS Card
  6525.  
  6526.    You may also declare arrays of records:
  6527.  
  6528.    TYPE Card
  6529.       Suit AS STRING*9
  6530.       Value AS INTEGER
  6531.    END TYPE
  6532.  
  6533.    DIM Deck(1 TO 52) AS Card
  6534.  
  6535.    See Appendix F, "Metacommands," in Programming in BASIC and Chapter 2,
  6536.    "Data Types," in this manual for more information.
  6537.  
  6538.  ■ Differences From Basica
  6539.  
  6540.    BASICA executes a DIM statement when it encounters the statement in the
  6541.    program. The array is only allocated when the statement is executed, so
  6542.    all arrays in BASICA are dynamic.
  6543.  
  6544.  ■ See Also
  6545.  
  6546.    ERASE, OPTION BASE, REDIM, SHARED
  6547.  
  6548.  ■ Example
  6549.  
  6550.    The following example finds and prints the maximum and minimum of a set of
  6551.    values:
  6552.  
  6553.    ' Find the maximum and minimum of up to 20 values.
  6554.    '
  6555.    ' Dimension an array to hold the values.
  6556.    CONST MAXDIM=20
  6557.    DIM A(1 TO MAXDIM)
  6558.    ' Use DIM to set up two integer variables.
  6559.    ' All other variables are SINGLE.
  6560.    DIM NumValues AS INTEGER, I AS INTEGER
  6561.  
  6562.    ' Get the values.
  6563.    NumValues=0
  6564.    PRINT "Enter values one per line. Type END to end."
  6565.  
  6566.    DO
  6567.       INPUT A$
  6568.       IF UCASE$(A$)="END" OR NumValues>=MAXDIM THEN EXIT DO
  6569.       NumValues=NumValues+1
  6570.       A(NumValues)=VAL(A$)
  6571.    LOOP
  6572.  
  6573.    ' Find the maximum and minimum values.
  6574.    IF NumValues>0 THEN
  6575.       Max=A(1)
  6576.       Min=A(1)
  6577.       FOR I=1 TO NumValues
  6578.          IF A(I)>Max THEN Max=A(I)
  6579.          IF A(I)<Min THEN Min=A(I)
  6580.       NEXT I
  6581.  
  6582.       PRINT "The maximum is ";Max;" The minimum is ";Min
  6583.    ELSE
  6584.       PRINT "Too few values."
  6585.    END IF
  6586.  
  6587.  ■ Output
  6588.  
  6589.    Enter values one per line. Type END to end.
  6590.    ? 23.2
  6591.    ? 11.3
  6592.    ? 1.6
  6593.    ? end
  6594.    The maximum is  23.2  The minimum is  1.6
  6595.  
  6596.  
  6597.  ────────────────────────────────────────────────────────────────────────────
  6598.  DO...LOOP Statement
  6599.  ────────────────────────────────────────────────────────────────────────────
  6600.  
  6601.  ■ Action
  6602.  
  6603.    Repeats a block of statements while a condition is true or until a
  6604.    condition becomes true
  6605.  
  6606.  ■ Syntax 1
  6607.  
  6608.    DO «statementblock » LOOP «{WHILE | UNTIL} booleanexpression»
  6609.  
  6610.  ■ Syntax 2
  6611.  
  6612.    DO «{WHILE | UNTIL} booleanexpression» «statementblock » LOOP
  6613.  
  6614.  ■ Remarks
  6615.  
  6616.    The following list describes the arguments of the DO...LOOP statement:
  6617.  
  6618.    Argument                 Description
  6619.    ──────────────────────────────────────────────────────────────────────────
  6620.    statementblock           One or more BASIC statements to be repeated
  6621.  
  6622.    booleanexpression        Any expression that evaluates to true (nonzero)
  6623.                             or false (zero)
  6624.    ──────────────────────────────────────────────────────────────────────────
  6625.  
  6626.    You can use a DO...LOOP statement instead of a WHILE...WEND statement. The
  6627.    DO...LOOP is more versatile because it can test for a condition at the
  6628.    beginning or at the end of a loop.
  6629.  
  6630.  ■ Examples
  6631.  
  6632.    The first two examples below show you how placement of the condition
  6633.    affects the number of times the block of statements is executed. The third
  6634.    example illustrates testing at the end of a loop and presents a sort
  6635.    subprogram where an ending test is appropriate.
  6636.  
  6637.    In the following example, the test is done at the beginning of the loop.
  6638.    Because I is not less than 10, the body of the loop (the statement block)
  6639.    is never executed.
  6640.  
  6641.    ' DO...LOOP with test at the top of the loop.
  6642.    ' Output shows that loop was not executed.
  6643.      I = 10
  6644.      PRINT "Value of I at beginning of loop is  ";I
  6645.      DO WHILE I < 10
  6646.         I = I + 1
  6647.      LOOP
  6648.      PRINT "Value of I at end of loop is  ";I
  6649.  
  6650.  ■ Output
  6651.  
  6652.    Value of I at beginning of loop is  10
  6653.    Value of I at end of loop is  10
  6654.  
  6655.    The following example tests I at the end of the loop, so the statement
  6656.    block executes at least once.
  6657.  
  6658.    ' DO...LOOP with test at the bottom of the loop.
  6659.    ' Output shows loop was executed once.
  6660.     I = 10
  6661.       DO
  6662.         PRINT "Value of I at beginning of loop is  ";I
  6663.         I = I + 1
  6664.       LOOP WHILE I < 10
  6665.       PRINT "Value of I at end of loop is  ";I
  6666.  
  6667.  ■ Output
  6668.  
  6669.    Value of I at beginning of loop is  10
  6670.    Value of I at end of loop is 11
  6671.  
  6672.    The following sort subprogram tests at the end of the loop because the
  6673.    entire array must be examined at least once to see if it is in order. In
  6674.    general, test at the end of a loop only if you know that you always want
  6675.    the statement block executed at least once.
  6676.  
  6677.    ' Bubble sort subroutine
  6678.    '        Exes is array to sort
  6679.    '        N is number of elements in Exes
  6680.    '
  6681.    '        Note: sort assumes the first element of
  6682.    '              Exes is Exes(1).
  6683.  
  6684.    ' Set up a special value to indicate no exchanges.
  6685.    CONST NOEXCH=-1
  6686.  
  6687.    SUB sort(Exes(1),N) STATIC
  6688.  
  6689.    Limit=N
  6690.    DO
  6691.  
  6692.       Exchange=NOEXCH
  6693.       FOR I=1 TO Limit-1     ' Make one pass over the array.
  6694.          IF Exes(I) > Exes(I+1) THEN
  6695.             SWAP Exes(I),Exes(I+1)   'Exchange array elements.
  6696.             Exchange=I               'Record location of most
  6697.          END IF                      'recent exchange.
  6698.       NEXT I
  6699.       Limit=Exchange      'Sort on next pass only to where
  6700.                           'last exchange was done.
  6701.    LOOP UNTIL Exchange=NOEXCH  'Sort until no elements
  6702.                                'are exchanged.
  6703.  
  6704.    END SUB
  6705.  
  6706.  
  6707.  ────────────────────────────────────────────────────────────────────────────
  6708.  DRAW Statement
  6709.  ────────────────────────────────────────────────────────────────────────────
  6710.  
  6711.  ■ Action
  6712.  
  6713.    Draws an object defined by stringexpression
  6714.  
  6715.  ■ Syntax
  6716.  
  6717.    DRAW stringexpression
  6718.  
  6719.  ■ Remarks
  6720.  
  6721.    The DRAW statement combines many of the capabilities of the other graphics
  6722.    statements into a graphics macro language, as described below under
  6723.    "Cursor-Movement Commands" and "Angle, Color, and Scale-Factor Commands."
  6724.    This macro language defines a set of characteristics that can be used to
  6725.    describe an image. These characteristics include motion (up, down, left,
  6726.    right), color, rotation angle, and scale factor. The stringexpression
  6727.    consists of these macro commands.
  6728.  
  6729.    CURSOR-MOVEMENT COMMANDS
  6730.  
  6731.    The following prefix commands can precede any of the movement commands:
  6732.  
  6733.    Prefix                   Description
  6734.    ──────────────────────────────────────────────────────────────────────────
  6735.    B                        Move, but do not plot any points.
  6736.    N                        Move, but return to original position when done.
  6737.    ──────────────────────────────────────────────────────────────────────────
  6738.  
  6739.    The following commands specify movement in units. The default unit size is
  6740.    one point; this unit size can be modified by the S command, which sets the
  6741.    scale factor. (S is described in "Angle, Color, and Scale-Factor
  6742.    Commands.") If no argument is supplied, the cursor is moved one unit.
  6743.  
  6744.    Each of the movement commands initiates movement from the current graphics
  6745.    position, which is usually the coordinate of the last graphics point
  6746.    plotted with another graphics macro-language command. The current position
  6747.    defaults to the center of the screen when a program is run.
  6748.  
  6749. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  6750.    Movement                 Description
  6751.    ──────────────────────────────────────────────────────────────────────────
  6752.    U «n»                    Move up n units.
  6753.  
  6754.    D «n»                    Move down n units.
  6755.  
  6756.    L «n»                    Move left n units.
  6757.  
  6758.    R «n»                    Move right n units.
  6759.  
  6760.    E «n»                    Move diagonally up and right n units.
  6761.  
  6762.    F «n»                    Move diagonally down and right n units.
  6763.  
  6764.    Movement                 Description
  6765.    ──────────────────────────────────────────────────────────────────────────
  6766. 
  6767.    G «n»                    Move diagonally down and left n units.
  6768.  
  6769.    H «n»                    Move diagonally up and left n units.
  6770.  
  6771.    M x,y                    Move absolute or relative. If x is preceded by a
  6772.                             plus (+) or minus (-), the movement is relative
  6773.                             to the current point; that is, x and y are added
  6774.                             to (or subtracted from) the coordinates of the
  6775.                             current graphics position and connected with that
  6776.                             position by a line.
  6777.  
  6778.                             If no sign precedes x, the movement is absolute;
  6779.                             that is, a line is drawn from the current cursor
  6780.                             position to the point with coordinates x,y.
  6781.    ──────────────────────────────────────────────────────────────────────────
  6782.  
  6783.  
  6784.    ANGLE, COLOR, AND SCALE-FACTOR COMMANDS
  6785.  
  6786.    The following commands let you change the appearance of a drawing by
  6787.    rotating it, changing colors, or scaling it:
  6788.  
  6789. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  6790.    Command                  Description
  6791.    ──────────────────────────────────────────────────────────────────────────
  6792.    A n                      Set angle of rotation n. The value of n may range
  6793.                             from 0 to 3, where 0 is 0°, 1 is 90°, 2 is 180°,
  6794.                             and 3 is 270°. Figures rotated 90° or 270° are
  6795.                             scaled so they appear the same size using 0° or
  6796.                             180° on a monitor screen with a standard screen
  6797.                             width-to-height ratio of 4/3.
  6798.  
  6799.    TA n                     Turn an angle of n degrees; n must be in the
  6800.                             range -360 to 360. If n is positive, rotation is
  6801.                             counterclockwise; if n is negative, rotation is
  6802.                             clockwise. The following example uses TA to draw
  6803.                             spokes:
  6804.  
  6805.                             SCREEN 1
  6806.    Command                  Description
  6807.    ──────────────────────────────────────────────────────────────────────────
  6808.                            SCREEN 1
  6809.                             FOR D=0 TO 360  STEP 10
  6810.                               DRAW "TA="+VARPTR$(D)+"NU50"
  6811.                             NEXT D
  6812.  
  6813.    C n                      Set color to n. See COLOR, PALETTE, and SCREEN
  6814.                             statements for discussions of valid colors,
  6815.                             numbers, and attributes.
  6816.  
  6817.    S n                      Set scale factor n, which may range from 1 to
  6818.                             255. The scale factor multiplied by the distances
  6819.                             given with U, D, L, R, or relative M commands
  6820.                             gives the actual distance traveled.
  6821.  
  6822.    P paintcolor,            The paintcolor is the paint color for a figure's
  6823.    bordercolor              interior, while bordercolor is the paint color
  6824.                             for the figure's border. Tile painting (painting
  6825.                             an area with a graphic pattern) is not supported
  6826.                             in DRAW.
  6827.    Command                  Description
  6828.    ──────────────────────────────────────────────────────────────────────────
  6829.                            in DRAW.
  6830.  
  6831.    X stringexpression       Execute substring. This powerful command allows
  6832.                             you to execute a second substring from a string.
  6833.                             You may have one string expression execute
  6834.                             another, which executes a third, and so on.
  6835.                             Numeric arguments can be constants like 123 or
  6836.                             variable names.
  6837.                             QuickBASIC requires the "X" +
  6838.                             VARPTR$(stringexpression) form of this command.
  6839.                             (See "Differences from BASICA" below.)
  6840.    ──────────────────────────────────────────────────────────────────────────
  6841.  
  6842.  
  6843.  ■ Differences From Basica
  6844.  
  6845.    The DRAW statement requires modification of BASICA programs when used with
  6846.    QuickBASIC. Specifically, the compiler requires the VARPTR$ form for
  6847.    variables. Statements such as the following:
  6848.  
  6849.    DRAW "XA$"
  6850.  
  6851.    DRAW "TA = ANGLE"
  6852.  
  6853.    (where A$ and ANGLE are variables) must be changed as follows:
  6854.  
  6855.    DRAW "X" + VARPTR$(A$)
  6856.  
  6857.    DRAW "TA =" + VARPTR$(ANGLE)
  6858.  
  6859.    when using the compiler.
  6860.  
  6861.    The compiler does not support the Xstringexpression command. However, you
  6862.    may execute a substring by appending the character form of the address to
  6863.    X. For example, the following two statements are equivalent. The first
  6864.    statement works when within the environment and when using the compiler;
  6865.    the second works only within the environment.
  6866.  
  6867.    DRAW "X" + VARPTR$(A$)
  6868.    DRAW "XA$"
  6869.  
  6870.  ■ Examples
  6871.  
  6872.    The following program draws a triangle's outline in magenta and paints the
  6873.    interior cyan:
  6874.  
  6875.    SCREEN 1
  6876.    DRAW "C2"             'Set color to magenta.
  6877.    DRAW "F60 L120 E60"   'Draw a triangle.
  6878.    DRAW "BD30"           'Move down into the triangle.
  6879.    DRAW "P1,2"           'Paint interior.
  6880.  
  6881.    The following example shows different ways of using the M macro command:
  6882.    with absolute movement and relative movement; using string-variable
  6883.    arguments; and using numeric-variable arguments:
  6884.  
  6885.    SCREEN 2
  6886.    'Absolute movement
  6887.    DRAW "M 50,80"
  6888.    DRAW "M 80,50"
  6889.    'Relative movement
  6890.    DRAW "M+40,-20"
  6891.    DRAW "M-40,-20"
  6892.    DRAW "M-40,+20"
  6893.    DRAW "M+40,+20"
  6894.    'Using a string variable.
  6895.    X$ = "400" : Y$ = "190"
  6896.    DRAW "M" + X$ + "," + Y$
  6897.    'Using numeric variables (note the two "=" signs).
  6898.    A = 300 : B = 120
  6899.    DRAW "M="+VARPTR$(A)+",="+VARPTR$(B)
  6900.  
  6901.    The following example draws a clock on the screen using the TIME$
  6902.    function:
  6903.  
  6904.    ' Declare procedure.
  6905.    DECLARE SUB Face (Min$)
  6906.  
  6907.    ' Select 640 x 200 pixel high-resolution graphics screen.
  6908.    SCREEN 2
  6909.  
  6910.    DO
  6911.  
  6912.       ' Clear the screen.
  6913.       CLS
  6914.  
  6915.       ' Get the string containing the minutes value.
  6916.       Min$ = MID$(TIME$,4,2)
  6917.  
  6918.       ' Draw the clock face.
  6919.       Face Min$
  6920.  
  6921.       ' Wait until the minute changes or a key is pressed.
  6922.       DO
  6923.  
  6924.         ' Print the time at the top of the screen.
  6925.         LOCATE 2,37
  6926.         PRINT TIME$
  6927.  
  6928.         ' Test for a key press.
  6929.         Test$ = INKEY$
  6930.       LOOP WHILE Min$ = MID$(TIME$,4,2) AND Test$ = ""
  6931.  
  6932.    ' End the program when a key is pressed.
  6933.    LOOP WHILE Test$ = ""
  6934.    END
  6935.    ' Draw the clock face.
  6936.    SUB Face (Min$) STATIC
  6937.       LOCATE 23,30
  6938.       PRINT "Press any key to end"
  6939.       CIRCLE (320,100),175
  6940.  
  6941.       ' Convert strings to numbers.
  6942.       Hr = VAL(TIME$)
  6943.       Min = VAL(Min$)
  6944.  
  6945.       ' Convert numbers to angles.
  6946.       Little = 360 - (30 * Hr + Min/2)
  6947.       Big = 360 - (6*Min)
  6948.  
  6949.       ' Draw the hands.
  6950.       DRAW "TA=" + VARPTR$(Little) + "NU40"
  6951.       DRAW "TA=" + VARPTR$(Big) + "NU70"
  6952.    END SUB
  6953.  
  6954.  
  6955.  ────────────────────────────────────────────────────────────────────────────
  6956.  END Statement
  6957.  ────────────────────────────────────────────────────────────────────────────
  6958.  
  6959.  ■ Action
  6960.  
  6961.    Ends a BASIC program, procedure, or block
  6962.  
  6963.  ■ Syntax
  6964.  
  6965.    END «{DEF | FUNCTION | IF | SELECT | SUB | TYPE}»
  6966.  
  6967.  ■ Remarks
  6968.  
  6969.    There are several ways to use the END statement, as described in the
  6970.    following list:
  6971.  
  6972.    Statement                Description
  6973.    ──────────────────────────────────────────────────────────────────────────
  6974.    END DEF                  Ends a multiline DEF FN function definition. You
  6975.                             must use END DEF with a multiline DEF FN.
  6976.  
  6977.    END FUNCTION             Ends a FUNCTION procedure definition. You must
  6978.                             use END FUNCTION with FUNCTION.
  6979.  
  6980.    END IF                   Ends a block IF...THEN...ELSE statement. You must
  6981.                             use END IF with block IF...THEN...ELSE.
  6982.  
  6983.    END SELECT               Ends a SELECT CASE block. You must use END SELECT
  6984.                             with a SELECT CASE statement.
  6985.  
  6986.    END SUB                  Ends a BASIC subprogram. You must use END SUB
  6987.                             with SUB.
  6988.  
  6989.    END TYPE                 Ends a user-defined type definition. You must use
  6990.                             END TYPE with TYPE.
  6991.    ──────────────────────────────────────────────────────────────────────────
  6992.  
  6993.    By itself, the END statement stops program execution and closes all files.
  6994.    In a stand-alone program, END returns control to the operating system.
  6995.    When running inside the QuickBASIC environment, END returns you to that
  6996.    environment.
  6997.  
  6998.    The compiler always assumes an END statement at the conclusion of any
  6999.    program, so omitting an END statement at the end of a program still
  7000.    produces proper program termination. You may place END statements anywhere
  7001.    in the program to end program execution.
  7002.  
  7003.  ■ See Also
  7004.  
  7005.    DEF FN; FUNCTION; IF...THEN...ELSE; SELECT CASE; SUB; TYPE
  7006.  
  7007.  ■ Example
  7008.  
  7009.    The following example uses a subprogram to query the user about continuing
  7010.    some action. If the user enters n or N the subprogram ends the program.
  7011.  
  7012.    DO
  7013.      .
  7014.      .
  7015.      .
  7016.      CALL ContinueQuery
  7017.    LOOP
  7018.  
  7019.    SUB ContinueQuery STATIC
  7020.       DO
  7021.          INPUT "Continue (Y or N)"; Response$
  7022.          R$=UCASE$(LEFT$(Response$,1))
  7023.          IF R$="N" THEN END
  7024.          IF R$="Y" THEN EXIT DO
  7025.          BEEP
  7026.       LOOP
  7027.    END SUB
  7028.  
  7029.  
  7030.  ────────────────────────────────────────────────────────────────────────────
  7031.  ENVIRON$ Function
  7032.  ────────────────────────────────────────────────────────────────────────────
  7033.  
  7034.  ■ Action
  7035.  
  7036.    Retrieves an environment string from the DOS environment-string table
  7037.  
  7038.  ■ Syntax
  7039.  
  7040.    ENVIRON$ (environmentstring)
  7041.    ENVIRON$ (n)
  7042.  
  7043.  ■ Remarks
  7044.  
  7045.    The environmentstring is a string constant or variable containing the name
  7046.    of an environment variable. The argument n is a numeric expression.
  7047.  
  7048.    If you specify an environmentstring name, but it cannot be found in the
  7049.    environment-string table, or there is no text following it, then ENVIRON$
  7050.    returns a null string. Otherwise, ENVIRON$ returns the text following the
  7051.    equal sign in the environment-string table.
  7052.  
  7053.    If you specify a numeric argument (n), the nth string in the
  7054.    environment-string table is returned. In this case, the string includes
  7055.    all of the text, including the environmentstring name. If the nth string
  7056.    does not exist, ENVIRON$ returns a null string. The n argument can be any
  7057.    numeric expression; it is rounded to an integer.
  7058.  
  7059.  ■ Example
  7060.  
  7061.    The following example prints the current environment-string table
  7062.    settings:
  7063.  
  7064.    I = 1
  7065.    DO WHILE ENVIRON$(I) <> ""
  7066.        PRINT ENVIRON$(I)
  7067.        I = I + 1
  7068.    LOOP
  7069.  
  7070.  ■ Output
  7071.  
  7072.    COMSPEC=C:\COMMAND.COM
  7073.    TMP=c:\tmp
  7074.    PATH=C:\TOOLS;C:\BIN
  7075.    PROMPT=¢ec4$l¢ec7$p¢ec4$g¢ec7¢eb1
  7076.    INIT=c:\tools
  7077.    LIB=c:\lib
  7078.    INCLUDE=c:\include
  7079.  
  7080.  
  7081.  ────────────────────────────────────────────────────────────────────────────
  7082.  ENVIRON Statement
  7083.  ────────────────────────────────────────────────────────────────────────────
  7084.  
  7085.  ■ Action
  7086.  
  7087.    Modifies a parameter in the DOS environment-string table
  7088.  
  7089.  ■ Syntax
  7090.  
  7091.    ENVIRON stringexpression
  7092.  
  7093.  ■ Remarks
  7094.  
  7095.    The stringexpression must be of the form parameterid=text, or the form
  7096.    parameterid text. Everything to the left of the equal sign or space is
  7097.    assumed to be a parameter, and everything to the right, text.
  7098.  
  7099.    If the parameterid has not previously existed in the environment-string
  7100.    table, it is appended to the end of the table. If a parameterid exists in
  7101.    the table when the ENVIRON statement is executed, it is deleted and the
  7102.    new parameterid is appended to the end of the table.
  7103.  
  7104.    The text string is the new parameter text. If the text is a null string
  7105.    ("") or a semicolon (";"), then the existing parameter is removed from the
  7106.    environment-string table and the remaining body of the table is
  7107.    compressed.
  7108.  
  7109.    DOS discards the environment-string table modified by this function when
  7110.    your program ends. The environment-string table is the same as it was
  7111.    before your program ran.
  7112.  
  7113.    You may use this statement to change the PATH parameter for a "child"
  7114.    process (a program or command started by a SHELL statement) or to pass
  7115.    parameters to a child by inventing a new environment parameter.
  7116.  
  7117.    Errors in environment-string tables include parameters that are not
  7118.    strings and lack of free space. An Out of memory error message is printed
  7119.    when no more space can be allocated to the environment-string table. The
  7120.    amount of free space in the table is usually quite small.
  7121.  
  7122.  ■ See Also
  7123.  
  7124.    ENVIRON$, SHELL
  7125.  
  7126.  ■ Example
  7127.  
  7128.    The following example changes the value of the PATH environment variable
  7129.    to that shown:
  7130.  
  7131.    'Change value of PATH environment variable.
  7132.    ENVIRON "PATH=A:\SALES;A:\ACCOUNTING"
  7133.  
  7134.  
  7135.  ────────────────────────────────────────────────────────────────────────────
  7136.  EOF Function
  7137.  ────────────────────────────────────────────────────────────────────────────
  7138.  
  7139.  ■ Action
  7140.  
  7141.    Tests for the end-of-file condition
  7142.  
  7143.  ■ Syntax
  7144.  
  7145.    EOF(filenumber)
  7146.  
  7147.  ■ Remarks
  7148.  
  7149.    The EOF function returns -1 (true) if the end of a sequential file has
  7150.    been reached. Use the EOF function to test for end-of-file while inputting
  7151.    data. In this way you may avoid the Input past end error message.
  7152.  
  7153.    When EOF is used with random-access or binary files, it returns "true" if
  7154.    the last executed GET statement was unable to read an entire record. This
  7155.    happens because of an attempt to read beyond the end of the file.
  7156.  
  7157.    EOF cannot be used with the BASIC devices SCRN:, KYBD:, CONS:, and LPTn:.
  7158.  
  7159.    When you use EOF with a communications device, the definition of the
  7160.    end-of-file condition is dependent on the mode (ASCII or binary) in which
  7161.    you opened the device. In ASCII mode, EOF is false until you receive
  7162.    CTRL+Z, after which it remains true until you close the device. In binary
  7163.    mode, EOF is true when the input queue is empty (LOC(n)=0). It becomes
  7164.    "false" when the input queue is not empty.
  7165.  
  7166.  ■ Example
  7167.  
  7168.    The fragment below reads single-precision values from a file until all
  7169.    values have been read:
  7170.  
  7171.    DIM M(0 TO 2000)
  7172.  
  7173.    OPEN "DATA" FOR INPUT AS 1
  7174.    C = 0
  7175.    DO WHILE NOT EOF(1) AND C <= 2000
  7176.          INPUT #1, M(C)
  7177.          C = C+1
  7178.    LOOP
  7179.    .
  7180.    .
  7181.    .
  7182.  
  7183.  
  7184.  ────────────────────────────────────────────────────────────────────────────
  7185.  ERASE Statement
  7186.  ────────────────────────────────────────────────────────────────────────────
  7187.  
  7188.  ■ Action
  7189.  
  7190.    Reinitializes the elements of static arrays; deallocates dynamic arrays
  7191.  
  7192.  ■ Syntax
  7193.  
  7194.    ERASE arrayname «,arrayname...»
  7195.  
  7196.  ■ Remarks
  7197.  
  7198.    The arrayname arguments are the names of arrays to erase. ERASE has
  7199.    different effects on static and dynamic arrays.
  7200.  
  7201.    The ERASE statement sets the elements of a static array to zeros in the
  7202.    case of a numeric array or null strings ("") in the case of a string
  7203.    array. If the array is an array of records, the ERASE statement sets all
  7204.    elements of each record to zeros, including fixed-string elements.
  7205.  
  7206.    However, using ERASE on a dynamic array frees the memory used by the
  7207.    array. Before your program can refer to the dynamic array again, it must
  7208.    first redimension the array with a DIM or REDIM statement. Redimensioning
  7209.    an array with a DIM statement without first erasing it produces a
  7210.    duplicate definition run-time error message that reads Array already
  7211.    dimensioned. The ERASE statement is not required when arrays are
  7212.    redimensioned with REDIM.
  7213.  
  7214.    See Chapter 2, "Data Types," in this manual and Appendix F,
  7215.    "Metacommands," in Programming in BASIC for more information on declaring
  7216.    dynamic and static arrays.
  7217.  
  7218.  ■ See Also
  7219.  
  7220.    DIM, REDIM
  7221.  
  7222.  ■ Example
  7223.  
  7224.    The following program fragment shows the use of ERASE with the ¢DYNAMIC
  7225.    and ¢STATIC metacommands:
  7226.  
  7227.    REM ¢DYNAMIC
  7228.    DIM A(100,100)
  7229.    .
  7230.    .
  7231.    .
  7232.  
  7233.    'This deallocates array A.
  7234.    ERASE A
  7235.    'Redimension array A.
  7236.    REDIM A(5,5)
  7237.    REM ¢STATIC
  7238.    DIM B(50,50)
  7239.    .
  7240.    .
  7241.    .
  7242.    'This sets all elements of B equal to zero.
  7243.    'B still has the dimensions assigned by DIM.
  7244.    ERASE B
  7245.  
  7246.  
  7247.  ────────────────────────────────────────────────────────────────────────────
  7248.  ERDEV, ERDEV$ Functions
  7249.  ────────────────────────────────────────────────────────────────────────────
  7250.  
  7251.  ■ Action
  7252.  
  7253.    Provides device-specific status information after an error
  7254.  
  7255.  ■ Syntax
  7256.  
  7257.    ERDEV
  7258.    ERDEV$
  7259.  
  7260.  ■ Remarks
  7261.  
  7262.    ERDEV is an integer function that returns an error code from the last
  7263.    device to declare an error. ERDEV$ is a string function that returns the
  7264.    name of the device generating the error. Because ERDEV and ERDEV$ return
  7265.    meaningful information only after an error, they are usually used in error
  7266.    handlers specified by an ON ERROR statement.
  7267.  
  7268.    ERDEV and ERDEV$ cannot be used on the left side of an assignment.
  7269.  
  7270.    ERDEV is set by the critical error handler (interrupt 24H) when DOS
  7271.    detects an error that prevents continuing.
  7272.  
  7273.    The value of ERDEV is a bit-encoded value containing the DOS error
  7274.    information. The lower eight bits (first byte) contain the DOS error code,
  7275.    a value from 0 to 12. The upper eight bits (second byte) contain bits 15,
  7276.    14, 13, XX, 3, 2, 1, and 0, in that order, of the device-attribute word.
  7277.    XX indicates the bit is always zero. See the Microsoft MS-DOS Programmer's
  7278.    Reference for more information about device-attribute words.
  7279.  
  7280.  ■ See Also
  7281.  
  7282.    ERR, ERL; ON ERROR
  7283.  
  7284.  ■ Example
  7285.  
  7286.    The following example prints the values of ERDEV and ERDEV$ when an error
  7287.    occurs:
  7288.  
  7289.    DEFINT A-Z
  7290.  
  7291.    ' Indicate first line of error handler.
  7292.    ON ERROR GO TO ErrorHandler
  7293.  
  7294.    ' Attempt to open the file.
  7295.    OPEN "A:JUNK.DAT" FOR INPUT AS #1
  7296.  
  7297.    END
  7298.  
  7299.    ' Error handling routine.
  7300.    ' Prints values of ERDEV and ERDEV$ and dies.
  7301.  
  7302.    ErrorHandler:
  7303.       PRINT "ERDEV value is ";ERDEV
  7304.       PRINT "Device name is ";ERDEV$
  7305.       ON ERROR GOTO 0
  7306.  
  7307.  ■ Output
  7308.  
  7309.    Running the program with drive A unlatched produces the following output
  7310.    (2 is the error code for "Drive not ready"):
  7311.  
  7312.    ERDEV value is  2
  7313.    Device name is A:
  7314.  
  7315.  
  7316.  ────────────────────────────────────────────────────────────────────────────
  7317.  ERR, ERL Functions
  7318.  ────────────────────────────────────────────────────────────────────────────
  7319.  
  7320.  ■ Action
  7321.  
  7322.    Return error status
  7323.  
  7324.  ■ Syntax
  7325.  
  7326.    ERR
  7327.    ERL
  7328.  
  7329.  ■ Remarks
  7330.  
  7331.    After an error, the function ERR returns the code for the error, and the
  7332.    ERL function returns the line number where the error occurred. Because ERR
  7333.    and ERL return meaningful values only after an error, they are usually
  7334.    used in error-handling routines to determine the error and the corrective
  7335.    action.
  7336.  
  7337.    Because ERL and ERR are functions, you cannot use them on the left-hand
  7338.    side of an assignment statement. However, you may indirectly set them with
  7339.    the ERROR statement.
  7340.  
  7341.  ■ Differences From Basica
  7342.  
  7343.    The ERL function returns only the line number, not line label, located
  7344.    before the line producing the error. If your program has no line numbers,
  7345.    ERL always returns 0.
  7346.  
  7347.  ■ See Also
  7348.  
  7349.    ERDEV, ERROR, ON ERROR, RESUME
  7350.  
  7351.  ■ Example
  7352.  
  7353.    See the example for ON ERROR.
  7354.  
  7355.  
  7356.  ────────────────────────────────────────────────────────────────────────────
  7357.  ERROR Statement
  7358.  ────────────────────────────────────────────────────────────────────────────
  7359.  
  7360.  ■ Action
  7361.  
  7362.    Simulates the occurrence of a BASIC error or allows the user to define
  7363.    error codes
  7364.  
  7365.  ■ Syntax
  7366.  
  7367.    ERROR integerexpression
  7368.  
  7369.  ■ Remarks
  7370.  
  7371.    The integerexpression represents the error code. It must be greater than 0
  7372.    and less than or equal to 255. If the integerexpression is an error code
  7373.    already used by BASIC, then the ERROR statement simulates the occurrence
  7374.    of that error and prints the corresponding error message.
  7375.  
  7376.    To define your own error code, use a value that is greater than any used
  7377.    by the standard BASIC error codes. (Start at 255 and work down to maintain
  7378.    compatibility with future Microsoft BASIC error codes.)
  7379.  
  7380.    If an ERROR statement specifies a code for which no error message has been
  7381.    defined, the message Unprintable error is printed. Executing an ERROR
  7382.    statement for which there is no error-handling routine causes an error
  7383.    message to be printed and execution to halt.
  7384.  
  7385.  ■ See Also
  7386.  
  7387.    ERR, ERL; ON ERROR; RESUME
  7388.  
  7389.  ■ Example
  7390.  
  7391.    The following fragment uses an ERROR statement to trap a user input error:
  7392.  
  7393.    ON ERROR GOTO Handler
  7394.    OpenFile:
  7395.        INPUT "Name of file to update";FileSpec$
  7396.        IF FileSpec$ = "" THEN END
  7397.        OPEN FileSpec$ FOR INPUT AS #1
  7398.        PRINT "The first five lines of ";FILESPEC$;" are:" : PRINT
  7399.        FOR I = 1 TO 5
  7400.            LINE INPUT #1, Temp$
  7401.            PRINT Temp$
  7402.        NEXT
  7403.        PRINT : INPUT "Is this the correct file";R$
  7404.        'Define error 200.
  7405.        IF LEFT$(R$,1) <> "y" THEN ERROR 200
  7406.        .
  7407.        .
  7408.        .
  7409.        END
  7410.  
  7411.    Handler:        'Error-handling routine.
  7412.        Number = ERR
  7413.        'Run-time error for "file not found."
  7414.        IF Number = 53 THEN
  7415.            CLOSE #1
  7416.            PRINT "File not in this directory"
  7417.            PRINT "Enter new file spec ([d:]xxx...xxx) or"
  7418.            PRINT "press <RETURN> to end program"
  7419.            RESUME OpenFile
  7420.        ELSEIF Number = 200 THEN
  7421.    'User entered "n"
  7422.            CLOSE #1
  7423.            RESUME OpenFile
  7424.        ELSE
  7425.            ERROR Number       'Error other than 53 or 200.
  7426.            ON ERROR GOTO 0    'Print message, disable error
  7427.        END IF                 'handling, and stop program.
  7428.  
  7429.  ■ Output
  7430.  
  7431.    Name of file to update? c:novelallenadv.txt
  7432.    File not in this directory
  7433.    Enter new file spec ([d:]xxx...xxx) or
  7434.    press <RETURN> to end program
  7435.    Name of file to update? c:toryallenadv.txt
  7436.    The first five lines of c:toryallenadv.txt are:
  7437.  
  7438.    Allen gripped the microphone. Small beads
  7439.    of perspiration glistened on his forehead
  7440.    like cheap pearls. He knew that what he
  7441.    said would change his life and the lives
  7442.    of those he loved. In a trembling voice,
  7443.  
  7444.    Is this the correct file? y
  7445.  
  7446.  
  7447.  ────────────────────────────────────────────────────────────────────────────
  7448.  EXIT Statement
  7449.  ────────────────────────────────────────────────────────────────────────────
  7450.  
  7451.  ■ Action
  7452.  
  7453.    Exits a DEF FN function, DO...LOOP or FOR...NEXT loop, FUNCTION, or SUB
  7454.  
  7455.  ■ Syntax
  7456.  
  7457.    EXIT {DEF | DO | FOR | FUNCTION | SUB }
  7458.  
  7459.  ■ Remarks
  7460.  
  7461.    There are several ways to use the EXIT statement as described in the
  7462.    following list:
  7463.  
  7464. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  7465.    Statement                Description
  7466.    ──────────────────────────────────────────────────────────────────────────
  7467.    EXIT DEF                 Causes an immediate exit from the executing DEF
  7468.                             FN function. Program execution continues where
  7469.                             the DEF FN function was invoked.
  7470.  
  7471.    EXIT DO                  Provides an alternative exit from a DO...LOOP.
  7472.                             Can be used only inside a DO...LOOP statement;
  7473.                             EXIT DO transfers control to the statement
  7474.                             following the LOOP statement. When used within
  7475.                             nested DO...LOOP statements, transfers out of the
  7476.                             immediately enclosing loop.
  7477.  
  7478.    Statement                Description
  7479.    ──────────────────────────────────────────────────────────────────────────
  7480. 
  7481.    EXIT FOR                 Provides another way to exit a FOR...NEXT loop.
  7482.                             May appear only in a FOR...NEXT loop; transfers
  7483.                             control to the statement following the NEXT
  7484.                             statement. When used within nested FOR...NEXT
  7485.                             loops, transfers out of the immediately enclosing
  7486.                             loop.
  7487.  
  7488.    EXIT FUNCTION            Causes an immediate exit from a FUNCTION
  7489.                             procedure. Program execution continues where the
  7490.                             FUNCTION was invoked. Can only be used in a
  7491.                             FUNCTION procedure.
  7492.  
  7493.    EXIT SUB                 Immediately exits a SUB procedure. Program
  7494.                             execution continues with the statement after the
  7495.                             CALL statement. Can only be used in a SUB
  7496.                             procedure.
  7497.    ──────────────────────────────────────────────────────────────────────────
  7498.  
  7499.    Statement                Description
  7500.    ──────────────────────────────────────────────────────────────────────────
  7501. 
  7502.  
  7503.    None of the EXIT statements define the end of the structure in which they
  7504.    are used. EXIT statements only provide an alternative exit from the
  7505.    structure.
  7506.  
  7507.  ■ See Also
  7508.  
  7509.    DEF FN; DO...LOOP; FOR...NEXT; FUNCTION; SUB
  7510.  
  7511.  ■ Examples
  7512.  
  7513.    See the third example for STATIC for a use of EXIT SUB.
  7514.  
  7515.    The following subprogram is an extended RTRIM$ that removes trailing
  7516.    blanks, tabs, carriage returns, and line feeds from a string. The
  7517.    subprogram begins looking at the end of the string and uses EXIT FOR to
  7518.    jump out of the loop when the first printing character is found.
  7519.  
  7520.    ' Rtrim removes trailing blanks, tabs, carriage returns,
  7521.    ' and line feeds from a string.
  7522.    SUB Rtrim(S$) STATIC
  7523.  
  7524.    J=0
  7525.  
  7526.    ' Begin at the end of the string and find the first
  7527.    ' character that isn't a blank, tab, carriage return, or
  7528.    ' line feed.
  7529.    FOR I=LEN(S$) TO 1 STEP -1
  7530.       C$=MID$(S$,I,1)
  7531.       IF C$<>" " AND C$<>CHR$(9) AND C$<>CHR$(10) AND C$<>CHR$(13) THEN
  7532.          J=I
  7533.          EXIT FOR
  7534.       END IF
  7535.    NEXT I
  7536.  
  7537.    ' Remove the unwanted trailing characters.
  7538.    S$=LEFT$(S$,J)
  7539.  
  7540.    END SUB
  7541.  
  7542.  
  7543.  ────────────────────────────────────────────────────────────────────────────
  7544.  EXP Function
  7545.  ────────────────────────────────────────────────────────────────────────────
  7546.  
  7547.  ■ Action
  7548.  
  7549.    Calculates the exponential function
  7550.  
  7551.  ■ Syntax
  7552.  
  7553.    EXP(x)
  7554.  
  7555.  ■ Remarks
  7556.  
  7557.    The EXP function returns e (the base of natural logarithms) to the power
  7558.    of x. The exponent x must be less than or equal to 88.02969. A value of x
  7559.    greater than 88.02969 produces an Overflow error message.
  7560.  
  7561.    The calculation of EXP is performed in single precision by default; if the
  7562.    argument x is double precision, EXP is calculated in double precision.
  7563.  
  7564.  ■ See Also
  7565.  
  7566.    LOG
  7567.  
  7568.  ■ Example
  7569.  
  7570.    The following program uses the EXP function to calculate the growth of a
  7571.    bacterial colony over a 15-day period. Since the growth of the population
  7572.    is related to its ever-changing size, its growth is exponential.
  7573.  
  7574.    INPUT "Initial bacterial population"; Colony0
  7575.    INPUT "Growth rate per day as a percentage of population"; Rate
  7576.    R = Rate/100 : Form$="##          ###,###"
  7577.    PRINT : PRINT "Day        Population"
  7578.    FOR T = 0 TO 15 STEP 5
  7579.        PRINT USING Form$; T, Colony0 * EXP(R*T)
  7580.    NEXT
  7581.  
  7582.  ■ Output
  7583.  
  7584.    Initial bacterial population? 10000
  7585.    Growth rate per day as a percentage of population? 10
  7586.  
  7587.    Day        Population
  7588.     0           10,000
  7589.     5           16,487
  7590.    10           27,183
  7591.    15           44,817
  7592.  
  7593.  
  7594.  ────────────────────────────────────────────────────────────────────────────
  7595.  FIELD Statement
  7596.  ────────────────────────────────────────────────────────────────────────────
  7597.  
  7598.  ■ Action
  7599.  
  7600.    Allocates space for variables in a random-access file buffer
  7601.  
  7602.  ■ Syntax
  7603.  
  7604.    FIELD «#»filenumber, fieldwidth AS stringvariable...
  7605.  
  7606.  ■ Remarks
  7607.  
  7608.    The following list describes the FIELD statement's arguments:
  7609.  
  7610.    Argument                 Description
  7611.    ──────────────────────────────────────────────────────────────────────────
  7612.    filenumber               The number used in the file's OPEN statement
  7613.  
  7614.    fieldwidth               The width of the field in the record
  7615.  
  7616.    stringvariable           The string variable that contains the date read
  7617.                             from a record or data that is used in an
  7618.                             assignment when information is written to a
  7619.                             record
  7620.    ──────────────────────────────────────────────────────────────────────────
  7621.  
  7622.    The total number of bytes that you allocate in a FIELD statement must not
  7623.    exceed the record length that you had specified when opening the file.
  7624.    Otherwise, an error message is generated that reads FIELD overflow. (The
  7625.    default record length is 128 bytes.)
  7626.  
  7627.    Any number of FIELD statements may be executed for the same file. All
  7628.    FIELD statements that have been executed remain in effect at the same
  7629.    time.
  7630.  
  7631.    All field definitions for a file are removed when the file is closed; that
  7632.    is, all strings defined as fields associated with the file are set to
  7633.    null.
  7634.  
  7635.    Do not use a variable name defined as a field in an INPUT or assignment
  7636.    statement if you wish the variable to remain a field. Once a variable name
  7637.    is a field, it points to the correct place in the random-access file
  7638.    buffer. If a subsequent INPUT or assignment statement with that variable
  7639.    name is executed, the variable's pointer no longer refers to the
  7640.    random-access record buffer, but to string space.
  7641.  
  7642.  ────────────────────────────────────────────────────────────────────────────
  7643.  NOTE
  7644.    BASIC's record variables and extended OPEN statement syntax provide a more
  7645.    convenient way to use random-access files. See Chapter 3, "File and Device
  7646.    I/O," in Programming in BASIC for an extended discussion of using record
  7647.    variables for file I/O.
  7648.  ────────────────────────────────────────────────────────────────────────────
  7649.  
  7650.  ■ Differences From Basica
  7651.  
  7652.    When a random-access file is closed with a CLOSE or RESET statement in a
  7653.    compiled program, all variables that are fields associated with that file
  7654.    are reset to null strings. When a random-access file is closed in a BASICA
  7655.    program, variables that are fields retain the last value assigned to them
  7656.    by a GET statement.
  7657.  
  7658.  ■ See Also
  7659.  
  7660.    GET, LSET, OPEN, PUT, RSET
  7661.  
  7662.  ■ Example
  7663.  
  7664.    This example illustrates a random-access file buffer with multiple
  7665.    definitions. In the first FIELD statement, the 67-byte buffer is broken up
  7666.    into five separate variables for name, address, city, state, and zip code.
  7667.    In the second FIELD statement, the same buffer is assigned entirely to one
  7668.    variable, PLIST$. The remainder of this example checks to see if ZIP$,
  7669.    which contains the zip code, falls within a certain range; if it does, the
  7670.    complete address string is printed.
  7671.  
  7672.    ' Define field and record lengths with constants.
  7673.    CONST LNAML=25, ADDRL=25, CTYL=10, STL=2, ZIPL=5
  7674.    CONST RECLEN=LNAML+ADDRL+CTYL+STL+ZIPL
  7675.  
  7676.    OPEN "MAILLIST" FOR RANDOM AS #1 LEN=RECLEN
  7677.  
  7678.    FIELD #1, LNAML AS Lnam$, ADDRL AS Addr$, CTYL AS Cty$, STL AS St$,
  7679.    ZIPL AS Zip$
  7680.    FIELD #1, RECLEN AS Plist$
  7681.  
  7682.    GET #1, 1
  7683.    ' Read the file, looking for zip codes in the range 85699 to
  7684.    ' 85801.
  7685.    DO WHILE NOT EOF(1)
  7686.       Zcheck$ = Zip$
  7687.       IF (Zcheck$ >= "85699" AND Zcheck$ <= "85801") THEN
  7688.          Info$ = Plist$
  7689.          PRINT LEFT$(Info$,25)
  7690.          PRINT MID$(Info$,26,25)
  7691.          PRINT RIGHT$(Info$,17)
  7692.       END IF
  7693.       GET #1
  7694.    LOOP
  7695.  
  7696.  
  7697.  ────────────────────────────────────────────────────────────────────────────
  7698.  FILEATTR Function
  7699.  ────────────────────────────────────────────────────────────────────────────
  7700.  
  7701.  ■ Action
  7702.  
  7703.    Returns information about an open file
  7704.  
  7705.  ■ Syntax
  7706.  
  7707.    FILEATTR(filenumber,attribute)
  7708.  
  7709.  ■ Remarks
  7710.  
  7711.    The FILEATTR function takes the following arguments:
  7712.  
  7713.    Argument                 Description
  7714.    ──────────────────────────────────────────────────────────────────────────
  7715.    filenumber               The number of an open file. This is the same
  7716.                             number used in the OPEN statement. You can use a
  7717.                             numeric expression as long as it evaluates to the
  7718.                             number of an open file.
  7719.  
  7720.    attribute                Indicates the type of information to return. When
  7721.                             attribute is 1, FILEATTR returns a code
  7722.                             indicating a file's mode (see below). When
  7723.                             attribute is 2, FILEATTR returns the file's DOS
  7724.                             file handle.
  7725.    ──────────────────────────────────────────────────────────────────────────
  7726.  
  7727.    Table R.2 lists the return values and corresponding file modes when
  7728.    attribute is 1.
  7729.  
  7730.    Table R.2   FILEATTR Mode Codes
  7731.  
  7732.    Return Value             Mode
  7733.    ──────────────────────────────────────────────────────────────────────────
  7734.    1                        INPUT
  7735.  
  7736.    2                        OUTPUT
  7737.  
  7738.    4                        RANDOM
  7739.  
  7740.    8                        APPEND
  7741.  
  7742.    32                       BINARY
  7743.    ──────────────────────────────────────────────────────────────────────────
  7744.  
  7745.  ■ See Also
  7746.  
  7747.    OPEN
  7748.  
  7749.  ■ Example
  7750.  
  7751.    The following example opens two files and prints out the DOS file handles
  7752.    and modes returned by FILEATTR:
  7753.  
  7754.  
  7755.    OPEN "tempfile.dat" FOR APPEND AS #1
  7756.    OPEN "tempfl2.dat" FOR RANDOM AS #2
  7757.  
  7758.    PRINT "Number Handle Mode"
  7759.    PRINT TAB(2);1;TAB(10);FILEATTR(1,2);TAB(15);FILEATTR(1,1)
  7760.    PRINT TAB(2);2;TAB(10);FILEATTR(2,2);TAB(15);FILEATTR(2,1)
  7761.    END
  7762.  
  7763.  ■ Output
  7764.  
  7765.    Number Handle Mode
  7766.      1       5    8
  7767.      2       6    4
  7768.  
  7769.  
  7770.  ────────────────────────────────────────────────────────────────────────────
  7771.  FILES Statement
  7772.  ────────────────────────────────────────────────────────────────────────────
  7773.  
  7774.  ■ Action
  7775.  
  7776.    Prints the names of files residing on the specified disk
  7777.  
  7778.  ■ Syntax
  7779.  
  7780.    FILES «filespec»
  7781.  
  7782.  ■ Remarks
  7783.  
  7784.    The filespec is a string variable or constant that includes either a file
  7785.    name or a path name, and an optional device designation.
  7786.  
  7787.    If you omit filespec, the FILES statement lists all the files in the
  7788.    current directory. You may use the DOS wild card characters──question
  7789.    marks (?) or asterisks (*). A question mark matches any single character
  7790.    in the file name or extension. An asterisk matches one or more characters
  7791.    starting at that position.
  7792.  
  7793.    If you use a filespec without an explicit path, the current directory is
  7794.    the default.
  7795.  
  7796.    Note that, regardless of the path name contained in filespec, the header
  7797.    printed by FILES is always the current directory.
  7798.  
  7799.  ■ Examples
  7800.  
  7801.    The following statements illustrate the use of FILES:
  7802.  
  7803.    FILES              'Shows all files on the current directory.
  7804.  
  7805.    FILES "*.BAS"      'Shows all files with the extension .BAS.
  7806.  
  7807.    FILES "B:*.*"      'Shows all files on drive B.
  7808.  
  7809.    FILES "B:"         'Equivalent to "B:*.*".
  7810.  
  7811.    FILES "TEST?.BAS"  'Shows all five-letter files whose names
  7812.                       'start with "TEST" and end with the .BAS
  7813.                       'extension.
  7814.  
  7815.    FILES "\SALES"     'If SALES is a directory, this statement
  7816.                       'displays all files in SALES; if SALES is
  7817.                       'a file in the current directory, this
  7818.                       'statement displays the name SALES.
  7819.  
  7820.  
  7821.  ────────────────────────────────────────────────────────────────────────────
  7822.  FIX Function
  7823.  ────────────────────────────────────────────────────────────────────────────
  7824.  
  7825.  ■ Action
  7826.  
  7827.    Returns the truncated integer part of x
  7828.  
  7829.  ■ Syntax
  7830.  
  7831.    FIX(x)
  7832.  
  7833.  ■ Remarks
  7834.  
  7835.    The x is a numeric expression. FIX(x) is equivalent to SGN(x)*INT(ABS(x)).
  7836.    The difference between FIX and INT is that for negative x, FIX returns the
  7837.    first negative integer greater than x, while INT returns the first
  7838.    negative integer less than x.
  7839.  
  7840.  ■ See Also
  7841.  
  7842.    CINT, INT
  7843.  
  7844.  ■ Example
  7845.  
  7846.    The following four statements illustrate the differences between INT and
  7847.    FIX:
  7848.  
  7849.  
  7850.    PRINT INT(-99.8)
  7851.    PRINT FIX(-99.8)
  7852.    PRINT INT(-99.2)
  7853.    PRINT FIX(-99.2)
  7854.  
  7855.  ■ Output
  7856.  
  7857.    -100
  7858.    -99
  7859.    -100
  7860.    -99
  7861.  
  7862.  
  7863.  ────────────────────────────────────────────────────────────────────────────
  7864.  FOR...NEXT Statement
  7865.  ────────────────────────────────────────────────────────────────────────────
  7866.  
  7867.  ■ Action
  7868.  
  7869.    Repeats a group of instructions a specified number of times
  7870.  
  7871.  ■ Syntax
  7872.  
  7873.    FOR counter = start TO end «STEP increment»
  7874.    .
  7875.    .
  7876.    .
  7877.    NEXT «counter «,counter...»»
  7878.  
  7879.  ■ Remarks
  7880.  
  7881.    The FOR statement takes the following arguments:
  7882.  
  7883.    Argument                 Description
  7884.    ──────────────────────────────────────────────────────────────────────────
  7885.    counter                  A numeric variable used as the loop counter. The
  7886.                             variable cannot be an array element or a record
  7887.                             element.
  7888.  
  7889.    start                    The initial value of the counter.
  7890.  
  7891.    end                      The final value of the counter.
  7892.  
  7893.    increment                The amount the counter is incremented each time
  7894.                             through the loop. If you do not specify STEP,
  7895.                             increment defaults to one.
  7896.    ──────────────────────────────────────────────────────────────────────────
  7897.  
  7898.    A FOR...NEXT loop executes only if start and end are consistent with
  7899.    increment. If end is greater than start, increment must be positive. If
  7900.    end is less than start, increment must be negative. This is checked at
  7901.    run-time by comparing the sign of (end - start) with the sign of step. If
  7902.    both have the same sign, the FOR...NEXT loop is entered. If not, the
  7903.    entire loop is skipped over.
  7904.  
  7905.    Within the FOR...NEXT loop, the program lines following the FOR statement
  7906.    are executed until the NEXT statement is encountered. Then counter is
  7907.    changed by the amount specified by STEP, and compared with the final
  7908.    value, end.
  7909.  
  7910.    If counter is less than or equal to end, control returns to the statement
  7911.    after the FOR statement and the process repeats. If counter is greater
  7912.    than end, the loop is exited; execution continues with the statement
  7913.    following the NEXT statement. (If STEP is negative, the loop repeats until
  7914.    counter is less than end.)
  7915.  
  7916.    If start and end have the same value, the loop executes once, regardless
  7917.    of the value of STEP. If STEP is zero, the loop repeats indefinitely.
  7918.  
  7919.    Avoid changing the value of counter within the loop. Changing the loop
  7920.    counter is poor programming practice; it makes the program more difficult
  7921.    to read and debug.
  7922.  
  7923.    You can nest FOR...NEXT loops; that is, you can place a FOR...NEXT loop
  7924.    within another FOR...NEXT loop. To ensure that nested loops work properly,
  7925.    give each loop a unique variable name as its counter. The NEXT statement
  7926.    for the inside loop must appear before the NEXT statement for the outside
  7927.    loop. The following construction is correct:
  7928.  
  7929.    FOR I = 1 TO 10
  7930.       FOR J = 1 TO 10
  7931.          FOR K = 1 TO 10
  7932.          .
  7933.          .
  7934.          .
  7935.          NEXT K
  7936.       NEXT J
  7937.    NEXT I
  7938.  
  7939.    A NEXT statement with the form
  7940.  
  7941.    NEXT K, J, I
  7942.  
  7943.    is equivalent to the following sequence of statements:
  7944.  
  7945.    NEXT K
  7946.    NEXT J
  7947.    NEXT I
  7948.  
  7949.    The EXIT FOR statement is a convenient alternative exit from FOR...NEXT
  7950.    loops. See the EXIT FOR statement.
  7951.  
  7952.  ────────────────────────────────────────────────────────────────────────────
  7953.  NOTE
  7954.    If you omit the variable in a NEXT statement, the NEXT statement matches
  7955.    the most recent FOR statement. If a NEXT statement is encountered before
  7956.    its corresponding FOR statement, an error message is generated that reads
  7957.    NEXT without FOR.
  7958.  ────────────────────────────────────────────────────────────────────────────
  7959.  
  7960.  ■ Differences From Basica
  7961.  
  7962.    Unlike BASICA, QuickBASIC supports double-precision control values (start,
  7963.    end, and counter) in its FOR...NEXT loops. However, if the control values
  7964.    fall within the range for integers, you should use integer control values
  7965.    for maximum speed.
  7966.  
  7967.  ■ Example
  7968.  
  7969.    The following example prints the first 11 columns of Pascal's triangle:
  7970.  
  7971.  
  7972.    'Print the first MAXCOL columns of Pascal's Triangle, in which
  7973.    'each number is the sum of the number immediately above it
  7974.    'and the number immediately below it in the preceding column.
  7975.  
  7976.    CONST MAXCOL=11
  7977.    DIM A(MAXCOL,MAXCOL)
  7978.    FOR M = 1 TO MAXCOL
  7979.        A(M,1) = 1 : A(M,M) = 1 'Top and bottom of each column is 1.
  7980.    NEXT
  7981.  
  7982.    FOR M = 3 TO MAXCOL
  7983.       FOR N = 2 TO M-1
  7984.          A(M,N) = A(M-1,N-1) + A(M-1,N)
  7985.       NEXT
  7986.    NEXT
  7987.    Startrow = 13                'Go to the middle of the screen.
  7988.    FOR M = 1 TO MAXCOL
  7989.       Col = 6 * M
  7990.       Row = Startrow
  7991.       FOR N = 1 TO M
  7992.          LOCATE Row,Col : PRINT A(M,N)
  7993.          Row = Row + 2        'Go down 2 rows to print next number.
  7994.       NEXT
  7995.       PRINT
  7996.       Startrow = Startrow - 1  'Next column starts 1 row above
  7997.    NEXT                        'preceding column.
  7998.  
  7999.  ■ Output
  8000.  
  8001.  
  8002.                                                      1
  8003.                                                 1
  8004.                                            1         10
  8005.                                       1         9
  8006.                                  1         8         45
  8007.                             1         7         36
  8008.                        1         6         28        120
  8009.                   1         5         21        84
  8010.              1         4         15        56        210
  8011.         1         3         10        35        126
  8012.    1         2         6         20        70        252
  8013.         1         3         10        35        126
  8014.              1         4         15        56        210
  8015.                   1         5         21        84
  8016.                        1         6         28        120
  8017.                             1         7         36
  8018.                                  1         8         45
  8019.                                       1         9
  8020.                                            1         10
  8021.                                                 1
  8022.                                                      1
  8023.  
  8024.  
  8025.  ────────────────────────────────────────────────────────────────────────────
  8026.  FRE Function
  8027.  ────────────────────────────────────────────────────────────────────────────
  8028.  
  8029.  ■ Action
  8030.  
  8031.    Returns the amount of available memory
  8032.  
  8033.  ■ Syntax 1
  8034.  
  8035.    FRE(numeric-expression)
  8036.  
  8037.  ■ Syntax 2
  8038.  
  8039.    FRE(stringexpression)
  8040.  
  8041.  ■ Remarks
  8042.  
  8043.    The FRE function returns the following values when it has a numeric
  8044.    argument (numeric-expression):
  8045.  
  8046.    Argument                 Value Returned
  8047.    ──────────────────────────────────────────────────────────────────────────
  8048.    -1                       The size, in bytes, of the largest nonstring
  8049.                             array that could be dimensioned
  8050.  
  8051.    -2                       The amount, in bytes, of unused stack space
  8052.                             available to the program
  8053.  
  8054.    Any other numeric value  The size of the next free block of string storage
  8055.    ──────────────────────────────────────────────────────────────────────────
  8056.  
  8057.    When the argument is a string expression (stringexpression), FRE returns
  8058.    the size, in bytes, of the free string storage. Before FRE returns the
  8059.    number of free bytes, it compacts the free string storage into a single
  8060.    block.
  8061.  
  8062.  ────────────────────────────────────────────────────────────────────────────
  8063.  NOTE
  8064.    FRE(-2) returns meaningful values only when a program is executing. Values
  8065.    returned by FRE(-2) are not accurate when the function is called from the
  8066.    Immediate window, during program tracing, or when watching a variable.
  8067.  ────────────────────────────────────────────────────────────────────────────
  8068.  
  8069.  ■ Example
  8070.  
  8071.    The following example shows some of the values FRE returns before and
  8072.    after dimensioning an array:
  8073.  
  8074.    ' ¢DYNAMIC
  8075.    PRINT "Before dimensioning arrays:  " FRE(""),FRE(0),FRE(-1)
  8076.    DIM LARGE%(150,150), BIG$(5000)
  8077.    PRINT "After dimensioning arrays:   " FRE(""),FRE(0),FRE(-1)
  8078.  
  8079.  ■ Output
  8080.  
  8081.    The actual values FRE will return on your own computer may be different.
  8082.  
  8083.    Before dimensioning arrays:   58420       58420       322120
  8084.    After dimensioning arrays:    38404       38404       276496
  8085.  
  8086.  
  8087.  ────────────────────────────────────────────────────────────────────────────
  8088.  FREEFILE Function
  8089.  ────────────────────────────────────────────────────────────────────────────
  8090.  
  8091.  ■ Action
  8092.  
  8093.    Returns the next free BASIC file number
  8094.  
  8095.  ■ Syntax
  8096.  
  8097.    FREEFILE
  8098.  
  8099.  ■ Remarks
  8100.  
  8101.    The FREEFILE function returns the next valid unused file number.
  8102.  
  8103.    You can use this function to avoid having SUB or FUNCTION procedures use
  8104.    file numbers that are already in use.
  8105.  
  8106.  ■ Example
  8107.  
  8108.    The example below uses FREEFILE to obtain a file number for opening a
  8109.    file:
  8110.  
  8111.    INPUT "Enter file name ", Filename$
  8112.    Filenum = FREEFILE
  8113.    OPEN Filename$ for Input as Filenum
  8114.    PRINT Filename$;" Opened as File # "; Filenum
  8115.  
  8116.  ■ Output
  8117.  
  8118.    Enter file name: Data.dat
  8119.  
  8120.    Data.dat Opened as File # 1
  8121.  
  8122.  
  8123.  ────────────────────────────────────────────────────────────────────────────
  8124.  FUNCTION Statement
  8125.  ────────────────────────────────────────────────────────────────────────────
  8126.  
  8127.  ■ Action
  8128.  
  8129.    Declares the name, the parameters, and the code that form the body of a
  8130.    FUNCTION procedure
  8131.  
  8132.  ■ Syntax
  8133.  
  8134.    FUNCTION name «(parameterlist)»«STATIC»
  8135.     .
  8136.     .
  8137.     .
  8138.     name = expression
  8139.     .
  8140.     .
  8141.     .
  8142.    END FUNCTION
  8143.  
  8144.  ■ Remarks
  8145.  
  8146.    The following list describes the parts of the FUNCTION statement:
  8147.  
  8148. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  8149.    Part                     Description
  8150.    Part                     Description
  8151.    ──────────────────────────────────────────────────────────────────────────
  8152.    name                     The name of the function. FUNCTION names follow
  8153.                             the same rules as BASIC variable names and can
  8154.                             include a type-declaration character (%, &, !, #,
  8155.                             or $). Note that the type of the name determines
  8156.                             the type of value the function returns. For
  8157.                             example, to create a function that returns a
  8158.                             string, you would include a dollar sign in the
  8159.                             name or give it a name defined as a string name
  8160.                             by a DEFSTR statement.
  8161.  
  8162.    parameterlist            The list of variables, separated by commas,
  8163.                             passed to the FUNCTION. The parameters are passed
  8164.                             by reference, so any change to a parameter's
  8165.                             value inside the function changes its value in
  8166.                             the calling program.
  8167.  
  8168.    STATIC                   Indicates that the function's local variables are
  8169.                             to be saved between calls. Without STATIC, the
  8170.                             local variables are allocated each time the
  8171.    Part                     Description
  8172.    ──────────────────────────────────────────────────────────────────────────
  8173.                            local variables are allocated each time the
  8174.                             function is invoked, and the variables' values
  8175.                             are lost when the function returns to the calling
  8176.                             program. The STATIC attribute does not affect
  8177.                             variables that are used in a FUNCTION but
  8178.                             declared outside the FUNCTION in DIM or COMMON
  8179.                             statements by use of the SHARED attribute.
  8180.  
  8181.    expression               The return value of the function. A FUNCTION
  8182.                             returns a value by assigning a value to the
  8183.                             function name. If no value is assigned to the
  8184.                             FUNCTION name, the FUNCTION returns a default
  8185.                             value: a numeric function returns a value of
  8186.                             zero, and a string function returns the null
  8187.                             string ("").
  8188.    ──────────────────────────────────────────────────────────────────────────
  8189.  
  8190.  
  8191.    A parameterlist has the following syntax:
  8192.    variable«( )»« AS type»«, variable«( )»« AS type»...»
  8193.  
  8194.    A variable is any valid BASIC variable. The optional type can be either
  8195.    INTEGER, LONG, SINGLE, DOUBLE, STRING, or a user-defined type.
  8196.  
  8197.    Earlier versions of BASIC required the number of dimensions in parentheses
  8198.    after an array name. The number of dimensions is no longer required. Only
  8199.    the parentheses are required to indicate the parameter is an array. For
  8200.    example, the following statement indicates that both Keywords$ and
  8201.    KeywordTypes are arrays:
  8202.  
  8203.    FUNCTION ParseLine(Keywords$(),KeywordTypes())
  8204.  
  8205.    A FUNCTION procedure is like a SUB procedure: it can accept parameters,
  8206.    perform a series of statements, and change the values of its parameters.
  8207.    Unlike a SUB, a FUNCTION is used in an expression in the same manner as a
  8208.    BASIC intrinsic function.
  8209.  
  8210.    Like SUB procedures, FUNCTION procedures use local variables. Any variable
  8211.    not in the parameter list is local to the FUNCTION unless it is declared
  8212.    as a shared variable in a SHARED statement, or unless the variable appears
  8213.    in a DIM or COMMON statement with the SHARED attribute.
  8214.  
  8215.    To return a value from a function, assign the value to the function name.
  8216.    For example, in a function named BinarySearch, you might assign the value
  8217.    of the constant FALSE to the name to indicate the value was not found:
  8218.  
  8219.    FUNCTION BinarySearch(...)
  8220.    CONST FALSE=0
  8221.    .
  8222.    .
  8223.    .
  8224.  
  8225.    ' Value not found. Return a value of FALSE.
  8226.  
  8227.       IF Lower>Upper THEN
  8228.          BinarySearch=FALSE
  8229.          EXIT FUNCTION
  8230.       END IF
  8231.    .
  8232.    .
  8233.    .
  8234.    END FUNCTION
  8235.  
  8236.    Using the STATIC keyword slightly increases execution speed. STATIC is not
  8237.    usually used with recursive FUNCTION procedures. See the examples below.
  8238.  
  8239.    The EXIT FUNCTION statement provides an alternative exit from a FUNCTION.
  8240.    See the EXIT statement.
  8241.  
  8242.    Because BASIC may rearrange arithmetic expressions to attain greater
  8243.    efficiency, avoid using FUNCTION procedures that change program variables
  8244.    in arithmetic expressions. Also avoid using FUNCTION procedures that
  8245.    perform I/O in I/O statements.
  8246.  
  8247.    QuickBASIC FUNCTION procedures are recursive──they can call themselves to
  8248.    perform a given task. See the second example below and Chapter 4,
  8249.    "Programs and Modules."
  8250.  
  8251.  ■ See Also
  8252.  
  8253.    DECLARE (BASIC), DEF FN, EXIT, STATIC, SUB
  8254.  
  8255.  ■ Examples
  8256.  
  8257.    The following example uses a function to count the number of vowels in a
  8258.    string:
  8259.  
  8260.    ' Function definition.
  8261.    FUNCTION NumVowels (A$) STATIC
  8262.       Num = 0
  8263.       ' Go through A$ a character at a time.
  8264.       FOR I = 1 TO LEN (A$)
  8265.          C$ = UCASE$ (MID$(A$,I,1))
  8266.          IF INSTR ("AEIOU",C$)<> 0 THEN
  8267.             ' Find a vowel--count it.
  8268.             Num = Num + 1
  8269.          END IF
  8270.       NEXT I
  8271.       NumVowels = Num
  8272.    END FUNCTION
  8273.  
  8274.    A$ = "The ultimate answer to the ultimate question is 42"
  8275.    PRINT CHR$(34)+A$+CHR$(34)
  8276.    PRINT "The number of vowels in the string is :";NumVowels (A$)
  8277.  
  8278.  ■ Output
  8279.  
  8280.    "The ultimate answer to the ultimate question is 42"
  8281.    The number of vowels in the string is : 18
  8282.  
  8283.    The following example uses a recursive function (a function that calls
  8284.    itself) to find the length of a string. Notice that the STATIC keyword is
  8285.    not used.
  8286.  
  8287.    FUNCTION StrLen(X$)
  8288.       IF X$ = "" THEN
  8289.          ' The length of a null string is zero.
  8290.          StrLen=0
  8291.       ELSE
  8292.          ' Non-null string--make a recursive call.
  8293.          ' The length of a non-null string is 1
  8294.          ' plus the length of the rest of the string.
  8295.          StrLen=1+StrLen(MID$(X$,2))
  8296.       END IF
  8297.    END FUNCTION
  8298.  
  8299.    LINE INPUT "Enter a string: ",InString$
  8300.    PRINT "The string length is"; StrLen(InString$)
  8301.  
  8302.  ■ Output
  8303.  
  8304.    Enter a string: Once upon a time
  8305.    The string length is 16
  8306.  
  8307.  
  8308.  ────────────────────────────────────────────────────────────────────────────
  8309.  GET Statement──Graphics
  8310.  ────────────────────────────────────────────────────────────────────────────
  8311.  
  8312.  ■ Action
  8313.  
  8314.    Stores graphic images from the screen
  8315.  
  8316.  ■ Syntax
  8317.  
  8318.    GET «STEP»(x1,y1) - «STEP»(x2,y2),arrayname«(indices)»
  8319.  
  8320.  ■ Remarks
  8321.  
  8322.    The list below describes the parts of the GET statement:
  8323.  
  8324. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  8325.    Part                     Description
  8326.    ──────────────────────────────────────────────────────────────────────────
  8327.    x1,y1,x2,y2              Coordinates marking a rectangular area on the
  8328.                             screen. The placeholders x1, y1, x2, and y2 are
  8329.                             numeric expressions that are the coordinates of
  8330.                             diagonally opposite corners of the rectangle.
  8331.  
  8332.    STEP                     Keyword indicating that coordinates are relative
  8333.                             to the most recently plotted point. For example,
  8334.                             if the last point plotted were (10,10), then the
  8335.                             actual coordinates referred to by STEP (5,10)
  8336.                             would be (5+10,10+10) or (15,20). If the second
  8337.                             coordinate pair in a GET statement has a STEP
  8338.                             argument, it is relative to the first coordinate
  8339.    Part                     Description
  8340.    ──────────────────────────────────────────────────────────────────────────
  8341.                            argument, it is relative to the first coordinate
  8342.                             pair in the statement.
  8343.  
  8344.    arrayname                Name assigned to the array that holds the image.
  8345.                             This array can be of any numeric type; its
  8346.                             dimensions must be large enough to hold the
  8347.                             entire image.
  8348.  
  8349.    indices                  Numeric constants or variables indicating the
  8350.                             element of the array where the saved image
  8351.                             starts.
  8352.    ──────────────────────────────────────────────────────────────────────────
  8353.  
  8354.  
  8355.    The GET statement transfers a screen image into the array specified by
  8356.    arrayname. The PUT statement, associated with GET, transfers the image
  8357.    stored in the array onto the screen.
  8358.  
  8359.    The following formula gives the required size of the array in bytes:
  8360.  
  8361.    4 + INT(((x2 - x1 + 1) * (bits-per-pixel-per-plane) + 7)/8) * planes *
  8362.    ((y2 - y1) + 1)
  8363.  
  8364.    The bits-per-pixel-per-plane and planes values depend on the specification
  8365.    set in the SCREEN statement. Table R.3 shows the number of bits per pixel
  8366.    per plane and the number of planes for each screen mode.
  8367.  
  8368.    Table R.3   Values for Bits per Pixel per Plane and for Planes
  8369.  
  8370. ╓┌─┌────────────────────────┌───────────────────────┌────────────────────────╖
  8371.                             Bits per Pixel
  8372.    Screen Mode              per Plane               Planes
  8373.    ──────────────────────────────────────────────────────────────────────────
  8374.    1                        2                       1
  8375.  
  8376.    2                        1                       1
  8377.  
  8378.    7                        1                       4
  8379.  
  8380.    8                        1                       4
  8381.                             Bits per Pixel
  8382.    Screen Mode              per Plane               Planes
  8383.    ──────────────────────────────────────────────────────────────────────────
  8384.   8                        1                       4
  8385.  
  8386.    9                        1                       2 (if 64K of EGA memory)
  8387.  
  8388.                                                     4 (if > 64K EGA memory)
  8389.  
  8390.    10                       1                       2
  8391.  
  8392.    11                       1                       1
  8393.  
  8394.    12                       1                       4
  8395.  
  8396.    13                       8                       1
  8397.    ──────────────────────────────────────────────────────────────────────────
  8398.  
  8399.  
  8400.    The bytes per element of an array are as follows:
  8401.  
  8402.    ■ Two bytes for an integer array element
  8403.  
  8404.    ■ Four bytes for a long-integer array element
  8405.  
  8406.    ■ Four bytes for a single-precision array element
  8407.  
  8408.    ■ Eight bytes for a double-precision array element
  8409.  
  8410.    For example, suppose you wanted to use the GET statement to store an image
  8411.    in high resolution (SCREEN 2). If the coordinates of the upper-left corner
  8412.    of the image are (0,0), and the coordinates of the lower- right corner are
  8413.    (32,32), then the required size of the array in bytes is 4 + INT((33 * 1 +
  8414.    7)/8) * 1 * (33), or 169. This means an integer array with 85 elements
  8415.    would be large enough to hold the image.
  8416.  
  8417.    Unless the array type is integer or long, the contents of an array after a
  8418.    GET appear meaningless when inspected directly. Examining or manipulating
  8419.    noninteger arrays containing graphics images may cause run-time errors.
  8420.  
  8421.    One of the most useful things that can be done with GET and PUT is
  8422.    animation. See Chapter 5, "Graphics," in Programming in BASIC for a
  8423.    discussion of animation.
  8424.  
  8425.  ■ See Also
  8426.  
  8427.    PUT (Graphics)
  8428.  
  8429.  ■ Example
  8430.  
  8431.    See the example for BSAVE.
  8432.  
  8433.  
  8434.  ────────────────────────────────────────────────────────────────────────────
  8435.  GET Statement──File I/O
  8436.  ────────────────────────────────────────────────────────────────────────────
  8437.  
  8438.  ■ Action
  8439.  
  8440.    Reads from a disk file into a random-access buffer or variable
  8441.  
  8442.  ■ Syntax
  8443.  
  8444.    GET «#»filenumber«,«recordnumber»«,variable»»
  8445.  
  8446.  ■ Remarks
  8447.  
  8448.    The following list describes the GET statement's arguments:
  8449.  
  8450. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  8451.    Argument                 Description
  8452.    ──────────────────────────────────────────────────────────────────────────
  8453.    filenumber               The number used in the OPEN statement to open the
  8454.                             file.
  8455.  
  8456.    recordnumber             For random-access files, the number of the record
  8457.                             to be read. For binary-mode files, the byte
  8458.                             position in the file where reading starts. The
  8459.                             first record or byte position in a file is 1. If
  8460.                             you omit recordnumber, the next record or byte
  8461.                             (the one after the last GET or PUT, or the one
  8462.                             pointed to by the last SEEK) is read into the
  8463.                             buffer. The largest possible record number is
  8464.                             2^31-1, or 2,147,483,647.
  8465.    Argument                 Description
  8466.    ──────────────────────────────────────────────────────────────────────────
  8467.                            2^31-1, or 2,147,483,647.
  8468.  
  8469.    variable                 The variable used to receive input from the file.
  8470.                             If you use a variable, you do not need to use
  8471.                             CVD, CVL, CVI, or CVS to convert record fields to
  8472.                             numbers. You may not use a FIELD statement with
  8473.                             the file if you use the variable argument.
  8474.  
  8475.                             For random-access files, you can use any variable
  8476.                             as long as the length of the variable is less
  8477.                             than or equal to the length of the record.
  8478.                             Usually, a record variable defined to match the
  8479.                             fields in a data record is used. For binary-mode
  8480.                             files, you can use any variable. The GET
  8481.                             statement reads as many bytes as there are in the
  8482.                             variable.
  8483.  
  8484.                             When you use a variable-length string variable,
  8485.                             the statement reads as many bytes as there are
  8486.    Argument                 Description
  8487.    ──────────────────────────────────────────────────────────────────────────
  8488.                            the statement reads as many bytes as there are
  8489.                             characters in the string's value. For example,
  8490.                             the following two statements read 10 bytes from
  8491.                             file number 1:
  8492.  
  8493.                             VarStrings$=STRING$ (10, " ")
  8494.  
  8495.                             GET #1,,VarString$
  8496.  
  8497.                             See the examples and Chapter 3, "File and Device
  8498.                             I/O," in Programming in BASIC for more
  8499.                             information about using variables rather than
  8500.                             FIELD statements for random-access files. A
  8501.                             record cannot be longer than 32,767 bytes.
  8502.    ──────────────────────────────────────────────────────────────────────────
  8503.  
  8504.  
  8505.    You may omit the recordnumber, the variable, or both. If you omit the
  8506.    recordnumber but include the variable, you must still include the commas:
  8507.  
  8508.    GET #4,,FileBuffer
  8509.  
  8510.    If you omit both arguments, you do not include the commas:
  8511.  
  8512.    GET #4
  8513.  
  8514.    The GET and PUT statements allow fixed-length input and output for BASIC
  8515.    communications files. Use GET carefully because if there is a
  8516.    communications failure, GET waits indefinitely for recordnumber
  8517.    characters.
  8518.  
  8519.  ────────────────────────────────────────────────────────────────────────────
  8520.  NOTE
  8521.    When you use GET with the FIELD statement, you can use either INPUT # or
  8522.    LINE INPUT # after a GET statement to read characters from the
  8523.    random-access file buffer. You may use the EOF function after GET to see
  8524.    if the GET went beyond the end of the file.
  8525.  ────────────────────────────────────────────────────────────────────────────
  8526.  
  8527.  ■ See Also
  8528.  
  8529.    CVI, CVS, CVL, CVD; FIELD; INPUT #;
  8530.    LINE INPUT #; LSET; MKD$, MKI$, MKL$, MKS$;
  8531.    PUT (File I/O); RSET; TYPE
  8532.  
  8533.  ■ Example
  8534.  
  8535.    The following program opens the file TESTDAT.DAT for random access and
  8536.    displays the contents on the screen:
  8537.  
  8538.    '  Read and display the contents of a file containing a
  8539.    '  name of up to 20 characters and a test score.
  8540.  
  8541.    '  Define record fields.
  8542.    TYPE TestRecord
  8543.       NameField  AS STRING*20
  8544.       ScoreField AS SINGLE
  8545.    END TYPE
  8546.  
  8547.    '  Open the test data file.
  8548.    DIM FileBuffer AS TestRecord
  8549.    OPEN "TESTDAT.DAT" FOR RANDOM AS #1 LEN=LEN(FileBuffer)
  8550.  
  8551.    '  Calculate number of records in the file.
  8552.    Max=LOF(1)/LEN(FileBuffer)
  8553.  
  8554.    '  Read and print contents of each record.
  8555.    FOR I=1 TO Max
  8556.       GET #1,I,FileBuffer
  8557.       PRINT FileBuffer.NameField,FileBuffer.ScoreField
  8558.    NEXT I
  8559.  
  8560.    CLOSE #1
  8561.  
  8562.  
  8563.  ────────────────────────────────────────────────────────────────────────────
  8564.  GOSUB...RETURN Statements
  8565.  ────────────────────────────────────────────────────────────────────────────
  8566.  
  8567.  ■ Action
  8568.  
  8569.    Branches to, and returns from, a subroutine
  8570.  
  8571.  ■ Syntax
  8572.  
  8573.    GOSUB {linelabel1 | linenumber1 }
  8574.    .
  8575.    .
  8576.    .
  8577.    RETURN «linelabel2 | linenumber2 »
  8578.  
  8579.  ■ Remarks
  8580.  
  8581.    The GOSUB...RETURN statements take the following arguments:
  8582.  
  8583.    Argument                 Description
  8584.    ──────────────────────────────────────────────────────────────────────────
  8585.    linelabel1, linenumber1  The line number or line label that is the first
  8586.                             line of the subroutine.
  8587.  
  8588.    linelabel2, linenumber2  The line label or line number where the
  8589.                             subroutine returns.
  8590.    ──────────────────────────────────────────────────────────────────────────
  8591.  
  8592.  ────────────────────────────────────────────────────────────────────────────
  8593.  NOTE
  8594.    BASIC's SUB and FUNCTION procedures provide a more well-structured
  8595.    alternative to GOSUB... RETURN subroutines.
  8596.  ────────────────────────────────────────────────────────────────────────────
  8597.  
  8598.    In addition to RETURN with no argument, BASIC supports RETURN with a line
  8599.    label or line number allowing a return from a subroutine to the statement
  8600.    having the specified line number or label, instead of returning to the
  8601.    statement after the GOSUB statement. Use this line-specific type of return
  8602.    with care.
  8603.  
  8604.    You may call a subroutine any number of times in a program. You may also
  8605.    call a subroutine from within another subroutine. How deeply you can nest
  8606.    subroutines is limited only by the available stack space (you may increase
  8607.    the stack space with the CLEAR statement). Subroutines that call
  8608.    themselves (recursive subroutines) can easily run out of stack space.
  8609.    RETURN with a line label or line number can only return control to a
  8610.    statement in the module-level code, not procedure-level code. See the
  8611.    example program.
  8612.  
  8613.    A subroutine may contain more than one RETURN statement. Simple RETURN
  8614.    statements (without the linelabel2, linenumber2 option) in a subroutine
  8615.    make BASIC branch back to the statement following the most recent GOSUB
  8616.    statement.
  8617.  
  8618.    Subroutines may appear anywhere in the program, but it is good programming
  8619.    practice to make them readily distinguishable from the main program. To
  8620.    prevent inadvertent entry into a subroutine, precede it with a STOP, END,
  8621.    or GOTO statement that directs program control around the subroutine.
  8622.  
  8623.  ────────────────────────────────────────────────────────────────────────────
  8624.  IMPORTANT
  8625.    The preceding discussion of subroutines applies only to the targets of
  8626.    GOSUB statements, not subprograms delimited by SUB statements. Entering
  8627.    and exiting SUB blocks with GOSUB...RETURN statements is not supported.
  8628.  ────────────────────────────────────────────────────────────────────────────
  8629.  
  8630.  ■ See Also
  8631.  
  8632.    RETURN, SUB
  8633.  
  8634.  ■ Example
  8635.  
  8636.    The following example shows the use of RETURN linelabel statements in
  8637.    module-level code:
  8638.  
  8639.    PRINT "in module-level code"
  8640.    GOSUB Sub1
  8641.    PRINT "this line in main routine should be skipped"
  8642.    Label1:
  8643.       PRINT "back in module-level code"
  8644.       END
  8645.  
  8646.    Sub1:
  8647.       PRINT "in subroutine one"
  8648.       GOSUB Sub2
  8649.       PRINT "this line in subroutine one should be skipped"
  8650.    Label2:
  8651.       PRINT "back in subroutine one"
  8652.       RETURN Label1
  8653.  
  8654.    Sub2:
  8655.       PRINT "in subroutine two"
  8656.       RETURN Label2
  8657.  
  8658.  ■ Output
  8659.  
  8660.    in module-level code
  8661.    in subroutine one
  8662.    in subroutine two
  8663.    back in subroutine one
  8664.    back in module-level code
  8665.  
  8666.  
  8667.  ────────────────────────────────────────────────────────────────────────────
  8668.  GOTO Statement
  8669.  ────────────────────────────────────────────────────────────────────────────
  8670.  
  8671.  ■ Action
  8672.  
  8673.    Branches unconditionally to the specified line
  8674.  
  8675.  ■ Syntax
  8676.  
  8677.    GOTO {linelabel | linenumber}
  8678.  
  8679.  ■ Remarks
  8680.  
  8681.    The GOTO statement provides a way to branch unconditionally to another
  8682.    line (linelabel or linenumber). A GOTO statement can branch only to
  8683.    another statement at the same level of a program. You cannot use GOTO to
  8684.    enter or exit a SUB, FUNCTION, or multiline DEF FN function. You can,
  8685.    however, use GOTO to control program flow within any of these program
  8686.    structures.
  8687.  
  8688.    It is good programming practice to use structured control statements
  8689.    (DO...LOOP, FOR, IF..THEN...ELSE, SELECT CASE) instead of GOTO statements
  8690.    because a program with many GOTO statements is difficult to read and
  8691.    debug.
  8692.  
  8693.  ■ Example
  8694.  
  8695.    The following program prints the area of the circle with the input radius:
  8696.  
  8697.    PRINT "Input 0 to end."
  8698.    Start:
  8699.       INPUT R
  8700.       IF R = 0 THEN
  8701.         END
  8702.       ELSE
  8703.          A = 3.14 * R^2
  8704.          PRINT "Area =";A
  8705.       END IF
  8706.    GOTO Start
  8707.  
  8708.  ■ Output
  8709.  
  8710.    Input 0 to end.
  8711.    ? 5
  8712.    Area = 78.5
  8713.    ? 0
  8714.  
  8715.  
  8716.  ────────────────────────────────────────────────────────────────────────────
  8717.  HEX$ Function
  8718.  ────────────────────────────────────────────────────────────────────────────
  8719.  
  8720.  ■ Action
  8721.  
  8722.    Returns a string that represents the hexadecimal value of the decimal
  8723.    argument expression
  8724.  
  8725.  ■ Syntax
  8726.  
  8727.    HEX$(expression)
  8728.  
  8729.  ■ Remarks
  8730.  
  8731.    The argument expression is rounded to an integer or, if the expression is
  8732.    outside the integer range, a long integer before the HEX$ function
  8733.    evaluates it.
  8734.  
  8735.  ■ See Also
  8736.  
  8737.    OCT$
  8738.  
  8739.  ■ Example
  8740.  
  8741.    The following example prints the hexadecimal representation of an input
  8742.    value:
  8743.  
  8744.    INPUT X
  8745.    A$ = HEX$(X)
  8746.    PRINT X "decimal is " A$ " hexadecimal"
  8747.  
  8748.  ■ Output
  8749.  
  8750.    ? 32
  8751.     32 decimal is 20 hexadecimal
  8752.  
  8753.  
  8754.  
  8755.  
  8756.  
  8757.  
  8758.  
  8759.  
  8760.  
  8761.  ────────────────────────────────────────────────────────────────────────────
  8762.  IF...THEN...ELSE Statement
  8763.  ────────────────────────────────────────────────────────────────────────────
  8764.  
  8765.  ■ Action
  8766.  
  8767.    Allows conditional execution, based on the evaluation of a Boolean
  8768.    expression
  8769.  
  8770.  ■ Syntax 1 (Single Line)
  8771.  
  8772.    IF booleanexpression THEN thenpart «ELSE elsepart»
  8773.  
  8774.  ■ Syntax 2 (Block)
  8775.  
  8776.    IF booleanexpression1 THEN
  8777.          «statementblock-1»
  8778.    «ELSEIF booleanexpression2 THEN
  8779.          «statementblock-2»»
  8780.    .
  8781.    .
  8782.    .
  8783.    «ELSE
  8784.          «statementblock-n»»
  8785.    END IF
  8786.  
  8787.  ■ Remarks
  8788.  
  8789.    The single-line form of the statement is best used for short,
  8790.    straightforward tests where only one action is taken.
  8791.  
  8792.    The block form provides several advantages:
  8793.  
  8794.    ■ The block form provides more structure and flexibility than the
  8795.      single-line form by allowing conditional branches across several lines.
  8796.  
  8797.    ■ With the block form, more complex conditions can be tested.
  8798.  
  8799.    ■ The block form lets you use longer statements and structures within the
  8800.      THEN...ELSE portion of the statement.
  8801.  
  8802.    ■ The block form allows your program's structure to be guided by logic
  8803.      rather than by how many statements fit on a line.
  8804.  
  8805.    Programs that use block-form IF...THEN...ELSE are usually easier to read,
  8806.    maintain, and debug.
  8807.  
  8808.    The single-line form is never required. Any program using single-line
  8809.    IF...THEN...ELSE statements can be written using block form.
  8810.  
  8811.    SINGLE-LINE IF...THEN...ELSE
  8812.  
  8813.    The following list describes the parts of the single-line form:
  8814.  
  8815.    Part                     Description
  8816.    ──────────────────────────────────────────────────────────────────────────
  8817.    booleanexpression        Any expression that evaluates to true (nonzero)
  8818.                             or false (zero).
  8819.  
  8820.    thenpart, elsepart       The statements or branches performed when
  8821.                             booleanexpression is true (thenpart) or false
  8822.                             (elsepart). Both parts have the same syntax,
  8823.                             which is described below.
  8824.    ──────────────────────────────────────────────────────────────────────────
  8825.  
  8826.    The thenpart and the elsepart both have the following syntax:
  8827.  
  8828.    {statements | «GOTO» linenumber | GOTO linelabel }
  8829.  
  8830.    The following list describes the parts of the thenpart and elsepart
  8831.    syntax:
  8832.  
  8833.    Part                     Description
  8834.    ──────────────────────────────────────────────────────────────────────────
  8835.    statements               One or more BASIC statements, separated by colons
  8836.  
  8837.    linenumber               A valid BASIC program line number
  8838.  
  8839.    linelabel                A valid BASIC line label
  8840.    ──────────────────────────────────────────────────────────────────────────
  8841.  
  8842.    Note that GOTO is optional with a line number but is required with a line
  8843.    label.
  8844.  
  8845.    The thenpart is executed if the booleanexpression is true; if the
  8846.    booleanexpression is false, the elsepart is executed. If the ELSE clause
  8847.    is not present, control passes to the next statement in the program.
  8848.  
  8849.    You can have multiple statements with a condition, but they must be on the
  8850.    same line and separated by colons:
  8851.  
  8852.    IF A > 10 THEN A=A+1:B=B+A:LOCATE 10,22:PRINT B,A
  8853.  
  8854.    BLOCK IF...THEN...ELSE
  8855.  
  8856.    The following list describes the parts of the block IF...THEN...ELSE:
  8857.  
  8858.    Part                     Description
  8859.    ──────────────────────────────────────────────────────────────────────────
  8860.    booleanexpression1,      Any expression that evaluates to true (nonzero)
  8861.    booleanexpression2       or false (zero)
  8862.  
  8863.    statementblock-1,        One or more BASIC statements on one or more lines
  8864.    statementblock-2,
  8865.    statementblock-n
  8866.    ──────────────────────────────────────────────────────────────────────────
  8867.  
  8868.    In executing a block-form IF, QuickBASIC tests booleanexpression1, the
  8869.    first Boolean expression. If the Boolean expression is true (nonzero), the
  8870.    statements following THEN are executed. If the first Boolean expression is
  8871.    false (zero), QuickBASIC begins evaluating each ELSEIF condition in turn.
  8872.    When QuickBASIC finds a true condition, the statements following the
  8873.    associated THEN are executed. If none of the ELSEIF conditions are true,
  8874.    the statements following the ELSE are executed. After the statements
  8875.    following a THEN or ELSE are executed, the program continues with the
  8876.    statement following the END IF.
  8877.  
  8878.    The ELSE and ELSEIF blocks are both optional. You can have as many ELSEIF
  8879.    clauses as you would like in a block IF. Any of the statement blocks can
  8880.    contain nested block IF statements.
  8881.  
  8882.    QuickBASIC looks at what appears after the THEN keyword to determine
  8883.    whether or not an IF statement is a block IF. If anything other than a
  8884.    comment appears after THEN, the statement is treated as a single-line IF
  8885.    statement.
  8886.  
  8887.    A block IF statement must be the first statement on a line. The ELSE,
  8888.    ELSEIF, and END IF parts of the statement can only have a line number or
  8889.    line label in front of them. The block must end with an END IF statement.
  8890.  
  8891.    For more information, see Chapter 1, "Control-Flow Structures," in
  8892.    Programming in BASIC.
  8893.  
  8894.  ■ See Also
  8895.  
  8896.    SELECT CASE
  8897.  
  8898.  ■ Examples
  8899.  
  8900.    The following program fragments demonstrate the use of single-line and
  8901.    block IF...THEN...ELSE and illustrate the differences. The first example
  8902.    demonstrates the single-line IF...THEN...ELSE form:
  8903.  
  8904.    DO
  8905.      INPUT "Enter a number greater than 0 and less than 10,000:",X
  8906.      IF X>=0 AND X<10000 THEN EXIT DO ELSE PRINT X;"out of range"
  8907.    LOOP
  8908.    IF X<10 THEN Y=1 ELSE IF X<100 THEN Y=2 ELSE IF X<1000 THEN Y=3 ELSE
  8909.    Y=4
  8910.    PRINT "The number has";Y;"digits"
  8911.  
  8912.    In the second example the block IF...THEN...ELSE makes the code more
  8913.    readable and more powerful:
  8914.  
  8915.    DO
  8916.       INPUT "Enter a number greater than 0 and less than 100,000:",X
  8917.       IF X>0 AND X<100000 THEN
  8918.          EXIT DO
  8919.       ELSE
  8920.          PRINT X;"out of range"
  8921.       END IF
  8922.    LOOP
  8923.    IF X<10 THEN
  8924.       Y=1
  8925.    ELSEIF X<100 THEN
  8926.       Y=2
  8927.    ELSEIF X<1000 THEN
  8928.       Y=3
  8929.    ELSEIF X<10000 THEN
  8930.       Y=4
  8931.    ELSE
  8932.       Y=5
  8933.    END IF
  8934.    PRINT "The number has";Y;"digits"
  8935.  
  8936.  
  8937.  ────────────────────────────────────────────────────────────────────────────
  8938.  INKEY$ Function
  8939.  ────────────────────────────────────────────────────────────────────────────
  8940.  
  8941.  ■ Action
  8942.  
  8943.    Reads a character from the keyboard
  8944.  
  8945.  ■ Syntax
  8946.  
  8947.    INKEY$
  8948.  
  8949.  ■ Remarks
  8950.  
  8951.    The INKEY$ function returns a one- or two-byte string containing a
  8952.    character read from the standard input device. A null string is returned
  8953.    if no character is waiting there. A one-character string contains the
  8954.    actual character read from the keyboard, while a two-character string
  8955.    indicates an extended code, the first character of which is hexadecimal
  8956.    00. For a complete list of these codes, see Appendix A, "Keyboard Scan
  8957.    Codes and ASCII Character Codes."
  8958.  
  8959.    The standard input device is usually the keyboard. INKEY$ does not echo
  8960.    characters to the screen; instead, all characters are passed through to
  8961.    the program except for these:
  8962.  
  8963.    ■ CTRL+BREAK, which halts program execution
  8964.  
  8965.    ■ CTRL+ALT+DEL, which does a system reboot
  8966.  
  8967.    ■ CTRL+NUMLOCK, which causes program execution to pause
  8968.  
  8969.    ■ PRTSC, which prints the screen
  8970.  
  8971.  ■ Example
  8972.  
  8973.    The following program fragment shows a common use of INKEY$──pausing until
  8974.    the user presses a key:
  8975.  
  8976.    PRINT "Press any key to continue..."
  8977.    DO
  8978.    LOOP WHILE INKEY$=""
  8979.  
  8980.  
  8981.  ────────────────────────────────────────────────────────────────────────────
  8982.  INP Function
  8983.  ────────────────────────────────────────────────────────────────────────────
  8984.  
  8985.  ■ Action
  8986.  
  8987.    Returns the byte read from an I/O port
  8988.  
  8989.  ■ Syntax
  8990.  
  8991.    INP(port)
  8992.  
  8993.  ■ Remarks
  8994.  
  8995.    The port must be an integer in the range 0-65,535. The INP function
  8996.    complements the OUT statement.
  8997.  
  8998.    The INP and OUT statements give a BASIC program direct control over the
  8999.    hardware in a system through the I/O ports. These statements must be used
  9000.    carefully because they directly manipulate the system hardware.
  9001.  
  9002.  ■ See Also
  9003.  
  9004.    OUT, WAIT
  9005.  
  9006.  ■ Example
  9007.  
  9008.    See the example for the OUT statement.
  9009.  
  9010.  
  9011.  ────────────────────────────────────────────────────────────────────────────
  9012.  INPUT Statement
  9013.  ────────────────────────────────────────────────────────────────────────────
  9014.  
  9015.  ■ Action
  9016.  
  9017.    Allows input from the keyboard during program execution
  9018.  
  9019.  ■ Syntax
  9020.  
  9021.    INPUT«;»«"promptstring"{; | ,}» variablelist
  9022.  
  9023.  ■ Remarks
  9024.  
  9025.    The following list describes the parts of the INPUT statement:
  9026.  
  9027.    Part                     Description
  9028.    ──────────────────────────────────────────────────────────────────────────
  9029.    ;                        A semicolon immediately after INPUT keeps the
  9030.                             cursor on the same line after the user presses
  9031.                             ENTER.
  9032.  
  9033.    promptstring             A string constant printed before the prompt
  9034.                             character.
  9035.  
  9036.    ;                        Prints a question mark at the end of the
  9037.                             promptstring.
  9038.  
  9039.    ,                        Prints the promptstring without a question mark.
  9040.  
  9041.    variablelist             A list of variables, separated by commas, to
  9042.                             accept the input values. See the discussion
  9043.                             below.
  9044.    ──────────────────────────────────────────────────────────────────────────
  9045.  
  9046.    The INPUT statement causes the program to pause and wait for data. You can
  9047.    then enter the required data at the keyboard.
  9048.  
  9049.    The data that you enter is assigned to the variables in variablelist. The
  9050.    number of data items that you supply must be the same as the number of
  9051.    variables in the list. The first character encountered after a comma that
  9052.    is not a space, carriage return, or line feed is assumed to be the start
  9053.    of a new item.
  9054.  
  9055.    The variable names in the list may be numeric- or string-variable names
  9056.    (including subscripted variables), array elements, or elements of records.
  9057.    The type of each data item that you input must agree with the type of the
  9058.    variable. (Strings input to an INPUT statement need not be surrounded by
  9059.    quotation marks.) If this first character is a quotation mark ("), the
  9060.    string item will consist of all characters read between the first
  9061.    quotation mark and the second. This means a quoted string may not contain
  9062.    a quotation mark as a character. If the first character of the string is
  9063.    not a quotation mark, the string is an unquoted string and terminates on a
  9064.    comma, carriage return, or line feed.
  9065.  
  9066.    Input stored in elements of a record must be input as single elements:
  9067.  
  9068.    TYPE Demograph
  9069.       FullName AS STRING*25
  9070.       Age  AS INTEGER
  9071.    END TYPE
  9072.  
  9073.    DIM Person AS Demograph
  9074.    INPUT "Enter name and age: ";Person.FullName,Person.Age
  9075.  
  9076.    Responding to an INPUT statement with too many or too few items, or with
  9077.    the wrong type of value (for example, numeric instead of string), produces
  9078.    this error message:
  9079.  
  9080.    Redo from start
  9081.  
  9082.    No assignment of input values is made until you give an acceptable
  9083.    response.
  9084.  
  9085.    It is possible to edit a line of input before you press ENTER. The
  9086.    following list describes the key combinations that allow you to move the
  9087.    cursor, delete text, and insert text on the input line:
  9088.  
  9089.  
  9090. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  9091.    Keys                     Action
  9092.    ──────────────────────────────────────────────────────────────────────────
  9093.    CTRL+\ or RIGHT          Moves cursor one character to the right.
  9094.  
  9095.    Keys                     Action
  9096.    ──────────────────────────────────────────────────────────────────────────
  9097. 
  9098.    CTRL+] or LEFT           Moves cursor one character to the left.
  9099.  
  9100.    CTRL+F or CTRL+RIGHT     Moves cursor one word to the right.
  9101.  
  9102.    CTRL+B or CTRL+LEFT      Moves cursor one word to the left.
  9103.  
  9104.    CTRL+K or HOME           Moves cursor to the beginning of the input line.
  9105.  
  9106.    CTRL+N or END            Moves cursor to the end of the input line.
  9107.  
  9108.    CTRL+R or INS            Toggles insert mode on and off. When insert mode
  9109.                             is on, character above and those to the right of
  9110.                             the cursor are shifted to the right as new
  9111.                             characters are entered.
  9112.  
  9113.    CTRL+I or TAB            Tabs right and inserts (insert mode on), or
  9114.                             overwrites (insert mode off).
  9115.  
  9116.    Keys                     Action
  9117.    ──────────────────────────────────────────────────────────────────────────
  9118. 
  9119.    DEL                      Deletes the character at the cursor.
  9120.  
  9121.    CTRL+H or BACKSPACE      Deletes the character to the left of the cursor,
  9122.                             unless the cursor is at the beginning of the
  9123.                             input, in which case it deletes the character at
  9124.                             the cursor.
  9125.  
  9126.    CTRL+E or CTRL+END       Deletes to the end of the line.
  9127.  
  9128.    CTRL+U or ESC            Deletes entire line, regardless of cursor
  9129.                             position.
  9130.  
  9131.    CTRL+M or RETURN         Stores input line.
  9132.  
  9133.    CTRL+T                   Toggles function key label display on and off at
  9134.                             bottom of screen.
  9135.  
  9136.    CTRL+BREAK or CTRL+C     Terminates input (exits compiled program).
  9137.    Keys                     Action
  9138.    ──────────────────────────────────────────────────────────────────────────
  9139.   CTRL+BREAK or CTRL+C     Terminates input (exits compiled program).
  9140.    ──────────────────────────────────────────────────────────────────────────
  9141.  
  9142.  
  9143.  ■ Example
  9144.  
  9145.    The following example calculates the area of a circle from an input
  9146.    radius:
  9147.  
  9148.    PI = 3.141593 : R = -1
  9149.    PRINT "Enter radius (0 to end)."
  9150.    DO WHILE R
  9151.        PRINT
  9152.        INPUT;"If radius = ", R
  9153.        IF R > 0 THEN
  9154.            A = PI*R^2
  9155.            PRINT ", the area of the circle =" A
  9156.        END IF
  9157.    LOOP
  9158.  
  9159.  ■ Output
  9160.  
  9161.    Enter radius (0 to end).
  9162.  
  9163.    If radius = 3, the area of the circle = 28.27434
  9164.  
  9165.    If radius = 4, the area of the circle = 50.26549
  9166.  
  9167.    If radius = 0
  9168.  
  9169.  
  9170.  ────────────────────────────────────────────────────────────────────────────
  9171.  INPUT # Statement
  9172.  ────────────────────────────────────────────────────────────────────────────
  9173.  
  9174.  ■ Action
  9175.  
  9176.    Reads data items from a sequential device or file and assigns them to
  9177.    variables
  9178.  
  9179.  ■ Syntax
  9180.  
  9181.    INPUT #filenumber, variablelist
  9182.  
  9183.  ■ Remarks
  9184.  
  9185.    The filenumber is the number used when the file was opened for input. The
  9186.    variablelist contains the names of the variables that are assigned values
  9187.    read from the file. (The variable type must match the type specified by
  9188.    the variable name.)
  9189.  
  9190.    The data items in the file should appear just as they would if you were
  9191.    entering data in response to an INPUT statement. Separate numbers with a
  9192.    space, carriage return, line feed, or comma. Separate strings with a
  9193.    carriage return or linefeed (leading spaces are ignored). The end-of-file
  9194.    character will end either a numeric or string entry.
  9195.  
  9196.    If BASIC is scanning the sequential data file for a string item, it will
  9197.    also ignore leading spaces, carriage returns, and line feeds. If
  9198.    end-of-file is reached when a numeric or string item is being INPUT, the
  9199.    item is terminated.
  9200.  
  9201.  ■ See Also
  9202.  
  9203.    INPUT, INPUT$
  9204.  
  9205.  ■ Example
  9206.  
  9207.    The following program reads a series of test scores from a sequential file
  9208.    and calculates the average score:
  9209.  
  9210.    DEFINT A-Z
  9211.  
  9212.    OPEN "class.dat" FOR INPUT AS #1
  9213.  
  9214.    DO WHILE NOT EOF(1)
  9215.       Count=Count+1
  9216.       INPUT #1,Score
  9217.       Total=Total+Score
  9218.       PRINT Count;Score
  9219.    LOOP
  9220.    PRINT
  9221.    PRINT "Total students:";Count;" Average score:";Total/Count
  9222.  
  9223.    END
  9224.  
  9225.  ■ Output
  9226.  
  9227.    1  97
  9228.    2  84
  9229.    3  63
  9230.    4  89
  9231.    5  100
  9232.  
  9233.    Total students: 5  Average score: 86.6
  9234.  
  9235.  
  9236.  ────────────────────────────────────────────────────────────────────────────
  9237.  INPUT$ Function
  9238.  ────────────────────────────────────────────────────────────────────────────
  9239.  
  9240.  ■ Action
  9241.  
  9242.    Returns a string of characters read from the specified file
  9243.  
  9244.  ■ Syntax
  9245.  
  9246.    INPUT$(n«,«#»filenumber»)
  9247.  
  9248.  ■ Remarks
  9249.  
  9250.    The n is the number of characters (bytes) to read from the file. The
  9251.    filenumber is the number that was used in opening the file.
  9252.  
  9253.    If the file is opened for random access, the argument n must be less than
  9254.    or equal to the record length set by the LEN clause in the OPEN statement
  9255.    (or less than or equal to 128 if the record length is not set). If the
  9256.    given file is opened for binary or sequential access, then n must be less
  9257.    than or equal to 32,767.
  9258.  
  9259.    If the filenumber is not specified, the characters are read from the
  9260.    standard input device. (If input has not been redirected, the keyboard is
  9261.    the standard input device).
  9262.  
  9263.    You can use the DOS redirection symbols (<, >, or >>) or the pipe symbol
  9264.    (|) to redefine the standard input or standard output for an executable
  9265.    file created with BASIC. (See your operating system manual for a complete
  9266.    discussion of redirection and pipes.)
  9267.  
  9268.    No characters are echoed on the screen. All control characters are passed
  9269.    through except CTRL+BREAK, which interrupts execution of the function.
  9270.  
  9271.  ■ Example
  9272.  
  9273.    The following program prints a file on the screen. It uses INPUT$ to read
  9274.    one character at a time, then converts the character, as necessary, and
  9275.    displays it.
  9276.  
  9277.    'ASCII codes for tab, and line feed.
  9278.    CONST HTAB = 9, LFEED = 10
  9279.  
  9280.    INPUT "Display which file"; Filename$
  9281.    OPEN Filename$ FOR INPUT AS #1
  9282.    CLS
  9283.    DO WHILE NOT EOF(1)
  9284.  
  9285.        ' Input a single character from the file.
  9286.        S$=INPUT$(1,#1)
  9287.        ' Convert the character to an integer and
  9288.        ' turn off the high bit so WordStar(R) files
  9289.        ' can be displayed.
  9290.        C=ASC(S$) AND &H7F
  9291.        ' Is it a printable character?
  9292.        IF (C >= 32 AND C <= 126) OR C = HTAB OR C = LFEED THEN
  9293.           PRINT CHR$(C);
  9294.        END IF
  9295.  
  9296.    LOOP
  9297.    END
  9298.  
  9299.  
  9300.  ────────────────────────────────────────────────────────────────────────────
  9301.  INSTR Function
  9302.  ────────────────────────────────────────────────────────────────────────────
  9303.  
  9304.  ■ Action
  9305.  
  9306.    Returns the character position of the first occurrence of a string in
  9307.    another string
  9308.  
  9309.  ■ Syntax
  9310.  
  9311.    INSTR(«start,»stringexpression1,stringexpression2)
  9312.  
  9313.  ■ Remarks
  9314.  
  9315.    The following list describes the INSTR function arguments:
  9316.  
  9317.    Argument                 Description
  9318.    ──────────────────────────────────────────────────────────────────────────
  9319.    start                    An optional offset that sets the position for
  9320.                             starting the search; start must be in the range
  9321.                             1-32,767. If start is not given, the INSTR
  9322.                             function begins the search at the first character
  9323.                             of stringexpression1.
  9324.  
  9325.    stringexpression1        The string being searched.
  9326.  
  9327.    stringexpression2        The string to look for.
  9328.    ──────────────────────────────────────────────────────────────────────────
  9329.  
  9330.    The arguments stringexpression1 and stringexpression2 can be string
  9331.    variables, string expressions, or string literals. The value returned by
  9332.    INSTR depends on these conditions:
  9333.  
  9334.    Condition                            Value Returned
  9335.    ──────────────────────────────────────────────────────────────────────────
  9336.    stringexpression2 found in           The position at which the match is
  9337.    stringexpression1                    found
  9338.  
  9339.    start greater than length of         0
  9340.    stringexpression1
  9341.    stringexpression1 is null string     0
  9342.  
  9343.    stringexpression2 cannot be found    0
  9344.  
  9345.    stringexpression2 is null string     start (if given); otherwise, 1
  9346.    ──────────────────────────────────────────────────────────────────────────
  9347.  
  9348.    Use the LEN function to find the length of stringexpression1.
  9349.  
  9350.  ■ Example
  9351.  
  9352.    The following fragment uses INSTR and UCASE$ to look for Mr., Mrs., or Ms.
  9353.    in a name in order to deduce the person's sex:
  9354.  
  9355.    ' Get a name.
  9356.    DO
  9357.       INPUT "Enter name: ", Nm$
  9358.    LOOP UNTIL LEN(Nm$)>=3
  9359.  
  9360.    ' Convert lowercase letters to uppercase.
  9361.    Nm$ = UCASE$(Nm$)
  9362.  
  9363.    ' Look for MS., MRS., or MR. to set Sex$.
  9364.    IF INSTR(Nm$,"MS.") > 0 OR INSTR(Nm$,"MRS.") > 0 THEN
  9365.        Sex$ = "F"
  9366.    ELSEIF INSTR(Nm$,"MR.") > 0 THEN
  9367.        Sex$ = "M"
  9368.    ELSE
  9369.        ' Can't deduce sex, so query user.
  9370.        DO
  9371.            INPUT "Enter sex (M/F): ", Sex$
  9372.            Sex$ = UCASE$(Sex$)
  9373.        LOOP WHILE Sex$ <> "M" AND Sex$ <> "F"
  9374.    END IF
  9375.  
  9376.  ■ Output
  9377.  
  9378.    Enter name: Elspeth Brandtkeep
  9379.    Enter sex (M/F): x
  9380.    Enter sex (M/F): F
  9381.  
  9382.  
  9383.  ────────────────────────────────────────────────────────────────────────────
  9384.  INT Function
  9385.  ────────────────────────────────────────────────────────────────────────────
  9386.  
  9387.  ■ Action
  9388.  
  9389.    Returns the largest integer less than or equal to numeric-expression
  9390.  
  9391.  ■ Syntax
  9392.  
  9393.    INT(numeric-expression)
  9394.  
  9395.  ■ Remarks
  9396.  
  9397.    The INT function removes the fractional part of its argument.
  9398.  
  9399.  ■ See Also
  9400.  
  9401.    CINT, FIX
  9402.  
  9403.  ■ Example
  9404.  
  9405.    The following example compares the output from the three functions that
  9406.    convert numeric data to integers:
  9407.  
  9408.    PRINT "  N","INT(N)","CINT(N)","FIX(N)" : PRINT
  9409.    FOR I% = 1 TO 6
  9410.        READ N
  9411.        PRINT N, INT(N), CINT(N), FIX(N)
  9412.    NEXT
  9413.    DATA  99.3, 99.5, 99.7, -99.3, -99.5, -99.7
  9414.  
  9415.  ■ Output
  9416.  
  9417.      N           INT(N)        CINT(N)       FIX(N)
  9418.  
  9419.     99.3          99            99            99
  9420.     99.5          99            100           99
  9421.     99.7          99            100           99
  9422.    -99.3         -100          -99           -99
  9423.    -99.5         -100          -100          -99
  9424.    -99.7         -100          -100          -99
  9425.  
  9426.  
  9427.  ────────────────────────────────────────────────────────────────────────────
  9428.  IOCTL$ Function
  9429.  ────────────────────────────────────────────────────────────────────────────
  9430.  
  9431.  ■ Action
  9432.  
  9433.    Receives a control data string from a device driver
  9434.  
  9435.  ■ Syntax
  9436.  
  9437.    IOCTL$ («#» filenumber)
  9438.  
  9439.  ■ Remarks
  9440.  
  9441.    The filenumber is the BASIC file number used to open the device. The
  9442.    IOCTL$ function is most frequently used to test whether an IOCTL statement
  9443.    succeeded or failed or to obtain current status information.
  9444.  
  9445.    You could use IOCTL$ to ask a communications device to return the current
  9446.    baud rate, information on the last error, logical line width, and so on.
  9447.    The exact information returned would depend on the specific device driver.
  9448.  
  9449.    The IOCTL$ function works only if all three of the following conditions
  9450.    are met:
  9451.  
  9452.    1. The device driver is installed.
  9453.  
  9454.    2. The device driver states that it processes IOCTL strings. See the
  9455.       documentation for the driver. You can also test for IOCTL support
  9456.       through DOS function &H44 by using interrupt &H21 and the CALL
  9457.       INTERRUPT routine. See the CALL INTERRUPT statement for more
  9458.       information.
  9459.  
  9460.    3. BASIC performs an OPEN statement on a file on that device.
  9461.  
  9462.  ────────────────────────────────────────────────────────────────────────────
  9463.  NOTE
  9464.    BASIC devices (LPT1:, COM1:, COM2:, SCRN:, CONS:) and DOS block devices
  9465.    (A: through Z:) do not support IOCTL.
  9466.  ────────────────────────────────────────────────────────────────────────────
  9467.  
  9468.  ■ See Also
  9469.  
  9470.    IOCTL
  9471.  
  9472.  ■ Example
  9473.  
  9474.    The following example opens the device driver ENGINE and uses the IOCTL$
  9475.    function to test for raw data mode being set:
  9476.  
  9477.    OPEN "\DEV\ENGINE" FOR OUTPUT AS #1
  9478.    IOCTL #1, "RAW"     'Tells the device that the data is raw.
  9479.    ' If the character driver "ENGINE" responds "false" from
  9480.    ' the raw data mode in the IOCTL statement, then the file
  9481.    ' is closed.
  9482.    IF IOCTL$(1) = "0" THEN CLOSE 1
  9483.  
  9484.  
  9485.  ────────────────────────────────────────────────────────────────────────────
  9486.  IOCTL Statement
  9487.  ────────────────────────────────────────────────────────────────────────────
  9488.  
  9489.  ■ Action
  9490.  
  9491.    Transmits a control data string to a device driver
  9492.  
  9493.  ■ Syntax
  9494.  
  9495.    IOCTL «#»filenumber, string
  9496.  
  9497.  ■ Remarks
  9498.  
  9499.    The filenumber is the BASIC file number used to open the device. The
  9500.    string is the command sent to the device. Commands are specific to the
  9501.    device driver. See the documentation for the device driver to find out
  9502.    what the valid IOCTL commands are. An IOCTL control data string can be up
  9503.    to 32,767 bytes long.
  9504.  
  9505.    The IOCTL statement works only if all three of the following conditions
  9506.    are met:
  9507.  
  9508.    1. The device driver is installed.
  9509.  
  9510.    2. The device driver states that it processes IOCTL strings. See the
  9511.       documentation for the driver. You can also test for IOCTL support
  9512.       through DOS function &H44 by using interrupt &H21 and the CALL
  9513.       INTERRUPT routine. See the Microsoft MS-DOS Programmer's Reference and
  9514.       the CALL INTERRUPT statement for more information.
  9515.  
  9516.    3. BASIC performs an OPEN on a file on that device, and the file is still
  9517.       open.
  9518.  
  9519.    Most standard DOS device drivers do not process IOCTL strings, and you
  9520.    must determine if the specific driver accepts the command.
  9521.  
  9522.  ■ See Also
  9523.  
  9524.    IOCTL$
  9525.  
  9526.  ■ Example
  9527.  
  9528.    If you wanted to set the page length to 66 lines per page on LPT1, your
  9529.    statement might look like this:
  9530.  
  9531.    OPEN "\DEV\LPT1" FOR OUTPUT AS 1
  9532.    IOCTL #1, "PL66"
  9533.  
  9534.  
  9535.  ────────────────────────────────────────────────────────────────────────────
  9536.  KEY Statements
  9537.  ────────────────────────────────────────────────────────────────────────────
  9538.  
  9539.  ■ Action
  9540.  
  9541.    Assign soft-key string values to FUNCTION keys, then display the values
  9542.    and enable or disable the FUNCTION key display line
  9543.  
  9544.  ■ Syntax
  9545.  
  9546.    KEY n, stringexpression
  9547.    KEY LIST
  9548.    KEY ON
  9549.    KEY OFF
  9550.  
  9551.  ■ Remarks
  9552.  
  9553.    The placeholder n is a number representing the FUNCTION key. The values
  9554.    for n are 1 to 10 for the FUNCTION keys, and 30 and 31 for FUNCTION keys
  9555.    F11 and F12 on 101-key keyboards. The stringexpression is a string of up
  9556.    to 15 characters that is returned when the FUNCTION key is pressed. If the
  9557.    stringexpression is longer than 15 characters, the extra characters are
  9558.    ignored.
  9559.  
  9560.    The KEY statement allows you to designate special "soft-key"
  9561.    functions──strings that are returned when FUNCTION keys are pressed.
  9562.  
  9563.    Assigning a null string to a soft key disables the FUNCTION key as a soft
  9564.    key.
  9565.  
  9566.    If the FUNCTION key number is not in the correct range, an error message
  9567.    is displayed that reads Illegal function call, and the previous key string
  9568.    expression is retained.
  9569.  
  9570.    You may display soft keys with the KEY ON, KEY OFF, and KEY LIST
  9571.    statements:
  9572.  
  9573.    Statement                Action
  9574.    ──────────────────────────────────────────────────────────────────────────
  9575.    KEY ON                   Displays the first six characters of the soft-key
  9576.                             string values on the bottom line of the screen.
  9577.  
  9578.    KEY OFF                  Erases the soft-key display from the bottom line,
  9579.                             making that line available for program use. It
  9580.                             does not disable the FUNCTION keys.
  9581.  
  9582.    KEY LIST                 Displays all soft-key values on the screen, with
  9583.                             all 15 characters of each key displayed.
  9584.    ──────────────────────────────────────────────────────────────────────────
  9585.  
  9586.    If a soft key is pressed, the effect is the same as if the user typed the
  9587.    string associated with the soft key. INPUT$, INPUT, and INKEY$ can all be
  9588.    used to read the string produced by pressing the soft key.
  9589.  
  9590.  ■ Examples
  9591.  
  9592.    The following examples show how to assign a string to a soft key and how
  9593.    to disable a soft key:
  9594.  
  9595.    KEY 1,"MENU"+CHR$(13)  'Assigns to soft key 1 the string
  9596.                           '"MENU" followed by a carriage return.
  9597.  
  9598.    KEY 1,""
  9599.    'Disables soft key 1.
  9600.  
  9601.    The following program uses KEY statements to set up one-key equivalents of
  9602.    menu selections. For example, pressing F1 is the same as entering the
  9603.    string Add:
  9604.  
  9605.    DIM KeyText$(3)
  9606.    DATA Add, Delete, Quit
  9607.    ' Assign soft-key strings to F1 to F3.
  9608.    FOR I=1 TO 3
  9609.       READ KeyText$(I)
  9610.       KEY I, KeyText$(I)+CHR$(13)
  9611.    NEXT I
  9612.    ' Print menu.
  9613.    PRINT "                 Main Menu" : PRINT
  9614.    PRINT "           Add to list (F1)"
  9615.    PRINT "           Delete from list (F2)"
  9616.    PRINT "           Quit (F3)" : PRINT
  9617.    ' Get input and respond.
  9618.    DO
  9619.       LOCATE 7,1 : PRINT SPACE$(50);
  9620.       LOCATE 7,1 : INPUT "             Enter your choice:",R$
  9621.       SELECT CASE R$
  9622.          CASE "Add", "Delete"
  9623.             LOCATE 10,1 : PRINT SPACE$(15);
  9624.             LOCATE 10,1 : PRINT R$;
  9625.          CASE "Quit"
  9626.             EXIT DO
  9627.          CASE ELSE
  9628.             LOCATE 10,1 : PRINT "Enter first word or press key."
  9629.       END SELECT
  9630.    LOOP
  9631.  
  9632.  
  9633.  ────────────────────────────────────────────────────────────────────────────
  9634.  KEY (n) Statements
  9635.  ────────────────────────────────────────────────────────────────────────────
  9636.  
  9637.  ■ Action
  9638.  
  9639.    Start or stop trapping of specified keys
  9640.  
  9641.  ■ Syntax
  9642.  
  9643.    KEY(n) ON
  9644.    KEY(n) OFF
  9645.    KEY(n) STOP
  9646.  
  9647.  ■ Remarks
  9648.  
  9649.    The argument n is the number of a FUNCTION key, a cursor-direction key, or
  9650.    a user-defined key. (See the KEY statement for information on assigning
  9651.    soft-key values to FUNCTION keys.) The values of n are as follows:
  9652.  
  9653.    Value                    Key
  9654.    ──────────────────────────────────────────────────────────────────────────
  9655.    1-10                     The FUNCTION keys F1-F10
  9656.    11                       UP
  9657.    12                       LEFT
  9658.    13                       RIGHT
  9659.    14                       DOWN
  9660.    15-25                    User-defined keys
  9661.    30-31                    The FUNCTION keys F11-F12 on 101-key keyboards
  9662.    ──────────────────────────────────────────────────────────────────────────
  9663.  
  9664.    LEFT, RIGHT, UP, and DOWN refer to the direction keys.
  9665.  
  9666.    You can enable trapping of combination keys by using a variation of the
  9667.    KEY statement:
  9668.  
  9669.    KEY n, CHR$(keyboardflag) + CHR$(scancode)
  9670.  
  9671.    The argument n is in the range 15-25 to indicate a user-defined key. The
  9672.    keyboardflag can be any combination of the following hexadecimal values:
  9673.  
  9674.    Value                    Key
  9675.    ──────────────────────────────────────────────────────────────────────────
  9676.    &H00                     No keyboard flag
  9677.    &H01-&H03                Either SHIFT key
  9678.    &H04                     CTRL
  9679.    &H08                     ALT
  9680.    &H20                     NUMLOCK
  9681.    &H40                     CAPSLOCK
  9682.    &H80                     101-key keyboard extended keys
  9683.    ──────────────────────────────────────────────────────────────────────────
  9684.  
  9685.    You can add the values together to test for multiple shift states. A
  9686.    keyboardflag value of &H12 would test for both CTRL and ALT being pressed,
  9687.    for example.
  9688.  
  9689.    Because key trapping assumes the left and right SHIFT keys are the same,
  9690.    you can use either &H01, &H02, or &H03 to indicate a SHIFT key. The
  9691.    scancode argument is a number identifying one of the 83 keys to trap, as
  9692.    shown in Table R.4.
  9693.  
  9694.    Table R.4   Keyboard Scan Codes
  9695.  
  9696.  
  9697. ╓┌─┌───────────┌────────────┌───────────┌───────────┌────────────┌───────────╖
  9698.                Code                     Code                     Code
  9699.    Key         in Hex       Key         in Hex      Key          in Hex
  9700.    ──────────────────────────────────────────────────────────────────────────
  9701.    ESC         01           CTRL        1D          SPACEBAR     39
  9702.    ! or 1      02           A           1E          CAPS LOCK    3A
  9703.    # or 3      04           D           20          F2           3C
  9704.                Code                     Code                     Code
  9705.    Key         in Hex       Key         in Hex      Key          in Hex
  9706.    ──────────────────────────────────────────────────────────────────────────
  9707.   # or 3      04           D           20          F2           3C
  9708.    $ or 4      05           F           21          F3           3D
  9709.    % or 5      06           G           22          F4           3E
  9710.    ^ or 6      07           H           23          F5           3F
  9711.    & or 7      08           J           24          F6           40
  9712.    * or 8      09           K           25          F7           41
  9713.    ( or 9      0A           L           26          F8           42
  9714.    ) or 0      0B           : or ;      27          F9           43
  9715.    _ or -      0C           " or '      28          F10          44
  9716.    + or =      0D           ~ or `      29          NUM LOCK     45
  9717.    LEFT        0E           LEFT SHIFT  2A          SCROLL LOCK  46
  9718.    TAB         0F           | or \      2B          HOME or 7    47
  9719.    Q           10           Z           2C          UP or 8      48
  9720.    W           11           X           2D          PGUP or 9    49
  9721.    E           12           C           2E          -            4A
  9722.    R           13           V           2F          LEFT or 4    4B
  9723.    T           14           B           30          5            4C
  9724.    Y           15           N           31          RIGHT or 6   4D
  9725.                Code                     Code                     Code
  9726.    Key         in Hex       Key         in Hex      Key          in Hex
  9727.    ──────────────────────────────────────────────────────────────────────────
  9728.   Y           15           N           31          RIGHT or 6   4D
  9729.    U           16           M           32          +            4E
  9730.    I           17           < or ,      33          END or 1     4F
  9731.    O           18           > or .      34          DOWN or 2    50
  9732.    P           19           ? or /      35          PGDN or 3    51
  9733.    { or [      1A           RIGHT SHIFT 36          INS or 0     52
  9734.    } or ]      1B           PRTSC or *  37          DEL or .     53
  9735.    RETURN      1C           ALT         38
  9736.    ──────────────────────────────────────────────────────────────────────────
  9737.  
  9738.  
  9739.  ────────────────────────────────────────────────────────────────────────────
  9740.  NOTE
  9741.    The scan codes in Table R.4 are equivalent to the first column of the
  9742.    scan code table in Appendix A, "Keyboard Scan Codes and ASCII Character
  9743.    Codes." The codes in the other columns of the table in the appendix should
  9744.    not be used for key trapping.
  9745.  ────────────────────────────────────────────────────────────────────────────
  9746.  
  9747.    The KEY(n) ON statement enables soft-key or cursor-direction-key event
  9748.    trapping by an ON KEY statement. If you specify a nonzero line number in
  9749.    the ON KEY statement while trapping is enabled, BASIC checks to see if you
  9750.    have pressed KEY(n). If you have, BASIC executes the GOSUB clause in the
  9751.    ON KEY statement. The text that would normally be associated with a
  9752.    FUNCTION key is not input.
  9753.  
  9754.    When you are working in the environment, QuickBASIC tests between
  9755.    statements for key presses. In stand-alone programs, you can specify
  9756.    checking between lines.
  9757.  
  9758.    KEY(n) OFF disables the event trap; even if an event takes place, it is
  9759.    not remembered. KEY(n) STOP inhibits the event trap; that is, if you press
  9760.    the specified key your action is remembered and an ON KEY event trap is
  9761.    executed as soon as a KEY(n) ON statement is executed.
  9762.  
  9763.  ■ See Also
  9764.  
  9765.    ON event
  9766.  
  9767.  ■ Example
  9768.  
  9769.    This example traps the DOWN direction key and CTRL+S (control key and
  9770.    lowercase "s"). To trap the combination of the CTRL key and uppercase "s,"
  9771.    you need to trap CTRL+SHIFT and CTRL+CAPS LOCK+S.
  9772.  
  9773.    I = 0
  9774.    PRINT "Press DOWN direction key to end."
  9775.    KEY 15,CHR$(&H04)+CHR$(&H1f)
  9776.    KEY(15) ON              'Trap CTRL+s.
  9777.    KEY(14) ON              'Trap DOWN direction key.
  9778.    ON KEY(15) GOSUB Keytrap
  9779.    ON KEY(14) GOSUB Endprog
  9780.    Idle: GOTO Idle        'Endless loop
  9781.  
  9782.    Keytrap:   'Counts the number of times CTRL+s pressed.
  9783.        I = I + 1
  9784.    RETURN
  9785.  
  9786.    Endprog:
  9787.        PRINT "CTRL+s trapped"; I; "times"
  9788.        END
  9789.    RETURN
  9790.  
  9791.  
  9792.  ────────────────────────────────────────────────────────────────────────────
  9793.  KILL Statement
  9794.  ────────────────────────────────────────────────────────────────────────────
  9795.  
  9796.  ■ Action
  9797.  
  9798.    Deletes a file from disk
  9799.  
  9800.  ■ Syntax
  9801.  
  9802.    KILL filespec
  9803.  
  9804.  ■ Remarks
  9805.  
  9806.    The KILL statement is similar to the DOS ERASE or DEL commands.
  9807.  
  9808.    KILL is used for all types of disk files: program files, random data
  9809.    files, and sequential data files. The filespec may contain question marks
  9810.    (?) or asterisks (*) used as wild cards. A question mark matches any
  9811.    single character in the file name or extension. An asterisk matches one or
  9812.    more characters starting at its position.
  9813.  
  9814.    You can use KILL only to delete files. To delete directories, use the
  9815.    RMDIR command. Using KILL to delete a file that is currently open produces
  9816.    an error message that reads File already open.
  9817.  
  9818.  ────────────────────────────────────────────────────────────────────────────
  9819.  WARNING
  9820.    Be extremely careful when using wild cards with KILL. You can delete files
  9821.    unintentionally with the wild card characters.
  9822.  ────────────────────────────────────────────────────────────────────────────
  9823.  
  9824.  ■ Examples
  9825.  
  9826.    The following examples show the effect of wild-card characters when used
  9827.    with KILL:
  9828.  
  9829.    KILL "DATA1?.DAT"           'Kills any file with a six-character
  9830.                                'base name starting with DATA1 and
  9831.                                'also with the extension .DAT.
  9832.  
  9833.    KILL "DATA1.*"              'Kills any file with the base name
  9834.                                'DATA1 and any extension.
  9835.  
  9836.    KILL "\GREG\*.DAT"        'Kills any file with the extension
  9837.                                '.DAT in a subdirectory called GREG.
  9838.  
  9839.    The following program deletes the file specified in the command line:
  9840.  
  9841.    DEFINT A-Z
  9842.    ON ERROR GOTO Errorhandle 'Set up error handling.
  9843.    FileName$ = COMMAND$      'Get file name.
  9844.    KILL FileName$
  9845.    END
  9846.  
  9847.    Errorhandle:
  9848.        Number = ERR
  9849.        IF Number = 53 THEN
  9850.           PRINT "Couldn't delete " FileName$ ;
  9851.           PRINT "; file does not exist in current directory"
  9852.        ELSE
  9853.           PRINT "Unrecoverable error:";Number
  9854.           ON ERROR GOTO 0   'ON ERROR GOTO zero aborts program.
  9855.        END IF
  9856.    RESUME NEXT
  9857.  
  9858.  
  9859.  ────────────────────────────────────────────────────────────────────────────
  9860.  LBOUND Function
  9861.  ────────────────────────────────────────────────────────────────────────────
  9862.  
  9863.  ■ Action
  9864.  
  9865.    Returns the lower bound (smallest available subscript) for the indicated
  9866.    dimension of an array
  9867.  
  9868.  ■ Syntax
  9869.  
  9870.    LBOUND(array«,dimension»)
  9871.  
  9872.  ■ Remarks
  9873.  
  9874.    The LBOUND function is used with the UBOUND function to determine the size
  9875.    of an array. LBOUND takes the following arguments:
  9876.  
  9877.    Argument                 Description
  9878.    ──────────────────────────────────────────────────────────────────────────
  9879.    array                    The name of the array being dimensioned
  9880.  
  9881.    dimension                An integer ranging from 1 to the number of
  9882.                             dimensions in array: indicates which dimension's
  9883.                             lower bound is returned
  9884.    ──────────────────────────────────────────────────────────────────────────
  9885.  
  9886.    For an array dimensioned as follows, LBOUND returns the values listed
  9887.    below:
  9888.  
  9889.    DIM A(1 TO 100, 0 TO 50, -3 TO 4)
  9890.  
  9891.    Invocation               Value Returned
  9892.    ──────────────────────────────────────────────────────────────────────────
  9893.    LBOUND(A,1)              1
  9894.    LBOUND(A,2)              0
  9895.    LBOUND(A,3)              -3
  9896.    ──────────────────────────────────────────────────────────────────────────
  9897.  
  9898.    The default lower bound for any dimension is either 0 or 1, depending on
  9899.    the setting of the OPTION BASE statement. If OPTION BASE is 0, the default
  9900.    lower bound is 0, and if OPTION BASE is 1, the default lower bound is 1.
  9901.  
  9902.    Arrays dimensioned using the TO clause in the DIM statement may have any
  9903.    integer value as a lower bound.
  9904.  
  9905.    You may use the shortened syntax LBOUND(array) for one-dimensional arrays,
  9906.    since the default value for dimension is 1. Use the UBOUND function to
  9907.    find the upper limit of an array dimension.
  9908.  
  9909.  ■ See Also
  9910.  
  9911.    UBOUND
  9912.  
  9913.  ■ Example
  9914.  
  9915.    The LBOUND and UBOUND functions may be used to determine the size of an
  9916.    array passed to a subprogram, as in the following program fragment:
  9917.  
  9918.    CALL Prntmat(Array())
  9919.    .
  9920.    .
  9921.    .
  9922.    ' Print a matrix (two-dimensional array).
  9923.    SUB Prntmat(A(2)) STATIC
  9924.       ' Outer loop controls row (dimension 1).
  9925.       FOR I% = LBOUND(A,1) TO UBOUND(A,1)
  9926.          ' Inner loop controls column (dimension 2).
  9927.          FOR J% = LBOUND(A,2) TO UBOUND(A,2)
  9928.             PRINT A(I%,J%);" ";
  9929.          NEXT J%
  9930.          PRINT:PRINT
  9931.       NEXT I%
  9932.    END SUB
  9933.  
  9934.  
  9935.  ────────────────────────────────────────────────────────────────────────────
  9936.  LCASE$ Function
  9937.  ────────────────────────────────────────────────────────────────────────────
  9938.  
  9939.  ■ Action
  9940.  
  9941.    Returns a string expression with all letters in lowercase
  9942.  
  9943.  ■ Syntax
  9944.  
  9945.    LCASE$ (stringexpression)
  9946.  
  9947.  ■ Remarks
  9948.  
  9949.    The LCASE$ function takes a string variable, string constant, or string
  9950.    expression as its single argument. LCASE$ works with both variable- and
  9951.    fixed-length strings.
  9952.  
  9953.    LCASE$ and UCASE$ are helpful in string comparison operations where tests
  9954.    need to be case insensitive.
  9955.  
  9956.  ■ See Also
  9957.  
  9958.    UCASE$
  9959.  
  9960.  ■ Example
  9961.  
  9962.    The following example converts uppercase characters in a string to
  9963.    lowercase characters:
  9964.  
  9965.    ' Program to convert to lowercase.
  9966.        READ Word$
  9967.        PRINT LCASE$(Word$);
  9968.        DATA "THIS IS THE STRING in lowercase."
  9969.  
  9970.  ■ Output
  9971.  
  9972.    this is the string in lowercase.
  9973.  
  9974.  
  9975.  ────────────────────────────────────────────────────────────────────────────
  9976.  LEFT$ Function
  9977.  ────────────────────────────────────────────────────────────────────────────
  9978.  
  9979.  ■ Action
  9980.  
  9981.    Returns a string consisting of the leftmost n characters of a string
  9982.  
  9983.  ■ Syntax
  9984.  
  9985.    LEFT$(stringexpression,n)
  9986.  
  9987.  ■ Remarks
  9988.  
  9989.    The argument stringexpression can be any string variable, any string
  9990.    constant, or any string expression.
  9991.  
  9992.    The argument n is a numeric expression in the range 0-32,767 indicating
  9993.    how many characters are to be returned.
  9994.  
  9995.    If n is greater than the number of characters in stringexpression, the
  9996.    entire string is returned. To find the number of characters in
  9997.    stringexpression, use LEN(stringexpression).
  9998.  
  9999.    If n is zero, the null string (length zero) is returned.
  10000.  
  10001.  ■ See Also
  10002.  
  10003.    MID$, RIGHT$
  10004.  
  10005.  ■ Example
  10006.  
  10007.    The following example prints the leftmost five characters of A$:
  10008.  
  10009.    A$="BASIC LANGUAGE"
  10010.    B$=LEFT$(A$,5)
  10011.    PRINT B$
  10012.  
  10013.  ■ Output
  10014.  
  10015.    BASIC
  10016.  
  10017.  
  10018.  ────────────────────────────────────────────────────────────────────────────
  10019.  LEN Function
  10020.  ────────────────────────────────────────────────────────────────────────────
  10021.  
  10022.  ■ Action
  10023.  
  10024.    Returns the number of characters in a string or the number of bytes
  10025.    required by a variable
  10026.  
  10027.  ■ Syntax
  10028.  
  10029.    LEN(stringexpression)
  10030.    LEN(variable)
  10031.  
  10032.  ■ Remarks
  10033.  
  10034.    In the first form, LEN returns the number of characters in the argument
  10035.    stringexpression. The second syntax returns the number of bytes required
  10036.    by a BASIC variable. This syntax is particularly useful for determining
  10037.    the correct record size of a random-access file.
  10038.  
  10039.  ■ Example
  10040.  
  10041.    The following example prints the sizes of BASIC variables of several
  10042.    different types and also prints the length of a string:
  10043.  
  10044.    TYPE EmpRec
  10045.       EmpName AS STRING*20
  10046.       EmpNum AS INTEGER
  10047.    END TYPE
  10048.    DIM A AS INTEGER, B AS LONG, C AS SINGLE, D AS DOUBLE
  10049.    DIM E AS EmpRec
  10050.  
  10051.    PRINT "Integer:" LEN(A)
  10052.    PRINT "Long:" LEN(B)
  10053.    PRINT "Single:" LEN(C)
  10054.    PRINT "Double:" LEN(D)
  10055.    PRINT "EmpRec:" LEN(E)
  10056.    PRINT "A string:" LEN("A string.")
  10057.    END
  10058.  
  10059.  ■ Output
  10060.  
  10061.    Integer: 2
  10062.    Long: 4
  10063.    Single: 4
  10064.    Double: 8
  10065.    EmpRec: 22
  10066.    A string: 9
  10067.  
  10068.  
  10069.  ────────────────────────────────────────────────────────────────────────────
  10070.  LET Statement
  10071.  ────────────────────────────────────────────────────────────────────────────
  10072.  
  10073.  ■ Action
  10074.  
  10075.    Assigns the value of an expression to a variable
  10076.  
  10077.  ■ Syntax
  10078.  
  10079.    «LET»variable=expression
  10080.  
  10081.  ■ Remarks
  10082.  
  10083.    Notice that the word LET is optional. The equal sign in the statement is
  10084.    enough to inform QuickBASIC that the statement is an assignment statement.
  10085.  
  10086.    LET statements can be used with record variables only when both variables
  10087.    are the same user-defined type. Use the LSET statement for assigning
  10088.    record variables of different user-defined types.
  10089.  
  10090.  ■ See Also
  10091.  
  10092.    LSET
  10093.  
  10094.  ■ Examples
  10095.  
  10096.    Corresponding lines perform the same function in these two examples:
  10097.  
  10098.    LET D=12
  10099.    LET E=12-2
  10100.    LET F=12-4
  10101.    LET SUM=D+E+F
  10102.    .
  10103.    .
  10104.    .
  10105.  
  10106.    or
  10107.  
  10108.    D=12
  10109.    E=12-2
  10110.    F=12-4
  10111.    SUM=D+E+F
  10112.    .
  10113.    .
  10114.    .
  10115.  
  10116.  
  10117.  ────────────────────────────────────────────────────────────────────────────
  10118.  LINE Statement
  10119.  ────────────────────────────────────────────────────────────────────────────
  10120.  
  10121.  ■ Action
  10122.  
  10123.    Draws a line or box on the screen
  10124.  
  10125.  ■ Syntax
  10126.  
  10127.    LINE ««STEP» (x1,y1)»-«STEP» (x2,y2) «,«color»«,«B«F»»«,style»»»
  10128.  
  10129.  ■ Remarks
  10130.  
  10131.    The coordinates (x1,y1) and (x2,y2) specify the endpoints of the line;
  10132.    note that the order in which these endpoints appear is unimportant, since
  10133.    a line from (10,20) to (120,130) is the same as a line from (120,130) to
  10134.    (10,20).
  10135.  
  10136.    The STEP option makes the specified coordinates relative to the most
  10137.    recent point, instead of absolute, mapped coordinates. For example, if the
  10138.    most recent point referred to by the program is (10,10), then
  10139.  
  10140.    LINE -STEP (10,5)
  10141.  
  10142.    draws a line from (10,10) to the point with x-coordinate equal to 10 + 10
  10143.    and y-coordinate equal to 10 + 5, or (20,15).
  10144.  
  10145.    You may establish a new most recent point by initializing the screen with
  10146.    the CLS and SCREEN statements. Using the PSET, PRESET, CIRCLE, and DRAW
  10147.    statements will also establish a new most recent point.
  10148.  
  10149.    Variations of the STEP argument are shown below. For the following
  10150.    examples, assume that the last point plotted was (10,10):
  10151.  
  10152. ╓┌─┌────────────────────────────────────────────────┌────────────────────────╖
  10153.    Statement                                        Description
  10154.    ──────────────────────────────────────────────────────────────────────────
  10155.    LINE -(50,50)                                    Draws from (10,10) to
  10156.                                                     (50,50)
  10157.  
  10158.    LINE -STEP(50,50)                                Draws from (10,10) to
  10159.                                                     (60,60); that is, to 10
  10160.                                                     plus offset 50
  10161.  
  10162.    LINE (25,25)-STEP(50,50)                         Draws from (25,25) to
  10163.                                                     (75,75); that is, to 25
  10164.                                                     plus offset 50
  10165.  
  10166.    Statement                                        Description
  10167.    ──────────────────────────────────────────────────────────────────────────
  10168. 
  10169.    LINE STEP(25,25)-STEP(50,50)                     Draws from (35,35) to
  10170.                                                     (85,85); that is, from 10
  10171.                                                     plus offset 25 to that
  10172.                                                     point plus offset 50
  10173.  
  10174.    LINE STEP(25,25)-(50,50)                         Draws from (35,35) to
  10175.                                                     (50,50); that is, from 10
  10176.                                                     plus offset 25 to
  10177.                                                     absolute 50
  10178.    ──────────────────────────────────────────────────────────────────────────
  10179.  
  10180.  
  10181.    The color is the number of the color in which the line is drawn. (If the B
  10182.    or BF options are used, the box is drawn in this color.) See the SCREEN
  10183.    statement for information on valid colors.
  10184.  
  10185.    The B option draws a box with the points (x1,y1) and (x2,y2) specifying
  10186.    diagonally opposite corners.
  10187.  
  10188.    The BF option draws a filled box. This option is similar to the B option;
  10189.    BF also paints the interior of the box with the selected color.
  10190.  
  10191.    The style is a 16-bit integer mask used to put pixels on the screen. Using
  10192.    the style argument is called "line styling." With line styling, LINE reads
  10193.    the bits in style from left to right. If a bit is 0, then no point is
  10194.    plotted; if the bit is 1, a point is plotted. After plotting a point, LINE
  10195.    selects the next bit position in style.
  10196.  
  10197.    Because a 0 bit in style does not change the point on the screen, you may
  10198.    want to draw a background line before using styling so you can have a
  10199.    known background. Style is used for normal lines and boxes, but has no
  10200.    effect on filled boxes.
  10201.  
  10202.    When coordinates specify a point that is not in the current viewport, the
  10203.    line segment is clipped to the viewport.
  10204.  
  10205.    See Chapter 5, "Graphics," in Programming in BASIC for more information on
  10206.    the LINE statement.
  10207.  
  10208.  ■ See Also
  10209.  
  10210.    SCREEN
  10211.  
  10212.  ■ Examples
  10213.  
  10214.    The following examples are different LINE statements that assume a screen
  10215.    320 pixels wide by 200 pixels high:
  10216.  
  10217.    SCREEN 1                          'Sets up the screen mode.
  10218.  
  10219.    LINE -(X2,Y2)                     'Draws a line (in the
  10220.                                      'foreground color) from
  10221.                                      'the most recent point
  10222.                                      'to  X2,Y2.
  10223.  
  10224.    LINE(0,0)-(319,199)               'Draws a diagonal line across
  10225.                                      'the screen (downward).
  10226.  
  10227.  
  10228.    LINE(0,100)-(319,100)             'Draws a horizontal line
  10229.                                      'across the screen.
  10230.  
  10231.    LINE(10,10)-(20,20),2             'Draws a line in color 2.
  10232.  
  10233.    FOR X=0 to 319                    'Draws an alternating pattern
  10234.        LINE(X,0)-(X,199),X AND 1     '(line on/line off) on mono-
  10235.    NEXT                              'chrome display.
  10236.  
  10237.    LINE (0,0)-(100,100),,B           'Draws a box in the fore-
  10238.                                      'ground color (note that the
  10239.                                      'color is not included).
  10240.  
  10241.    LINE STEP(0,0)-STEP(200,200),2,BF 'Draws a filled box in color
  10242.                                      '2 (coordinates are given as
  10243.                                      'offsets with the STEP option).
  10244.  
  10245.    LINE(0,0)-(160,100),3,,&HFF00     'Draws a dashed line from
  10246.                                      'the upper lefthand corner to
  10247.                                      'the center of the screen in
  10248.                                      'color 3.
  10249.  
  10250.  
  10251.  ────────────────────────────────────────────────────────────────────────────
  10252.  LINE INPUT Statement
  10253.  ────────────────────────────────────────────────────────────────────────────
  10254.  
  10255.  ■ Action
  10256.  
  10257.    Inputs an entire line (up to 255 characters) to a string variable, without
  10258.    the use of delimiters
  10259.  
  10260.  ■ Syntax
  10261.  
  10262.    LINE INPUT«;» «"promptstring";» stringvariable
  10263.  
  10264.  ■ Remarks
  10265.  
  10266.    The promptstring is a string constant displayed on the screen before input
  10267.    is accepted. A question mark is not printed unless it is part of the
  10268.    promptstring. All input from the end of promptstring to the carriage
  10269.    return is assigned to stringvariable.
  10270.  
  10271.    A semicolon immediately after the LINE INPUT statement keeps the cursor on
  10272.    the same line after the user presses ENTER.
  10273.  
  10274.    LINE INPUT uses the same editing characters as INPUT.
  10275.  
  10276.  ■ See Also
  10277.  
  10278.    INPUT
  10279.  
  10280.  ■ Example
  10281.  
  10282.    The following program enables the user to enter text in a notes file. The
  10283.    LINE INPUT statement allows you to enter any characters, including those
  10284.    (such as a comma) that are delimiters in a regular INPUT statement.
  10285.  
  10286.    'Opens and writes lines to a notes file until you
  10287.    'enter a blank line.
  10288.    DO
  10289.        CLS
  10290.        PRINT "Enter text. To stop, press <RETURN> without ";
  10291.        PRINT "entering any new text." : PRINT
  10292.        OPEN "NOTES.TXT" FOR OUTPUT AS #1
  10293.  
  10294.        ' Take lines until a blank line is entered.
  10295.        DO
  10296.            LINE INPUT "->";Inline$
  10297.            IF Inline$ <> "" THEN PRINT #1, Inline$
  10298.        LOOP WHILE Inline$ <> ""
  10299.        CLS : CLOSE #1
  10300.  
  10301.    ' Echo the notes back and see if they are correct.
  10302.        OPEN "NOTES.TXT" FOR INPUT AS #1
  10303.        PRINT "You entered: " : PRINT
  10304.        DO WHILE NOT EOF(1)
  10305.            LINE INPUT #1, Inline$
  10306.            PRINT Inline$
  10307.        LOOP
  10308.        CLOSE #1
  10309.        PRINT : INPUT "Is this correct (Y/N)"; R$
  10310.  
  10311.    LOOP WHILE UCASE$(R$)="N"
  10312.    END
  10313.  
  10314.  
  10315.  ────────────────────────────────────────────────────────────────────────────
  10316.  LINE INPUT # Statement
  10317.  ────────────────────────────────────────────────────────────────────────────
  10318.  
  10319.  ■ Action
  10320.  
  10321.    Reads an entire line without delimiters from a sequential file to a string
  10322.    variable
  10323.  
  10324.  ■ Syntax
  10325.  
  10326.    LINE INPUT #filenumber,stringvariable
  10327.  
  10328.  ■ Remarks
  10329.  
  10330.    The filenumber is the number used to open the file. The stringvariable is
  10331.    the variable the line is assigned to.
  10332.  
  10333.    The LINE INPUT # statement reads all characters in the sequential file up
  10334.    to a carriage return. It then skips over the carriage-return and line-feed
  10335.    sequence. The next LINE INPUT # reads all characters up to the next
  10336.    carriage return.
  10337.  
  10338.    LINE INPUT # is especially useful if each line of a data file has been
  10339.    broken into fields or a text file is being read a line at a time.
  10340.  
  10341.  ■ See Also
  10342.  
  10343.    INPUT$, LINE INPUT
  10344.  
  10345.  ■ Example
  10346.  
  10347.    The following uses LINE INPUT # to echo data input to a file:
  10348.  
  10349.    OPEN "LIST" FOR OUTPUT AS #1
  10350.    PRINT "CUSTOMER INFORMATION:"
  10351.    ' Get customer information.
  10352.    DO
  10353.        PRINT
  10354.        INPUT "   LAST NAME:  ", LName$
  10355.        INPUT "   FIRST NAME: ", FrName$
  10356.        INPUT "   AGE:        ", Age$
  10357.        INPUT "   SEX:        ", Sex$
  10358.        Sex$=UCASE$(Sex$)
  10359.        WRITE #1, LName$, FrName$, Age$, Sex$
  10360.        INPUT "Add another"; R$
  10361.    LOOP WHILE UCASE$(R$)="Y"
  10362.    CLOSE #1
  10363.  
  10364.  
  10365.    ' Echo the file back.
  10366.    OPEN "LIST" FOR INPUT AS #1
  10367.    CLS
  10368.    PRINT "Records in file:" : PRINT
  10369.    DO WHILE NOT EOF(1)
  10370.        LINE INPUT #1, REC$
  10371.    'Read records from file with
  10372.        PRINT REC$          'LINE INPUT #. Print the
  10373.                            'records on the screen.
  10374.    LOOP
  10375.  
  10376.  ■ Output
  10377.  
  10378.    CUSTOMER INFORMATION:
  10379.  
  10380.  
  10381.       LAST NAME:  Saintsbury
  10382.       FIRST NAME: Aloysius
  10383.       AGE:        35
  10384.       SEX:        m
  10385.    Add another? y
  10386.  
  10387.       LAST NAME:  Frangio
  10388.       FIRST NAME: Louisa
  10389.       AGE:        27
  10390.       SEX:        f
  10391.    Add another? n
  10392.  
  10393.    Records in file:
  10394.  
  10395.    "Saintsbury","Aloysius","35","M"
  10396.    "Frangio","Louisa","27","F"
  10397.  
  10398.  
  10399.  ────────────────────────────────────────────────────────────────────────────
  10400.  LOC Function
  10401.  ────────────────────────────────────────────────────────────────────────────
  10402.  
  10403.  ■ Action
  10404.  
  10405.    Returns the current position within the file
  10406.  
  10407.  ■ Syntax
  10408.  
  10409.    LOC(filenumber)
  10410.  
  10411.  ■ Remarks
  10412.  
  10413.    The filenumber is the number used in the OPEN statement to open the file.
  10414.    With random-access files, the LOC function returns the number of the last
  10415.    record read from or written to the file. With sequential files, LOC
  10416.    returns the current byte position in the file, divided by 128. With binary
  10417.    mode files, LOC returns the position of the last byte read or written.
  10418.  
  10419.    For a COM device, LOC(filenumber) returns the number of characters in the
  10420.    input queue waiting to be read. The value returned depends on whether the
  10421.    device was opened in ASCII or binary mode. In ASCII mode, the low-level
  10422.    routines stop queuing characters as soon as end-of-file is received. The
  10423.    end-of-file itself is not queued and cannot be read. An attempt to read
  10424.    the end-of-file produces an error message that reads Input past end of
  10425.    file. In binary mode, the end-of-file character is ignored and the entire
  10426.    file can therefore be read.
  10427.  
  10428.    The LOC function cannot be used on the SCRN:, KYBD:, or LPTn: devices.
  10429.  
  10430.  ■ See Also
  10431.  
  10432.    OPEN COM
  10433.  
  10434.  ■ Example
  10435.  
  10436.    The following line stops the program if the current file position is
  10437.    beyond 50:
  10438.  
  10439.    IF LOC(1) > 50 THEN STOP
  10440.  
  10441.  
  10442.  ────────────────────────────────────────────────────────────────────────────
  10443.  LOCATE Statement
  10444.  ────────────────────────────────────────────────────────────────────────────
  10445.  
  10446.  ■ Action
  10447.  
  10448.    Moves the cursor to the specified position
  10449.  
  10450.  ■ Syntax
  10451.  
  10452.    LOCATE«row»«,«column»«,«cursor»«,«start»«,stop»»»»
  10453.  
  10454.  ■ Remarks
  10455.  
  10456.    The following list describes the LOCATE statement's arguments:
  10457.  
  10458. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  10459.    Argument                 Description
  10460.    Argument                 Description
  10461.    ──────────────────────────────────────────────────────────────────────────
  10462.    row                      The number of a row on the screen; row is a
  10463.                             numeric expression returning an integer. If row
  10464.                             is not specified, then the line (row) does not
  10465.                             change.
  10466.  
  10467.    column                   The number of a column on the screen; column is a
  10468.                             numeric expression returning an integer. If
  10469.                             column is not specified, then the column location
  10470.                             does not change.
  10471.  
  10472.    cursor                   A Boolean value indicating whether the cursor is
  10473.                             visible or not. A value of 0 (zero) indicates
  10474.                             cursor off; a value of 1 indicates cursor on.
  10475.  
  10476.    start                    The starting scan line of cursor on the screen.
  10477.                             It must be a numeric expression returning an
  10478.                             integer.
  10479.  
  10480.    stop                     The ending scan line of cursor on the screen. It
  10481.    Argument                 Description
  10482.    ──────────────────────────────────────────────────────────────────────────
  10483.   stop                     The ending scan line of cursor on the screen. It
  10484.                             must be a numeric expression returning an
  10485.                             integer.
  10486.    ──────────────────────────────────────────────────────────────────────────
  10487.  
  10488.  
  10489.    You may omit any argument from the statement except that if stop is
  10490.    specified, start must also be specified. When you omit the row or column,
  10491.    LOCATE leaves the cursor at the row or column where it was moved by a
  10492.    previous LOCATE or a previous input or output statement, whichever
  10493.    occurred most recently. When you omit other arguments, QuickBASIC assumes
  10494.    the previous value for the argument.
  10495.  
  10496.    Note that the start and stop lines are the CRT scan lines that specify
  10497.    which pixels on the screen are lit. A wider range between the start and
  10498.    stop lines produces a taller cursor, such as one that occupies an entire
  10499.    character block. When start is greater than stop, LOCATE produces a
  10500.    two-part cursor. If the start line is given but the stop line is omitted,
  10501.    stop assumes the same value as start.
  10502.  
  10503.    The last line on the screen is reserved for the soft-key display and is
  10504.    not accessible to the cursor unless the soft-key display is off (KEY OFF)
  10505.    and LOCATE is used with PRINT to write on the line.
  10506.  
  10507.  ■ See Also
  10508.  
  10509.    CSRLIN, POS
  10510.  
  10511.  ■ Examples
  10512.  
  10513.    The following statements show the effects on the cursor of different
  10514.    LOCATE statements:
  10515.  
  10516.    LOCATE 1,1    'Moves cursor to upper-left corner of the screen.
  10517.  
  10518.    LOCATE,,1     'Makes the cursor visible; position remains
  10519.                  'unchanged.
  10520.  
  10521.    LOCATE,,,7    'Position and cursor visibility remain unchanged;
  10522.                  'sets the cursor to display at the bottom of
  10523.                  'the character box starting and ending on
  10524.                  'scan line 7.
  10525.  
  10526.    LOCATE 5,1,1,0,7     'Moves the cursor to line 5, column 1;
  10527.                         'turns cursor on; cursor covers entire
  10528.                         'character cell starting at scan line
  10529.                         '0 and ending on scan line 7.
  10530.  
  10531.    The following example prints a menu on the screen, then waits for input in
  10532.    the allowable range (1-4). If a number outside that range is entered, the
  10533.    program continues to prompt for a selection.
  10534.  
  10535.    CONST FALSE=0, TRUE=NOT FALSE
  10536.    DO
  10537.        CLS
  10538.        PRINT "MAIN MENU" : PRINT
  10539.        PRINT "1)  Add Records"
  10540.        PRINT "2)  Display/Update/Delete a Record"
  10541.        PRINT "3)  Print Out List of People Staying at Hotel"
  10542.        PRINT "4)  End Program"
  10543.        ' Change cursor to a block.
  10544.        LOCATE ,,1,1,12
  10545.        LOCATE 12,1
  10546.        PRINT "What is your selection?";
  10547.        DO
  10548.           CH$ = INPUT$(1)
  10549.        LOOP WHILE (CH$ < "1" OR CH$ > "4")
  10550.        PRINT CH$
  10551.  
  10552.    ' Call the appropriate subprogram.
  10553.        SELECT CASE VAL(CH$)
  10554.           CASE 1
  10555.              CALL Add
  10556.           CASE 2
  10557.              CALL Search
  10558.           CASE 3
  10559.              CALL Hotel
  10560.           CASE 4
  10561.              CALL Quit
  10562.        END SELECT
  10563.    LOOP WHILE NOT ENDPROG
  10564.    .
  10565.    .
  10566.    .
  10567.    END
  10568.  
  10569.  
  10570.  ────────────────────────────────────────────────────────────────────────────
  10571.  LOCK...UNLOCK Statement
  10572.  ────────────────────────────────────────────────────────────────────────────
  10573.  
  10574.  ■ Action
  10575.  
  10576.    Controls access by other processes to all or part of an opened file
  10577.  
  10578.  ■ Syntax
  10579.  
  10580.    LOCK «#» filenumber «,{record | «start» TO end}»
  10581.    .
  10582.    .
  10583.    .
  10584.    UNLOCK «#» filenumber «,{record | «start» TO end}»
  10585.  
  10586.  ■ Remarks
  10587.  
  10588.    These statements are used in networked environments where several
  10589.    processes might need access to the same file. The LOCK and UNLOCK
  10590.    statements take the following arguments:
  10591.  
  10592.    Argument                 Description
  10593.    ──────────────────────────────────────────────────────────────────────────
  10594.    filenumber               The number with which the file was opened.
  10595.  
  10596.    record                   The number of the record or byte to be locked;
  10597.                             record can be any number from 1 to 2,147,483,647
  10598.                             (equivalent to 2^31-1). A record may be up to
  10599.                             32,767 bytes in length.
  10600.  
  10601.    start                    The number of the first record or byte to be
  10602.                             locked.
  10603.  
  10604.    end                      The number of the last record or byte to be
  10605.                             locked.
  10606.    ──────────────────────────────────────────────────────────────────────────
  10607.  
  10608.    For binary-mode files, the arguments record, start, and end represent the
  10609.    number of a byte relative to the beginning of the file. The first byte in
  10610.    a file is byte 1. For random-access files, the arguments record, start,
  10611.    and end are the number of a record relative to the beginning of the file.
  10612.    The first record is record 1.
  10613.  
  10614.    The LOCK and UNLOCK statements are always used in pairs. The arguments to
  10615.    LOCK and UNLOCK must match exactly when you use them. See the second
  10616.    example below.
  10617.  
  10618.    If you specify just one record, then only that record is locked or
  10619.    unlocked. If you specify a range of records and omit a starting record
  10620.    (start), then all records from the first record to the end of the range
  10621.    (end) are locked or unlocked. LOCK with no record arguments locks the
  10622.    entire file, while UNLOCK with no record arguments unlocks the entire
  10623.    file.
  10624.  
  10625.    If the file has been opened for sequential input or output, LOCK and
  10626.    UNLOCK affect the entire file, regardless of the range specified by start
  10627.    and end. LOCK and UNLOCK only function at run time if you are using
  10628.    versions of DOS that support networking (version 3.1 or later). In
  10629.    addition, each terminal (or the network setup programs) must run the DOS
  10630.    SHARE.EXE program to enable locking operations. Earlier versions of DOS
  10631.    return an error message that reads Advanced feature unavailable if LOCK
  10632.    and UNLOCK are executed.
  10633.  
  10634.  ────────────────────────────────────────────────────────────────────────────
  10635.  NOTE
  10636.    Be sure to remove all locks with an UNLOCK statement before closing a file
  10637.    or terminating your program. Failing to remove locks produces
  10638.    unpredictable results. The arguments to LOCK and UNLOCK must match
  10639.    exactly.
  10640.  ────────────────────────────────────────────────────────────────────────────
  10641.  
  10642.    If you attempt to access a file that is locked, the following error
  10643.    messages may appear:
  10644.  
  10645.    Bad record number
  10646.    Permission denied
  10647.  
  10648.  ■ Examples
  10649.  
  10650.    These examples assume a random-access file. The following statement locks
  10651.    the entire file opened as number 2:
  10652.  
  10653.    LOCK #2
  10654.  
  10655.    The following statement locks only record 32 in file number 2:
  10656.  
  10657.    LOCK #2, 32
  10658.  
  10659.    The following statement locks records 1-32 in file number 2:
  10660.  
  10661.    LOCK #2, TO 32
  10662.  
  10663.    The two UNLOCK statements below unlock the records locked by the preceding
  10664.    LOCK statements:
  10665.  
  10666.    LOCK #1, 1 TO 4
  10667.    LOCK #1, 5 TO 8
  10668.    UNLOCK #1, 1 TO 4
  10669.    UNLOCK #1, 5 TO 8
  10670.  
  10671.    The following UNLOCK statement is illegal because the range in an UNLOCK
  10672.    statement must exactly match the range in the corresponding LOCK
  10673.    statements (no error is reported, but the statements produce unpredictable
  10674.    results):
  10675.  
  10676.    LOCK #1, 1 TO 4
  10677.    LOCK #1, 5 TO 8
  10678.    UNLOCK #1, 1 TO 8
  10679.  
  10680.    The following program fragment opens a file and allows a user to lock an
  10681.    individual record before updating the information in that record. When the
  10682.    user is done, the program unlocks the locked record. (Unlocking the locked
  10683.    records allows other processes to use the data in the file.)
  10684.  
  10685.    TYPE AccountRec
  10686.       Payer AS STRING*15
  10687.       Address AS STRING*20
  10688.       Place AS STRING*20
  10689.       Owe AS SINGLE
  10690.    END TYPE
  10691.    DIM CustRec AS AccountRec
  10692.  
  10693.    OPEN "MONITOR" SHARED AS #1 LEN = LEN(CustRec)
  10694.  
  10695.    DO
  10696.       CLS:LOCATE 10,10
  10697.       INPUT "Customer Number?   #"; Number%
  10698.       ' Lock the current record so another process
  10699.       ' doesn't change it while you're using it.
  10700.       LOCK #1, Number%
  10701.          GET #1, Number%
  10702.          LOCATE 11,10: PRINT "Customer: ";CustRec.Payer
  10703.          LOCATE 12,10: PRINT "Address:  ";CustRec.Address
  10704.          LOCATE 13,10: PRINT "Currently owes: $";CustRec.Owe
  10705.          LOCATE 15,10: INPUT "Change (+ or -)", Change!
  10706.          CustRec.Owe=CustRec.Owe+Change!
  10707.          PUT #1, Number%
  10708.       ' Unlock the record.
  10709.       UNLOCK #1, Number%
  10710.       LOCATE 17,10: INPUT "Update another? ", Continue$
  10711.       Update$ = UCASE$(LEFT$(Continue$,1))
  10712.    LOOP WHILE Update$="Y"
  10713.  
  10714.  
  10715.  ────────────────────────────────────────────────────────────────────────────
  10716.  LOF Function
  10717.  ────────────────────────────────────────────────────────────────────────────
  10718.  
  10719.  ■ Action
  10720.  
  10721.    Returns the length of the named file in bytes
  10722.  
  10723.  ■ Syntax
  10724.  
  10725.    LOF(filenumber)
  10726.  
  10727.  ■ Remarks
  10728.  
  10729.    The argument filenumber is the number used in the OPEN statement. When a
  10730.    file is opened in any mode, the LOF function returns the size of the file
  10731.    in bytes.
  10732.  
  10733.    LOF cannot be used with the BASIC devices SCRN:, KYBD:, CONS:, and LPTn:.
  10734.    When used on a device opened as a file with the statement OPEN COM, the
  10735.    LOF function returns the number of bytes free in the output buffer.
  10736.  
  10737.  ■ Example
  10738.  
  10739.    See the example for the GET statement.
  10740.  
  10741.  
  10742.  ────────────────────────────────────────────────────────────────────────────
  10743.  LOG Function
  10744.  ────────────────────────────────────────────────────────────────────────────
  10745.  
  10746.  ■ Action
  10747.  
  10748.    Returns the natural logarithm of a numeric expression
  10749.  
  10750.  ■ Syntax
  10751.  
  10752.    LOG(n)
  10753.  
  10754.  ■ Remarks
  10755.  
  10756.    The numeric expression, n, must be greater than zero. The natural
  10757.    logarithm is the logarithm to the base e. The constant e is approximately
  10758.    equal to 2.718282.
  10759.  
  10760.    The LOG function calculates the natural logarithm with single-precision
  10761.    accuracy, unless the argument n is a double-precision value. In this case
  10762.    LOG is calculated with double-precision accuracy.
  10763.  
  10764.    You may calculate base-10 logarithms by dividing the natural logarithm of
  10765.    the number by the logarithm of 10. The following FUNCTION calculates
  10766.    base-10 logarithms:
  10767.  
  10768.    FUNCTION Log10(X) STATIC
  10769.       Log10=LOG(X)/LOG(10.#)
  10770.    END FUNCTION
  10771.  
  10772.  ■ Example
  10773.  
  10774.    The following example first prints the value of e and then prints the
  10775.    natural logarithms of e taken to the first, second, and third powers:
  10776.  
  10777.    PRINT EXP(1),
  10778.    FOR I = 1 TO 3
  10779.        PRINT LOG(EXP(1)^I),
  10780.    NEXT
  10781.  
  10782.  ■ Output
  10783.  
  10784.    2.718282       1       2       3
  10785.  
  10786.  
  10787.  ────────────────────────────────────────────────────────────────────────────
  10788.  LPOS Function
  10789.  ────────────────────────────────────────────────────────────────────────────
  10790.  
  10791.  ■ Action
  10792.  
  10793.    Returns the current position of the line printer's print head within the
  10794.    printer buffer
  10795.  
  10796.  ■ Syntax
  10797.  
  10798.    LPOS(n)
  10799.  
  10800.  ■ Remarks
  10801.  
  10802.    The argument n is the index of the printer being tested. For example,
  10803.    LPT1: would be tested with LPOS(1), while LPT2: would be tested with
  10804.    LPOS(2), and so on.
  10805.  
  10806.    The LPOS function does not necessarily give the physical position of the
  10807.    print head because it does not expand tab characters. In addition, some
  10808.    printers may buffer characters.
  10809.  
  10810.  ■ Example
  10811.  
  10812.    The following program prompts the user for team names and the names of
  10813.    players on each team. It then prints the players and their teams on the
  10814.    printer.
  10815.  
  10816.    LPRINT"Team Members"; TAB(76); "TEAM" : LPRINT
  10817.    INPUT "How many teams"; TEAMS
  10818.    INPUT "How many players per team";PPT
  10819.    PRINT
  10820.    FOR T = 1 TO TEAMS
  10821.        INPUT "Team name: ", TEAM$
  10822.        FOR P = 1 TO PPT
  10823.            INPUT "   Enter player name: ", PLAYER$
  10824.            LPRINT PLAYER$;
  10825.            IF P < PPT THEN
  10826.                IF LPOS(0) > 55 THEN     'Print a new line if print
  10827.                                          'head past column 55.
  10828.                   LPRINT : LPRINT "     ";
  10829.                ELSE
  10830.                   LPRINT ", ";           'Otherwise, print a comma.
  10831.                END IF
  10832.            END IF
  10833.        NEXT P
  10834.        LPRINT STRING$(80-LPOS(0)-LEN(TEAM$),"."); TEAM$
  10835.    NEXT T
  10836.  
  10837.  
  10838.  ────────────────────────────────────────────────────────────────────────────
  10839.  LPRINT, LPRINT USING Statements
  10840.  ────────────────────────────────────────────────────────────────────────────
  10841.  
  10842.  ■ Action
  10843.  
  10844.    Prints data on the printer LPT1:
  10845.  
  10846.  ■ Syntax 1
  10847.  
  10848.    LPRINT «expressionlist» «{;|,}»
  10849.  
  10850.  ■ Syntax 2
  10851.  
  10852.    LPRINT USING formatstring; expressionlist «{;|,}»
  10853.  
  10854.  ■ Remarks
  10855.  
  10856.    These statements function in the same way as the PRINT and PRINT USING
  10857.    statements except that output goes to the line printer and the filenumber
  10858.    option is not permitted.
  10859.  
  10860.    The LPRINT statement assumes an 80-character-wide printer. This width can
  10861.    be changed with a WIDTH LPRINT statement.
  10862.  
  10863.  ────────────────────────────────────────────────────────────────────────────
  10864.  WARNING
  10865.    Since the LPRINT statement uses the LPT1 printer device, you should not
  10866.    use LPRINT in a program that also contains an OPEN LPT1 statement. Using
  10867.    these two statements together produces unpredictable results.
  10868.  ────────────────────────────────────────────────────────────────────────────
  10869.  
  10870.  ■ Differences From Basica
  10871.  
  10872.    An LPRINT CHR$(13) statement actually outputs both CHR$(13) and CHR$(10).
  10873.    This feature was created to provide compatibility with BASICA.
  10874.  
  10875.  ■ See Also
  10876.  
  10877.    PRINT, PRINT USING, WIDTH
  10878.  
  10879.  ■ Example
  10880.  
  10881.    See examples for PRINT, PRINT USING.
  10882.  
  10883.  
  10884.  ────────────────────────────────────────────────────────────────────────────
  10885.  LSET Statement
  10886.  ────────────────────────────────────────────────────────────────────────────
  10887.  
  10888.  ■ Action
  10889.  
  10890.    Moves data from memory to a random-access file buffer (in preparation for
  10891.    a PUT statement), copies one record variable to another, or left-justifies
  10892.    the value of a string in a string variable
  10893.  
  10894.  ■ Syntax
  10895.  
  10896.    LSET {stringvariable=stringexpression | stringexpression1=
  10897.    stringexpression2}
  10898.  
  10899.  ■ Remarks
  10900.  
  10901.    The stringvariable is usually a random-access file field defined in a
  10902.    FIELD statement, although it can be any string variable. The
  10903.    stringexpression is the value assigned to the variable.
  10904.  
  10905.    If stringexpression requires fewer bytes than were defined for
  10906.    stringvariable in the FIELD statement, the LSET function left-justifies
  10907.    the string in the field (RSET will right-justify the string). Spaces are
  10908.    used to pad the extra positions. If the string is too long for the field,
  10909.    both LSET and RSET truncate characters from the right. Numeric values must
  10910.    be converted to strings before they are justified with the LSET or RSET
  10911.    statements.
  10912.  
  10913.  ────────────────────────────────────────────────────────────────────────────
  10914.  NOTE
  10915.    You may also use LSET or RSET with a string variable not defined in a
  10916.    FIELD statement to left-justify or right-justify a string in a given
  10917.    field. For example, the program lines
  10918.  
  10919.    A$=SPACE$(20)
  10920.    RSET A$=N$
  10921.  
  10922.    will right-justify the string N$ in a 20-character field. This can be
  10923.    useful for formatting printed output.
  10924.  
  10925.  ────────────────────────────────────────────────────────────────────────────
  10926.  
  10927.    You can use LSET to assign one record variable to another. The following
  10928.    example copies the contents of RecTwo to RecOne:
  10929.  
  10930.    TYPE TwoString
  10931.       StrFld AS STRING * 2
  10932.    END TYPE
  10933.  
  10934.    TYPE ThreeString
  10935.       StrFld AS STRING * 3
  10936.    END TYPE
  10937.    DIM RecOne AS TwoString, RecTwo AS ThreeString
  10938.    .
  10939.    .
  10940.    .
  10941.    LSET RecOne = RecTwo
  10942.  
  10943.    Notice that LSET is used to assign record variables of differing types.
  10944.    Record variables of the same type can be assigned using LET. Also, because
  10945.    RecOne is only two bytes long, only two bytes are copied from RecTwo. LSET
  10946.    copies only the number of bytes in the shorter of the two record
  10947.    variables.
  10948.  
  10949.  ■ See Also
  10950.  
  10951.    LET; MKD$, MKI$, MKL$, MKS$; PUT (File I/O); RSET
  10952.  
  10953.  ■ Example
  10954.  
  10955.    The first line of the following example converts the single-precision
  10956.    numeric variable AMT to a 4-byte string and stores that string in A$,
  10957.    left-justified. The second line converts the integer numeric variable
  10958.    COUNT% to a 2-byte string and stores that string in D$, right-justified.
  10959.  
  10960.    LSET A$ = MKS$(AMT)
  10961.    RSET D$ = MKI$(COUNT%)
  10962.  
  10963.  
  10964.  ────────────────────────────────────────────────────────────────────────────
  10965.  LTRIM$ Function
  10966.  ────────────────────────────────────────────────────────────────────────────
  10967.  
  10968.  ■ Action
  10969.  
  10970.    Returns a copy of a string with leading spaces removed
  10971.  
  10972.  ■ Syntax
  10973.  
  10974.    LTRIM$(stringexpression)
  10975.  
  10976.  ■ Remarks
  10977.  
  10978.    The stringexpression can be any string expression.
  10979.  
  10980.  ■ See Also
  10981.  
  10982.    RTRIM$
  10983.  
  10984.  ■ Example
  10985.  
  10986.    This program copies a file to a new file, removing all leading and
  10987.    trailing spaces:
  10988.  
  10989.    CLS
  10990.    ' Get the file names.
  10991.    INPUT "Enter input file name:",InFile$
  10992.    INPUT "Enter output file name:",OutFile$
  10993.  
  10994.    OPEN InFile$ FOR INPUT AS #1
  10995.    OPEN OutFile$ FOR OUTPUT AS #2
  10996.  
  10997.    ' Read, trim, and write each line.
  10998.    DO WHILE NOT EOF(1)
  10999.       LINE INPUT #1,LineIn$
  11000.       ' Remove leading and trailing blanks.
  11001.       LineIn$=LTRIM$(RTRIM$(LineIn$))
  11002.       PRINT #2, LineIn$
  11003.    LOOP
  11004.  
  11005.    CLOSE #1,#2
  11006.  
  11007.    END
  11008.  
  11009.  
  11010.  ────────────────────────────────────────────────────────────────────────────
  11011.  MID$ Function
  11012.  ────────────────────────────────────────────────────────────────────────────
  11013.  
  11014.  ■ Action
  11015.  
  11016.    Returns a substring of a string
  11017.  
  11018.  ■ Syntax
  11019.  
  11020.    MID$(stringexpression,start«,length»)
  11021.  
  11022.  ■ Remarks
  11023.  
  11024.    The MID$ function takes the following arguments:
  11025.  
  11026.    Argument                 Description
  11027.    ──────────────────────────────────────────────────────────────────────────
  11028.    stringexpression         The string expression that the substring is
  11029.                             extracted from. This can be any string
  11030.                             expression.
  11031.  
  11032.    start                    The character position in stringexpression where
  11033.                             the substring starts.
  11034.  
  11035.    length                   The number of characters to extract.
  11036.    ──────────────────────────────────────────────────────────────────────────
  11037.  
  11038.    The arguments start and length must be in the range 1 to 32,767. If length
  11039.    is omitted or if there are fewer than length characters to the right of
  11040.    the start character, the MID$ function returns all characters to the right
  11041.    of the start character.
  11042.  
  11043.    If start is greater than the number of characters in stringexpression,
  11044.    MID$ returns a null string.
  11045.  
  11046.    Use the LEN function to find the number of characters in stringexpression.
  11047.  
  11048.  ■ See Also
  11049.  
  11050.    LEFT$, LEN, MID$ Statement, RIGHT$
  11051.  
  11052.  ■ Example
  11053.  
  11054.    The following program converts a binary number to a decimal number. Digits
  11055.    are extracted from the binary number (input as a string) using MID$.
  11056.  
  11057.    INPUT "Binary number = ",Binary$   'Input binary number as
  11058.                                       'string.
  11059.    Length = LEN(Binary$)              'Get length of string.
  11060.    Decimal = 0
  11061.  
  11062.    FOR K = 1 TO Length
  11063.       'Get individual digits from string, from left to right.
  11064.       Digit$ = MID$(Binary$,K,1)
  11065.       'Test for valid binary digit.
  11066.       IF Digit$="0" OR Digit$="1" THEN
  11067.          'Convert digit characters to numbers.
  11068.          Decimal = 2*Decimal + VAL(Digit$)
  11069.       ELSE
  11070.          PRINT "Error--invalid binary digit: ";Digit$
  11071.          EXIT FOR
  11072.       END IF
  11073.    NEXT
  11074.    PRINT "Decimal number =" Decimal
  11075.  
  11076.  ■ Output
  11077.  
  11078.    Binary number = 10110
  11079.    Decimal number = 22
  11080.  
  11081.  
  11082.  ────────────────────────────────────────────────────────────────────────────
  11083.  MID$ Statement
  11084.  ────────────────────────────────────────────────────────────────────────────
  11085.  
  11086.  ■ Action
  11087.  
  11088.    Replaces a portion of a string variable with another string
  11089.  
  11090.  ■ Syntax
  11091.  
  11092.    MID$(stringvariable,start«,length»)=stringexpression
  11093.  
  11094.  ■ Remarks
  11095.  
  11096.    The MID$ statement has the following arguments:
  11097.  
  11098.    Argument                 Description
  11099.    ──────────────────────────────────────────────────────────────────────────
  11100.    stringvariable           The string variable being modified.
  11101.  
  11102.    start                    A numeric expression giving the position in
  11103.                             stringvariable where the replacement starts.
  11104.  
  11105.    length                   The length of the string being replaced. The
  11106.                             length is a numeric expression.
  11107.  
  11108.    stringexpression         The string expression that replaces part of the
  11109.                             stringvariable.
  11110.    ──────────────────────────────────────────────────────────────────────────
  11111.  
  11112.    The arguments start and length are integer expressions. The argument
  11113.    stringvariable is a string variable, but stringexpression can be a string
  11114.    variable, a string constant, or a string expression.
  11115.  
  11116.    The optional length refers to the number of characters from the argument
  11117.    stringexpression that are used in the replacement. If length is omitted,
  11118.    all of stringexpression is used. However, regardless of whether length is
  11119.    omitted or included, the replacement of characters never goes beyond the
  11120.    original length of stringvariable.
  11121.  
  11122.  ■ See Also
  11123.  
  11124.    MID$ Function
  11125.  
  11126.  ■ Example
  11127.  
  11128.    The following example uses the MID$ statement to get characters from a
  11129.    string:
  11130.  
  11131.    Test$ = "Paris, France"
  11132.    PRINT Test$
  11133.    MID$(Test$,8)="Texas "
  11134.    PRINT Test$
  11135.  
  11136.  ■ Output
  11137.  
  11138.    Paris, France
  11139.    Paris, Texas
  11140.  
  11141.  
  11142.  ────────────────────────────────────────────────────────────────────────────
  11143.  MKDIR Statement
  11144.  ────────────────────────────────────────────────────────────────────────────
  11145.  
  11146.  ■ Action
  11147.  
  11148.    Creates a new directory
  11149.  
  11150.  ■ Syntax
  11151.  
  11152.    MKDIR pathname
  11153.  
  11154.  ■ Remarks
  11155.  
  11156.    The pathname is a string expression specifying the name of the directory
  11157.    to be created. The pathname must be a string of less than 128 characters.
  11158.  
  11159.    The MKDIR statement works like the DOS command MKDIR; the syntax in BASIC
  11160.    cannot, however, be shortened to MD, as in DOS.
  11161.  
  11162.  ■ See Also
  11163.  
  11164.    CHDIR, RMDIR
  11165.  
  11166.  ■ Example
  11167.  
  11168.    The following fragment creates a new directory (if the directory does not
  11169.    exist) and copies files into that directory:
  11170.  
  11171.    ON ERROR GOTO Errorhandler
  11172.    PRINT "This program creates a new directory named MONTHS"
  11173.    PRINT "in this directory, then creates files in that directory"
  11174.    MKDIR "MONTHS"
  11175.    DO
  11176.        INPUT "Filename"; File$
  11177.        IF File$ = "" THEN END
  11178.        OPEN "MONTHS\" + File$ FOR OUTPUT AS #1
  11179.        .
  11180.        .
  11181.        .
  11182.        CLOSE #1
  11183.    LOOP
  11184.  
  11185.    Errorhandler:
  11186.        'Error 75 means MONTHS directory already exists
  11187.        IF ERR = 75 THEN RESUME NEXT
  11188.        ON ERROR GOTO 0
  11189.  
  11190.  
  11191.  ────────────────────────────────────────────────────────────────────────────
  11192.  MKSMBF$, MKDMBF$ Functions
  11193.  ────────────────────────────────────────────────────────────────────────────
  11194.  
  11195.  ■ Action
  11196.  
  11197.    Converts an IEEE-format number to a string containing a Microsoft Binary
  11198.    format number.
  11199.  
  11200.  ■ Syntax
  11201.  
  11202.    MKSMBF$(single-precision-expression)
  11203.    MKDMBF$(double-precision-expression)
  11204.  
  11205.  ■ Remarks
  11206.  
  11207.    These functions are used to write real numbers to random-access files
  11208.    using Microsoft Binary format. They are particularly useful for
  11209.    maintaining data files created with older versions of BASIC.
  11210.  
  11211.    The MKSMBF$ and MKDMBF$ functions convert real numbers in IEEE-format to
  11212.    strings so they can be written to the random-access file.
  11213.  
  11214.    To write a real number to a random-access file in Microsoft Binary format,
  11215.    convert the number to a string using MKSMBF$ (for a single-precision
  11216.    number) or MKDMBF$ (for a double-precision number). Then store the result
  11217.    in the corresponding field (defined in the FIELD statement) and write the
  11218.    record to the file using the PUT statement.
  11219.  
  11220.  ■ Example
  11221.  
  11222.    The following example uses MKSMBF$ to store real values in a file as
  11223.    Microsoft Binary format numbers:
  11224.  
  11225.    ' Read a name and a test score from the console.
  11226.    ' Store as a record in a random-access file.
  11227.    ' Scores are written out as
  11228.    ' Microsoft Binary format single-precision values.
  11229.  
  11230.    TYPE Buffer
  11231.       NameField AS STRING * 20
  11232.       ScoreField AS STRING * 4
  11233.    END TYPE
  11234.  
  11235.    DIM RecBuffer AS Buffer
  11236.    OPEN "TESTDAT.DAT" FOR RANDOM AS #1 LEN=LEN(RecBuffer)
  11237.  
  11238.    PRINT "Enter names and scores, one name and score per line."
  11239.    PRINT "Enter END, 0 to end input."
  11240.  
  11241.    INPUT NameIn$, Score
  11242.  
  11243.    I=0
  11244.  
  11245.    ' Read pairs of names and scores from the console
  11246.    ' until the name is END.
  11247.  
  11248.    DO WHILE UCASE$(NameIn$) <> "END"
  11249.       I=I+1
  11250.       RecBuffer.NameField=NameIn$
  11251.  
  11252.    ' Convert the score to a string.
  11253.       RecBuffer.ScoreField=MKSMBF$(Score)
  11254.       PUT #1,I,RecBuffer
  11255.       INPUT NameIn$, Score
  11256.    LOOP
  11257.  
  11258.    PRINT I;" records written."
  11259.  
  11260.    CLOSE #1
  11261.  
  11262.  
  11263.  ────────────────────────────────────────────────────────────────────────────
  11264.  MKD$, MKI$, MKL$, MKS$ Functions
  11265.  ────────────────────────────────────────────────────────────────────────────
  11266.  
  11267.  ■ Action
  11268.  
  11269.    Converts numeric values to string values
  11270.  
  11271.  ■ Syntax
  11272.  
  11273.    MKI$(integerexpression)
  11274.    MKS$(single-precision-expression)
  11275.    MKL$(long-integer-expression)
  11276.    MKD$(double-precision-expression)
  11277.  
  11278.  ■ Remarks
  11279.  
  11280.    The MKI$, MKS$, MKL$, and MKD$ functions are used with FIELD and PUT
  11281.    statements to write real numbers to a random-access file. The functions
  11282.    take numeric expressions and convert them to strings that can be stored in
  11283.    the strings defined in the FIELD statement. The functions are the inverse
  11284.    of CVI, CVS, CVL, and CVD.
  11285.  
  11286.    Function                 Description
  11287.    ──────────────────────────────────────────────────────────────────────────
  11288.    MKI$                     Converts an integer to a two-byte string
  11289.  
  11290.    MKS$                     Converts a single-precision value to a four-byte
  11291.                             string
  11292.  
  11293.    MKL$                     Converts a long-integer value to a four-byte
  11294.                             string
  11295.  
  11296.    MKD$                     Converts a double-precision value to an
  11297.                             eight-byte string
  11298.    ──────────────────────────────────────────────────────────────────────────
  11299.  
  11300.  ────────────────────────────────────────────────────────────────────────────
  11301.  NOTE
  11302.    BASIC record variables provide a more efficient and convenient way of
  11303.    reading and writing random-access files. See Chapter 3, "File and Device
  11304.    I/O," in Programming in BASIC for a discussion of the new method.
  11305.  ────────────────────────────────────────────────────────────────────────────
  11306.  
  11307.  ■ See Also
  11308.  
  11309.    CVI, CVS, CVL, CVD; FIELD; PUT
  11310.  
  11311.  ■ Example
  11312.  
  11313.    See the example for the CVI, CVS, CVL, CVD statements.
  11314.  
  11315.  
  11316.  ────────────────────────────────────────────────────────────────────────────
  11317.  NAME Statement
  11318.  ────────────────────────────────────────────────────────────────────────────
  11319.  
  11320.  ■ Action
  11321.  
  11322.    Changes the name of a disk file or directory
  11323.  
  11324.  ■ Syntax
  11325.  
  11326.    NAME oldfilename AS newfilename
  11327.  
  11328.  ■ Remarks
  11329.  
  11330.    The NAME statement is similar to the DOS RENAME command. NAME can move a
  11331.    file from one directory to another but cannot move a directory.
  11332.  
  11333.    The arguments oldfilename and newfilename are string expressions each of
  11334.    which contains a file or directory name and an optional path. If the path
  11335.    in newfilename is different from the path in oldfilename, the NAME
  11336.    statement changes the pathname as well as renames the file as indicated.
  11337.  
  11338.    A file named oldfilename must exist and the newfilename must not be in
  11339.    use. Both files must be on the same drive. Using NAME with different drive
  11340.    designations in the old and new file names produces an error message that
  11341.    reads Rename across disks.
  11342.  
  11343.    After a NAME statement, the file or directory exists on the same disk, in
  11344.    the same disk space, but with the new name.
  11345.  
  11346.    Using NAME on an open file causes a run-time error message reading File
  11347.    already open. You must close an open file before renaming it.
  11348.  
  11349.  ■ Examples
  11350.  
  11351.    The following statements show NAME used with and without a path
  11352.    specification:
  11353.  
  11354.    'Changes the name of file ACCTS to LEDGER.
  11355.    NAME "ACCTS" AS "LEDGER"
  11356.  
  11357.    'Moves file CLIENTS from directory X to directory \XYZ\P.
  11358.    NAME "\X\CLIENTS" AS "\XYZ\P\CLIENTS"
  11359.  
  11360.  
  11361.  ────────────────────────────────────────────────────────────────────────────
  11362.  OCT$ Function
  11363.  ────────────────────────────────────────────────────────────────────────────
  11364.  
  11365.  ■ Action
  11366.  
  11367.    Returns a string representing the octal value of the numeric argument
  11368.  
  11369.  ■ Syntax
  11370.  
  11371.    OCT$(numeric-expression)
  11372.  
  11373.  ■ Remarks
  11374.  
  11375.    The numeric-expression may be of any type. The numeric-expression is
  11376.    rounded to an integer or long integer before the OCT$ function evaluates
  11377.    it.
  11378.  
  11379.  ■ See Also
  11380.  
  11381.    HEX$
  11382.  
  11383.  ■ Example
  11384.  
  11385.    The following line prints the octal representation of 24:
  11386.  
  11387.    PRINT OCT$(24)
  11388.  
  11389.  ■ Output
  11390.  
  11391.    30
  11392.  
  11393.  
  11394.  ────────────────────────────────────────────────────────────────────────────
  11395.  ON event Statements
  11396.  ────────────────────────────────────────────────────────────────────────────
  11397.  
  11398.  ■ Action
  11399.  
  11400.    Indicates the first line of an event-trapping subroutine
  11401.  
  11402.  ■ Syntax
  11403.  
  11404.    ON event GOSUB {linenumber | linelabel }
  11405.  
  11406.  ■ Remarks
  11407.  
  11408.    The ON event statement lets you specify a subroutine that is executed
  11409.    whenever an event occurs on a specified device. The following list
  11410.    describes the parts of the statement:
  11411.  
  11412.    Argument                 Description
  11413.    ──────────────────────────────────────────────────────────────────────────
  11414.    event                    Specifies the event that causes a branch to the
  11415.                             event-trapping subroutine. An event is a
  11416.                             condition on a specific device. See below for
  11417.                             more information about specific devices.
  11418.  
  11419.    linenumber linelabel     The number or label of the first line in the
  11420.                             event-trapping subroutine. This line must be in
  11421.                             the module-level code.
  11422.    ──────────────────────────────────────────────────────────────────────────
  11423.  
  11424.    A linenumber of 0 disables event trapping and does not specify line 0 as
  11425.    the start of the subroutine.
  11426.  
  11427.    The following list describes the events that can be trapped:
  11428.  
  11429. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  11430.    Event                    Description
  11431.    ──────────────────────────────────────────────────────────────────────────
  11432.    COM(n)                   Branches to the subroutine when characters are
  11433.                             received at a communications port. The integer
  11434.                             expression n indicates one of the serial ports,
  11435.                             either 1 or 2.
  11436.  
  11437.    KEY(n)                   Branches to the subroutine when a specified key
  11438.                             is pressed. The integer expression n is the
  11439.                             number of a function key, direction key, or
  11440.                             user-defined key. See Appendix A, "Keyboard Scan
  11441.                             Codes and ASCII Character Codes," and the KEY
  11442.                             statement for more information about these
  11443.                             values.
  11444.  
  11445.    PEN                      Branches to the subroutine when a lightpen is
  11446.                             activated.
  11447.    Event                    Description
  11448.    ──────────────────────────────────────────────────────────────────────────
  11449.                            activated.
  11450.  
  11451.    PLAY(queuelimit)         Branches when the number of notes in the music
  11452.                             buffer goes from queuelimit to queuelimit-1. The
  11453.                             value of queuelimit is an integer expression from
  11454.                             1 to 32.
  11455.  
  11456.                             A PLAY event-trapping subroutine can be used with
  11457.                             a PLAY statement to play music in the background
  11458.                             while a program is running.
  11459.  
  11460.    STRIG(n)                 Branches to the event-trapping subroutine when a
  11461.                             joystick trigger is pressed. The integer
  11462.                             expression n is the joystick trigger number: 0
  11463.                             for the lower button and 4 for the upper button
  11464.                             on the first joystick; 2 for the lower button and
  11465.                             6 for the upper button on the second joystick.
  11466.  
  11467.    TIMER(n)                 Branches to the subroutine when n seconds have
  11468.    Event                    Description
  11469.    ──────────────────────────────────────────────────────────────────────────
  11470.   TIMER(n)                 Branches to the subroutine when n seconds have
  11471.                             passed. The integer expression n is in the range
  11472.                             1 to 86,400 (1 second to 24 hours).
  11473.    ──────────────────────────────────────────────────────────────────────────
  11474.  
  11475.  
  11476.    The ON event statement only specifies the start of an event-trapping
  11477.    subroutine. Another set of statements determines whether or not the
  11478.    subroutine is called. This set of statements turns event trapping on or
  11479.    off and determines how events are handled when trapping is off. The
  11480.    following list describes these statements in a general way. See the
  11481.    entries for particular statements for more specific information.
  11482.  
  11483.    Event                    Description
  11484.    ──────────────────────────────────────────────────────────────────────────
  11485.    event ON                 Enables event trapping. Event trapping occurs
  11486.                             only after an event ON statement is executed.
  11487.  
  11488.    event OFF                Disables event trapping. No trapping takes place
  11489.                             until the execution of another event ON
  11490.                             statement. Events occurring while trapping is off
  11491.                             are ignored.
  11492.  
  11493.    event STOP               Inhibits event trapping so no trapping takes
  11494.                             place until an event ON statement is executed.
  11495.                             Events occurring while trapping is inhibited are
  11496.                             remembered and processed when an event ON
  11497.                             statement is executed.
  11498.    ──────────────────────────────────────────────────────────────────────────
  11499.  
  11500.    When an event trap occurs (the subroutine is called), BASIC performs an
  11501.    automatic event STOP that prevents recursive traps. The RETURN from the
  11502.    trapping subroutine automatically performs an event ON statement unless an
  11503.    explicit event OFF is performed inside the subroutine.
  11504.  
  11505.  ────────────────────────────────────────────────────────────────────────────
  11506.  NOTE
  11507.    Because of the implicit event STOP and event ON statements, the events
  11508.    during execution of the trapping subroutine are remembered and processed
  11509.    when the trapping subroutine ends.
  11510.  ────────────────────────────────────────────────────────────────────────────
  11511.  
  11512.    The RETURN linenumber or RETURN linelabel forms of RETURN can be used to
  11513.    return to a specific line number from the trapping subroutine. Use this
  11514.    type of return with care, however, because any other GOSUB, WHILE, or FOR
  11515.    statements active at the time of the trap remain active. This may produce
  11516.    error messages such as NEXT without FOR. In addition, if an event occurs
  11517.    in a procedure, a RETURN linenumber or RETURN linelabel statement cannot
  11518.    get back into the procedure──the line number or label must be in the
  11519.    module-level code.
  11520.  
  11521.    The next three sections contain additional information about the ON COM,
  11522.    ON KEY, and ON PLAY statements.
  11523.  
  11524.    USING ON COM
  11525.  
  11526.    If your program receives data using an asynchronous communications
  11527.    adapter, the BASIC command-line option /C can be used to set the size of
  11528.    the data buffer.
  11529.  
  11530.    USING ON KEY
  11531.  
  11532.    Keys are processed in the following order:
  11533.  
  11534.    1. The line printer's echo-toggle key is processed first. Making this key
  11535.       a user-defined key trap does not prevent characters from being echoed
  11536.       to the line printer when pressed.
  11537.  
  11538.    2. Function keys and the cursor-direction keys are examined next. Defining
  11539.       a FUNCTION key or DIRECTION key as a user-defined key trap has no
  11540.       effect because these keys are predefined.
  11541.  
  11542.    3. Finally, the user-defined keys are examined.
  11543.  
  11544.    The ON KEY statement can trap any key, including BREAK or system reset.
  11545.    This makes it possible to prevent accidentally breaking out of a program
  11546.    or rebooting the machine.
  11547.  
  11548.  ────────────────────────────────────────────────────────────────────────────
  11549.  NOTE
  11550.    When a key is trapped, the key event is destroyed. You cannot subsequently
  11551.    use INPUT or INKEY$ statements to find out which key caused the trap.
  11552.    Because there is no way to know which key press caused the branch to the
  11553.    trap, you must set up a subroutine for each key if you want to assign
  11554.    different functions to particular keys.
  11555.  ────────────────────────────────────────────────────────────────────────────
  11556.  
  11557.    USING ON PLAY
  11558.  
  11559.    The following three rules apply to the use of ON PLAY:
  11560.  
  11561.    1. A play event trap occurs only when music is playing in the background.
  11562.       Play event traps do not occur when music is running in the foreground.
  11563.  
  11564.    2. A play event trap does not occur if the background music queue has
  11565.       already gone from having queuelimit to queuelimit-1 notes when a PLAY
  11566.       ON is executed.
  11567.  
  11568.    3. If queuelimit is a large number, event traps may occur often enough to
  11569.       slow down the program.
  11570.  
  11571.  ■ Differences From Basica
  11572.  
  11573.    If you use BC from the DOS prompt, you must use /V or /W if a program
  11574.    contains ON event statements to allow the compiler to function correctly
  11575.    when event-trapping subroutines are included in a program. BASICA does not
  11576.    require additional options.
  11577.  
  11578.  ■ See Also
  11579.  
  11580.    COM, KEY (n), PEN ON, PLAY ON, RETURN, STRIG ON, TIMER ON
  11581.  
  11582.  ■ Examples
  11583.  
  11584.    The following example plays continuous music by calling an event-handling
  11585.    subroutine whenever the music buffer goes from three to two notes:
  11586.  
  11587.    '  Call subroutine Background when the music buffer goes from
  11588.    '  3 to 2 notes.
  11589.    ON PLAY(3) GOSUB Background
  11590.    '  Turn on event trapping for PLAY.
  11591.    PLAY ON
  11592.  
  11593.    '  Define a string containing the melody.
  11594.    Lizzie$="o3 L8 E D+ E D+ E o2 B o3 D C L2 o2 A"
  11595.    '  Play the melody for the first time.
  11596.    PLAY "MB X" + VARPTR$(Lizzie$)
  11597.  
  11598.    '  Continue until a key is pressed.
  11599.    LOCATE 2,1 : PRINT "Press any key to stop.";
  11600.    DO WHILE INKEY$=""
  11601.    LOOP
  11602.  
  11603.    END
  11604.  
  11605.    ' PLAY event-handling subroutine.
  11606.    Background:
  11607.       ' Increment and print a counter each time.
  11608.       Count% = Count% + 1
  11609.       LOCATE 1,1 : PRINT "Background called ";Count%;"time(s)";
  11610.       ' Execute another PLAY to fill the buffer.
  11611.       PLAY "MB X" + VARPTR$(Lizzie$)
  11612.       RETURN
  11613.  
  11614.    The following example draws a polygon every three seconds with a random
  11615.    shape (three to seven sides), size, and location:
  11616.  
  11617.    SCREEN 1
  11618.    DEFINT A-Z
  11619.    DIM X(6), Y(6)
  11620.    TIMER ON            'Enable timer event trapping.
  11621.    ON TIMER(3) GOSUB Drawpoly    'Draw a new polygon every
  11622.                                  'three seconds.
  11623.    PRINT "Press any key to end program"
  11624.    INPUT "Press <RETURN> to start",Test$
  11625.  
  11626.    DO
  11627.    LOOP WHILE INKEY$=""     'End program if any key pressed.
  11628.  
  11629.    END
  11630.  
  11631.    Drawpoly:
  11632.       CLS            'Erase old polygon.
  11633.       N = INT(5*RND + 2)      'N is random number from 2 to 6.
  11634.       FOR I = 0 TO N
  11635.          X(I) = INT(RND*319)   'Get coordinates of vertices of
  11636.          Y(I) = INT(RND*199)   'polygon.
  11637.       NEXT
  11638.       PSET (X(N),Y(N))
  11639.       FOR I = 0 TO N
  11640.          LINE -(X(I),Y(I)),2   'Draw new polygon.
  11641.       NEXT
  11642.       RETURN
  11643.  
  11644.  
  11645.  ────────────────────────────────────────────────────────────────────────────
  11646.  ON ERROR Statement
  11647.  ────────────────────────────────────────────────────────────────────────────
  11648.  
  11649.  ■ Action
  11650.  
  11651.    Enables error handling and specifies the first line of the error-handling
  11652.    routine
  11653.  
  11654.  ■ Syntax
  11655.  
  11656.    ON ERROR GOTO line
  11657.  
  11658.  ■ Remarks
  11659.  
  11660.    The line argument is the line number or line label of the first line in
  11661.    the error-handling routine. This line must appear in module-level code.
  11662.  
  11663.    If line cannot be found in the module where the error occurred, or if
  11664.    there is no ON ERROR GOTO statement, a backward search is made through the
  11665.    modules that invoked the module with the error. If an active error handler
  11666.    is found, it is used. If no active error handler is found, an error
  11667.    message is printed and program execution halts. The specific error message
  11668.    depends on the type of error.
  11669.  
  11670.    Only modules in the invocation path are searched. Modules outside the path
  11671.    are not searched, even if there is no active error handler in the search
  11672.    path.
  11673.  
  11674.    A line number of 0 disables error handling. It does not specify line 0 as
  11675.    the start of the error-handling code, even if the program contains a line
  11676.    numbered 0. Subsequent errors print an error message and halt the program.
  11677.    Once error handling is enabled, any error that can be trapped causes a
  11678.    jump to the specified error-handling routine.
  11679.  
  11680.    Inside an error handler, executing an ON ERROR statement with a line
  11681.    number of 0 halts program execution and prints the error message for the
  11682.    error that caused the trap. This is a convenient way to halt a program in
  11683.    response to errors that cannot be processed by the error-handling routine.
  11684.  
  11685.    Note that an error-handling routine is not a SUB or FUNCTION procedure or
  11686.    a DEF FN function. An error-handling routine is a module-level block of
  11687.    code marked by a line label or line number.
  11688.  
  11689.  ────────────────────────────────────────────────────────────────────────────
  11690.  NOTE
  11691.    Errors occurring within an error-handling routine are not trapped. These
  11692.    errors halt program execution after printing an error message.
  11693.  ────────────────────────────────────────────────────────────────────────────
  11694.  
  11695.  ■ Differences From Basica
  11696.  
  11697.    Compiling from the BC command line requires additional options when you
  11698.    use ON ERROR GOTO. BASICA does not require any additional options. If a
  11699.    program contains ON ERROR GOTO or RESUME linenumber statements, you must
  11700.    use the On Error /E compile option when compiling from the BC command
  11701.    line. If a program contains the statements RESUME, RESUME NEXT, or RESUME
  11702.    0, you must also use the Resume Next /X compile option when compiling from
  11703.    the command line. No compile options are required when compiling within
  11704.    the QuickBASIC environment.
  11705.  
  11706.  ■ See Also
  11707.  
  11708.    ERR, ERL; ERROR; RESUME
  11709.  
  11710.  ■ Example
  11711.  
  11712.    The following program gets a file name from the user and displays the file
  11713.    on the screen. If the file cannot be opened, an error-handling routine
  11714.    traps the error and starts the program again at the prompt for the file
  11715.    name.
  11716.  
  11717.    DEFINT A-Z
  11718.  
  11719.    ' Establish the error-handling routine.
  11720.    ON ERROR GOTO ErrorHandler
  11721.  
  11722.    CLS
  11723.  
  11724.    ' Get a file name.
  11725.    INPUT "Enter the file to display: ",filename$
  11726.    ' Open the file.
  11727.    OPEN filename$ FOR INPUT AS #1
  11728.  
  11729.    ' Display the file on the screen.
  11730.    DO WHILE NOT EOF(1)
  11731.       LINE INPUT #1, aline$
  11732.       PRINT aline$
  11733.    LOOP
  11734.  
  11735.    END
  11736.  
  11737.    ' Error handling routine handles only "Bad file name,"
  11738.    ' aborts on any other error.
  11739.  
  11740.    CONST BADFILENAME=64
  11741.  
  11742.    ErrorHandler:
  11743.       IF ERR=BADFILENAME THEN
  11744.          ' Get another file name.
  11745.          PRINT "File "; UCASE$(filename$); " not found."
  11746.          INPUT "Enter the file to display: ",filename$
  11747.          RESUME
  11748.       ELSE
  11749.          ' Some other error, so print message and abort.
  11750.          PRINT "Unrecoverable error--";ERR
  11751.          ON ERROR GOTO 0
  11752.       END IF
  11753.  
  11754.  
  11755.  ────────────────────────────────────────────────────────────────────────────
  11756.  ON...GOSUB, ON...GOTO Statements
  11757.  ────────────────────────────────────────────────────────────────────────────
  11758.  
  11759.  ■ Action
  11760.  
  11761.    Branches to one of several specified lines, depending on the value of an
  11762.    expression
  11763.  
  11764.  ■ Syntax 1
  11765.  
  11766.    ON expression GOSUB {line-number-list | line-label-list }
  11767.  
  11768.  ■ Syntax 2
  11769.  
  11770.    ON expression GOTO {line-number-list | line-label-list }
  11771.  
  11772.  ■ Remarks
  11773.  
  11774.    The expression argument can be any numeric expression (expression is
  11775.    rounded to an integer before the ON...GOSUB or ON...GOTO is evaluated).
  11776.    The line-number-list or line-label-list consists of a list of line numbers
  11777.    or line labels, separated by commas. The value of expression determines
  11778.    which line the program branches to. For example, if the value is 3, the
  11779.    third line specified in the list is the destination of the branch.
  11780.  
  11781.    The value of expression should be greater than or equal to 1 and less than
  11782.    or equal to the number of items in the list. If the value falls outside
  11783.    this range, one of the following results occurs:
  11784.  
  11785.    Value                                            Result
  11786.    ──────────────────────────────────────────────────────────────────────────
  11787.    Number equal to 0 or greater than number of      Control drops to the next
  11788.    items in list                                    BASIC statement.
  11789.  
  11790.    Negative number or a number greater than 255     An error message appears
  11791.                                                     that reads Illegal
  11792.                                                     function call.
  11793.    ──────────────────────────────────────────────────────────────────────────
  11794.  
  11795.    You may mix line numbers and labels in the same list.
  11796.  
  11797.  ────────────────────────────────────────────────────────────────────────────
  11798.  NOTE
  11799.    The ON...GOTO statement accepts a maximum of 60 line labels or line
  11800.    numbers. The SELECT CASE statement provides a more powerful, convenient,
  11801.    and flexible way to do multiple branches.
  11802.  ────────────────────────────────────────────────────────────────────────────
  11803.  
  11804.  ■ See Also
  11805.  
  11806.    GOSUB, RETURN, SELECT CASE
  11807.  
  11808.  ■ Example
  11809.  
  11810.    The following program fragment causes program control to branch to one of
  11811.    the four subroutines listed, depending on the value of Chval:
  11812.  
  11813.    DO
  11814.        CLS
  11815.        PRINT "1) Display attendance at workshops."
  11816.        PRINT "2) Calculate total registration fees paid."
  11817.        PRINT "3) Print mailing list."
  11818.        PRINT "4) End program."
  11819.        PRINT : PRINT "What is your choice?"
  11820.        DO
  11821.           Ch$=INKEY$
  11822.        LOOP WHILE Ch$=""
  11823.        Chval = VAL(Ch$)
  11824.        IF Chval > 0 AND Chval < 5 THEN
  11825.            ON Chval GOSUB Shop, Fees, Mailer, Progend
  11826.        END IF
  11827.    LOOP
  11828.    END
  11829.    .
  11830.    .
  11831.    .
  11832.  
  11833.  
  11834.  ────────────────────────────────────────────────────────────────────────────
  11835.  ON UEVENT GOSUB Statement
  11836.  ────────────────────────────────────────────────────────────────────────────
  11837.  
  11838.  ■ Action
  11839.  
  11840.    Defines the event-handler for a user-defined event
  11841.  
  11842.  ■ Syntax
  11843.  
  11844.    ON UEVENT GOSUB { linenumber | linelabel }
  11845.  
  11846.  ■ Remarks
  11847.  
  11848.    The linenumber or linelabel argument is the number or label of the first
  11849.    line in the event-handling routine. ON UEVENT GOSUB lets your program
  11850.    branch to an event-handling routine when a user-defined event occurs. The
  11851.    event is usually a hardware interrupt.
  11852.  
  11853.    This gives user-defined events one of the features enjoyed by the COM,
  11854.    KEY, and other events in BASIC. Once these events have been defined with
  11855.    an ON event statement, they act like interrupts. The program does not need
  11856.    to poll for the event.
  11857.  
  11858.    Likewise, once ON UEVENT GOSUB and UEVENT ON have been executed, the
  11859.    user-defined event automatically triggers execution of the BASIC routine
  11860.    to handle it. The program does not have to poll.
  11861.  
  11862.    At least two (and sometimes three) pieces of code are needed to set up a
  11863.    user-defined event. The first is the interrupt service routine. The second
  11864.    is an initialization routine to insert the address of the service routine
  11865.    into the interrupt vector table. The third is the routine your BASIC
  11866.    program calls to retrieve the data (if any) collected by the interrupt
  11867.    service routine.
  11868.  
  11869.    If the initialization routine "steals" an interrupt used by another
  11870.    service routine, the original address must be restored before your program
  11871.    terminates.
  11872.  
  11873.    These routines are usually written in assembly language. However, any
  11874.    language whose compiler can generate interrupt service routines and whose
  11875.    object code can be linked with BASIC may be used.
  11876.  
  11877.    There are four steps in creating a user-defined event:
  11878.  
  11879.    1. Write an event-handling routine and add it to your BASIC program.
  11880.  
  11881.    2. Execute the ON UEVENT GOSUB statement to specify the user-event
  11882.       handling routine.
  11883.  
  11884.    3. Execute the UEVENT ON statement to enable user-event trapping.
  11885.  
  11886.    4. Call the interrupt-initialization routine to insert the address of the
  11887.       interrupt service routine into the interrupt vector table.
  11888.  
  11889.    You're now ready for the interrupt when it occurs. The interrupt transfers
  11890.    execution to the interrupt service routine. The service routine collects
  11891.    and stores the data the user wants. It then calls SetUEvent.
  11892.  
  11893.    SetUEvent sets a flag checked by QuickBASIC before going to the next BASIC
  11894.    statement (or label if executing compiled code using /W instead of /V).
  11895.    When the flag is set, control transfers to the event-handling routine
  11896.    designated in ON UEVENT GOSUB.
  11897.  
  11898.    The SetUEvent procedure is a part of BASIC, and is automatically included
  11899.    in compiled applications or when running QuickBASIC with the /L
  11900.    command-line option. Your interrupt service routine must call SetUEvent;
  11901.    it is the only way to alert your program that the event has occurred. You
  11902.    can call SetUEvent from any language, not just from assembly language.
  11903.  
  11904.    SetUEvent is not a function; it cannot return a value to BASIC. If you
  11905.    wish to return a value, you must write a function for your BASIC program
  11906.    to call. (It would usually be called by your event-handling routine.) This
  11907.    function must be described in a DECLARE statement so your BASIC program
  11908.    can find and use it.
  11909.  
  11910.    Although ON UEVENT GOSUB ties an event-handling routine to a user-defined
  11911.    event, it does not enable the event trap. The UEVENT statement is used to
  11912.    enable, disable, and suspend user-defined event trapping.
  11913.  
  11914.  ■ See Also
  11915.  
  11916.    UEVENT
  11917.  
  11918.  ■ Example
  11919.  
  11920.    The following example illustrates the use of ON UEVENT GOSUB:
  11921.  
  11922.    DECLARE SUB test (a)
  11923.    ON UEVENT GOSUB Event1
  11924.    UEVENT ON
  11925.    INPUT "Enter a number";a
  11926.    CALL test(a)
  11927.    END
  11928.    Event1:
  11929.    PRINT "Got to the event handler"
  11930.    RETURN
  11931.    SUB test(a)
  11932.    IF a=5 THEN CALL SetUEvent
  11933.    END SUB
  11934.  
  11935.  
  11936.  ────────────────────────────────────────────────────────────────────────────
  11937.  OPEN Statement
  11938.  ────────────────────────────────────────────────────────────────────────────
  11939.  
  11940.  ■ Action
  11941.  
  11942.    Enables I/O to a file or device
  11943.  
  11944.  ■ Syntax 1
  11945.  
  11946.    OPEN file «FOR mode1» «ACCESS access» «lock» AS
  11947.    «#» filenum «LEN=reclen»
  11948.  
  11949.  ■ Syntax 2
  11950.  
  11951.    OPEN  mode2,«#»filenum, file «,reclen»
  11952.  
  11953.  ■ Remarks
  11954.  
  11955.    The file is a string expression that specifies an optional device,
  11956.    followed by a file name or path name conforming to the DOS file-naming
  11957.    conventions.
  11958.  
  11959.    You must open a file before any I/O operation can be performed on it. OPEN
  11960.    allocates a buffer for I/O to the file or device and determines the mode
  11961.    of access used with the buffer.
  11962.  
  11963.    SYNTAX 1
  11964.  
  11965.    In the first syntax, mode1 is one of the following:
  11966.  
  11967. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  11968.    Mode                     Description
  11969.    ──────────────────────────────────────────────────────────────────────────
  11970.    OUTPUT                   Specifies sequential output mode.
  11971.  
  11972.    Mode                     Description
  11973.    ──────────────────────────────────────────────────────────────────────────
  11974. 
  11975.    INPUT                    Specifies sequential input mode.
  11976.  
  11977.    APPEND                   Specifies sequential output mode and sets the
  11978.                             file pointer to the end of file and the record
  11979.                             number to the last record of the file. A PRINT #
  11980.                             or WRITE # statement then extends (appends to)
  11981.                             the file.
  11982.  
  11983.    RANDOM                   Specifies random-access file mode, the default
  11984.                             mode. In RANDOM mode, if no ACCESS clause is
  11985.                             present, three attempts are made to open the file
  11986.                             when the OPEN statement is executed. Access is
  11987.                             attempted in the following order:
  11988.  
  11989.                             1. Read/write
  11990.  
  11991.                             2. Write-only
  11992.  
  11993.    Mode                     Description
  11994.    ──────────────────────────────────────────────────────────────────────────
  11995. 
  11996.                             3. Read-only
  11997.  
  11998.    BINARY                   Specifies binary file mode. In binary mode, you
  11999.                             may read or write information to any byte
  12000.                             position in the file using GET and PUT.
  12001.                             In binary mode, if no ACCESS clause is present,
  12002.                             three attempts are made to open the file. The
  12003.                             attempts follow the same order as those for
  12004.                             RANDOM files.
  12005.    ──────────────────────────────────────────────────────────────────────────
  12006.  
  12007.  
  12008.    If mode1 is omitted, the default random-access mode is assumed.
  12009.  
  12010.    The access expression specifies the operation performed on the opened
  12011.    file. If the file is already opened by another process and the specified
  12012.    type of access is not allowed, the OPEN fails and an error message is
  12013.    generated that reads Permission denied. The ACCESS clause works in an OPEN
  12014.    statement only if you are using a version of DOS that supports networking
  12015.    (DOS Versions 3.0 or later). In addition, you must run the SHARE.EXE
  12016.    program (or the network startup program must run it) to perform any
  12017.    locking operation. If ACCESS is used with OPEN, earlier versions of DOS
  12018.    return an error message that reads Advanced feature unavailable.
  12019.  
  12020.    The access argument can be one of the following:
  12021.  
  12022.    Access Type              Description
  12023.    ──────────────────────────────────────────────────────────────────────────
  12024.    READ                     Opens the file for reading only.
  12025.  
  12026.    WRITE                    Opens the file for writing only.
  12027.  
  12028.    READ WRITE               Opens the file for both reading and writing. This
  12029.                             mode is valid only for RANDOM and BINARY files
  12030.                             and files opened for APPEND.
  12031.    ──────────────────────────────────────────────────────────────────────────
  12032.  
  12033.    The lock clause works in a multiprocessing environment to restrict access
  12034.    by other processes to an open file. The lock types are as follows:
  12035.  
  12036. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  12037.    Lock Type                Description
  12038.    ──────────────────────────────────────────────────────────────────────────
  12039.    Default                  If locktype is not specified, the file may be
  12040.                             opened for reading and writing any number of
  12041.                             times by this process, but other processes are
  12042.                             denied access to the file while it is opened.
  12043.  
  12044.    SHARED                   Any process on any machine may read from or write
  12045.                             to this file. Do not confuse the SHARED lock type
  12046.                             with the SHARED statement or the SHARED attribute
  12047.                             appearing in other statements.
  12048.  
  12049.    LOCK READ                No other process is granted read access to this
  12050.                             file. This access is granted only if no other
  12051.                             process has a previous READ access to the file.
  12052.  
  12053.    LOCK WRITE               No other process is granted write access to this
  12054.                             file. This lock is granted only if no other
  12055.                             process has a previous WRITE access to the file.
  12056.    Lock Type                Description
  12057.    ──────────────────────────────────────────────────────────────────────────
  12058.                            process has a previous WRITE access to the file.
  12059.  
  12060.    LOCK READ WRITE          No other process is granted either read or write
  12061.                             access to this file. This access is granted only
  12062.                             if READ or WRITE access has not already been
  12063.                             granted to another process, or if a LOCK READ or
  12064.                             LOCK WRITE is not already in place.
  12065.    ──────────────────────────────────────────────────────────────────────────
  12066.  
  12067.  
  12068.    When the OPEN is restricted by a previous process, it generates error 70,
  12069.    Permission denied, under DOS.
  12070.  
  12071.    The filenum (file number) argument is an integer expression whose value is
  12072.    between 1 and 255. When an OPEN is executed, the file number is associated
  12073.    with the file as long as it is open. Other I/O statements may use the
  12074.    number to refer to the file.
  12075.  
  12076.    The reclen (record length) argument is an integer expression that, if
  12077.    included, sets the record length (number of characters in one record) for
  12078.    random-access files. For sequential files, the default length for records
  12079.    is 512 bytes; for random-access files, the default is 128 bytes. The value
  12080.    of reclen cannot exceed 32,767 bytes. If the file mode is binary, then the
  12081.    LEN clause is ignored.
  12082.  
  12083.    For sequential files, reclen need not correspond to an individual record
  12084.    size, since a sequential file may have records of different sizes. When
  12085.    used to open a sequential file, reclen specifies the number of characters
  12086.    to be loaded into the buffer before the buffer is written to, or read
  12087.    from, the disk. A larger buffer means more room taken from BASIC, but
  12088.    faster file I/O. A smaller buffer means more room in memory for BASIC, but
  12089.    slower I/O. The default buffer size is 512 bytes.
  12090.  
  12091.    SYNTAX 2
  12092.  
  12093.    In the second form of the OPEN syntax, mode2 is a string expression the
  12094.    first character of which must be one of the following:
  12095.  
  12096.    Mode                     Description
  12097.    ──────────────────────────────────────────────────────────────────────────
  12098.    O                        Specifies sequential output mode.
  12099.  
  12100.    I                        Specifies sequential input mode.
  12101.  
  12102.    R                        Specifies random-access file input/output mode.
  12103.  
  12104.    B                        Specifies binary file mode.
  12105.  
  12106.    A                        Specifies sequential output mode and sets the
  12107.                             file pointer to the end of the file and the
  12108.                             record number to the last record of the file. A
  12109.                             PRINT # or WRITE # statement extends (appends to)
  12110.                             the file.
  12111.    ──────────────────────────────────────────────────────────────────────────
  12112.  
  12113.  ────────────────────────────────────────────────────────────────────────────
  12114.  NOTE
  12115.    The second form of the OPEN syntax does not support any of the access and
  12116.    file-sharing options found in the first syntax and is supported for
  12117.    compatibility with programs written in earlier versions of BASIC.
  12118.  ────────────────────────────────────────────────────────────────────────────
  12119.  
  12120.    The following devices are supported by BASIC and can be named and opened
  12121.    with the file argument: KYBD:, SCRN:, COMn:, LPTn:, CONS:.
  12122.  
  12123.    The BASIC file I/O system allows you to take advantage of user-installed
  12124.    devices. (See your DOS manual for information on character devices.)
  12125.  
  12126.    Character devices are opened and used in the same manner as disk files.
  12127.    However, characters are not buffered by BASIC as they are for disk files.
  12128.    The record length for the device files is set to one.
  12129.  
  12130.    BASIC only sends a carriage return at the end of a line. If the device
  12131.    requires a line feed, the driver must provide it. When writing device
  12132.    drivers, keep in mind that other BASIC users will want to read and write
  12133.    control information. The writing and reading of device-control data is
  12134.    handled by the IOCTL statement and IOCTL$ function.
  12135.  
  12136.    None of the BASIC devices directly supports binary mode. However, the line
  12137.    printer devices (LPT1:, LPT2:) can be opened in binary mode by adding the
  12138.    BIN keyword:
  12139.  
  12140.    OPEN "LPT1:BIN" FOR OUTPUT AS #1
  12141.  
  12142.    Opening a printer in BIN mode eliminates printing a carriage return at the
  12143.    end of a line.
  12144.  
  12145.  ────────────────────────────────────────────────────────────────────────────
  12146.  NOTE
  12147.    In INPUT, RANDOM, and BINARY modes you can open a file under a different
  12148.    file number without first closing the file. In OUTPUT or APPEND mode you
  12149.    must close a file before opening it with a different file number.
  12150.  ────────────────────────────────────────────────────────────────────────────
  12151.  
  12152.  ■ See Also
  12153.  
  12154.    FREEFILE
  12155.  
  12156.  ■ Examples
  12157.  
  12158.    The following statement opens MAILING.DAT as file number 1 and allows data
  12159.    to be added without destroying what is already in MAILING.DAT:
  12160.  
  12161.    OPEN "MAILING.DAT" FOR APPEND AS #1
  12162.  
  12163.    If you wrote and installed a device driver named ROBOT, then the OPEN
  12164.    statement might appear as
  12165.  
  12166.    OPEN "\DEV\ROBOT" FOR OUTPUT AS #1
  12167.  
  12168.    To open the printer for output, you could use either of the following two
  12169.    lines. (The first line uses the BASIC device LPT1: while the second line
  12170.    uses the DOS device LPT1.)
  12171.  
  12172.    OPEN "LPT1:" FOR OUTPUT AS #1
  12173.  
  12174.    OPEN "LPT1" FOR OUTPUT AS #1
  12175.  
  12176.    The following statement opens the file RECORDS in random-access mode, for
  12177.    reading only. The statement locks the file for writing, but allows reading
  12178.    by other processes while the OPEN is in effect.
  12179.  
  12180.    OPEN "RECORDS" FOR RANDOM ACCESS READ LOCK WRITE AS #1
  12181.  
  12182.    The following example opens the file named INVEN for input as file number
  12183.    2:
  12184.  
  12185.    OPEN "I",2,"INVEN"
  12186.  
  12187.  
  12188.  ────────────────────────────────────────────────────────────────────────────
  12189.  OPEN COM Statement
  12190.  ────────────────────────────────────────────────────────────────────────────
  12191.  
  12192.  ■ Action
  12193.  
  12194.    Opens and initializes a communications channel for I/O
  12195.  
  12196.  ■ Syntax
  12197.  
  12198.    OPEN "COMn: optlist1 optlist2" «FOR mode» AS «#»filenum «LEN=reclen»
  12199.  
  12200.  ■ Remarks
  12201.  
  12202.    COMn: is the name of the device to be opened. The n argument is the number
  12203.    of a legal communications device, such as COM1: or COM2:. The first list
  12204.    of options, optlist1, has the following form:
  12205.  
  12206.    «speed»«,«parity» «,«data»«,«stop»»»»
  12207.  
  12208.    The following list describes the possible options:
  12209.  
  12210.    Option                   Description
  12211.    ──────────────────────────────────────────────────────────────────────────
  12212.    speed                    The "baud" rate (baud means "bits per second") of
  12213.                             the device to be opened. Valid speeds are 75,
  12214.                             110, 150, 300, 600, 1200, 1800, 2400, 4800, and
  12215.                             9600. The default is 300 bps.
  12216.  
  12217.    parity                   The parity of the device to be opened. Valid
  12218.                             entries for parity are: N (none), E (even), O
  12219.                             (odd), S (space), or M (mark).
  12220.  
  12221.    data                     The number of data bits per byte. Valid entries
  12222.                             are 5, 6, 7, or 8.
  12223.  
  12224.    stop                     The number of stop bits. Valid entries are 1,
  12225.                             1.5, or 2.
  12226.    ──────────────────────────────────────────────────────────────────────────
  12227.  
  12228.    Options from this list must be entered in the order shown; moreover, if
  12229.    any options from optlist2 are chosen, comma placeholders must still be
  12230.    used even if none of the options from optlist1 are chosen. For example:
  12231.  
  12232.    OPEN "COM1: ,,,,CD1500" FOR INPUT AS #1
  12233.  
  12234.    If you set the data bits per byte to eight, you must specify no parity
  12235.    (N). Because QuickBASIC uses complete bytes (eight bits) for numbers, you
  12236.    must specify eight data bits when transmitting or receiving numeric data.
  12237.  
  12238.    The choices for optlist2 are described in the following list. The argument
  12239.    m is given in milliseconds; the default value for m is 1000.
  12240.  
  12241. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  12242.    Option                   Description
  12243.    ──────────────────────────────────────────────────────────────────────────
  12244.    ASC                      Opens the device in ASCII mode. In ASCII mode,
  12245.    Option                   Description
  12246.    ──────────────────────────────────────────────────────────────────────────
  12247.    ASC                      Opens the device in ASCII mode. In ASCII mode,
  12248.                             tabs are expanded to spaces, carriage returns are
  12249.                             forced at end-of-line, and CTRL+Z is treated as
  12250.                             end-of-file. When the channel is closed, CTRL+Z
  12251.                             is sent over the RS-232 line.
  12252.  
  12253.    BIN                      Opens the device in binary mode. This option
  12254.                             supersedes the LF option. BIN is selected by
  12255.                             default unless ASC is specified.
  12256.                             In the BIN mode, tabs are not expanded to spaces,
  12257.                             a carriage return is not forced at the
  12258.                             end-of-line, and CTRL+Z is not treated as
  12259.                             end-of-file. When the channel is closed, CTRL+Z
  12260.                             will not be sent over the RS-232 line.
  12261.  
  12262.    CD«m»                    Controls the timeout on the Data Carrier Detect
  12263.                             line (DCD). If DCD is low for more than m
  12264.                             milliseconds, a device timeout occurs.
  12265.  
  12266.    Option                   Description
  12267.    ──────────────────────────────────────────────────────────────────────────
  12268. 
  12269.    CS«m»                    Controls the timeout on the Clear To Send line
  12270.                             (CTS). If CTS is low (there is no signal) for
  12271.                             more than m milliseconds, a device timeout
  12272.                             occurs.
  12273.  
  12274.    DS«m»                    Controls the timeout on the Data Set Ready line
  12275.                             (DSR). If DSR is low for more than m
  12276.                             milliseconds, a device timeout occurs.
  12277.  
  12278.    LF                       Allows communication files to be printed on a
  12279.                             serial line printer. When LF is specified, a
  12280.                             line-feed character (0AH) is automatically sent
  12281.                             after each carriage-return character (0DH). This
  12282.                             includes the carriage return sent as a result of
  12283.                             the width setting. Note that INPUT and LINE
  12284.                             INPUT, when used to read from a COM file that was
  12285.                             opened with the LF option, stop when they see a
  12286.                             carriage return, ignoring the line feed.
  12287.    Option                   Description
  12288.    ──────────────────────────────────────────────────────────────────────────
  12289.                            carriage return, ignoring the line feed.
  12290.  
  12291.    OP«m»                    Controls how long the statement waits for the
  12292.                             open to be successful. The parameter m is a value
  12293.                             in the range 0 to 65,535 representing the number
  12294.                             of milliseconds to wait for the communications
  12295.                             lines to become active. If OP is specified
  12296.                             without a value, the statement waits
  12297.                             indefinitely. If OP is omitted, OPEN COM waits
  12298.                             for ten times the maximum value of the CD or DS
  12299.                             timeout values.
  12300.  
  12301.    RB«n»                    Sets the size of the receive buffer to n bytes.
  12302.                             If n is omitted, or the option is omitted, the
  12303.                             current value is used. The current value can be
  12304.                             set by the /C option on the QuickBASIC or BC
  12305.                             command line. The default is 512 bytes. The
  12306.                             maximum size is 32,767 bytes.
  12307.  
  12308.    Option                   Description
  12309.    ──────────────────────────────────────────────────────────────────────────
  12310. 
  12311.    RS                       Suppresses detection of Request To Send (RTS).
  12312.  
  12313.    TB«n»                    Sets the size of the transmit buffer to n bytes.
  12314.                             If n is omitted, or the option is omitted, the
  12315.                             current value is used. The default size is 512
  12316.                             bytes.
  12317.    ──────────────────────────────────────────────────────────────────────────
  12318.  
  12319.  
  12320.    The options from the list above can be entered in any order, but they must
  12321.    be separated from one another by commas. For CS«m», DS«m», and CD«m», if
  12322.    there is no signal within m milliseconds, a timeout occurs. The value for
  12323.    m may range from 0 to 65,535, with 1000 as the default value. (The CD
  12324.    default is 0.) If m is equal to 0 for any of these options the option is
  12325.    ignored. The CTS line is checked whenever there is data in the transmit
  12326.    buffer if the CS option is specified. The DSR and DCD lines are
  12327.    continuously checked for timeouts if the corresponding options (DS, CD)
  12328.    are specified.
  12329.  
  12330.    The mode argument is one of the following string expressions:
  12331.  
  12332.    Mode                     Description
  12333.    ──────────────────────────────────────────────────────────────────────────
  12334.    OUTPUT                   Specifies sequential output mode
  12335.    INPUT                    Specifies sequential input mode
  12336.    RANDOM                   Specifies random-access mode
  12337.    ──────────────────────────────────────────────────────────────────────────
  12338.  
  12339.    If the mode expression is omitted, it is assumed to be random-access
  12340.    input/output. The filenum is the number used to open the file. The OPEN
  12341.    COM statement must be executed before a device can be used for
  12342.    communication using an RS-232 interface.
  12343.  
  12344.    If the device is opened in RANDOM mode, the LEN option specifies the
  12345.    length of an associated random-access buffer. The default value for length
  12346.    is 128. You can use any of the random-access I/O statements, such as GET
  12347.    and PUT, to treat the device as if it were a random-access file. The OPEN
  12348.    COM statement performs the following steps in opening a communications
  12349.    device:
  12350.  
  12351.    1. The communications buffers are allocated and interrupts are enabled.
  12352.  
  12353.    2. The Data Terminal Ready line (DTR) is set high.
  12354.  
  12355.    3. If either of the OP or DS options is nonzero, the statement waits up to
  12356.       the indicated time for the Data Set Ready line (DSR) to be high. If a
  12357.       timeout occurs, the process goes to step 6.
  12358.  
  12359.    4. The Request To Send line (RTS) is set high if the RS option is not
  12360.       specified.
  12361.  
  12362.    5. If either of the OP or CD options is nonzero, OPEN COM waits up to the
  12363.       indicated time for the Data Carrier Detect line (DCD) to be high. If a
  12364.       timeout occurs, the process goes to step 6. Otherwise, OPEN COM has
  12365.       succeeded.
  12366.  
  12367.    6. The open has failed due to a timeout. The process deallocates the
  12368.       buffers, disables interrupts, and clears all of the control lines.
  12369.  
  12370.  ────────────────────────────────────────────────────────────────────────────
  12371.  NOTE
  12372.    Use a relatively large value for the OP option compared to the CS, DS, or
  12373.    CD options. If two programs are attempting to establish a communications
  12374.    link, they both need to attempt an OPEN during at least half of the time
  12375.    they are executing.
  12376.  ────────────────────────────────────────────────────────────────────────────
  12377.  
  12378.    Any syntax errors in the OPEN COM statement produce an error message that
  12379.    reads Bad file name.
  12380.  
  12381.  ■ Example
  12382.  
  12383.    The following program fragment opens communications channel 1 in
  12384.    random-access mode at a speed of 9600 baud, no parity bit, eight data
  12385.    bits, and one stop bit. Input/output will be in the binary mode. Other
  12386.    lines in the program can now access channel 1 as file number 2.
  12387.  
  12388.    OPEN "COM1:9600,N,8,1,BIN" AS 2
  12389.  
  12390.  
  12391.  ────────────────────────────────────────────────────────────────────────────
  12392.  OPTION BASE Statement
  12393.  ────────────────────────────────────────────────────────────────────────────
  12394.  
  12395.  ■ Action
  12396.  
  12397.    Declares the default lower bound for array subscripts
  12398.  
  12399.  ■ Syntax
  12400.  
  12401.    OPTION BASE n
  12402.  
  12403.  ■ Remarks
  12404.  
  12405.    The OPTION BASE statement is never required. It is used to change the
  12406.    default lower bound for array subscripts.
  12407.  
  12408.    The value of n must be either 0 or 1. The default base is 0. If the
  12409.    following statement
  12410.  
  12411.    OPTION BASE 1
  12412.  
  12413.    is executed, the lowest value an array subscript can have is 1.
  12414.  
  12415.  ────────────────────────────────────────────────────────────────────────────
  12416.  NOTE
  12417.    The TO clause in the DIM statement provides an easier, more flexible way
  12418.    to control the range of an array's subscripts. If the lower bound of an
  12419.    array subscript is not explicitly set, then OPTION BASE can be used to
  12420.    change the default lower bound to 1.
  12421.  ────────────────────────────────────────────────────────────────────────────
  12422.  
  12423.    The OPTION BASE statement can be used only once in a module (source file)
  12424.    and can only appear in the module-level code. An OPTION BASE statement
  12425.    must be used before any arrays are dimensioned.
  12426.  
  12427.    Chained programs may have an OPTION BASE statement if no arrays are passed
  12428.    in COMMON between them or if the specified base is identical in the
  12429.    chained programs. The chained-to program inherits the OPTION BASE value of
  12430.    the chaining program if OPTION BASE is omitted in the latter.
  12431.  
  12432.  ■ See Also
  12433.  
  12434.    DIM, LBOUND, REDIM
  12435.  
  12436.  ■ Example
  12437.  
  12438.    The following statement overrides the default value of zero, so the lowest
  12439.    value a subscript in an array can have in this program is 1:
  12440.  
  12441.  
  12442.    OPTION BASE 1
  12443.    DIM A(20)
  12444.    PRINT LBOUND(A), UBOUND(A)
  12445.  
  12446.  ■ Output
  12447.  
  12448.    1               20
  12449.  
  12450.  
  12451.  ────────────────────────────────────────────────────────────────────────────
  12452.  OUT Statement
  12453.  ────────────────────────────────────────────────────────────────────────────
  12454.  
  12455.  ■ Action
  12456.  
  12457.    Sends a byte to a machine I/O port
  12458.  
  12459.  ■ Syntax
  12460.  
  12461.    OUT port, data
  12462.  
  12463.  ■ Remarks
  12464.  
  12465.    The following list describes the arguments of the OUT statement:
  12466.  
  12467.    Argument                 Description
  12468.    ──────────────────────────────────────────────────────────────────────────
  12469.    port                     The number of the port. The number must be an
  12470.                             integer expression in the range 0-65,535.
  12471.  
  12472.    data                     The data to be sent to the port. It must be an
  12473.                             integer expression in the range 0-255.
  12474.    ──────────────────────────────────────────────────────────────────────────
  12475.  
  12476.    The OUT and INP statements give a BASIC program direct control over the
  12477.    hardware in a system through the I/O ports. These statements must be used
  12478.    carefully because they directly manipulate the hardware.
  12479.  
  12480.  ■ See Also
  12481.  
  12482.    INP, WAIT
  12483.  
  12484.  ■ Example
  12485.  
  12486.    The following example uses OUT and INP to control the timer and speaker to
  12487.    produce a note. (This example is specific to the IBM PC and close
  12488.    compatibles and produces unpredictable results on other machines.)
  12489.  
  12490.    ' Play a scale using the speaker and timer.
  12491.    CONST WHOLE=5000!, QRTR=WHOLE/4.
  12492.    CONST C=523.0, D=587.33, E=659.26, F=698.46, G=783.99, A=880.00
  12493.    CONST B=987.77, C1=1046.50
  12494.    CALL Sounds(C,QRTR) : CALL Sounds(D,QRTR)
  12495.    CALL Sounds(E,QRTR) : CALL Sounds(F,QRTR)
  12496.    CALL Sounds(G,QRTR) : CALL Sounds(A,QRTR)
  12497.    CALL Sounds(B,QRTR) : CALL Sounds(C1,WHOLE)
  12498.  
  12499.    ' Use ports 66, 67, and 97 to control the timer and speaker
  12500.    ' to produce a sound.
  12501.    SUB Sounds (Freq!,Length!) STATIC
  12502.  
  12503.    ' Divide the clock frequency by the sound frequency to
  12504.    ' get the number of "clicks" the clock must produce.
  12505.       Clicks%=CINT(1193280!/Freq!)
  12506.       LoByte%=Clicks% AND &H00FF
  12507.       HiByte%=Clicks%\256
  12508.    ' Tell timer that data is coming.
  12509.       OUT 67,182
  12510.    ' Send the low byte followed by the high byte of the count.
  12511.       OUT 66,LoByte%
  12512.       OUT 66,HiByte%
  12513.    ' Turn the speaker on by setting bits 0 and 1 of the PPI chip.
  12514.    ' Get the current value, and turn the bits on.
  12515.       SpkrOn%=INP(97) OR &H03
  12516.       OUT 97,SpkrOn%
  12517.    ' Leave the speaker on for a while.
  12518.       FOR I!=1 TO Length! : NEXT I!
  12519.    ' Turn the speaker off.
  12520.       SpkrOff%=INP(97) AND &HFC
  12521.       OUT 97,SpkrOff%
  12522.  
  12523.    END SUB
  12524.  
  12525.  
  12526.  ────────────────────────────────────────────────────────────────────────────
  12527.  PAINT Statement
  12528.  ────────────────────────────────────────────────────────────────────────────
  12529.  
  12530.  ■ Action
  12531.  
  12532.    Fills a graphics area with the color or pattern specified
  12533.  
  12534.  ■ Syntax
  12535.  
  12536.    PAINT «STEP» (x,y)«,«paint» «,«bordercolor» «,background»»»
  12537.  
  12538.  ■ Remarks
  12539.  
  12540.    The following list describes the parts of the PAINT statement:
  12541.  
  12542. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  12543.    Part                     Description
  12544.    ──────────────────────────────────────────────────────────────────────────
  12545.    STEP                     Defines coordinates to be relative to the most
  12546.                             recently plotted point. For example, if the last
  12547.                             point plotted were (10,10), then the coordinates
  12548.                             referred to by STEP (4,5) would be (4+10, 5+10)
  12549.                             or (14,15).
  12550.  
  12551.    (x,y)                    The coordinates where painting begins. The point
  12552.                             must be inside or outside a figure, not on the
  12553.                             border itself. If this point is inside, the
  12554.                             figure's interior is painted; if the point is on
  12555.                             the outside, the background is painted.
  12556.  
  12557.    paint                    A numeric or string expression. If paint is a
  12558.                             numeric expression, then the number must be a
  12559.                             valid color attribute. The corresponding color is
  12560.    Part                     Description
  12561.    ──────────────────────────────────────────────────────────────────────────
  12562.                            valid color attribute. The corresponding color is
  12563.                             used to paint the area. If you do not specify
  12564.                             paint, the foreground color attribute is used.
  12565.                             (See the COLOR, PALETTE, and SCREEN statements
  12566.                             for discussions of valid colors, numbers, and
  12567.                             attributes.)
  12568.  
  12569.                             If the paint argument is a string expression,
  12570.                             then PAINT does "tiling," a process that paints a
  12571.                             pattern rather than a solid color. Tiling is
  12572.                             similar to "line styling," which creates dashed
  12573.                             lines rather than solid lines.
  12574.  
  12575.    bordercolor              A numeric expression identifying the color
  12576.                             attribute to use to paint the border of the
  12577.                             figure. When the border color is encountered,
  12578.                             painting of the current line stops. If the border
  12579.                             color is not specified, the paint argument is
  12580.                             used.
  12581.    Part                     Description
  12582.    ──────────────────────────────────────────────────────────────────────────
  12583.                            used.
  12584.  
  12585.    background               A string value giving the "background tile slice"
  12586.                             to skip when checking for termination of the
  12587.                             boundary. Painting is terminated when adjacent
  12588.                             points display the paint color. Specifying a
  12589.                             background tile slice allows you to paint over an
  12590.                             already painted area. When you omit background
  12591.                             the default is CHR$ (0).
  12592.    ──────────────────────────────────────────────────────────────────────────
  12593.  
  12594.  
  12595.    Painting is complete when a line is painted without changing the color of
  12596.    any pixel, in other words, when the entire line is equal to the paint
  12597.    color. The PAINT command permits coordinates outside the screen or
  12598.    viewport.
  12599.  
  12600.      Tiling
  12601.  
  12602.    "Tiling" is the design of a PAINT pattern that is eight bits wide and up
  12603.    to 64 bytes long. In the tile string, each byte masks eight bits along the
  12604.    x-axis when putting down points. The syntax for constructing this tile
  12605.    mask is
  12606.  
  12607.    PAINT (x,y), CHR$(arg1)+CHR$(arg2)+...+CHR$(argn)
  12608.  
  12609.    The arguments to CHR$ are numbers between 0 and 255, represented in binary
  12610.    form across the x axis of the tile. There can be up to 64 of these CHR$
  12611.    elements; each generates an image not of the assigned character, but of
  12612.    the bit arrangement of the code for that character. For example, the
  12613.    decimal number 85 is binary 01010101; the graphic image line on a
  12614.    black-and-white screen generated by CHR$(85) is an eight-pixel line, with
  12615.    even-numbered points white and odd-numbered points black. That is, each
  12616.    bit equal to 1 turns the associated pixel on and each bit equal to 0 turns
  12617.    the associated bit off in a black-and-white system. The ASCII character
  12618.    CHR$(85), which is U, is not displayed in this case.
  12619.  
  12620.    When supplied, background defines the "background tile slice" to skip when
  12621.    checking for boundary termination. You cannot specify more than two
  12622.    consecutive bytes that match the tile string in the tile background slice.
  12623.    Specifying more than two consecutive bytes produces an error message that
  12624.    reads Illegal function call.
  12625.  
  12626.    Tiling can also be done to produce various patterns of different colors.
  12627.    See Chapter 5, "Graphics," in Programming in BASIC for a complete
  12628.    description of how to do tiling.
  12629.  
  12630.  ■ See Also
  12631.  
  12632.    CHR$, CIRCLE, DRAW, LINE, SCREEN
  12633.  
  12634.  ■ Example
  12635.  
  12636.    The following program draws a magenta fish with a cyan tail:
  12637.  
  12638.    CONST PI=3.1415926536
  12639.    CLS
  12640.    SCREEN 1
  12641.  
  12642.    CIRCLE (190,100),100,1,,,.3   'Outline fish body in cyan.
  12643.    CIRCLE (265,92),5,1,,,.7      'Outline fish eye in cyan.
  12644.    PAINT (190,100),2,1           'Fill in fish body with magenta.
  12645.  
  12646.    LINE (40,120)-STEP (0,-40),2  'Outline
  12647.    LINE -STEP (60,+20),2         '   tail in
  12648.    LINE -STEP (-60,+20),2        '      magenta.
  12649.    PAINT (50,100),1,2            'Paint tail cyan.
  12650.  
  12651.    CIRCLE (250,100),30,0,PI*3/4,PI* 5/4,1.5  'Draw
  12652.    gills in black.
  12653.    FOR Y = 90 TO 110 STEP 4
  12654.       LINE (40,Y)-(52,Y),0       'Draw comb in tail.
  12655.    NEXT
  12656.  
  12657.  
  12658.  ────────────────────────────────────────────────────────────────────────────
  12659.  PALETTE, PALETTE USING Statements
  12660.  ────────────────────────────────────────────────────────────────────────────
  12661.  
  12662.  ■ Action
  12663.  
  12664.    Changes one or more of the colors in the palette
  12665.  
  12666.  ■ Syntax
  12667.  
  12668.    PALETTE «attribute,color»
  12669.    PALETTE USING array-name «(array-index)»
  12670.  
  12671.  ■ Remarks
  12672.  
  12673.    The PALETTE statement takes the following arguments:
  12674.  
  12675. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  12676.    Argument                 Description
  12677.    ──────────────────────────────────────────────────────────────────────────
  12678.    attribute                The palette attribute to be changed.
  12679.  
  12680.    color                    The display color number to be assigned to the
  12681.                             attribute. The color must be a long integer
  12682.                             expression for the IBM Video Graphics Array
  12683.                             adapter (VGA) and IBM Multicolor Graphics Array
  12684.                             adapter (MCGA) in screen modes 11 to 13. Integer
  12685.                             or long-integer expressions may be used with the
  12686.    Argument                 Description
  12687.    ──────────────────────────────────────────────────────────────────────────
  12688.                            or long-integer expressions may be used with the
  12689.                             IBM Enhanced Graphics Adapter (EGA).
  12690.  
  12691.    array-name               An array containing the color numbers to be
  12692.                             assigned to the attributes available in the
  12693.                             current screen mode. The VGA and MCGA adapters
  12694.                             require a long integer array in screen modes 11
  12695.                             to 13. With the EGA this can be either an integer
  12696.                             or long-integer array.
  12697.  
  12698.    array-index              The index of the first array element to use in
  12699.                             setting the palette.
  12700.    ──────────────────────────────────────────────────────────────────────────
  12701.  
  12702.  
  12703.    The PALETTE statement works only on systems equipped with the EGA, VGA, or
  12704.    MCGA adapters.
  12705.  
  12706.    The statement provides a way of mapping display colors (the actual binary
  12707.    values used by the adapter) to color attributes (a smaller set of values).
  12708.    All BASIC graphics statements such as CIRCLE, COLOR, DRAW, or LINE use
  12709.    color attributes rather than display-color values.
  12710.  
  12711.    When a program enters a screen mode, the attributes are set to a series of
  12712.    default color values. (See the SCREEN statement for a list of the default
  12713.    colors.) In the EGA, VGA, and MCGA adapters these default values have been
  12714.    selected so the display shows the same colors, even though the EGA uses
  12715.    different color values.
  12716.  
  12717.    With the palette statement you can assign different colors to the
  12718.    attributes, giving you greater control over the colors on the display. A
  12719.    PALETTE statement with no arguments sets the palette back to the default
  12720.    color values.
  12721.  
  12722.    When you execute a PALETTE statement with arguments, the adapter
  12723.    subsequently uses the display color (indicated by color) whenever the
  12724.    value attribute appears in a statement like DRAW or LINE that specifies a
  12725.    color. Changing the display color assigned to an attribute changes the
  12726.    color on the screen immediately.
  12727.  
  12728.    For example, assume that the current palette contains colors 0, 1, 2, and
  12729.    3 in the four attributes numbered 0, 1, 2, and 3. The DRAW statement
  12730.  
  12731.    DRAW "C3L100"
  12732.  
  12733.    selects attribute 3, and draws a line of 100 pixels using the display
  12734.    color associated with attribute 3, in this case also 3. If the statement
  12735.  
  12736.    PALETTE 3,2
  12737.  
  12738.    is executed, then the color associated with attribute 3 is changed to
  12739.    color 2. All text or graphics currently on the screen displayed using
  12740.    attribute 3 are instantaneously changed to color 2. Text or graphics
  12741.    subsequently displayed with attribute 3 are also displayed in color 2. The
  12742.    new palette of colors contains 0, 1, 2, and 2.
  12743.  
  12744.    With the USING option, all entries in the palette can be modified in one
  12745.    PALETTE statement. The array-name argument is the name of an integer or
  12746.    long-integer array and the array-index specifies the index of the first
  12747.    array element in the array-name to use in setting the palette. Each
  12748.    attribute in the palette is assigned a corresponding color from this
  12749.    array. The array must be dimensioned large enough to set all the palette
  12750.    entries after array-index. For example, if you are assigning colors to all
  12751.    16 attributes, and the index of the first array element that is given in
  12752.    your PALETTE USING statement is 5, then the array must be dimensioned to
  12753.    hold at least 20 elements (since the number of elements from 5-20,
  12754.    inclusive, is 16):
  12755.  
  12756.    DIM PAL%(20)
  12757.    .
  12758.    .
  12759.    .
  12760.    PALETTE USING PAL%(5)
  12761.  
  12762.    A color argument of -1 in the array leaves the attribute unchanged. All
  12763.    other negative numbers are invalid values for color.
  12764.  
  12765.    You can use the COLOR statement to set the default foreground color and
  12766.    the background display color. The foreground color argument specifies the
  12767.    way text characters appear on the display screen. Under a common initial
  12768.    palette setting, points colored with the attribute 0 appear black on the
  12769.    display screen. Using the PALETTE statement, you could, for example,
  12770.    change the mapping of attribute 0 from black to white. Table R.5 lists
  12771.    attribute and color ranges for various adapter types and screen modes.
  12772.  
  12773.    Table R.5   Screen Color and Attribute Ranges
  12774.  
  12775. ╓┌─┌───────────┌────────────────────────┌───────────┌────────────┌───────────╖
  12776.    Screen      Monitor                              Attribute    Color
  12777.    Mode        Attached                 Adapter     Range        Range
  12778.    ──────────────────────────────────────────────────────────────────────────
  12779.    0           Monochrome               MDPA        0-15         N/A
  12780.                Monochrome               EGA         0-15         0-2
  12781.                Color                    CGA         0-15         N/A
  12782.                Color/Enhanced          EGA         0-15         0-63
  12783.                N/A                      VGA         0-15         0-63
  12784.                N/A                      MCGA        0-15         N/A
  12785.    1           Color                    CGA         0-3          N/A
  12786.                Color/Enhanced          EGA         0-3          0-15
  12787.                N/A                      VGA         0-3          0-15
  12788.                N/A                      MCGA        0-3          N/A
  12789.    2           Color                    CGA         0-1          N/A
  12790.                Color/Enhanced          EGA         0-1          0-15
  12791.    Screen      Monitor                              Attribute    Color
  12792.    Mode        Attached                 Adapter     Range        Range
  12793.    ──────────────────────────────────────────────────────────────────────────
  12794.               Color/Enhanced          EGA         0-1          0-15
  12795.                N/A                      VGA         0-1          0-15
  12796.                N/A                      MCGA        0-1          N/A
  12797.    7           Color/Enhanced          EGA         0-15         0-15
  12798.                N/A                      VGA         0-15         0-15
  12799.    8           Color/Enhanced          EGA         0-15         0-15
  12800.                N/A                      VGA         0-15         0-15
  12801.    9           Enhanced                EGA        0-3          0-63
  12802.                Enhanced                EGA        0-15         0-63
  12803.                N/A                      VGA         0-16         0-63
  12804.    10          Monochrome               EGA         0-3          0-8
  12805.                N/A                      VGA         0-3          0-8
  12806.    11          N/A                      VGA         0-1          0-262,143
  12807.                N/A                      MCGA        0-1          0-262,143
  12808.    12          N/A                      VGA         0-15         0-262,143
  12809.    13          N/A                      VGA         0-255        0-262,143
  12810.                N/A                      MCGA        0-255        0-262,143
  12811.    ──────────────────────────────────────────────────────────────────────────
  12812.    Screen      Monitor                              Attribute    Color
  12813.    Mode        Attached                 Adapter     Range        Range
  12814.    ──────────────────────────────────────────────────────────────────────────
  12815.   ──────────────────────────────────────────────────────────────────────────
  12816.  
  12817.  
  12818.    The VGA uses a different way of calculating color values from the EGA. To
  12819.    calculate a color value, select the intensities of red, green, and blue.
  12820.    The intensity of a color is a number from 0 (low intensity) to 63 (high
  12821.    intensity). Then use the following formula to calculate the actual color
  12822.    number:
  12823.  
  12824.    color number = 65536 * blue + 256 * green + red
  12825.  
  12826.    Because there are gaps in the range of color numbers, you should use the
  12827.    formula rather than just select a number.
  12828.  
  12829.    When used with the IBM Analog Monochrome Monitor, the VGA color values are
  12830.    converted to a gray-scale value by taking a weighted sum of the red, blue,
  12831.    and green intensities as follows:
  12832.  
  12833.    gray value = 11% blue + 59% green + 30% red
  12834.  
  12835.    For example if the blue, green, and red intensities are 45, 20, and 20,
  12836.    the gray value would be .11*45+.59*20+.30*20 or 22 (the fraction in the
  12837.    result is dropped).
  12838.  
  12839.    See the SCREEN statement for the list of colors available for various
  12840.    screen-mode, monitor, and graphics-adapter combinations.
  12841.  
  12842.  ────────────────────────────────────────────────────────────────────────────
  12843.  NOTE
  12844.    Because of their wide range of colors, the VGA and MCGA adapters require a
  12845.    long-integer array in the PALETTE USING statement in screen modes 11 to
  12846.    13.
  12847.  ────────────────────────────────────────────────────────────────────────────
  12848.  
  12849.  ■ See Also
  12850.  
  12851.    CIRCLE, COLOR, DRAW, LINE, SCREEN
  12852.  
  12853.  ■ Examples
  12854.  
  12855.    The following lines show the different forms of the PALETTE and PALETTE
  12856.    USING statements:
  12857.  
  12858.    PALETTE 0,2          'Changes all points colored with attribute 0 to
  12859.                         'color 2.
  12860.  
  12861.    PALETTE USING A%(0)  'Changes each palette entry. Since the
  12862.                         'array is initialized to zero when it
  12863.                         'is first declared, all attributes are
  12864.                         'now mapped to display color zero. The
  12865.                         'screen will now appear as one single
  12866.                         'color. However, it will still be
  12867.                         'possible to execute BASIC statements.
  12868.  
  12869.    PALETTE              'Sets each palette entry to its appropriate
  12870.                         'initial display color. Actual initial colors
  12871.                         'depend on your screen-hardware configuration.
  12872.  
  12873.  
  12874.  ────────────────────────────────────────────────────────────────────────────
  12875.  PCOPY Statement
  12876.  ────────────────────────────────────────────────────────────────────────────
  12877.  
  12878.  ■ Action
  12879.  
  12880.    Copies one screen page to another
  12881.  
  12882.  ■ Syntax
  12883.  
  12884.    PCOPY sourcepage, destinationpage
  12885.  
  12886.  ■ Remarks
  12887.  
  12888.    The sourcepage is an integer expression in the range 0 to n, where n is
  12889.    the maximum number of pages determined by the current video-memory size
  12890.    and the size per page for the current screen mode.
  12891.  
  12892.    The destinationpage has the same requirements as the sourcepage.
  12893.  
  12894.    See the SCREEN statement for more information about the number of pages
  12895.    available in different modes.
  12896.  
  12897.  ■ See Also
  12898.  
  12899.    CLEAR, SCREEN
  12900.  
  12901.  ■ Example
  12902.  
  12903.    The following example copies the contents of page 1 to page 2:
  12904.  
  12905.    PCOPY 1,2
  12906.  
  12907.  
  12908.  ────────────────────────────────────────────────────────────────────────────
  12909.  PEEK Function
  12910.  ────────────────────────────────────────────────────────────────────────────
  12911.  
  12912.  ■ Action
  12913.  
  12914.    Returns the byte stored at a specified memory location
  12915.  
  12916.  ■ Syntax
  12917.  
  12918.    PEEK(address)
  12919.  
  12920.  ■ Remarks
  12921.  
  12922.    The returned value is an integer in the range 0-255. The argument address
  12923.    is a value in the range 0-65,535. The argument address is treated as the
  12924.    offset from the current default segment (as set by the DEF SEG statement).
  12925.  
  12926.    If the argument is a single- or double-precision floating-point value or a
  12927.    long integer, it is converted to a two-byte integer.
  12928.  
  12929.    The PEEK function complements the POKE statement.
  12930.  
  12931.  ■ See Also
  12932.  
  12933.    DEF SEG, POKE, VARPTR
  12934.  
  12935.  ■ Example
  12936.  
  12937.    See the example for DEF SEG.
  12938.  
  12939.  
  12940.  ────────────────────────────────────────────────────────────────────────────
  12941.  PEN Function
  12942.  ────────────────────────────────────────────────────────────────────────────
  12943.  
  12944.  ■ Action
  12945.  
  12946.    Reads the lightpen coordinates
  12947.  
  12948.  ■ Syntax
  12949.  
  12950.    PEN(n)
  12951.  
  12952.  ■ Remarks
  12953.  
  12954.    The argument n indicates what value is to be returned. It is a numeric
  12955.    expression in the range 0-9.
  12956.  
  12957.  ────────────────────────────────────────────────────────────────────────────
  12958.  NOTE
  12959.    The PEN function does not work when the mouse driver is enabled because
  12960.    the mouse driver uses the PEN function's BIOS calls. Use mouse function 14
  12961.    to disable the driver's lightpen emulation. Mouse function 13 turns
  12962.    emulation back on. See your mouse manual for more information.
  12963.  ────────────────────────────────────────────────────────────────────────────
  12964.  
  12965.    The following list describes the values for n and the corresponding values
  12966.    returned by PEN:
  12967.  
  12968. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  12969.    Argument                 Value Returned
  12970.    ──────────────────────────────────────────────────────────────────────────
  12971.    0                        The most recent pen use: -1 if pen was down since
  12972.                             last poll, 0 if not
  12973.  
  12974.    1                        The x pixel coordinate where pen was last pressed
  12975.  
  12976.    2                        The y pixel coordinate where pen was last pressed
  12977.  
  12978.    3                        The current pen-switch value: -1 if down, 0 if up
  12979.  
  12980.    Argument                 Value Returned
  12981.    ──────────────────────────────────────────────────────────────────────────
  12982. 
  12983.    4                        The last known valid x pixel coordinate
  12984.  
  12985.    5                        The last known valid y pixel coordinate
  12986.  
  12987.    6                        The character row position where pen was last
  12988.                             pressed
  12989.  
  12990.    7                        The character column position where pen was last
  12991.                             pressed
  12992.  
  12993.    8                        The last known character row where the pen was
  12994.                             positioned
  12995.  
  12996.    9                        The last known character column where the pen was
  12997.                             positioned
  12998.    ──────────────────────────────────────────────────────────────────────────
  12999.  
  13000.  
  13001.  ■ Example
  13002.  
  13003.    The following example produces an endless loop to print the current
  13004.    pen-switch status (UP/DOWN):
  13005.  
  13006.    CLS
  13007.    PEN ON
  13008.    DO
  13009.       P = PEN(3)
  13010.       LOCATE 1,1 : PRINT "PEN IS ";
  13011.       IF P THEN PRINT "DOWN" ELSE PRINT "UP"
  13012.       X = PEN(4) : Y = PEN(5)
  13013.       PRINT "X =" X, "Y =" Y
  13014.    LOOP
  13015.  
  13016.  
  13017.  ────────────────────────────────────────────────────────────────────────────
  13018.  PEN ON, OFF, and STOP Statements
  13019.  ────────────────────────────────────────────────────────────────────────────
  13020.  
  13021.  ■ Action
  13022.  
  13023.    Enables, disables, or suspends lightpen-event trapping
  13024.  
  13025.  ■ Syntax
  13026.  
  13027.    PEN ON
  13028.    PEN OFF
  13029.    PEN STOP
  13030.  
  13031.  ■ Remarks
  13032.  
  13033.    The PEN ON statement enables lightpen-event trapping by using an ON PEN
  13034.    statement. The pen is initially off. A lightpen event occurs whenever the
  13035.    lightpen is activated by pressing the tip to the screen or pressing the
  13036.    touch ring. A PEN ON statement must be executed before any read-pen
  13037.    function calls. If a read-pen function is called when the pen is off, an
  13038.    error message results that reads Illegal function call.
  13039.  
  13040.    The PEN OFF statement disables lightpen event trapping. The PEN STOP
  13041.    statement suspends lightpen event trapping; a pen event is remembered and
  13042.    trapped as soon as event trapping is enabled.
  13043.  
  13044.    To speed program execution, the pen should be turned off by using a PEN
  13045.    OFF statement when pen trapping is not needed.
  13046.  
  13047.  ────────────────────────────────────────────────────────────────────────────
  13048.  NOTE
  13049.    The lightpen requires an IBM Color Graphics Adapter.
  13050.  ────────────────────────────────────────────────────────────────────────────
  13051.  
  13052.  ■ See Also
  13053.  
  13054.    ON event, PEN Function
  13055.  
  13056.  ■ Example
  13057.  
  13058.    See the example for the PEN function.
  13059.  
  13060.  
  13061.  ────────────────────────────────────────────────────────────────────────────
  13062.  PLAY Statement
  13063.  ────────────────────────────────────────────────────────────────────────────
  13064.  
  13065.  ■ Action
  13066.  
  13067.    Plays music as specified by a string
  13068.  
  13069.  ■ Syntax
  13070.  
  13071.    PLAY commandstring
  13072.  
  13073.  ■ Remarks
  13074.  
  13075.    The commandstring is a string expression containing one or more of the
  13076.    commands listed below.
  13077.  
  13078.    The PLAY statement uses a concept similar to DRAW in that it embeds a
  13079.    music macro language (described below) in one statement. A set of
  13080.    commands, used as part of the PLAY statement, specifies a particular
  13081.    action.
  13082.  
  13083.    In compiled programs, you should use the VARPTR$(variable) form for
  13084.    variables. For example, the BASICA statements
  13085.  
  13086.    PLAY "XA$"
  13087.    PLAY "O=I"
  13088.  
  13089.    should be written for the compiler like this:
  13090.  
  13091.    PLAY "X" + VARPTR$(A$)
  13092.    PLAY "O=" + VARPTR$(I)
  13093.  
  13094.    The commandstring music macros are described as follows:
  13095.  
  13096.    Octave Commands          Action
  13097.    ──────────────────────────────────────────────────────────────────────────
  13098.    o n                      Sets the current octave. There are seven octaves,
  13099.                             numbered 0-6.
  13100.  
  13101.    >                        Increases octave by 1. Octave cannot go beyond 6.
  13102.  
  13103.    <                        Decreases octave by 1. Octave cannot drop below
  13104.                             0.
  13105.  
  13106.    Tone Commands            Action
  13107.    ──────────────────────────────────────────────────────────────────────────
  13108.    A-G                      Plays a note in the range A-G. The "#" symbol or
  13109.                             the "+" symbol after a note specifies sharp; a
  13110.                             "-" specifies flat.
  13111.  
  13112.    N n                      Plays note n. The range for n is 0-84 (in the
  13113.                             seven possible octaves, there are 84 notes); n =
  13114.                             0 means a rest.
  13115.  
  13116.    Duration Commands        Action
  13117.    ──────────────────────────────────────────────────────────────────────────
  13118.    L n                      Sets the length of each note. L4 is a quarter
  13119.                             note, L1 is a whole note, etc. The range for n is
  13120.                             1-64.
  13121.                             The length may also follow the note when a change
  13122.                             of length only is desired for a particular note.
  13123.                             In this case, A16 is equivalent to L16A.
  13124.  
  13125.    MN                       Sets "music normal" so that each note will play
  13126.                             7/8 of the time determined by the length (L).
  13127.  
  13128.    ML                       Sets "music legato" so that each note will play
  13129.                             the full period set by length (L).
  13130.  
  13131.    MS                       Sets "music staccato" so that each note will play
  13132.                             3/4 of the time determined by the length (L).
  13133.  
  13134.    Tempo Commands           Action
  13135.    ──────────────────────────────────────────────────────────────────────────
  13136.    P n                      Specifies a pause, ranging from 1-64. This option
  13137.                             corresponds to the length of each note, set with
  13138.                             L n.
  13139.  
  13140.    T n                      Sets the "tempo," or the number of L4 quarter
  13141.                             notes in one minute. The range for n is 32-255.
  13142.                             The default for n is 120.
  13143.  
  13144.    Operation Commands       Action
  13145.    ──────────────────────────────────────────────────────────────────────────
  13146.    MF                       Sets music (PLAY statement) and SOUND to run in
  13147.                             the foreground. That is, each subsequent note or
  13148.                             sound will not start until the previous note or
  13149.                             sound has finished. This is the default setting.
  13150.  
  13151.    MB                       Music (PLAY statement) and SOUND are set to run
  13152.                             in the background. That is, each note or sound is
  13153.                             placed in a buffer, allowing the BASIC program to
  13154.                             continue executing while the note or sound plays
  13155.                             in the background. The maximum number of notes
  13156.                             that can be played in the background at one time
  13157.                             is 32.
  13158.  
  13159.    Suffixes                 Action
  13160.    ──────────────────────────────────────────────────────────────────────────
  13161.    # or +                   Follows a specified note and turns it into a
  13162.                             sharp.
  13163.  
  13164.    -                        Follows a specified note and turns it into a
  13165.                             flat.
  13166.  
  13167.    .                        A period after a note causes the note to play 3/2
  13168.                             times the length determined by L (length) times T
  13169.                             (tempo). The period has the same meaning as in a
  13170.                             musical score. Multiple periods can appear after
  13171.                             a note. Each period adds a length equal to one
  13172.                             half the length of the previous period. The
  13173.                             command A. plays 1 + 1/2 or 3/2 times the length;
  13174.                             A.. plays 1 + 1/2 + 1/4 or 7/4 times the length;
  13175.                             and so on. Periods can appear after a pause (P).
  13176.                             In this case, the pause length is scaled in the
  13177.                             same way notes are scaled.
  13178.  
  13179.    Substring Command        Action
  13180.    ──────────────────────────────────────────────────────────────────────────
  13181.    "X" + VARPTR$(string)    Executes a substring.
  13182.    ──────────────────────────────────────────────────────────────────────────
  13183.  
  13184.    Because of the slow clock-interrupt rate, some notes will not play at
  13185.    higher tempos (L64 at T255, for example).
  13186.  
  13187.  ■ Examples
  13188.  
  13189.    The following example uses ">" to play the scales from octave 0 to octave
  13190.    6, then reverses with "<" to play the scales from octave 6 to octave 0:
  13191.  
  13192.    SCALE$ = "CDEFGAB"
  13193.    PLAY "o0 X" + VARPTR$(SCALE$)
  13194.    FOR I = 1 TO 6
  13195.       PLAY ">X" + VARPTR$(SCALE$)
  13196.    NEXT
  13197.    PLAY "o6 X" + VARPTR$(SCALE$)
  13198.    FOR I = 1 TO 6
  13199.       PLAY "<X" + VARPTR$(SCALE$)
  13200.    NEXT
  13201.  
  13202.    The following example plays the beginning of the first movement of
  13203.    Beethoven's Fifth Symphony:
  13204.  
  13205.    LISTEN$ = "T180 o2 P2 P8 L8 GGG L2 E-"
  13206.    FATE$ = "P24 P8 L8 FFF L2 D"
  13207.    PLAY LISTEN$ + FATE$
  13208.  
  13209.  
  13210.  ────────────────────────────────────────────────────────────────────────────
  13211.  PLAY Function
  13212.  ────────────────────────────────────────────────────────────────────────────
  13213.  
  13214.  ■ Action
  13215.  
  13216.    Returns the number of notes currently in the background-music queue
  13217.  
  13218.  ■ Syntax
  13219.  
  13220.    PLAY (n)
  13221.  
  13222.  ■ Remarks
  13223.  
  13224.    The argument n is a dummy argument and may be any numeric value.
  13225.  
  13226.    PLAY(n) will return 0 when the user is in music-foreground mode.
  13227.  
  13228.  ■ See Also
  13229.  
  13230.    ON event; PLAY Statement; PLAY ON, OFF, and STOP
  13231.  
  13232.  ■ Example
  13233.  
  13234.    See the examples for the ON event statements.
  13235.  
  13236.  
  13237.  ────────────────────────────────────────────────────────────────────────────
  13238.  PLAY ON, OFF, and STOP Statements
  13239.  ────────────────────────────────────────────────────────────────────────────
  13240.  
  13241.  ■ Action
  13242.  
  13243.    PLAY ON enables play event trapping, PLAY OFF disables play event
  13244.    trapping, and PLAY STOP suspends play event trapping.
  13245.  
  13246.  ■ Syntax
  13247.  
  13248.    PLAY ON
  13249.    PLAY OFF
  13250.    PLAY STOP
  13251.  
  13252.  ■ Remarks
  13253.  
  13254.    These statements are used with the ON PLAY statement to trap play events.
  13255.    When a PLAY OFF statement is executed, the event-trapping subroutine is
  13256.    not performed and the event is not remembered.
  13257.  
  13258.    A PLAY STOP statement does not perform the event-trapping subroutine, but
  13259.    the subroutine is performed as soon as a PLAY ON statement is executed.
  13260.  
  13261.    When a play event trap occurs (that is, the GOSUB is performed), an
  13262.    automatic PLAY STOP is executed so that recursive traps cannot take place.
  13263.    The RETURN from the trapping subroutine automatically performs a PLAY ON
  13264.    statement unless an explicit PLAY OFF was performed inside the subroutine.
  13265.  
  13266.  ■ Example
  13267.  
  13268.    See the entry for the ON event statements for an example of play event
  13269.    trapping.
  13270.  
  13271.  
  13272.  ────────────────────────────────────────────────────────────────────────────
  13273.  PMAP Function
  13274.  ────────────────────────────────────────────────────────────────────────────
  13275.  
  13276.  ■ Action
  13277.  
  13278.    Maps view-coordinate expressions to physical locations or maps physical
  13279.    expressions to a view-coordinate location
  13280.  
  13281.  ■ Syntax
  13282.  
  13283.    PMAP (expression, function)
  13284.  
  13285.  ■ Remarks
  13286.  
  13287.    The argument expression indicates the coordinate of the point to be
  13288.    mapped. The argument function can have one of the four following values:
  13289.  
  13290.    Value                    Description
  13291.    ──────────────────────────────────────────────────────────────────────────
  13292.    0                        Maps view-coordinate expression to physical
  13293.                             x-coordinate
  13294.  
  13295.    1                        Maps view-coordinate expression to physical
  13296.                             y-coordinate
  13297.  
  13298.    2                        Maps physical expression to view x-coordinate
  13299.  
  13300.    3                        Maps physical expression to view y-coordinate
  13301.    ──────────────────────────────────────────────────────────────────────────
  13302.  
  13303.    The four PMAP functions allow the user to find equivalent point locations
  13304.    between the view coordinates created with the WINDOW statement and the
  13305.    physical coordinate system of the screen or viewport as defined by the
  13306.    VIEW statement.
  13307.  
  13308.  ■ See Also
  13309.  
  13310.    VIEW, WINDOW
  13311.  
  13312.  ■ Example
  13313.  
  13314.    The following fragment uses PMAP to convert coordinate values from view to
  13315.    screen coordinates and from screen coordinates to view coordinates:
  13316.  
  13317.    SCREEN 2
  13318.    'Coordinates of upper-left corner of window defined in follow-
  13319.    'ing statement are (80,100); coordinates of lower-right corner
  13320.    'are 200,200.
  13321.    WINDOW SCREEN (80,100) - (200,200)
  13322.  
  13323.    'If physical screen coordinates are (0,0) in the upper-left
  13324.    'corner and (639,199) in the lower-right corner, then the
  13325.    'following statements will return the screen coordinates
  13326.    'equivalent to the view coordinates 80,100.
  13327.    X = PMAP(80,0)          'X = 0
  13328.    Y = PMAP(100,1)         'Y = 0
  13329.  
  13330.    'The following statements will return the screen coordinates
  13331.    'equivalent to the view coordinates 200,200.
  13332.    X = PMAP(200,0)         'X = 639
  13333.    Y = PMAP(200,1)         'Y = 199
  13334.  
  13335.    'The following statements will return the view coordinates
  13336.    'equivalent to the screen coordinates 639,199.
  13337.    X = PMAP(639,2)         'X = 200
  13338.    Y = PMAP(199,3)         'Y = 200
  13339.  
  13340.  
  13341.  ────────────────────────────────────────────────────────────────────────────
  13342.  POINT Function
  13343.  ────────────────────────────────────────────────────────────────────────────
  13344.  
  13345.  ■ Action
  13346.  
  13347.    Reads the color number of a pixel from the screen or returns the pixel's
  13348.    coordinates
  13349.  
  13350.  ■ Syntax
  13351.  
  13352.    POINT (x,y)
  13353.    POINT (number)
  13354.  
  13355.  ■ Remarks
  13356.  
  13357.    The coordinates x and y refer to the pixel being evaluated by the POINT
  13358.    function. When called with two coordinates, POINT returns the color number
  13359.    of the indicated pixel. If the specified pixel is out of range, POINT
  13360.    returns the value -1.
  13361.  
  13362.    POINT with one argument (as explained in the list below) allows the user
  13363.    to retrieve the current graphics-cursor coordinates.
  13364.  
  13365.    Argument                 Value Returned
  13366.    ──────────────────────────────────────────────────────────────────────────
  13367.    0                        The current physical x-coordinate.
  13368.  
  13369.    1                        The current physical y-coordinate.
  13370.  
  13371.    2                        The current view x-coordinate. This returns the
  13372.                             same value as the POINT(0) function if the WINDOW
  13373.                             statement has not been used.
  13374.  
  13375.    3                        The current view y-coordinate. This returns the
  13376.                             same value as the POINT(1) function if the WINDOW
  13377.                             statement has not been used.
  13378.    ──────────────────────────────────────────────────────────────────────────
  13379.  
  13380.  ■ Example
  13381.  
  13382.    The following example redraws the ellipse drawn with the CIRCLE statement,
  13383.    using POINT to find the border of the ellipse by testing for a change in
  13384.    color:
  13385.  
  13386.    DEFINT X,Y
  13387.    INPUT "Enter angle of tilt in degrees (0 to 90): ",Ang
  13388.    SCREEN 1         'Medium resolution screen.
  13389.    Ang = (3.1415926#/180)*Ang      'Convert degrees to radians.
  13390.    Cs = COS(Ang) : Sn = SIN(Ang)
  13391.    CIRCLE (45,70),50,2,,,2         'Draw ellipse.
  13392.    PAINT (45,70),2                 'Paint interior of ellipse.
  13393.  
  13394.    FOR Y = 20 TO 120
  13395.       FOR X = 20 TO 70
  13396.       'Check each point in rectangle enclosing ellipse.
  13397.       IF POINT(X,Y) <> 0 THEN
  13398.           'If the point is in the ellipse, plot a corresponding
  13399.           'point in the "tilted" ellipse.
  13400.           Xnew = (X*Cs - Y*Sn) + 200 : Ynew = (X*Sn + Y*Cs)
  13401.           PSET(Xnew,Ynew),2
  13402.       END IF
  13403.       NEXT
  13404.    NEXT
  13405.    END
  13406.  
  13407.  
  13408.  ────────────────────────────────────────────────────────────────────────────
  13409.  POKE Statement
  13410.  ────────────────────────────────────────────────────────────────────────────
  13411.  
  13412.  ■ Action
  13413.  
  13414.    Writes a byte into a memory location
  13415.  
  13416.  ■ Syntax
  13417.  
  13418.    POKE address,byte
  13419.  
  13420.  ■ Remarks
  13421.  
  13422.    The expression address is a value that represents the address of the
  13423.    memory location; address must be in the range 0-65,535. The expression
  13424.    byte is the data byte to be written; it is an integer value in the range
  13425.    0-255.
  13426.  
  13427.    The address is treated as the offset from the current default segment (as
  13428.    set by the DEF SEG statement). If the argument is a single- or
  13429.    double-precision floating-point value or a long integer, it is converted
  13430.    to a two-byte integer.
  13431.  
  13432.    The complementary function to POKE is PEEK.
  13433.  
  13434.  ────────────────────────────────────────────────────────────────────────────
  13435.  WARNING
  13436.    Use POKE carefully. If used incorrectly, it can cause BASIC or the
  13437.    operating system to fail.
  13438.  ────────────────────────────────────────────────────────────────────────────
  13439.  
  13440.  ■ See Also
  13441.  
  13442.    DEF SEG, PEEK, VARPTR
  13443.  
  13444.  ■ Example
  13445.  
  13446.    See the example for the DEF SEG statement.
  13447.  
  13448.  
  13449.  ────────────────────────────────────────────────────────────────────────────
  13450.  POS Function
  13451.  ────────────────────────────────────────────────────────────────────────────
  13452.  
  13453.  ■ Action
  13454.  
  13455.    Returns the current horizontal position of the cursor
  13456.  
  13457.  ■ Syntax
  13458.  
  13459.    POS(0)
  13460.  
  13461.  ■ Remarks
  13462.  
  13463.    The leftmost cursor position is numbered 1. To return the current
  13464.    vertical-line position of the cursor, use the CSRLIN function.
  13465.  
  13466.  ■ See Also
  13467.  
  13468.    CSRLIN, LPOS
  13469.  
  13470.  ■ Example
  13471.  
  13472.    The following example uses POS to start input on a new line after every 40
  13473.    characters:
  13474.  
  13475.    PRINT "This program starts a new line after every forty"
  13476.    PRINT "characters are printed. Press <CTRL-C> to end."
  13477.    PRINT
  13478.    DO
  13479.       DO WHILE POS(0) < 41   'Stay on same line until 40 characters
  13480.          DO                  'printed.
  13481.             Char$=INKEY$
  13482.          LOOP WHILE Char$=""
  13483.          'If input is key combination CTRL-C then end; otherwise,
  13484.          'print the character.
  13485.          IF ASC(Char$) = 3 THEN END ELSE PRINT Char$;
  13486.       LOOP
  13487.       PRINT                  'Print a new line.
  13488.    LOOP
  13489.  
  13490.  
  13491.  ────────────────────────────────────────────────────────────────────────────
  13492.  PRESET Statement
  13493.  ────────────────────────────────────────────────────────────────────────────
  13494.  
  13495.  ■ Action
  13496.  
  13497.    Draws a specified point on the screen
  13498.  
  13499.  ■ Syntax
  13500.  
  13501.    PRESET «STEP»(xcoordinate,ycoordinate) «,color»
  13502.  
  13503.  ■ Remarks
  13504.  
  13505.    PRESET works exactly like PSET, except that if the color is not specified,
  13506.    the background color is selected. The following list describes the parts
  13507.    of the PRESET statement:
  13508.  
  13509.    Part                     Description
  13510.    ──────────────────────────────────────────────────────────────────────────
  13511.    STEP                     Indicates that the given x- and y-coordinates are
  13512.                             relative, not absolute. The coordinates are
  13513.                             treated as distances from the most recent cursor
  13514.                             location, not distances from the (0,0) screen
  13515.                             coordinate.
  13516.                             For example, if the most recent point referenced
  13517.                             were (10,10),
  13518.                             PRESET STEP (10,5)
  13519.                             would reference the point at (20,15).
  13520.  
  13521.    xcoordinate              The x-coordinate of the pixel that is to be set.
  13522.  
  13523.    ycoordinate              The y-coordinate of the pixel that is to be set.
  13524.  
  13525.    color                    The color attribute for the specified point.
  13526.    ──────────────────────────────────────────────────────────────────────────
  13527.  
  13528.    If a coordinate is outside the current viewport, no action is taken, nor
  13529.    is an error message given.
  13530.  
  13531.  ■ See Also
  13532.  
  13533.    PSET
  13534.  
  13535.  ■ Example
  13536.  
  13537.    The following example draws a line 20 pixels long. The line then moves
  13538.    across the screen from left to right:
  13539.  
  13540.  
  13541.    SCREEN 1 : COLOR 1,1 : CLS
  13542.    FOR I = 0 TO 299 STEP 3
  13543.        FOR J = I TO 20+I
  13544.            PSET (J,50),2                  'Draw the line in new location.
  13545.        NEXT
  13546.        FOR J = I TO 20+I
  13547.            PRESET (J,50)                  'Erase the line.
  13548.        NEXT
  13549.    NEXT
  13550.  
  13551.  
  13552.  ────────────────────────────────────────────────────────────────────────────
  13553.  PRINT Statement
  13554.  ────────────────────────────────────────────────────────────────────────────
  13555.  
  13556.  ■ Action
  13557.  
  13558.    Outputs data on the screen
  13559.  
  13560.  ■ Syntax
  13561.  
  13562.    PRINT «expressionlist» «{, | ;}»
  13563.  
  13564.  ■ Remarks
  13565.  
  13566.    If expressionlist is omitted, a blank line is printed. If expressionlist
  13567.    is included, the values of the expressions are printed on the screen. The
  13568.    expressions in the list may be numeric or string expressions. (String
  13569.    literals must be enclosed in quotation marks.)
  13570.  
  13571.    A printed number is always followed by a space. If the number is positive,
  13572.    it is also preceded by a space; if the number is negative, it is preceded
  13573.    by a minus sign (-).
  13574.  
  13575.    There are two formats that PRINT uses to display single- and
  13576.    double-precision numbers: fixed point and floating point. If PRINT can
  13577.    represent a single-precision number in the fixed-point format with seven
  13578.    or fewer digits and no loss of accuracy, then it uses the fixed-point
  13579.    format; otherwise, it uses the floating-point format. For example, the
  13580.    number 1.1E-6 is output as .0000011, but the number 1.1E-7 is output as
  13581.    1.1E-7.
  13582.  
  13583.    Similarly, if PRINT can represent a double-precision number in the
  13584.    fixed-point format with 16 or fewer digits and no loss of accuracy, then
  13585.    it uses the fixed-point format; otherwise, it uses the floating-point
  13586.    format. For example, the number 1.1D-15 is output as .0000000000000011,
  13587.    but the number 1.1D-16 is output as 1.1D-16.
  13588.  
  13589.    The PRINT statement supports only elementary BASIC data types (integers,
  13590.    long integers, single-precision real numbers, double-precision real
  13591.    numbers, and strings). To print information in a record, use the PRINT
  13592.    statement with individual record elements as in the following fragment:
  13593.  
  13594.    TYPE MyType
  13595.       Word AS STRING*20
  13596.       Count AS LONG
  13597.    END TYPE
  13598.    DIM Myrec AS MyType
  13599.  
  13600.    PRINT Myrec.Word
  13601.  
  13602.    PRINT POSITIONS
  13603.  
  13604.    The position of each printed item is determined by the punctuation used to
  13605.    separate the items in the list. BASIC divides the line into print zones of
  13606.    14 spaces each. In the expression list, a comma makes the next value print
  13607.    at the start of the next zone. A semicolon makes the next value print
  13608.    immediately after the last value. Typing one or more spaces or tabs
  13609.    between expressions has the same effect as typing a semicolon.
  13610.  
  13611.    If a comma or a semicolon terminates the list of expressions, the next
  13612.    PRINT statement prints on the same line, after spacing accordingly. If the
  13613.    expression list ends without a comma or a semicolon, a carriage-return and
  13614.    line-feed sequence is printed at the end of the line. If the printed line
  13615.    is wider than the screen width, BASIC goes to the next physical line and
  13616.    continues printing.
  13617.  
  13618.  ■ Examples
  13619.  
  13620.    In the following example, the commas in the PRINT statement print each
  13621.    value at the beginning of the next print zone:
  13622.  
  13623.    X=5
  13624.    PRINT X+5, X-5, X*(-5), X^5
  13625.    END
  13626.  
  13627.  ■ Output
  13628.  
  13629.    10            0            -25            3125
  13630.  
  13631.    In the following example, the semicolon at the end of the first PRINT
  13632.    statement makes the first two PRINT statements print on the same line. The
  13633.    last PRINT statement prints a blank line before the next prompt.
  13634.  
  13635.    DO
  13636.       INPUT "Input X (input 0 to end): ", X
  13637.       IF X = 0 THEN
  13638.          EXIT DO
  13639.       ELSE
  13640.          PRINT X "squared is" X^2 "and";
  13641.          PRINT X "cubed is" X^3
  13642.          PRINT
  13643.       END IF
  13644.    LOOP
  13645.  
  13646.  ■ Output
  13647.  
  13648.    Input X (input 0 to end): 9
  13649.     9 squared is 81 and 9 cubed is 729
  13650.  
  13651.    Input X (input 0 to end): 21
  13652.     21 squared is 441 and 21 cubed is 9261
  13653.  
  13654.    Input X (input 0 to end): 0
  13655.  
  13656.    In the following example, the semicolons in the PRINT statement print each
  13657.    value immediately after the preceding value. (Remember, a space always
  13658.    follows a number and a space precedes a positive number.)
  13659.  
  13660.    FOR X=1 TO 5
  13661.      J=J+5
  13662.      K=K+10
  13663.      PRINT J;K;
  13664.    NEXT X
  13665.  
  13666.  ■ Output
  13667.  
  13668.    5  10  10  20  15  30  20  40  25  50
  13669.  
  13670.  
  13671.  ────────────────────────────────────────────────────────────────────────────
  13672.  PRINT #, PRINT # USING Statements
  13673.  ────────────────────────────────────────────────────────────────────────────
  13674.  
  13675.  ■ Action
  13676.  
  13677.    Writes data to a sequential file
  13678.  
  13679.  ■ Syntax
  13680.  
  13681.    PRINT #filenumber,«USING stringexpression;» expressionlist «{, | ;}»
  13682.  
  13683.  ■ Remarks
  13684.  
  13685.    The filenumber is the number specified when the file was opened for
  13686.    output. The stringexpression consists of formatting characters as
  13687.    described under PRINT USING. The expressions in expressionlist are the
  13688.    numeric or string expressions to be written to the file. Spaces, commas,
  13689.    and semicolons in the expressionlist have the same meaning they have in a
  13690.    PRINT statement.
  13691.  
  13692.    If you omit expressionlist, the PRINT # statement prints a blank line in
  13693.    the file.
  13694.  
  13695.    PRINT # works like PRINT and writes an image of the data to the file, just
  13696.    as the data would be displayed on the terminal screen. For this reason, be
  13697.    careful to delimit the data so it is output correctly. If you use commas
  13698.    as delimiters, the blanks between print fields are also written to the
  13699.    file.
  13700.  
  13701.    For more information, see Chapter 3, "File and Device I/O," in Programming
  13702.    in BASIC.
  13703.  
  13704.  ■ See Also
  13705.  
  13706.    PRINT; PRINT USING; WRITE#
  13707.  
  13708.  ■ Example
  13709.  
  13710.    The following example shows the effects of omitting and of including
  13711.    delimiters in data written out with PRINT #:
  13712.  
  13713.    A$ = "CAMERA, AUTOFOCUS" : B$= "September 20, 1985"
  13714.    : C$ = "42"
  13715.    Q$ = CHR$(34)
  13716.    OPEN "INVENT.DAT" FOR OUTPUT AS #1 'Open INVENT.DAT for writing
  13717.    'Write A$, B$, C$ without delimiters.
  13718.    PRINT #1, A$ B$ C$
  13719.    'Write A$, B$, C$ with delimiters.
  13720.    PRINT #1, Q$ A$ Q$ Q$ B$ Q$ Q$ C$ Q$
  13721.    CLOSE #1
  13722.    OPEN "INVENT.DAT" FOR INPUT AS #1  'Open INVENT.DAT for reading.
  13723.    FOR I% = 1 TO 2                    'Read first two records and
  13724.       INPUT #1, First$,Second$,Third$ 'print.
  13725.       PRINT First$ TAB(30) Second$ TAB(60) Third$ : PRINT
  13726.    NEXT
  13727.    CLOSE #1
  13728.  
  13729.  ■ Output
  13730.  
  13731.    CAMERA           AUTOFOCUSSeptember 20         198542
  13732.  
  13733.    CAMERA, AUTOFOCUS      September 20, 1985            42
  13734.  
  13735.  
  13736.  ────────────────────────────────────────────────────────────────────────────
  13737.  PRINT USING Statement
  13738.  ────────────────────────────────────────────────────────────────────────────
  13739.  
  13740.  ■ Action
  13741.  
  13742.    Prints strings or numbers using a specified format
  13743.  
  13744.  ■ Syntax
  13745.  
  13746.    PRINT USING formatstring; expressionlist «{, | ;}»
  13747.  
  13748.  ■ Remarks
  13749.  
  13750.    The formatstring is a string literal (or variable) containing literal
  13751.    characters to print (such as labels) and special formatting characters.
  13752.    These formatting characters determine the field and the format of the
  13753.    printed strings or numbers. Spaces, commas, and semicolons in the
  13754.    expressionlist have the same meaning they do in a PRINT statement.
  13755.  
  13756.    The expressionlist contains the string expressions or numeric expressions
  13757.    to be printed, separated by semicolons.
  13758.  
  13759.    When PRINT USING is used to print strings, you may use one of three
  13760.    formatting characters to format the string field, as described in the
  13761.    following list:
  13762.  
  13763.    Character                Description
  13764.    ──────────────────────────────────────────────────────────────────────────
  13765.    !                        Only the first character in the given string is
  13766.                             to be printed.
  13767.  
  13768.    \    \                   Prints 2 + n characters from the string, where n
  13769.                             is the number of spaces between the two
  13770.                             backslashes. If the backslashes are typed with no
  13771.                             spaces, two characters are printed. With one
  13772.                             space, three characters are printed, and so on.
  13773.                             If the field is longer than the string, the
  13774.                             string is left-justified in the field and padded
  13775.                             with spaces on the right.
  13776.  
  13777.    &                        Indicates a variable-length string field. When
  13778.                             the field is specified with the ampersand (&),
  13779.                             the string is output without modification.
  13780.    ──────────────────────────────────────────────────────────────────────────
  13781.  
  13782.    When PRINT USING is used to print numbers, the following special
  13783.    characters can be used to format the numeric field:
  13784.  
  13785. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  13786.    Character                Description
  13787.    ──────────────────────────────────────────────────────────────────────────
  13788.    #                        Represents each digit position. Digit positions
  13789.                             are always filled. If the number to be printed
  13790.                             has fewer digits than positions specified, the
  13791.                             number is right-justified (preceded by spaces) in
  13792.                             the field.
  13793.  
  13794.    .                        Prints a decimal point. A decimal point may be
  13795.                             inserted at any position in the field. If the
  13796.                             format string specifies that a digit is to
  13797.                             precede the decimal point, the digit is always
  13798.                             printed (as 0, if necessary). If necessary,
  13799.    Character                Description
  13800.    ──────────────────────────────────────────────────────────────────────────
  13801.                            printed (as 0, if necessary). If necessary,
  13802.                             numbers are rounded.
  13803.  
  13804.    +                        Causes the sign of the number (plus or minus) to
  13805.                             be printed before the number (if it appears at
  13806.                             the beginning of the format string) or after (if
  13807.                             it appears at the end of the format string).
  13808.  
  13809.    -                        Causes a negative number to be printed with a
  13810.                             trailing minus sign if it appears at the end of
  13811.                             the format string.
  13812.  
  13813.    **                       Causes leading spaces in the numeric field to be
  13814.                             filled with asterisks. The double asterisk also
  13815.                             specifies positions for two more digits.
  13816.  
  13817.    $$                       Causes a dollar sign to be printed to the
  13818.                             immediate left of the formatted number. The $$
  13819.                             specifies two more digit positions, one of which
  13820.    Character                Description
  13821.    ──────────────────────────────────────────────────────────────────────────
  13822.                            specifies two more digit positions, one of which
  13823.                             is the dollar sign.
  13824.  
  13825.    **$                      Combines the effects of the double-asterisk and
  13826.                             double-dollar-sign symbols. Leading spaces are
  13827.                             asterisk-filled and a dollar sign is printed
  13828.                             before the number. The **$ symbols specify three
  13829.                             more digit positions, one of which is the dollar
  13830.                             sign. When negative numbers are printed, the
  13831.                             minus sign appears to the immediate left of the
  13832.                             dollar sign.
  13833.  
  13834.    ,                        If the comma appears to the left of the decimal
  13835.                             point in a format string, it causes a comma to be
  13836.                             printed to the left of every third digit left of
  13837.                             the decimal point. If it appears at the end of
  13838.                             the format string, it is printed as part of the
  13839.                             string. A comma specifies another digit position.
  13840.                             The comma has no effect if used with exponential
  13841.    Character                Description
  13842.    ──────────────────────────────────────────────────────────────────────────
  13843.                            The comma has no effect if used with exponential
  13844.                             (^^^^ or ^^^^^) format.
  13845.  
  13846.    ^^^^                     Specifies exponential format. You can also use
  13847.                             five carets (^^^^^) to allow E+xxx to be printed
  13848.                             for larger numbers. Any decimal point position
  13849.                             may be specified. The significant digits are
  13850.                             left-justified and the exponent is adjusted.
  13851.                             Unless a leading +, trailing +, or - is
  13852.                             specified, one digit position is used to the left
  13853.                             of the decimal point to print a space or a minus
  13854.                             sign.
  13855.  
  13856.    _                        An underscore in the format string prints the
  13857.                             next character as a literal character. A literal
  13858.                             underscore is printed as the result of two
  13859.                             underscores ( __ ) in the format string.
  13860.  
  13861.    %                        If the number to be printed is larger than the
  13862.    Character                Description
  13863.    ──────────────────────────────────────────────────────────────────────────
  13864.   %                        If the number to be printed is larger than the
  13865.                             specified numeric field, a percent sign (%) is
  13866.                             printed in front of the number. If rounding
  13867.                             causes the number to exceed the field, a percent
  13868.                             sign is printed in front of the rounded number.
  13869.                             If the number of digits specified exceeds 24, an
  13870.                             error message results that reads Illegal function
  13871.                             call.
  13872.    ──────────────────────────────────────────────────────────────────────────
  13873.  
  13874.  
  13875.  ■ Examples
  13876.  
  13877.    The following example shows the results of using the three
  13878.    string-formatting characters:
  13879.  
  13880.    'Using the three string-formatting characters to modify the
  13881.    'appearance of printed output.
  13882.    A$ = "LOOK" : B$ = "OUT"
  13883.    PRINT USING "!";A$;B$
  13884.    PRINT USING "\  \";A$;B$        'Two spaces between back-
  13885.                                    'slashes, will print four
  13886.                                    'characters from A$.
  13887.    PRINT USING "\   \";A$;B$;"!!"  'Three spaces, will print
  13888.    PRINT USING "!";A$;             'A$ and a blank.
  13889.    PRINT USING "&";B$
  13890.  
  13891.  ■ Output
  13892.  
  13893.    LO
  13894.    LOOKOUT
  13895.    LOOK OUT  !!
  13896.    LOUT
  13897.  
  13898.    The following example shows the effects of different combinations of
  13899.    numeric formatting characters:
  13900.  
  13901.    'Format and print numeric data.
  13902.    PRINT USING "##.##";.78
  13903.    PRINT USING "###.##";987.654
  13904.    PRINT USING "##.##   ";10.2,5.3,66.789,.234
  13905.    PRINT USING "+##.##   ";-68.95,2.4,55.6,-.9
  13906.    PRINT USING "##.##-   ";-68.95,22.449,-7.01
  13907.    PRINT USING "**#.#   ";12.39,-0.9,765.1
  13908.    PRINT USING "$$###.##";456.78
  13909.    PRINT USING "**$##.##";2.34
  13910.    PRINT USING "####,.##";1234.5
  13911.    PRINT USING "##.##^^^^";234.56
  13912.    PRINT USING ".####^^^^-";-888888
  13913.    PRINT USING "+.##^^^^";123
  13914.    PRINT USING "+.##^^^^^";123
  13915.    PRINT USING "_!##.##_!";12.34
  13916.    PRINT USING "##.##";111.22
  13917.    PRINT USING ".##";.999
  13918.  
  13919.  ■ Output
  13920.  
  13921.    0.78
  13922.    987.65
  13923.    10.20    5.30   66.79    0.23
  13924.    -68.95    +2.40   +55.60    -0.90
  13925.    68.95-   22.45     7.01-
  13926.    *12.4   *-0.9   765.1
  13927.     $456.78
  13928.    ***$2.34
  13929.    1,234.50
  13930.     2.35E+02
  13931.    .8889E+06-
  13932.    +.12E+03
  13933.    +.12E+003
  13934.    !12.34!
  13935.    %111.22
  13936.    %1.00
  13937.  
  13938.  
  13939.  ────────────────────────────────────────────────────────────────────────────
  13940.  PSET Statement
  13941.  ────────────────────────────────────────────────────────────────────────────
  13942.  
  13943.  ■ Action
  13944.  
  13945.    Draws a point on the screen
  13946.  
  13947.  ■ Syntax
  13948.  
  13949.    PSET «STEP»(xcoordinate,ycoordinate) «,color»
  13950.  
  13951.  ■ Remarks
  13952.  
  13953.    The following list describes the parts of the PSET statement:
  13954.  
  13955.    Part                     Description
  13956.    ──────────────────────────────────────────────────────────────────────────
  13957.    STEP                     Indicates that the given xcoordinate and
  13958.                             ycoordinate are relative, not absolute. The
  13959.                             coordinates are treated as distances from the
  13960.                             most recent cursor location, not distances from
  13961.                             the (0,0) screen coordinate.
  13962.  
  13963.                             For example, if the most recent point referenced
  13964.                             were (10,10) then
  13965.  
  13966.                             PSET STEP (10,5)
  13967.  
  13968.                             would reference the point at (20,15).
  13969.  
  13970.    xcoordinate              The x-coordinate of the pixel that is to be set.
  13971.  
  13972.    ycoordinate              The y-coordinate of the pixel that is to be set.
  13973.  
  13974.    color                    The color attribute for the specified point.
  13975.    ──────────────────────────────────────────────────────────────────────────
  13976.  
  13977.    If a coordinate is outside the current viewport, no action is taken nor is
  13978.    an error message given. PSET allows the color to be left off the command
  13979.    line. If it is omitted, the default is the foreground color.
  13980.  
  13981.  ■ See Also
  13982.  
  13983.    PRESET
  13984.  
  13985.  ■ Example
  13986.  
  13987.    The following example draws a line from (0,0) to (100,100) and then erases
  13988.    that line by writing over it with the background color:
  13989.  
  13990.    SCREEN 2  'Draw a line from (0,0) to (100,100).
  13991.    FOR I=0 TO 100
  13992.       PSET (I,I)
  13993.    NEXT I
  13994.    FOR I=0 TO 100 'Now erase that line.
  13995.       PSET STEP (-1,-1),0
  13996.    NEXT I
  13997.  
  13998.  
  13999.  ────────────────────────────────────────────────────────────────────────────
  14000.  PUT Statement──Graphics
  14001.  ────────────────────────────────────────────────────────────────────────────
  14002.  
  14003.  ■ Action
  14004.  
  14005.    Places a graphic image obtained by a GET statement onto the screen
  14006.  
  14007.  ■ Syntax
  14008.  
  14009.    PUT «STEP» (x, y), arrayname«(indices)» «,actionverb»
  14010.  
  14011.  ■ Remarks
  14012.  
  14013.    The parts of the PUT statement are described as follows:
  14014.  
  14015. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  14016.    Part                     Description
  14017.    ──────────────────────────────────────────────────────────────────────────
  14018.    STEP                     Indicates that the given x- and y-coordinates are
  14019.                             relative, not absolute. The coordinates are
  14020.                             treated as distances from the most recent cursor
  14021.                             location, not distances from the (0,0) screen
  14022.                             coordinate.
  14023.  
  14024.                             For example, if the most recent point referenced
  14025.                             were (10,10) then the statement
  14026.  
  14027.                             PUT STEP (10,5),Ball
  14028.  
  14029.                             would put the object stored in Ball at (20,15).
  14030.    Part                     Description
  14031.    ──────────────────────────────────────────────────────────────────────────
  14032.                            would put the object stored in Ball at (20,15).
  14033.  
  14034.    (x,y)                    Coordinates specifying the top-left corner of the
  14035.                             rectangle enclosing the image to be placed in the
  14036.                             current output window.
  14037.  
  14038.    arrayname                The name of the array that holds the image. See
  14039.                             the entry for GET (Graphics) for the formula that
  14040.                             computes the size of this array. The array can be
  14041.                             a multidimensional array.
  14042.  
  14043.    indices                  Specifies that the image is retrieved starting
  14044.                             from the designated array element, rather than at
  14045.                             the first array element.
  14046.  
  14047.    actionverb               The actionverb determines the interaction between
  14048.                             the stored image and the one already on the
  14049.                             screen.
  14050.    ──────────────────────────────────────────────────────────────────────────
  14051.    Part                     Description
  14052.    ──────────────────────────────────────────────────────────────────────────
  14053.   ──────────────────────────────────────────────────────────────────────────
  14054.  
  14055.  
  14056.    The different values for actionverb are described in the following list.
  14057.    The default for actionverb is XOR.
  14058.  
  14059. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  14060.    Verb                     Description
  14061.    ──────────────────────────────────────────────────────────────────────────
  14062.    PSET                     Transfers the data point-by-point onto the
  14063.                             screen. Each point has the exact color attribute
  14064.                             it had when it was taken from the screen with
  14065.                             GET.
  14066.  
  14067.    PRESET                   The same as PSET except that a negative image
  14068.                             (for example, black on white) is produced.
  14069.  
  14070.    AND                      Used when the image is to be transferred over an
  14071.                             existing image on the screen. The resulting image
  14072.    Verb                     Description
  14073.    ──────────────────────────────────────────────────────────────────────────
  14074.                            existing image on the screen. The resulting image
  14075.                             is the result of a logical AND of the stored
  14076.                             image and the screen; points that had the same
  14077.                             color in both the existing image and the stored
  14078.                             image remain the same color, while those points
  14079.                             that do not have the same color in both the
  14080.                             existing image and the stored image do not.
  14081.  
  14082.    OR                       Used to superimpose the image onto an existing
  14083.                             image; the stored image does not erase the
  14084.                             previous screen contents. The resulting image is
  14085.                             the product of a logical OR of the stored image
  14086.                             and the screen image.
  14087.  
  14088.    XOR                      A special mode often used for animation. XOR
  14089.                             causes the points on the screen to be inverted
  14090.                             where a point exists in the array image. This
  14091.                             behavior is exactly like that of the cursor: when
  14092.                             an image is placed on the screen against a
  14093.    Verb                     Description
  14094.    ──────────────────────────────────────────────────────────────────────────
  14095.                            an image is placed on the screen against a
  14096.                             complex background twice, the background is
  14097.                             restored. This allows you to move an object
  14098.                             around the screen without erasing the background.
  14099.    ──────────────────────────────────────────────────────────────────────────
  14100.  
  14101.  
  14102.    See Chapter 5, "Graphics," in Programming in BASIC for a detailed
  14103.    description of doing animation with the PUT statement.
  14104.  
  14105.  ■ See Also
  14106.  
  14107.    GET (Graphics), PRESET, PRINT, PSET
  14108.  
  14109.  ■ Example
  14110.  
  14111.    The following example creates a moving white ball that ricochets off the
  14112.    sides of the screen until you press a key to end the program:
  14113.  
  14114.    DEFINT A-Z
  14115.    DIM Ball(84)     'Dimension integer array large enough
  14116.                     'to hold ball.
  14117.    SCREEN 2         '640 pixels by 200 pixels screen resolution.
  14118.    INPUT "Press any key to end; press <ENTER> to start",Test$
  14119.    CLS
  14120.    CIRCLE (16,16),14       'Draw and paint ball.
  14121.    PAINT (16,16),1
  14122.    GET (0,0)-(32,32),Ball
  14123.    X = 0 : Y = 0
  14124.    Xdelta = 2 : Ydelta = 1
  14125.  
  14126.    DO
  14127.  
  14128.       'Continue moving in same direction as long as ball is within
  14129.       'the boundaries of the screen - (0,0) to (640,200).
  14130.  
  14131.       X = X + Xdelta : Y = Y + Ydelta
  14132.       IF INKEY$<>"" THEN END  ' Test for key press.
  14133.  
  14134.       'Change X direction if ball hits left or right edge.
  14135.       IF (X < 1 OR X > 600) THEN
  14136.          Xdelta = -Xdelta
  14137.          BEEP
  14138.       END IF
  14139.       'Change Y direction if ball hits top or bottom edge.
  14140.       IF (Y < 1 OR Y > 160) THEN
  14141.          Ydelta = -Ydelta
  14142.          BEEP
  14143.       END IF
  14144.       'Put new image on screen, simultaneously erasing old image.
  14145.       PUT (X,Y),Ball,PSET
  14146.  
  14147.    LOOP
  14148.    END
  14149.  
  14150.  
  14151.  ────────────────────────────────────────────────────────────────────────────
  14152.  PUT Statement──File I/O
  14153.  ────────────────────────────────────────────────────────────────────────────
  14154.  
  14155.  ■ Action
  14156.  
  14157.    Writes from a variable or a random-access buffer to a file
  14158.  
  14159.  ■ Syntax
  14160.  
  14161.    PUT «#»filenumber«,«recordnumber»«,variable»»
  14162.    PUT «#»filenumber«,{recordnumber|recordnumber, variable|,variable}»
  14163.  
  14164.  ■ Remarks
  14165.  
  14166.    The following list describes the parts of the PUT statement:
  14167.  
  14168. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  14169.    Argument                 Description
  14170.    ──────────────────────────────────────────────────────────────────────────
  14171.    filenumber               The number used in the OPEN statement to open the
  14172.                             file.
  14173.  
  14174.    recordnumber             For random-mode files, the number of the record
  14175.                             to be written. For binary-mode files, the byte
  14176.                             position in the file where writing is done. The
  14177.    Argument                 Description
  14178.    ──────────────────────────────────────────────────────────────────────────
  14179.                            position in the file where writing is done. The
  14180.                             first record in a file is record 1. If you omit
  14181.                             recordnumber, the next record or byte (the one
  14182.                             after the last GET or PUT statement, or the one
  14183.                             pointed to by the last SEEK) is written to. The
  14184.                             largest possible record number is 2^31-1 or
  14185.                             2,147,483,647.
  14186.  
  14187.    variable                 The variable containing the output to be written
  14188.                             to the file. The PUT statement writes as many
  14189.                             bytes to the file as there are bytes in the
  14190.                             variable.
  14191.  
  14192.                             If you use a variable, you do not need to use
  14193.                             MKI$, MKL$, MKS$, or MKD$ to convert numeric
  14194.                             fields before writing. You may not use a FIELD
  14195.                             statement with the file if you use the variable
  14196.                             argument.
  14197.  
  14198.    Argument                 Description
  14199.    ──────────────────────────────────────────────────────────────────────────
  14200. 
  14201.                             For random-access files, you can use any variable
  14202.                             as long as the length of the variable is less
  14203.                             than or equal to the length of the record.
  14204.                             Usually, a record variable defined to match the
  14205.                             fields in a data record is used.
  14206.  
  14207.                             For binary-mode files, you can use any variable.
  14208.  
  14209.                             When you use a variable-length string variable,
  14210.                             the statement writes as many bytes as there are
  14211.                             characters in the string's value. For example,
  14212.                             the following two statements write 15 bytes to
  14213.                             file number 1:
  14214.  
  14215.                             VarString$=STRING$ (15, "X") PUT #1,,VarString$
  14216.  
  14217.                             See the examples below and Chapter 3, "File and
  14218.                             Device I/O," in Programming in BASIC, for more
  14219.    Argument                 Description
  14220.    ──────────────────────────────────────────────────────────────────────────
  14221.                            Device I/O," in Programming in BASIC, for more
  14222.                             information about using variables rather than
  14223.                             FIELD statements for random-access files.
  14224.  
  14225.                             A record cannot contain more than 32,767 bytes.
  14226.    ──────────────────────────────────────────────────────────────────────────
  14227.  
  14228.  
  14229.    You can omit the recordnumber, the variable, or both. If you omit only the
  14230.    recordnumber, you must still include the commas:
  14231.  
  14232.    PUT #4,,FileBuffer
  14233.  
  14234.    If you omit both arguments, you do not include the commas:
  14235.  
  14236.    PUT #4
  14237.  
  14238.    The GET and PUT statements allow fixed-length input and output for BASIC
  14239.    communications files. Be careful using GET and PUT for communications
  14240.    because PUT writes a fixed number of characters and may wait indefinitely
  14241.    if there is a communications failure.
  14242.  
  14243.  ────────────────────────────────────────────────────────────────────────────
  14244.  NOTE
  14245.    When using a file buffer defined by a FIELD statement, LSET, RSET, PRINT
  14246.    #, PRINT # USING, and WRITE # may be used to put characters in the
  14247.    random-file buffer before executing a PUT statement. In the case of WRITE
  14248.    # , BASIC pads the buffer with spaces up to the carriage return. Any
  14249.    attempt to read or write past the end of the buffer causes an error
  14250.    message that reads FIELD overflow.
  14251.  ────────────────────────────────────────────────────────────────────────────
  14252.  
  14253.  ■ See Also
  14254.  
  14255.    CVI, CVS, CVL, CVD;
  14256.    GET (File I/O);LSET; MKD$,
  14257.    MKI$, MKL$, MKS$
  14258.  
  14259.  ■ Example
  14260.  
  14261.    The following example reads names and test scores from the console and
  14262.    stores the names and scores in a random-access file:
  14263.  
  14264.  
  14265.    ' Read a name and a test score from the console.
  14266.    ' Store each name and score as a record in a
  14267.    ' random-access file.
  14268.  
  14269.    ' Define record fields.
  14270.    TYPE TestRecord
  14271.       NameField  AS STRING*20
  14272.       ScoreField AS SINGLE
  14273.    END TYPE
  14274.  
  14275.    ' Open the test data file.
  14276.    DIM FileBuffer AS TestRecord
  14277.    OPEN "TESTDAT.DAT" FOR RANDOM AS #1 LEN=LEN(FileBuffer)
  14278.  
  14279.    ' Read pairs of names and scores from the console.
  14280.  
  14281.    I=0
  14282.    DO
  14283.       I=I+1
  14284.       INPUT "Name ? ",FileBuffer.NameField
  14285.       INPUT "Score? ",FileBuffer.ScoreField
  14286.       INPUT "-->More (y/n)? ",Resp$
  14287.       PUT #1,I,FileBuffer
  14288.    LOOP UNTIL UCASE$(MID$(Resp$,1,1))="N"
  14289.  
  14290.    PRINT I;" records written."
  14291.  
  14292.    CLOSE #1
  14293.  
  14294.  
  14295.  ────────────────────────────────────────────────────────────────────────────
  14296.  RANDOMIZE Statement
  14297.  ────────────────────────────────────────────────────────────────────────────
  14298.  
  14299.  ■ Action
  14300.  
  14301.    Initializes (reseeds) the random-number generator
  14302.  
  14303.  ■ Syntax
  14304.  
  14305.    RANDOMIZE«expression»
  14306.  
  14307.  ■ Remarks
  14308.  
  14309.    If you omit expression, BASIC pauses and asks for a value by printing
  14310.  
  14311.    Random Number Seed (-32768 to 32767)?
  14312.  
  14313.    before executing the RANDOMIZE statement. When you use the argument
  14314.    expression, QuickBASIC uses this value to initialize the random-number
  14315.    generator.
  14316.  
  14317.    If the random-number generator is not reseeded, the RND function returns
  14318.    the same sequence of random numbers each time the program is run. To
  14319.    change the sequence of random numbers every time the program is run, place
  14320.    a RANDOMIZE statement at the beginning of the program and change the
  14321.    argument with each run.
  14322.  
  14323.    A convenient way to initialize the random-number generator is to use the
  14324.    TIMER function. Using TIMER ensures a new series of random numbers each
  14325.    time you use the program. See the example below.
  14326.  
  14327.  ■ See Also
  14328.  
  14329.    RND, TIMER
  14330.  
  14331.  ■ Example
  14332.  
  14333.    The following program simulates rolling two dice. The RANDOMIZE statement
  14334.    initializes the random-number generator so the program produces different
  14335.    numbers each time.
  14336.  
  14337.    ' Use the timer as the seed for the number generator.
  14338.    RANDOMIZE TIMER
  14339.  
  14340.    DO
  14341.       ' Simulate rolling two dice using RND.
  14342.       D1=INT(RND*6)+1
  14343.       D2=INT(RND*6)+1
  14344.       ' Report the roll.
  14345.       PRINT "You rolled a";D1;"and a";D2;"for a total of";D1+D2
  14346.       INPUT "Roll again (Y/N)";Resp$
  14347.       PRINT
  14348.    LOOP UNTIL UCASE$(MID$(Resp$,1,1))="N"
  14349.  
  14350.    END
  14351.  
  14352.  ■ Output
  14353.  
  14354.    You rolled a 3 and a 5 for a total of 8
  14355.    Roll again (Y/N)? y
  14356.  
  14357.    You rolled a 4 and a 1 for a total of 5
  14358.    Roll again (Y/N)? y
  14359.  
  14360.    You rolled a 5 and a 6 for a total of 11
  14361.    Roll again (Y/N)? n
  14362.  
  14363.  
  14364.  ────────────────────────────────────────────────────────────────────────────
  14365.  READ Statement
  14366.  ────────────────────────────────────────────────────────────────────────────
  14367.  
  14368.  ■ Action
  14369.  
  14370.    Reads values from a DATA statement and assigns the values to variables
  14371.  
  14372.  ■ Syntax
  14373.  
  14374.    READ variablelist
  14375.  
  14376.  ■ Remarks
  14377.  
  14378.    A variablelist is a series of valid BASIC variables separated by commas.
  14379.    READ statements are always used with DATA statements. READ assigns DATA
  14380.    values to variables on a one-to-one basis. These variables may be numeric
  14381.    or string. Attempting to read a string value into a numeric variable
  14382.    produces a run-time syntax error. Reading a numeric value into a string
  14383.    variable does not produce an error, but stores the value as a string of
  14384.    numerals.
  14385.  
  14386.    Values read into integer variables are rounded before the value is
  14387.    assigned to the variable. Reading a numeric value too large for a variable
  14388.    produces a run-time error.
  14389.  
  14390.    String values read into fixed-length string variables are truncated if the
  14391.    string is too long. String values shorter than the string-variable length
  14392.    are left-justified and padded with blanks.
  14393.  
  14394.    Only individual elements of a record variable may appear in a READ
  14395.    statement. See example below.
  14396.  
  14397.    A single READ statement may use one or more DATA statements (they will be
  14398.    used in order); several READ statements may use the same DATA statement.
  14399.    If there are more variables in variablelist than there are values in the
  14400.    DATA statement or statements, an error message is printed that reads Out
  14401.    of DATA. If there are fewer variables than the number of elements in the
  14402.    DATA statement or statements, subsequent READ statements begin reading
  14403.    data at the first unread element. If there are no subsequent READ
  14404.    statements, the extra items are ignored.
  14405.  
  14406.    Use the RESTORE statement to reread DATA statements.
  14407.  
  14408.  ■ See Also
  14409.  
  14410.    DATA, RESTORE
  14411.  
  14412.  ■ Example
  14413.  
  14414.    The following fragment shows how a READ statement can be used to read
  14415.    information into the user-defined type named Employee:
  14416.  
  14417.    TYPE Employee
  14418.       FullName AS STRING*35
  14419.       SocSec AS STRING*9
  14420.       JobClass AS INTEGER
  14421.    END TYPE
  14422.  
  14423.    DIM ThisEmp AS Employee
  14424.    DATA "Julia Magruder","300-32-3403",3
  14425.    DATA "Amelie Reeves Troubetzkoy","777-29-3206",7
  14426.    .
  14427.    .
  14428.    .
  14429.    READ ThisEmp.FullName, ThisEmp.SocSec, ThisEmp.JobClass
  14430.    .
  14431.    .
  14432.    .
  14433.  
  14434.    See also the examples for DATA and RESTORE.
  14435.  
  14436.  
  14437.  ────────────────────────────────────────────────────────────────────────────
  14438.  REDIM Statement
  14439.  ────────────────────────────────────────────────────────────────────────────
  14440.  
  14441.  ■ Action
  14442.  
  14443.    Changes the space allocated to an array that has been declared ¢DYNAMIC
  14444.  
  14445.  ■ Syntax
  14446.  
  14447.    REDIM «SHARED» variable(subscripts)«AS type» «,variable(subscripts)«AS typ
  14448.    e»»...
  14449.  
  14450.  ■ Remarks
  14451.  
  14452.    The REDIM statement has the following arguments:
  14453.  
  14454.    Arguments                Description
  14455.    ──────────────────────────────────────────────────────────────────────────
  14456.    SHARED                   The optional SHARED attribute allows a module to
  14457.                             share variables with all the procedures in the
  14458.                             module; this differs from the SHARED statement,
  14459.                             which affects only the variables within a single
  14460.                             module. SHARED can only be used in REDIM
  14461.                             statements in the module-level code.
  14462.  
  14463.    variable                 A BASIC variable name.
  14464.  
  14465.    subscripts               The dimensions of the array. Multiple dimensions
  14466.                             can be declared. The subscript syntax is
  14467.                             described below.
  14468.  
  14469.    AS type                  Declares variable as an elementary or
  14470.                             user-defined type. The elementary types are
  14471.                             INTEGER, LONG, SINGLE, DOUBLE, and STRING.
  14472.    ──────────────────────────────────────────────────────────────────────────
  14473.  
  14474.    Subscripts in REDIM statements have the following form:
  14475.  
  14476.    «lower TO» upper «, «lower TO» upper»...
  14477.  
  14478.    The TO keyword provides a way to indicate both the lower and the upper
  14479.    bounds of an array's subscripts. The arguments lower and upper are numeric
  14480.    expressions specifying the lowest and highest value for the subscript. See
  14481.    the DIM statement for more information about using the TO keyword.
  14482.  
  14483.    The REDIM statement changes the space allocated to an array that has been
  14484.    declared dynamic. See Chapter 2, "Data Types," for more information about
  14485.    both static and dynamic arrays.
  14486.  
  14487.    When a REDIM statement is compiled, all arrays declared in the statement
  14488.    are treated as dynamic. At run time, when a REDIM statement is executed,
  14489.    the array is deallocated (if it is already allocated) and then reallocated
  14490.    with the new dimensions. Old array-element values are lost because all
  14491.    numeric elements are reset to 0 and all string elements are reset to null
  14492.    strings. Although you may change the size of an array's dimensions with
  14493.    the REDIM statement, you may not change the number of dimensions. For
  14494.    example, the following statements are legal:
  14495.  
  14496.    ' ¢DYNAMIC
  14497.    DIM A(50,50)
  14498.    ERASE A
  14499.    REDIM A(20,15)    'Array A still has two dimensions.
  14500.  
  14501.    However, the following statements are not legal and produce an error
  14502.    message that reads Wrong number of dimensions:
  14503.  
  14504.    ' ¢DYNAMIC
  14505.    DIM A(50,50)
  14506.    ERASE A
  14507.    REDIM A(5,5,5)   'Changed number of dimensions from
  14508.                     'two to three.
  14509.  
  14510.  ■ See Also
  14511.  
  14512.    DIM, ERASE, LBOUND, OPTION BASE, SHARED, UBOUND
  14513.  
  14514.  ■ Example
  14515.  
  14516.    The following program fragment shows one way to use REDIM to allocate an
  14517.    array of records when the records are needed and later to free the memory
  14518.    that the records use:
  14519.  
  14520.    TYPE KeyElement
  14521.       Word AS STRING*20
  14522.       Count AS INTEGER
  14523.    END TYPE
  14524.  
  14525.    ' Make arrays dynamic.
  14526.    ' ¢DYNAMIC
  14527.    .
  14528.    .
  14529.    .
  14530.    ' Allocate an array of records when you need it.
  14531.    REDIM Keywords(500) AS KeyElement
  14532.    Keywords(99).Word="ERASE"
  14533.    Keywords(99).Count=2
  14534.    PRINT Keywords(99).Word,Keywords(99).Count
  14535.    .
  14536.    .
  14537.    .
  14538.    ' Free the space taken by Keywords when you're finished.
  14539.    ERASE Keywords
  14540.    .
  14541.    .
  14542.    .
  14543.    END
  14544.  
  14545.  
  14546.  ────────────────────────────────────────────────────────────────────────────
  14547.  REM Statement
  14548.  ────────────────────────────────────────────────────────────────────────────
  14549.  
  14550.  ■ Action
  14551.  
  14552.    Allows explanatory remarks to be inserted in a program
  14553.  
  14554.  ■ Syntax 1
  14555.  
  14556.    REM remark
  14557.  
  14558.  ■ Syntax 2
  14559.  
  14560.    ' remark
  14561.  
  14562.  ■ Remarks
  14563.  
  14564.    REM statements are not compiled, but they appear exactly as entered when
  14565.    the program is listed. You may branch from a GOTO or GOSUB statement to a
  14566.    REM statement. Execution continues with the first executable statement
  14567.    after the REM statement.
  14568.  
  14569.    A single quotation mark can be used instead of the REM keyword. If the REM
  14570.    keyword follows other statements on a line, it must be separated from the
  14571.    statements by a colon.
  14572.  
  14573.    REM statements are also used to introduce metacommands (see Appendix F,
  14574.    "Metacommands," in Programming in BASIC for more information).
  14575.  
  14576.  ────────────────────────────────────────────────────────────────────────────
  14577.  NOTE
  14578.    Do not use the single quotation form of the REM statement in a DATA
  14579.    statement because it will be considered valid data.
  14580.  ────────────────────────────────────────────────────────────────────────────
  14581.  
  14582.  ■ Examples
  14583.  
  14584.    The following two lines are equivalent (notice that the colon is not
  14585.    required with the single quote):
  14586.  
  14587.    FOR I=1 TO 23 : Array(I)=1 : NEXT I : REM Initialize the array.
  14588.    FOR I=1 TO 23 : Array(I)=1 : NEXT I   ' Initialize the array.
  14589.  
  14590.  
  14591.  ────────────────────────────────────────────────────────────────────────────
  14592.  RESET Statement
  14593.  ────────────────────────────────────────────────────────────────────────────
  14594.  
  14595.  ■ Action
  14596.  
  14597.    Closes all disk files
  14598.  
  14599.  ■ Syntax
  14600.  
  14601.    RESET
  14602.  
  14603.  ■ Remarks
  14604.  
  14605.    The RESET statement closes all open disk files and writes data still in
  14606.    the file buffers to disk. All files must be closed before a disk is
  14607.    removed from its drive.
  14608.  
  14609.  ■ See Also
  14610.  
  14611.    CLOSE, END, SYSTEM
  14612.  
  14613.  ■ Example
  14614.  
  14615.    There are no programming examples for the RESET statement.
  14616.  
  14617.  
  14618.  ────────────────────────────────────────────────────────────────────────────
  14619.  RESTORE Statement
  14620.  ────────────────────────────────────────────────────────────────────────────
  14621.  
  14622.  ■ Action
  14623.  
  14624.    Allows DATA statements to be reread from a specified line
  14625.  
  14626.  ■ Syntax
  14627.  
  14628.    RESTORE «{linenumber | linelabel }»
  14629.  
  14630.  ■ Remarks
  14631.  
  14632.    After executing a RESTORE statement without a specified linenumber or
  14633.    linelabel, the next READ statement gets the first item in the first DATA
  14634.    statement in the program.
  14635.  
  14636.    If linenumber or linelabel is specified, the next READ statement gets the
  14637.    first item in the specified DATA statement. If a line is specified, the
  14638.    line number or line label must be in the module-level code. (Note that in
  14639.    the QuickBASIC environment, DATA statements are automatically moved to the
  14640.    module-level code.)
  14641.  
  14642.  ■ See Also
  14643.  
  14644.    DATA, READ
  14645.  
  14646.  ■ Example
  14647.  
  14648.    The RESTORE statement in the following fragment (from a program that
  14649.    generates random bridge hands) allows the program to reread the prompts in
  14650.    the DATA statement so the user can enter new boundary conditions for the
  14651.    different suits:
  14652.  
  14653.    DEFINT A-Z
  14654.    DIM X(13), Param(5,2)
  14655.    DATA Spades, Hearts, Diamonds, Clubs, Points
  14656.  
  14657.    CALL GetParameters(Param())
  14658.  
  14659.    DO
  14660.    .
  14661.    .
  14662.    .
  14663.       INPUT "Repeat with same parameters"; Ch$
  14664.       IF UCASE$(Ch$) <> "Y" THEN
  14665.          INPUT "Repeat with new parameters"; Ch$
  14666.          IF UCASE$(Ch$) <> "Y" THEN
  14667.             EXIT DO
  14668.          ELSE
  14669.             RESTORE
  14670.             CALL GetParameters(Param())
  14671.          END IF
  14672.       END IF
  14673.    LOOP
  14674.  
  14675.    END
  14676.  
  14677.    SUB GetParameters(Param(2)) STATIC
  14678.       CLS
  14679.       FOR I = 0 TO 4
  14680.          READ SUIT$
  14681.          PRINT SUIT$ " (low, high)";
  14682.          INPUT Param(I,0), Param(I,1)
  14683.       NEXT
  14684.    END SUB
  14685.  
  14686.  ■ Output
  14687.  
  14688.    Spades (low, high)? 5,10
  14689.    Hearts (low, high)? 5,10
  14690.    Diamonds (low, high)? 6,8
  14691.    Clubs (low, high)? 6,8
  14692.    Points (low, high)? 5,15
  14693.    .
  14694.    .
  14695.    .
  14696.    Repeat with same parameters? n
  14697.    Repeat with new parameters? y
  14698.    Spades (low, high)? 4,8
  14699.    Hearts (low, high)? 4,8
  14700.    .
  14701.    .
  14702.    .
  14703.  
  14704.  
  14705.  ────────────────────────────────────────────────────────────────────────────
  14706.  RESUME Statement
  14707.  ────────────────────────────────────────────────────────────────────────────
  14708.  
  14709.  ■ Action
  14710.  
  14711.    Continues program execution after an error-trapping routine has been
  14712.    invoked
  14713.  
  14714.  ■ Syntax
  14715.  
  14716.    RESUME «0»
  14717.    RESUME NEXT
  14718.    RESUME  { linenumber | linelabel }
  14719.  
  14720.  ■ Remarks
  14721.  
  14722.    The different forms of the RESUME statement redirect program flow as
  14723.    described in the following list:
  14724.  
  14725. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  14726.    Statement                Where Execution Resumes
  14727.    ──────────────────────────────────────────────────────────────────────────
  14728.    RESUME «0»               At the last statement executed in the module
  14729.                             containing the error handler.
  14730.  
  14731.                             If an active error handler is found in the module
  14732.                             where the error occurs, execution resumes with
  14733.                             the statement that caused the error.
  14734.  
  14735.    RESUME NEXT              At the statement immediately following the last
  14736.                             statement executed in the module containing the
  14737.                             error handler.
  14738.  
  14739.                             If an active error handler is found in the module
  14740.                             where the error occurs, execution resumes with
  14741.                             the statement immediately following the statement
  14742.                             that caused the error.
  14743.  
  14744.    Statement                Where Execution Resumes
  14745.    ──────────────────────────────────────────────────────────────────────────
  14746. 
  14747.    RESUME linenumber        At linenumber.
  14748.  
  14749.    RESUME linelabel         At linelabel.
  14750.    ──────────────────────────────────────────────────────────────────────────
  14751.  
  14752.  
  14753.    A RESUME statement that is not in an error-handling routine produces the
  14754.    error message RESUME without error. Reaching the end of an error-handling
  14755.    routine without finding RESUME produces the error message No RESUME.
  14756.  
  14757.    The line specified in a RESUME { linenumber | linelabel } statement must
  14758.    be defined at module level. As a rule, avoid using a line number or line
  14759.    label with a RESUME statement. Omitting the line number allows your
  14760.    program to continue no matter where the error occurred.
  14761.  
  14762.  ────────────────────────────────────────────────────────────────────────────
  14763.  NOTE
  14764.    Programs containing error-handling routines must be compiled with either
  14765.    the /E (On Error) or /X (Resume Next) options when you are compiling from
  14766.    the BC command line. No options are required when compiling in the
  14767.    QuickBASIC environment, or using the Make EXE command from the QuickBASIC
  14768.    Run menu.
  14769.  ────────────────────────────────────────────────────────────────────────────
  14770.  
  14771.  ■ DIFFERENCES FROM BASICA
  14772.  
  14773.    In BASICA, if an error occurs in a DEF FN function, both RESUME and RESUME
  14774.    NEXT attempt to resume program execution at the line containing the
  14775.    function.
  14776.  
  14777.  ■ See Also
  14778.  
  14779.    ERR, ERL; ERROR; ON ERROR
  14780.  
  14781.  ■ Example
  14782.  
  14783.    This example has an error-handling routine starting at line 900. In
  14784.    BASICA, this routine would cause an error message (No negative arguments)
  14785.    to be printed for I= -1 and -2. The routine would then end. In BASIC, the
  14786.    error-handling routine prints its message when I= -1, then resumes at the
  14787.    beginning of the FOR...NEXT loop with I reset to 4, as seen below.
  14788.  
  14789.    10 ON ERROR GOTO 900
  14790.    20 DEF FNTEST(A) = 1 - SQR(A)
  14791.    30 FOR I = 4 TO -2 STEP -1
  14792.    40     PRINT I,FNTEST(I)
  14793.    50 NEXT
  14794.    60 END
  14795.  
  14796.    900 'Error-handling routine
  14797.    910     PRINT "No negative arguments"
  14798.    920 RESUME NEXT
  14799.  
  14800.  ■ Output
  14801.  
  14802.    4      -1
  14803.    3      -.7320509
  14804.    2      -.4142136
  14805.    1       0
  14806.    0       1
  14807.    -1      No negative arguments
  14808.    4      -1
  14809.    3      -.7320509
  14810.    2      -.4142136
  14811.    .
  14812.    .
  14813.    .
  14814.  
  14815.  
  14816.  ────────────────────────────────────────────────────────────────────────────
  14817.  RETURN Statement
  14818.  ────────────────────────────────────────────────────────────────────────────
  14819.  
  14820.  ■ Action
  14821.  
  14822.    Returns control from a subroutine
  14823.  
  14824.  ■ Syntax
  14825.  
  14826.    RETURN «{linenumber | linelabel }»
  14827.  
  14828.  ■ Remarks
  14829.  
  14830.    Without a line label or number, RETURN continues execution where an event
  14831.    occurred (for event handling) or at the statement following the GOSUB (for
  14832.    subroutine calls). GOSUB and RETURN without a line number can be used
  14833.    anywhere in a program, but the GOSUB and corresponding RETURN must be at
  14834.    the same level.
  14835.  
  14836.    The linenumber or linelabel in the RETURN statement causes an
  14837.    unconditional return from a GOSUB subroutine to the specified line. RETURN
  14838.    with a line label or line number can only return control to a statement in
  14839.    the module-level code.
  14840.  
  14841.    A RETURN statement cannot be used to return control to a calling program
  14842.    from a subprogram defined by SUB. Use EXIT SUB.
  14843.  
  14844.  ────────────────────────────────────────────────────────────────────────────
  14845.  NOTE
  14846.    BASIC's SUB procedures provide a more well-structured alternative to GOSUB
  14847.    subroutines.
  14848.  ────────────────────────────────────────────────────────────────────────────
  14849.  
  14850.  ■ See Also
  14851.  
  14852.    EXIT, GOSUB, ON event
  14853.  
  14854.  ■ Example
  14855.  
  14856.    See the example for the GOSUB statement.
  14857.  
  14858.  
  14859.  ────────────────────────────────────────────────────────────────────────────
  14860.  RIGHT$ Function
  14861.  ────────────────────────────────────────────────────────────────────────────
  14862.  
  14863.  ■ Action
  14864.  
  14865.    Returns the rightmost n characters of a string
  14866.  
  14867.  ■ Syntax
  14868.  
  14869.    RIGHT$(stringexpression,n)
  14870.  
  14871.  ■ Remarks
  14872.  
  14873.    The argument stringexpression can be any string variable, string constant,
  14874.    or string expression. If n is equal to the number of characters in the
  14875.    argument stringexpression, then the RIGHT$ function returns
  14876.    stringexpression. If n = 0, RIGHT$ returns the null string (length zero).
  14877.  
  14878.  ■ See Also
  14879.  
  14880.    LEFT$, MID$
  14881.  
  14882.  ■ Example
  14883.  
  14884.    This program converts names that have been input in the form "Firstname
  14885.    [Middlename] Lastname" to the form "Lastname, Firstname [Middlename]":
  14886.  
  14887.    LINE INPUT "Name: "; Nm$
  14888.    I = 1 : Sppos = 0
  14889.    DO WHILE I > 0
  14890.        I = INSTR(Sppos+1,Nm$," ")   'Get position of next space.
  14891.        IF I > 0 THEN Sppos = I
  14892.    LOOP
  14893.  
  14894.    'SPPOS now points to the position of the last space.
  14895.    IF Sppos = 0 THEN
  14896.        PRINT Nm$                    'There was just a last name.
  14897.    ELSE
  14898.        'Everything after last space.
  14899.        Lastname$ = RIGHT$(Nm$,LEN(Nm$)-Sppos)
  14900.        'Everything before last space.
  14901.        Firstname$ = LEFT$(Nm$,Sppos-1)
  14902.        PRINT Lastname$ ", " Firstname$
  14903.    END IF
  14904.    END
  14905.  
  14906.  
  14907.  ────────────────────────────────────────────────────────────────────────────
  14908.  RMDIR Statement
  14909.  ────────────────────────────────────────────────────────────────────────────
  14910.  
  14911.  ■ Action
  14912.  
  14913.    Removes an existing directory
  14914.  
  14915.  ■ Syntax
  14916.  
  14917.    RMDIR pathname
  14918.  
  14919.  ■ Remarks
  14920.  
  14921.    The pathname is the name of the directory that is to be deleted. The
  14922.    pathname must be a string of less than 128 characters. The directory to be
  14923.    removed must be empty except for the working directory ('.') and the
  14924.    parent directory ('..'); otherwise, one of two error messages is printed,
  14925.    either Path not found or Path/File access error.
  14926.  
  14927.    RMDIR works like the DOS command of the same name; the syntax in BASIC
  14928.    cannot be shortened to RD, as in DOS.
  14929.  
  14930.  ■ See Also
  14931.  
  14932.    CHDIR, MKDIR
  14933.  
  14934.  ■ Example
  14935.  
  14936.    The following example illustrates the use of the RMDIR statement:
  14937.  
  14938.    CHDIR "C:\SALES\TEMP"         'Move to \TEMP subdirectory in \SALES.
  14939.    KILL "*.*"                    'Remove all files in \TEMP.
  14940.    CHDIR ".."                    'Move back up to \SALES.
  14941.    RMDIR "TEMP"                  'Remove \TEMP subdirectory.
  14942.  
  14943.  
  14944.  ────────────────────────────────────────────────────────────────────────────
  14945.  RND Function
  14946.  ────────────────────────────────────────────────────────────────────────────
  14947.  
  14948.  ■ Action
  14949.  
  14950.    Returns a single-precision random number between 0 and 1
  14951.  
  14952.  ■ Syntax
  14953.  
  14954.    RND«(n)»
  14955.  
  14956.  ■ Remarks
  14957.  
  14958.    The value of n determines how RND generates the next random number:
  14959.  
  14960.    Argument                 Number Returned
  14961.    ──────────────────────────────────────────────────────────────────────────
  14962.    n < 0                    Always returns the same number for any given n
  14963.  
  14964.    n > 0 or n omitted       Returns the next random number in the sequence
  14965.  
  14966.    n = 0                    Returns the last number generated
  14967.    ──────────────────────────────────────────────────────────────────────────
  14968.  
  14969.    Even if n>0, the same sequence of random numbers is generated each time
  14970.    the program is run unless you initialize the random-number generator each
  14971.    time you run the program. (See the RANDOMIZE statement entry for more
  14972.    information about initializing the random-number generator.)
  14973.  
  14974.    To produce random integers in a given range, use the formula
  14975.  
  14976.    INT ((upperbound - lowerbound + 1)*RND + lowerbound)
  14977.  
  14978.    where upperbound is the highest number in the range, and lowerbound is the
  14979.    lowest number in the range.
  14980.  
  14981.  ■ Example
  14982.  
  14983.    See the examples for the RANDOMIZE and TYPE statements.
  14984.  
  14985.  
  14986.  ────────────────────────────────────────────────────────────────────────────
  14987.  RSET Statement
  14988.  ────────────────────────────────────────────────────────────────────────────
  14989.  
  14990.  ■ Action
  14991.  
  14992.    Moves data from memory to a random-access file buffer (in preparation for
  14993.    a PUT statement) or right-justifies the value of a string in a string
  14994.    variable
  14995.  
  14996.  ■ Syntax
  14997.  
  14998.    RSET stringvariable=stringexpression
  14999.  
  15000.  ■ Remarks
  15001.  
  15002.    The stringvariable is usually a random-access file field defined in a
  15003.    FIELD statement, although it can be any string variable. The
  15004.    stringexpression is the value assigned to the variable.
  15005.  
  15006.    If stringexpression requires fewer bytes than were defined for
  15007.    stringvariable in the FIELD statement, the RSET statement right-justifies
  15008.    the string in the field (LSET left-justifies the string). Spaces are used
  15009.    to pad the extra positions. If the string is too long for the field, both
  15010.    LSET and RSET truncate characters from the right. Numeric values must be
  15011.    converted to strings before they are justified with the RSET or LSET
  15012.    statements.
  15013.  
  15014.    The RSET statement can be used with string variables unrelated to FIELD
  15015.    statements. When used with a fixed-length string variable, the value is
  15016.    right-justified and left-padded with blanks.
  15017.  
  15018.    When RSET is used with a variable-length string, the string is treated as
  15019.    a fixed field. The length of the field is the length of the value the
  15020.    variable had before the RSET statement. See the example below.
  15021.  
  15022.  ■ See Also
  15023.  
  15024.    FIELD; LSET; MKD$, MKI$, MKL$, MKS$; PUT
  15025.  
  15026.  ■ Example
  15027.  
  15028.    The following example shows the effects of using RSET to assign values to
  15029.    fixed- and variable-length strings:
  15030.  
  15031.    DIM TmpStr2 AS STRING * 10
  15032.    PRINT "         1         2         3"
  15033.    PRINT "123456789012345678901234567890"
  15034.    ' Use RSET on null variable-length string of length.
  15035.    ' Nothing prints because TmpStr$ is a zero-length field.
  15036.    TmpStr$ = ""
  15037.    RSET TmpStr$ = "Another"
  15038.    PRINT TmpStr$
  15039.    ' Use RSET on variable-length string with a value.
  15040.    TmpStr$ = SPACE$(20)
  15041.    RSET TmpStr$ = "Another"
  15042.    PRINT TmpStr$
  15043.  
  15044.    ' Use RSET on fixed-length string of length 10.
  15045.    RSET TmpStr2 = "Another"
  15046.    PRINT TmpStr2
  15047.  
  15048.  ■ Output
  15049.  
  15050.    1         2         3
  15051.    123456789012345678901234567890
  15052.  
  15053.                 Another
  15054.       Another
  15055.  
  15056.  
  15057.  ────────────────────────────────────────────────────────────────────────────
  15058.  RTRIM$ Function
  15059.  ────────────────────────────────────────────────────────────────────────────
  15060.  
  15061.  ■ Action
  15062.  
  15063.    Returns a string with trailing (right-hand) spaces removed
  15064.  
  15065.  ■ Syntax
  15066.  
  15067.    RTRIM$(stringexpression)
  15068.  
  15069.  ■ Remarks
  15070.  
  15071.    The stringexpression can be any string expression. The RTRIM$ function
  15072.    works with both fixed- and variable-length string variables.
  15073.  
  15074.  ■ See Also
  15075.  
  15076.    LTRIM$
  15077.  
  15078.  ■ Example
  15079.  
  15080.    The example shows the effects of the RTRIM$ function on fixed- and
  15081.    variable-length strings. See also the example for the LTRIM$ function.
  15082.  
  15083.    DIM FixStr AS STRING * 10
  15084.    PRINT "         1         2"
  15085.    PRINT "12345678901234567890"
  15086.    FixStr = "Twine"
  15087.    PRINT FixStr + "*"
  15088.    PRINT RTRIM$(FixStr) + "*"
  15089.    VarStr$ = "Braided" + SPACE$(10)
  15090.    PRINT VarStr$ + "*"
  15091.    PRINT RTRIM$(VarStr$) + "*"
  15092.  
  15093.  ■ Output
  15094.  
  15095.    1         2
  15096.    12345678901234567890
  15097.    Twine     *
  15098.    Twine*
  15099.    Braided          *
  15100.    Braided*
  15101.  
  15102.  
  15103.  ────────────────────────────────────────────────────────────────────────────
  15104.  RUN Statement
  15105.  ────────────────────────────────────────────────────────────────────────────
  15106.  
  15107.  ■ Action
  15108.  
  15109.    Restarts the program currently in memory or executes a specified program
  15110.  
  15111.  ■ Syntax
  15112.  
  15113.    RUN «{ linenumber | filespec }»
  15114.  
  15115.  ■ Remarks
  15116.  
  15117.    The RUN statement accepts the following arguments:
  15118.  
  15119.    Argument                 Description
  15120.    ──────────────────────────────────────────────────────────────────────────
  15121.    linenumber               The numeric label of the line where execution
  15122.                             begins. If no argument is given, execution begins
  15123.                             at the first executable line of code.
  15124.  
  15125.    filespec                 A string expression naming the program file to
  15126.                             load and run. The current program is cleared from
  15127.                             memory before the specified program is loaded.
  15128.    ──────────────────────────────────────────────────────────────────────────
  15129.  
  15130.    The line where execution begins must be in the module-level code.
  15131.    Therefore, a RUN statement in a SUB or FUNCTION procedure must point to
  15132.    labels at module level. If no line label is given, execution always starts
  15133.    with the first executable line of the program's main module.
  15134.  
  15135.    During compilation, if linenumber cannot be found in the module-level
  15136.    code, compilation halts and the error message Label not defined appears.
  15137.  
  15138.    Program lines can have line numbers or alphanumeric labels, such as
  15139.    OpenWindow:. If an alphanumeric label is the target of a RUN statement,
  15140.    execution halts, and the error message Type mismatch appears. Note that
  15141.    the QuickBASIC syntax checker does not warn you if you give the RUN
  15142.    statement an alphanumeric label instead of a line number.
  15143.  
  15144.    You do not need to specify the file name extension in filespec. The .BAS
  15145.    extension is assumed in the QuickBASIC environment, and the .EXE extension
  15146.    is assumed when running compiled, stand-alone programs. If the program you
  15147.    wish to run has a different extension, you must give the extension. If the
  15148.    program name has no extension, the file name given must end with a period.
  15149.  
  15150.    For example,
  15151.  
  15152.    RUN "CATCHALL"
  15153.  
  15154.    would execute CATCHALL.EXE from a BC-compiled program, and CATCHALL.BAS
  15155.    from within QuickBASIC.
  15156.  
  15157.    Programs running within the QuickBASIC environment must call only
  15158.    QuickBASIC program files. The file is loaded and run as if it were a
  15159.    QuickBASIC program; if it is not in the QuickBASIC program format,
  15160.    execution halts. The error message that appears varies, depending on the
  15161.    file's contents. Likewise, programs compiled with BC must not invoke
  15162.    QuickBASIC source files, as these run only within the QuickBASIC
  15163.    environment.
  15164.  
  15165.    An executable file need not have been written in QuickBASIC. Any
  15166.    executable file may be run.
  15167.  
  15168.    When running a program under QuickBASIC, if an executable file matching
  15169.    the file name in filespec cannot be found, the error message File not
  15170.    found appears, and control returns to QuickBASIC. When running a program
  15171.    compiled by BC, the error message File not found in module programname
  15172.    appears, and control returns to DOS.
  15173.  
  15174.    When the invoked program completes execution, control does not return to
  15175.    the invoking program. If the invoking program ran outside QuickBASIC,
  15176.    control returns to DOS. If the invoking program ran under QuickBASIC,
  15177.    control returns to QuickBASIC.
  15178.  
  15179.    If you edit a QuickBASIC program containing a RUN statement, then run the
  15180.    program before saving the changes, QuickBASIC asks if you wish to save the
  15181.    new version of the program before RUN clears it from memory.
  15182.  
  15183.    RUN closes all files and clears program memory before loading the
  15184.    designated program.The BC compiler does not support the R option from
  15185.    BASICA. (This option keeps all open data files open.) If you want to run a
  15186.    different program, but leave open files open, use the CHAIN statement.
  15187.  
  15188.  ■ See Also
  15189.  
  15190.    CHAIN
  15191.  
  15192.  ■ Examples
  15193.  
  15194.    The following example shows how RUN linenumber resets all numeric
  15195.    variables to 0. As the line number following RUN increases in lines 60,
  15196.    70, 80, and 90, the variables in the earlier statements lose their
  15197.    assigned values.
  15198.  
  15199.    10 A = 9
  15200.    20 B = 7
  15201.    30 C = 5
  15202.    40 D = 4
  15203.    50 PRINT A,B,C,D
  15204.    60 IF A = 0 THEN 70 ELSE RUN 20
  15205.    70 IF B = 0 THEN 80 ELSE RUN 30
  15206.    80 IF C = 0 THEN 90 ELSE RUN 40
  15207.    90 IF D = 0 THEN END ELSE RUN 50
  15208.  
  15209.  ■ Output
  15210.  
  15211.    9   7   5   4
  15212.    0   7   5   4
  15213.    0   0   5   4
  15214.    0   0   0   4
  15215.    0   0   0   0
  15216.  
  15217.  
  15218.  ────────────────────────────────────────────────────────────────────────────
  15219.  SADD Function
  15220.  ────────────────────────────────────────────────────────────────────────────
  15221.  
  15222.  ■ Action
  15223.  
  15224.    Returns the address of the specified string expression
  15225.  
  15226.  ■ Syntax
  15227.  
  15228.    SADD(stringvariable)
  15229.  
  15230.  ■ Remarks
  15231.  
  15232.    The SADD function returns the address of a string as an offset (near
  15233.    pointer) from the current data segment. The offset is a two-byte integer.
  15234.    SADD is most often used in mixed-language programming.
  15235.  
  15236.    The argument may be a simple string variable or a single element of a
  15237.    string array. You may not use fixed-length string arguments.
  15238.  
  15239.    Use this function with care because strings can move in the BASIC string
  15240.    space (storage area) at any time. SADD works only with string variables
  15241.    stored in DGROUP.
  15242.  
  15243.  ────────────────────────────────────────────────────────────────────────────
  15244.  NOTE
  15245.    Do not add characters to the beginning or end of a string passed using
  15246.    SADD and LEN. Adding characters may produce a run-time error.
  15247.  ────────────────────────────────────────────────────────────────────────────
  15248.  
  15249.  ■ See Also
  15250.  
  15251.    CALL, CALLS (Non-BASIC); DECLARE (Non-BASIC); FRE; PEEK; POKE;
  15252.    VARPTR; VARPTR$; VARSEG
  15253.  
  15254.  ■ Example
  15255.  
  15256.    The following example uses SADD and LEN to pass a string to a function
  15257.    written in C. The C function returns the ASCII value of a character at a
  15258.    given position in the string. The C program would be separately compiled
  15259.    and stored in a Quick library or explicitly linked to form an .EXE file.
  15260.    Note that BYVAL is the default for C.
  15261.  
  15262.    ' Pass a string to a C function using SADD and LEN.
  15263.    DEFINT A-Z
  15264.    ' Declare the function;
  15265.    DECLARE FUNCTION MyAsc CDECL (BYVAL A%, BYVAL B%, BYVAL C%)
  15266.  
  15267.    A$="abcdefghijklmnopqrstuvwxyz"
  15268.    PRINT "Enter a character position (1-26). Enter 0 to Quit."
  15269.    DO
  15270.  
  15271.    ' Get a character position.
  15272.       INPUT N
  15273.    ' End if the position is less than zero.
  15274.       IF N<=0 THEN EXIT DO
  15275.    ' Call C function; the function returns the ASCII code of the
  15276.    ' character at position N in A$.
  15277.       AscValue=MyAsc(SADD(A$),LEN(A$),N)
  15278.       PRINT "ASCII value: ";AscValue;"Character: ";CHR$(AscValue)
  15279.  
  15280.    LOOP
  15281.    END
  15282.  
  15283.    /* C function to return the ASCII value of the character
  15284.       at position pos in string c of length len.          */
  15285.  
  15286.    int far myasc(c,len,pos)
  15287.    char near *c;
  15288.    int len, pos;
  15289.    {
  15290.  
  15291.       if(pos>len) return(c[--len]);/* Avoid indexing off end. */
  15292.       else if (pos<1) return(c[0]);/* Avoid indexing off start. */
  15293.       else
  15294.          return(c[--pos]);/* pos is good. Return the character at
  15295.                              pos-1 because C arrays (strings) are
  15296.                              zero-indexed. */
  15297.    }
  15298.  
  15299.  ■ Output
  15300.  
  15301.    Enter a character position (1-26). Enter -1 to Quit.
  15302.    ? 24
  15303.    ASCII value:  120 Character: x
  15304.    ? -1
  15305.  
  15306.  
  15307.  ────────────────────────────────────────────────────────────────────────────
  15308.  SCREEN Function
  15309.  ────────────────────────────────────────────────────────────────────────────
  15310.  
  15311.  ■ Action
  15312.  
  15313.    Reads a character's ASCII value or its color from a specified screen
  15314.    location
  15315.  
  15316.  ■ Syntax
  15317.  
  15318.    SCREEN(row,column«,colorflag»)
  15319.  
  15320.  ■ Remarks
  15321.  
  15322.    The following list describes the SCREEN function's arguments:
  15323.  
  15324.    Argument                 Description
  15325.    ──────────────────────────────────────────────────────────────────────────
  15326.    row                      The row number of the screen location. The row is
  15327.                             a numeric expression that evaluates to an
  15328.                             unsigned integer.
  15329.  
  15330.    column                   The column number of the screen location. The
  15331.                             column is a numeric expression that evaluates to
  15332.                             an unsigned integer.
  15333.  
  15334.    colorflag                A numeric expression. When colorflag is nonzero,
  15335.                             SCREEN returns the number of the color at the
  15336.                             screen location. If the colorflag is zero or
  15337.                             absent, the ASCII code of the character at the
  15338.                             location is returned as an integer.
  15339.    ──────────────────────────────────────────────────────────────────────────
  15340.  
  15341.  ■ Examples
  15342.  
  15343.    If the character at (10,10) in the following examples is A, then the
  15344.    function would return 65, the ASCII code for A:
  15345.  
  15346.    X=SCREEN(10,10)
  15347.  
  15348.    The following example returns the color attribute of the character in the
  15349.    upper-left corner of the screen:
  15350.  
  15351.    X=SCREEN(1,1,1)
  15352.  
  15353.  
  15354.  ────────────────────────────────────────────────────────────────────────────
  15355.  SCREEN Statement
  15356.  ────────────────────────────────────────────────────────────────────────────
  15357.  
  15358.  ■ Action
  15359.  
  15360.    Sets the specifications for the display screen
  15361.  
  15362.  ■ Syntax
  15363.  
  15364.    SCREEN «mode» «,«colorswitch»
  15365.    »«,«apage» »«,«vpage»»
  15366.  
  15367.  ■ Remarks
  15368.  
  15369.    The SCREEN statement selects a screen mode appropriate for a particular
  15370.    combination of display and adapter. Later sections describe the available
  15371.    modes for specific adapters. The following list describes the arguments of
  15372.    the SCREEN statement:
  15373.  
  15374. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  15375.    Argument                 Description
  15376.    ──────────────────────────────────────────────────────────────────────────
  15377.    mode                     An integer constant or expression indicating the
  15378.                             screen mode. The valid modes are described below
  15379.                             for each of the supported adapters.
  15380.  
  15381.    colorswitch              Determines whether color is displayed on
  15382.                             composite monitors. The colorswitch is a numeric
  15383.                             expression in the range 0-255. When it is true
  15384.                             (nonzero), color is disabled and only
  15385.                             black-and-white images are displayed. When
  15386.                             colorswitch is false (zero), images are in color.
  15387.                             The colorswitch argument's meaning is inverted in
  15388.                             screen mode 0. In screen modes 2 and up,
  15389.                             colorswitch is ignored.
  15390.  
  15391.    apage                    A numeric expression that is the number of the
  15392.                             screen page that text output or graphics commands
  15393.                             write to. Tables below indicate valid values for
  15394.                             apage with various adapters.
  15395.    Argument                 Description
  15396.    ──────────────────────────────────────────────────────────────────────────
  15397.                            apage with various adapters.
  15398.  
  15399.    vpage                    A numeric expression that is the number of the
  15400.                             screen page being displayed. Tables below
  15401.                             indicate valid values for vpage with various
  15402.                             adapters.
  15403.    ──────────────────────────────────────────────────────────────────────────
  15404.  
  15405.  
  15406.    The next two subsections summarize the screen modes and discuss the modes
  15407.    available with specific combinations of adapters and displays. The final
  15408.    subsection summarizes attributes and colors.
  15409.  
  15410.    SUMMARY OF SCREEN MODES
  15411.  
  15412.    The following paragraphs briefly summarize each of the screen modes. The
  15413.    color adapters referred to are the IBM Color Graphics Adapter (CGA), the
  15414.    IBM Enhanced Graphics Adapter (EGA), the IBM Video Graphics Array (VGA)
  15415.    and the IBM Multicolor Graphics Array (MCGA). The Hercules(R) Graphics
  15416.    Card, Graphics Card Plus and InColor(R) adapters are supported, but only
  15417.    with monochrome monitors. The next subsection supplies detailed
  15418.    information about the effects of a screen mode when used with a specific
  15419.    combination of display and adapter.
  15420.  
  15421.  ────────────────────────────────────────────────────────────────────────────
  15422.  NOTE
  15423.    Many screen modes support more than one combination of rows and columns on
  15424.    the screen. See the entry for the WIDTH statement for more information
  15425.    about changing the number of rows and columns on the display.
  15426.  ────────────────────────────────────────────────────────────────────────────
  15427.  
  15428.    Screen 0
  15429.  
  15430.    ■ Text mode only
  15431.  
  15432.    ■ Either 40 x 25, 40 x 43, 40 x 50, 80 x 25, 80 x 43, or 80 x 50 text
  15433.      format with character-box size of 8 x 8 (8 x 14, 9 x 14, or 9 x 16 with
  15434.      EGA or VGA)
  15435.  
  15436.    ■ Assignment of 16 colors to 2 attributes
  15437.  
  15438.    ■ Assignment of 16 colors to any of 16 attributes (with CGA or EGA)
  15439.  
  15440.    ■ Assignment of 64 colors to any of 16 attributes (with EGA or VGA)
  15441.  
  15442.    Screen 1
  15443.  
  15444.    ■ 320 x 200 pixel medium-resolution graphics
  15445.  
  15446.    ■ 40 x 25 text format with character-box size of 8 x 8
  15447.  
  15448.    ■ Assignment of 16 colors to 4 attributes with EGA or VGA
  15449.  
  15450.    ■ Supports CGA, EGA, VGA, and MCGA
  15451.  
  15452.    Screen 2
  15453.  
  15454.    ■ 640 x 200 pixel high-resolution graphics
  15455.  
  15456.    ■ 80 x 25 text format with character-box size of 8 x 8
  15457.  
  15458.    ■ Assignment of 16 colors to 2 attributes with EGA or VGA
  15459.  
  15460.    ■ Supports CGA, EGA, VGA, and MCGA Screen 3
  15461.  
  15462.    ■ Hercules adapter required
  15463.  
  15464.    ■ Monochrome monitor only
  15465.  
  15466.    ■ 720 x 348 pixel resolution, monochrome
  15467.  
  15468.    ■ 80 x 25 text format with character-box size of 9 x 14; bottom two scan
  15469.      lines of 25th row not visible
  15470.  
  15471.    ■ Two screen pages (one only if a second display adapter is installed)
  15472.  
  15473.    ■ PALETTE statement not supported
  15474.  
  15475.  ────────────────────────────────────────────────────────────────────────────
  15476.  NOTE
  15477.    The Hercules driver (MSHERC.COM) must be loaded for the Hercules card to
  15478.    function. This file is supplied with QuickBASIC. Type MSHERC before
  15479.    running QuickBASIC. If a compatible color adapter is also installed (eg,
  15480.    CGA), type MSHERC /H instead. This limits the Hercules card to one screen
  15481.    page but permits normal operation of the color adapter. If the Hercules
  15482.    driver is not loaded, the Hercules card operates like an IBM Monochrome
  15483.    Display Adapter (MDA).
  15484.  ────────────────────────────────────────────────────────────────────────────
  15485.  
  15486.    Screen 4
  15487.  
  15488.    ■ 640 x 400 pixel high-resolution graphics
  15489.  
  15490.    ■ 80 x 25 text format with character-box size of 8 x 16
  15491.  
  15492.    ■ Assignment of 1 of 16 colors as the foreground color (selected by the
  15493.      COLOR statement); background fixed at black
  15494.  
  15495.    ■ Supports Olivetti(R) Personal Computers, models M24, M240, M28, M280,
  15496.      M380, M380/C, and M380/T, and AT&T(R) Personal Computers 6300 series
  15497.  
  15498.  ────────────────────────────────────────────────────────────────────────────
  15499.  WARNING
  15500.    Olivetti personal computers running in DOS-compatibility mode under
  15501.    Microsoft Operating System/2 should avoid this screen mode.
  15502.  ────────────────────────────────────────────────────────────────────────────
  15503.  
  15504.    Screen 7
  15505.  
  15506.    ■ 320 x 200 pixel medium-resolution graphics
  15507.  
  15508.    ■ 40 x 25 text format with character-box size of 8 x 8
  15509.  
  15510.    ■ Multiple screen pages
  15511.  
  15512.    ■ Assignment of 16 colors to any of 16 attributes
  15513.  
  15514.    ■ EGA or VGA required
  15515.  
  15516.    Screen 8
  15517.  
  15518.    ■ 640 x 200 pixel high-resolution graphics
  15519.  
  15520.    ■ 80 x 25 text format with character-box size of 8 x 8
  15521.  
  15522.    ■ Multiple screen pages
  15523.  
  15524.    ■ Assignment of 16 colors to any of 16 attributes
  15525.  
  15526.    ■ EGA or VGA required
  15527.  
  15528.    Screen 9
  15529.  
  15530.    ■ 640 x 350 pixel enhanced-resolution graphics
  15531.  
  15532.    ■ 80 x 25 or 80 x 43 text format with character-box size of 8 x 14 or 8 x
  15533.      8
  15534.  
  15535.    ■ Assignment of either 64 colors to 16 attributes (more than 64K of EGA or
  15536.      VGA memory) or 16 colors to 4 attributes (64K of EGA or VGA memory)
  15537.  
  15538.    ■ Multiple screen pages
  15539.  
  15540.    ■ EGA or VGA required
  15541.  
  15542.    Screen 10
  15543.  
  15544.    ■ Monochrome only
  15545.  
  15546.    ■ 640 x 350 pixel enhanced-resolution graphics
  15547.  
  15548.    ■ 80 x 25 or 80 x 43 text format with character-box size of 8 x 14 or 8 x
  15549.      8
  15550.  
  15551.    ■ Multiple screen pages
  15552.  
  15553.    ■ Assignment of up to nine pseudocolors to 4 attributes (refer to Tables
  15554.      R.9 and R.10 in the next section)
  15555.  
  15556.    ■ EGA or VGA required
  15557.  
  15558.    Screen 11
  15559.  
  15560.    ■ 640 x 480 pixel very high-resolution graphics
  15561.  
  15562.    ■ 80 x 30 or 80 x 60 text format with character-box size of 8 x 16 or 8 x
  15563.      8
  15564.  
  15565.    ■ Assignment of up to 256K colors to 2 attributes
  15566.  
  15567.    ■ VGA or MCGA required
  15568.  
  15569.    Screen 12
  15570.  
  15571.    ■ 640 x 480 pixel very-high-resolution graphics
  15572.  
  15573.    ■ 80 x 30 or 80 x 60 text format with character-box size of 8 x 16 or 8 x
  15574.      8
  15575.  
  15576.    ■ Assignment of up to 256K colors to 16 attributes
  15577.  
  15578.    ■ VGA required
  15579.  
  15580.    Screen 13
  15581.  
  15582.    ■ 320 x 200 pixel medium-resolution graphics
  15583.  
  15584.    ■ 40 x 25 text format with character-box size of 8 x 8
  15585.  
  15586.    ■ Assignment of up to 256K colors to up to 256 attributes
  15587.  
  15588.    ■ VGA or MCGA required
  15589.  
  15590.    SCREEN MODES, ADAPTERS, AND DISPLAYS
  15591.  
  15592.    This section describes the screen modes for specific combinations of
  15593.    adapters and displays. The IBM Monochrome Display and Printer Adapter
  15594.    (MDPA) can be used only with a monochrome display. Only screen mode 0,
  15595.    text mode, can be used with the MDPA. Table R.6 summarizes the effect of
  15596.    using screen mode 0 with an MDPA.
  15597.  
  15598.    Table R.6   MDPA Screen Modes
  15599.  
  15600.    Screen      Rows and
  15601.    Mode        Columns      Attributes  Colors      Resolution   Pages
  15602.    ──────────────────────────────────────────────────────────────────────────
  15603.    0           80x25        16          3           720x350      1
  15604.    ──────────────────────────────────────────────────────────────────────────
  15605.  
  15606.    Table R.7 summarizes the screen modes available with Hercules adapters.
  15607.  
  15608.    Table R.7   Hercules Screen Modes
  15609.  
  15610.    Screen      Rows and
  15611.    Mode        Columns      Attributes  Colors      Resolution   Pages
  15612.    ──────────────────────────────────────────────────────────────────────────
  15613.    0           80x25        16          1           720x348      2
  15614.    3           80x25        16          1           720x348      2
  15615.    ──────────────────────────────────────────────────────────────────────────
  15616.  
  15617.    The IBM Color Graphics Adapter (CGA) and Color Display are typically
  15618.    paired. This combination permits running text-mode programs and both
  15619.    medium-resolution and high-resolution graphics programs.
  15620.  
  15621.    Table R.8 summarizes the screen modes available with the CGA.
  15622.  
  15623.    Table R.8   CGA Screen Modes
  15624.  
  15625.    Screen         Rows and
  15626.    Mode           Columns        Colors        Resolution     Pages
  15627.    ──────────────────────────────────────────────────────────────────────────
  15628.    0              40x25          16            320x200        8
  15629.                   80x25          16            640x200        4
  15630.    1              40x25          4             320x200        1
  15631.    2              80x25          2             640x200        1
  15632.    ──────────────────────────────────────────────────────────────────────────
  15633.  
  15634.    The IBM Enhanced Graphics Adapter (EGA) may be used with either the IBM
  15635.    Color Display or the Enhanced Color Display. In screen modes 0, 1, 2, 7,
  15636.    and 8, these pairings produce similar results, except for the following
  15637.    possible differences:
  15638.  
  15639.    1. The border color cannot be set on an Enhanced Color Display when it is
  15640.       in 640 x 350 text mode.
  15641.  
  15642.    2. The text quality is better on the Enhanced Color Display (an 8 x 14
  15643.       character box for Enhanced Color Display versus an 8 x 8 character box
  15644.       for Color Display).
  15645.  
  15646.    Screen mode 9 takes full advantage of the capabilities of the Enhanced
  15647.    Color Display and provides for the highest resolution possible for the
  15648.    EGA/Enhanced Color Display configuration. Programs written for this mode
  15649.    will not work for any other hardware configuration except the VGA. Table
  15650.    R.9 summarizes the screen modes that can be used with an EGA.
  15651.  
  15652.    Table R.9   EGA Screen Modes
  15653.  
  15654. ╓┌─┌───────┌─────────┌────────┌──────────┌───────┌──────────┌─────────┌──────╖
  15655.    Screen  Rows and                                         Page
  15656.    Mode    Columns   Display  Attributes Colors  Resolution Size      Pages
  15657.                      
  15658.    ──────────────────────────────────────────────────────────────────────────
  15659.    0       40x25     C        16         16      320x200    N/A       8
  15660.            40x25     E        16         64      320x350    N/A       8
  15661.            40x43     E        16         64      320x350    N/A       8
  15662.            80x25     C        16         16      640x200    N/A       8
  15663.            80x25     E        16         64      640x350    N/A       8
  15664.            80x25     C        16         16      640x200    N/A       8
  15665.            80x25     M        16         3       720x350    N/A       8
  15666.            80x43     E        16         64      640x350    N/A       4
  15667.            80x43     M        16         3       720x350    N/A       4
  15668.    Screen  Rows and                                         Page
  15669.    Mode    Columns   Display  Attributes Colors  Resolution Size      Pages
  15670.                      
  15671.    ──────────────────────────────────────────────────────────────────────────
  15672.           80x43     M        16         3       720x350    N/A       4
  15673.    1       40x25     N/A      4          16      320x200    16K       1
  15674.    2       80x25     N/A      2          16      640x200    16K       1
  15675.    7       40x25     N/A      16         16      320x200    32K       
  15676.    8       80x25     N/A      16         16      640x200    64K       
  15677.    9      80x25     E        4          64      640x350    64K       1
  15678.            80x43     E        4          64      640x350    64K       1
  15679.            80x25     E        16         64      640x350    128K      
  15680.            80x43     E        16         64      640x350    128K      
  15681.    10      80x25     M        4          9       640x350    64K       
  15682.            80x43     M        4          9       640x350    64K       
  15683.    ──────────────────────────────────────────────────────────────────────────
  15684.  
  15685.  
  15686.    Only the EGA and VGA can be paired with the IBM Monochrome Display to run
  15687.    programs in screen mode 10. This mode can be used to display monochrome
  15688.    graphics at a very high resolution.
  15689.  
  15690.    The following two tables summarize the default attributes and colors for
  15691.    screen mode 10 used with a monochrome display.
  15692.  
  15693.    Table R.10   Default Attributes: Screen Mode 10, Monochrome Display
  15694.  
  15695.    Attribute                Displayed
  15696.    Value                    Pseudocolor
  15697.    ──────────────────────────────────────────────────────────────────────────
  15698.    0                        Off
  15699.    1                        On, normal intensity
  15700.    2                        Blink
  15701.    3                        On, high intensity
  15702.    ──────────────────────────────────────────────────────────────────────────
  15703.  
  15704.    Table R.11   Color Values: Screen Mode 10, Monochrome Display
  15705.  
  15706.    Color                    Displayed
  15707.    Value                    Pseudocolor
  15708.    ──────────────────────────────────────────────────────────────────────────
  15709.    0                        Off
  15710.    1                        Blink, off to on
  15711.    2                        Blink, off to high intensity
  15712.    3                        Blink, on to off
  15713.    4                        On
  15714.    5                        Blink, on to high intensity
  15715.    6                        Blink, high intensity to off
  15716.    7                        Blink, high intensity to on
  15717.    8                        High intensity
  15718.    ──────────────────────────────────────────────────────────────────────────
  15719.  
  15720.    The IBM Video Graphics Array (VGA) adapter offers significantly enhanced
  15721.    text and graphics in all screen modes. Table R.12 summarizes the modes
  15722.    available with the VGA.
  15723.  
  15724.    Table R.12   VGA Screen Modes
  15725.  
  15726. ╓┌─┌──────────┌─────────┌──────────┌─────────┌──────────┌─────────┌──────────╖
  15727.               Rows and                                  Page
  15728.    Mode       Columns   Attributes Colors    Resolution Size      Pages
  15729.    ──────────────────────────────────────────────────────────────────────────
  15730.    0          40x25     16         64        360x400    N/A       8
  15731.               Rows and                                  Page
  15732.    Mode       Columns   Attributes Colors    Resolution Size      Pages
  15733.    ──────────────────────────────────────────────────────────────────────────
  15734.    0          40x25     16         64        360x400    N/A       8
  15735.               40x43     16         64        320x350    N/A       8
  15736.               40x50     16         64        320x400    N/A       4
  15737.               80x25     16         64        720x400    N/A       8
  15738.               80x43     16         64        640x350    N/A       4
  15739.               80x43     16         3         720x350    N/A       4
  15740.               80x50     16         64        640x400    N/A       4
  15741.               80x50     16         3         720x400    N/A       4
  15742.    1          40x25     4          16        320x200    16K       1
  15743.    2          80x25     2          16        640x200    16K       1
  15744.    7          40x25     16         16        320x200    32K       
  15745.    8          80x25     16         16        640x200    64K       
  15746.    9          80x25     16         64        640x350    128K      
  15747.               80x43     16         64        640x350    128K      
  15748.    10         80x25     4          9         640x350    64K       
  15749.               80x43     4          9         640x350    64K       
  15750.    11         80x30     2          256K      640x480    64K       1
  15751.               80x60     2          256K      640x480    64K       1
  15752.               Rows and                                  Page
  15753.    Mode       Columns   Attributes Colors    Resolution Size      Pages
  15754.    ──────────────────────────────────────────────────────────────────────────
  15755.              80x60     2          256K      640x480    64K       1
  15756.    12         80x30     16         256K      640x480    256K      1
  15757.               80x60     16         256K      640x480    256K      1
  15758.    13         40x25     256        256K      320x200    64K       1
  15759.    ──────────────────────────────────────────────────────────────────────────
  15760.  
  15761.  
  15762.    See the PALETTE statement for a description of how the VGA calculates
  15763.    color values.
  15764.  
  15765.    The IBM Multicolor Graphics Array (MCGA) combines the modes of the CGA
  15766.    with the very high resolution and 256K color modes of the VGA to provide
  15767.    enhanced text and graphics in all modes. Table R.13 summarizes the modes
  15768.    supported by the MCGA.
  15769.  
  15770.    Table R.13   MCGA Screen Modes
  15771.  
  15772.               Rows and                                  Page
  15773.    Mode       Columns   Attributes Colors    Resolution Size      Pages
  15774.    ──────────────────────────────────────────────────────────────────────────
  15775.    0          40x25     16         N/A       320x400    N/A       8
  15776.               80x25     16         N/A       640x400    N/A       8
  15777.    1          40x25     4          N/A       320x200    16K       1
  15778.    2          80x25     2          N/A       640x200    16K       1
  15779.    11         80x30     2          256K      640x480    64K       1
  15780.               80x60     2          256K      640x480    64K       1
  15781.    13         40x25     256        256K      320x200    64K       1
  15782.    ──────────────────────────────────────────────────────────────────────────
  15783.  
  15784.    The MCGA uses the same color values as the VGA. See the PALETTE statement
  15785.    for a description of how the MCGA calculates color values.
  15786.  
  15787.    ATTRIBUTES AND COLORS
  15788.  
  15789.    For various screen modes and display hardware configurations, different
  15790.    attribute and color settings exist. (See the PALETTE statement for a
  15791.    discussion of attribute and color number.) The majority of these attribute
  15792.    and color configurations are summarized in Tables R.14-R.16.
  15793.  
  15794.    Table R.14   Default Attributes and Colors for Screen Modes 1 and 9
  15795.  
  15796.    Attributes   Color Display                  Monochrome Display
  15797.                 Number        Color           Number       Color
  15798.    ──────────────────────────────────────────────────────────────────────────
  15799.    0            0              Black           0             Off
  15800.    1            11             Light cyan      2             High intensity
  15801.    2            13             Light magenta   2             High intensity
  15802.    3            15             High-intensity  0             Off
  15803.                                white
  15804.    ──────────────────────────────────────────────────────────────────────────
  15805.  
  15806.    Table R.15   Default Attributes and Colors for Screen Modes 2 and 11
  15807.  
  15808.    Attributes   Color Display                  Monochrome Display
  15809.                 Number        Color           NumberColor
  15810.    ──────────────────────────────────────────────────────────────────────────
  15811.    0            0              Black           0             Off
  15812.    1            15             High-intensity  0             Off
  15813.                                white
  15814.    ──────────────────────────────────────────────────────────────────────────
  15815.  
  15816.    Table R.16   Default Attributes and Colors for Screen Modes 0, 7, 8, 9,
  15817.    12, and 13
  15818.  
  15819. ╓┌─┌──────────────┌────────────┌───────────────┌─────────────┌───────────────╖
  15820.    Attributes     Color Display                Monochrome Display
  15821.                   Number      Color           Number       Color
  15822.    ──────────────────────────────────────────────────────────────────────────
  15823.    0              0            Black           0             Off
  15824.    1              1            Blue                          Underlined
  15825.    2              2            Green           1             On
  15826.    3              3            Cyan            1             On
  15827.    4              4            Red             1             On
  15828.    5              5            Magenta         1             On
  15829.    6              6            Brown           1             On
  15830.    7              7            White           1             On
  15831.    8              8            Gray            0             Off
  15832.    9              9            Light blue                    High intensity
  15833.                                                              Underlined
  15834.    10             10           Light green     2             High intensity
  15835.    11             11           Light cyan      2             High intensity
  15836.    Attributes     Color Display                Monochrome Display
  15837.                   Number      Color           Number       Color
  15838.    ──────────────────────────────────────────────────────────────────────────
  15839.   11             11           Light cyan      2             High intensity
  15840.    12             12           Light red       2             High intensity
  15841.    13             13           Light magenta   2             High intensity
  15842.    14             14           Yellow          2             High intensity
  15843.    15             15           High-intensity  0             Off
  15844.                                white
  15845.    ──────────────────────────────────────────────────────────────────────────
  15846.  
  15847.  
  15848.  ■ Example
  15849.  
  15850.    See the LINE, CIRCLE, and DRAW statements for examples of the SCREEN
  15851.    statement.
  15852.  
  15853.  
  15854.  ────────────────────────────────────────────────────────────────────────────
  15855.  SEEK Function
  15856.  ────────────────────────────────────────────────────────────────────────────
  15857.  
  15858.  ■ Action
  15859.  
  15860.    Returns the current file position
  15861.  
  15862.  ■ Syntax
  15863.  
  15864.    SEEK(filenumber)
  15865.  
  15866.  ■ Remarks
  15867.  
  15868.    The filenumber is the number used in the OPEN statement to open the file.
  15869.    SEEK returns a value in the range 1 to 2,147,483,647 (equivalent to
  15870.    2^31-1).
  15871.  
  15872.    SEEK returns the number of the next record read or written when used on
  15873.    RANDOM mode files. For files opened in BINARY, OUTPUT, APPEND, or INPUT
  15874.    mode, SEEK returns the byte position in the file where the next operation
  15875.    is to take place. The first byte in a file is 1.
  15876.  
  15877.    When used on a device that does not support SEEK, the function returns
  15878.    zero. The BASIC devices (SCRN:, CONS:, KYBD:, COMn:, and LPTn:) do not
  15879.    support SEEK.
  15880.  
  15881.    See Chapter 3, "File and Device I/O," in Programming in BASIC for more
  15882.    information.
  15883.  
  15884.  ■ See Also
  15885.  
  15886.    GET (File I/O), OPEN, PUT (File I/O), SEEK Statement
  15887.  
  15888.  ■ Example
  15889.  
  15890.    The following code fragment prints a message indicating whether the last
  15891.    read or write was done in the first, second, or final third of the file:
  15892.  
  15893.    SELECT CASE (SEEK(1))
  15894.       CASE IS < .333*LOF(1)
  15895.          PRINT "In first third of file."
  15896.       CASE .333*LOF(1) TO .667*LOF(1)
  15897.          PRINT "In second third of file."
  15898.       CASE IS >= .667*LOF(1)
  15899.          PRINT "In last third of file."
  15900.       CASE ELSE
  15901.    END SELECT
  15902.  
  15903.  
  15904.  ────────────────────────────────────────────────────────────────────────────
  15905.  SEEK Statement
  15906.  ────────────────────────────────────────────────────────────────────────────
  15907.  
  15908.  ■ Action
  15909.  
  15910.    Sets the position in a file for the next read or write
  15911.  
  15912.  ■ Syntax
  15913.  
  15914.    SEEK «#»filenumber,position
  15915.  
  15916.  ■ Remarks
  15917.  
  15918.    The filenumber is an integer number used in the OPEN statement to open the
  15919.    file.
  15920.  
  15921.    The position is a numeric expression indicating where the next read or
  15922.    write is done. The position must be in the range 1 to 2,147,483,647
  15923.    (equivalent to 2^31-1). For files opened in RANDOM mode, position is the
  15924.    number of a record in the file.
  15925.  
  15926.    For files opened in BINARY, INPUT, OUTPUT, or APPEND modes, position is
  15927.    the number of a byte from the beginning of the file. The first byte in a
  15928.    file is 1. After a SEEK, the next file I/O operation starts at that byte
  15929.    in the file.
  15930.  
  15931.  ────────────────────────────────────────────────────────────────────────────
  15932.  NOTE
  15933.    Record numbers on a GET or PUT override the file positioning done by SEEK.
  15934.  ────────────────────────────────────────────────────────────────────────────
  15935.  
  15936.    Performing a file write after doing a SEEK beyond the end of a file
  15937.    extends the file. A SEEK to a negative or zero position produces an error
  15938.    message that reads Bad record number.
  15939.  
  15940.    When used on a device that does not support SEEK, BASIC ignores SEEK and
  15941.    leaves the file position unchanged. The BASIC devices (SCRN:, CONS:,
  15942.    KYBD:, COMn:, and LPTn:) do not support SEEK.
  15943.  
  15944.    See Chapter 3, "File and Device I/O," in Programming in BASIC for more
  15945.    information.
  15946.  
  15947.  ■ See Also
  15948.  
  15949.    GET (File I/O), OPEN, PUT (File I/O), SEEK Function
  15950.  
  15951.  ■ Example
  15952.  
  15953.    The following code fragment uses a combination of the SEEK function and
  15954.    SEEK statement to back up the file position and rewrite a record if a
  15955.    variable is true (nonzero):
  15956.  
  15957.    CONST FALSE=0, TRUE=NOT FALSE
  15958.    .
  15959.    .
  15960.    .
  15961.    IF ReWriteFlag = TRUE THEN
  15962.       ' Back up file by the length of the record variable that
  15963.       ' is used to write to the file.
  15964.       SEEK #1, SEEK(1)-LEN(RecordVar)
  15965.       PUT #1,,RecordVar
  15966.    END IF
  15967.  
  15968.  
  15969.  ────────────────────────────────────────────────────────────────────────────
  15970.  SELECT CASE Statement
  15971.  ────────────────────────────────────────────────────────────────────────────
  15972.  
  15973.  ■ Action
  15974.  
  15975.    Executes one of several statement blocks depending on the value of an
  15976.    expression
  15977.  
  15978.  ■ Syntax
  15979.  
  15980.    SELECT CASE testexpression
  15981.    CASE expressionlist1
  15982.  
  15983.        «statementblock-1»
  15984.  
  15985.    «CASE expressionlist2
  15986.  
  15987.        «statementblock-2»»
  15988.    .
  15989.    .
  15990.    .
  15991.  
  15992.    «CASE ELSE
  15993.  
  15994.        «statementblock-n»»
  15995.  
  15996.    END SELECT
  15997.  
  15998.  ■ Remarks
  15999.  
  16000.    The following list describes the parts of the SELECT CASE statement:
  16001.  
  16002.    Argument                 Description
  16003.    ──────────────────────────────────────────────────────────────────────────
  16004.    testexpression           Any numeric or string expression.
  16005.  
  16006.    statementblock-1,        The elements statementblock-1 to statementblock-n
  16007.    statementblock-2,        consist of any number of statements on one or
  16008.    statementblock-n         more lines.
  16009.  
  16010.    expressionlist1,         These elements can have any of the three
  16011.    expressionlist2          following forms: expression«,expression...»
  16012.                             expression TO expression IS relational-operator
  16013.                             expression
  16014.    ──────────────────────────────────────────────────────────────────────────
  16015.  
  16016.    The following list describes the parts of an expressionlist:
  16017.  
  16018. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  16019.    Argument                 Description
  16020.    ──────────────────────────────────────────────────────────────────────────
  16021.    expression               Any numeric or string expression. The type of the
  16022.                             expression must match the type of the expression
  16023.                             being tested.
  16024.  
  16025.    Argument                 Description
  16026.    ──────────────────────────────────────────────────────────────────────────
  16027. 
  16028.    relational-operator      Any of the following operators:
  16029.  
  16030.                             Symbol                  Meaning
  16031.  
  16032.                             <                       Less than
  16033.  
  16034.                             <=                      Less than or equal to
  16035.  
  16036.                             >                       Greater than
  16037.  
  16038.                             >=                      Greater than or equal to
  16039.  
  16040.                             <>                      Not equal
  16041.  
  16042.                             =                       Equal
  16043.  
  16044.    ──────────────────────────────────────────────────────────────────────────
  16045.  
  16046.    Argument                 Description
  16047.    ──────────────────────────────────────────────────────────────────────────
  16048. 
  16049.  
  16050.    If the testexpression matches the expressionlist associated with a CASE
  16051.    clause, then the statement block following that CASE clause is executed up
  16052.    to the next CASE clause or, for the last one, up to END SELECT. Control
  16053.    then passes to the statement following END SELECT.
  16054.  
  16055.    If you use the TO keyword to indicate a range of values, the smaller value
  16056.    must appear first. For example, the statements associated with the line
  16057.    CASE -1 TO -5 are not executed if the testexpression is -4. The line
  16058.    should be written as CASE -5 TO -1.
  16059.  
  16060.    You may use a relational operator only if the IS keyword appears. If CASE
  16061.    ELSE is used, its associated statements are executed only if the
  16062.    testexpression does not match any of the other CASE selections. It is a
  16063.    good idea to have a CASE ELSE statement in your SELECT CASE block to
  16064.    handle unforeseen testexpression values.
  16065.  
  16066.    When there is no CASE ELSE statement and no expression listed in the CASE
  16067.    clauses matches testexpression, program execution continues normally. No
  16068.    error occurs.
  16069.  
  16070.    You may use multiple expressions or ranges in each CASE clause. For
  16071.    example, the following line is valid:
  16072.  
  16073.    CASE 1 TO 4, 7 TO 9, 11, 13, IS > MaxNumber%
  16074.  
  16075.    You may also specify ranges and multiple expressions for strings:
  16076.  
  16077.    CASE "everything", "nuts" TO "soup", TestItem$
  16078.  
  16079.    CASE matches strings that are exactly equal to everything, the current
  16080.    value of TestItem$, or that fall between nuts and soup in alphabetical
  16081.    order.
  16082.  
  16083.    Strings are evaluated according to the ASCII values of their characters.
  16084.    Lowercase letters have larger ASCII values than uppercase letters, so
  16085.  
  16086.    nuts  >  Nuts  >  NUTS
  16087.  
  16088.    If an expression appears in more than one CASE clause, only the statements
  16089.    associated with the first appearance of the expression are executed.
  16090.  
  16091.    SELECT CASE statements may be nested. Each SELECT CASE statement must have
  16092.    a matching END SELECT statement.
  16093.  
  16094.  ■ Example
  16095.  
  16096.    In the following program, the SELECT CASE statement is used to take
  16097.    different actions based on the input value:
  16098.  
  16099.    ' Program demonstrates various forms of CASE items
  16100.         INPUT "Enter acceptable level of risk (1-10): ", Total
  16101.         SELECT CASE Total
  16102.  
  16103.            CASE IS >= 10
  16104.               PRINT "Maximum risk and potential return"
  16105.               PRINT "Choose stock investment plan"
  16106.  
  16107.            CASE  6 TO 9
  16108.               PRINT "High risk and potential return"
  16109.               PRINT "Choose corporate bonds"
  16110.  
  16111.            CASE  2 TO 5
  16112.               PRINT "Moderate risk and return"
  16113.               PRINT "Choose mutual fund"
  16114.  
  16115.            CASE 1
  16116.               PRINT "No risk, low return"
  16117.               PRINT "Choose IRA"
  16118.  
  16119.            CASE ELSE
  16120.               PRINT "RESPONSE OUT OF RANGE"
  16121.  
  16122.         END SELECT
  16123.  
  16124.  ■ Output
  16125.  
  16126.    Enter acceptable level of risk (1-10): 10
  16127.    Maximum risk and potential return
  16128.    Choose stock investment plan
  16129.  
  16130.    Enter acceptable level of risk (1-10): 0
  16131.    RESPONSE OUT OF RANGE
  16132.  
  16133.  
  16134.  ────────────────────────────────────────────────────────────────────────────
  16135.  SETMEM Function
  16136.  ────────────────────────────────────────────────────────────────────────────
  16137.  
  16138.  ■ Action
  16139.  
  16140.    Changes the amount of memory used by the far heap──the area where far
  16141.    objects and internal tables are stored
  16142.  
  16143.  ■ Syntax
  16144.  
  16145.    SETMEM(numeric-expression)
  16146.  
  16147.  ■ Remarks
  16148.  
  16149.    The SETMEM function increases or decreases the far heap by the number of
  16150.    bytes indicated by numeric-expression. If the numeric-expression is
  16151.    negative, SETMEM decreases the far heap by the indicated number of bytes.
  16152.    When the numeric-expression is positive, SETMEM attempts to increase the
  16153.    far heap space by the number of bytes.
  16154.  
  16155.    SETMEM returns the total number of bytes in the far heap. If the
  16156.    numeric-expression is zero, SETMEM returns the current size of the far
  16157.    heap. If SETMEM cannot change the far heap by the requested number of
  16158.    bytes, it reallocates as many bytes as possible.
  16159.  
  16160.    SETMEM can be used in mixed-language programming to decrease the far heap
  16161.    space so procedures in other languages can dynamically allocate far
  16162.    memory. A first call to SETMEM trying to increase the far heap has no
  16163.    effect because BASIC allocates as much memory as possible to the far heap
  16164.    when a program starts.
  16165.  
  16166.  ■ Example
  16167.  
  16168.    The following program outlines how SETMEM could be used to free memory for
  16169.    a C function that uses malloc to get dynamic memory. The C function is
  16170.    separately compiled and then put in a Quick library or linked to the BASIC
  16171.    program. The C function is compiled using the large memory model, so calls
  16172.    to malloc use the far space freed by the BASIC program.
  16173.  
  16174.    DEFINT A-Z
  16175.    DECLARE SUB CFunc CDECL (BYVAL X AS INTEGER)
  16176.  
  16177.    ' Decrease the size of the far heap so CFunc can use
  16178.    ' malloc to get dynamic memory.
  16179.    BeforeCall=SETMEM(-2048)
  16180.  
  16181.    ' Call the C function.
  16182.    CFunc(1024%)
  16183.  
  16184.    ' Return the memory to the far heap; use a larger value so
  16185.    ' all space goes back into the heap.
  16186.    AfterCall=SETMEM(3500)
  16187.  
  16188.    IF AfterCall <= BeforeCall THEN PRINT "Memory not reallocated."
  16189.  
  16190.    END
  16191.  
  16192.    void far cfunc(bytes)
  16193.    int bytes;
  16194.    {
  16195.       char *malloc();
  16196.       char *workspace;
  16197.  
  16198.       /* Allocate working memory using amount BASIC freed. */
  16199.       workspace=malloc((unsigned) bytes);
  16200.  
  16201.       /* Working space would be used here. */
  16202.  
  16203.       /* Free memory before returning to BASIC. */
  16204.       free(workspace);
  16205.    }
  16206.  
  16207.  
  16208.  ────────────────────────────────────────────────────────────────────────────
  16209.  SGN Function
  16210.  ────────────────────────────────────────────────────────────────────────────
  16211.  
  16212.  ■ Action
  16213.  
  16214.    Indicates the sign of a numeric expression
  16215.  
  16216.  ■ Syntax
  16217.  
  16218.    SGN(numeric-expression)
  16219.  
  16220.  ■ Remarks
  16221.  
  16222.    The SGN function returns a value depending on the sign of its argument:
  16223.  
  16224.    If numeric-expression > 0, then SGN(numeric-expression) returns 1.
  16225.  
  16226.    If numeric-expression = 0, then SGN(numeric-expression) returns 0.
  16227.  
  16228.    If numeric-expression < 0, then SGN(numeric-expression) returns -1.
  16229.  
  16230.  ■ Example
  16231.  
  16232.    The following program calculates and prints the solution for a quadratic
  16233.    (or for a second-degree) equation. The program uses the sign of a test
  16234.    expression to determine how to calculate the solution.
  16235.  
  16236.    CONST NoRealSoln=-1, OneSoln=0, TwoSolns=1
  16237.    ' Input coefficients of quadratic equation:
  16238.    ' ax^2 + bx + c = 0.
  16239.    INPUT;"a = ",   A
  16240.    INPUT;",  b = ",B
  16241.    INPUT ",  c = ",C
  16242.    Test = B^2 - 4*A*C
  16243.    SELECT CASE SGN(Test)
  16244.       CASE  NoRealSoln
  16245.          PRINT "This equation has no real-number solutions."
  16246.       CASE  OneSoln
  16247.          PRINT "This equation has one solution: ";
  16248.          PRINT -B/(2*A)
  16249.       CASE  TwoSolns
  16250.          PRINT "This equation has two solutions: ";
  16251.          PRINT (-B + SQR(Test))/(2*A) " and ";
  16252.          PRINT (-B - SQR(Test))/(2*A)
  16253.    END SELECT
  16254.  
  16255.  ■ Output
  16256.  
  16257.    a = 12,  b = -5,  c = -2
  16258.    This equation has two solutions:  .6666667          -.25
  16259.  
  16260.  
  16261.  ────────────────────────────────────────────────────────────────────────────
  16262.  SHARED Statement
  16263.  ────────────────────────────────────────────────────────────────────────────
  16264.  
  16265.  ■ Action
  16266.  
  16267.    Gives a SUB or FUNCTION procedure access to variables declared at the
  16268.    module level without passing them as parameters
  16269.  
  16270.  ■ Syntax
  16271.  
  16272.    SHARED variable «AS type» «, variable «AS type»»...
  16273.  
  16274.  ■ Remarks
  16275.  
  16276.    The argument variable is either an array name followed by () or a variable
  16277.    name. The AS clause can be used to indicate the variable's type. The type
  16278.    argument can be INTEGER, LONG, SINGLE, DOUBLE, STRING, fixed-length string
  16279.    (STRING*length), or a user-defined type.
  16280.  
  16281.    By using either the SHARED statement in a SUB or FUNCTION procedure, or
  16282.    the SHARED attribute with COMMON or DIM in the module-level code, you can
  16283.    use variables in a procedure without passing them as parameters. The
  16284.    SHARED attribute shares variables among all procedures in a module, while
  16285.    the SHARED statement shares variables between a single procedure and the
  16286.    module-level code.
  16287.  
  16288.  ────────────────────────────────────────────────────────────────────────────
  16289.  NOTE
  16290.    The SHARED statement only shares variables within a single compiled
  16291.    module. It does not share variables with programs in the Quick library or
  16292.    with procedures compiled separately and linked to the program. The SHARED
  16293.    statement only shares variables between the module-level code and a SUB or
  16294.    FUNCTION in the same module.
  16295.  ────────────────────────────────────────────────────────────────────────────
  16296.  
  16297.    The SHARED statement can appear only in a SUB or FUNCTION. For more
  16298.    information see Chapter 2, "SUB and FUNCTION Procedures," in Programming
  16299.    in BASIC and Chapter 4, "Programs and Modules," in this manual.
  16300.  
  16301.  ■ See Also
  16302.  
  16303.    COMMON, DIM, SUB
  16304.  
  16305.  ■ Example
  16306.  
  16307.    The following program calls a subprogram named CONVERT that converts the
  16308.    input decimal number to its string representation in the given new base.
  16309.    The string N$ is shared by the subprogram and the main program.
  16310.  
  16311.    DEFINT A-Z
  16312.    DO
  16313.       INPUT "Decimal number (input number <= 0 to quit): ",Decimal
  16314.       IF Decimal <= 0 THEN EXIT DO
  16315.       INPUT "New base: ",Newbase
  16316.       N$ = ""
  16317.       PRINT Decimal "base 10 equals ";
  16318.       DO WHILE Decimal > 0
  16319.          CALL Convert (Decimal,Newbase)
  16320.          Decimal = Decimal\Newbase
  16321.       LOOP
  16322.       PRINT N$ " base" Newbase
  16323.       PRINT
  16324.    LOOP
  16325.  
  16326.    SUB Convert (D,Nb) STATIC
  16327.    SHARED N$
  16328.       ' Take the remainder to find the value of the current
  16329.       ' digit.
  16330.       R = D MOD Nb
  16331.       ' If the digit is less than ten, return a digit (0...9).
  16332.       ' Otherwise, return a letter (A...Z).
  16333.       IF R < 10 THEN Digit$ = CHR$(R+48) ELSE Digit$ = CHR$(R+55)
  16334.       N$ = RIGHT$(Digit$,1) + N$
  16335.    END SUB
  16336.  
  16337.  ■ Output
  16338.  
  16339.    Decimal number (input number <= 0 to quit): 256
  16340.    New base: 2
  16341.     256 base 10 equals 100000000 base 2
  16342.  
  16343.    Decimal number (input number <= 0 to quit): 31
  16344.    New base: 16
  16345.     31 base 10 equals 1F base 16
  16346.  
  16347.    Decimal number (input number <= 0 to quit): -1
  16348.  
  16349.  
  16350.  ────────────────────────────────────────────────────────────────────────────
  16351.  SHELL Statement
  16352.  ────────────────────────────────────────────────────────────────────────────
  16353.  
  16354.  ■ Action
  16355.  
  16356.    Exits the BASIC program, runs a .COM, .EXE, or .BAT program or a DOS
  16357.    command, and returns to the program at the line following the SHELL
  16358.    statement
  16359.  
  16360.  ■ Syntax
  16361.  
  16362.    SHELL «commandstring»
  16363.  
  16364.  ■ Remarks
  16365.  
  16366.    The commandstring must be a valid string expression containing the name of
  16367.    a program to run and any program options.
  16368.  
  16369.    Any .COM file, .EXE file, .BAT program, or DOS function that runs under
  16370.    the SHELL statement is called a "child process." Child processes are
  16371.    executed by the SHELL statement, loading and running a copy of COMMAND.COM
  16372.    with the /C option automatically; this option allows any parameters in
  16373.    commandstring to be passed to the child process. It also allows
  16374.    redirection of standard input and output, and execution of built-in
  16375.    commands such as DIR, PATH, and SORT.
  16376.  
  16377.    The program name in commandstring may have any extension you wish. If no
  16378.    extension is supplied, COMMAND.COM looks for a .COM file, then an .EXE
  16379.    file, and finally, a .BAT file. If COMMAND.COM is not found, SHELL issues
  16380.    an error message that reads File not found. BASIC does not generate an
  16381.    error if COMMAND.COM cannot find the file specified in commandstring.
  16382.  
  16383.    Any text separated from the program name by at least one blank is treated
  16384.    as program parameters by COMMAND.COM. BASIC remains in memory while the
  16385.    child process is running. When the child process finishes, BASIC
  16386.    continues.
  16387.  
  16388.    SHELL with no commandstring gives you a new COMMAND.COM shell. You may now
  16389.    do anything that COMMAND.COM allows. Enter the DOS command EXIT when you
  16390.    are ready to return to BASIC.
  16391.  
  16392.  ■ Examples
  16393.  
  16394.    This example shows how a SHELL statement starts up a new COMMAND.COM:
  16395.  
  16396.    SHELL   'Get a new COMMAND.COM.
  16397.  
  16398.  ■ Output
  16399.  
  16400.    The IBM Personal Computer DOS
  16401.    Version 3.20 (C)Copyright International
  16402.    Business Machines Corp 1981, 1986 (C)Copyright
  16403.    Microsoft Corp 1981, 1986
  16404.  
  16405.    D:\QB4>
  16406.  
  16407.    The following example copies all files modified on a certain date from a
  16408.    specified directory:
  16409.  
  16410.    ' This program copies all files in this directory modified
  16411.    ' on a certain date to the drive and directory you specify.
  16412.  
  16413.    DECLARE FUNCTION GetName$ (DirLine$)
  16414.    LINE INPUT "Enter target drive and directory: ",PathSpec$
  16415.    SHELL "DIR > DIRFILE"
  16416.     'Store directory listing in DIRFILE.
  16417.    DO
  16418.       OPEN "DIRFILE" FOR INPUT AS #1
  16419.       INPUT "Enter date (MM-DD-YY): ",MDate$
  16420.       PRINT
  16421.  
  16422.       ' Read DIRFILE, test for input date.
  16423.       DO
  16424.       LINE INPUT #1, DirLine$
  16425.       ' Test directory line to see if date matches and the line
  16426.       ' is not one of the special directories ( . or .. ).
  16427.       IF INSTR(DirLine$,MDate$) > 0 AND LEFT$(DirLine$,1) <> "." THEN
  16428.            FileSpec$ = GetName$(DirLine$)
  16429.            ' Make sure we don't move our temporary file.
  16430.            IF FileSpec$ <> "DIRFILE" THEN
  16431.               ' Build the DOS command line to copy the file.
  16432.               DoLine$ = "COPY " + FileSpec$ + "  " + PathSpec$
  16433.               PRINT DoLine$
  16434.               ' Copy the file.
  16435.               SHELL DoLine$
  16436.            END IF
  16437.       END IF
  16438.       LOOP UNTIL EOF(1)
  16439.  
  16440.    CLOSE #1
  16441.       PRINT "New date?"
  16442.       R$ = INPUT$(1)
  16443.       CLS
  16444.    LOOP UNTIL UCASE$(R$) <> "Y"
  16445.    ' KILL "DIRFILE".
  16446.    END
  16447.  
  16448.    ' This function gets the file name and extension from
  16449.    ' the directory-listing line.
  16450.    FUNCTION GetName$ (DirLine$) STATIC
  16451.       BaseName$ = RTRIM$(LEFT$(DirLine$,8))
  16452.  
  16453.       ' Check for extension.
  16454.       ExtName$  = RTRIM$(MID$(DirLine$,10,3))
  16455.  
  16456.       IF ExtName$ <> "" THEN
  16457.          BaseName$ = BaseName$ + "." + ExtName$
  16458.       END IF
  16459.  
  16460.       GetName$ = BaseName$
  16461.    END FUNCTION
  16462.  
  16463.  ■ Output
  16464.  
  16465.    Enter target drive and directory: c:\bas\temp
  16466.    Enter date (MM-DD-YY): 6-11-87
  16467.  
  16468.    COPY CONF.DAT  c:\bas\temp
  16469.    COPY TEST.BAS  c:\bas\temp
  16470.    COPY TEMPFILE  c:\bas\temp
  16471.  
  16472.    New date? n
  16473.  
  16474.  
  16475.  ────────────────────────────────────────────────────────────────────────────
  16476.  SIN Function
  16477.  ────────────────────────────────────────────────────────────────────────────
  16478.  
  16479.  ■ Action
  16480.  
  16481.    Returns the sine of the angle x, where x is in radians
  16482.  
  16483.  ■ Syntax
  16484.  
  16485.    SIN(x)
  16486.  
  16487.  ■ Remarks
  16488.  
  16489.    When x is a double-precision value, the SIN function is calculated with
  16490.    double-precision accuracy. When x is not double precision, SIN is
  16491.    calculated with single-precision accuracy.
  16492.  
  16493.  ■ See Also
  16494.  
  16495.    ATN, COS, TAN
  16496.  
  16497.  ■ Example
  16498.  
  16499.    The example plots the graph of the polar equation r = 1 + sin n (Θ). This
  16500.    figure is sometimes known as a cardioid, owing to its resemblance to a
  16501.    heart when n equals 1.
  16502.  
  16503.    CONST PI = 3.141593
  16504.    SCREEN 1 : COLOR 1,1      'Medium resolution, blue background.
  16505.    WINDOW (-3,-2)-(3,2)      'Convert screen to Cartesian
  16506.                              'coordinates.
  16507.    INPUT "Number of petals = ", N
  16508.    CLS
  16509.    PSET (1,0)         'Set initial point.
  16510.    FOR Angle = 0 TO 2*PI STEP .02
  16511.       R = 1 + SIN(N*Angle)   'Polar equation for "flower."
  16512.       X = R * COS(Angle)     'Convert polar coordinates to
  16513.       Y = R * SIN(Angle)     'Cartesian coordinates.
  16514.       LINE -(X,Y)         'Draw line from previous point to
  16515.                           'new point.
  16516.    NEXT
  16517.  
  16518.  
  16519.  ────────────────────────────────────────────────────────────────────────────
  16520.  SLEEP Statement
  16521.  ────────────────────────────────────────────────────────────────────────────
  16522.  
  16523.  ■ Action
  16524.  
  16525.    Suspends execution of the calling program
  16526.  
  16527.  ■ Syntax
  16528.  
  16529.    SLEEP  « seconds »
  16530.  
  16531.  ■ Remarks
  16532.  
  16533.    The optional argument seconds determines the number of seconds the program
  16534.    is suspended. The SLEEP statement suspends the program until one of the
  16535.    following events occurs:
  16536.  
  16537.    ■ The time period in the seconds argument elapses.
  16538.  
  16539.    ■ A key is pressed.
  16540.  
  16541.    ■ An enabled event occurs.
  16542.  
  16543.    If seconds is zero or not specified, the program is suspended
  16544.    indefinitely. Only an enabled event or a keystroke can interrupt an
  16545.    indefinite suspension.
  16546.  
  16547.    SLEEP responds only to keystrokes that occur after it executes. SLEEP
  16548.    ignores characters in the keyboard buffer that were typed before it
  16549.    executed.
  16550.  
  16551.    An event (such as ON COM or ON TIMER) cannot interrupt a SLEEP suspension
  16552.    unless its trapping is active when the event occurs. This means that
  16553.    trapping must have been initialized with an ON event statement, turned on
  16554.    with an event ON statement, and not have been disabled with an event OFF
  16555.    statement or an event STOP statement.
  16556.  
  16557.  ■ See Also
  16558.  
  16559.    WAIT
  16560.  
  16561.  ■ Example
  16562.  
  16563.    The following program suspends execution for 10 seconds. There is no ON
  16564.    event statement, so the only way to interrupt the suspension before 10
  16565.    seconds have passed is to press a key.
  16566.  
  16567.    PRINT "Taking a 10 second nap..."
  16568.    SLEEP 10
  16569.    PRINT "Awake!"
  16570.    END
  16571.  
  16572.  
  16573.  ────────────────────────────────────────────────────────────────────────────
  16574.  SOUND Statement
  16575.  ────────────────────────────────────────────────────────────────────────────
  16576.  
  16577.  ■ Action
  16578.  
  16579.    Generates sound through the speaker
  16580.  
  16581.  ■ Syntax
  16582.  
  16583.    SOUND frequency,duration
  16584.  
  16585.  ■ Remarks
  16586.  
  16587.    The frequency is the desired frequency in hertz (cycles/second). It must
  16588.    be a numeric expression returning an integer in the range 37-32,767.
  16589.  
  16590.    The duration is the duration in clock ticks. (There are 18.2 clock ticks
  16591.    per second regardless of CPU speed.) The duration must be a numeric
  16592.    expression returning an unsigned integer in the range 0-65,535.
  16593.  
  16594.    If the duration is zero, any current SOUND statement that is running is
  16595.    turned off. If no SOUND statement is running, a SOUND statement with a
  16596.    duration of zero has no effect.
  16597.  
  16598.  ■ SEE ALSO
  16599.  
  16600.    PLAY
  16601.  
  16602.  ■ Example
  16603.  
  16604.    This program fragment produces a rising and descending glissando:
  16605.  
  16606.    FOR I = 440 TO 1000 STEP 5
  16607.       SOUND I, I/1000
  16608.    NEXT
  16609.    FOR I = 1000 TO 440 STEP -5
  16610.      SOUND I, I/1000
  16611.    NEXT
  16612.  
  16613.  
  16614.  ────────────────────────────────────────────────────────────────────────────
  16615.  SPACE$ Function
  16616.  ────────────────────────────────────────────────────────────────────────────
  16617.  
  16618.  ■ Action
  16619.  
  16620.    Returns a string of spaces of length n
  16621.  
  16622.  ■ Syntax
  16623.  
  16624.    SPACE$(n)
  16625.  
  16626.  ■ Remarks
  16627.  
  16628.    The expression n is rounded to an integer and must be in the range
  16629.    0-32,767.
  16630.  
  16631.  ■ See Also
  16632.  
  16633.    SPC
  16634.  
  16635.  ■ Example
  16636.  
  16637.    This example illustrates the use of SPACE$:
  16638.  
  16639.    FOR I=1 TO 5
  16640.       X$=SPACE$(I)
  16641.       PRINT X$;I
  16642.    NEXT I
  16643.  
  16644.  ■ Output
  16645.  
  16646.     1
  16647.      2
  16648.       3
  16649.        4
  16650.         5
  16651.  
  16652.  
  16653.  ────────────────────────────────────────────────────────────────────────────
  16654.  SPC Function
  16655.  ────────────────────────────────────────────────────────────────────────────
  16656.  
  16657.  ■ Action
  16658.  
  16659.    Skips n spaces in a PRINT statement
  16660.  
  16661.  ■ Syntax
  16662.  
  16663.    SPC(n)
  16664.  
  16665.  ■ Remarks
  16666.  
  16667.    SPC may only be used with PRINT and LPRINT statements. The argument n must
  16668.    be in the range 0-32,767. A semicolon (;) is assumed to follow the SPC(n)
  16669.    command.
  16670.  
  16671.  ■ See Also
  16672.  
  16673.    SPACE$
  16674.  
  16675.  ■ Example
  16676.  
  16677.    This example illustrates the use of SPC:
  16678.  
  16679.    PRINT "OVER";SPC(15) "THERE"
  16680.  
  16681.  ■ Output
  16682.  
  16683.    OVER               THERE
  16684.  
  16685.  
  16686.  ────────────────────────────────────────────────────────────────────────────
  16687.  SQR Function
  16688.  ────────────────────────────────────────────────────────────────────────────
  16689.  
  16690.  ■ Action
  16691.  
  16692.    Returns the square root of n
  16693.  
  16694.  ■ Syntax
  16695.  
  16696.    SQR(n)
  16697.  
  16698.  ■ Remarks
  16699.  
  16700.    The argument n must be >= 0.
  16701.  
  16702.  ■ Example
  16703.  
  16704.    The following program plots the graphs of y = √-x for -9 <= x < 0 and of y
  16705.    = √x for 0 <= x <= 9:
  16706.  
  16707.    SCREEN 1 : COLOR 1         'Low-resolution color graphics mode.
  16708.    WINDOW (-9,-.25)-(9,3.25)  'Convert screen to Cartesian
  16709.                               'coordinates.
  16710.    LINE (-9,0)-(9,0)          'Draw X-axis.
  16711.    LINE (0,-.25)-(0,3.25)     'Draw Y-axis.
  16712.  
  16713.    FOR X = -9 TO 9
  16714.        LINE(X,.04)-(X,-.04)   'Put tick marks on X-axis.
  16715.    NEXT
  16716.  
  16717.    FOR Y = .25 TO 3.25 STEP .25
  16718.        LINE (-.08,Y)-(.12,Y)  'Put tick marks on Y-axis.
  16719.    NEXT
  16720.  
  16721.    PSET (-9,3)                'Plot the first point of function.
  16722.    FOR X = -9 TO 9 STEP .25
  16723.        Y = SQR(ABS(X))
  16724.       'SQR argument cannot be negative.
  16725.        LINE -(X,Y),2          'Draw a line to the next point.
  16726.    NEXT
  16727.  
  16728.  
  16729.  ────────────────────────────────────────────────────────────────────────────
  16730.  STATIC Statement
  16731.  ────────────────────────────────────────────────────────────────────────────
  16732.  
  16733.  ■ Action
  16734.  
  16735.    Makes simple variables or arrays local to either a DEF FN function, a
  16736.    FUNCTION, or a SUB and preserves values between calls
  16737.  
  16738.  ■ Syntax
  16739.  
  16740.    STATIC variablelist
  16741.  
  16742.  ■ Remarks
  16743.  
  16744.    A STATIC statement variablelist has the following syntax:
  16745.  
  16746.    variable«( )»«AS type» «, variable«( )»«AS type»»...
  16747.  
  16748.    The variablelist takes the following arguments:
  16749.  
  16750.    Argument                 Description
  16751.    ──────────────────────────────────────────────────────────────────────────
  16752.    variable                 Either a variable name or an array name.
  16753.  
  16754.    AS type                  Declares the type of variable. The type argument
  16755.                             can be INTEGER, LONG, SINGLE, DOUBLE, STRING, or
  16756.                             a user-defined type.
  16757.    ──────────────────────────────────────────────────────────────────────────
  16758.  
  16759.    The STATIC statement can appear only in a SUB, FUNCTION, or DEF FN
  16760.    function. Earlier versions of BASIC required the number of dimensions in
  16761.    parentheses after an array name. In QuickBASIC, the number of dimensions
  16762.    is optional.
  16763.  
  16764.    Variables declared in a STATIC statement override variables of the same
  16765.    name shared by DIM or COMMON statements in the module-level code.
  16766.    Variables in a STATIC statement also override global constants of the same
  16767.    name.
  16768.  
  16769.    Usually, variables used in DEF FN functions are global to the module;
  16770.    however, you can use the STATIC statement inside a DEF FN statement to
  16771.    declare a variable as local to only that function.
  16772.  
  16773.  ────────────────────────────────────────────────────────────────────────────
  16774.  NOTE
  16775.    The STATIC attribute on SUB and FUNCTION statements declares the default
  16776.    for variables to be static. Variables having the same name as variables
  16777.    shared by the module-level code are still shared. In contrast, the STATIC
  16778.    statement makes specific variables static and overrides any variables
  16779.    shared by the module-level code. The ¢STATIC metacommand affects how
  16780.    memory is allocated for arrays. See Chapter 2, "Data Types," for a
  16781.    discussion of the differences among these statements and attributes.
  16782.  ────────────────────────────────────────────────────────────────────────────
  16783.  
  16784.  ■ See Also
  16785.  
  16786.    COMMON, DEF FN, DIM, FUNCTION, SHARED, SUB
  16787.  
  16788.  ■ Examples
  16789.  
  16790.    This example contrasts the STATIC and SHARED statements within a
  16791.    subprogram AUGMENT. The variables R and N are both local to this
  16792.    subprogram, while the variables REP and NUM are shared between the main
  16793.    program and the subprogram. The STATIC R,N statement ensures that R and N
  16794.    retain the last values assigned to them each time the main program calls
  16795.    the subprogram.
  16796.  
  16797.    Rep = 0 : Num = 0
  16798.    PRINT "Before loop, REP = ";Rep;", NUM = ";Num;
  16799.    PRINT ", R = ";R;", N = ";N
  16800.    FOR I = 1 TO 10
  16801.       CALL Augment
  16802.    NEXT
  16803.    PRINT "After loop, REP = ";Rep;", NUM = ";Num;
  16804.    PRINT ", R = ";R;", N = ";N
  16805.    END
  16806.  
  16807.    SUB Augment STATIC
  16808.    SHARED Rep,Num    'Shared with main program.
  16809.    STATIC R,N        'Not shared with main program.
  16810.       R = R + 1      'Both R and N initially equal 0.
  16811.       N = N + 2
  16812.       Rep = R
  16813.       Num = N
  16814.    END SUB
  16815.  
  16816.  ■ Output
  16817.  
  16818.    Before loop, REP = 0 , NUM = 0 , R = 0 , N = 0
  16819.    After loop, REP = 10 , NUM = 20 , R = 0 , N = 0
  16820.  
  16821.    The following program searches for every occurrence of a certain string
  16822.    expression (stored in the variable OLD$) in the specified file and
  16823.    replaces that string with the string stored in NW$. The name of the file
  16824.    with these changes is the old filename with the extension .NEW. The
  16825.    program also prints the number of substitutions and the number of lines
  16826.    changed.
  16827.  
  16828.    INPUT "Name of file";F1$
  16829.    INPUT "String to replace";Old$
  16830.    INPUT "Replace with";Nw$
  16831.    Rep = 0 : Num = 0
  16832.    M = LEN(Old$)
  16833.    OPEN F1$ FOR INPUT AS #1
  16834.    CALL Extension
  16835.    OPEN F2$ FOR OUTPUT AS #2
  16836.  
  16837.    DO WHILE NOT EOF(1)
  16838.       LINE INPUT #1, Temp$
  16839.       CALL Search
  16840.       PRINT #2, Temp$
  16841.    LOOP
  16842.  
  16843.    CLOSE
  16844.    PRINT "There were ";Rep;" substitutions in ";Num;" lines."
  16845.    PRINT "Substitutions are in file ";F2$
  16846.    END
  16847.    SUB Extension STATIC
  16848.    SHARED F1$,F2$
  16849.       Mark = INSTR(F1$,".")
  16850.       IF Mark = 0 THEN
  16851.          F2$ = F1$ + ".NEW"
  16852.       ELSE
  16853.          F2$ = LEFT$(F1$,Mark - 1) + ".NEW"
  16854.       END IF
  16855.    END SUB
  16856.  
  16857.    SUB Search STATIC
  16858.    SHARED Temp$,Old$,Nw$,Rep,Num,M
  16859.    STATIC R
  16860.       Mark = INSTR(Temp$,Old$)
  16861.       WHILE Mark
  16862.          Part1 = LEFT$(Temp$,Mark - 1)
  16863.          Part2 = MID$(Temp$,Mark + M)
  16864.          Temp$ = Part1$ + Nw$ + Part2$
  16865.          R = R + 1
  16866.          Mark = INSTR(Temp$,Old$)
  16867.       WEND
  16868.       IF Rep = R THEN
  16869.           EXIT SUB
  16870.       ELSE
  16871.           Rep = R
  16872.           Num = Num + 1
  16873.       END IF
  16874.    END SUB
  16875.  
  16876.  ■ Output
  16877.  
  16878.    Name of file? CHAP1.S
  16879.    String to replace? CHAPTER 1
  16880.    Replace with? INTRODUCTION
  16881.    There were 23 substitutions in 19 lines.
  16882.    Substitutions are in file CHAP1.NEW
  16883.  
  16884.    The file CHAP1.NEW now contains every line in CHAP1.S, with each
  16885.    occurrence of the string CHAPTER 1 replaced by INTRODUCTION.
  16886.  
  16887.  
  16888.  ────────────────────────────────────────────────────────────────────────────
  16889.  STICK Function
  16890.  ────────────────────────────────────────────────────────────────────────────
  16891.  
  16892.  ■ Action
  16893.  
  16894.    Returns the x- and y-coordinates of the two joysticks
  16895.  
  16896.  ■ Syntax
  16897.  
  16898.    STICK(n)
  16899.  
  16900.  ■ Remarks
  16901.  
  16902.    The argument n is a numeric expression whose value is an unsigned integer
  16903.    in the range 0 to 3:
  16904.  
  16905.    Argument                 Value Returned
  16906.    ──────────────────────────────────────────────────────────────────────────
  16907.    0                        The x-coordinate of joystick A
  16908.  
  16909.    1                        The y-coordinate of joystick A when STICK(0) was
  16910.                             last called
  16911.  
  16912.    2                        The x-coordinate of joystick B when STICK(0) was
  16913.                             last called
  16914.  
  16915.    3                        The y-coordinate of joystick B when STICK(0) was
  16916.                             last called
  16917.    ──────────────────────────────────────────────────────────────────────────
  16918.  
  16919.    The x- and y-coordinates have a range of 1 to 200. You must use STICK(0)
  16920.    before you use STICK(1), STICK(2), or STICK(3). STICK(0) not only returns
  16921.    the x-coordinate of joystick A, it also records the other joystick
  16922.    coordinates. These recorded coordinates are returned by calling
  16923.    STICK(1)-STICK(3).
  16924.  
  16925.  ■ Example
  16926.  
  16927.    The following fragment prints the coordinates of joystick B:
  16928.  
  16929.    TEMP = STICK(0)
  16930.    PRINT STICK(2), STICK(3)
  16931.  
  16932.  
  16933.  ────────────────────────────────────────────────────────────────────────────
  16934.  STOP Statement
  16935.  ────────────────────────────────────────────────────────────────────────────
  16936.  
  16937.  ■ Action
  16938.  
  16939.    Terminates the program
  16940.  
  16941.  ■ Syntax
  16942.  
  16943.    STOP
  16944.  
  16945.  ■ Remarks
  16946.  
  16947.    STOP statements can be used anywhere in a program to terminate execution.
  16948.  
  16949.    When running in the QuickBASIC environment, the STOP statement leaves
  16950.    files open and does not exit to the operating system. In contrast, a STOP
  16951.    statement in a stand-alone .EXE file does close all files and return to
  16952.    the operating system.
  16953.  
  16954.    If you use the /D, /E, or /X compile options on the bc command line, the
  16955.    STOP statement prints the number of the line where execution stopped, if
  16956.    your program has line numbers. If there is no line number associated with
  16957.    the STOP statement, the most recent line number is printed. If your
  16958.    program has no line numbers, then the line number printed is 0.
  16959.  
  16960.    In the past, STOP statements were used for debugging. QuickBASIC's new
  16961.    debugging features make this use of STOP unnecessary.
  16962.  
  16963.  ■ Example
  16964.  
  16965.    There is no programming example for the STOP statement.
  16966.  
  16967.  
  16968.  ────────────────────────────────────────────────────────────────────────────
  16969.  STR$ Function
  16970.  ────────────────────────────────────────────────────────────────────────────
  16971.  
  16972.  ■ Action
  16973.  
  16974.    Returns a string representation of the value of a numeric expression
  16975.  
  16976.  ■ Syntax
  16977.  
  16978.    STR$(numeric-expression)
  16979.  
  16980.  ■ Remarks
  16981.  
  16982.    If numeric-expression is positive, the string returned by the STR$
  16983.    function contains a leading blank. The VAL function complements STR$.
  16984.  
  16985.  ■ See Also
  16986.  
  16987.    VAL
  16988.  
  16989.  ■ Example
  16990.  
  16991.    The following example contains a FUNCTION that uses the STR$ function to
  16992.    convert a number to its string representation. The FUNCTION then strips
  16993.    out the leading and trailing blanks that BASIC prints with numeric output.
  16994.  
  16995.    FUNCTION NumRemBlanks$(X) STATIC
  16996.       X$ = STR$(X)
  16997.       NumRemBlanks$ = LTRIM$(RTRIM$(X$))
  16998.    END FUNCTION
  16999.  
  17000.    PRINT "Enter 0 to end."
  17001.    DO
  17002.        INPUT "Find cosine of: ",Num
  17003.        IF Num = 0 THEN EXIT DO
  17004.        PRINT "COS(" NumRemBlanks$(Num) ") = " COS(Num)
  17005.    LOOP
  17006.  
  17007.  ■ Output
  17008.  
  17009.    Enter 0 to end.
  17010.    Find cosine of: 3.1
  17011.    COS(3.1) = -.9991351
  17012.    Find cosine of: 0
  17013.  
  17014.  
  17015.  ────────────────────────────────────────────────────────────────────────────
  17016.  STRIG Function and Statement
  17017.  ────────────────────────────────────────────────────────────────────────────
  17018.  
  17019.  ■ Action
  17020.  
  17021.    Returns the status of a specified joystick trigger
  17022.  
  17023.  ■ Syntax 1 (Function)
  17024.  
  17025.    STRIG(n)
  17026.  
  17027.  ■ Syntax 2 (Statement)
  17028.  
  17029.    STRIG {ON | OFF}
  17030.  
  17031.  ■ Remarks
  17032.  
  17033.    The STRIG function is used to test the joystick trigger status. In
  17034.    previous versions of BASIC, the statement STRIG ON enables testing of the
  17035.    joystick triggers; STRIG OFF disables joystick trigger testing. QuickBASIC
  17036.    ignores STRIG ON and STRIG OFF statements──the statements are provided for
  17037.    compatibility with earlier versions.
  17038.  
  17039.    The numeric expression n is an unsigned integer in the range 0-7,
  17040.    indicating the joystick and trigger to check. The following list describes
  17041.    the values returned by the STRIG(n) function for different values of n:
  17042.  
  17043. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  17044.    Argument                 Value Returned
  17045.    ──────────────────────────────────────────────────────────────────────────
  17046.    0                        Returns -1 if the lower button on joystick A has
  17047.                             been pressed since the last STRIG(0) call;
  17048.                             otherwise returns 0
  17049.  
  17050.    1                        Returns -1 if the lower button on joystick A is
  17051.                             currently down; otherwise returns 0
  17052.  
  17053.    2                        Returns -1 if the lower button on joystick B has
  17054.    Argument                 Value Returned
  17055.    ──────────────────────────────────────────────────────────────────────────
  17056.   2                        Returns -1 if the lower button on joystick B has
  17057.                             been pressed since the last STRIG(2) call;
  17058.                             otherwise returns 0
  17059.  
  17060.    3                        Returns -1 if the lower button on joystick B is
  17061.                             currently down; otherwise returns 0
  17062.  
  17063.    4                        Returns -1 if the upper button on joystick A has
  17064.                             been pressed since the last STRIG(4) call;
  17065.                             otherwise returns 0
  17066.  
  17067.    5                        Returns -1 if the upper button on joystick A is
  17068.                             currently down; otherwise returns 0
  17069.  
  17070.    6                        Returns -1 if the upper button on joystick B has
  17071.                             been pressed since the last STRIG(6) call;
  17072.                             otherwise returns 0
  17073.  
  17074.    7                        Returns -1 if the upper button on joystick B is
  17075.    Argument                 Value Returned
  17076.    ──────────────────────────────────────────────────────────────────────────
  17077.   7                        Returns -1 if the upper button on joystick B is
  17078.                             currently down; otherwise returns 0
  17079.    ──────────────────────────────────────────────────────────────────────────
  17080.  
  17081.  
  17082.    You can also use event trapping to get information from the joystick by
  17083.    using the ON STRIG statement (see the ON event statement). You cannot use
  17084.    the STRIG function inside a joystick event trap because the event that
  17085.    caused the trap is destroyed.
  17086.  
  17087.  ■ Differences From Basica
  17088.  
  17089.    If you are compiling from the BC command line, you must use the /V or /W
  17090.    option if a program contains a STRIG statement.
  17091.  
  17092.  ■ See Also
  17093.  
  17094.    ON event; STRIG ON, OFF, and STOP
  17095.  
  17096.  ■ Example
  17097.  
  17098.    The following example illustrates STRIG:
  17099.  
  17100.    'Wait for trigger A to be pressed.
  17101.    DO
  17102.       GotATrig = STRIG(0)
  17103.    LOOP UNTIL GotATrig
  17104.    'As long as trigger A is down, beep.
  17105.    DO
  17106.       GotATrig = STRIG(1)
  17107.       BEEP
  17108.    LOOP WHILE GotATrig
  17109.  
  17110.  
  17111.  ────────────────────────────────────────────────────────────────────────────
  17112.  STRIG ON, OFF, and STOP Statements
  17113.  ────────────────────────────────────────────────────────────────────────────
  17114.  
  17115.  ■ Action
  17116.  
  17117.    Enables, disables, or inhibits trapping of joystick activity
  17118.  
  17119.  ■ Syntax
  17120.  
  17121.    STRIG(n) ON
  17122.    STRIG(n) OFF
  17123.    STRIG(n) STOP
  17124.  
  17125.  ■ Remarks
  17126.  
  17127.    The argument, n, is a numeric expression indicating the joystick button to
  17128.    trap:
  17129.  
  17130.    Value                    Button
  17131.    ──────────────────────────────────────────────────────────────────────────
  17132.    0                        Lower button, joystick A
  17133.    2                        Lower button, joystick B
  17134.    4                        Upper button, joystick A
  17135.    6                        Upper button, joystick B
  17136.    ──────────────────────────────────────────────────────────────────────────
  17137.  
  17138.    The STRIG(n) ON statement enables joystick event trapping by an ON STRIG
  17139.    statement (see the ON event statement). While trapping is enabled, and if
  17140.    a nonzero line number is specified in the ON STRIG statement, BASIC checks
  17141.    between every statement to see if the joystick trigger has been pressed.
  17142.  
  17143.    The STRIG(n) OFF statement disables event trapping. If a subsequent event
  17144.    occurs (i.e., if the trigger is pressed), it will not be remembered when
  17145.    the next STRIG ON is executed.
  17146.  
  17147.    The STRIG(n) STOP statement inhibits event trapping. If an event occurs it
  17148.    is remembered, and the event trap takes place as soon as trapping is
  17149.    reenabled.
  17150.  
  17151.  ■ See Also
  17152.  
  17153.    ON event, STRIG
  17154.  
  17155.  ■ Example
  17156.  
  17157.    There is no programming example for the STRIG statement.
  17158.  
  17159.  
  17160.  ────────────────────────────────────────────────────────────────────────────
  17161.  STRING$ Function
  17162.  ────────────────────────────────────────────────────────────────────────────
  17163.  
  17164.  ■ Action
  17165.  
  17166.    Returns a string whose characters all have a given ASCII code or whose
  17167.    characters are all the first character of a string expression
  17168.  
  17169.  ■ Syntax
  17170.  
  17171.    STRING$(m,n)
  17172.    STRING$(m,stringexpression)
  17173.  
  17174.  ■ Remarks
  17175.  
  17176.    The STRING$ function has the following arguments:
  17177.  
  17178.    Argument                 Description
  17179.    ──────────────────────────────────────────────────────────────────────────
  17180.    m                        A numeric expression indicating the length of the
  17181.                             string to return.
  17182.  
  17183.    n                        The ASCII code of the character to use to build
  17184.                             the string. It is a numeric expression that
  17185.                             evaluates to an integer value in the range 0-255.
  17186.  
  17187.    stringexpression         The string expression whose first character is
  17188.                             used to build the return string.
  17189.    ──────────────────────────────────────────────────────────────────────────
  17190.  
  17191.  ■ Examples
  17192.  
  17193.    The following example uses STRING$ to create part of a report heading:
  17194.  
  17195.    Dash$ = STRING$(10,45)
  17196.    PRINT Dash$;"MONTHLY REPORT";Dash$
  17197.  
  17198.  ■ Output
  17199.  
  17200.    ----------MONTHLY REPORT----------
  17201.  
  17202.    The following program uses STRING$ to generate a bar graph:
  17203.  
  17204.    PRINT TAB(7);"Daily Mean Temperature in Seattle" :
  17205.    PRINT
  17206.    'Get data for each month and graph.
  17207.    FOR Month = 1 TO 12 STEP 2
  17208.        READ Month$, Temp
  17209.        'Print Temp-35 stars.
  17210.        PRINT Month$;" +"; STRING$(Temp-35,"*")
  17211.        PRINT "    |"
  17212.    NEXT Month
  17213.  
  17214.    'Print horizontal line.
  17215.    PRINT "    +";
  17216.    FOR X = 1 TO 7
  17217.        PRINT "----+";
  17218.    NEXT X
  17219.    PRINT
  17220.  
  17221.    'Print temperature labels.
  17222.    FOR X = 4 TO 39 STEP 5
  17223.        PRINT TAB(X); X+31;
  17224.    NEXT X
  17225.    PRINT
  17226.  
  17227.    DATA Jan, 40, Mar, 46, May, 56
  17228.    DATA Jul, 66, Sep, 61, Nov, 46
  17229.  
  17230.  ■ Output
  17231.  
  17232.    Daily Mean Temperature in Seattle
  17233.  
  17234.    Jan +*****
  17235.        |
  17236.    Mar +***********
  17237.        |
  17238.    May +*********************
  17239.        |
  17240.    Jul +*******************************
  17241.        |
  17242.    Sep +**************************
  17243.        |
  17244.    Nov +***********
  17245.        |
  17246.        +----+----+----+----+----+----+----+
  17247.        35   40   45   50   55   60   65   70
  17248.  
  17249.  
  17250.  ────────────────────────────────────────────────────────────────────────────
  17251.  SUB Statements
  17252.  ────────────────────────────────────────────────────────────────────────────
  17253.  
  17254.  ■ Action
  17255.  
  17256.    Marks the beginning and end of a subprogram
  17257.  
  17258.  ■ Syntax
  17259.  
  17260.    SUB globalname«(parameterlist)» «STATIC»
  17261.    .
  17262.    .
  17263.    .
  17264.    «EXIT SUB»
  17265.    .
  17266.    .
  17267.    .
  17268.    END SUB
  17269.  
  17270.  ■ Remarks
  17271.  
  17272.    The SUB statement takes the following arguments:
  17273.  
  17274.    Argument                 Description
  17275.    ──────────────────────────────────────────────────────────────────────────
  17276.    globalname               A variable name up to 40 characters long. This
  17277.                             name cannot appear in any other FUNCTION or SUB
  17278.                             statement in the same program or the user
  17279.                             library.
  17280.  
  17281.    parameterlist            Contains the names of simple variables and arrays
  17282.                             passed to the subprogram when the SUB is invoked.
  17283.                             Each name is separated from the preceding name by
  17284.                             a comma. Note that these variables and arrays are
  17285.                             passed by reference, so any change to an
  17286.                             argument's value in the subprogram also changes
  17287.                             its value in the calling program. See below for a
  17288.                             complete description of the syntax.
  17289.    ──────────────────────────────────────────────────────────────────────────
  17290.  
  17291.    A SUB parameterlist has the following syntax:
  17292.  
  17293.    variable«( )» «AS type» «, variable«( )» «AS type»»...
  17294.  
  17295.    A variable is a BASIC variable name. Previous versions of BASIC required
  17296.    the number of dimensions in parentheses after an array name. In
  17297.    QuickBASIC, the number of dimensions is not required. The argument type is
  17298.    the type of the variable. The type argument can be INTEGER, LONG, SINGLE,
  17299.    DOUBLE, STRING, or a user-defined type. You may not use a fixed-length
  17300.    string, or an array of fixed-length strings, as a parameter. However, you
  17301.    may use a simple fixed-length string as an argument in a CALL
  17302.    statement──QuickBASIC converts a simple fixed-length string argument to a
  17303.    variable-length string argument before passing the string to a SUB.
  17304.  
  17305.    A subprogram is a separate procedure, like a FUNCTION. However, a SUB
  17306.    cannot be used in an expression, unlike a FUNCTION.
  17307.  
  17308.    SUB and END SUB mark the beginning and end of a subprogram. You may also
  17309.    use the optional EXIT SUB statement to exit a subprogram.
  17310.  
  17311.    Subprograms are called by a CALL statement or by using the subprogram name
  17312.    followed by the argument list. See the entry for the CALL statement.
  17313.    QuickBASIC subprograms can be recursive──they can call themselves to
  17314.    perform a given task. See the second example below and Section 4.4,
  17315.    "Recursion."
  17316.  
  17317.    The STATIC attribute indicates that all variables local to the SUB are
  17318.    static──their values are saved between calls. Using the STATIC keyword
  17319.    slightly increases execution speed. STATIC is not usually used with
  17320.    recursive subprograms. See the examples below.
  17321.  
  17322.    Any subprogram variables or arrays are considered local to that subprogram
  17323.    unless they are explicitly declared as shared variables in a SHARED
  17324.    statement. You cannot define SUB procedures, DEF FN functions, or FUNCTION
  17325.    procedures inside a SUB procedure.
  17326.  
  17327.  ────────────────────────────────────────────────────────────────────────────
  17328.  NOTE
  17329.    You cannot use GOSUB, GOTO, or RETURN to enter or exit a subprogram.
  17330.  ────────────────────────────────────────────────────────────────────────────
  17331.  
  17332.    See Chapter 2, "SUB and FUNCTION Procedures," in Programming in BASIC for
  17333.    more information.
  17334.  
  17335.  ■ See Also
  17336.  
  17337.    CALL (BASIC), DECLARE (BASIC), SHARED, STATIC
  17338.  
  17339.  ■ Examples
  17340.  
  17341.    In this example, the main program calls a subprogram, LINESEARCH, which
  17342.    searches for the given string, P$, in each line of input from file F$.
  17343.    When the subprogram finds P$ in a line, it prints the line, along with the
  17344.    number of the line. Notice that the value of Num is saved between calls
  17345.    because the STATIC keyword is used on the SUB statement.
  17346.  
  17347.    INPUT "File to be searched";F$
  17348.    INPUT "Pattern to search for";P$
  17349.    OPEN F$ FOR INPUT AS #1
  17350.    DO WHILE NOT EOF(1)
  17351.       LINE INPUT #1, Test$
  17352.       CALL Linesearch(Test$,P$)
  17353.    LOOP
  17354.  
  17355.    SUB Linesearch(Test$,P$) STATIC
  17356.       Num = Num + 1
  17357.       X = INSTR(Test$,P$)
  17358.       IF X > 0 THEN PRINT "Line #";Num;": ";Test$
  17359.    END SUB
  17360.  
  17361.  ■ Output
  17362.  
  17363.    File to be searched? search.bas
  17364.    Pattern to search for? SUB
  17365.    Line # 9 : SUB Linesearch(Test$,P$) STATIC
  17366.    Line # 13 : END SUB
  17367.  
  17368.    The following example uses a recursive SUB to solve the classic Tower of
  17369.    Hanoi puzzle for a variable number of disks. For large numbers of disks,
  17370.    the stack size must be increased using the CLEAR statement.
  17371.  
  17372.    DECLARE SUB Hanoi (N%, Srce%, Dest%, Hold%)
  17373.    DEFINT A-Z
  17374.    DIM SHARED MoveCount
  17375.  
  17376.    MoveCount = 0
  17377.    CLS
  17378.    PRINT "Tower of Hanoi Puzzle"
  17379.    INPUT "Enter number of disks: ", Disks
  17380.  
  17381.    ' Call the recursive Hanoi SUB to solve the puzzle.
  17382.    CALL Hanoi(Disks, 1, 3, 2)
  17383.  
  17384.    PRINT "Puzzle complete in"; MoveCount; "moves."
  17385.  
  17386.    END
  17387.  
  17388.    ' Move N disks from Srce to Dest using Hold as holding peg.
  17389.    SUB Hanoi (N, Srce, Dest, Hold)
  17390.       IF N <= 1 THEN
  17391.          ' Only 1 disk. Move it directly to Dest.
  17392.          PRINT "Move a disk from"; Srce; "to"; Dest
  17393.          MoveCount = MoveCount + 1
  17394.       ELSE
  17395.          ' More than one disk.
  17396.          ' Move the N-1 disks to Hold, using Dest as holding peg.
  17397.          CALL Hanoi(N - 1, Srce, Hold, Dest)
  17398.          ' Move the Nth disk directly to Dest.
  17399.          PRINT "Move a disk from"; Srce; "to"; Dest:
  17400.          MoveCount = MoveCount + 1
  17401.          ' Move the N-1 disks to Dest, using Srce as holding peg.
  17402.          CALL Hanoi(N - 1, Hold, Dest, Srce)
  17403.       END IF
  17404.    END SUB
  17405.  
  17406.  ■ Output
  17407.  
  17408.    Tower of Hanoi Puzzle
  17409.    Enter number of disks: 3
  17410.    Move a disk from 1 to 3
  17411.    Move a disk from 1 to 2
  17412.    Move a disk from 3 to 2
  17413.    Move a disk from 1 to 3
  17414.    Move a disk from 2 to 1
  17415.    Move a disk from 2 to 3
  17416.    Move a disk from 1 to 3
  17417.    Puzzle complete in 7 moves.
  17418.  
  17419.  
  17420.  ────────────────────────────────────────────────────────────────────────────
  17421.  SWAP Statement
  17422.  ────────────────────────────────────────────────────────────────────────────
  17423.  
  17424.  ■ Action
  17425.  
  17426.    Exchanges the values of two variables
  17427.  
  17428.  ■ Syntax
  17429.  
  17430.    SWAP variable1,variable2
  17431.  
  17432.  ■ Remarks
  17433.  
  17434.    Any type of variable can be swapped (integer, long, single precision,
  17435.    double precision, string, or record). However, the two variables must be
  17436.    exactly the same type or an error message appears (Type mismatch). For
  17437.    example, trying to swap an integer with a single-precision value produces
  17438.    Type mismatch.
  17439.  
  17440.  ■ Example
  17441.  
  17442.    The following subroutine (ShellSort) sorts the elements of a string array
  17443.    in descending order using a Shell sort. ShellSort uses SWAP to exchange
  17444.    array elements that are out of order.
  17445.  
  17446.    ' Sort the word list using a Shell sort.
  17447.    SUB ShellSort (Array$(), Num%) STATIC
  17448.       Span% = Num% \ 2
  17449.       DO WHILE Span% > 0
  17450.          FOR I% = Span% TO Num% - 1
  17451.  
  17452.              J% = I% - Span% + 1
  17453.          FOR J% = (I% - Span% + 1) TO 1 STEP -Span%
  17454.  
  17455.       IF Array$(J%) <= Array$(J% + Span%) THEN EXIT FOR
  17456.        ' Swap array elements that are out of order.
  17457.        SWAP Array$(J%), Array$(J% + Span%)
  17458.     NEXT J%
  17459.  
  17460.          NEXT I%
  17461.          Span% = Span% \ 2
  17462.       LOOP
  17463.    END SUB
  17464.  
  17465.  
  17466.  ────────────────────────────────────────────────────────────────────────────
  17467.  SYSTEM Statement
  17468.  ────────────────────────────────────────────────────────────────────────────
  17469.  
  17470.  ■ Action
  17471.  
  17472.    Closes all open files and returns control to the operating system
  17473.  
  17474.  ■ Syntax
  17475.  
  17476.    SYSTEM
  17477.  
  17478.  ■ Remarks
  17479.  
  17480.    When a SYSTEM command is executed, all files are closed and BASIC exits to
  17481.    the operating system (for stand-alone executable programs) or stops
  17482.    program execution (if the program is run in the QuickBASIC environment).
  17483.  
  17484.  ────────────────────────────────────────────────────────────────────────────
  17485.  NOTE
  17486.    A program containing a SYSTEM statement exits to the operating system if
  17487.    run from the QuickBASIC command line with the /RUN option. Entering a
  17488.    SYSTEM statement in the Immediate window terminates QuickBASIC.
  17489.  ────────────────────────────────────────────────────────────────────────────
  17490.  
  17491.  ■ Differences From Basica
  17492.  
  17493.    END and SYSTEM are distinct in BASICA but act identically in QuickBASIC.
  17494.  
  17495.  ■ Example
  17496.  
  17497.    There is no programming example for the SYSTEM statement.
  17498.  
  17499.  
  17500.  ────────────────────────────────────────────────────────────────────────────
  17501.  TAB Function
  17502.  ────────────────────────────────────────────────────────────────────────────
  17503.  
  17504.  ■ Action
  17505.  
  17506.    Moves the print position
  17507.  
  17508.  ■ Syntax
  17509.  
  17510.    TAB(column)
  17511.  
  17512.  ■ Remarks
  17513.  
  17514.    The argument, column, is a numeric expression that is the column number of
  17515.    the new print position. If the current print position is already beyond
  17516.    column, the TAB function moves the print position to that column on the
  17517.    next line. Column 1 is the leftmost position, and the rightmost position
  17518.    is the current line width of the output device minus one. If column is
  17519.    greater than the output width, TAB wraps the output and the print position
  17520.    becomes 1 + (column MOD width). If column is less than 1, TAB moves the
  17521.    print position to column 1.
  17522.  
  17523.    TAB can only be used in PRINT and LPRINT statements.
  17524.  
  17525.  ■ See Also
  17526.  
  17527.    WIDTH
  17528.  
  17529.  ■ Examples
  17530.  
  17531.    The following example uses TAB to locate columns of output:
  17532.  
  17533.    FOR I = 1 TO 4
  17534.       READ A$,B$
  17535.       PRINT A$ TAB(25) B$
  17536.    NEXT
  17537.    DATA NAME, AMOUNT,,, G.T. JONES, $25.00, H.L. STEVENS, $32.25
  17538.  
  17539.  ■ Output
  17540.  
  17541.    NAME                    AMOUNT
  17542.  
  17543.    G.T. JONES              $25.00
  17544.    H.L. STEVENS            $32.25
  17545.  
  17546.    The following example shows the effects of different values used as
  17547.    arguments to TAB:
  17548.  
  17549.    'Assumes 80-column screen width.
  17550.    PRINT TAB(1287); "one"
  17551.    PRINT TAB(255); "two"
  17552.    PRINT TAB(-5); "three"
  17553.    PRINT "123456789012345678901234567890" TAB(20) "four"
  17554.  
  17555.  ■ Output
  17556.  
  17557.          one
  17558.                  two
  17559.    three
  17560.    123456789012345678901234567890
  17561.                       four
  17562.  
  17563.  
  17564.  ────────────────────────────────────────────────────────────────────────────
  17565.  TAN Function
  17566.  ────────────────────────────────────────────────────────────────────────────
  17567.  
  17568.  ■ Action
  17569.  
  17570.    Returns the tangent of the angle x, where x is in radians
  17571.  
  17572.  ■ Syntax
  17573.  
  17574.    TAN(x)
  17575.  
  17576.  ■ Remarks
  17577.  
  17578.    TAN is calculated with single-precision accuracy unless x is a
  17579.    double-precision value, in which case TAN is calculated with
  17580.    double-precision accuracy.
  17581.  
  17582.  ■ Differences From Basica
  17583.  
  17584.    In BASICA, if TAN overflows, the interpreter displays the Overflow error
  17585.    message, returns machine infinity as the result, and continues execution.
  17586.  
  17587.    If TAN overflows, QuickBASIC does not display machine infinity and
  17588.    execution halts (unless the program has an error-handling routine).
  17589.  
  17590.  ■ Example
  17591.  
  17592.    The following example computes the height of an object using the distance
  17593.    from the object and the angle of elevation. The program draws the triangle
  17594.    produced by the base and the computed height.
  17595.  
  17596.    SCREEN 2
  17597.  
  17598.    INPUT "LENGTH OF BASE: ",Baselen
  17599.    INPUT "ANGLE OF ELEVATION (DEGREES,MINUTES): ",Deg,Min
  17600.  
  17601.    Ang = (3.141593/180)*(Deg + Min/60)   'Convert to radians.
  17602.    Height = Baselen*TAN(Ang)      'Calculate height.
  17603.    PRINT "HEIGHT =" Height
  17604.    H = 180 - Height
  17605.    B = 15 + Baselen
  17606.  
  17607.    LINE (15,180)-(B,180):LINE -(B,H)       'Draw triangle.
  17608.    LINE -(10,180)
  17609.    LOCATE 24,1 : PRINT "Press any key to continue...";
  17610.    DO
  17611.    LOOP WHILE INKEY$=""
  17612.  
  17613.  
  17614.  ────────────────────────────────────────────────────────────────────────────
  17615.  TIME$ Function
  17616.  ────────────────────────────────────────────────────────────────────────────
  17617.  
  17618.  ■ Action
  17619.  
  17620.    Returns the current time from the operating system
  17621.  
  17622.  ■ Syntax
  17623.  
  17624.    TIME$
  17625.  
  17626.  ■ Remarks
  17627.  
  17628.    The TIME$ function returns an eight-character string in the pattern
  17629.    hh:mm:ss, where hh is the hour (00-23), mm is minutes (00-59), and ss is
  17630.    seconds (00-59). A 24-hour clock is used; therefore, 8:00 PM is shown as
  17631.    20:00:00.
  17632.  
  17633.    To set the time, use the TIME$ statement.
  17634.  
  17635.  ■ See Also
  17636.  
  17637.    TIME$ Statement, TIMER
  17638.  
  17639.  ■ Example
  17640.  
  17641.    The following example converts the 24-hour time returned by TIME$ to a
  17642.    12-hour time:
  17643.  
  17644.    'Convert the 24-hour clock used by TIME$ to
  17645.    '12-hour output followed by "AM" or "PM."
  17646.    T$ = TIME$
  17647.    Hr = VAL(T$)
  17648.    IF Hr < 12 THEN Ampm$ = " AM" ELSE Ampm$ = " PM"
  17649.    IF Hr > 12 THEN Hr = Hr - 12
  17650.    PRINT "The time is" STR$(Hr) RIGHT$(T$,6) Ampm$
  17651.  
  17652.  ■ Output
  17653.  
  17654.    The time is 11:26:31 AM
  17655.  
  17656.  
  17657.  ────────────────────────────────────────────────────────────────────────────
  17658.  TIMER Function
  17659.  ────────────────────────────────────────────────────────────────────────────
  17660.  
  17661.  ■ Action
  17662.  
  17663.    Returns the number of seconds elapsed since midnight
  17664.  
  17665.  ■ Syntax
  17666.  
  17667.    TIMER
  17668.  
  17669.  ■ Remarks
  17670.  
  17671.    The TIMER function can be used with the RANDOMIZE statement to generate a
  17672.    random number. It can also be used to time programs or parts of programs.
  17673.  
  17674.  ■ Example
  17675.  
  17676.    The following program searches for the prime numbers from 3 to 10,000
  17677.    using a variation of the Sieve of Eratosthenes. The TIMER function is used
  17678.    to time the program.
  17679.  
  17680.    DEFINT A-Z
  17681.    CONST UNMARK = 0, MARKIT = NOT UNMARK
  17682.    DIM Mark(10000)
  17683.    Start! = TIMER
  17684.    Num = 0
  17685.    FOR N = 3 TO 10000 STEP 2
  17686.       IF NOT Mark(N) THEN
  17687.          'PRINT N,   'To print the primes, remove the
  17688.                      'remark delimiter in front of the
  17689.                      'PRINT statement.
  17690.          Delta = 2*N
  17691.          FOR I = 3*N TO 10000 STEP Delta
  17692.             Mark(I) = MARKIT
  17693.          NEXT
  17694.          Num = Num + 1
  17695.       END IF
  17696.    NEXT
  17697.    Finish! = TIMER
  17698.    PRINT : PRINT "Program took"; Finish!-Start!;
  17699.    PRINT "seconds to find the"; Num; "primes"
  17700.    END
  17701.  
  17702.  ■ Output
  17703.  
  17704.    Program took .1601563 seconds to find the 1228 primes
  17705.  
  17706.  
  17707.  ────────────────────────────────────────────────────────────────────────────
  17708.  TIMER ON, OFF, and STOP Statements
  17709.  ────────────────────────────────────────────────────────────────────────────
  17710.  
  17711.  ■ Action
  17712.  
  17713.    Enables, disables, or inhibits timer event trapping
  17714.  
  17715.  ■ Syntax
  17716.  
  17717.    TIMER ON
  17718.    TIMER OFF
  17719.    TIMER STOP
  17720.  
  17721.  ■ Remarks
  17722.  
  17723.    TIMER ON enables timer event trapping by an ON TIMER statement (see the
  17724.    statement ON event). While trapping is enabled, a check is made after
  17725.    every statement to see if the specified time has elapsed. If it has, the
  17726.    ON TIMER event-handling routine is executed.
  17727.  
  17728.    TIMER OFF disables timer event trapping. If an event takes place, it is
  17729.    not remembered if a subsequent TIMER ON is executed.
  17730.  
  17731.    TIMER STOP disables the timer event trapping. However, if an event occurs,
  17732.    it is remembered and the ON TIMER event-handling routine is executed as
  17733.    soon as trapping is reenabled with TIMER ON.
  17734.  
  17735.  ■ See Also
  17736.  
  17737.    ON event
  17738.  
  17739.  ■ Example
  17740.  
  17741.    The following example displays the time of day on line 1, and updates the
  17742.    display once a minute:
  17743.  
  17744.    TIMER ON
  17745.    ON TIMER(60) GOSUB Display
  17746.    DO WHILE INKEY$ = "" : LOOP
  17747.    END
  17748.  
  17749.    Display:
  17750.        Oldrow = CSRLIN       'Save current row.
  17751.        Oldcol = POS(0)       'Save current column.
  17752.        LOCATE 1,1 : PRINT TIME$;
  17753.        LOCATE Oldrow,Oldcol   'Restore row & column.
  17754.    RETURN
  17755.  
  17756.  
  17757.  ────────────────────────────────────────────────────────────────────────────
  17758.  TIME$ Statement
  17759.  ────────────────────────────────────────────────────────────────────────────
  17760.  
  17761.  ■ Action
  17762.  
  17763.    Sets the time
  17764.  
  17765.  ■ Syntax
  17766.  
  17767.    TIME$=stringexpression
  17768.  
  17769.  ■ Remarks
  17770.  
  17771.    The stringexpression must be in one of the following forms:
  17772.  
  17773.    Form                     Description
  17774.    ──────────────────────────────────────────────────────────────────────────
  17775.    hh                       Sets the hour; minutes and seconds default to 00
  17776.    hh:mm                    Sets the hour and minutes; seconds default to 00
  17777.    hh:mm:ss                 Sets the hour, minutes, and seconds
  17778.    ──────────────────────────────────────────────────────────────────────────
  17779.  
  17780.    A 24-hour clock is used, so 8:00 PM would be entered as 20:00:00.
  17781.  
  17782.    This statement complements the TIME$ function, which returns the current
  17783.    time.
  17784.  
  17785.  ■ See Also
  17786.  
  17787.    TIME$ Function
  17788.  
  17789.  ■ Example
  17790.  
  17791.    The following example sets the current time to 8:00 AM:
  17792.  
  17793.    TIME$="08:00:00"
  17794.  
  17795.  
  17796.  ────────────────────────────────────────────────────────────────────────────
  17797.  TRON/TROFF Statements
  17798.  ────────────────────────────────────────────────────────────────────────────
  17799.  
  17800.  ■ Action
  17801.  
  17802.    Traces the execution of program statements
  17803.  
  17804.  ■ Syntax
  17805.  
  17806.    TRON
  17807.    TROFF
  17808.  
  17809.  ■ Remarks
  17810.  
  17811.    In the QuickBASIC environment, executing a TRON statement has the same
  17812.    effect as selecting Trace On from the Debug menu──each statement is
  17813.    highlighted on the screen as it executes.
  17814.  
  17815.    The TROFF statement turns off the program trace.
  17816.  
  17817.    The TRON and TROFF statements only display line numbers when compiled with
  17818.    the Debug option or the /D option on the BC command line.
  17819.  
  17820.  ────────────────────────────────────────────────────────────────────────────
  17821.  NOTE
  17822.    The debugging features of the QuickBASIC environment make these statements
  17823.    unnecessary.
  17824.  ────────────────────────────────────────────────────────────────────────────
  17825.  
  17826.  ■ Example
  17827.  
  17828.    There is no programming example for the TRON statement.
  17829.  
  17830.  
  17831.  ────────────────────────────────────────────────────────────────────────────
  17832.  TYPE Statement
  17833.  ────────────────────────────────────────────────────────────────────────────
  17834.  
  17835.  ■ Action
  17836.  
  17837.    Defines a data type containing one or more elements
  17838.  
  17839.  ■ Syntax
  17840.  
  17841.    TYPE usertype
  17842.       elementname AS typename
  17843.       elementname AS typename
  17844.    .
  17845.    .
  17846.    .
  17847.    END TYPE
  17848.  
  17849.  ■ Remarks
  17850.  
  17851.    The TYPE statement takes the following arguments:
  17852.  
  17853.    Argument                 Description
  17854.    ──────────────────────────────────────────────────────────────────────────
  17855.    usertype                 A name given to the user-defined data type.
  17856.                             Follows the same rules as a BASIC variable name.
  17857.  
  17858.    elementname              The name of an element of the user-defined data
  17859.                             type. Follows the same rules as a BASIC variable
  17860.                             name. Cannot be the name of an array.
  17861.  
  17862.    typename                 May be any of the following BASIC data types:
  17863.                             INTEGER, LONG, SINGLE, DOUBLE, fixed-length
  17864.                             string (see note below), or user-defined type.
  17865.    ──────────────────────────────────────────────────────────────────────────
  17866.  
  17867.  ────────────────────────────────────────────────────────────────────────────
  17868.  NOTE
  17869.    Strings in user types must be fixed-length strings. String lengths are
  17870.    indicated by an asterisk and a numeric constant. For example, the
  17871.    following line defines an element named Keyword in a user-defined type as
  17872.    a string with length 40:
  17873.  
  17874.    Keyword AS STRING*40
  17875.  
  17876.  ────────────────────────────────────────────────────────────────────────────
  17877.  
  17878.    A user-defined type must be declared in a TYPE declaration before it can
  17879.    be used in the program. Although a user-defined type can only be declared
  17880.    in the module-level code, you may declare a variable to be of a
  17881.    user-defined type anywhere in the module, even in a SUB or FUNCTION.
  17882.  
  17883.    Use the DIM, REDIM, COMMON, STATIC, or SHARED statements to declare a
  17884.    variable to be of a user-defined type.
  17885.  
  17886.  ■ Example
  17887.  
  17888.    The following example simulates a deck of cards by using a user-defined
  17889.    type. The program builds a deck of cards (an array of user-defined type
  17890.    Card), shuffles the deck, and displays the first five cards.
  17891.  
  17892.    ' This program uses a user-defined type to
  17893.    ' simulate a deck of cards.
  17894.  
  17895.    ' Define the Card type--an integer value and a string
  17896.    ' representing the suit.
  17897.    TYPE Card
  17898.       Value AS INTEGER
  17899.       Suit AS STRING*9
  17900.    END TYPE
  17901.  
  17902.    DEFINT A-Z
  17903.    ' Define the Deck as a 52-element array of Cards.
  17904.    DIM Deck(1 TO 52) AS Card
  17905.  
  17906.    ' Build, shuffle, and deal the top five cards.
  17907.    CALL BuildDeck(Deck())
  17908.    CALL Shuffle(Deck())
  17909.    FOR I%=1 TO 5
  17910.       CALL ShowCard(Deck(I%))
  17911.    NEXT I%
  17912.  
  17913.    ' Build the deck--fill the array of Cards with
  17914.    ' appropriate values.
  17915.    SUB BuildDeck(Deck(1) AS Card) STATIC
  17916.    DIM Suits(4) AS STRING*9
  17917.  
  17918.       Suits(1)="Hearts"
  17919.       Suits(2)="Clubs"
  17920.       Suits(3)="Diamonds"
  17921.       Suits(4)="Spades"
  17922.    ' This loop controls the suit.
  17923.       FOR I%=1 TO 4
  17924.        ' This loop controls the face value.
  17925.          FOR J%=1 TO 13
  17926.           ' Figure out which card (1...52) you're creating.
  17927.             CardNum%=J%+(I%-1)*13
  17928.           ' Place the face value and suit into the Card.
  17929.             Deck(CardNum%).Value=J%
  17930.             Deck(CardNum%).Suit=Suits(I%)
  17931.          NEXT J%
  17932.       NEXT I%
  17933.  
  17934.    END SUB
  17935.  
  17936.    ' Shuffle a deck (an array containing Card elements).
  17937.    SUB Shuffle(Deck(1) AS Card) STATIC
  17938.  
  17939.       RANDOMIZE TIMER
  17940.    ' Shuffle by transposing 1000 randomly selected pairs of cards.
  17941.       FOR I%=1 TO 1000
  17942.          CardOne%=INT(52*RND+1)
  17943.          CardTwo%=INT(52*RND+1)
  17944.       ' Notice that SWAP works on arrays of user types.
  17945.          SWAP Deck(CardOne%),Deck(CardTwo%)
  17946.       NEXT I%
  17947.  
  17948.    END SUB
  17949.  
  17950.    ' Display a single card by converting and printing the
  17951.    ' face value and the suit.
  17952.    SUB ShowCard (SingleCard AS Card) STATIC
  17953.  
  17954.       SELECT CASE SingleCard.Value
  17955.          CASE 13
  17956.             PRINT "King ";
  17957.          CASE 12
  17958.             PRINT "Queen";
  17959.          CASE 11
  17960.             PRINT "Jack ";
  17961.          CASE  1
  17962.             PRINT "Ace  ";
  17963.          CASE ELSE
  17964.             PRINT USING "  ## ";SingleCard.Value;
  17965.       END SELECT
  17966.  
  17967.       PRINT " ";SingleCard.Suit
  17968.  
  17969.    END SUB
  17970.  
  17971.  ■ Output
  17972.  
  17973.       3  Clubs
  17974.       4  Hearts
  17975.       3  Diamonds
  17976.    Jack  Clubs
  17977.       8  Spades
  17978.  
  17979.  
  17980.  ────────────────────────────────────────────────────────────────────────────
  17981.  UBOUND Function
  17982.  ────────────────────────────────────────────────────────────────────────────
  17983.  
  17984.  ■ Action
  17985.  
  17986.    Returns the upper bound (largest available subscript) for the indicated
  17987.    dimension of an array
  17988.  
  17989.  ■ Syntax
  17990.  
  17991.    UBOUND(array«,dimension»)
  17992.  
  17993.  ■ Remarks
  17994.  
  17995.    The argument dimension is an integer from 1 to the number of dimensions in
  17996.    array. For an array dimensioned as follows, UBOUND returns the values
  17997.    listed below:
  17998.  
  17999.    DIM A(1 TO 100, 1 TO 50, -3 TO 4)
  18000.  
  18001.    Invocation               Value Returned
  18002.    ──────────────────────────────────────────────────────────────────────────
  18003.    UBOUND(A,1)              100
  18004.    UBOUND(A,2)              50
  18005.    UBOUND(A,3)              4
  18006.    ──────────────────────────────────────────────────────────────────────────
  18007.  
  18008.    You can use the shortened syntax UBOUND(array) for one-dimensional arrays
  18009.    since the default value for dimension is 1. Use the LBOUND function to
  18010.    find the lower limit of an array dimension.
  18011.  
  18012.  ■ See Also
  18013.  
  18014.    LBOUND
  18015.  
  18016.  ■ Example
  18017.  
  18018.    LBOUND and UBOUND can be used together to determine the size of an array
  18019.    passed to a subprogram, as in the following program fragment:
  18020.  
  18021.    CALL PRNTMAT(ARRAY())
  18022.    .
  18023.    .
  18024.    .
  18025.    SUB PRNTMAT(A()) STATIC
  18026.        FOR I% = LBOUND(A,1) TO UBOUND(A,1)
  18027.        FOR J% = LBOUND(A,2) TO UBOUND(A,2)
  18028.            PRINT A(I%,J%);" ";
  18029.            NEXT J%
  18030.        PRINT:PRINT
  18031.        NEXT I%
  18032.    END SUB
  18033.  
  18034.  
  18035.  ────────────────────────────────────────────────────────────────────────────
  18036.  UCASE$ Function
  18037.  ────────────────────────────────────────────────────────────────────────────
  18038.  
  18039.  ■ Action
  18040.  
  18041.    Returns a string expression with all letters in uppercase
  18042.  
  18043.  ■ Syntax
  18044.  
  18045.    UCASE$ (stringexpression)
  18046.  
  18047.  ■ Remarks
  18048.  
  18049.    The stringexpression argument can be any string expression. The UCASE$
  18050.    function works with both variable- and fixed-length strings. The UCASE$
  18051.    and LCASE$ statements are helpful in making string comparisons case
  18052.    insensitive.
  18053.  
  18054.  ■ See Also
  18055.  
  18056.    LCASE$
  18057.  
  18058.  ■ Example
  18059.  
  18060.    The following program contains a FUNCTION, YesQues, that returns a Boolean
  18061.    value depending on how the user responds. The program YesQues uses UCASE$
  18062.    to make a case-insensitive test of the user's response.
  18063.  
  18064.    DEFINT A-Z
  18065.  
  18066.    FUNCTION YesQues(Prompt$,Row,Col) STATIC
  18067.       OldRow=CSRLIN
  18068.       OldCol=POS(0)
  18069.       ' Print prompt at Row, Col.
  18070.       LOCATE Row,Col : PRINT Prompt$ "(Y/N):";
  18071.       DO
  18072.          ' Get the user to press a key.
  18073.          DO
  18074.             Resp$=INKEY$
  18075.          LOOP WHILE Resp$=""
  18076.          Resp$=UCASE$(Resp$)
  18077.          ' Test to see if it's yes or no.
  18078.          IF Resp$="Y" OR Resp$="N" THEN
  18079.             EXIT DO
  18080.          ELSE
  18081.             BEEP
  18082.          END IF
  18083.       LOOP
  18084.       ' Print the response on the line.
  18085.       PRINT Resp$;
  18086.       ' Move the cursor back to the old position.
  18087.       LOCATE OldRow,OldCol
  18088.       ' Return a Boolean value by returning the result of a test.
  18089.       YesQues=(Resp$="Y")
  18090.    END FUNCTION
  18091.  
  18092.    DO
  18093.    LOOP WHILE NOT YesQues("Do you know the frequency?",12,5)
  18094.  
  18095.  
  18096.  ────────────────────────────────────────────────────────────────────────────
  18097.  UEVENT Statement
  18098.  ────────────────────────────────────────────────────────────────────────────
  18099.  
  18100.  ■ Action
  18101.  
  18102.    Enables, disables, or suspends event trapping for a user-defined event
  18103.  
  18104.  ■ Syntax
  18105.  
  18106.    UEVENT ON
  18107.    UEVENT OFF
  18108.    UEVENT STOP
  18109.  
  18110.  ■ Remarks
  18111.  
  18112.    The effects of the UEVENT statements are like that of other event-trapping
  18113.    statements. When UEVENT ON is executed, the event-trapping routine is
  18114.    enabled. Occurrences of the event trigger execution of the event-handling
  18115.    routine.
  18116.  
  18117.    When UEVENT OFF is executed, the event-trapping routine is disabled. Any
  18118.    occurrences of the event are ignored.
  18119.  
  18120.    When UEVENT STOP is executed, the event-trapping routine is suspended. An
  18121.    event occurrence is remembered and the event-trapping routine performed as
  18122.    soon as a UEVENT ON statement is executed.
  18123.  
  18124.  ■ See Also
  18125.  
  18126.    ON UEVENT
  18127.  
  18128.  ■ Example
  18129.  
  18130.    See the example for ON UEVENT.
  18131.  
  18132.  
  18133.  ────────────────────────────────────────────────────────────────────────────
  18134.  UNLOCK Statement
  18135.  ────────────────────────────────────────────────────────────────────────────
  18136.  
  18137.  ■ Action
  18138.  
  18139.    Releases locks applied to parts of a file
  18140.  
  18141.  ■ Syntax
  18142.  
  18143.    UNLOCK «#» filenumber «,{record | «start» TO end}»
  18144.  
  18145.  ■ Remarks
  18146.  
  18147.    The UNLOCK statement is used only after a LOCK statement. See the LOCK
  18148.    statement for a complete discussion.
  18149.  
  18150.    For binary-mode files, the arguments record, start, and end represent the
  18151.    number of a byte relative to the beginning of the file. The first byte in
  18152.    a file is byte 1.
  18153.  
  18154.    For random-access files, these arguments are the number of a record
  18155.    relative to the beginning of the file. The first record is record 1.
  18156.  
  18157.  ■ See Also
  18158.  
  18159.    LOCK
  18160.  
  18161.  ■ Example
  18162.  
  18163.    See the example for LOCK.
  18164.  
  18165.  
  18166.  ────────────────────────────────────────────────────────────────────────────
  18167.  Creating a User-Defined Event
  18168.  ────────────────────────────────────────────────────────────────────────────
  18169.  
  18170.    In previous versions of QuickBASIC, the only events that could be trapped
  18171.    were those already defined in the language: COM, KEY, PEN, PLAY, STRIG and
  18172.    TIMER. There was no way to define your own event.
  18173.  
  18174.    QuickBASIC 4.5 allows you to define your own event trap. When the event
  18175.    occurs, BASIC calls the routine that handles the trap, just as if the
  18176.    event were part of the QuickBASIC language.
  18177.  
  18178.    A user-defined event has three elements. The first is a routine that
  18179.    detects the event. The second is this routine's call to the BASIC
  18180.    procedure SetUEvent, which traps the event. The third is BASIC's call to a
  18181.    routine that handles the event.
  18182.  
  18183.    You create a user-defined event by writing two pieces of code. The first
  18184.    is the routine that detects the event. (The event could be a hardware
  18185.    interrupt, or perhaps an altered data value at a special memory location.)
  18186.    This routine can be written in BASIC, or other languages, such as C and
  18187.    assembler. (BASIC routines can be included in the main module. Code
  18188.    written in other languages must be separately compiled and added to a
  18189.    Quick Library.)
  18190.  
  18191.    The event-detecting routine must block; that is, it must sit waiting for
  18192.    the event. (A routine that does not block would have to be called
  18193.    repeatedly to see if the event has occurred. This defeats the purpose of a
  18194.    user-defined event, as it is no different from conventional polling.) When
  18195.    the event occurs, it calls the BASIC routine SetUEvent. It is this call
  18196.    that traps the event. BASIC then calls the event handler.
  18197.  
  18198.    The event handler is the second piece of code. The advantage of separating
  18199.    event trapping from event handling is that the handling can be tailored to
  18200.    the needs of the moment; the same event can be handled differently in
  18201.    different parts of the program.
  18202.  
  18203.    Let's consider a simple example to see how this works. Our hypothetical
  18204.    programmer has designed an interface board for home monitoring and
  18205.    control. One of its features is a mailbox alarm: opening the mailbox door
  18206.    closes a switch that sets the most-significant bit at a specific buss
  18207.    address.
  18208.  
  18209.    Here is a simple BASIC routine to monitor this switch. (The segment and
  18210.    address quantities are for illustration only. They are in the video RAM
  18211.    space, and probably wouldn't be useful for other kinds of interfaces.)
  18212.  
  18213.    MailBoxOpened:
  18214.  
  18215.       DEF SEG = &h9000              ' set the address segment
  18216.       value% = PEEK (&h1234)        ' read value at address in that segment
  18217.       IF value% THEN CALL SetUEvent ' tell BASIC event has occurred
  18218.       DEF SEG                       ' return to BASIC data segment
  18219.  
  18220.  ■ RETURN
  18221.  
  18222.    Value% is either zero, or has its MSB set. In the latter case it is
  18223.    logically "true" (indicating that the mailbox was opened), and the
  18224.    SetUEvent routine is called. This routine (which is part of BASIC) tells
  18225.    BASIC that the expected event has occurred, and it is time to execute the
  18226.    event-handling routine. All event-detecting routines, regardless of the
  18227.    languages they are written in, must call SetUEvent.
  18228.  
  18229.    If the event-detecting routine is in a language other than BASIC, the
  18230.    Quick Library containing it has to be loaded before a QuickBASIC program
  18231.    that uses it can run or be compiled. Include a DECLARE SUB statement in
  18232.    the module calling the event-detection routine, so that BASIC knows how to
  18233.    find it.
  18234.  
  18235.    Now let's write an event-handling routine to tell our programmer his mail
  18236.    has arrived:
  18237.  
  18238.    MailCame:
  18239.  
  18240.       PRINT "Ta-Dah! Your day is made! The mail came!"
  18241.  
  18242.  ■ RETURN
  18243.  
  18244.    All that's left is to tell BASIC about the user-defined event handler,
  18245.    using the ON UEVENT statement. ON UEVENT works just like ON EVENT; it
  18246.    associates the user-defined event with the event-handling routine:
  18247.  
  18248.    ON UEVENT GOSUB MailCame  ' associate the handler routine with user event
  18249.    UEVENT ON                 ' initiate user-event trapping
  18250.       .
  18251.       .
  18252.       .
  18253.    CALL MailBoxOpened        ' call the routine that looks for the event
  18254.       .
  18255.       .
  18256.       .
  18257.    END
  18258.  
  18259.    Note that ON UEVENT deals only with the event-handler; it is not concerned
  18260.    with event-detection. Once the UEVENT ON statement has been executed, any
  18261.    call to SetUEvent will trigger the specified event-handler, regardless of
  18262.    how or where the call is issued.
  18263.  
  18264.    Here is a summary of the steps in creating and using a user-defined event
  18265.    handler:
  18266.  
  18267.    1. Write the routine that detects the event. When the event occurs, the
  18268.       routine must call the BASIC routine SetUEvent.
  18269.  
  18270.    2. If the event-detecting routine is in BASIC, place it after the END
  18271.       statement in the module where it will be called.
  18272.  
  18273.       If the event-detecting routine is not in BASIC, compile it and include
  18274.       it in a BASIC Quick Library. The module(s) that call this routine must
  18275.       include a DECLARE SUB statement so that BASIC can find the routine.
  18276.  
  18277.    3. Write the routine that handles the event.
  18278.  
  18279.    4. Use the ON UEVENT statement to tell BASIC the name of the
  18280.       event-handling routine associated with the user-defined event.
  18281.  
  18282.    5. Use the UEVENT ON statement to initiate trapping. (UEVENT OFF and
  18283.       UEVENT STOP may be used to terminate or postpone trapping.)
  18284.  
  18285.    6. Call the event-detecting routine. When the event occurs, BASIC will
  18286.       call the event-handling routine named in the ON UEVENT statement.
  18287.  
  18288.  
  18289.  ────────────────────────────────────────────────────────────────────────────
  18290.  VAL Function
  18291.  ────────────────────────────────────────────────────────────────────────────
  18292.  
  18293.  ■ Action
  18294.  
  18295.    Returns the numeric value of a string of digits
  18296.  
  18297.  ■ Syntax
  18298.  
  18299.    VAL(stringexpression)
  18300.  
  18301.  ■ Remarks
  18302.  
  18303.    The stringexpression is a sequence of characters that can be interpreted
  18304.    as a numeric value. The VAL function stops reading the string at the first
  18305.    character that it cannot recognize as part of a number. The VAL function
  18306.    also strips leading blanks, tabs, and line feeds from the argument string.
  18307.    For example,
  18308.  
  18309.    VAL("    -33/LP")
  18310.  
  18311.    returns the value -33.
  18312.  
  18313.  ■ See Also
  18314.  
  18315.    STR$
  18316.  
  18317.  ■ Example
  18318.  
  18319.    The following program prints the names and addresses of people with
  18320.    specific telephone area codes:
  18321.  
  18322.    INPUT "Search for which area: ", Targetarea
  18323.    OPEN "MAIL.DAT" FOR INPUT AS #1
  18324.    DO WHILE NOT EOF(1)
  18325.       INPUT #1, Nm$, Phonenum$, Street$, Citystate$
  18326.       'VAL reads everything up to the first non-numeric
  18327.       'character ("-" in this case).
  18328.       Area = VAL(Phonenum$)
  18329.       IF Area = Targetarea THEN
  18330.          PRINT : PRINT Nm$
  18331.          PRINT Street$
  18332.          PRINT Citystate$
  18333.       END IF
  18334.    LOOP
  18335.    CLOSE : END
  18336.  
  18337.  
  18338.  
  18339.  ────────────────────────────────────────────────────────────────────────────
  18340.  VARPTR, VARSEG Functions
  18341.  ────────────────────────────────────────────────────────────────────────────
  18342.  
  18343.  ■ Action
  18344.  
  18345.    Returns the address of a variable
  18346.  
  18347.  ■ Syntax
  18348.  
  18349.    VARPTR(variablename)
  18350.    VARSEG(variablename)
  18351.  
  18352.  ■ Remarks
  18353.  
  18354.    The variablename may be any BASIC variable, including a record variable or
  18355.    record element. The VARPTR function returns an unsigned integer that is
  18356.    the offset of the variable within its segment. The VARSEG function returns
  18357.    an unsigned integer that is the segment part of the variable's address. If
  18358.    variablename is not defined before either VARPTR or VARSEG is called, the
  18359.    variable is created and its address is returned. When variablename is a
  18360.    string variable, VARPTR and VARSEG return the location of the first byte
  18361.    of the string descriptor.
  18362.  
  18363.  ────────────────────────────────────────────────────────────────────────────
  18364.  NOTE
  18365.    Because many BASIC statements change the locations of variables in memory,
  18366.    use the values returned by VARPTR and VARSEG immediately after the
  18367.    functions are used. See Section 2.3.3, "Variable Storage Allocation," for
  18368.    a list of things that cause variable locations to move.
  18369.  ────────────────────────────────────────────────────────────────────────────
  18370.  
  18371.    VARPTR and VARSEG are often used with BLOAD, BSAVE, CALL ABSOLUTE, CALL
  18372.    INTERRUPT, PEEK, POKE, or when passing arrays to procedures written in
  18373.    other languages.
  18374.  
  18375.    When using VARPTR or VARSEG to get the address of an array, use the first
  18376.    element of the array as the argument:
  18377.  
  18378.    DIM A(150)
  18379.    .
  18380.    .
  18381.    .
  18382.    ArrAddress=VARPTR(A(1))
  18383.  
  18384.    You may no longer use VARPTR to get the address of a file's buffer. Use
  18385.    the function FILEATTR to get information about a file. In addition,
  18386.    programs written in earlier versions of BASIC that used VARPTR to access
  18387.    numeric arrays may no longer work. You must now use a combination of
  18388.    VARPTR and VARSEG. For example, the following QuickBASIC Version 3.0
  18389.    fragment no longer works correctly:
  18390.  
  18391.    DIM Cube(675)
  18392.    .
  18393.    .
  18394.    .
  18395.    BSAVE "graph.dat",VARPTR(Cube(1)),2700
  18396.  
  18397.    The fragment would be rewritten as follows:
  18398.  
  18399.    DIM Cube(675)
  18400.    .
  18401.    .
  18402.    .
  18403.    ' Change segment to segment containing Cube.
  18404.    DEF SEG=VARSEG(Cube(1))
  18405.    BSAVE "graph.dat",VARPTR(Cube(1)),2700
  18406.    ' Restore BASIC segment.
  18407.    DEF SEG
  18408.  
  18409.    You may use VARPTR alone to get the address of a variable stored in
  18410.    DGROUP. You must use both VARPTR and VARSEG to get the complete address of
  18411.    a variable stored as a far object. See Section 2.3.3, "Variable Storage
  18412.    Allocation," for rules to determine when a variable is stored in DGROUP.
  18413.  
  18414.    The VARSEG function combined with VARPTR replaces the PTR86 subprogram
  18415.    used in previous versions of QuickBASIC.
  18416.  
  18417.  ■ See Also
  18418.  
  18419.    BLOAD, BSAVE, CALL ABSOLUTE, CALL INTERRUPT, DEF SEG, PEEK, POKE
  18420.  
  18421.  ■ Example
  18422.  
  18423.    See the entries for BLOAD, BSAVE, CALL ABSOLUTE, and CALL INTERRUPT for
  18424.    examples of how to use VARPTR and VARSEG with those statements.
  18425.  
  18426.    The following program illustrates how to use VARPTR and VARSEG to pass a
  18427.    BASIC array to a C function. The C function would be separately compiled
  18428.    and then placed in a Quick library or linked to the BASIC main program.
  18429.  
  18430.    ' BASIC program passing an array to C function.
  18431.    DECLARE SUB AddArr CDECL (BYVAL Offs%, BYVAL Segm%, BYVAL Num%)
  18432.    DIM A(1 TO 100) AS INTEGER
  18433.    ' Fill the array with the numbers 1 to 15.
  18434.    FOR I=1 TO 15
  18435.       A(I)=I
  18436.    NEXT I
  18437.  
  18438.    ' Call the C function. AddArr expects a far address (segment
  18439.    ' and offset). Because CDECL puts things on the stack from
  18440.    ' right to left, put the offset ( VARPTR(A(1)) ) first in the
  18441.    ' list, followed by the segment ( VARSEG(A(1)) ).
  18442.    CALL AddArr(VARPTR(A(1)),VARSEG(A(1)),15%)
  18443.  
  18444.    ' Print the modified array.
  18445.    FOR I=1 TO 15
  18446.       PRINT A(I)
  18447.    NEXT I
  18448.  
  18449.    END
  18450.  
  18451.    /* Add one to the first num elements of array arr.*/
  18452.    void far addarr(arr,num)
  18453.    int far *arr;
  18454.    int num;
  18455.    {
  18456.       int i;
  18457.       for(i=0;i<num;i++) arr[i]++;
  18458.    }
  18459.  
  18460.  
  18461.  ────────────────────────────────────────────────────────────────────────────
  18462.  VARPTR$ Function
  18463.  ────────────────────────────────────────────────────────────────────────────
  18464.  
  18465.  ■ Action
  18466.  
  18467.    Returns a string representation of a variable's address as needed for use
  18468.    in DRAW and PLAY statements
  18469.  
  18470.  ■ Syntax
  18471.  
  18472.    VARPTR$(variablename)
  18473.  
  18474.  ■ Remarks
  18475.  
  18476.    The variablename is the name of a variable in the program. If variablename
  18477.    is an array element, then the array must be dimensioned before the VARPTR$
  18478.    function is used. The array must be an array of variable-length strings.
  18479.  
  18480.  ────────────────────────────────────────────────────────────────────────────
  18481.  NOTE
  18482.    To guarantee correct results, use the value of VARPTR$ immediately after
  18483.    invoking the function.
  18484.  ────────────────────────────────────────────────────────────────────────────
  18485.  
  18486.  ■ Differences From Basica
  18487.  
  18488.    In QuickBASIC programs, VARPTR$ must be used in the DRAW and PLAY
  18489.    statements to execute substrings containing variables. BASICA supports
  18490.    both the VARPTR$ syntax and the syntax containing just the variable name.
  18491.  
  18492.  ■ See Also
  18493.  
  18494.    DRAW, PLAY
  18495.  
  18496.  ■ Example
  18497.  
  18498.    See the DRAW and PLAY statement for examples.
  18499.  
  18500.  
  18501.  ────────────────────────────────────────────────────────────────────────────
  18502.  VIEW Statement
  18503.  ────────────────────────────────────────────────────────────────────────────
  18504.  
  18505.  ■ Action
  18506.  
  18507.    Defines screen limits for graphics output
  18508.  
  18509.  ■ Syntax
  18510.  
  18511.    VIEW ««SCREEN» (x1,y1)-(x2,y2) «,«color» «,border»»»
  18512.  
  18513.  ■ Remarks
  18514.  
  18515.    The list below describes the parts of the VIEW statement:
  18516.  
  18517. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  18518.    Part                     Description
  18519.    ──────────────────────────────────────────────────────────────────────────
  18520.    SCREEN                   When SCREEN is used, the x-and y-coordinates are
  18521.                             absolute to the screen, not relative to the
  18522.                             border of the physical viewport. Only graphics
  18523.                             within the viewport are plotted. When SCREEN is
  18524.    Part                     Description
  18525.    ──────────────────────────────────────────────────────────────────────────
  18526.                            within the viewport are plotted. When SCREEN is
  18527.                             omitted, all points are plotted relative to the
  18528.                             viewport (x1 and x2 are added to coordinates
  18529.                             before plotting the point).
  18530.  
  18531.    (x1,y1) - (x2,y2)        Indicates a rectangular area on the screen. The
  18532.                             placeholders x1, y1, x2, and y2 are numeric
  18533.                             expressions that are the coordinates of
  18534.                             diagonally opposite corners of the area.
  18535.  
  18536.    color                    The color attribute of the color used to fill the
  18537.                             area. If you omit color, the area is not filled.
  18538.  
  18539.    border                   Any numeric expression in this area draws a line
  18540.                             around the viewport if space is available. If you
  18541.                             omit border, no border is drawn.
  18542.    ──────────────────────────────────────────────────────────────────────────
  18543.  
  18544.  
  18545.    The VIEW statement defines a "physical viewport," or a rectangular section
  18546.    of the screen into which graphics can be mapped. All coordinates used in
  18547.    the statement must be within the physical bounds of the screen.
  18548.  
  18549.    If VIEW is given with no arguments, the entire screen is defined as the
  18550.    viewport. RUN and SCREEN also define the entire screen as the viewport and
  18551.    disable any viewports defined with VIEW.
  18552.  
  18553.  ■ Examples
  18554.  
  18555.    The following example contrasts the output after VIEW and VIEW SCREEN are
  18556.    executed:
  18557.  
  18558.    SCREEN 1
  18559.    'SCREEN option makes all screen coordinates absolute.
  18560.    VIEW SCREEN (10,10)-(200,100)
  18561.    'This line will not be visible, since its end
  18562.    'points are outside the viewport.
  18563.    LINE (5,5)-(100,5)
  18564.    PRINT "Press any key to continue."
  18565.    SUSPEND$ = INPUT$(1)
  18566.    'Wait for a key to be pressed.
  18567.  
  18568.    'No SCREEN option - all screen coordinates relative to
  18569.    'this viewport.
  18570.    VIEW (10,10)-(200,100)
  18571.    'This line is now visible, since its end points
  18572.    'are added to (10,10).
  18573.    LINE (5,5)-(100,5)
  18574.  
  18575.    You may use multiple VIEW statements. If the newly described viewport is
  18576.    not wholly within the previous viewport, the screen can be reinitialized
  18577.    with the VIEW statement and the new viewport can be defined. If the new
  18578.    viewport is entirely within the previous one, as in the following example,
  18579.    the intermediate VIEW statement is not necessary. This example opens three
  18580.    viewports, each smaller than the previous one. In each case, the points of
  18581.    the line that lie outside the viewport borders are clipped and do not
  18582.    appear on the screen.
  18583.  
  18584.    SCREEN 1
  18585.    CLS
  18586.    VIEW
  18587.    'Make the viewport cover most of the screen.
  18588.    VIEW (10,10) - (300,180),,1
  18589.       CLS
  18590.       LINE (0,0) - (310,190),1
  18591.       LOCATE 1,11: PRINT "A big viewport"
  18592.    VIEW SCREEN (50,50)-(250,150),,1
  18593.       CLS
  18594.    'Note CLS clears only viewport.
  18595.       LINE (300,0)-(0,199),1
  18596.       LOCATE 9,9: PRINT "A medium viewport"
  18597.    VIEW SCREEN (80,80)-(200,125),,1
  18598.       CLS
  18599.       CIRCLE (150,100),20,1
  18600.       LOCATE 11,9: PRINT "A small viewport"
  18601.  
  18602.  
  18603.  ────────────────────────────────────────────────────────────────────────────
  18604.  VIEW PRINT Statement
  18605.  ────────────────────────────────────────────────────────────────────────────
  18606.  
  18607.  ■ Action
  18608.  
  18609.    Sets the boundaries of the screen text viewport
  18610.  
  18611.  ■ Syntax
  18612.  
  18613.    VIEW PRINT «topline TO bottomline»
  18614.  
  18615.  ■ Remarks
  18616.  
  18617.    The topline argument is the number of the upper line in the viewport; the
  18618.    bottomline is the number of the lower line.
  18619.  
  18620.    Without topline and bottomline parameters, the VIEW PRINT statement
  18621.    initializes the whole screen area as the text viewport. The number of
  18622.    lines in the screen depends on the screen mode and whether or not the /H
  18623.    option was used when QuickBASIC was started. See the entry for the WIDTH
  18624.    statement and Chapter 3, "File and Device I/O," in Programming in BASIC,
  18625.    for more information.
  18626.  
  18627.    Statements and functions that operate within the defined text viewport
  18628.    include CLS, LOCATE, PRINT, and the SCREEN function.
  18629.  
  18630.  ■ See Also
  18631.  
  18632.    CLS, LOCATE, PRINT, SCREEN Function, VIEW
  18633.  
  18634.  ■ Example
  18635.  
  18636.    See the example for CLS.
  18637.  
  18638.  
  18639.  ────────────────────────────────────────────────────────────────────────────
  18640.  WAIT Statement
  18641.  ────────────────────────────────────────────────────────────────────────────
  18642.  
  18643.  ■ Action
  18644.  
  18645.    Suspends program execution while monitoring the status of a machine input
  18646.    port
  18647.  
  18648.  ■ Syntax
  18649.  
  18650.    WAIT portnumber,and-expression«,xor-expression»
  18651.  
  18652.  ■ Remarks
  18653.  
  18654.    The following list describes the arguments of the WAIT statement:
  18655.  
  18656.    Argument                 Description
  18657.    ──────────────────────────────────────────────────────────────────────────
  18658.    portnumber               An integer expression in the range 0-255 that is
  18659.                             the number of the port
  18660.  
  18661.    and-expression           An integer expression combined with data from the
  18662.                             port through an AND operation
  18663.  
  18664.    xor-expression           An integer expression combined with data from the
  18665.                             port using an XOR operation
  18666.    ──────────────────────────────────────────────────────────────────────────
  18667.  
  18668.    The WAIT statement suspends execution until a specified bit pattern is
  18669.    read from a designated input port. The data read from the port is
  18670.    combined, using an XOR operation, with xor-expression, if it appears. The
  18671.    result is then combined with the and-expression using an AND operation. If
  18672.    the result is zero, BASIC loops back and reads the data at the port again.
  18673.    If the result is nonzero, execution continues with the next statement. If
  18674.    xor-expression is omitted, it is assumed to be 0.
  18675.  
  18676.  ────────────────────────────────────────────────────────────────────────────
  18677.  WARNING
  18678.    It is possible to enter an infinite loop with the WAIT statement if the
  18679.    input port fails to develop a nonzero bit pattern. In this case, you must
  18680.    manually restart the machine.
  18681.  ────────────────────────────────────────────────────────────────────────────
  18682.  
  18683.  ■ Example
  18684.  
  18685.    The following example illustrates the WAIT statement:
  18686.  
  18687.    WAIT 32,2
  18688.  
  18689.  
  18690.  ────────────────────────────────────────────────────────────────────────────
  18691.  WHILE...WEND Statement
  18692.  ────────────────────────────────────────────────────────────────────────────
  18693.  
  18694.  ■ Action
  18695.  
  18696.    Executes a series of statements in a loop, as long as a given condition is
  18697.    true
  18698.  
  18699.  ■ Syntax
  18700.  
  18701.    WHILE condition
  18702.    .
  18703.    .
  18704.    .
  18705.    «statements»
  18706.    .
  18707.    .
  18708.    .
  18709.    WEND
  18710.  
  18711.  ■ Remarks
  18712.  
  18713.    If the condition is true (that is, if it does not equal zero), then any
  18714.    intervening statements are executed until the WEND statement is
  18715.    encountered. BASIC then returns to the WHILE statement and checks
  18716.    condition. If it is still true, the process is repeated. If it is not true
  18717.    (or if it equals zero), execution resumes with the statement following the
  18718.    WEND statement.
  18719.  
  18720.  ────────────────────────────────────────────────────────────────────────────
  18721.  NOTE
  18722.    QuickBASIC's DO...LOOP statement provides a more powerful and flexible
  18723.    loop-control structure.
  18724.  ────────────────────────────────────────────────────────────────────────────
  18725.  
  18726.    WHILE...WEND loops may be nested to any level. Each WEND matches the most
  18727.    recent WHILE. An unmatched WHILE statement causes an error message that
  18728.    reads WHILE without WEND. An unmatched WEND statement causes an error
  18729.    message that reads WEND without WHILE.
  18730.  
  18731.  ────────────────────────────────────────────────────────────────────────────
  18732.  NOTE
  18733.    Do not branch into the body of a WHILE...WEND loop without executing the
  18734.    WHILE. This may cause run-time errors or program problems that are
  18735.    difficult to locate.
  18736.  ────────────────────────────────────────────────────────────────────────────
  18737.  
  18738.  ■ See Also
  18739.  
  18740.    DO...LOOP
  18741.  
  18742.  ■ Example
  18743.  
  18744.    The following fragment performs a bubble sort on the array A$. The second
  18745.    line makes the variable Exchange true by assigning it a nonzero value and
  18746.    thereby forces one pass through the WHILE...WEND loop (this construction
  18747.    is unnecessary with DO...LOOP). When there are no more swaps, all elements
  18748.    of A$ are sorted, the variable Exchange is false (equal to zero), and the
  18749.    program continues execution with the line following the WEND statement.
  18750.  
  18751.    ' Bubble sort of array A$.
  18752.    CONST FALSE=0, TRUE=NOT FALSE
  18753.    Max = UBOUND(A$)
  18754.    Exchange=TRUE  ' Force first pass through the array.
  18755.  
  18756.    WHILE Exchange ' Sort until no elements are exchanged.
  18757.       Exchange=FALSE
  18758.       ' Compare the array elements by pairs. When two
  18759.       ' are exchanged, force another pass by setting Exchange
  18760.       ' to TRUE.
  18761.       FOR I = 2 TO Max
  18762.          IF A$(I-1) > A$(I) THEN
  18763.             Exchange=TRUE
  18764.             SWAP A$(I-1),A$(I)
  18765.          END IF
  18766.       NEXT
  18767.    WEND
  18768.  
  18769.    .
  18770.    .
  18771.    .
  18772.  
  18773.  
  18774.  ────────────────────────────────────────────────────────────────────────────
  18775.  WIDTH Statement
  18776.  ────────────────────────────────────────────────────────────────────────────
  18777.  
  18778.  ■ Action
  18779.  
  18780.    Assigns an output-line width to a file or device or changes the number of
  18781.    columns and lines displayed on the screen
  18782.  
  18783.  ■ Syntax
  18784.  
  18785.    WIDTH «columns»«,lines»
  18786.    WIDTH {#filenumber | device},width
  18787.    WIDTH LPRINT width
  18788.  
  18789.  ■ Remarks
  18790.  
  18791.    Both files and devices can be assigned an output-line width. The different
  18792.    forms of the WIDTH statement are explained in the following list:
  18793.  
  18794. ╓┌─┌────────────────────────────────────┌────────────────────────────────────╖
  18795.    Syntax                               Description
  18796.    ──────────────────────────────────────────────────────────────────────────
  18797.    Syntax                               Description
  18798.    ──────────────────────────────────────────────────────────────────────────
  18799.    WIDTH «columns»«,lines»              Sets the number of columns and lines
  18800.                                         to display on the screen.
  18801.  
  18802.                                         The value of columns must be either
  18803.                                         40 or 80. The default value is 80.
  18804.  
  18805.                                         The value of lines may be 25, 30, 43,
  18806.                                         50, or 60, depending on both the
  18807.                                         display adapter used and the screen
  18808.                                         mode.
  18809.  
  18810.                                         The number of lines displayed when
  18811.                                         the program started will determine
  18812.                                         the default value. See the SCREEN
  18813.                                         statement for more information.
  18814.  
  18815.    WIDTH #filenumber, width             Sets to width the line width of an
  18816.                                         output device opened as a file (for
  18817.                                         example, LPT1: or CONS:). The
  18818.    Syntax                               Description
  18819.    ──────────────────────────────────────────────────────────────────────────
  18820.                                        example, LPT1: or CONS:). The
  18821.                                         filenumber argument is the number
  18822.                                         associated with the file in the OPEN
  18823.                                         statement.
  18824.  
  18825.                                         This form permits altering the width
  18826.                                         while a file is open, since the
  18827.                                         statement takes place immediately.
  18828.  
  18829.    WIDTH device,width                   Sets to width the line width of
  18830.                                         device (a device file name). The
  18831.                                         device should be a string expression
  18832.                                         (for example, "CONS:").
  18833.  
  18834.                                         Note that this width assignment is
  18835.                                         deferred until the next OPEN
  18836.                                         statement affecting the device; the
  18837.                                         assignment does not affect output for
  18838.                                         an already open file.
  18839.    Syntax                               Description
  18840.    ──────────────────────────────────────────────────────────────────────────
  18841.                                        an already open file.
  18842.  
  18843.    WIDTH LPRINT width                   Sets to width the line width of the
  18844.                                         line printer for use by subsequent
  18845.                                         LPRINT statements.
  18846.    ──────────────────────────────────────────────────────────────────────────
  18847.  
  18848.  
  18849.  ■ See Also
  18850.  
  18851.    SCREEN Statement
  18852.  
  18853.  ■ Example
  18854.  
  18855.    In the following example, the record width for file #1 (the lineprinter)
  18856.    is set to different widths:
  18857.  
  18858.    OPEN "LPT1:" FOR OUTPUT AS #1
  18859.    Test$ = "1234567890"
  18860.    WIDTH #1, 3
  18861.    PRINT #1, Test$
  18862.    WIDTH #1, 4
  18863.    PRINT #1, Test$
  18864.    CLOSE
  18865.  
  18866.  ■ Output
  18867.  
  18868.    123
  18869.    456
  18870.    789
  18871.    0
  18872.    1234
  18873.    5678
  18874.    90
  18875.  
  18876.  
  18877.  ────────────────────────────────────────────────────────────────────────────
  18878.  WINDOW Statement
  18879.  ────────────────────────────────────────────────────────────────────────────
  18880.  
  18881.  ■ Action
  18882.  
  18883.    Defines the dimensions of the current viewport
  18884.  
  18885.  ■ Syntax
  18886.  
  18887.    WINDOW ««SCREEN» (x1,y1)-(x2,y2)»
  18888.  
  18889.  ■ Remarks
  18890.  
  18891.    The WINDOW statement allows the user to create a customized coordinate
  18892.    system to draw lines, graphs, or objects without being constrained by the
  18893.    screen's physical coordinates (the dimensions of the screen). This is done
  18894.    by redefining the screen-border coordinates with the "view coordinates"
  18895.    (x1, y1) and (x2, y2). These view coordinates are single-precision
  18896.    numbers.
  18897.  
  18898.    WINDOW defines the section of the view coordinate system that is mapped to
  18899.    the physical coordinates of the screen. All subsequent graphics statements
  18900.    use these new view coordinates and are displayed within the current
  18901.    viewport. (The size of the viewport can be changed with the VIEW
  18902.    statement.)
  18903.  
  18904.    Either the RUN statement or WINDOW with no arguments disables the window
  18905.    transformation. The WINDOW SCREEN variant inverts the normal Cartesian
  18906.    direction of the y-coordinate, so y values go from negative to positive
  18907.    from top to bottom.
  18908.  
  18909.    Figure R.1 shows the effects of WINDOW and WINDOW SCREEN on a line drawn
  18910.    in screen mode 2. Notice the change in the coordinates of the screen
  18911.    corners.
  18912.  
  18913.  ■ Examples
  18914.  
  18915.    The following example illustrates two lines with the same end-point
  18916.    coordinates. The first is drawn on the default screen, and the second is
  18917.    on a redefined window.
  18918.  
  18919.    SCREEN 2
  18920.    LINE (100,100) - (150,150), 1
  18921.    LOCATE 2,20 : PRINT "The line on the default screen"
  18922.    WINDOW SCREEN (100,100) - (200,200)
  18923.    LINE (100,100) - (150,150), 1
  18924.    LOCATE 8,18 : PRINT"& the same line on a redefined window"
  18925.  
  18926.                                  Increasing X
  18927.                           ─────────────────────────
  18928.                         │ ┌─────────────────────────┐
  18929.                         │ │(0,0)             (639,0)│
  18930.               Increasing│ │                         │
  18931.                   Y     │ │                         │
  18932.                         │ │                         │
  18933.                         │ │                         │
  18934.                         │ │                         │
  18935.                         │ │                         │
  18936.                         │ │(0,199)         (639,199)│
  18937.                          └─────────────────────────┘
  18938.                                       /  \
  18939.                                     /       \
  18940.                                   /            \
  18941.              WINDOW (-25,-15)   /        WINDOW SCREEN (-25,-15)-(5,10)
  18942.              LINE (-15,-10)-(-5,-5)      LINE  (-15,-10)-(-5,-5)
  18943.                            /                           \
  18944.                          /                                \
  18945.                        /                                     \
  18946.                      /                                          \      Increas
  18947.                ┌─────────────────────────┐                     ───────────────
  18948.               │(-25,10)           (5,10)│                   │  ┌─────────────
  18949.              │ │                         │                   │  │(-25,-15)
  18950.    Increasing│ │                 (0,0)   │        Increasing │  │
  18951.        Y     │ │                         │            Y      │  │      ∙\(-15,
  18952.              │ │           (-5,-5)∙      │                   │  │         \
  18953.              │ │              /          │                   │  │           \∙
  18954.              │ │            /            │                   │  │
  18955.              │ │  (-15,-10)∙             │                   │  │
  18956.              │ │(-25,-15)         (5,-15)│                   │  │
  18957.                └─────────────────────────┘                   │  │(-25,10)
  18958.                ─────────────────────────                      └─────────────
  18959.                       Increasing X
  18960.  
  18961.    Figure R.1 WINDOW and WINDOW SCREEN
  18962.  
  18963.    The following example shows how changing the window size changes the size
  18964.    of a figure drawn on the screen. The effect is one of zooming in and out;
  18965.    as the window gets smaller, the figure appears larger on the screen, until
  18966.    parts of it are finally clipped because they lie outside the window. As
  18967.    the window gets larger, the figure appears smaller on the screen.
  18968.  
  18969.    PRINT "Press ENTER to start."
  18970.    INPUT;"",A$
  18971.    SCREEN 1 : COLOR 7              'Grey screen.
  18972.    X = 500 : Xdelta = 50
  18973.  
  18974.    DO
  18975.       DO WHILE X < 525 AND X > 50
  18976.          X = X + Xdelta            'Change window size.
  18977.          CALL Zoom(X)
  18978.          FOR I = 1 TO 1000         'Delay loop.
  18979.             IF INKEY$ <> "" THEN END   'Stop if key pressed.
  18980.          NEXT
  18981.       LOOP
  18982.       X = X - Xdelta
  18983.       Xdelta = -Xdelta             'Reverse size change.
  18984.    LOOP
  18985.  
  18986.    SUB Zoom(X) STATIC
  18987.       CLS
  18988.       WINDOW (-X,-X)-(X,X)         'Define new window.
  18989.       LINE (-X,-X)-(X,X),1,B       'Draw window border.
  18990.       CIRCLE (0,0),60,1,,,.5       'Draw ellipse with x-radius 60.
  18991.       PAINT (0,0),1                'Paint ellipse.
  18992.    END SUB
  18993.  
  18994.  
  18995.  ────────────────────────────────────────────────────────────────────────────
  18996.  WRITE Statement
  18997.  ────────────────────────────────────────────────────────────────────────────
  18998.  
  18999.  ■ Action
  19000.  
  19001.    Sends data to the screen
  19002.  
  19003.  ■ Syntax
  19004.  
  19005.    WRITE «expressionlist»
  19006.  
  19007.  ■ Remarks
  19008.  
  19009.    If expressionlist is omitted, a blank line is written. If expressionlist
  19010.    is included, the values of the expressions are written to the screen. The
  19011.    expressions in the list may be numeric and/or string expressions. They
  19012.    must be separated by commas.
  19013.  
  19014.    When the printed items are written, each item is separated from the last
  19015.    by a comma. Printed strings are delimited by quotation marks. After the
  19016.    last item in the list is printed, BASIC inserts a carriage-return and
  19017.    line-feed. The WRITE statement writes numeric values without leading or
  19018.    trailing spaces.
  19019.  
  19020.  ■ See Also
  19021.  
  19022.    PRINT
  19023.  
  19024.  ■ Example
  19025.  
  19026.    The following example shows the difference between the PRINT and WRITE
  19027.    statements:
  19028.  
  19029.    A=80 : B=90 : C$="That's all." : D=-1.0E-13
  19030.    WRITE A,B,C$,D
  19031.    PRINT A,B,C$,D
  19032.  
  19033.  ■ Output
  19034.  
  19035.    80,90,"That's all.",-1E-13
  19036.     80            90           That's all.  -1E-13
  19037.  
  19038.  
  19039.  ────────────────────────────────────────────────────────────────────────────
  19040.  WRITE # Statement
  19041.  ────────────────────────────────────────────────────────────────────────────
  19042.  
  19043.  ■ Action
  19044.  
  19045.    Writes data to a sequential file
  19046.  
  19047.  ■ Syntax
  19048.  
  19049.    WRITE #filenumber,expressionlist
  19050.  
  19051.  ■ Remarks
  19052.  
  19053.    The filenumber is the number used in the OPEN statement. The file must be
  19054.    opened in OUTPUT or APPEND mode. The expressions in the argument
  19055.    expressionlist are string and/or numeric expressions, separated by commas.
  19056.    If you omit the expressionlist, the WRITE # statement writes a blank line
  19057.    to the file.
  19058.  
  19059.    The WRITE # statement, unlike the PRINT # statement, inserts commas
  19060.    between items as they are written to the file. You do not have to put
  19061.    explicit delimiters in the list. A new line is inserted once the last item
  19062.    in the list has been written to the file.
  19063.  
  19064.    If WRITE # attempts to write data to a sequential file restricted by a
  19065.    LOCK statement, an error message appears that reads Permission denied
  19066.    unless the error is trapped by the program. All of BASIC's usual
  19067.    error-handling routines can trap and examine this error.
  19068.  
  19069.  ■ See Also
  19070.  
  19071.    LOCK, OPEN, PRINT #, WRITE
  19072.  
  19073.  ■ Example
  19074.  
  19075.    The output from the following program illustrates the difference between
  19076.    the WRITE # and PRINT # statements:
  19077.  
  19078.    A$ = "VCR, remote control" : B$ = "$399.00"
  19079.    OPEN  "PRICES" FOR OUTPUT AS #1       'Open PRICES for writing.
  19080.    PRINT #1,A$,B$   'Store A$ and B$ in first record with PRINT #.
  19081.    WRITE #1,A$,B$   'Store A$ and B$ in second record with WRITE #.
  19082.    CLOSE #1
  19083.  
  19084.  ■ Output
  19085.  
  19086.    VCR, remote control         $399.00
  19087.    "VCR, remote control","$399.00"
  19088.  
  19089.  
  19090.  ════════════════════════════════════════════════════════════════════════════
  19091.  Glossary
  19092.  
  19093.  
  19094.  CONTROL FLOW
  19095.  
  19096.  FOR...NEXT  Repeats statements between FOR and NEXT a specific number of
  19097.      times.
  19098.  
  19099.  EXIT FOR  alternative exit from FOR...NEXT
  19100.  
  19101.  DO...LOOP  Repeats statements between DO and LOOP, while (until) a condition
  19102.      is(becomes) true.
  19103.  
  19104.  EXIT DO  alternative exit from DO...LOOP
  19105.  
  19106.  WHILE...WEND  Repeats statements between WHILE and WEND while a given
  19107.      condition is true.
  19108.  
  19109.  IF...THEN...ELSE... END IF  Conditionally executes or branches todifferent
  19110.      statements.
  19111.  
  19112.  SELECT CASE  Conditionally executes statements based on value of a variable.
  19113.  
  19114.  GOSUB...RETURN  Transfers contol to a specific line in a module; control
  19115.      returns to the line following GOSUB. (Old style; SUB is a more powerful
  19116.      alternative.)
  19117.  
  19118.  RUN  Restarts current program, or loads and runs another program.
  19119.  
  19120.  CHAIN "program"  Passes execution to program specified, then returns.
  19121.  
  19122.  SLEEP  Suspends program execution.
  19123.  
  19124.  WAIT  Suspends program execution while monitoring status of a machine input
  19125.      port.
  19126.  
  19127.  
  19128.  PROCEDURES
  19129.  
  19130.  SUB...END SUB  Mark the beginning and end of a SUBprocedure.
  19131.  
  19132.  EXIT SUB  alternative exit from a SUB procedure
  19133.  
  19134.  FUNCTION... END FUNCTION  Mark the beginning and end of aFUNCTION procedure.
  19135.  
  19136.  EXIT FUNCTION  alternative exit from aFUNCTION procedure
  19137.  
  19138.  DEF FN...END DEF  Mark the beginning and end of a DEF FN function. (Old
  19139.      style; FUNCTION is a more powerful alternative.)
  19140.  
  19141.  EXIT DEF  alternative exit from aDEF FN function
  19142.  
  19143.  CALL, CALLS  Transfers control to a BASIC SUB procedure, or a procedure
  19144.      written in another language and compiled separately.
  19145.  
  19146.  
  19147.  STANDARD I/O
  19148.  
  19149.  BEEP  Makes the speaker beep.
  19150.  
  19151.  SOUND  Makes a sound of specified frequency and duration.
  19152.  
  19153.  PRINT [USING]  Outputs [formatted] text to the screen.
  19154.  
  19155.  WIDTH  Sets screen width and number of lines.
  19156.  
  19157.  INKEY$  Reads a character from the keyboard.
  19158.  
  19159.  INP (n)  Returns the value read from I/O port n.
  19160.  
  19161.  INPUT  Reads string and/or numerical input from the keyboard and stores it
  19162.      in a list ofvariables.
  19163.  
  19164.  INPUT$  Reads characters from the keyboard into a string variable.
  19165.  
  19166.  LINE INPUT  Reads an entire line (up to 255 chars) into a string variable.
  19167.  
  19168.  LOCATE  Moves cursor to a specified screen row and column.
  19169.  
  19170.  SPC  Skips spaces in printed output.
  19171.  
  19172.  TAB  Skips to a specified display column.
  19173.  
  19174.  CSRLIN  Returns row number of cursor.
  19175.  
  19176.  POS  Returns line number of cursor.
  19177.  
  19178.  LPOS  Returns position of line printer's print head within the printer
  19179.      buffer.
  19180.  
  19181.  VIEW PRINT  Sets top and bottom rows for displaying print.
  19182.  
  19183.  LPRINT [USING]  Prints [formatted] data on LPT1: printer.
  19184.  
  19185.  OPEN COMn:  Opens and initializes a communications channel for I/O.
  19186.  
  19187.  OUT  Sends a byte to a machine I/O port.
  19188.  
  19189.  PEN  Returns the light pen coordinates.
  19190.  
  19191.  STICK  Returns the x and y coordinates of the two joysticks.
  19192.  
  19193.  STRIG  Returns the status of a specified joystick trigger (fire button).
  19194.  
  19195.  READ  Returns values from a DATA statement and assigns them to variables.
  19196.  
  19197.  RESTORE  Allows DATA statements to be reread from a specified line.
  19198.  
  19199.  
  19200.  FILE I/O
  19201.  
  19202.  OPEN  Opens a file for reading or writing records.
  19203.  
  19204.  CLOSE  Ends I/O operations to a file.
  19205.  
  19206.  RESET  Closes all disk files.
  19207.  
  19208.  PRINT [USING] #  Stores a [formatted] list of variables in a file.
  19209.  
  19210.  WRITE #  Stores a list of variables as record fields in a file.
  19211.  
  19212.  FIELD  Allocates space for variables in a random-access file buffer.
  19213.  
  19214.  WIDTH  Specifies a standard length for each record in a file.
  19215.  
  19216.  PUT  Stores contents of a variable in a file.
  19217.  
  19218.  INPUT #  Reads fields from a record; assigns each to a variable.
  19219.  
  19220.  INPUT$  Reads a string of characters from a file.
  19221.  
  19222.  LINE INPUT #  Reads a record and stores it in a string variable.
  19223.  
  19224.  GET  Reads data from a file; assigns data to elements of a variable.
  19225.  
  19226.  FREEFILE  Returns the next available file number.
  19227.  
  19228.  EOF  Tests whether the end of a disk file has been reached.
  19229.  
  19230.  FILEATTR  Returns a number indicating the mode in which a file was opened.
  19231.  
  19232.  LOC  Gives the current position within a file.
  19233.  
  19234.  LOF  Gives the number of bytes in an open file.
  19235.  
  19236.  SEEK (function)  Gives the location where the next file I/O operation will
  19237.      occur.
  19238.  
  19239.  SEEK (statement)  Sets the byte position for the next file I/O operation.
  19240.  
  19241.  IOCTL  Transmits a control data string to a device driver.
  19242.  
  19243.  IOCTL$  Receives a control data string from a device driver.
  19244.  
  19245.  LOCK...UNLOCK  Controls access by other processes to all or part of an open
  19246.      file.
  19247.  
  19248.  
  19249.  STRING PROCESSING
  19250.  
  19251.  LEFT$  Returns characters from the left side of the string.
  19252.  
  19253.  RIGHT$  Returns characters from the right side of the string.
  19254.  
  19255.  MID$ function  Returns characters from anywhere in the string.
  19256.  
  19257.  MID$ statement  Replaces part of a string with another string.
  19258.  
  19259.  LTRIM$  Strips leading blanks from string.
  19260.  
  19261.  RTRIM$  Strips trailing blanks from string.
  19262.  
  19263.  INSTR  Searches for a string within another string.
  19264.  
  19265.  LCASE$  Converts a string to all lower-case letters.
  19266.  
  19267.  UCASE$  Converts a string to all upper-case letters.
  19268.  
  19269.  LSET  Left-justifies a fixed-length string.
  19270.  
  19271.  RSET  Right-justifies a fixed-length string.
  19272.  
  19273.  STR$  Returns the string representation of the decimal value of a numeric
  19274.      expression.
  19275.  
  19276.  HEX$  Returns the string representation of the hex value of a numeric
  19277.      expression.
  19278.  
  19279.  VAL  Returns the numeric value of a stringexpression.
  19280.  
  19281.  SPACE$  Returns a string of blanks.
  19282.  
  19283.  STRING$  Returns a string of one repeatedcharacter.
  19284.  
  19285.  LEN  Returns the number of characters in a string.
  19286.  
  19287.  ASC  Returns the ASCII value of a character.
  19288.  
  19289.  CHR$  Returns the character with the given ASCII value.
  19290.  
  19291.  SADD  Returns the address of the specifiedstring expression.
  19292.  
  19293.  
  19294.  GRAPHICS
  19295.  
  19296.  SCREEN  Specifies a BASIC screen mode.
  19297.  
  19298.  PSET  Sets a pixel to the foreground color.
  19299.  
  19300.  PRESET  Sets a pixel to the background color.
  19301.  
  19302.  LINE  Draws a straight line or a box.
  19303.  
  19304.  CIRCLE  Draws a circle or an ellipse.
  19305.  
  19306.  DRAW  Combines BASIC graphics features into a graphics macro language.
  19307.  
  19308.  WINDOW  Sets the logical coordinates for a screen viewport.
  19309.  
  19310.  VIEW  Specifies a viewport rectangle for graphics output.
  19311.  
  19312.  PMAP  Maps pixel physical coordinates to logical coordinates.
  19313.  
  19314.  POINT  Returns physical or logical coordinates of cursor, or color number of
  19315.      pixel.
  19316.  
  19317.  COLOR  Sets default colors for graphics output.
  19318.  
  19319.  PALETTE  Assigns colors to color numbers.
  19320.  
  19321.  PAINT  Fills an area with color or a pattern.
  19322.  
  19323.  GET  Saves a rectangular area of graphics screen in memory.
  19324.  
  19325.  PUT  Displays graphics stored by GET.
  19326.  
  19327.  PCOPY  Copies one screen storage page to another.
  19328.  
  19329.  
  19330.  ERROR AND EVENT TRAPPING
  19331.  
  19332.  ON ERROR GOTO line  Program branches to line number or line label when error
  19333.      occurs.
  19334.  
  19335.  RESUME  Returns control after executing error-handling routine.
  19336.  
  19337.  ERR  Returns code for run-time error.
  19338.  
  19339.  ERL  Returns line number on which erroroccurred.
  19340.  
  19341.  ERDEV  Returns code for last device which caused an error.
  19342.  
  19343.  ERDEV$  Returns name of last device which caused an error.
  19344.  
  19345.  ERROR  Simulates occurrence of a BASIC error.
  19346.  
  19347.  ON event GOSUB line  Branches to routine labelled with line, whenever event
  19348.      occurs.
  19349.  
  19350.  event ON  Enables trapping of event.
  19351.  
  19352.  event OFF
  19353.  
  19354.  
  19355.  
  19356.  ────────────────────────────────────────────────────────────────────────────
  19357.  Appendix A  Keyboard Scan Codes and ASCII Character Codes
  19358.  
  19359.        A.1  Keyboard Scan Codes
  19360.        A.2  ASCII Character Codes
  19361.  
  19362.  A.1  Keyboard Scan Codes
  19363.  
  19364.    The table on the next page shows the DOS keyboard scan codes. These codes
  19365.    are returned by the INKEY$ function.
  19366.  
  19367.    Key combinations with NUL in the Char column return two bytes──a null byte
  19368.    (&H00) followed by the value listed in the Dec and Hex columns. For
  19369.    example, pressing ALT+F1 returns a null byte followed by a byte containing
  19370.    104 (&H68).
  19371.  
  19372.  ┌────────┬───────┬────────────┬─────────────┬─────────────┬──────────────┐
  19373.  │        │       │            │ASCII or     │ASCII or     │   ASCII or   │
  19374.  │        │Scan   │ ASCII or   │Extended     │Extended     │   Extended   │
  19375.  │  Key   │Code   │ Extended   │with SHIFT   │with CTRL    │   with ALT   │
  19376.  ├────────┼───────┼────────────┼─────────────┼─────────────┼──────────────┤
  19377.  │        │Dec Hex│Dec Hex Char│Dec Hex Char │Dec Hex Char │ Dec Hex Char │
  19378.  ├────────┼───────┼────────────┼─────────────┼─────────────┼──────────────┤
  19379.  │ESC     │ 1  01 │ 27  1B     │ 27  1B      │ 27  1B      │              │
  19380.  │1!      │ 2  02 │ 49  31  1  │ 33  21   !  │             │ 120  78  NUL │
  19381.  │2@      │ 3  03 │ 50  32  2  │ 64  40   @  │  3  03 NUL  │ 121  79  NUL │
  19382.  │3#      │ 4  04 │ 51  33  3  │ 35  23   #  │             │ 122  7A  NUL │
  19383.  │4$      │ 5  05 │ 52  34  4  │ 36  24   $  │             │ 123  7B  NUL │
  19384.  │5%      │ 6  06 │ 53  35  5  │ 37  25   %  │             │ 124  7C  NUL │
  19385.  │6^      │ 7  07 │ 54  36  6  │ 94  5E   ^  │ 30  IE      │ 125  7D  NUL │
  19386.  │7&      │ 8  08 │ 55  37  7  │ 38  26   &  │             │ 126  7E  NUL │
  19387.  │8*      │ 9  09 │ 56  38  8  │ 42  2A   *  │             │ 127  7F  NUL │
  19388.  │9(      │10  0A │ 57  39  9  │ 40  28   (  │             │ 128  80  NUL │
  19389.  │0)      │11  0B │ 48  30  0  │ 41  29   )  │             │ 129  81  NUL │
  19390.  │-_      │12  0C │ 45  2D  -  │ 95  5F   -  │ 31  IF      │ 130  82  NUL │
  19391.  │=+      │13  0D │ 61  3D  =  │ 43  2B   +  │             │ 131  83  NUL │
  19392.  │BKSP    │14  0E │  8  08     │  8  08      │127  7F      │              │
  19393.  │TAB     │15  0F │  9  09     │ 15  OF   NUL│             │              │
  19394.  │Q       │16  10 │113  71  q  │ 81  51   Q  │ 17  11      │  16  10  NUL │
  19395.  │W       │17  11 │119  77  w  │ 87  57   W  │ 23  17      │  17  11  NUL │
  19396.  │E       │18  12 │101  65  e  │ 69  45   E  │  5  05      │  18  12  NUL │
  19397.  │R       │19   13│114  72   r │ 82  52   R  │ 18  12      │  19  13  NUL │
  19398.  │T       │20   14│116  74   t │ 84  54   T  │ 20  14      │  20  14  NUL │
  19399.  │Y       │21   15│121  79   y │ 89  59   Y  │ 25  19      │  21  15  NUL │
  19400.  │U       │22   16│117  75   u │ 85  55   U  │ 21  15      │  22  16  NUL │
  19401.  │I       │23   17│105  69   i │ 73  49   I  │  9  09      │  23  17  NUL │
  19402.  │O       │24   18│111  6F   o │ 79  4F   O  │ 15  0F      │  24  18  NUL │
  19403.  │P       │25   19│112  70   p │ 80  50   P  │ 16  10      │  25  19  NUL │
  19404.  │[{      │26   1A│ 91  5B   [ │123  7B   {  │ 27  1B      │              │
  19405.  │]}      │27   1B│ 93  5D   ] │125  7D   }  │ 29  1D      │              │
  19406.  │ENTER   │28   1C│ 13  OD   CR│ 13  OD   CR │ 10  OA   LF │              │
  19407.  │CTRL    │29   1D│            │             │             │              │
  19408.  │A       │30   1E│ 97  61   a │ 65  41   A  │  1  01      │  30  1E  NUL │
  19409.  │S       │31   1F│115  73   s │ 83  53   S  │ 19  13      │  31  1F  NUL │
  19410.  │D       │32   20│100  64   d │ 68  44   D  │  4  04      │  32  20  NUL │
  19411.  │F       │33   21│102  66   f │ 70  46   F  │  6  06      │  33  21  NUL │
  19412.  │G       │34   22│103  67   g │ 71  47   G  │  7  07      │  34  22  NUL │
  19413.  │H       │35   23│104  68   h │ 72  48   H  │  8  08      │  35  23  NUL │
  19414.  │J       │36   24│106  6A   j │ 74  4A   J  │ 10  0A      │  36  24  NUL │
  19415.  │K       │37   25│107  6B   k │ 75  4B   K  │ 11  0B      │  37  25  NUL │
  19416.  │L       │38   26│108  6C   l │ 76  4C   L  │ 12  0C      │  38  26  NUL │
  19417.  │;:      │39   27│ 59  3B   ; │ 58  3A   :  │             │              │
  19418.  │'"      │40   28│ 39  27   ' │ 34  22   "  │             │              │
  19419.  │`~      │41   29│ 96  60   ` │126  7E   ~  │             │              │
  19420.  │L SHIFT │42   2A│            │             │             │              │
  19421.  │\|      │43   2B│ 92  5C   \ │124  7C   |  │ 28  1C      │              │
  19422.  │Z       │44  2C │122  7A  z  │ 90  5A   Z  │ 26  1A      │  44  2C  NUL │
  19423.  │X       │45  2D │120  78  x  │ 88  58   X  │ 24  18      │  45  2D  NUL │
  19424.  │C       │46  2E │ 99  63  c  │ 67  43   C  │  3  03      │  46  2E  NUL │
  19425.  │V       │47  2F │118  76  v  │ 86  56   V  │ 22  16      │  47  2F  NUL │
  19426.  │B       │48  30 │ 98  62  b  │ 66  42   B  │  2  OE      │  48  30  NUL │
  19427.  │N       │49  31 │110  6E  n  │ 78  4E   N  │ 14  OD      │  49  31  NUL │
  19428.  │M       │50  32 │109  6D  m  │ 77  4D   M  │ 13          │  50  32  NUL │
  19429.  │,<      │51  33 │ 44  2C  '  │ 60  3C   <  │             │              │
  19430.  │.>      │52  34 │ 46  2E  .  │ 62  3E   >  │             │              │
  19431.  │/?      │53  35 │ 47  2F  /  │ 63  3F   ?  │             │              │
  19432.  │R SHIFT │54  36 │            │             │             │              │
  19433.  │* PRTSC │55  37 │ 42  2A  *  │     INT  5 │ 16  10      │              │
  19434.  │ALT     │56  38 │            │             │             │              │
  19435.  │SPACE   │57  39 │ 32  20  SPC│ 32  20   SPC│ 32  20  SPC │  32  20  SPC │
  19436.  │CAPS    │58  3A │            │             │             │              │
  19437.  │F1      │59  3B │ 59  3B  NUL│ 84  54   NUL│ 94  5E  NUL │ 104  68  NUL │
  19438.  │F2      │60  3C │ 60  3C  NUL│ 85  55   NUL│ 95  5F  NUL │ 105  69  NUL │
  19439.  │F3      │61  3D │ 61  3D  NUL│ 86  56   NUL│ 96  60  NUL │ 106  6A  NUL │
  19440.  │F4      │62  3E │ 62  3E  NUL│ 87  57   NUL│ 97  61  NUL │ 107  6B  NUL │
  19441.  │F5      │63  3F │ 63  3F  NUL│ 88  58   NUL│ 98  62  NUL │ 108  6C  NUL │
  19442.  │F6      │64  40 │ 64  40  NUL│ 89  59   NUL│ 99  63  NUL │ 109  6D  NUL │
  19443.  │F7      │65  41 │ 65  41  NUL│ 90  5A   NUL│100  64  NUL │ 110  6E  NUL │
  19444.  │F8      │66  42 │ 66  46  NUL│ 91  5B   NUL│101  65  NUL │ 111  6F  NUL │
  19445.  │F9      │67  43 │ 67  43  NUL│ 92  5C   NUL│102  66  NUL │ 112  70  NUL │
  19446.  │F10     │68  44 │ 68  44  NUL│ 93  5D   NUL│103  67  NUL │ 113  71  NUL │
  19447.  │NUM     │69  45 │            │             │             │              │
  19448.  │SCROLL  │70  46 │            │             │             │              │
  19449.  │HOME    │71  47 │ 71  47 NUL │ 55  37   7  │119  77  NUL │              │
  19450.  │UP      │72  48 │ 72  48 NUL │ 56  38   8  │             │              │
  19451.  │PGUP    │73  49 │ 73  49 NUL │ 57  39   9  │132  84  NUL │              │
  19452.  │GREY-   │74  4A │ 45  2D  -  │ 45  2D   -  │             │              │
  19453.  │LEFT    │75  4B │ 75  4B NUL │ 52  34   4  │115  73  NUL │              │
  19454.  │CENTER  │76  4C │            │ 53  35   5  │             │              │
  19455.  │RIGHT   │77  4D │ 77  4D NUL │ 54  36   6  │116  74  NUL │              │
  19456.  │GREY+   │78  4E │ 43  2B  +  │ 43  2b   +  │             │              │
  19457.  │END     │79  4F │ 79  4F NUL │ 49  31   1  │117  75  NUL │              │
  19458.  │DOWN    │80  50 │ 80  50 NUL │ 50  32   2  │             │              │
  19459.  │PGDN    │81  51 │ 81  51 NUL │ 51  33   3  │118  76  NUL │              │
  19460.  │INS     │82  52 │ 82  52 NUL │ 48  30   0  │             │              │
  19461.  │DEL     │83  53 │ 83  53 NUL │ 46  2E   .  │             │              │
  19462.  └────────┴───────┴────────────┴─────────────┴─────────────┴──────────────┘
  19463.  
  19464.  ┌──────────────────────┐   ┌────────────┐   ┌────────────┐   ┌────────────┐
  19465.  │Ctrl Dec Hex Char Code│   │Dec Hex Char│   │Dec Hex Char│   │Dec Hex Char│
  19466.  ├────┬───┬───┬────┬────┤   ├───┬───┬────┤   ├───┬───┬────┤   ├───┬───┬────┤
  19467.  │ ^@ │  0│00 │    │ NUL│   │ 32│ 20│    │   │ 64│40 │ @  │   │ 96│60 │ `  │
  19468.  │ ^A │  1│01 │   │ SOH│   │ 33│ 21│ !  │   │ 65│41 │ A  │   │ 97│61 │ a  │
  19469.  │ ^B │  2│02 │   │ STX│   │ 34│ 22│ "  │   │ 66│42 │ B  │   │ 98│62 │ b  │
  19470.  │ ^C │  3│03 │   │ ETX│   │ 35│ 23│ #  │   │ 67│43 │ C  │   │ 99│63 │ c  │
  19471.  │ ^D │  4│04 │   │ EOT│   │ 36│ 24│ $  │   │ 68│44 │ D  │   │100│64 │ d  │
  19472.  │ ^E │  5│05 │   │ ENQ│   │ 37│ 25│ %  │   │ 69│45 │ E  │   │101│65 │ e  │
  19473.  │ ^F │  6│06 │   │ ACK│   │ 38│ 26│ &  │   │ 70│46 │ F  │   │102│66 │ f  │
  19474.  │ ^G │  7│07 │   │ BEL│   │ 39│ 27│ '  │   │ 71│47 │ G  │   │103│67 │ g  │
  19475.  │ ^H │  8│08 │   │ BS │   │ 40│ 28│ (  │   │ 72│48 │ H  │   │104│68 │ h  │
  19476.  │ ^I │  9│09 │    │ HT │   │ 41│ 29│ )  │   │ 73│49 │ I  │   │105│69 │ i  │
  19477.  │ ^J │ 10│0A │    │ LF │   │ 42│ 2A│ *  │   │ 74│4A │ J  │   │106│6A │ j  │
  19478.  │ ^K │ 11│0B │    │ VT │   │ 43│ 2B│ +  │   │ 75│4B │ K  │   │107│6B │ k  │
  19479.  │ ^L │ 12│0C │    │ FF │   │ 44│ 2C│ ,  │   │ 76│4C │ L  │   │108│6C │ l  │
  19480.  │ ^M │ 13│0D │    │ CR │   │ 45│ 2D│ -  │   │ 77│4D │ M  │   │109│6D │ m  │
  19481.  │ ^N │ 14│0E │   │ SO │   │ 46│ 2E│ .  │   │ 78│4E │ N  │   │110│6E │ n  │
  19482.  │ ^O │ 15│0F │    │ SI │   │ 47│ 2F│ /  │   │ 79│4F │ O  │   │111│6F │ o  │
  19483.  │ ^P │ 16│10 │   │ DLE│   │ 48│ 30│ 0  │   │ 80│50 │ P  │   │112│70 │ p  │
  19484.  │ ^Q │ 17│11 │   │ DC1│   │ 49│ 31│ 1  │   │ 81│51 │ Q  │   │113│71 │ q  │
  19485.  │ ^R │ 18│12 │   │ DC2│   │ 50│ 32│ 2  │   │ 82│52 │ R  │   │114│72 │ r  │
  19486.  │ ^S │ 19│13 │   │ DC3│   │ 51│ 33│ 3  │   │ 83│53 │ S  │   │115│73 │ s  │
  19487.  │ ^T │ 20│14 │   │ DC4│   │ 52│ 34│ 4  │   │ 84│54 │ T  │   │116│74 │ t  │
  19488.  │ ^U │ 21│15 │   │ NAK│   │ 53│ 35│ 5  │   │ 85│55 │ U  │   │117│75 │ u  │
  19489.  │ ^V │ 22│ 16│   │ SYN│   │ 54│ 36│ 6  │   │ 86│ 56│ V  │   │118│ 76│ v  │
  19490.  │ ^W │ 23│ 17│   │ ETB│   │ 55│ 37│ 7  │   │ 87│ 57│ W  │   │119│ 77│ w  │
  19491.  │ ^X │ 24│ 18│   │ CAN│   │ 56│ 38│ 8  │   │ 88│ 58│ X  │   │120│ 78│ x  │
  19492.  │ ^Y │ 25│ 19│   │ EM │   │ 57│ 39│ 9  │   │ 89│ 59│ Y  │   │121│ 79│ y  │
  19493.  │ ^Z │ 26│ 1A│    │ SUB│   │ 58│ 3A│ :  │   │ 90│ 5A│ Z  │   │122│ 7A│ z  │
  19494.  │ ^[ │ 27│ 1B│   │ ESC│   │ 59│ 3B│ ;  │   │ 91│ 5B│ [  │   │123│ 7B│ {  │
  19495.  │ ^\ │ 28│ 1C│   │ FS │   │ 60│ 3C│ <  │   │ 92│ 5C│ \  │   │124│ 7C│ |  │
  19496.  │ ^} │ 29│ 1D│   │ GS │   │ 61│ 3D│ =  │   │ 93│ 5D│ ]  │   │125│ 7D│ }  │
  19497.  │ ^^ │ 30│ 1E│   │ RS │   │ 62│ 3E│ >  │   │ 94│ 5E│ ^  │   │126│ 7E│ ~  │
  19498.  │ ^_ │ 31│ 1F│   │ US │   │ 63│ 3F│ ?  │   │ 95│ 5F│ _  │   │127│ 7F│    │
  19499.  └────┴───┴───┴────┴────┘   └───┴───┴────┘   └───┴───┴────┘   └───┴───┴────┘
  19500.  
  19501.  ┌────────────┐       ┌────────────┐       ┌────────────┐       ┌────────────┐
  19502.  │Dec Hex Char│       │Dec Hex Char│       │Dec Hex Char│       │Dec Hex Char│
  19503.  ├───┬───┬────┤       ├───┬───┬────┤       ├───┬───┬────┤       ├───┬───┬────┤
  19504.  │128│ 80│ Ç  │       │160│ A0│ á  │       │192│ C0│ └  │       │224│ E0│ α  │
  19505.  │129│ 81│ ü  │       │161│ A1│ í  │       │193│ C1│ ┴  │       │225│ E1│ ß  │
  19506.  │130│ 82│ é  │       │162│ A2│ ó  │       │194│ C2│ ┬  │       │226│ E2│ Γ  │
  19507.  │131│ 83│ â  │       │163│ A3│ ú  │       │195│ C3│ ├  │       │227│ E3│ π  │
  19508.  │132│ 84│ ä  │       │164│ A4│ ñ  │       │196│ C4│ ─  │       │228│ E4│ Σ  │
  19509.  │133│ 85│ à  │       │165│ A5│ Ñ  │       │197│ C5│ ┼  │       │229│ E5│ σ  │
  19510.  │134│ 86│ å  │       │166│ A6│ ª  │       │198│ C6│ ╞  │       │230│ E6│ µ  │
  19511.  │135│ 87│ ç  │       │167│ A7│ º  │       │199│ C7│ ╟  │       │231│ E7│ τ  │
  19512.  │136│ 88│ ê  │       │168│ A8│ ¿  │       │200│ C8│ ╚  │       │232│ E8│ Φ  │
  19513.  │137│ 89│ ë  │       │169│ A9│ ⌐  │       │201│ C9│ ╔  │       │233│ E9│ Θ  │
  19514.  │138│ 90│ è  │       │170│ AA│ ¬  │       │202│ CA│ ╩  │       │234│ EA│ Ω  │
  19515.  │139│ 91│ ï  │       │171│ AB│ ½  │       │203│ CB│ ╦  │       │235│ EB│ δ  │
  19516.  │140│ 92│ î  │       │172│ AC│ ¼  │       │204│ CC│ ╠  │       │236│ EC│ ∞  │
  19517.  │141│ 93│ ì  │       │173│ AD│ ¡  │       │205│ CD│ ═  │       │237│ ED│ φ  │
  19518.  │142│ 94│ Ä  │       │174│ AE│ «  │       │206│ CE│ ╬  │       │238│ EE│ ε  │
  19519.  │143│ 95│ Å  │       │175│ AF│ »  │       │207│ CF│ ╧  │       │239│ EF│ ∩  │
  19520.  │144│ 96│ É  │       │176│ B0│ ░  │       │208│ D0│ ╨  │       │240│ F0│ ≡  │
  19521.  │145│ 97│ æ  │       │177│ B1│ ▒  │       │209│ D1│ ╤  │       │241│ F1│ ±  │
  19522.  │146│ 98│ Æ  │       │178│ B2│ ▓  │       │210│ D2│ ╥  │       │242│ F2│ ≥  │
  19523.  │147│ 99│ ô  │       │179│ B3│ │  │       │211│ D3│ ╙  │       │243│ F3│ ≤  │
  19524.  │148│ 9A│ ö  │       │180│ B4│ ┤  │       │212│ D4│ ╘  │       │244│ F4│ ⌠  │
  19525.  │149│ 9B│ ò  │       │181│ B5│ ╡  │       │213│ D5│ ╒  │       │245│ F5│ ⌡  │
  19526.  │150│ 96│ û  │       │182│ B6│ ╢  │       │214│ D6│ ╓  │       │246│ F6│ ÷  │
  19527.  │151│ 97│ ù  │       │183│ B7│ ╖  │       │215│ D7│ ╫  │       │247│ F7│ ≈  │
  19528.  │152│ 98│ ÿ  │       │184│ B8│ ╕  │       │216│ D8│ ╪  │       │248│ F8│ °  │
  19529.  │153│ 99│ Ö  │       │185│ B9│ ╣  │       │217│ D9│ ≈  │       │249│ F9│ ∙  │
  19530.  │154│ 9A│ Ü  │       │186│ BA│ ║  │       │218│ DA│ ┌  │       │250│ FA│ ·  │
  19531.  │155│ 9B│ ¢  │       │187│ BB│ ╗  │       │219│ DB│ █  │       │251│ FB│ √  │
  19532.  │156│ 9C│ £  │       │188│ BC│ ╝  │       │220│ DC│ ▄  │       │252│ FC│ ⁿ  │
  19533.  │157│ 9D│ ¥  │       │189│ BD│ ╜  │       │221│ DD│ ▌  │       │253│ FD│ ²  │
  19534.  │158│ 9E│ ₧  │       │190│ BE│ ╛  │       │222│ DE│ ▐  │       │254│ FE│ ■  │
  19535.  │159│ 9F│ ƒ  │       │191│ BF│ ┐  │       │223│ DF│ ▀  │       │255│ FF│    │
  19536.  └───┴───┴────┘       └───┴───┴─┴──┘       └───┴───┴────┘       └───┴───┴────┘
  19537.  
  19538.  
  19539.  A.2  ASCII Character Codes
  19540.  
  19541. ╓┌─┌───────────┌────────────┌───────────┌────────────────────────────────────╖
  19542.                     Number
  19543.    Char        Dec          Hex         Control
  19544.    ──────────────────────────────────────────────────────────────────────────
  19545.                0            00H         NUL (Null)
  19546.               1            01H         SOH (Start of heading)
  19547.               2            02H         STX (Start of text)
  19548.               3            03H         ETX (End of text)
  19549.               4            04H         EOT (End of transmission)
  19550.               5            05H         ENQ (Enquiry)
  19551.               6            06H         ACK (Acknowledge)
  19552.               7            07H         BEL (Bell)
  19553.                     Number
  19554.    Char        Dec          Hex         Control
  19555.    ──────────────────────────────────────────────────────────────────────────
  19556.              7            07H         BEL (Bell)
  19557.               8            08H         BS (Backspace)
  19558.                9            09H         HT (Horizontal tab)
  19559.                10           0AH         LF (Linefeed)
  19560.                11           0BH         VT (Vertical tab)
  19561.                12           0CH         FF (Formfeed)
  19562.                13           0DH         CR (Carriage return)
  19563.               14           EH          SO (Shift out)
  19564.                15           0FH         SI (Shift in)
  19565.               16           10H         DLE (Data link escape)
  19566.               17           11H         DC1 (Device control 1)
  19567.               18           12H         DC2 (Device control 2)
  19568.               19           13H         DC3 (Device control 3)
  19569.               20           14H         DC4 (Device control 4)
  19570.               21           15H         NAK (Negative acknowledge)
  19571.               22           16H         SYN (Synchronous idle)
  19572.               23           17H         ETB (End transmission block)
  19573.               24           18H         CAN (Cancel)
  19574.                     Number
  19575.    Char        Dec          Hex         Control
  19576.    ──────────────────────────────────────────────────────────────────────────
  19577.              24           18H         CAN (Cancel)
  19578.               25           19H         EM (End of medium)
  19579.                26           1AH         SUB (Substitute)
  19580.               27           1BH         ESC (Escape)
  19581.               28           1CH         FS (File separator)
  19582.               29           1DH         GS (Group separator)
  19583.               30           1EH         RS (Record separator)
  19584.               31           1FH         US (Unit separator)
  19585.                32           20H
  19586.    !           33           21H
  19587.    "           34           22H
  19588.    #           35           23H
  19589.    $           36           24H
  19590.    %           37           25H
  19591.    &           38           26H
  19592.    '           39           27H
  19593.    (           40           28H
  19594.    )           41           29H
  19595.                     Number
  19596.    Char        Dec          Hex         Control
  19597.    ──────────────────────────────────────────────────────────────────────────
  19598.   )           41           29H
  19599.    *           42           2AH
  19600.    +           43           2BH
  19601.    ,           44           2CH
  19602.    -           45           2DH
  19603.    .           46           2EH
  19604.    /           47           2FH
  19605.    0           48           30H
  19606.    1           49           31H
  19607.    2           50           32H
  19608.    3           51           33H
  19609.    4           52           34H
  19610.    5           53           35H
  19611.    6           54           36H
  19612.    7           55           37H
  19613.    8           56           38H
  19614.    9           57           39H
  19615.    :           58           3AH
  19616.                     Number
  19617.    Char        Dec          Hex         Control
  19618.    ──────────────────────────────────────────────────────────────────────────
  19619.   :           58           3AH
  19620.    ;           59           3BH
  19621.    <           60           3CH
  19622.    =           61           3DH
  19623.    >           62           3EH
  19624.    ?           63           3FH
  19625.    @           64           40H
  19626.    A           65           41H
  19627.    B           66           42H
  19628.    C           67           43H
  19629.    D           68           44H
  19630.    E           69           45H
  19631.    F           70           46H
  19632.    G           71           47H
  19633.    H           72           48H
  19634.    I           73           49H
  19635.    J           74           4AH
  19636.    K           75           4BH
  19637.                     Number
  19638.    Char        Dec          Hex         Control
  19639.    ──────────────────────────────────────────────────────────────────────────
  19640.   K           75           4BH
  19641.    L           76           4CH
  19642.    M           77           4DH
  19643.    N           78           4EH
  19644.    O           79           4FH
  19645.    P           80           50H
  19646.    Q           81           51H
  19647.    R           82           52H
  19648.    S           83           53H
  19649.    T           84           54H
  19650.    U           85           55H
  19651.    V           86           56H
  19652.    W           87           57H
  19653.    X           88           58H
  19654.    Y           89           59H
  19655.    Z           90           5AH
  19656.    [           91           5BH
  19657.    \           92           5CH
  19658.                     Number
  19659.    Char        Dec          Hex         Control
  19660.    ──────────────────────────────────────────────────────────────────────────
  19661.   \           92           5CH
  19662.    ]           93           5DH
  19663.    ^           94           5EH
  19664.    _           95           5FH
  19665.    g           96           60H
  19666.    a           97           61H
  19667.    b           98           62H
  19668.    c           99           63H
  19669.    d           100          64H
  19670.    e           101          65H
  19671.    f           102          66H
  19672.    g           103          67H
  19673.    h           104          68H
  19674.    i           105          69H
  19675.    j           106          6AH
  19676.    k           107          6BH
  19677.    l           108          6CH
  19678.    m           109          6DH
  19679.                     Number
  19680.    Char        Dec          Hex         Control
  19681.    ──────────────────────────────────────────────────────────────────────────
  19682.   m           109          6DH
  19683.    n           110          6EH
  19684.    o           111          6FH
  19685.    p           112          70H
  19686.    q           113          71H
  19687.    r           114          72H
  19688.    s           115          73H
  19689.    t           116          74H
  19690.    u           117          75H
  19691.    v           118          76H
  19692.    w           119          77H
  19693.    x           120          78H
  19694.    y           121          79H
  19695.    z           122          7AH
  19696.    {           123          7BH
  19697.    |           124          7CH
  19698.    }           125          7DH
  19699.    ~           126          7EH
  19700.                     Number
  19701.    Char        Dec          Hex         Control
  19702.    ──────────────────────────────────────────────────────────────────────────
  19703.   ~           126          7EH
  19704.                127          7FH         DEL (Delete)
  19705.    Ç           128          80H
  19706.    ü           129          81H
  19707.    é           130          82H
  19708.    â           131          83H
  19709.    ä           132          84H
  19710.    à           133          85H
  19711.    å           134          86H
  19712.    ç           135          87H
  19713.    ê           136          88H
  19714.    ë           137          89H
  19715.    è           138          8AH
  19716.    ï           139          8BH
  19717.    î           140          8CH
  19718.    ì           141          8DH
  19719.    Ä           142          8EH
  19720.    Å           143          8FH
  19721.                     Number
  19722.    Char        Dec          Hex         Control
  19723.    ──────────────────────────────────────────────────────────────────────────
  19724.   Å           143          8FH
  19725.    É           144          90H
  19726.    æ           145          91H
  19727.    Æ           146          92H
  19728.    ô           147          93H
  19729.    ö           148          94H
  19730.    ò           149          95H
  19731.    û           150          96H
  19732.    ù           151          97H
  19733.    ÿ           152          98H
  19734.    Ö           153          99H
  19735.    Ü           154          9AH
  19736.    ¢           155          9BH
  19737.    £           156          9CH
  19738.    ¥           157          9DH
  19739.    ₧           158          9EH
  19740.    ƒ           159          9FH
  19741.    á           160          A0H
  19742.                     Number
  19743.    Char        Dec          Hex         Control
  19744.    ──────────────────────────────────────────────────────────────────────────
  19745.   á           160          A0H
  19746.    í           161          A1H
  19747.    ó           162          A2H
  19748.    ú           163          A3H
  19749.    ñ           164          A4H
  19750.    Ñ           165          A5H
  19751.    ª           166          A6H
  19752.    º           167          A7H
  19753.    ¿           168          A8H
  19754.    ⌐           169          A9H
  19755.    ¬           170          AAH
  19756.    ½           171          ABH
  19757.    ¼           172          ACH
  19758.    ¡           173          ADH
  19759.    «           174          AEH
  19760.    »           175          AFH
  19761.    ░           176          B0H
  19762.    ▒           177          B1H
  19763.                     Number
  19764.    Char        Dec          Hex         Control
  19765.    ──────────────────────────────────────────────────────────────────────────
  19766.   ▒           177          B1H
  19767.    ▓           178          B2H
  19768.    │           179          B3H
  19769.    ┤           180          B4H
  19770.    ╡           181          B5H
  19771.    ╢           182          B6H
  19772.    ╖           183          B7H
  19773.    ╕           184          B8H
  19774.    ╣           185          B9H
  19775.    ║           186          BAH
  19776.    ╗           187          BBH
  19777.    ╝           188          BCH
  19778.    ╜           189          BDH
  19779.    ╛           190          BEH
  19780.    ┐           191          BFH
  19781.    └           192          C0H
  19782.    ┴           193          C1H
  19783.    ┬           194          C2H
  19784.                     Number
  19785.    Char        Dec          Hex         Control
  19786.    ──────────────────────────────────────────────────────────────────────────
  19787.   ┬           194          C2H
  19788.    ├           195          C3H
  19789.    ─           196          C4H
  19790.    ┼           197          C5H
  19791.    ╞           198          C6H
  19792.    ╟           199          C7H
  19793.    ╚           200          C8H
  19794.    ╔           201          C9H
  19795.    ╩           202          CAH
  19796.    ╦           203          CBH
  19797.    ╠           204          CCH
  19798.    ═           205          CDH
  19799.    ╬           206          CEH
  19800.    ╧           207          CFH
  19801.    ╨           208          D0H
  19802.    ╤           209          D1H
  19803.    ╥           210          D2H
  19804.    ╙           211          D3H
  19805.                     Number
  19806.    Char        Dec          Hex         Control
  19807.    ──────────────────────────────────────────────────────────────────────────
  19808.   ╙           211          D3H
  19809.    ╘           212          D4H
  19810.    ╒           213          D5H
  19811.    ╓           214          D6H
  19812.    ╫           215          D7H
  19813.    ╪           216          D8H
  19814.    ┘           217          D9H
  19815.    ┌           218          DAH
  19816.    █           219          DBH
  19817.    ▄           220          DCH
  19818.    ▌           221          DDH
  19819.    ▐           222          DEH
  19820.    ▀           223          DFH
  19821.                224          E0H
  19822.    ß           225          E1H
  19823.    Γ           226          E2H
  19824.    π           227          E3H
  19825.    Σ           228          E4H
  19826.                     Number
  19827.    Char        Dec          Hex         Control
  19828.    ──────────────────────────────────────────────────────────────────────────
  19829.   Σ           228          E4H
  19830.    σ           229          E5H
  19831.    µ           230          E6H
  19832.    τ           231          E7H
  19833.    Φ           232          E8H
  19834.    Θ           233          E9H
  19835.    Ω           234          EAH
  19836.    δ           235          EBH
  19837.    ∞           236          ECH
  19838.    φ           237          EDH
  19839.    ε           238          EEH
  19840.    ∩           239          EFH
  19841.    ≡           240          F0H
  19842.    ±           241          F1H
  19843.    ≥           242          F2H
  19844.    ≤           243          F3H
  19845.    ⌠           244          F4H
  19846.    ⌡           245          F5H
  19847.                     Number
  19848.    Char        Dec          Hex         Control
  19849.    ──────────────────────────────────────────────────────────────────────────
  19850.   ⌡           245          F5H
  19851.    ÷           246          F6H
  19852.    ≈           247          F7H
  19853.    °           248          F8H
  19854.    ∙           249          F9H
  19855.    ·           250          FAH
  19856.    √           251          FBH
  19857.    ⁿ           252          FCH
  19858.    ²           253          FDH
  19859.    ■           254          FEH
  19860.                255          FFH
  19861.    ──────────────────────────────────────────────────────────────────────────
  19862.  
  19863.  
  19864.  
  19865.  
  19866.  
  19867.  ────────────────────────────────────────────────────────────────────────────
  19868.  Appendix B  Error Messages
  19869.  
  19870.        B.1  Error-Message Display
  19871.        B.2  Invocation, Compile-Time, and Run-Time Error Messages
  19872.        B.3  LINK Error Messages
  19873.        B.4  LIB Error Messages
  19874.    During development of a BASIC program with QuickBASIC, the following types
  19875.    of errors can occur:
  19876.  
  19877.    ■ Invocation errors
  19878.  
  19879.    ■ Compile-time errors
  19880.  
  19881.    ■ Link-time errors
  19882.  
  19883.    ■ Run-time errors
  19884.  
  19885.    Each type of error is associated with a particular step in the program
  19886.    development process. Invocation errors occur when you invoke QuickBASIC
  19887.    with the QB or BC commands. Compile-time errors (and warnings) occur
  19888.    during compilation, and run-time errors occur when the program is
  19889.    executing. Link-time errors occur only when you use the LINK command to
  19890.    link object files created with BC or other language compilers.
  19891.  
  19892.    Section B.2 lists alphabetically the invocation, compile-time, and
  19893.    run-time error messages, along with any error codes that are assigned.
  19894.    Table B.1 lists the run-time error messages and error codes in numerical
  19895.    order. Section B.3 lists the Microsoft Overlay Linker error messages, and
  19896.    Section B.4, the Microsoft Library Manager error messages.
  19897.  
  19898.  
  19899.  B.1  Error-Message Display
  19900.  
  19901.    When a run-time error occurs within the QuickBASIC environment (with
  19902.    default screen options), the error message appears in a dialog box and the
  19903.    cursor is placed on the line where the error occurred.
  19904.  
  19905.    In stand-alone executable programs (that is, programs that are executed by
  19906.    entering the base name of the executable file at the system prompt), the
  19907.    run-time system prints the error messages followed by an address, unless
  19908.    the /D, /E, or /W option is specified on the BC command line. In those
  19909.    cases, the error message is followed by the number of the line in which
  19910.    the error occurred. The standard forms of this type of error message are
  19911.    as follows:
  19912.  
  19913.    Error n in module module-name at address segment:offset
  19914.  
  19915.    and
  19916.  
  19917.    Error n in line linenumber of module module-name at address segment:offset
  19918.  
  19919.    An ERR code is listed for some errors. If an error occurs, the value
  19920.    returned by ERR is set to the appropriate code when an error-trapping
  19921.    subroutine is entered. (Error-trapping routines are entered via the ON
  19922.    ERROR statement.) The ERR value remains unchanged until a RESUME statement
  19923.    returns control to the main program. See Chapter 6, "Error and Event
  19924.    Trapping," in Programming in BASIC for more information.
  19925.  
  19926.    Table B.1 lists the error codes in numerical order. See the alphabetical
  19927.    listing for explanations of the errors.
  19928.  
  19929.    Table B.1   Run-Time Error Codes
  19930.  
  19931. ╓┌─┌───────────┌────────────────────────┌───────────┌────────────────────────╖
  19932.    Code        Description              Code        Description
  19933.    ──────────────────────────────────────────────────────────────────────────
  19934.    2           Syntax error             53          File not found
  19935.  
  19936.    3           RETURN without GOSUB     54          Bad file mode
  19937.  
  19938.    4           Out of DATA              55          File already open
  19939.  
  19940.    5           Illegal function call    56          FIELD statement active
  19941.  
  19942.    6           Overflow                 57          Device I/O error
  19943.  
  19944.    7           Out of memory            58          File already exists
  19945.  
  19946.    9           Subscript out of range   59          Bad record length
  19947.  
  19948.    10          Duplicate definition     61          Disk full
  19949.  
  19950.    11          Division by zero         62          Input past end of file
  19951.  
  19952.    Code        Description              Code        Description
  19953.    ──────────────────────────────────────────────────────────────────────────
  19954. 
  19955.    13          Type mismatch            63          Bad record number
  19956.  
  19957.    14          Out of string space      64          Bad file name
  19958.  
  19959.    16          String formula too       67          Too many files
  19960.                complex
  19961.  
  19962.    19          No RESUME                68          Device unavailable
  19963.  
  19964.    20          RESUME without error     69          Communication-buffer
  19965.                                                     overflow
  19966.  
  19967.    24          Device timeout           70          Permission denied
  19968.  
  19969.    25          Device fault             71          Disk not ready
  19970.  
  19971.    27          Out of paper             72          Disk-media error
  19972.  
  19973.    Code        Description              Code        Description
  19974.    ──────────────────────────────────────────────────────────────────────────
  19975. 
  19976.    39          CASE ELSE expected       73          Advanced feature
  19977.                                                     unavailable
  19978.  
  19979.    40          Variable required        74          Rename across disks
  19980.  
  19981.    50          FIELD overflow           75          Path/File access error
  19982.  
  19983.    51          Internal error           76          Path not found
  19984.  
  19985.    52          Bad file name or number
  19986.  
  19987.    ──────────────────────────────────────────────────────────────────────────
  19988.  
  19989.  
  19990.    QYInvocation Error
  19991.  
  19992.  
  19993.  B.2  Invocation, Compile-Time, and Run-Time Error Messages
  19994.  
  19995.  Advanced feature unavailable
  19996.  
  19997.    You are attempting to use a feature of QuickBASIC that is available with
  19998.    another version of BASIC, or supported only under a later version of DOS.
  19999.    (Compile-time or run-time error)
  20000.  
  20001.    ERR code: 73
  20002.  
  20003.  Argument-count mismatch
  20004.  
  20005.    You are using an incorrect number of arguments with a BASIC subprogram or
  20006.    function. (Compile-time error)
  20007.  
  20008.  Array already dimensioned
  20009.  
  20010.    This error can be caused by any of the following:
  20011.  
  20012.    ■ More than one DIM statement for the same static array.
  20013.  
  20014.    ■ A DIM statement after the initial use of an array. Dynamic arrays must
  20015.      be deallocated with the ERASE statement before they can be redimensioned
  20016.      with DIM; dynamic arrays may also be redimensioned with the REDIM
  20017.      statement.
  20018.  
  20019.    ■ An OPTION BASE statement that occurs after an array is dimensioned.
  20020.  
  20021.    (Compile-time or run-time error)
  20022.  
  20023.  Array not defined
  20024.  
  20025.    An array is referenced but never defined. (Compile-time error)
  20026.  
  20027.  Array not dimensioned
  20028.  
  20029.    An array is referenced but not dimensioned. If you are compiling the
  20030.    program with BC, this error is not "fatal"; the program will execute,
  20031.    although program results may be incorrect. (Compile-time warning)
  20032.  
  20033.  Array too big
  20034.  
  20035.    There is not enough user data space to accommodate the array declaration.
  20036.    Reduce the size of the array or use the ¢DYNAMIC metacommand. You may also
  20037.    get this error if the array size exceeds 64K, the array is not dynamic,
  20038.    and the /AH option is not used. Reduce the size of the array, or make the
  20039.    array dynamic and use the /AH command-line option. (Compile-time error)
  20040.  
  20041.  AS clause required
  20042.  
  20043.    A variable declared with an AS clause is referenced without one. If the
  20044.    first declaration of a variable has an AS clause, every subsequent DIM,
  20045.    REDIM, SHARED, and COMMON statement that references that variable must
  20046.    have an AS clause. (Compile-time error)
  20047.  
  20048.  AS clause required on first declaration
  20049.  
  20050.    A variable that has not been declared using an AS clause is being
  20051.    referenced with an AS clause. (Compile-time error)
  20052.  
  20053.  AS missing
  20054.  
  20055.    The compiler expects an AS keyword, as in OPEN "FILENAME" FOR INPUT AS #1.
  20056.    (Compile-time error)
  20057.  
  20058.  Asterisk missing
  20059.  
  20060.    The asterisk is missing from a string definition in a user type.
  20061.    (Compile-time error)
  20062.  
  20063.  Bad file mode
  20064.  
  20065.    This error occurs in the following situations:
  20066.  
  20067.    ■ The program tries to use PUT or GET with a sequential file or execute an
  20068.      OPEN statement with a file mode other than I, O, or R.
  20069.  
  20070.    ■ The program tries to use a FIELD statement with a file not opened for
  20071.      random access.
  20072.  
  20073.    ■ The program tries to print to a file opened for input.
  20074.  
  20075.    ■ The program tries to read from a file opened for output or appending.
  20076.  
  20077.    ■ QuickBASIC tries to use an include file previously saved in compressed
  20078.      format. Include files must be saved in text format. Reload the include
  20079.      file, save it in text format, then try to run the program again.
  20080.  
  20081.    ■ You try to load a corrupt binary program.
  20082.  
  20083.    (Run-time error)
  20084.  
  20085.    ERR code: 54
  20086.  
  20087.  Bad file name
  20088.  
  20089.    An illegal form is used for the file name with LOAD, SAVE, KILL, or OPEN
  20090.    (for example, the file name has too many characters). (Run-time error)
  20091.  
  20092.    ERR code: 64
  20093.  
  20094.  Bad file name or number
  20095.  
  20096.    A statement or command references a file with a file name or number that
  20097.    is not specified in the OPEN statement or is out of the range of file
  20098.    numbers specified earlier in the program. (Run-time error)
  20099.  
  20100.    ERR code: 52
  20101.  
  20102.  Bad record length
  20103.  
  20104.    A GET or PUT statement that specified a record variable whose length did
  20105.    not match the record length specified in the corresponding OPEN statement
  20106.    was executed. (Run-time error)
  20107.  
  20108.    ERR code: 59
  20109.  
  20110.  Bad record number
  20111.  
  20112.    In a PUT or GET statement, the record number is less than or equal to
  20113.    zero. (Run-time error)
  20114.  
  20115.    ERR code: 63
  20116.  
  20117.  BASE missing
  20118.  
  20119.    QuickBASIC expected the keyword BASE here, as in OPTION BASE.
  20120.  
  20121.    (Compile-time error)
  20122.  
  20123.  Binary source file
  20124.  
  20125.    The file you have attempted to compile is not an ASCII file. All source
  20126.    files saved by BASICA should be saved with the ,A option. QuickBASIC also
  20127.    uses this message to warn you when you try to use the /ZI or /ZD CodeView
  20128.    options with binary source files. (Compile-time error)
  20129.  
  20130.  Block IF without END IF
  20131.  
  20132.    There is no corresponding END IF in a block IF construct. (Compile-time
  20133.    error)
  20134.  
  20135.  Buffer size expected after /C:
  20136.  
  20137.    You must specify a buffer size after the /C option. (BC invocation error)
  20138.  
  20139.  BYVAL allowed only with numeric arguments
  20140.  
  20141.    BYVAL does not accept string or record arguments. (Compile-time error)
  20142.  
  20143.  /C: buffer size too large
  20144.  
  20145.    The maximum size of the communications buffer is 32,767 bytes. (BC
  20146.    invocation error)
  20147.  
  20148.  Cannot continue
  20149.  
  20150.    While debugging, you have made a change that prevents execution from
  20151.    continuing. (Run-time error)
  20152.  
  20153.  Cannot find file (filename). Input path:
  20154.  
  20155.    This error occurs when QuickBASIC cannot find a Quick library or utility
  20156.    (BC.EXE, LINK.EXE, LIB.EXE, or QB.EXE) required by the program. Enter the
  20157.    correct path name, or press CTRL+C to return to the DOS prompt. (QB
  20158.    invocation error)
  20159.  
  20160.  Cannot generate listing for BASIC binary source files
  20161.  
  20162.    You are attempting to compile a binary source file with the BC command and
  20163.    the /A option. Recompile without the /A option. (BC invocation error)
  20164.  
  20165.  Cannot start with `FN'
  20166.  
  20167.    You used "FN" as the first two letters of a subprogram or variable name.
  20168.    "FN" can only be used as the first two letters when calling a DEF FN
  20169.    function. (Compile-time error)
  20170.  
  20171.  CASE ELSE expected
  20172.  
  20173.    No matching case was found for an expression in a SELECT CASE statement.
  20174.    (Run-time error)
  20175.  
  20176.    ERR code: 39
  20177.  
  20178.  CASE without SELECT
  20179.  
  20180.    The first part of a SELECT CASE statement is missing or misspelled.
  20181.    (Compile-time error)
  20182.  
  20183.  Colon expected after /C
  20184.  
  20185.    A colon is required between the option and the buffer size argument. (BC
  20186.    invocation error)
  20187.  
  20188.  Comma missing
  20189.  
  20190.    QuickBASIC expects a comma. (Compile-time error)
  20191.  
  20192.  COMMON and DECLARE must precede executable statements
  20193.  
  20194.    A COMMON statement or a DECLARE statement is misplaced. COMMON and DECLARE
  20195.    statements must appear before any executable statements. All BASIC
  20196.    statements are executable except the following:
  20197.  
  20198.    ■ COMMON
  20199.  
  20200.    ■ DEFtype
  20201.  
  20202.    ■ DIM (for static arrays)
  20203.  
  20204.    ■ OPTION BASE
  20205.  
  20206.    ■ REM
  20207.  
  20208.    ■ TYPE
  20209.  
  20210.    ■ All metacommands
  20211.  
  20212.    (Compile-time error)
  20213.  
  20214.  COMMON in Quick library too small
  20215.  
  20216.    More common variables are specified in the module than in the currently
  20217.    loaded Quick library. (Compile-time error)
  20218.  
  20219.  COMMON name illegal
  20220.  
  20221.    QuickBASIC encountered an illegal /blockname/ specification (for example,
  20222.    a blockname that is a BASIC reserved word) in a named COMMON block.
  20223.    (Compile-time error).
  20224.  
  20225.  Communication-buffer overflow
  20226.  
  20227.    During remote communications, the receive buffer overflowed. The size of
  20228.    the receive buffer is set by the /C command line option or the RB option
  20229.    in the OPEN COM statement. Try checking the buffer more frequently (with
  20230.    the LOC function) or emptying it more often (with the INPUT$ function).
  20231.    (Run-time error)
  20232.  
  20233.    ERR code: 69
  20234.  
  20235.  CONST/DIM SHARED follows SUB/FUNCTION
  20236.  
  20237.    CONST and DIM SHARED statements should appear before any subprogram or
  20238.    FUNCTION procedure definitions. If you are compiling your program with BC,
  20239.    this error is not "fatal"; the program will execute, although the results
  20240.    may be incorrect. (Compile-time warning)
  20241.  
  20242.  Control structure in IF...THEN...ELSE incomplete
  20243.  
  20244.    An unmatched NEXT, WEND, END IF, END SELECT, or LOOP statement appears in
  20245.    a single-line IF...THEN...ELSE statement. (Compile-time error)
  20246.  
  20247.  Data-memory overflow
  20248.  
  20249.    There is too much program data to fit in memory. This error is often
  20250.    caused by too many constants, or too much static array data. If you are
  20251.    using the BC command, or the Make EXE File or Make Library commands, try
  20252.    turning off any debugging options. If memory is still exhausted, break
  20253.    your program into parts and use the CHAIN statement or use the ¢DYNAMIC
  20254.    metacommand. (Compile-time error)
  20255.  
  20256.  DECLARE required
  20257.  
  20258.    An implicit SUB or FUNCTION procedure call appears before the procedure
  20259.    definition. (An implicit call does not use the CALL statement.) All
  20260.    procedures must be defined or declared before they are implicitly called.
  20261.    (Compile-time error)
  20262.  
  20263.  DEF FN not allowed in control statements
  20264.  
  20265.    DEF FN function definitions are not permitted inside control constructs
  20266.    such as IF...THEN...ELSE and SELECT CASE. (Compile-time error)
  20267.  
  20268.  DEF without END DEF
  20269.  
  20270.    There is no corresponding END DEF in a multiline function definition.
  20271.  
  20272.    (Compile-time error)
  20273.  
  20274.  DEFtype character specification illegal
  20275.  
  20276.    A DEFtype statement is entered incorrectly. DEF can only be followed by
  20277.    LNG, DBL, INT, SNG, STR, or (for user-defined functions) a blank space.
  20278.    (Compile-time error)
  20279.  
  20280.  Device fault
  20281.  
  20282.    A device has returned a hardware error. If this message occurs while data
  20283.    are being transmitted to a communications file, it indicates that the
  20284.    signals being tested with the OPEN COM statement were not found in the
  20285.    specified period of time. (Run-time error)
  20286.  
  20287.    ERR code: 25
  20288.  
  20289.  Device I/O error
  20290.  
  20291.    An I/O error occurred on a device I/O operation. The operating system
  20292.    cannot recover from the error. (Run-time error)
  20293.  
  20294.    ERR code: 57
  20295.  
  20296.  Device timeout
  20297.  
  20298.    The program did not receive information from an I/O device within a
  20299.    predetermined amount of time. (Run-time error)
  20300.  
  20301.    ERR code: 24
  20302.  
  20303.  Device unavailable
  20304.  
  20305.    The device you are attempting to access is not on line or does not exist.
  20306.    (Run-time error)
  20307.  
  20308.    ERR code: 68
  20309.  
  20310.  Disk full
  20311.  
  20312.    There is not enough room on the disk for the completion of a PRINT, WRITE,
  20313.    or CLOSE operation. This error can also occur if there is not enough room
  20314.    for QuickBASIC to write out an object or executable file. (Run-time error)
  20315.  
  20316.    ERR code: 61
  20317.  
  20318.  Disk-media error
  20319.  
  20320.    Disk-drive hardware has detected a physical flaw on the disk. (Run-time
  20321.    error)
  20322.  
  20323.    ERR code: 72
  20324.  
  20325.  Disk not ready
  20326.  
  20327.    The disk-drive door is open, or no disk is in the drive. (Run-time error)
  20328.  
  20329.    ERR code: 71
  20330.  
  20331.  Division by zero
  20332.  
  20333.    A division by zero is encountered in an expression, or an exponentiation
  20334.    operation results in zero being raised to a negative power. (Compile-time
  20335.    or run-time error)
  20336.  
  20337.    ERR code: 11
  20338.  
  20339.  DO without LOOP
  20340.  
  20341.    The terminating LOOP clause is missing from a DO...LOOP statement.
  20342.    (Compile-time error)
  20343.  
  20344.  Document too large
  20345.  
  20346.    Your document exceeds QuickBASIC's internal limit. Divide the document
  20347.    into separate files.
  20348.  
  20349.  Duplicate definition
  20350.  
  20351.    You are using an identifier that has already been defined. For example,
  20352.    you are attempting to use the same name in a CONST statement and as a
  20353.    variable definition, or the same name for a procedure and a variable.
  20354.  
  20355.    This error also occurs if you attempt to redimension an array. You must
  20356.    use DIM or REDIM when redimensioning dynamic arrays. (Compile-time or
  20357.    run-time error)
  20358.  
  20359.    ERR code: 10
  20360.  
  20361.  Duplicate label
  20362.  
  20363.    Two program lines are assigned the same number or label. Each line number
  20364.    or label in a module must be unique. (Compile-time error)
  20365.  
  20366.  Dynamic array element illegal
  20367.  
  20368.    Dynamic array elements are not allowed with VARPTR$. (Compile-time error)
  20369.  
  20370.  Element not defined
  20371.  
  20372.    A user-defined type element is referenced but not defined. For example, if
  20373.    the user-defined type MYTYPE contained elements A, B, and C, then an
  20374.    attempt to use the variable D as an element of MYTYPE would cause this
  20375.    message to appear. (Compile-time error)
  20376.  
  20377.  ELSE without IF
  20378.  
  20379.    An ELSE clause appears without a corresponding IF. Sometimes this error is
  20380.    caused by incorrectly nested IF statements. (Compile-time error)
  20381.  
  20382.  ELSEIF without IF
  20383.  
  20384.    An ELSEIF statement appears without a corresponding IF. Sometimes this
  20385.    error is caused by incorrectly nested IF statements. (Compile-time error)
  20386.  
  20387.  END DEF without DEF
  20388.  
  20389.    An END DEF statement has no corresponding DEF statement. (Compile-time
  20390.    error)
  20391.  
  20392.  END IF without block IF
  20393.  
  20394.    The beginning of an IF block is missing. (Compile-time error)
  20395.  
  20396.  END SELECT without SELECT
  20397.  
  20398.    The end of a SELECT CASE statement appears without a beginning SELECT
  20399.    CASE. The beginning of the SELECT CASE statement may be missing or
  20400.    misspelled. (Compile-time error)
  20401.  
  20402.  END SUB or END FUNCTION must be last line in window
  20403.  
  20404.    You are attempting to add code after a procedure. You must either return
  20405.    to the main module or open another module. (Compile-time error)
  20406.  
  20407.  END SUB/FUNCTION without SUB/FUNCTION
  20408.  
  20409.    You deleted the SUB or FUNCTION statement. (Compile-time error)
  20410.  
  20411.  END TYPE without TYPE
  20412.  
  20413.    An END TYPE statement is used outside a TYPE declaration. (Compile-time
  20414.    error)
  20415.  
  20416.  Equal sign missing
  20417.  
  20418.    QuickBASIC expects an equal sign. (Compile-time error)
  20419.  
  20420.  Error during QuickBASIC initialization
  20421.  
  20422.    Several conditions can cause this error. It is most commonly caused when
  20423.    there is not enough memory in the machine to load QuickBASIC. If you are
  20424.    loading a Quick library, try reducing the size of the library.
  20425.  
  20426.    This error may occur when you attempt to use QuickBASIC on unsupported
  20427.    hardware. (QB invocation error)
  20428.  
  20429.  Error in loading file (filename)──Cannot find file
  20430.  
  20431.    This error occurs when redirecting input to QuickBASIC from a file. The
  20432.    input file is not at the location specified on the command line. (QB
  20433.    invocation error)
  20434.  
  20435.  Error in loading file (filename)──Disk I/O error
  20436.  
  20437.    This error is caused by physical problems accessing the disk, for example,
  20438.    if the drive door is left open. (QB invocation error)
  20439.  
  20440.  Error in loading file (filename)──DOS memory-area error
  20441.  
  20442.    The area of memory used by DOS has been written to, either by an assembly
  20443.    language routine or with the POKE statement. (QB invocation error)
  20444.  
  20445.  Error in loading file (filename)──Invalid format
  20446.  
  20447.    You are attempting to load a Quick library that is not in the correct
  20448.    format. This error can occur if you are attempting to use a Quick library
  20449.    created with a previous version of QuickBASIC, if you are trying to use a
  20450.    file that has not been processed with QuickBASIC's Make Library command or
  20451.    the /QU option from LINK, or if you are trying to load a stand-alone
  20452.    (.LIB) library with QuickBASIC. (QB invocation error)
  20453.  
  20454.  Error in loading file (filename)──Out of memory
  20455.  
  20456.    More memory is required than is available. For example, there may not be
  20457.    enough memory to allocate a file buffer. Try reducing the size of your DOS
  20458.    buffers, getting rid of any terminate-and-stay resident programs, or
  20459.    eliminating some device drivers. If you have large arrays, try placing a
  20460.    ¢DYNAMIC metacommand at the top of your program. If you have documents
  20461.    loaded, then unloading them will free some memory. (Run-time error)
  20462.  
  20463.  EXIT DO not within DO...LOOP
  20464.  
  20465.    An EXIT DO statement is used outside of a DO...LOOP statement.
  20466.    (Compile-time error)
  20467.  
  20468.  EXIT not within FOR...NEXT
  20469.  
  20470.    An EXIT FOR statement is used outside of a FOR...NEXT statement.
  20471.    (Compile-time error)
  20472.  
  20473.  Expected: item
  20474.  
  20475.    This is a syntax error. The cursor is positioned at the unexpected item.
  20476.    (Compile-time error)
  20477.  
  20478.  Expression too complex
  20479.  
  20480.    This error is caused when certain internal limitations are exceeded. For
  20481.    example, during expression evaluation, strings that are not associated
  20482.    with variables are assigned temporary locations. A large number of such
  20483.    strings can cause this error to occur. Try simplifying expressions, and
  20484.    assigning strings to variables. (Compile-time error)
  20485.  
  20486.  Extra file name ignored
  20487.  
  20488.    You specified too many files on the command line; the last file name on
  20489.    the line is ignored. (BC invocation error)
  20490.  
  20491.  Far heap corrupt
  20492.  
  20493.    The far-heap memory has been corrupted by one of the following:
  20494.  
  20495.    ■ The QB compiler does not support a terminate-and-stay-resident program
  20496.      resident in DOS.
  20497.  
  20498.    ■ The POKE statement modified areas of memory used by QuickBASIC. (This
  20499.      may modify the descriptor for a dynamic array of numbers or fixed-length
  20500.      strings.)
  20501.  
  20502.    ■ The program called an other-language routine that modified areas of
  20503.      memory used by QuickBASIC. (This may modify the descriptor for a dynamic
  20504.      array of numbers or fixed-length strings.
  20505.  
  20506.    (Compile-time error)
  20507.  
  20508.  FIELD overflow
  20509.  
  20510.    A FIELD statement is attempting to allocate more bytes than were specified
  20511.    for the record length of a random file. (Run-time error)
  20512.  
  20513.    ERR code: 50
  20514.  
  20515.  FIELD statement active
  20516.  
  20517.    A GET or PUT statement referred to a record variable used in a a file with
  20518.    space previously allocated by the FIELD statement. GET or PUT with a
  20519.    record variable argument may only be used on files where no FIELD
  20520.    statements have been executed. (Run-time error)
  20521.  
  20522.    ERR code: 56
  20523.  
  20524.  File already exists
  20525.  
  20526.    The file name specified in a NAME statement is identical to a file name
  20527.    already in use on the disk. (Run-time error)
  20528.  
  20529.    ERR code: 58
  20530.  
  20531.  File already open
  20532.  
  20533.    A sequential-output-mode OPEN statement is issued for a file that is
  20534.    already open, or a KILL statement is given for a file that is open.
  20535.    (Run-time error)
  20536.  
  20537.    ERR code: 55
  20538.  
  20539.  File not found
  20540.  
  20541.    A FILES, KILL, NAME, OPEN or RUN statement references a file that does not
  20542.    exist. (Run-time error)
  20543.  
  20544.    ERR code: 53
  20545.  
  20546.  File not found in module module-name at address segment:offset
  20547.  
  20548.    A FILES, KILL, NAME, OPEN or RUN statement references a file that does not
  20549.    exist. This error message is equivalent to the File not found message, but
  20550.    it occurs during execution of compiled programs. The module-name is the
  20551.    name of the calling module. The address is the location of the error in
  20552.    the code. (Run-time error)
  20553.  
  20554.    ERR code: 53
  20555.  
  20556.  File previously loaded
  20557.  
  20558.    You are attempting to load a file that is already in memory. (Compile-time
  20559.    error)
  20560.  
  20561.  Fixed-length string illegal
  20562.  
  20563.    You are attempting to use a fixed-length string as a formal parameter.
  20564.  
  20565.    (Compile-time error)
  20566.  
  20567.  FOR index variable already in use
  20568.  
  20569.    This error occurs when an index variable is used more than once in nested
  20570.    FOR loops. (Compile-time error)
  20571.  
  20572.  FOR index variable illegal
  20573.  
  20574.    This error is usually caused when an incorrect variable type is used in a
  20575.    FOR-loop index. A FOR-loop index variable must be a simple numeric
  20576.    variable. (Compile-time error)
  20577.  
  20578.  FOR without NEXT
  20579.  
  20580.    Each FOR statement must have a matching NEXT statement. (Compile-time
  20581.    error)
  20582.  
  20583.  Formal parameter specification illegal
  20584.  
  20585.    There is an error in a function or subprogram parameter list.
  20586.    (Compile-time error)
  20587.  
  20588.  Formal parameters not unique
  20589.  
  20590.    A FUNCTION or SUB declaration contains duplicate parameters, as in this
  20591.    example: SUB GetName(A,B,C,A) STATIC. (Compile-time error)
  20592.  
  20593.  Function already defined
  20594.  
  20595.    This error occurs when a previously defined FUNCTION is redefined.
  20596.  
  20597.    (Compile-time error)
  20598.  
  20599.  Function name illegal
  20600.  
  20601.    A BASIC reserved word is used as a user-defined FUNCTION name.
  20602.    (Compile-time error)
  20603.  
  20604.  Function not defined
  20605.  
  20606.    You must declare or define a FUNCTION before using it. (Compile-time
  20607.    error)
  20608.  
  20609.  GOSUB missing
  20610.  
  20611.    The GOSUB is missing from an ON event statement. (Compile-time error)
  20612.  
  20613.  GOTO missing
  20614.  
  20615.    The GOTO is missing from an ON ERROR statement. (Compile-time error)
  20616.  
  20617.  GOTO or GOSUB expected
  20618.  
  20619.    QuickBASIC expects a GOTO or GOSUB statement. (Compile-time error)
  20620.  
  20621.  Help not found
  20622.  
  20623.    Help was requested but not found, and the program contains errors
  20624.    prohibiting QuickBASIC from building a variable table. Press F5 to view
  20625.    the line that caused the error.
  20626.  
  20627.  Identifier cannot end with %, &, !, #, or $
  20628.  
  20629.    The above suffixes are not allowed in type identifiers, subprogram names,
  20630.    or names appearing in COMMON statements. (Compile-time error)
  20631.  
  20632.  Identifier cannot include period
  20633.  
  20634.    User-defined type identifier and record element names cannot contain
  20635.    periods. The period should only be used as a record variable separator. In
  20636.    addition, a variable name cannot contain a period if the part of the name
  20637.    before the period has been used in an identifier AS usertype clause
  20638.    anywhere in the program. If you have programs that use the period in
  20639.    variable names, it is recommended that you change them to use mixed case
  20640.    instead. For example, variable ALPHA.BETA would become AlphaBeta.
  20641.    (Compile-time error)
  20642.  
  20643.  Identifier expected
  20644.  
  20645.    You are attempting to use a number or a BASIC reserved word where an
  20646.    identifier is expected. (Compile-time error)
  20647.  
  20648.  Identifier too long
  20649.  
  20650.    Identifiers must not be longer than 40 characters. (Compile-time error)
  20651.  
  20652.  Illegal function call
  20653.  
  20654.    A parameter that is out of range is passed to a math or string function. A
  20655.    function-call error can also occur for the following reasons:
  20656.  
  20657.    ■ A negative or unreasonably large subscript is used.
  20658.  
  20659.    ■ A negative number is raised to a power that is not an integer.
  20660.  
  20661.    ■ A negative record number is given when using GET file or PUT file.
  20662.  
  20663.    ■ An improper or out-of-range argument is given to a function.
  20664.  
  20665.    ■ A BLOAD or BSAVE operation is directed to a nondisk device.
  20666.  
  20667.    ■ An I/O function or statement (LOC or LOF, for example) is performed on a
  20668.      device that does not support it.
  20669.  
  20670.    ■ Strings are concatenated to create a string greater than 32,767
  20671.      characters in length.
  20672.  
  20673.    (Run-time error)
  20674.  
  20675.    ERR code: 5
  20676.  
  20677.  Illegal in direct mode
  20678.  
  20679.    The statement is valid only within a program and cannot be used in the
  20680.    Immediate window. (Compile-time error)
  20681.  
  20682.  Illegal in procedure or DEF FN
  20683.  
  20684.    The statement is not allowed inside a procedure. (Compile-time error)
  20685.  
  20686.  Illegal number
  20687.  
  20688.    The format of the number does not correspond to a valid number format. You
  20689.    have probably made a typographical error. For example, the number 2p3 will
  20690.    produce this error. (Compile-time error)
  20691.  
  20692.  Illegal outside of SUB, FUNCTION, or DEF FN
  20693.  
  20694.    This statement is not allowed in module-level code. (Compile-time error)
  20695.  
  20696.  Illegal outside of SUB/FUNCTION
  20697.  
  20698.    The statement is not allowed in module-level code or DEF FN functions.
  20699.    (Compile-time error)
  20700.  
  20701.  Illegal outside of TYPE block
  20702.  
  20703.    The element AS type clause is permitted only within a TYPE...END TYPE
  20704.    block. (Compile-time error)
  20705.  
  20706.  Illegal type character in numeric constant
  20707.  
  20708.    A numeric constant contains an inappropriate type-declaration character.
  20709.  
  20710.    (Compile-time error)
  20711.  
  20712.  ¢INCLUDE-file access error
  20713.  
  20714.    The include file named in the ¢INCLUDE metacommand cannot be located.
  20715.    (Compile-time error)
  20716.  
  20717.  Include file too large
  20718.  
  20719.    Your include file exceeds QuickBASIC's internal limit. Break the file into
  20720.    separate files. (Compile-time error)
  20721.  
  20722.  Input file not found
  20723.  
  20724.    The source file you gave on the command line is not in the specified
  20725.    location. (BC invocation error)
  20726.  
  20727.  INPUT missing
  20728.  
  20729.    The compiler expects the keyword INPUT. (Compile-time error)
  20730.  
  20731.  Input past end of file
  20732.  
  20733.    An INPUT statement reads from a null (empty) file or from a file in which
  20734.    all data have already been read. To avoid this error, use the EOF function
  20735.    to detect the end of file. (Run-time error)
  20736.  
  20737.    ERR code: 62
  20738.  
  20739.  Input runtime module path:
  20740.  
  20741.    This prompt appears if the run-time module BRUN45.EXE is not found. Enter
  20742.    the correct path specification. This error is severe and cannot be
  20743.    trapped. (Run-time error)
  20744.  
  20745.  Integer between 1 and 32767 required
  20746.  
  20747.    The statement requires an integer argument. (Compile-time error)
  20748.  
  20749.  Internal error
  20750.  
  20751.    An internal malfunction occurred in QuickBASIC. Use the Product Assistance
  20752.    Request form included with your documentation to report to Microsoft the
  20753.    conditions under which the message appeared. (Run-time error)
  20754.  
  20755.    ERR code: 51
  20756.  
  20757.  Internal error near xxxx
  20758.  
  20759.    An internal malfunction occurred in QuickBASIC at location xxxx. Use the
  20760.    Product Assistance Request form included with your documentation to report
  20761.    the conditions under which the message appeared. (Compile-time error)
  20762.  
  20763.  Invalid character
  20764.  
  20765.    QuickBASIC found an invalid character, such as a control character, in the
  20766.    source file. (Compile-time error)
  20767.  
  20768.  Invalid constant
  20769.  
  20770.    An invalid expression is used to assign a value to a constant. Remember
  20771.    that expressions assigned to constants may contain numeric constants,
  20772.    symbolic constants, and any of the arithmetic or logical operators except
  20773.    exponentiation. A string expression assigned to a constant may consist
  20774.    only of a single literal string. (Compile-time error)
  20775.  
  20776.  Invalid DECLARE for BASIC procedure
  20777.  
  20778.    You are attempting to use the DECLARE statement keywords ALIAS, CDECL, or
  20779.    BYVAL with a BASIC procedure. ALIAS, CDECL, and BYVAL can only be used
  20780.    with non-BASIC procedures. (Compile-time error)
  20781.  
  20782.  Label not defined
  20783.  
  20784.    A line label is referenced (in a GOTO statement, for example), but does
  20785.    not occur in the program. (Compile-time error)
  20786.  
  20787.  Label not defined: label
  20788.  
  20789.    A GOTO linelabel statement refers to a nonexistent line label.
  20790.    (Compile-time error)
  20791.  
  20792.  Left parenthesis missing
  20793.  
  20794.    QuickBASIC expected a left parenthesis, or a REDIM statement tried to
  20795.    reallocate space for a scalar. (Compile-time error)
  20796.  
  20797.  Line invalid. Start again
  20798.  
  20799.    An invalid file-name character was used following the path characters "\"
  20800.    (backslash) or ":" (colon). (BC invocation error)
  20801.  
  20802.  Line number or label missing
  20803.  
  20804.    A line number or label is missing from a statement that requires one, for
  20805.    example, GOTO. (Compile-time error)
  20806.  
  20807.  Line too long
  20808.  
  20809.    Lines are limited to 255 characters. (Compile-time error)
  20810.  
  20811.  LOOP without DO
  20812.  
  20813.    The DO starting a DO...LOOP statement is missing or misspelled.
  20814.    (Compile-time error)
  20815.  
  20816.  Lower bound exceeds upper bound
  20817.  
  20818.    The lower bound exceeds the upper bound defined in a DIM statement.
  20819.  
  20820.    (Compile-time error)
  20821.  
  20822.  Math overflow
  20823.  
  20824.    The result of a calculation is too large to be represented in BASIC number
  20825.    format. (Compile-time error)
  20826.  
  20827.  ¢Metacommand error
  20828.  
  20829.    A metacommand is incorrect. If you are compiling the program with BC this
  20830.    error is not "fatal"; the program will execute, although the results may
  20831.    be incorrect. (Compile-time warning)
  20832.  
  20833.  Minus sign missing
  20834.  
  20835.    QuickBASIC expects a minus sign. (Compile-time error)
  20836.  
  20837.  Missing Event Trapping (/W) or Checking Between Statements (/V) option
  20838.  
  20839.    The program contains an ON event statement requiring one of these options.
  20840.    (Compile-time error)
  20841.  
  20842.  Missing On Error (/E) option
  20843.  
  20844.    When using the BC command, programs containing ON ERROR statements must be
  20845.    compiled with the On Error (/E) option. (Compile-time error)
  20846.  
  20847.  Missing Resume Next (/X) option
  20848.  
  20849.    When using the BC command, programs containing RESUME, RESUME NEXT, and
  20850.    RESUME 0 statements must be compiled with the Resume Next (/X) option.
  20851.    (Compile-time error)
  20852.  
  20853.  Module level code too large
  20854.  
  20855.    Your module-level code exceeds QuickBASIC's internal limit. Try moving
  20856.    some of the code into SUB or FUNCTION procedures. (Compile-time error)
  20857.  
  20858.  Module not found. Unload module from program?
  20859.  
  20860.    When loading the program, QuickBASIC did not find the file containing the
  20861.    indicated module. QuickBASIC created an empty module instead. You must
  20862.    delete the empty module before you can run the program.
  20863.  
  20864.  Must be first statement on the line
  20865.  
  20866.    In block IF...THEN...ELSE constructs, IF, ELSE, ELSEIF, and END IF can be
  20867.    preceded only by a line number or label. (Compile-time error)
  20868.  
  20869.  Name of subprogram illegal
  20870.  
  20871.    The error is caused when a subprogram name is a BASIC reserved word, or a
  20872.    subprogram name is used twice. (Compile-time error)
  20873.  
  20874.  Nested function definition
  20875.  
  20876.    A FUNCTION definition appears inside another FUNCTION definition, or
  20877.    inside an IF...THEN...ELSE clause. (Compile-time error)
  20878.  
  20879.  NEXT missing for variable
  20880.  
  20881.    A FOR statement is missing a corresponding NEXT statement. The variable is
  20882.    the FOR-loop index variable. (Compile-time error)
  20883.  
  20884.  NEXT without FOR
  20885.  
  20886.    Each NEXT statement must have a matching FOR statement. (Compile-time
  20887.    error)
  20888.  
  20889.  No line number in module-name at address segment:offset
  20890.  
  20891.    This error occurs when the error address cannot be found in the
  20892.    line-number table during error trapping. This happens if there are no
  20893.    integer line numbers between 0 and 65,527. It may also occur if the
  20894.    line-number table has been accidentally overwritten by the user program.
  20895.    This error is severe and cannot be trapped. (Run-time error)
  20896.  
  20897.  No main module. Choose Set Main Module from the Run menu to select one
  20898.  
  20899.    You are attempting to run the program after you have unloaded the main
  20900.    module. Every program must have a main module. (Compile-time error)
  20901.  
  20902.  No RESUME
  20903.  
  20904.    The end of the program was encountered while the program was in an
  20905.    error-handling routine. A RESUME statement is needed to remedy this
  20906.    situation. (Run-time error)
  20907.  
  20908.    ERR code: 19
  20909.  
  20910.  Not watchable
  20911.  
  20912.    This error occurs when you are specifying a variable in a watch
  20913.    expression. Make sure the module or procedure in the active View window
  20914.    has access to the variable you want to watch. For example, module-level
  20915.    code cannot access variables that are local to a SUB or FUNCTION.
  20916.    (Run-time error)
  20917.  
  20918.  Numeric array illegal
  20919.  
  20920.    Numeric arrays are not allowed as arguments to VARPTR$. Only simple
  20921.    variables and string array elements are permitted. (Compile-time error)
  20922.  
  20923.  Only simple variables allowed
  20924.  
  20925.    User-defined types and arrays are not permitted in READ and INPUT
  20926.    statements. Array elements that are not of a user-defined type are
  20927.    permitted. (Compile-time error)
  20928.  
  20929.  Operation requires disk
  20930.  
  20931.    You are attempting to load from, or save to, a nondisk device such as the
  20932.    printer or keyboard. (Compile-time error)
  20933.  
  20934.  Option unknown: option
  20935.  
  20936.    You have given an illegal option. (BC invocation error)
  20937.  
  20938.  Out of DATA
  20939.  
  20940.    A READ statement is executed when there are no DATA statements with unread
  20941.    data remaining in the program. (Run-time error)
  20942.  
  20943.    ERR code: 4
  20944.  
  20945.  Out of data space
  20946.  
  20947.    Try modifying your data space requirements as follows:
  20948.  
  20949.    ■ Use a smaller file buffer in the OPEN statement's LEN clause.
  20950.  
  20951.    ■ Use the ¢DYNAMIC metacommand to create dynamic arrays. Dynamic array
  20952.      data can usually be much larger than static array data.
  20953.  
  20954.    ■ Use fixed-length string arrays instead of variable-length string arrays.
  20955.  
  20956.    ■ Use the smallest data type that will accomplish your task. Use integers
  20957.      whenever possible.
  20958.  
  20959.    ■ Try not to use many small procedures. QuickBASIC must create several
  20960.      bytes of control information for each procedure.
  20961.  
  20962.    ■ Use CLEAR to modify the size of the stack. Use only enough stack space
  20963.      to accomplish your task.
  20964.  
  20965.    ■ Do not use source lines longer than 255 characters. Such lines require
  20966.      allocation of additional text buffer space.
  20967.  
  20968.    (Compile-time or run-time error)
  20969.  
  20970.  Out of memory
  20971.  
  20972.    More memory is required than is available. For example, there may not be
  20973.    enough memory to allocate a file buffer. Try reducing the size of your DOS
  20974.    buffers, or getting rid of any terminate-and-stay-resident programs, or
  20975.    eliminating some device drivers. If you have large arrays, try placing a
  20976.    ¢DYNAMIC metacommand at the top of your program. If you have documents
  20977.    loaded, unloading them will free some memory. (BC invocation,
  20978.    compile-time, or run-time error)
  20979.  
  20980.    ERR code: 7
  20981.  
  20982.  Out of paper
  20983.  
  20984.    The printer is out of paper or is not turned on. (Run-time error)
  20985.  
  20986.    ERR code: 27
  20987.  
  20988.  Out of stack space
  20989.  
  20990.    This error can occur when a recursive FUNCTION procedure nests too deeply,
  20991.    or there are too many active subroutine, FUNCTION, and SUB calls. You can
  20992.    use the CLEAR statement to increase the program's allotted stack space.
  20993.    This error cannot be trapped. (Run-time error)
  20994.  
  20995.  Out of string space
  20996.  
  20997.    String variables exceed the allocated amount of string space. (Run-time
  20998.    error)
  20999.  
  21000.    ERR code: 14
  21001.  
  21002.  Overflow
  21003.  
  21004.    The result of a calculation is too large to be represented within the
  21005.    range allowed for either floating-point or integer numbers. (Run-time
  21006.    error)
  21007.  
  21008.    ERR code: 6
  21009.  
  21010.  Overflow in numeric constant
  21011.  
  21012.    The numeric constant is too large. (Compile-time error)
  21013.  
  21014.  Parameter type mismatch
  21015.  
  21016.    A subprogram or FUNCTION parameter type does not match the DECLARE
  21017.    statement argument or the calling argument. (Compile-time error)
  21018.  
  21019.  Path not found
  21020.  
  21021.    During an OPEN, MKDIR, CHDIR, or RMDIR operation, DOS was unable to find
  21022.    the path specified. The operation is not completed. (Run-time error)
  21023.  
  21024.    ERR code: 76
  21025.  
  21026.  Path/File access error
  21027.  
  21028.    During an OPEN, MKDIR, CHDIR, or RMDIR operation, DOS was unable to make a
  21029.    correct connection between the path and file name. The operation is not
  21030.    completed. (Compile-time or run-time error)
  21031.  
  21032.    ERR code: 75
  21033.  
  21034.  Permission denied
  21035.  
  21036.    An attempt was made to write to a write-protected disk, or to access a
  21037.    locked file. (Run-time error)
  21038.  
  21039.    ERR code: 70
  21040.  
  21041.  Procedure already defined in Quick library
  21042.  
  21043.    A procedure in the Quick library has the same name as a procedure in your
  21044.    program. (Compile-time error)
  21045.  
  21046.  Procedure too large
  21047.  
  21048.    The procedure has exceeded QuickBASIC's internal limit. Make the procedure
  21049.    smaller by dividing it into several procedures. (Compile-time error)
  21050.  
  21051.  Program-memory overflow
  21052.  
  21053.    You are attempting to compile a program whose code segment is larger than
  21054.    64K. Try splitting the program into separate modules, or use the CHAIN
  21055.    statement. (Compile-time error)
  21056.  
  21057.  Read error on standard input
  21058.  
  21059.    A system error occurred while reading from the console or a redirected
  21060.    input file. (BC invocation error)
  21061.  
  21062.  Record/string assignment required
  21063.  
  21064.    The string or record variable assignment is missing from the LSET
  21065.    statement. (Compile-time error)
  21066.  
  21067.  Redo from start
  21068.  
  21069.    You have responded to an INPUT prompt with the wrong number or type of
  21070.    items. Retype your response in the correct form. (Run-time error)
  21071.  
  21072.  Rename across disks
  21073.  
  21074.    An attempt was made to rename a file with a new drive designation. This is
  21075.    not allowed. (Run-time prompt)
  21076.  
  21077.    ERR code: 74
  21078.  
  21079.  Requires DOS 2.10 or later
  21080.  
  21081.    You are attempting to use QuickBASIC with an incorrect version of DOS. (QB
  21082.    invocation or run-time error)
  21083.  
  21084.  RESUME without error
  21085.  
  21086.    A RESUME statement is encountered before an error-trapping routine is
  21087.    entered. (Run-time error)
  21088.  
  21089.    ERR code: 20
  21090.  
  21091.  RETURN without GOSUB
  21092.  
  21093.    A RETURN statement is encountered for which there is no previous,
  21094.    unmatched GOSUB statement. (Run-time error)
  21095.  
  21096.    ERR code: 3
  21097.  
  21098.  Right parenthesis missing
  21099.  
  21100.    QuickBASIC expects a right (closing) parenthesis. (Compile-time error)
  21101.  
  21102.  SEG or BYVAL not allowed in CALLS
  21103.  
  21104.    BYVAL and SEG are permitted only in a CALL statement. (Compile-time error)
  21105.  
  21106.  SELECT without END SELECT
  21107.  
  21108.    The end of a SELECT CASE statement is missing or misspelled. (Compile-time
  21109.    error)
  21110.  
  21111.  Semicolon missing
  21112.  
  21113.    QuickBASIC expects a semicolon. (Compile-time error)
  21114.  
  21115.  Separator illegal
  21116.  
  21117.    There is an illegal delimiting character in a PRINT USING or WRITE
  21118.    statement. Use a semicolon or a comma as a delimiter. (Compile-time error)
  21119.  
  21120.  Simple or array variable expected
  21121.  
  21122.    The compiler expects a variable argument. (Compile-time error)
  21123.  
  21124.  Skipping forward to END TYPE statement
  21125.  
  21126.    An error in the TYPE statement has caused QuickBASIC to ignore everything
  21127.    between the TYPE and END TYPE statement. (Compile-time error)
  21128.  
  21129.  Statement cannot occur within $INCLUDE file
  21130.  
  21131.    SUB...END SUB and FUNCTION...END FUNCTION statement blocks are not
  21132.    permitted in include files. Use the Merge command from the File menu to
  21133.    insert the include file into the current module, or load the include file
  21134.    as a separate module. If you load the include file as a separate module,
  21135.    some restructuring may be necessary because shared variables are shared
  21136.    only within the scope of the module. (Compile-time error)
  21137.  
  21138.  Statement cannot precede SUB/FUNCTION definition
  21139.  
  21140.    The only statements allowed before a procedure definition are the
  21141.    statements REM and DEFtype. (Compile-time error)
  21142.  
  21143.  Statement ignored
  21144.  
  21145.    You are using the BC command to compile a program that contains TRON and
  21146.    TROFF statements without using the /D option. This error is not "fatal" ;
  21147.    the program will execute, although the results may be incorrect.
  21148.    (Compile-time warning)
  21149.  
  21150.  Statement illegal in TYPE block
  21151.  
  21152.    The only statements allowed between the TYPE and END TYPE statements are
  21153.    REM and element AS typename. (Compile-time error)
  21154.  
  21155.  Statement unrecognizable
  21156.  
  21157.    You have probably mistyped a BASIC statement. (Compile-time error)
  21158.  
  21159.  Statements/labels illegal between SELECT CASE and CASE
  21160.  
  21161.    Statements and line labels are not permitted between SELECT CASE and the
  21162.    first CASE statement. Comments and statement separators are permitted.
  21163.    (Compile-time error)
  21164.  
  21165.  STOP in module name at address segment:offset
  21166.  
  21167.    A STOP statement was encountered in the program. (Run-time error)
  21168.  
  21169.  String assignment required
  21170.  
  21171.    The string assignment is missing from an RSET statement. (Compile-time
  21172.    error)
  21173.  
  21174.  String constant required for ALIAS
  21175.  
  21176.    The DECLARE statement ALIAS keyword requires a string-constant argument.
  21177.    (Compile-time error)
  21178.  
  21179.  String expression required
  21180.  
  21181.    The statement requires a string-expression argument. (Compile-time error)
  21182.  
  21183.  String formula too complex
  21184.  
  21185.    Either a string formula is too long or an INPUT statement requests more
  21186.    than 15 string variables. Break the formula or INPUT statement into parts
  21187.    for correct execution. (Run-time error)
  21188.  
  21189.    ERR code: 16
  21190.  
  21191.  String space corrupt
  21192.  
  21193.    This error occurs when an invalid string in string space is being deleted
  21194.    during heap compaction. The probable causes of this error are as follows:
  21195.  
  21196.    ■ A string descriptor or string back pointer has been improperly modified.
  21197.      This may occur if you use an assembly-language subroutine to modify
  21198.      strings.
  21199.  
  21200.    ■ Out-of-range array subscripts are used and string space is inadvertently
  21201.      modified. The Produce Debug Code option can be used at compile time to
  21202.      check for array subscripts that exceed the array bounds.
  21203.  
  21204.    ■ Incorrect use of the POKE and/or DEF SEG statements may modify string
  21205.      space improperly.
  21206.  
  21207.    ■ Mismatched COMMON declarations may occur between two chained programs.
  21208.  
  21209.    (Run-time error)
  21210.  
  21211.  String variable required
  21212.  
  21213.    The statement requires a string-variable argument. (Compile-time error)
  21214.  
  21215.  SUB or FUNCTION missing
  21216.  
  21217.    A DECLARE statement has no corresponding procedure. (Compile-time error)
  21218.  
  21219.  SUB/FUNCTION without END SUB/FUNCTION
  21220.  
  21221.    The terminating statement is missing from a procedure. (Compile-time
  21222.    error)
  21223.  
  21224.  Subprogram error
  21225.  
  21226.    This is a SUB or FUNCTION definition error and is usually caused by one of
  21227.    the following:
  21228.  
  21229.    ■ The SUB or FUNCTION is already defined.
  21230.  
  21231.    ■ The program contains incorrectly nested FUNCTION or SUB statements.
  21232.  
  21233.    ■ The SUB or FUNCTION does not terminate with an END SUB or END FUNCTION
  21234.      statement.
  21235.  
  21236.    (Compile-time error)
  21237.  
  21238.  Subprogram not defined
  21239.  
  21240.    A subprogram is called but never defined. (Compile-time error)
  21241.  
  21242.  Subprograms not allowed in control statements
  21243.  
  21244.    Subprogram FUNCTION definitions are not permitted inside control
  21245.    constructs such as IF...THEN...ELSE and SELECT CASE. (Compile-time error)
  21246.  
  21247.  Subscript out of range
  21248.  
  21249.    An array element was referenced with a subscript that was outside the
  21250.    dimensions of the array, or an element of an undimensioned dynamic array
  21251.    was accessed. This message may be generated if the Debug (/D) option was
  21252.    specified at compile time. You may also get this error if the array size
  21253.    exceeds 64K, the array is not dynamic, and the /AH option was not used.
  21254.    Reduce the size of the array, or make the array dynamic and use the /AH
  21255.    command-line option. (Run-time error)
  21256.  
  21257.    ERR code: 9
  21258.  
  21259.  Subscript syntax illegal
  21260.  
  21261.    An array subscript contains a syntax error: for example, an array
  21262.    subscript contains both string and integer data types. (Compile-time
  21263.    error)
  21264.  
  21265.  Syntax error
  21266.  
  21267.    Several conditions can cause this error. The most common cause at compile
  21268.    time is a mistyped BASIC keyword or argument. At run-time, it is often
  21269.    caused by an improperly formatted DATA statement. (Compile-time or
  21270.    run-time error)
  21271.  
  21272.    ERR code: 2
  21273.  
  21274.  Syntax error in numeric constant
  21275.  
  21276.    A numeric constant is not properly formed. (Compile-time error)
  21277.  
  21278.  THEN missing
  21279.  
  21280.    QuickBASIC expects a THEN keyword. (Compile-time error)
  21281.  
  21282.  TO missing
  21283.  
  21284.    QuickBASIC expects a TO keyword. (Compile-time error)
  21285.  
  21286.  Too many arguments in function call
  21287.  
  21288.    Function calls are limited to 60 arguments. (Compile-time error)
  21289.  
  21290.  Too many dimensions
  21291.  
  21292.    Arrays are limited to 60 dimensions. (Compile-time error)
  21293.  
  21294.  Too many files
  21295.  
  21296.    At compile time, this error occurs when include files are nested more than
  21297.    five levels deep. It occurs at run time when the 255-file directory
  21298.    maximum is exceeded by an attempt to create a new file with a SAVE or OPEN
  21299.    statement. (Compile-time or run-time error)
  21300.  
  21301.    ERR code: 67
  21302.  
  21303.  Too many labels
  21304.  
  21305.    The number of lines in the line list following an ON...GOTO or ON...GOSUB
  21306.    statement exceeds 255 (Compile-time error) or 59 (Run-time error in
  21307.    compiled applications).
  21308.  
  21309.  Too many named COMMON blocks
  21310.  
  21311.    The maximum number of named COMMON blocks permitted is 126. (Compile-time
  21312.    error)
  21313.  
  21314.  Too many TYPE definitions
  21315.  
  21316.    The maximum number of user-defined types permitted is 240. (Compile-time
  21317.    error)
  21318.  
  21319.  Too many variables for INPUT
  21320.  
  21321.    An INPUT statement is limited to 60 variables. (Compile-time error)
  21322.  
  21323.  Too many variables for LINE INPUT
  21324.  
  21325.    Only one variable is allowed in a LINE INPUT statement. (Compile-time
  21326.    error)
  21327.  
  21328.  Type mismatch
  21329.  
  21330.    The variable is not of the required type. For example, you are trying to
  21331.    use the SWAP statement with a string variable and a numeric variable.
  21332.    (Compile-time or run-time error)
  21333.  
  21334.    ERR code: 13
  21335.  
  21336.  TYPE missing
  21337.  
  21338.    The TYPE keyword is missing from an END TYPE statement. (Compile-time
  21339.    error)
  21340.  
  21341.  Type more than 65535 bytes
  21342.  
  21343.    A user-defined type cannot exceed 64K. (Compile-time error)
  21344.  
  21345.  Type not defined
  21346.  
  21347.    The usertype argument to the TYPE statement is not defined. (Compile-time
  21348.    error)
  21349.  
  21350.  TYPE statement improperly nested
  21351.  
  21352.    User-defined type definitions are not allowed in procedures. (Compile-time
  21353.    error)
  21354.  
  21355.  TYPE without END TYPE
  21356.  
  21357.    There is no END TYPE statement associated with a TYPE statement.
  21358.    (Compile-time error)
  21359.  
  21360.  Typed variable not allowed in expression
  21361.  
  21362.    Variables that are user-defined types are not permitted in expressions
  21363.    such as CALL ALPHA((X)), where X is a user-defined type. (Compile-time
  21364.    error)
  21365.  
  21366.  Unexpected end of file in TYPE declaration
  21367.  
  21368.    There is an end-of-file character inside a TYPE...END TYPE block.
  21369.  
  21370.  Unprintable error
  21371.  
  21372.    An error message is not available for the error condition that exists.
  21373.    This may be caused by an ERROR statement that doesn't have a defined error
  21374.    code. (Run-time error)
  21375.  
  21376.  Unrecognized switch error: "QU"
  21377.  
  21378.    You are attempting to create an .EXE file or Quick library with an
  21379.    incorrect version of the Microsoft Overlay Linker. You must use the linker
  21380.    supplied on the QuickBASIC distribution disks to create an .EXE file or
  21381.    Quick library. (Compile-time error)
  21382.  
  21383.  Valid options: [/RUN] file /AH /B /C:buf /G /NOHI /H /L [lib] /MBF /CMD
  21384.  string
  21385.  
  21386.    This message appears when you invoke QuickBASIC with an invalid option.
  21387.    (QB invocation error)
  21388.  
  21389.  Variable-length string required
  21390.  
  21391.    Only variable-length strings are permitted in a FIELD statement.
  21392.    (Compile-time error)
  21393.  
  21394.  Variable name not unique
  21395.  
  21396.    You are attempting to define the variable x as a user-defined type after
  21397.    x.y has been used. (Compile-time error)
  21398.  
  21399.  Variable required
  21400.  
  21401.    QuickBASIC encountered an INPUT, LET, READ, or SHARED statement without a
  21402.    variable argument. (Compile-time error)
  21403.  
  21404.  Variable required
  21405.  
  21406.    A GET or PUT statement didn't specify a variable when an operation is
  21407.    performed on a file opened in BINARY mode. (Run-time error)
  21408.  
  21409.    ERR code: 40
  21410.  
  21411.  WEND without WHILE
  21412.  
  21413.    This error is caused when a WEND statement has no corresponding WHILE
  21414.    statement. (Compile-time error)
  21415.  
  21416.  WHILE without WEND
  21417.  
  21418.    This error is caused when a WHILE statement has no corresponding WEND
  21419.    statement. (Compile-time error)
  21420.  
  21421.  Wrong number of dimensions
  21422.  
  21423.    An array reference contains the wrong number of dimensions. (Compile-time
  21424.    error)
  21425.  
  21426.  
  21427.  B.3  LINK Error Messages
  21428.  
  21429.    This section lists and describes error messages generated by the Microsoft
  21430.    Overlay Linker, LINK.
  21431.  
  21432.    Fatal errors cause the linker to stop execution. Fatal error messages have
  21433.    the following format:
  21434.  
  21435.    location : fatal error L1xxx:messagetext
  21436.  
  21437.    Nonfatal errors indicate problems in the executable file. LINK produces
  21438.    the executable file. Nonfatal error messages have the following format:
  21439.  
  21440.    location : error L2xxx: messagetext
  21441.  
  21442.    Warnings indicate possible problems in the executable file. LINK produces
  21443.    the executable file. Warnings have the following format:
  21444.  
  21445.    location : warning L4xxx: messagetext
  21446.  
  21447.    In these messages, location is the input file associated with the error,
  21448.    or LINK if there is no input file.
  21449.  
  21450.    The following error messages may appear when you link object files with
  21451.    LINK:
  21452.  
  21453. ╓┌─┌───────────┌─────────────────────────────────────────────────────────────╖
  21454.    Number      LINK Error Message
  21455.    ──────────────────────────────────────────────────────────────────────────
  21456.    L1001       option : option name ambiguous A unique option name did not
  21457.                appear after the option indicator (/). For example, the
  21458.                command LINK /N main;
  21459.  
  21460.                generates this error, since LINK cannot tell which of the
  21461.                three options beginning with the letter "N" was intended.
  21462.  
  21463.    L1002       option : unrecognized option name
  21464.    Number      LINK Error Message
  21465.    ──────────────────────────────────────────────────────────────────────────
  21466.   L1002       option : unrecognized option name
  21467.  
  21468.                An unrecognized character followed the option indicator (/),
  21469.                as in the following example: LINK /ABCDEF main;
  21470.  
  21471.    L1003       /QUICKLIB, /EXEPACK incompatible
  21472.  
  21473.                You specified two options that cannot be used together:
  21474.                /QUICKLIB and /EXEPACK.
  21475.  
  21476.    L1004       option : invalid numeric value
  21477.  
  21478.                An incorrect value appeared for one of the LINK options. For
  21479.                example, a character string was given for an option that
  21480.                requires a numeric value.
  21481.  
  21482.    L1006       option : stack size exceeds 65535 bytes
  21483.  
  21484.                The value given as a parameter to the /STACKSIZE option
  21485.    Number      LINK Error Message
  21486.    ──────────────────────────────────────────────────────────────────────────
  21487.               The value given as a parameter to the /STACKSIZE option
  21488.                exceeds the maximum allowed.
  21489.  
  21490.    L1007       option : interrupt number exceeds 255
  21491.  
  21492.                For the /OVERLAYINTERRUPT option, a number greater than 255
  21493.                was given as a value.
  21494.  
  21495.    L1008       option : segment limit set too high
  21496.  
  21497.                The limit on the number of segments allowed was set to greater
  21498.                than 3072 using the /SEGMENTS option.
  21499.  
  21500.    L1009       number : CPARMAXALLOC : illegal value
  21501.  
  21502.                The number specified in the /CPARMAXALLOC option was not in
  21503.                the range 1-65,535.
  21504.  
  21505.    L1020       no object modules specified
  21506.    Number      LINK Error Message
  21507.    ──────────────────────────────────────────────────────────────────────────
  21508.   L1020       no object modules specified
  21509.  
  21510.                No object-file names were specified to LINK.
  21511.  
  21512.    L1021       cannot nest response files
  21513.  
  21514.                A response file occurred within a response file.
  21515.  
  21516.    L1022       response line too long
  21517.  
  21518.                A line in a response file was longer than 127 characters.
  21519.  
  21520.    L1023       terminated by user
  21521.  
  21522.                You entered CTRL+C or CRTL+BREAK.
  21523.  
  21524.    L1024       nested right parentheses
  21525.  
  21526.                The contents of an overlay were typed incorrectly on the
  21527.    Number      LINK Error Message
  21528.    ──────────────────────────────────────────────────────────────────────────
  21529.               The contents of an overlay were typed incorrectly on the
  21530.                command line.
  21531.  
  21532.    L1025       nested left parentheses
  21533.  
  21534.                The contents of an overlay were typed incorrectly on the
  21535.                command line.
  21536.  
  21537.    L1026       unmatched right parenthesis
  21538.  
  21539.                A right parenthesis was missing from the contents
  21540.                specification of an overlay on the command line.
  21541.  
  21542.    L1027       unmatched left parenthesis
  21543.  
  21544.                A left parenthesis was missing from the contents specification
  21545.                of an overlay on the command line.
  21546.  
  21547.    L1043       relocation table overflow
  21548.    Number      LINK Error Message
  21549.    ──────────────────────────────────────────────────────────────────────────
  21550.   L1043       relocation table overflow
  21551.  
  21552.                More than 32,768 long calls, long jumps, or other long
  21553.                pointers appeared in the program. Try replacing long
  21554.                references with short references, where possible, and recreate
  21555.                the object module.
  21556.  
  21557.    L1045       too many TYPDEF records
  21558.  
  21559.                An object module contained more than 255 TYPDEF records. These
  21560.                records describe communal variables. This error can appear
  21561.                only with programs produced by the Microsoft FORTRAN Compiler
  21562.                or other compilers that support communal variables. (TYPDEF is
  21563.                a DOS term. It is explained in the Microsoft MS-DOS
  21564.                Programmer's Reference and in other reference books on DOS.)
  21565.  
  21566.    L1046       too many external symbols in one module
  21567.  
  21568.                An object module specified more than the limit of 1023
  21569.    Number      LINK Error Message
  21570.    ──────────────────────────────────────────────────────────────────────────
  21571.               An object module specified more than the limit of 1023
  21572.                external symbols. Break the module into smaller parts.
  21573.  
  21574.    L1047       too many group, segment, and class names in one module
  21575.  
  21576.                The program contained too many group, segment, and class
  21577.                names. Reduce the number of groups, segments, or classes, and
  21578.                recreate the object file.
  21579.  
  21580.    L1048       too many segments in one module
  21581.  
  21582.                An object module had more than 255 segments. Split the module
  21583.                or combine segments.
  21584.  
  21585.    L1049       too many segments
  21586.  
  21587.                The program had more than the maximum number of segments. Use
  21588.                the /SEGMENTS option, which has a default value of 128, to
  21589.                specify the maximum legal number of segments. The default is
  21590.    Number      LINK Error Message
  21591.    ──────────────────────────────────────────────────────────────────────────
  21592.               specify the maximum legal number of segments. The default is
  21593.                128 in the /SEGMENTS option, which specifies the maximum legal
  21594.                number. Relink using the /SEGMENTS option with an appropriate
  21595.                number of segments.
  21596.  
  21597.    L1050       too many groups in one module
  21598.  
  21599.                LINK encountered over 21 group definitions (GRPDEF) in a
  21600.                single module. Reduce the number of group definitions or split
  21601.                the module. (Group definitions are explained in the Microsoft
  21602.                MS-DOS Programmer's Reference and in other reference books on
  21603.                DOS.)
  21604.  
  21605.    L1051       too many groups
  21606.  
  21607.                The program defined more than 20 groups, not counting DGROUP.
  21608.                Reduce the number of groups.
  21609.  
  21610.    L1052       too many libraries
  21611.    Number      LINK Error Message
  21612.    ──────────────────────────────────────────────────────────────────────────
  21613.   L1052       too many libraries
  21614.  
  21615.                An attempt was made to link with more than 32 libraries.
  21616.                Combine libraries, or use modules that require fewer
  21617.                libraries.
  21618.  
  21619.    L1053       out of memory for symbol table
  21620.  
  21621.                There is no fixed limit to the size of the symbol table.
  21622.                However, it is limited by the amount of available memory.
  21623.                Combine modules or segments and recreate the object files.
  21624.                Eliminate as many public symbols as possible.
  21625.  
  21626.    L1054       requested segment limit too high
  21627.  
  21628.                LINK did not have enough memory to allocate tables describing
  21629.                the number of segments requested. (The default is 128 or the
  21630.                value specified with the /SEGMENTS option.) Try linking again
  21631.                using the /SEGMENTS option to select a smaller number of
  21632.    Number      LINK Error Message
  21633.    ──────────────────────────────────────────────────────────────────────────
  21634.               using the /SEGMENTS option to select a smaller number of
  21635.                segments (for example, use 64 if the default was used
  21636.                previously), or free some memory by eliminating resident
  21637.                programs or shells.
  21638.  
  21639.    L1056       too many overlays
  21640.  
  21641.                The program defined more than 63 overlays.
  21642.  
  21643.    L1057       data record too large
  21644.  
  21645.                A LEDATA record (in an object module) contained more than 1024
  21646.                bytes of data. This is a translator error. (LEDATA is a DOS
  21647.                term, which is explained in the Microsoft MS-DOS Programmer's
  21648.                Reference and in other DOS reference books.) Note which
  21649.                translator (compiler or assembler) produced the incorrect
  21650.                object module and the circumstances. Please report this error
  21651.                to Microsoft Corporation using the Product Assistance Request
  21652.                form included with the documentation.
  21653.    Number      LINK Error Message
  21654.    ──────────────────────────────────────────────────────────────────────────
  21655.               form included with the documentation.
  21656.  
  21657.    L1063       out of memory for CodeView information
  21658.  
  21659.                Too many linked object (".OBJ") files contain debugging
  21660.                information. Turn off the Produce Debug Code option in the
  21661.                Make EXE file dialog box.
  21662.  
  21663.    L1070       segment size exceeds 64K
  21664.  
  21665.                A single segment contained more than 64K of code or data. Try
  21666.                compiling and linking using the large model.
  21667.  
  21668.    L1071       segment _TEXT larger than 65520 bytes
  21669.  
  21670.                This error is likely to occur only in small-model C programs,
  21671.                but it can occur when any program with a segment named _TEXT
  21672.                is linked using the /DOSSEG option. Small-model C programs
  21673.                must reserve code addresses 0 and 1; this range is increased
  21674.    Number      LINK Error Message
  21675.    ──────────────────────────────────────────────────────────────────────────
  21676.               must reserve code addresses 0 and 1; this range is increased
  21677.                to 16 for alignment purposes.
  21678.  
  21679.    L1072       common area longer than 65536 bytes
  21680.  
  21681.                The program had more than 64K of communal variables. This
  21682.                error occurs only with programs produced by compilers that
  21683.                support communal variables.
  21684.  
  21685.    L1080       cannot open list file
  21686.  
  21687.                The disk or the root directory was full. Delete or move files
  21688.                to make space.
  21689.  
  21690.    L1081       out of space for run file
  21691.  
  21692.                The disk on which the executable file was being written was
  21693.                full. Free more space on the disk and restart LINK.
  21694.  
  21695.    Number      LINK Error Message
  21696.    ──────────────────────────────────────────────────────────────────────────
  21697. 
  21698.    L1083       cannot open run file
  21699.  
  21700.                The disk or the root directory was full. Delete or move files
  21701.                to make space.
  21702.  
  21703.    L1084       cannot create temporary file
  21704.  
  21705.                The disk or root directory was full. Free more space in the
  21706.                directory and restart LINK.
  21707.  
  21708.    L1085       cannot open temporary file
  21709.  
  21710.                The disk or the root directory was full. Delete or move files
  21711.                to make space.
  21712.  
  21713.    L1086       scratch file missing
  21714.  
  21715.                An internal error has occurred. Note the circumstances of the
  21716.    Number      LINK Error Message
  21717.    ──────────────────────────────────────────────────────────────────────────
  21718.               An internal error has occurred. Note the circumstances of the
  21719.                problem and contact Microsoft Corporation using the Product
  21720.                Assistance Request form included with the documentation.
  21721.  
  21722.    L1087       unexpected end-of-file on scratch file
  21723.  
  21724.                The disk with the temporary output file from LINK was removed.
  21725.  
  21726.    L1088       out of space for list file
  21727.  
  21728.                The disk where the listing file is being written is full. Free
  21729.                more space on the disk and restart LINK.
  21730.  
  21731.    L1089       filename : cannot open response file LINK could not find the
  21732.                specified response file. This usually indicates a typing
  21733.                error.
  21734.  
  21735.    L1090       cannot reopen list file
  21736.  
  21737.    Number      LINK Error Message
  21738.    ──────────────────────────────────────────────────────────────────────────
  21739. 
  21740.                The original disk was not replaced at the prompt. Restart
  21741.                LINK.
  21742.  
  21743.    L1091       unexpected end-of-file on library
  21744.  
  21745.                The disk containing the library probably was removed. Replace
  21746.                the disk containing the library and run LINK again.
  21747.  
  21748.    L1093       object not found
  21749.  
  21750.                One of the object files specified in the input to LINK was not
  21751.                found. Restart LINK and specify the object file.
  21752.  
  21753.    L1101       invalid object module
  21754.  
  21755.                One of the object modules was invalid. If the error persists
  21756.                after recompiling, please contact Microsoft Corporation using
  21757.                the Product Assistance Request form included with the
  21758.    Number      LINK Error Message
  21759.    ──────────────────────────────────────────────────────────────────────────
  21760.               the Product Assistance Request form included with the
  21761.                documentation.
  21762.  
  21763.    L1102       unexpected end-of-file
  21764.  
  21765.                An invalid format for a library was encountered.
  21766.  
  21767.    L1103       attempt to access data outside segment bounds
  21768.  
  21769.                A data record in an object module specified data extending
  21770.                beyond the end of a segment. This is a translator error. Note
  21771.                which translator (compiler or assembler) produced the
  21772.                incorrect object module and the circumstances in which it was
  21773.                produced. Please report this error to Microsoft Corporation
  21774.                using the Product Assistance Request form included with the
  21775.                documentation.
  21776.  
  21777.    L1104       filename : not valid library
  21778.  
  21779.    Number      LINK Error Message
  21780.    ──────────────────────────────────────────────────────────────────────────
  21781. 
  21782.                The specified file was not a valid library file. This error
  21783.                causes LINK to abort.
  21784.  
  21785.    L1113       unresolved COMDEF; internal error
  21786.  
  21787.                Note the circumstances of the failure and contact Microsoft
  21788.                Corporation using the Product Assistance Request form included
  21789.                with the documentation.
  21790.  
  21791.    L1114       file not suitable for /EXEPACK; relink without
  21792.  
  21793.                For the linked program, the size of the packed load image plus
  21794.                packing overhead was larger than that of the unpacked load
  21795.                image. Relink without the /EXEPACK option.
  21796.  
  21797.    L1115       /QUICKLIB, overlays incompatible
  21798.  
  21799.                You specified overlays and used the /QUICKLIB option. These
  21800.    Number      LINK Error Message
  21801.    ──────────────────────────────────────────────────────────────────────────
  21802.               You specified overlays and used the /QUICKLIB option. These
  21803.                cannot be used together.
  21804.  
  21805.    L2001       fixup(s) without data
  21806.  
  21807.                A FIXUPP record occurred without a data record immediately
  21808.                preceding it. This is probably a compiler error. (See the
  21809.                Microsoft MS-DOS Programmer's Reference for more information
  21810.                on FIXUPP.)
  21811.  
  21812.    L2002       fixup overflow near number in frame seg segname target seg
  21813.                segname target offset number The following conditions can
  21814.                cause this error:
  21815.  
  21816.                ■ A group is larger than 64K.
  21817.  
  21818.                ■ The program contains an intersegment short jump or
  21819.                intersegment short call.
  21820.  
  21821.    Number      LINK Error Message
  21822.    ──────────────────────────────────────────────────────────────────────────
  21823. 
  21824.                ■ The name of a data item in the program conflicts with the
  21825.                name of a library subroutine included in the link.
  21826.  
  21827.                ■ An EXTRN declaration in an assembly-language source file
  21828.                appeared inside the body of a segment, as in the following
  21829.                example:
  21830.  
  21831.                code   SEGMENT public 'CODE'
  21832.                       EXTRN   main:far
  21833.                start  PROC    far
  21834.                       call    main
  21835.                       ret
  21836.                start  ENDP
  21837.                code   ENDS
  21838.  
  21839.                The following construction is preferred:
  21840.  
  21841.                EXTRN   main:far
  21842.    Number      LINK Error Message
  21843.    ──────────────────────────────────────────────────────────────────────────
  21844.               EXTRN   main:far
  21845.                code   SEGMENT public 'CODE'
  21846.                start  PROC    far
  21847.                       call    main
  21848.                       ret
  21849.                start  ENDP
  21850.                code   ENDS
  21851.  
  21852.                Revise the source file and recreate the object file. (See the
  21853.                Microsoft MS-DOS Programmer's Reference for information about
  21854.                frame and target segments.
  21855.  
  21856.    L2003       intersegment self-relative fixup at offset in segment segname
  21857.  
  21858.                You tried to make a near call or jump to a far entry in
  21859.                segment segname at offset. Change the call or jump to far or
  21860.                make the entry near.
  21861.  
  21862.    L2004       LOBYTE-type fixup overflow
  21863.    Number      LINK Error Message
  21864.    ──────────────────────────────────────────────────────────────────────────
  21865.   L2004       LOBYTE-type fixup overflow
  21866.  
  21867.                A LOBYTE fixup generated an address overflow. (See the
  21868.                Microsoft MS-DOS Programmer's Reference for more information.)
  21869.  
  21870.    L2005       fixup type unsupported
  21871.  
  21872.                A fixup type occurred that is not supported by the Microsoft
  21873.                linker. This is probably a compiler error. Note the
  21874.                circumstances of the failure and contact Microsoft Corporation
  21875.                using the Product Assistance Request form included with the
  21876.                documentation.
  21877.  
  21878.    L2011       name : NEAR/HUGE conflict
  21879.  
  21880.                Conflicting NEAR and HUGE attributes were given for a communal
  21881.                variable. This error can occur only with programs produced by
  21882.                compilers that support communal variables.
  21883.  
  21884.    Number      LINK Error Message
  21885.    ──────────────────────────────────────────────────────────────────────────
  21886. 
  21887.    L2012       name : array-element size mismatch
  21888.  
  21889.                A far communal array was declared with two or more different
  21890.                array-element sizes (for instance, an array was declared once
  21891.                as an array of characters and once as an array of real
  21892.                numbers). This error occurs only with compilers that support
  21893.                far communal arrays.
  21894.  
  21895.    L2013       LIDATA record too large
  21896.  
  21897.                A LIDATA record contains more than 512 bytes. This error is
  21898.                usually caused by a compiler error.
  21899.  
  21900.    L2024       name : symbol already defined
  21901.  
  21902.                LINK has found a public-symbol redefinition. Remove extra
  21903.                definition(s).
  21904.  
  21905.    Number      LINK Error Message
  21906.    ──────────────────────────────────────────────────────────────────────────
  21907. 
  21908.    L2025       name : symbol defined more than once
  21909.  
  21910.                Remove the extra symbol definition from the object file.
  21911.  
  21912.    L2029       unresolved externals One or more symbols were declared to be
  21913.                external in one or more modules, but they were not publicly
  21914.                defined in any of the modules or libraries. A list of the
  21915.                unresolved external references appears after the message, as
  21916.                shown in the following example: unresolved externals
  21917.                EXIT in file(s):
  21918.                 MAIN.OBJ (main.for)
  21919.                OPEN in file(s):
  21920.                 MAIN.OBJ (main.for)
  21921.  
  21922.                The name that comes before in file(s) is the unresolved
  21923.                external symbol. On the next line is a list of object modules
  21924.                that have made references to this symbol. This message and the
  21925.                list are also written to the map file, if one exists.
  21926.    Number      LINK Error Message
  21927.    ──────────────────────────────────────────────────────────────────────────
  21928.               list are also written to the map file, if one exists.
  21929.  
  21930.    L2041       stack plus data exceed 64K
  21931.  
  21932.                The total size of near data and the stack exceeds 64K. Reduce
  21933.                the stack size to control the error. LINK tests for this
  21934.                condition only if the /DOSSEG option is enabled. This option
  21935.                is automatically enabled by the library startup module.
  21936.  
  21937.    L2043       Quick library support module missing
  21938.  
  21939.                You did not specify, or LINK could not find, the object module
  21940.                or library required for creating a Quick library. In the case
  21941.                of QuickBASIC, the library provided is BQLB45.LIB.
  21942.  
  21943.    L2044       name : symbol multiply defined, use /NOE
  21944.  
  21945.                LINK has found a possible public-symbol redefinition. This
  21946.                error is often caused by redefining a symbol defined in a
  21947.    Number      LINK Error Message
  21948.    ──────────────────────────────────────────────────────────────────────────
  21949.               error is often caused by redefining a symbol defined in a
  21950.                library. Relink using the /NOEXTDICTIONARY option. This error
  21951.                in combination with error L2025 for the same symbol indicates
  21952.                a real redefinition error.
  21953.  
  21954.    L4011       PACKCODE value exceeding 65500 unreliable
  21955.  
  21956.                Packcode segment sizes that exceed 65,500 bytes may be
  21957.                unreliable on the Intel(R) 80286 processor.
  21958.  
  21959.    L4012       load-high disables EXEPACK
  21960.  
  21961.                The /HIGH and /EXEPACK options cannot be used at the same
  21962.                time.
  21963.  
  21964.    L4015       /CODEVIEW disables /DSALLOCATE
  21965.  
  21966.                The /CODEVIEW and /DSALLOCATE options cannot be used at the
  21967.                same time.
  21968.    Number      LINK Error Message
  21969.    ──────────────────────────────────────────────────────────────────────────
  21970.               same time.
  21971.  
  21972.    L4016       /CODEVIEW disables /EXEPACK
  21973.  
  21974.                The /CODEVIEW and /EXEPACK options cannot be used at the same
  21975.                time.
  21976.  
  21977.    L4020       name : code-segment size exceeds 65500
  21978.  
  21979.                Code segments of 65,501-65,536 bytes in length may be
  21980.                unreliable on the Intel 80286 processor.
  21981.  
  21982.    L4021       no stack segment
  21983.  
  21984.                The program did not contain a stack segment defined with STACK
  21985.                combine type. This message should not appear for modules
  21986.                compiled with Microsoft QuickBASIC, but it could appear for an
  21987.                assembly-language module. Normally, every program should have
  21988.                a stack segment with the combine type specified as STACK. You
  21989.    Number      LINK Error Message
  21990.    ──────────────────────────────────────────────────────────────────────────
  21991.               a stack segment with the combine type specified as STACK. You
  21992.                can ignore this message if you have a specific reason for not
  21993.                defining a stack or for defining one without the STACK combine
  21994.                type. Linking with versions of LINK earlier than Version 2.40
  21995.                might cause this message, since these linkers search libraries
  21996.                only once.
  21997.  
  21998.    L4031       name : segment declared in more than one group
  21999.  
  22000.                A segment was declared to be a member of two different groups.
  22001.                Correct the source file and recreate the object files.
  22002.  
  22003.    L4034       more than 239 overlay segments; extra put in root
  22004.  
  22005.                The program designates more than 239 segments to go in
  22006.                overlays. When this error occurs, segments beginning with
  22007.                number 234 are placed in the root, the permanently resident
  22008.                portion.
  22009.  
  22010.    Number      LINK Error Message
  22011.    ──────────────────────────────────────────────────────────────────────────
  22012. 
  22013.    L4045       name of output file is name
  22014.  
  22015.                The prompt for the run-file field gave an inaccurate default
  22016.                because the /QUICKLIB option was not used early enough. The
  22017.                output will be a Quick library with the name given in the
  22018.                error message.
  22019.  
  22020.    L4050       too many public symbols for sorting
  22021.  
  22022.                The number of public symbols exceeds the space available for
  22023.                sorting the symbols as requested by the /MAP option. The
  22024.                symbols are left unsorted.
  22025.  
  22026.    L4051       filename : cannot find library
  22027.  
  22028.                LINK could not find the specified file. Enter a new file name,
  22029.                a new path specification, or both.
  22030.  
  22031.    Number      LINK Error Message
  22032.    ──────────────────────────────────────────────────────────────────────────
  22033. 
  22034.    L4053       VM.TMP : illegal file name; ignored VM.TMP appeared as an
  22035.                object-file name. Rename the file and rerun LINK.
  22036.  
  22037.    L4054       filename : cannot find file
  22038.  
  22039.                LINK could not find the specified file. Enter a new file name,
  22040.                a new path specification, or both.
  22041.  
  22042.    ──────────────────────────────────────────────────────────────────────────
  22043.  
  22044.  
  22045.  
  22046.  B.4  LIB Error Messages
  22047.  
  22048.    Error messages generated by the Microsoft Library Manager, LIB, have one
  22049.    of the following formats: {filename | LIB} : fatal error U1xxx:
  22050.    messagetext {filename | LIB} : error U2xxx: messagetext {filename | LIB} :
  22051.    warning U4xxx: messagetext
  22052.  
  22053.    The message begins with the input-file name (filename), if one exists, or
  22054.    with the name of the utility. If possible, LIB prints a warning and
  22055.    continues operation. In some cases errors are fatal, and LIB terminates
  22056.    processing.
  22057.  
  22058.    LIB may display the following error messages:
  22059.  
  22060.  
  22061.    Number      LIB Error Message<
  22062.    ──────────────────────────────────────────────────────────────────────────
  22063.    U1150       page size too small
  22064.  
  22065.                The page size of an input library was too small, which
  22066.                indicates an invalid input .LIB file.
  22067.  
  22068.    U1151       syntax error : illegal file specification
  22069.  
  22070.                A command operator such as a minus sign (-) was given without
  22071.                a following module name.
  22072.  
  22073.    U1152       syntax error : option name missing
  22074.  
  22075.                A forward slash (/) was given without an option after it.
  22076.  
  22077.    U1153       syntax error : option value missing
  22078.  
  22079.                The /PAGESIZE option was given without a value following it.
  22080.  
  22081.    U1154       option unknown
  22082.  
  22083.                An unknown option was given. Currently, LIB recognizes only
  22084.                the /PAGESIZE option.
  22085.  
  22086.    U1155       syntax error : illegal input
  22087.  
  22088.                The given command did not follow correct LIB syntax as
  22089.                specified in Appendix G, "Compiling and Linking from DOS."
  22090.  
  22091.    U1156       syntax error
  22092.  
  22093.                The given command did not follow correct LIB syntax as
  22094.                specified in Appendix G, "Compiling and Linking from DOS."
  22095.  
  22096.    U1157       comma or new line missing
  22097.  
  22098.                A comma or carriage return was expected in the command line
  22099.                but did not appear. This may indicate an inappropriately
  22100.                placed comma, as in the line that follows:
  22101.                LIB math.lib,-mod1+mod2;
  22102.  
  22103.                The line should have been entered as follows:
  22104.                LIB math.lib -mod1+mod2;
  22105.  
  22106.    U1158       terminator missing
  22107.  
  22108.                Either the response to the "Output library" prompt or the last
  22109.                line of the response file used to start LIB did not end with a
  22110.                carriage return.
  22111.  
  22112.    U1161       cannot rename old library
  22113.  
  22114.                LIB could not rename the old library to have a .BAK extension
  22115.                because the .BAK version already existed with read-only
  22116.                protection. Change the protection on the old .BAK version.
  22117.  
  22118.    U1162       cannot reopen library
  22119.  
  22120.                The old library could not be reopened after it was renamed to
  22121.                have a .BAK extension.
  22122.  
  22123.    U1163       error writing to cross-reference file
  22124.  
  22125.                The disk or root directory was full. Delete or move files to
  22126.                make space.
  22127.  
  22128.    U1170       too many symbols
  22129.  
  22130.                More than 4609 symbols appeared in the library file.
  22131.  
  22132.    U1171       insufficient memory
  22133.  
  22134.                LIB did not have enough memory to run. Remove any shells or
  22135.                resident programs and try again, or add more memory.
  22136.  
  22137.    U1172       no more virtual memory
  22138.  
  22139.                Note the circumstances of the failure and notify Microsoft
  22140.                Corporation using the Product Assistance Request form included
  22141.                with the documentation.
  22142.  
  22143.    U1173       internal failure
  22144.  
  22145.                Note the circumstances of the failure and notify Microsoft
  22146.                Corporation using the Product Assistance Request form included
  22147.                with the documentation.
  22148.  
  22149.    U1174       mark: not allocated
  22150.  
  22151.                Note the circumstances of the failure and notify Microsoft
  22152.                Corporation using the Product Assistance Request form included
  22153.                with the documentation.
  22154.  
  22155.    U1175       free: not allocated
  22156.  
  22157.                Note the circumstances of the failure and notify Microsoft
  22158.                Corporation using the Product Assistance Request form included
  22159.                with the documentation.
  22160.  
  22161.    U1180       write to extract file failed
  22162.  
  22163.                The disk or root directory was full. Delete or move files to
  22164.                make space.
  22165.  
  22166.    U1181       write to library file failed
  22167.  
  22168.                The disk or root directory was full. Delete or move files to
  22169.                make space.
  22170.  
  22171.    U1182       filename : cannot create extract file
  22172.  
  22173.                The disk or root directory was full, or the specified extract
  22174.                file already existed with read-only protection. Make space on
  22175.                the disk or change the protection of the extract file.
  22176.  
  22177.    U1183       cannot open response file
  22178.  
  22179.                The response file was not found.
  22180.  
  22181.    U1184       unexpected end-of-file on command input
  22182.  
  22183.                An end-of-file character was received prematurely in response
  22184.                to a prompt.
  22185.  
  22186.    U1185       cannot create new library
  22187.  
  22188.                The disk or root directory was full, or the library file
  22189.                already existed with read-only protection. Make space on the
  22190.                disk or change the protection of the library file.
  22191.  
  22192.    U1186       error writing to new library
  22193.  
  22194.                The disk or root directory was full. Delete or move files to
  22195.                make space.
  22196.  
  22197.    U1187       cannot open VM.TMP
  22198.  
  22199.                The disk or root directory was full. Delete or move files to
  22200.                make space.
  22201.  
  22202.    U1188       cannot write to VM
  22203.  
  22204.                Note the circumstances of the failure and notify Microsoft
  22205.                Corporation using the Product Assistance Request form.
  22206.  
  22207.    U1189       cannot read from VM
  22208.  
  22209.                Note the circumstances of the failure and notify Microsoft
  22210.                Corporation using the Product Assistance Request form.
  22211.  
  22212.    U1190       interrupted by user
  22213.  
  22214.                The user pressed CTRL+C or CTRL+BREAK.
  22215.  
  22216.    U1200       name : invalid library header
  22217.  
  22218.                The input library file had an invalid format. It was either
  22219.                not a library file, or it had been corrupted.
  22220.  
  22221.    U1203       name : invalid object module near location
  22222.  
  22223.                The module specified by name was not a valid object module.
  22224.  
  22225.    U2152       filename : cannot create listing
  22226.  
  22227.                The directory or disk was full, or the cross-reference-listing
  22228.                file already existed with read-only protection. Either make
  22229.                space on the disk or change the protection of the
  22230.                cross-reference-listing file.
  22231.  
  22232.    U2155       modulename : module not in library; ignored
  22233.  
  22234.                The specified module was not found in the input library.
  22235.  
  22236.    U2157       filename : cannot access file
  22237.  
  22238.                LIB was unable to open the specified file.
  22239.  
  22240.    U2158       libraryname : invalid library header; file ignored
  22241.  
  22242.                The input library had an incorrect format.
  22243.  
  22244.    U2159       filename : invalid format hexnumber; file ignored
  22245.  
  22246.                The signature byte or word hexnumber of the given file was not
  22247.                one of the following recognized types: Microsoft library,
  22248.                Intel library, Microsoft object, or XENIX(R) archive.
  22249.  
  22250.    U4150       modulename : module redefinition ignored
  22251.  
  22252.                A module was specified to be added to a library but a module
  22253.                with the same name was already in the library. Or, a module
  22254.                with the same name was found more than once in the library.
  22255.  
  22256.    U4151       symbol : symbol redefined in module modulename, redefinition
  22257.                ignored
  22258.  
  22259.                The specified symbol was defined in more than one module.
  22260.  
  22261.    U4153       number : page size too small; ignored
  22262.  
  22263.                The value specified in the /PAGESIZE option was less than 16.
  22264.  
  22265.    U4155       modulename : module not in library
  22266.  
  22267.                A module to be replaced is not in the library. LIB adds the
  22268.                module to the library.
  22269.  
  22270.    U4156       libraryname : output-library specification ignored
  22271.  
  22272.                An output library was specified in addition to a new library
  22273.                name. For example, specifying
  22274.                LIB new.lib+one.obj,new.lst,new.lib
  22275.  
  22276.                where new.lib does not already exist causes this error.
  22277.  
  22278.    U4157       Insufficient memory, extended dictionary not created.
  22279.  
  22280.                LIB was unable to create the extended dictionary. The library
  22281.                is still valid, but LINK cannot take advantage of extended
  22282.                dictionaries to link faster.
  22283.  
  22284.    U4158       Internal error, extended dictionary not created.
  22285.  
  22286.                LIB was unable to create the extended dictionary. The library
  22287.                is still valid, but LINK cannot take advantage of extended
  22288.                dictionaries to link faster.
  22289.  
  22290.  
  22291.  
  22292.  
  22293.  ────────────────────────────────────────────────────────────────────────────
  22294.  Index
  22295.  
  22296.  
  22297.  Symbols
  22298.  
  22299.  ' (apostrophe)
  22300.    entering
  22301.  + (concatenation operator)
  22302.  
  22303.  A
  22304.  
  22305.  ABS function
  22306.  ALIAS, use in DECLARE statement
  22307.  Alphanumeric line labelsLine labels
  22308.  Angle measurement
  22309.    degrees to radians, converting from
  22310.    radians to degrees, converting from
  22311.  Animation
  22312.  Apostrophe (')
  22313.    entering
  22314.  Arctangent, ATN function
  22315.  Argument passing
  22316.  Arithmetic operators
  22317.  Arithmetic overflow
  22318.  Arrays
  22319.    dimensioning
  22320.    dynamic
  22321.      ERASE statement
  22322.      REDIM statement
  22323.    elements
  22324.    INT86OLD statements
  22325.    LBOUND function
  22326.    location in memory
  22327.    of records
  22328.    static, ERASE statement
  22329.    subscripts, specifying
  22330.      changing lower bound for
  22331.      described
  22332.      maximum value for
  22333.      number of
  22334.    UBOUND function
  22335.    variables
  22336.  AS clause
  22337.  ASC function
  22338.  ASCII character codes
  22339.    special character
  22340.    string expression
  22341.    (table)
  22342.  Assembly language subroutines
  22343.    calling
  22344.    name, PUBLIC symbol
  22345.    string descriptor length
  22346.  Assignment statements
  22347.  ATN function
  22348.  AT&T displays
  22349.  Automatic variables
  22350.  
  22351.  B
  22352.  
  22353.  Background music
  22354.  .BAS files
  22355.  BASIC
  22356.    error codes
  22357.    run-time errors
  22358.  BASICA, differences from
  22359.    BLOAD statement
  22360.    BSAVE statement
  22361.    CALL ABSOLUTE statement
  22362.    CALL statement
  22363.    CLEAR statement
  22364.    COM statement
  22365.    DEF SEG statement
  22366.    DEF type statements
  22367.    DIM statement
  22368.    DRAW statement
  22369.    ERL function
  22370.    FIELD statement
  22371.    RESUME statement
  22372.    STRIG function
  22373.    SYSTEM statement
  22374.    TAN function
  22375.    VARPTR$ function
  22376.  basica, Differences From
  22377.    Chain Statement
  22378.    For...Next Statement
  22379.  BEEP statement
  22380.  Binary mode
  22381.    functions
  22382.      FILEATTR
  22383.      LOC
  22384.    statements
  22385.      GET (File I/O)
  22386.      LOCK
  22387.      OPEN
  22388.      PUT (File I/O)
  22389.      SEEK
  22390.  BLOAD statement
  22391.  Block IF...THEN...ELSE statement
  22392.  Bold text, indicating keywords
  22393.  Boolean operations
  22394.  BSAVE statement
  22395.  Built-in functions
  22396.  BYVAL, use in DECLARE statement
  22397.  
  22398.  C
  22399.  
  22400.  CALL ABSOLUTE statement
  22401.  CALL INT86OLD statement
  22402.  CALL INT86XOLD statement
  22403.  CALL INTERRUPT statement
  22404.  CALL INTERRUPTX statement
  22405.  CALL statement (BASIC procedures)
  22406.  CALL statement (non-BASIC procedures)
  22407.    described
  22408.    location of arguments
  22409.  Calling conventions
  22410.  CALLS statement
  22411.    described
  22412.    location of arguments
  22413.  Cardioid
  22414.  Carriage return
  22415.  CASE clause
  22416.  Case, line labels
  22417.  CDBL function
  22418.  CDECL, use in DECLARE statement
  22419.  CGA adapter
  22420.  CHAIN statement
  22421.  Chaining programs, statements for
  22422.    CHAIN
  22423.    COMMON
  22424.    RUN
  22425.  Chainingprograms, statements for
  22426.    COMMON
  22427.  Characters recognized by BASIC
  22428.  CHDIR statement
  22429.  CHR$ function
  22430.  CINT function
  22431.  CIRCLE statement
  22432.  CLEAR statement
  22433.  CLNG function
  22434.  CLOSE statement
  22435.  CLS statement
  22436.  /CMD option
  22437.  Color Graphics AdapterCGA adapter
  22438.  COLOR statement
  22439.  COM devices
  22440.  COM statements
  22441.  COMMAND$ function
  22442.  COMMAND.COM
  22443.  Commandline, passing to BASIC program
  22444.  Comments
  22445.    introducing
  22446.    REM statement
  22447.  COMMON statement
  22448.    blank
  22449.    chaining programs
  22450.    declaring variables
  22451.    named
  22452.    order of variables
  22453.    SHARED attribute
  22454.  Compile-time error messages
  22455.  Concatenation operator(+)
  22456.  CONST statement
  22457.  Constants
  22458.    global
  22459.    local
  22460.    scope rules
  22461.    symbolic
  22462.  Control-flow statements
  22463.    CALL
  22464.    CALL ABSOLUTE
  22465.    CALLS
  22466.    CHAIN
  22467.    DEF FN
  22468.    DO...LOOP
  22469.    FOR...NEXT
  22470.    FUNCTION
  22471.    GOSUB...RETURN
  22472.    GOTO
  22473.    IF...THEN...ELSE
  22474.    ON GOSUB
  22475.    ON GOTO
  22476.    RETURN
  22477.    SELECT CASE
  22478.    WHILE...WEND
  22479.  COS function
  22480.  Cosine, COS function
  22481.  CSNG function
  22482.  CSRLIN function
  22483.  CVD function
  22484.  CVDMBF function
  22485.  CVI function
  22486.  CVL function
  22487.  CVS function
  22488.  CVSMBF function
  22489.  
  22490.  D
  22491.  
  22492.  DATA statement
  22493.  Data types
  22494.    double-precision floating-point numeric
  22495.    fixed-length string
  22496.    four-byte integer numeric
  22497.    integer numeric
  22498.    long-integer numeric
  22499.    single-precision floating-point numeric
  22500.    specifying
  22501.    two-byte integer numeric
  22502.    TYPE statement
  22503.    variable-length string
  22504.  Date and time
  22505.    functions
  22506.      DATE$
  22507.      TIME$
  22508.    statements
  22509.      DATE$
  22510.      TIME$
  22511.  DATE$ function
  22512.  DATE$ statement
  22513.  Debugging statements
  22514.  Declarations
  22515.    CONST statement
  22516.    DECLARE statement (BASIC procedures)
  22517.    DECLARE statement (non-BASIC procedures)
  22518.    DEF type statements
  22519.    DIM statement
  22520.    fixed-length strings
  22521.    simple variables
  22522.    variable types
  22523.  DECLARE statements
  22524.    described
  22525.    location of arguments
  22526.  DEF FN functions
  22527.    BASIC, used in
  22528.    exit from, alternative
  22529.    variable scope
  22530.  DEF FN statement
  22531.  DEF SEG statement
  22532.  DEF type statements
  22533.  Default data segments
  22534.  DEFDBL statement
  22535.  DEFINT statement
  22536.  DEFLNG statement
  22537.  DEFSNG statement
  22538.  DEFSTR statement
  22539.  Device errors
  22540.  Devices, handling
  22541.    functions
  22542.      IOCTL$
  22543.      LPOS
  22544.      PEN
  22545.    statements
  22546.      IOCTL
  22547.      OPEN COM
  22548.      OUT
  22549.      WAIT
  22550.  Device-status information
  22551.  DGROUP, defined
  22552.  DIM statement
  22553.    description
  22554.    SHARED attribute
  22555.    variable types
  22556.  Directory statements
  22557.    CHDIR
  22558.    FILES
  22559.    MKDIR
  22560.    NAME
  22561.    RMDIR
  22562.  Display memory, PCOPY statement
  22563.  Division by zero
  22564.  DO UNTIL statement
  22565.  DO WHILE statement
  22566.  Document conventions
  22567.  DO...LOOP statement
  22568.    exit from, alternative
  22569.    flow control
  22570.  DOS
  22571.    environment variables
  22572.    interrupts
  22573.  DOS-level commands
  22574.  Double precision
  22575.    numbers
  22576.      converting to
  22577.      description
  22578.      PRINT, displayed by
  22579.    variables
  22580.  DRAW statement
  22581.    description
  22582.  DRAWstatement
  22583.    VARPTR$ function, using
  22584.  ¢DYNAMIC arrays
  22585.    described
  22586.    location in memory
  22587.  Dynamic arrays
  22588.    ERASE statement
  22589.    REDIM statement
  22590.  
  22591.  E
  22592.  
  22593.  EGA adapter
  22594.    COLOR statement
  22595.    PALETTE statement
  22596.    SCREEN statement
  22597.  EGAadapter
  22598.    COLOR statement
  22599.  END CASE clause
  22600.  END DEF statement
  22601.  END FUNCTION statement
  22602.  END IF statement
  22603.  END SELECT statement
  22604.  END statement
  22605.  END SUB statement
  22606.  END TYPE statement
  22607.  Enhanced Graphics AdapterEGA adapter
  22608.  ENVIRON$ function
  22609.  ENVIRON statement
  22610.  Environment variables
  22611.  Environment-string table
  22612.  EOF function
  22613.  ERASE statement
  22614.  ERDEV function
  22615.  ERDEV$ function
  22616.  ERL function
  22617.    described
  22618.    line labels with
  22619.  ERR code
  22620.  ERR function
  22621.  Error codes
  22622.  Error handling
  22623.    error line number
  22624.    statements
  22625.      ERDEV
  22626.      ERR, ERL
  22627.      ERROR
  22628.      ON ERROR
  22629.      RESUME
  22630.  Error messages
  22631.    compile-time
  22632.    described
  22633.    invocation
  22634.    LIB
  22635.    LINK
  22636.    run-time
  22637.  ERROR statement
  22638.  Error trapping
  22639.    ERROR statement
  22640.    line 0, using
  22641.  Event-trapping statements
  22642.    COM
  22643.    KEY(n)
  22644.    ON event
  22645.    ON UEVENT
  22646.    PEN ON, OFF, and STOP
  22647.    PLAY ON, OFF, and STOP
  22648.    TIMER ON, OFF, and STOP
  22649.    UEVENT
  22650.  .EXE files
  22651.  EXIT DEF statement
  22652.  EXIT DO statement
  22653.  EXIT FOR statement
  22654.  EXIT FUNCTION statement
  22655.  EXIT statement
  22656.    description
  22657.    multiline functions, use in
  22658.    subprograms, use in
  22659.  EXIT SUB statement
  22660.  EXP function
  22661.  Expressions
  22662.    conversion of operands
  22663.    definition
  22664.  
  22665.  F
  22666.  
  22667.  Far addresses
  22668.  FIELD statement
  22669.  File access
  22670.    LOCK statement
  22671.    UNLOCK statement
  22672.  File conversion
  22673.  File handling
  22674.    functions
  22675.      EOF
  22676.      FILEATTR
  22677.      FREEFILE
  22678.      LOC
  22679.      LOF
  22680.      SEEK
  22681.    statements
  22682.      CHDIR
  22683.      CLOSE
  22684.      FIELD
  22685.      GET
  22686.      INPUT #
  22687.      KILL
  22688.      LOCK
  22689.      NAME
  22690.      OPEN
  22691.      RESET
  22692.      SEEK
  22693.      UNLOCK
  22694.  File names, described
  22695.  FILEATTR function
  22696.  Files
  22697.    attributes
  22698.    binary mode, statements and functions
  22699.      FILEATTR
  22700.      GET
  22701.      LOC
  22702.      LOCK
  22703.      OPEN
  22704.      PUT
  22705.      SEEK function
  22706.      SEEK statement
  22707.    random access, statements and functions
  22708.      EOF
  22709.      FIELD
  22710.      GETIO
  22711.      KILL
  22712.      LOC
  22713.      LOCK
  22714.      LSET
  22715.      MKI$, MKS$, MKD$, MKL$
  22716.      OPEN
  22717.      PUT
  22718.      RSET
  22719.      SEEK function
  22720.      SEEK statement
  22721.    sequential, statements and functions
  22722.      EOF
  22723.      INPUT #
  22724.      KILL
  22725.      LINE INPUT #
  22726.      LOC
  22727.      LOF
  22728.      OPEN
  22729.      PRINT #
  22730.      WRITE #
  22731.  FILES statement
  22732.  FIX function
  22733.  Fixed-point constants
  22734.  Floating point
  22735.    double precision
  22736.      constants
  22737.      range
  22738.    numbers
  22739.    single precision, range
  22740.  Formatting output
  22741.  FOR...NEXT statements
  22742.    description
  22743.    exit from, alternative
  22744.  FRE function
  22745.  FREEFILE function
  22746.  FUNCTION procedures
  22747.    DECLARE statements
  22748.    exit from, alternative
  22749.    module organization
  22750.    STATIC keyword
  22751.  FUNCTION statements
  22752.  Functional operators
  22753.  Functions
  22754.    built-in
  22755.    intrinsic
  22756.    user-defined
  22757.    variables, declaring as local
  22758.  
  22759.  G
  22760.  
  22761.  GET statements
  22762.    FIELD statement
  22763.    File I/O
  22764.    Graphics
  22765.  Global constants
  22766.  Global variables
  22767.  GOSUB statement
  22768.  GOTO statement
  22769.    description
  22770.    line labels, using
  22771.    subroutines, use with
  22772.  Graphics
  22773.    functions
  22774.      PMAP
  22775.      POINT
  22776.    macro language
  22777.    statements
  22778.      BLOAD
  22779.      BSAVE
  22780.      CIRCLE
  22781.      COLOR
  22782.      DRAW
  22783.      GET
  22784.      LINE
  22785.      PAINT
  22786.      PALETTE
  22787.      PALETTE USING
  22788.      PRESET
  22789.      PSET
  22790.      PUT
  22791.      VIEW
  22792.      WINDOW
  22793.  
  22794.  H
  22795.  
  22796.  Hercules adapters
  22797.  HEX$ function
  22798.  Hexadecimal numbers
  22799.  Hierarchy, of operators
  22800.  
  22801.  I
  22802.  
  22803.  IEEE-format numbers
  22804.  IF...THEN...ELSE statements
  22805.    description
  22806.    GOTO statement, when required
  22807.    line labels
  22808.  INKEY$ function
  22809.  INP function
  22810.  INPUT$ function
  22811.  Input functions
  22812.    COMMAND$
  22813.    INP
  22814.    INPUT$
  22815.  INPUT # statement
  22816.  INPUT statement
  22817.    description
  22818.    FIELD statement
  22819.    line editor commands
  22820.  Input statements
  22821.    DATA
  22822.    INPUT
  22823.    INPUT #
  22824.    LINE INPUT
  22825.    LINE INPUT #
  22826.    READ
  22827.    RESTORE
  22828.    WAIT
  22829.  INSTR function
  22830.  INT function
  22831.  INT86, INT86X replacements
  22832.    CALL INT86OLD statements
  22833.    CALL INTERRUPT statements
  22834.  Integers
  22835.    constants
  22836.      decimal
  22837.      hexadecimal
  22838.      octal
  22839.    converting to
  22840.    division
  22841.    FIX function
  22842.  Intrinsic functions
  22843.  Invocation error messages
  22844.  I/O ports
  22845.  IOCTL$ function
  22846.  IOCTL statement
  22847.  Italic text, showing placeholders
  22848.  
  22849.  J
  22850.  
  22851.  Joysticks
  22852.  
  22853.  K
  22854.  
  22855.  KEY OFF statement
  22856.  Keyboard scan codes
  22857.  KEY(n) statements
  22858.  KILL statement
  22859.  
  22860.  L
  22861.  
  22862.  LBOUND function
  22863.  LCASE$ function
  22864.  LEFT$ function
  22865.  LEN function
  22866.  LET statement
  22867.  LIB error messages
  22868.  Line 0, effect on error trapping
  22869.  Line feed
  22870.  LINE INPUT # statement
  22871.  LINE INPUT statement
  22872.  Line labels
  22873.    alphanumeric
  22874.    case, significance of
  22875.    GOTO statement, use with
  22876.    RESUME statement
  22877.    use of
  22878.  Line numbers
  22879.    example of
  22880.    restrictions
  22881.    RESUME statement
  22882.    use of
  22883.  Line printer
  22884.  LINE statement
  22885.  Line styling
  22886.  Line-editor commands
  22887.  LINK error messages
  22888.  LOC function
  22889.  Local constants
  22890.  Local variables
  22891.  LOCATE statement
  22892.  LOCK statement
  22893.  LOF function
  22894.  LOG function
  22895.  Logical operators
  22896.    description
  22897.    type conversion
  22898.  Long integers
  22899.    constants
  22900.    converting to
  22901.  Loops
  22902.  LPOS function
  22903.  LPRINT statement
  22904.    description
  22905.    SPC function
  22906.  LPRINT USING statement
  22907.  LSET statement
  22908.  LTRIM$ function
  22909.  
  22910.  M
  22911.  
  22912.  Main module
  22913.  Math functions
  22914.    ABS
  22915.    ATN
  22916.    COS
  22917.    CVSMBF
  22918.    EXP
  22919.    LOG
  22920.    MKSMBF$, MKDMBF$
  22921.    SIN
  22922.    SQR
  22923.    TAN
  22924.  MCGA adapter
  22925.    COLOR statement
  22926.    PALETTE statement
  22927.    SCREEN statement
  22928.  MDPA adapter, PALETTE statement
  22929.  Memory management
  22930.    functions
  22931.      FRE
  22932.      SETMEM
  22933.    statements
  22934.      CLEAR
  22935.      DEF SEG
  22936.      ERASE
  22937.      PCOPY
  22938.  Microsoft Binary format numbers
  22939.  MID$ function
  22940.  MID$ statement
  22941.  Mixed-language programming
  22942.    ALIAS, use of
  22943.    BYVAL, use of
  22944.    CALL, CALLS statement (non-BASIC)
  22945.    CDECL, use of
  22946.    DECLARE statement (non-BASIC)
  22947.    SADD function
  22948.    SEG, use of
  22949.    variable storage allocation
  22950.    VARPTR function
  22951.  MKD$ function
  22952.  MKDIR statement
  22953.  MKI$ function
  22954.  MKL$ function
  22955.  MKS$ function
  22956.  MKSMBF$ function
  22957.  MOD, module arithmetic operator
  22958.  Module-level code
  22959.  Modules
  22960.  Modulo arithmetic
  22961.  Modulus operator
  22962.  MulticolorGraphics Array adapterMCGA
  22963.  Multiline functions, run-time features, nesting
  22964.  Music
  22965.    background
  22966.    macro language
  22967.  
  22968.  N
  22969.  
  22970.  NAME statement
  22971.  Near addresses
  22972.  NEXT statement
  22973.  Notational conventions
  22974.  Numeric constants
  22975.  Numeric conversions
  22976.    CVD function
  22977.    CVI function
  22978.    CVL function
  22979.    CVS function
  22980.    double precision
  22981.    integer
  22982.    single precision
  22983.  Numeric functions
  22984.    CDBL
  22985.    CINT
  22986.    CLNG
  22987.    CSNG
  22988.    CVD
  22989.    CVI
  22990.    CVL
  22991.    CVS
  22992.    FIX
  22993.    INT
  22994.    RND
  22995.    SGN
  22996.  
  22997.  O
  22998.  
  22999.  OCT$ function
  23000.  Octal conversion
  23001.  Olivetti
  23002.    displays
  23003.    OS/2 warning
  23004.  ON COM statement
  23005.  ON ERROR statement
  23006.    description
  23007.    line 0, effect of
  23008.    line labels
  23009.  ON event statements
  23010.  ON KEY statement
  23011.  ON PEN statement
  23012.  ON PLAY statement
  23013.  ON STRIG statement
  23014.  ON TIMER statement
  23015.  ON UEVENT statement
  23016.  ON...GOSUB statement
  23017.  ON...GOTO statement
  23018.  OPEN COM statement
  23019.  OPEN statement
  23020.  Operators
  23021.    arithmetic
  23022.    concatenation
  23023.    definition
  23024.    functional
  23025.    logical
  23026.    precedence
  23027.    relational
  23028.    string
  23029.  OPTION BASE statement
  23030.  OUT statement
  23031.  Output
  23032.    functions
  23033.      LPOS
  23034.      POS
  23035.      TAB
  23036.    line width
  23037.    statements
  23038.      BEEP
  23039.      CLS
  23040.      LPRINT
  23041.      OUT
  23042.      PRINT
  23043.      PRINT #
  23044.      PRINT # USING
  23045.      PRINT USING
  23046.      PUT
  23047.      WRITE
  23048.      WRITE #
  23049.  Overflow
  23050.  
  23051.  P
  23052.  
  23053.  PAINT statement
  23054.  PALETTE statement
  23055.  PALETTE USING statement
  23056.  Passing arguments
  23057.  PCOPY statement
  23058.  PEEK function
  23059.  PEN function
  23060.  PEN OFF statement
  23061.  PEN ON statement
  23062.  PEN STOP statement
  23063.  Physical coordinates
  23064.    mapping to logical coordinates
  23065.    view
  23066.  Physicalviewport
  23067.  PLAY function
  23068.  PLAY OFF statement
  23069.  PLAY ON statement
  23070.  PLAY statement
  23071.    description
  23072.    VARPTR$ function,using
  23073.  PLAY STOP statement
  23074.  PMAP function
  23075.  POINT function
  23076.  POKE statement
  23077.  POS function
  23078.  Precedence of operators
  23079.  PRESET statement
  23080.  PRINT # statement
  23081.  PRINT statement
  23082.    description
  23083.    SPC function
  23084.  PRINT # USING statement
  23085.  PRINT USING statement
  23086.  Procedures
  23087.  Program suspension
  23088.  Program termination
  23089.  PSET statement
  23090.  PUBLIC symbol
  23091.  PUT statements
  23092.    FIELD statement
  23093.    File I/O
  23094.    Graphics
  23095.  
  23096.  R
  23097.  
  23098.  Random numbers
  23099.  Random-access files, statements and functions
  23100.    EOF
  23101.    FIELD
  23102.    GET
  23103.    KILL
  23104.    LOC
  23105.    LOCK
  23106.    MKD$, MKI$, MKL$, MKS$
  23107.    OPEN
  23108.    PUT
  23109.    SEEK function
  23110.    SEEK statement
  23111.    storing data in buffer
  23112.  RANDOMIZE statement
  23113.  READ statement
  23114.  Real numbers
  23115.  Record elements, reference
  23116.  Record variables
  23117.  Records
  23118.    arrays of
  23119.    variable length
  23120.  Recursion
  23121.  REDIM statement
  23122.    description
  23123.    SHARED attribute
  23124.    variables, declaring
  23125.  Referencing record elements
  23126.  Register values, INT86OLD, INT86XOLD
  23127.  Relational operators
  23128.  REM statement
  23129.  RESET statement
  23130.  RESTORE statement
  23131.  RESUME NEXT statement
  23132.  RESUME statement
  23133.    alphanumeric line labels
  23134.    BASICA, differences from
  23135.    description
  23136.    RESUME 0, effect of
  23137.  RETURN statement
  23138.    description
  23139.    EXIT statement, not equivalent to
  23140.    GOSUB statement
  23141.  RIGHT$ function
  23142.  RMDIR statement
  23143.  RND function
  23144.  RSET statement
  23145.  RTRIM$ function
  23146.  RUN statement
  23147.  Run-time error messages
  23148.  
  23149.  S
  23150.  
  23151.  SADD function
  23152.    described
  23153.    movement of variables
  23154.  Scan codes, keyboard
  23155.  Scope
  23156.  SCREEN 10, using
  23157.  Screen functions
  23158.    CSRLIN
  23159.    POS
  23160.    SCREEN
  23161.  Screen statements
  23162.    CLS
  23163.    COLOR
  23164.    LOCATE
  23165.    PCOPY
  23166.    SCREEN
  23167.    VIEW PRINT
  23168.  Screenstatements
  23169.    WIDTH
  23170.  SEEK
  23171.    function
  23172.    statement
  23173.  SEG, use in DECLARE statement
  23174.  SELECT CASE statement
  23175.  Sequential files, statements and functions
  23176.    EOF
  23177.    INPUT #
  23178.    KILL
  23179.    LINE INPUT #
  23180.    LOC
  23181.    LOF
  23182.    OPEN
  23183.    PRINT #
  23184.    WRITE #
  23185.  SETMEM function
  23186.    described
  23187.    movement of variables
  23188.  SetUEvent routine
  23189.  SGN function
  23190.  SHARED statement
  23191.    described
  23192.    variables
  23193.      declaring
  23194.      local
  23195.      sharing
  23196.  Shared variables
  23197.    among modules
  23198.    within a module
  23199.  Shell escape
  23200.  SHELL statement
  23201.  Simple variables
  23202.    declaring
  23203.    location in memory
  23204.  SIN function
  23205.  Sine, SIN function
  23206.  Single-precision numbers
  23207.    converting to
  23208.    PRINT, displayed by
  23209.    types of constants
  23210.  SLEEP statement
  23211.  SOUND statement
  23212.  Source files
  23213.  SPACE$ function
  23214.  SPC function
  23215.  Special characters
  23216.  Spiral of Archimedes
  23217.  SQR function
  23218.  Statements
  23219.  ¢STATIC arrays
  23220.    described
  23221.    location in memory
  23222.  Static arrays, ERASE statement
  23223.  STATIC keyword
  23224.  STATIC statement
  23225.    description
  23226.    variables
  23227.      declaring
  23228.      local
  23229.      STATIC, creating
  23230.  STICK function
  23231.  STOP statement
  23232.  Storage requirements, variables
  23233.  STR$ function
  23234.  STRIG function
  23235.  STRIG OFF statement
  23236.  STRIG ON statement
  23237.  STRIG(n) statements
  23238.  String
  23239.    concatenation
  23240.    constants
  23241.    descriptor length
  23242.    functions
  23243.      ASC
  23244.      CHR$
  23245.      DATE$
  23246.      HEX$
  23247.      INPUT$
  23248.      INSTR
  23249.      LCASE$
  23250.      LEFT$
  23251.      LEN
  23252.      LTRIM$
  23253.      MID$
  23254.      RIGHT$
  23255.      RTRIM$
  23256.      SADD
  23257.      SPACE$
  23258.      STR$
  23259.      STRING$
  23260.      UCASE$
  23261.      VAL
  23262.    operators
  23263.    processing
  23264.    statements
  23265.      LSET
  23266.      MID$
  23267.      RSET
  23268.    variables
  23269.  STRING$ function
  23270.  String-space compaction
  23271.  SUB procedures
  23272.    DECLARE statements
  23273.    exit from, alternative
  23274.    STATIC keyword
  23275.    using
  23276.  SUB statement
  23277.  Subprograms
  23278.    CALL statement
  23279.    CALLS statement
  23280.    CHAIN statement
  23281.    SUB statement
  23282.    user library, example
  23283.    variables
  23284.  Subroutines
  23285.  Subscripts, specifying
  23286.    lower bound for
  23287.    maximum value for
  23288.    number of
  23289.  SWAP statement
  23290.  Symbolic constants
  23291.    CONST
  23292.    use of
  23293.  Syntax notation
  23294.    choices
  23295.    optional items
  23296.    placeholders
  23297.  System calls
  23298.  SYSTEM statement
  23299.  
  23300.  T
  23301.  
  23302.  TAB function
  23303.  TAN function
  23304.  Tangent, TAN function
  23305.  Tiling
  23306.  TIME$ function
  23307.  TIME$ statement
  23308.  TIMER function
  23309.  TIMER OFF statement
  23310.  TIMER ON statement
  23311.  TIMER STOP statement
  23312.  Timing function
  23313.  Trigonometric functions
  23314.    ATN
  23315.    COS
  23316.    SIN
  23317.    TAN
  23318.  TROFF statement
  23319.  TRON statement
  23320.  Type conversion
  23321.    logical operators
  23322.    rules for
  23323.  TYPE statements
  23324.  Typeface
  23325.    key names
  23326.    keywords
  23327.    placeholders
  23328.    program
  23329.  Type-mismatch error message
  23330.  Typographic conventions
  23331.  
  23332.  U
  23333.  
  23334.  UBOUND function
  23335.  UCASE$ function
  23336.  UEVENT statement
  23337.  UNLOCK statement
  23338.  User-defined data types
  23339.  User-defined events
  23340.  User-defined functions
  23341.  
  23342.  V
  23343.  
  23344.  VAL function
  23345.  Variable-length records
  23346.  Variable-length strings, location in memory
  23347.  Variables
  23348.    array
  23349.    automatic
  23350.    data type
  23351.    definition
  23352.    global
  23353.      function definitions
  23354.      subprograms
  23355.      using
  23356.    local
  23357.      function definitions
  23358.      subprograms
  23359.      using
  23360.    names
  23361.      length
  23362.      rules
  23363.    record
  23364.    scope
  23365.    shared variables
  23366.    STATIC variables
  23367.    storage allocation
  23368.    storage requirements
  23369.    string
  23370.    type-declaration suffixes
  23371.  VARPTR function
  23372.    described
  23373.    movement of variables
  23374.  VARPTR$ function
  23375.    described
  23376.    movement of variables
  23377.  VARSEG function
  23378.    described
  23379.    movement of variables
  23380.  VGA adapter
  23381.    COLOR statement
  23382.    PALETTE statement
  23383.    SCREEN statement
  23384.  VGAadapter
  23385.    COLOR statement
  23386.  Video GraphicsArray adapterVGA adapter
  23387.  Video memory
  23388.  View coordinates
  23389.    mapping to physical coordinates
  23390.    WINDOW statement
  23391.  VIEW PRINT statement
  23392.  VIEW statement
  23393.  
  23394.  W
  23395.  
  23396.  WAIT statement
  23397.  WEND statement
  23398.  WHILE statement
  23399.  WIDTH statement
  23400.  WINDOW statement
  23401.  WRITE # statement
  23402.  WRITE statement
  23403.