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

  1.  Microsoft QuickBASIC: Learning to Use Microsoft QuickBASIC
  2.  
  3.  
  4.  ════════════════════════════════════════════════════════════════════════════
  5.  
  6.  
  7.  Microsoft(R) QuickBASIC: Learning to Use Microsoft QuickBASIC
  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
  21.    or nondisclosure agreement. No part of this manual may be reproduced or
  22.    transmitted in any form or by any means, electronic or mechanical,
  23.    including photocopying and recording, for any purpose without the express
  24.    written permission of Microsoft.
  25.  
  26.    (C)Copyright Microsoft Corporation, 1988. All rights reserved.
  27.  
  28.    Simultaneously published in the U.S. and Canada.
  29.  
  30.    Printed and bound in the United States of America.
  31.  
  32.    Microsoft, MS, MS-DOS, CodeView, and GW-BASIC are registered trademarks of
  33.    Microsoft Corporation.
  34.  
  35.    IBM is a registered trademark of International Business Machines
  36.    Corporation.
  37.  
  38.    Intel is a registered trademark of Intel Corporation.
  39.  
  40.    Lotus and 1-2-3 are registered trademarks of Lotus Development
  41.    Corporation.
  42.  
  43.    WordStar is a registered trademark of MicroPro International Corporation.
  44.  
  45.  
  46.  
  47.  ────────────────────────────────────────────────────────────────────────────
  48.  Contents
  49.  
  50.  Introduction
  51.             Instant Feedback
  52.             Instant Help
  53.             Hardware Requirements
  54.             The QuickBASIC Package
  55.               Printed Documentation
  56.               On-Line Documentation
  57.             Document Conventions
  58.             Requesting Assistance
  59.  
  60.  PART 1  GETTING STARTED
  61.  
  62.  Chapter 1  Setting Up Microsoft(R) QuickBASIC
  63.             The Setup Program
  64.             The Setup Main Menu
  65.             Installation
  66.             QB Express
  67.             Getting Into QuickBASIC
  68.               If You Are a Novice Programmer
  69.               If You Already Know BASIC
  70.             If You Use a Mouse
  71.  
  72.  Chapter 2  Using Menus and Commands
  73.             Starting QuickBASIC
  74.             The QuickBASIC Environment
  75.               The Menu Bar
  76.               The Reference Bar
  77.               Opening Menus
  78.             QuickBASIC's On-Line Help
  79.               Using On-Line Help
  80.               The Help Menu
  81.             Choosing Commands
  82.             Using Dialog Boxes
  83.               Anatomy of a Dialog Box
  84.               Displaying a Dialog Box
  85.               Other Dialog-Box Features
  86.             Issuing Commands Directly
  87.               Shortcut Keys for Commands
  88.               Other Key Combinations
  89.             Exiting from QuickBASIC
  90.             For More Information
  91.  
  92.  Chapter 3  QuickBASIC's Windows
  93.             Windows Available with Easy Menus
  94.             The View Window
  95.               Loading Programs in the View Window
  96.               Moving the Cursor
  97.               Scrolling Text
  98.               Starting a New Program
  99.               Changing Window Sizes
  100.             QuickBASIC's Other Windows
  101.               Moving between Windows
  102.               Executing Code in the Immediate Window
  103.               Monitoring Variables with the Watch Window
  104.               The Help Window
  105.                 Context-Sensitive Help
  106.                 Hyperlinks
  107.             Exiting from QuickBASIC and Saving Programs
  108.             For More Information
  109.  
  110.  Chapter 4  Interlude: BASIC for Beginners
  111.             What is a Program?
  112.             Comments
  113.             Displaying Words and Numbers on the Screen
  114.             Variables
  115.               Storing Data in Memory
  116.               Variable Types
  117.                 Integer Variables
  118.                 Floating-Point Variables
  119.                 String Variables
  120.             Assigning Values to Variables
  121.             Calculations
  122.               Integer Division and the Remainder Operator
  123.               Precedence of Operations
  124.               Math Functions
  125.             Expressions
  126.             Displaying Variables and Expressions
  127.             Entering Data with the INPUT Statement
  128.             Arrays of Variables
  129.               Declaring Arrays
  130.               Specifying Array Elements
  131.             Logical Relations Used in Decision-Making
  132.               Relational Operators
  133.               Boolean Expressions
  134.               Compound Expressions
  135.             Using Logical Statements to Control Program Flow
  136.             Repeating Program Operations
  137.               The FOR...NEXT Loop
  138.               The DO...LOOP
  139.                 The DO WHILE Loop
  140.                 The DO UNTIL Loop
  141.             Writing a Simple BASIC Program
  142.             For More Information
  143.               Books about BASIC
  144.               Books about DOS
  145.  
  146.  PART 2  HANDS ON WITH QUICKBASIC
  147.  
  148.  Chapter 5  The QCARDS Program
  149.             Building QCARDS
  150.             Loading a Program When You Start QuickBASIC
  151.             A Quick Tour of QCARDS
  152.               The QCARDS Program
  153.               Declarations and Definitions
  154.               Comments
  155.               Statements Following the END Statement
  156.               Calling QCARDS Procedures from the Immediate Window
  157.               Breaking an Unconditional Loop from QCARDS
  158.               The Module-Level Code
  159.               Structured Programming with Procedures
  160.               A Profile of the Parts of the Program
  161.               Defining a Procedure in QCARDS
  162.             Saving Edited Text
  163.             For More Information
  164.  
  165.  Chapter 6  Editing in the View Window
  166.             The Smart Editor
  167.               Automatic Formatting
  168.               Syntax Checking
  169.               Errors Detected When You Run Your Program
  170.                 Help for Error Messages
  171.                 Overtyping the Error
  172.               Automatic Procedure Declarations
  173.             Working with Selected Text Blocks
  174.               Cutting or Copying Selected Text
  175.               Pasting a Text Block
  176.               Manipulating Selected Text
  177.             Searching and Replacing Text
  178.               Defining the Symbolic Constant
  179.               Replacing Multiple Occurrences of Text
  180.               Checking Your Work
  181.             For More Information
  182.  
  183.  Chapter 7  Programming with On-Line Help
  184.             Using On-Line Help to Construct Statements
  185.               On-Line Help for Keywords
  186.               Hyperlinks in On-Line Help
  187.               On-Line Help for Program Symbols
  188.             Printing Screens from On-Line Help
  189.             For More Information
  190.  
  191.  Chapter 8  Using Example Code from On-Line Help
  192.             Copying Example Code from On-Line Help
  193.             Indenting a Block of Code
  194.             Copying Large Code Blocks from On-Line Help
  195.             Editing the Block Copied from On-Line Help
  196.             Finishing the QCARDS Code
  197.             Using QCARDS
  198.             For More Information
  199.  
  200.  Chapter 9  Debugging While You Program
  201.             Debugging Commands
  202.               Debug-Menu Commands
  203.               Debugging Commands on the Run Menu
  204.               Function Keys Used in Debugging
  205.             Debugging a Procedure
  206.               Learning about Procedures
  207.               Continuing a Suspended Program
  208.             Isolating a Bug
  209.             Closing the Watch Window
  210.             Automatic Procedure Declarations
  211.             Creating a Stand-Alone Executable File
  212.             Learning about QuickBASIC's Other Menu Items
  213.             For More Information
  214.  
  215.  PART 3  QUICKBASIC MENUS AND COMMANDS
  216.  
  217.  Chapter 10 Getting Around in QuickBASIC
  218.             10.1  Starting QuickBASIC
  219.                   10.1.1  The QB Command
  220.                   10.1.2  The /NOHI Option
  221.                   10.1.3  The QuickBASIC Screen
  222.             10.2  Opening Menus and Choosing Commands
  223.                   10.2.1  Keyboard Technique
  224.                   10.2.2  Using Shortcut Keys
  225.             10.3  Using Dialog Boxes
  226.             10.4  Using Windows
  227.                   10.4.1  Window Types
  228.                   10.4.2  Splitting the View Window (Full Menus Only)
  229.                   10.4.3  Changing the Active Window
  230.                   10.4.4  Changing Window Size
  231.                   10.4.5  Scrolling in the Active Window
  232.             10.5  Using the Immediate Window
  233.                   10.5.1  Statements Not Allowed
  234.                   10.5.2  Doing Calculations
  235.                   10.5.3  Testing Screen Output
  236.                   10.5.4  Invoking Procedures
  237.                   10.5.5  Changing the Values of Variables
  238.                   10.5.6  Simulating Run-Time Errors
  239.             10.6  Using the Watch Window
  240.             10.7  Using the Mouse
  241.             10.8  Using On-Line Help
  242.                   10.8.1  Help Features
  243.                   10.8.2  Hyperlinks
  244.                   10.8.3  Moving in Help Windows
  245.                   10.8.4  Help Files
  246.                   10.8.5  Hard-Disk System
  247.                   10.8.6  Removable-Disk System
  248.  
  249.  Chapter 11 The File Menu
  250.             11.1  New Program Command
  251.             11.2  Open Program Command
  252.                   11.2.1  Specifying a File
  253.                   11.2.2  Listing Directory Contents
  254.             11.3  The Merge Command (Full Menus Only)
  255.             11.4  Save Command (Full Menus Only)
  256.             11.5  Save As Command
  257.             11.6  Save All Command (Full Menus Only)
  258.             11.7  Create File Command (Full Menus Only)
  259.             11.8  Load File Command (Full Menus Only)
  260.             11.9  Unload File Command (Full Menus Only)
  261.             11.10 The Print Command
  262.             11.11 DOS Shell Command (Full Menus Only)
  263.             11.12 Exit Command
  264.  
  265.  Chapter 12 Using the Editor
  266.             12.1  Entering Text
  267.             12.2  Selecting Text
  268.             12.3  Indenting text
  269.             12.4  Using Placemarkers in Text
  270.             12.5  The Smart Editor
  271.                   12.5.1  When Is the Smart Editor On?
  272.                   12.5.2  Automatic Syntax Checking
  273.                   12.5.3  Error Messages
  274.                   12.5.4  Automatic Formatting
  275.             12.6  Entering Special Characters
  276.             12.7  Summary of Editing Commands
  277.  
  278.  Chapter 13 The Edit Menu
  279.             13.1  Understanding the Clipboard
  280.             13.2  Undo Command (Full Menus Only)
  281.             13.3  Cut Command
  282.             13.4  Copy Command
  283.             13.5  Paste Command
  284.             13.6  Clear Command (Full Menus Only)
  285.             13.7  New SUB Command (Full Menus Only)
  286.                   13.7.1  Creating a New SUB Procedure
  287.                   13.7.2  Default Data Types for Procedures
  288.                   13.7.3  Changing a Procedure's Default Type
  289.                   13.7.4  Saving and Naming Procedures
  290.             13.8  New FUNCTION Command (Full Menus Only)
  291.  
  292.  Chapter 14 The View Menu
  293.             14.1  SUBs Command
  294.             14.2  Next SUB Command (Full Menus Only)
  295.             14.3  Split Command (Full Menus Only)
  296.             14.4  Next Statement Command (Full Menus Only)
  297.             14.5  Output Screen Command
  298.             14.6  Included File Command (Full Menus Only)
  299.                   14.6.1  Nesting Include Files
  300.                   14.6.2  Finding Include Files
  301.             14.7  Included Lines Command
  302.  
  303.  Chapter 15 The Search Menu
  304.             15.1  Defining Target Text
  305.             15.2  Find Command
  306.             15.3  Selected Text Command (Full Menus Only)
  307.             15.4  Repeat Last Find Command (Full Menus Only)
  308.             15.5  Change Command
  309.             15.6  Label Command (Full Menus Only)
  310.  
  311.  Chapter 16 The Run Menu
  312.             16.1  Start Command
  313.             16.2  Restart Command
  314.             16.3  Continue Command
  315.             16.4  Modify COMMAND$ Command (Full Menus Only)
  316.             16.5  Make EXE File Command
  317.                   16.5.1  Creating Executable Files
  318.                   16.5.2  Quick Libraries and Executable Files
  319.                   16.5.3  Types of Executable Files
  320.                           16.5.3.1  Programs that Use the Run-Time Module
  321.                           16.5.3.2  Stand-Alone Programs
  322.                   16.5.4  Run-Time Error Checking in Executable Files
  323.                   16.5.5  Floating-Point Arithmetic in Executable Files
  324.             16.6  Make Library Command (Full Menus Only)
  325.                   16.6.1  Unloading and Loading Modules
  326.                   16.6.2  Creating Libraries
  327.             16.7  Set Main Module Command (Full Menus Only)
  328.                   16.7.1  Changing the Main Module
  329.                   16.7.2  The .MAK File
  330.  
  331.  Chapter 17 Debugging Concepts and Procedures
  332.             17.1  Debugging with QuickBASIC
  333.             17.2  Preventing Bugs with QuickBASIC
  334.             17.3  QuickBASIC's Debugging Features
  335.                   17.3.1  Tracing (Full Menus Only)
  336.                   17.3.2  Breakpoints and Watchpoints
  337.                   17.3.3  Watch Expressions
  338.                   17.3.4  Watch Window
  339.                   17.3.5  Immediate Window
  340.                   17.3.6  Other Debugging Features
  341.  
  342.  Chapter 18 The Debug Menu
  343.             18.1  Add Watch Command
  344.             18.2  Instant Watch Command
  345.             18.3  Watchpoint Command (Full Menus Only)
  346.             18.4  Delete Watch Command
  347.             18.5  Delete All Watch Command (Full Menus Only)
  348.             18.6  Trace On Command (Full Menus Only)
  349.             18.7  History On Command (Full Menus Only)
  350.                   18.7.1  History Back
  351.                   18.7.2  History Forward
  352.             18.8  Toggle Breakpoint Command
  353.             18.9  Clear All Breakpoints Command
  354.             18.10 Break on Errors Command (Full Menus Only)
  355.             18.11 Set Next Statement Command
  356.  
  357.  Chapter 19 The Calls Menu (Full Menus Only)
  358.             19.1  Using the Calls Menu
  359.             19.2  Active Procedures
  360.  
  361.  Chapter 20 The Options Menu
  362.             20.1  Display Command
  363.             20.2  Set Paths Command
  364.             20.3  Right Mouse Command (Full Menus Only)
  365.             20.4  Syntax Checking Command(Full Menus Only)
  366.             20.5  Full Menus Command
  367.  
  368.  Chapter 21 The Help Menu
  369.             21.1  Index Command
  370.             21.2  Contents Command
  371.             21.3  Topic Command
  372.             21.4  Help On Help Command
  373.  
  374.  Glossary
  375.  
  376.  Figures
  377.             Figure 2.1  QuickBASIC Invocation Screen
  378.             Figure 2.2  The File Menu
  379.             Figure 2.3  Help Dialog Box for the Help Menu
  380.             Figure 2.4  Open Program Dialog Box
  381.             Figure 2.5  Display Dialog Box
  382.             Figure 2.6  Help on Output Screen Command
  383.             Figure 3.1  Windows Available with Easy Menus
  384.             Figure 3.2  Open Program Dialog Box
  385.             Figure 3.3  Output Screen for Code Lines
  386.             Figure 3.4  Immediate Window Showing Lines Just Entered
  387.             Figure 3.5  Placing Variables in the Watch Window
  388.             Figure 3.6  QuickSCREEN for PRINT Statement
  389.             Figure 3.7  Example Screen for PRINT Statement
  390.             Figure 3.8  Save As Dialog Box
  391.             Figure 4.1  Addresses in Memory
  392.             Figure 4.2  Array Created by the BASIC Statement DIM Price (4)
  393.             Figure 5.1  QCARDS' Interface
  394.             Figure 5.2  Modules and Procedures
  395.             Figure 5.3  SUBs Dialog Box
  396.             Figure 5.4  Save As Dialog Box
  397.             Figure 6.1  Error-Message Dialog Box
  398.             Figure 6.2  Error Message
  399.             Figure 6.3  Help on Error Message
  400.             Figure 6.4  Find Dialog Box
  401.             Figure 6.5  Change Dialog Box
  402.             Figure 6.6  Change, Skip, Cancel Dialog Box
  403.             Figure 7.1  QuickSCREEN for IF...THEN...ELSE Statement
  404.             Figure 7.2  Symbol Help for CardNum
  405.             Figure 7.3  Instant Watch Dialog Box
  406.             Figure 7.4  Print Dialog Box (Help)
  407.             Figure 8.1  Example Screen for DO...LOOP Statement
  408.             Figure 8.2  QuickSCREEN for SELECT CASE Statement
  409.             Figure 8.3  Code Showing Call to AsciiKey Procedure
  410.             Figure 9.1  Selecting the SELECT CASE Choice$ Block
  411.             Figure 9.2  DirectionKey Procedure in View Window
  412.             Figure 9.3  Restart Program Error Message
  413.             Figure 9.4  Setting a Breakpoint
  414.             Figure 9.5  Symbol Help for Symbolic Constant HOME
  415.             Figure 9.6  Error in Naming Symbolic Constant for the ENV
  416.             Key
  417.             Figure 9.7  Make EXE File Dialog Box
  418.             Figure 10.1 Top Half of QuickBASIC Invocation Screen
  419.             Figure 10.2 Bottom Half of QuickBASIC Invocation
  420.             Screen
  421.             Figure 10.3 The File Menu
  422.             Figure 10.4 Load File Dialog Box
  423.             Figure 10.5 Display Dialog Box
  424.             Figure 10.6 QuickBASIC Screen with Five Windows Open
  425.             Figure 10.7 Immediate Window
  426.             Figure 10.8 Simulated Run-Time Error
  427.             Figure 10.9 Watch Window
  428.             Figure 10.10 Help on the PRINT Statement
  429.             Figure 10.11 Dialog Box for Missing Help File
  430.             Figure 11.1 Open Program Dialog Box
  431.             Figure 11.2 Merge Dialog Box
  432.             Figure 11.3 Save Dialog Box
  433.             Figure 11.4 Create File Dialog Box
  434.             Figure 11.5 Load File Dialog Box
  435.             Figure 11.6 Unload File Dialog Box
  436.             Figure 11.7 Print Dialog Box
  437.             Figure 11.8 Exit Dialog Box
  438.             Figure 12.1 Syntax Error Message
  439.             Figure 12.2 Initial Help Screen on the OPEN Keyword
  440.             Figure 13.1 New SUB Dialog Box
  441.             Figure 13.2 New FUNCTION Dialog Box
  442.             Figure 14.1 New SUBs Dialog Box
  443.             Figure 14.2 Move Dialog Box
  444.             Figure 15.1 Find Dialog Box
  445.             Figure 15.2 Change Dialog Box
  446.             Figure 15.3 Change, Skip, Cancel Dialog Box
  447.             Figure 15.4 Label Dialog Box
  448.             Figure 16.1 Modify COMMAND$ Dialog Box
  449.             Figure 16.2 Make EXE File Dialog Box
  450.             Figure 16.3 Make Library Dialog Box
  451.             Figure 16.4 Set Main Module DIalog Box
  452.             Figure 18.1 Add Watch Dialog Box
  453.             Figure 18.2 Instant Watch Dialog Box
  454.             Figure 18.3 Watchpoint Dialog Box
  455.             Figure 18.4 Delete Watch Dialog Box
  456.             Figure 19.1 Sequence of Procedures on Calls Menu
  457.             Figure 20.1 Display Dialog Box
  458.             Figure 20.2 Set Paths Dialog Box
  459.             Figure 20.3 Right Mouse Dialog Box
  460.             Figure 21.1 Index Entries for Help
  461.             Figure 21.2 Table of Contents for Help
  462.             Figure 21.3 Help on the FOR...NEXT Statement
  463.             Figure 21.4 Help on Help Screen
  464.  
  465.  Tables
  466.             Table 10.1  QuickBASIC Shortcut Keys
  467.             Table 10.2  Scrolling
  468.             Table 10.3  Mouse Commands
  469.             Table 10.4  Help Keys
  470.             Table 12.1  QuickBASIC Indentation Controls
  471.             Table 12.2  Editing Commands
  472.             Table 15.1  Search Options
  473.             Table 15.2  Search Restrictions
  474.             Table 17.1  Additional Debugging Features
  475.  
  476.  QCARDS Code Entries
  477.             QCARDS Code Entry 1
  478.             QCARDS Code Entry 2
  479.             QCARDS Code Entry 3
  480.             QCARDS Code Entry 4
  481.             QCARDS Code Entry 5
  482.             QCARDS Code Entry 6
  483.             QCARDS Code Entry 7
  484.             QCARDS Code Entry 8
  485.             QCARDS Code Entry 9
  486.             QCARDS Code Entry 10
  487.             QCARDS Code Entry 11
  488.             Optional QCARDS Code Entry 1
  489.             Optional QCARDS Code Entry 2
  490.             Optional QCARDS Code Entry 3
  491.             QCARDS Code Entry 12
  492.             QCARDS Code Entry 13
  493.             QCARDS Code Entry 14
  494.             QCARDS Code Entry 15
  495.             QCARDS Code Entry 16
  496.             QCARDS Code Entry 17
  497.             QCARDS Code Entry 18
  498.             QCARDS Code Entry 19
  499.             QCARDS Code Entry 20
  500.             QCARDS Code Entry 21
  501.             QCARDS Code Entry 22
  502.             Optional QCARDS Code Entry 4
  503.             QCARDS Code Entry 23
  504.             QCARDS Code Entry 24
  505.             QCARDS Code Entry 25
  506.             QCARDS Code Entry 26
  507.             QCARDS Code Entry 27
  508.             QCARDS Code Entry 28
  509.             QCARDS Code Entry 29
  510.             QCARDS Code Entry 30
  511.  
  512.  
  513.  
  514.  ────────────────────────────────────────────────────────────────────────────
  515.  Introduction
  516.  
  517.    Microsoft(R) QuickBASIC is a programming environment that includes all the
  518.    tools you need for writing, editing, running, and debugging programs.
  519.    These tools are integrated with a powerful version of the BASIC
  520.    programming language and an on-line help system that explains everything
  521.    about both the environment and the language.
  522.  
  523.  
  524.  Instant Feedback
  525.  
  526.    Microsoft QuickBASIC speeds your programming and learning by giving
  527.    virtually instant feedback for your ideas. When you write a program, you
  528.    enter "code" (sequences of QuickBASIC statements) that describe what you
  529.    want the program to do. QuickBASIC checks the validity of each line as you
  530.    enter it, then immediately translates your code into a form the computer
  531.    can execute. If your code contains errors that make it impossible to
  532.    translate, QuickBASIC specifies the error and helps you correct it. As
  533.    soon as your code is correct, you can press a key and immediately run it.
  534.    If your code doesn't run as you expect, you can use QuickBASIC's
  535.    sophisticated debugging tools to track and correct flaws in your code's
  536.    logic.You get the speed and power of a compiled language without the
  537.    tedious cycles of separate editing, compiling, running, and debugging.
  538.  
  539.  
  540.  Instant Help
  541.  
  542.    Microsoft QuickBASIC's on-line help system includes two parts. The
  543.    Microsoft QB Advisor contains explanations and runnable examples of every
  544.    statement in the QuickBASIC language. Also, you can get on-line help for
  545.    every aspect of the QuickBASIC environment, all symbols you define in your
  546.    program, and error messages.
  547.  
  548.    In this manual you will see how to get information on the following with
  549.    on-line help:
  550.  
  551.    ■ QuickBASIC statements and functions
  552.  
  553.    ■ Menu and dialog-box items and options
  554.  
  555.    ■ Special keys and key combinations for editing and debugging
  556.  
  557.    ■ How to correct errors in your program
  558.  
  559.    ■ Symbols you define in your programs
  560.  
  561.  
  562.  Hardware Requirements
  563.  
  564.    Microsoft QuickBASIC requires an IBM Personal Computer or IBM(R)-PC
  565.    compatible with at least 384 kilobytes (K) of available memory and a
  566.    minimum of 720K disk-drive capacity. A hard disk and 640K of memory are
  567.    recommended for best performance.
  568.  
  569.    The QuickBASIC environment fully supports any mouse that is compatible
  570.    with the Microsoft Mouse. See Section 10.7 for complete information on
  571.    using your mouse with QuickBASIC.
  572.  
  573.    ──────────────────────────────────────────────────────────────────────────
  574.    NOTE
  575.      Throughout this manual, the term "DOS" refers to both the MS-DOS(R) and
  576.      IBM Personal Computer DOS operating systems. The name of a specific
  577.      operating system is used when it is necessary to note features that are
  578.      unique to that system.
  579.    ──────────────────────────────────────────────────────────────────────────
  580.  
  581.  
  582.  The QuickBASIC Package
  583.  
  584.    The Microsoft QuickBASIC package includes two manuals, an extensive
  585.    on-line help system, example programs, and other on-line documentation.
  586.    The next sections describe the contents of the package.
  587.  
  588.  Printed Documentation
  589.  
  590.    Your Microsoft QuickBASIC package includes two manuals. This manual
  591.    discusses the QuickBASIC programming environment. The first two parts are
  592.    a tutorial on how to use QuickBASIC. The last part is a reference on
  593.    QuickBASIC menus and commands. The following list describes these parts in
  594.    more detail:
  595.  
  596.    Part                     Content
  597.    ──────────────────────────────────────────────────────────────────────────
  598.    "Getting Started"       General description of how to use QuickBASIC and
  599.                             a brief introduction to BASIC programming.
  600.  
  601.    "Hands On with           Tutorial introduction to the Easy-Menus version
  602.    QuickBASIC"             of the QuickBASIC environment. The tutorial gives
  603.                             you practice with editing, debugging, and on-line
  604.                             help and guides you in creating your first
  605.                             QuickBASIC application, QCARDS.BAS.
  606.  
  607.    "QuickBASIC Menus and    Reference to the QuickBASIC environment that
  608.    Commands"               presents detailed information on each command on
  609.                             QuickBASIC's Full Menus. Full Menus provide the
  610.                             complete multiple-module functionality of
  611.                             QuickBASIC. Use this section to extend your
  612.                             knowledge after you feel comfortable with the
  613.                             fundamentals of QuickBASIC.
  614.  
  615.    "Glossary"              Definitions of terms used in the documentation.
  616.    ──────────────────────────────────────────────────────────────────────────
  617.  
  618.    This manual provides the following information that you'll need to begin
  619.    programming with QuickBASIC:
  620.  
  621.    ■ The QuickBASIC environment
  622.  
  623.    ■ The QuickBASIC implementation of the BASIC language
  624.  
  625.    ■ The principles of programming
  626.  
  627.    If you are new to programming, new to the BASIC language, or both, you
  628.    will need to learn the environment, the QuickBASIC version of the BASIC
  629.    language, and general programming skills. You should begin with Chapters
  630.    1-4 in Part 1, "Getting Started." If you already know how to program in
  631.    BASIC, you should be able to get right to programming after reading
  632.    Chapters 1-3 in Part 1.
  633.  
  634.    In the tutorial in Part 2, "Hands On with QuickBASIC," you will practice
  635.    using some of the QuickBASIC environment's most exciting features. You'll
  636.    use the sophisticated editor, on-line help, and debugging features. When
  637.    you finish the tutorial, you will have built a useful database application
  638.    program, QCARDS.BAS.
  639.  
  640.    The QuickBASIC package includes another manual, Programming in BASIC,
  641.    which discusses the following:
  642.  
  643.    ■ Specific, practical programming topics, each illustrated by extensive
  644.      programming examples
  645.  
  646.    ■ The action and syntax of each QuickBASIC statement and function with
  647.      tables listing the statements and functions by task groups
  648.  
  649.    ■ Information on topics such as converting interpreted BASIC programs to
  650.      run in QuickBASIC, changes in Version 4.5 from previous versions of
  651.      QuickBASIC, and compiling and linking from DOS
  652.  
  653.    Use Programming in BASIC for in-depth information on programming topics
  654.    and a synopsis of the BASIC language.
  655.  
  656.  On-Line Documentation
  657.  
  658.    Microsoft QuickBASIC includes comprehensive on-line help and several disk
  659.    files that provide supplementary information and programming examples.
  660.    These are described in the following list:
  661.  
  662. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  663.    Documentation            Purpose
  664.    ──────────────────────────────────────────────────────────────────────────
  665.    On-Line Help             All information needed for programming in
  666.                             QuickBASIC. When you use help commands within the
  667.                             environment, QuickBASIC searches several files to
  668.                             provide the information.
  669.  
  670.                             The file QB45QCK.HLP includes summaries and
  671.                             syntax descriptions of each QuickBASIC statement
  672.                             and function. The file QB45ADVR.HLP contains
  673.                             comprehensive information on using each statement
  674.    Documentation            Purpose
  675.    ──────────────────────────────────────────────────────────────────────────
  676.                            comprehensive information on using each statement
  677.                             and function, including example code you can copy
  678.                             and run. The file QB45ENER.HLP has explanations
  679.                             of all environment menus, commands, dialog boxes,
  680.                             and error messages.
  681.  
  682.    README.DOC               A file describing changes to QuickBASIC that
  683.                             occurred after the manuals were printed.
  684.  
  685.    PACKING.LST              A file describing each file on the QuickBASIC
  686.                             distribution disks.
  687.  
  688.    LEARN.COM                Microsoft QB Express, a computer-based training
  689.                             program that gives an overview of QuickBASIC.
  690.  
  691.    Sample programs          All the programs from Programming in BASIC. Check
  692.                             the file called PACKING.LST to locate them. Other
  693.                             sample programs are also included. Many
  694.                             demonstrate advanced programming techniques and
  695.    Documentation            Purpose
  696.    ──────────────────────────────────────────────────────────────────────────
  697.                            demonstrate advanced programming techniques and
  698.                             algorithms.
  699.    ──────────────────────────────────────────────────────────────────────────
  700.  
  701.  
  702.  
  703.  Document Conventions
  704.  
  705.    This manual uses the following document conventions:
  706.  
  707. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  708.    Example of Convention    Description
  709.    ──────────────────────────────────────────────────────────────────────────
  710.    QB.LIB, ADD.EXE, COPY,   Uppercase (capital) letters indicate file names
  711.    LINK, /X                 and DOS-level commands. Uppercase is also used
  712.                             for command-line options (unless the application
  713.                             accepts only lowercase).
  714.  
  715.    SUB, IF, LOOP, PRINT,    Bold capital letters indicate language-specific
  716.    Example of Convention    Description
  717.    ──────────────────────────────────────────────────────────────────────────
  718.   SUB, IF, LOOP, PRINT,    Bold capital letters indicate language-specific
  719.    WHILE, TIME$             keywords with special meaning to Microsoft BASIC.
  720.                             Keywords are a required part of statement syntax,
  721.                             unless they are enclosed in double brackets as
  722.                             explained below. In programs you write, you must
  723.                             enter keywords exactly as shown. However, you can
  724.                             use uppercase letters or lowercase letters.
  725.  
  726.    CALL Proc(arg1!, var2%)  This kind of type is used for program examples,
  727.                             program output, words you should type in, and
  728.                             error messages within the text.
  729.  
  730.    CONST FALSE  =  0        A column of three dots indicates that part of the
  731.      .                      example program has been intentionally omitted.
  732.      .
  733.      .
  734.    CHAIN "PROG1"
  735.    END
  736.  
  737.    Example of Convention    Description
  738.    ──────────────────────────────────────────────────────────────────────────
  739. 
  740.    ' Make one pass          The apostrophe (single right quotation mark)
  741.                             marks the beginning of a comment in sample
  742.                             programs.
  743.  
  744.    filespec                 Italic letters indicate placeholders for
  745.                             information, such as a file name, that you must
  746.                             supply. Italics are also occasionally used in the
  747.                             text for emphasis.
  748.  
  749.    [[optional-item]]        Items inside double square brackets are optional.
  750.  
  751.    ALT+F1                   Capital letters are used for the names of keys
  752.                             and key sequences, such as ENTER and CTRL+R.
  753.  
  754.                             A plus (+) indicates a combination of keys. For
  755.                             example, CTRL+E means to hold down the CTRL key
  756.                             while pressing the E key.
  757.  
  758.    Example of Convention    Description
  759.    ──────────────────────────────────────────────────────────────────────────
  760. 
  761.                             The carriage-return key, sometimes marked with a
  762.                             bent arrow, is referred to as ENTER.
  763.  
  764.                             The cursor movement ("arrow") keys on the numeric
  765.                             keypad are called DIRECTION keys. Individual
  766.                             DIRECTION keys are referred to by the direction
  767.                             of the arrow on the key top (LEFT, RIGHT, UP,
  768.                             DOWN) or the name on the key top (PGUP, PGDN).
  769.  
  770.                             The key names used in this manual correspond to
  771.                             the names on the IBM Personal Computer keys.
  772.                             Other machines may use different names.
  773.  
  774.    "defined term"           Quotation marks usually indicate a new term
  775.                             defined in the text.
  776.  
  777.    Video Graphics Array     Acronyms are usually spelled out the first time
  778.    (VGA)                    they are used.
  779.    Example of Convention    Description
  780.    ──────────────────────────────────────────────────────────────────────────
  781.   (VGA)                    they are used.
  782.    ──────────────────────────────────────────────────────────────────────────
  783.  
  784.  
  785.    The following syntax block shows how some of these document conventions
  786.    are used in this manual:
  787.  
  788.    GET[[#]] filenumber [[,[[recordnumber]][[,variable]]]]
  789.    .
  790.    .
  791.    .
  792.    PUT[[#]] filenumber [[,[[recordnumber]][[,variable]]]]
  793.  
  794.  
  795.  Requesting Assistance
  796.  
  797.    If you feel you have discovered a problem in the software, please report
  798.    the problem using the Product Assistance Request form at the back of this
  799.    manual.
  800.  
  801.    If you have comments or suggestions regarding any of the manuals
  802.    accompanying this product, please use the Documentation Feedback form at
  803.    the back of this manual.
  804.  
  805.  
  806.  
  807.  ────────────────────────────────────────────────────────────────────────────
  808.  PART 1  GETTING STARTED
  809.  ────────────────────────────────────────────────────────────────────────────
  810.  
  811.    Part 1, "Getting Started," introduces you to the Microsoft QuickBASIC
  812.    environment, then moves on to an introductory discussion on BASIC
  813.    programming. Each major feature of the environment is explained, then
  814.    demonstrated in a brief hands-on exercise. Each chapter ends with a
  815.    section specifying where you can look for more information on each of the
  816.    topics discussed.
  817.  
  818.    Chapter 1 guides you through installation of QuickBASIC, using the SETUP
  819.    program provided.
  820.  
  821.    Chapters 2 and 3 introduce you to working with QuickBASIC's Easy Menus,
  822.    dialog boxes, and windows.
  823.  
  824.    Chapter 4 introduces the BASIC language for novice programmers. Be sure
  825.    you understand everything in this chapter before moving ahead. If you have
  826.    programmed in another language this chapter should provide all you need to
  827.    complete Part 2, "Hands On with QuickBASIC," and start using QuickBASIC
  828.    to write your own programs. If you are new to programming, you may want to
  829.    consult some of the books on BASIC listed at the end of the chapter.
  830.  
  831.  
  832.  
  833.  ────────────────────────────────────────────────────────────────────────────
  834.  Chapter 1  Setting Up Microsoft(R) QuickBASIC
  835.  
  836.    Your Microsoft QuickBASIC package includes the file SETUP.EXE (on the
  837.    Setup/Microsoft QB Express disk). This program automates installation of
  838.    QuickBASIC, and lets you choose display options to install or update files
  839.    required by QuickBASIC and your hardware.
  840.  
  841.    This chapter discusses
  842.  
  843.    ■ Installing Microsoft QuickBASIC
  844.  
  845.    ■ Using Microsoft QB Express
  846.  
  847.    ■ Exploring QuickBASIC, depending on your experience level
  848.  
  849.  
  850.  The Setup Program
  851.  
  852.    If you do not have a hard disk, be sure you have five formatted, 360K
  853.    removable disks (or an equivalent amount of space on disks of other
  854.    sizes). If you have a hard disk, you need 1.8 megabytes of space available
  855.    to install all QuickBASIC files. To start SETUP
  856.  
  857.      Place the Setup/Microsoft QB Express disk in your disk drive, and type
  858.       setup at the DOS prompt.
  859.  
  860.    Each screen in the SETUP program contains the following:
  861.  
  862.    ■ An explanation of the current screen or the following screen.
  863.  
  864.    ■ The Setup menu, which you use to choose what you want to do next.
  865.      Generally, the Setup menu on each screen lets you continue, go back a
  866.      screen, examine the options you've chosen, or return to the starting
  867.      screen. To move within the menu and make choices, use the DIRECTION
  868.      keys, then press ENTER when your choice is highlighted.
  869.  
  870.    ■ A prompt at the bottom of the screen tells you how to move on to the
  871.      next step.
  872.  
  873.    ──────────────────────────────────────────────────────────────────────────
  874.    NOTE
  875.      If you make a mistake when installing QuickBASIC with SETUP, you can go
  876.      back to any previous point and start again from there. You can run SETUP
  877.      as many times as you like.
  878.    ──────────────────────────────────────────────────────────────────────────
  879.  
  880.  
  881.  The Setup Main Menu
  882.  
  883.    The items on the Setup Main menu allow you to choose the defaults for all
  884.    options (Easy Setup) and customize the options you choose during setup
  885.    (Full Setup).
  886.  
  887.    If you are a novice programmer, you should choose Easy Setup. As you learn
  888.    more about QuickBASIC, you can reset these options from within the
  889.    environment without running SETUP again.
  890.  
  891.    If you are an experienced programmer, Full Setup lets you tailor the
  892.    appearance and certain behaviors of QuickBASIC. Chapter 20, "The Options
  893.    Menu," describes how QuickBASIC handles the search paths and colors you
  894.    choose during setup. (They correspond to the Options menu's Display and
  895.    Set Paths commands.)
  896.  
  897.    Whether you choose Easy or Full Setup, use the Show Options menu command
  898.    to look at the final settings before completing the installation.
  899.  
  900.  
  901.  Installation
  902.  
  903.    After you have decided about options, choose Perform Installation from the
  904.    menu to begin automated installation. QuickBASIC prompts you for each disk
  905.    you need to insert in your disk drive as installation progresses.
  906.  
  907.    If you have a hard disk, QuickBASIC places the files you need in the
  908.    directories specified in either the Easy Setup or Full Setup options. If
  909.    the directories don't already exist, QuickBASIC creates the directories
  910.    you specify on your hard disk.
  911.  
  912.    If you do not have a hard disk, you must start the installation phase with
  913.    five formatted removable disks. QuickBASIC prompts you when to install
  914.    each disk. You might want to label the disks, using the same names as
  915.    appear on the original disks.
  916.  
  917.  
  918.  QB Express
  919.  
  920.    After installation is complete, return to the Main Setup menu. Even if
  921.    you've used QuickBASIC before, you should choose Exit and Run QB Express
  922.    from the main menu. Microsoft QB Express, a brief computer-based training
  923.    program, introduces the QuickBASIC environment and gives you some practice
  924.    in the things you'll do when you fire up QuickBASIC itself. If you've used
  925.    QuickBASIC before, QB Express alerts you to Version 4.5 enhancements to
  926.    the environment.
  927.  
  928.  
  929.  Getting Into QuickBASIC
  930.  
  931.    QuickBASIC is a superb environment in which to learn programming, but it
  932.    is not specifically designed as a "learn to program" environment.
  933.    QuickBASIC provides all the tools you need for programming──editing,
  934.    debugging, and on-line help──plus a powerful version of the BASIC
  935.    language.
  936.  
  937.    Chapters 2-9 of this book are a tutorial on QuickBASIC. A typewriter icon
  938.    marks all the practice exercises.
  939.  
  940.  If You Are a Novice Programmer
  941.  
  942.    In learning to use QuickBASIC, you need to distinguish between the tools
  943.    provided by the environment, and the language itself. The best way to
  944.    acquaint yourself with the environment is by reading Chapter 2, "Using
  945.    Menus and Commands," and Chapter 3, "QuickBASIC's Windows." Then, try
  946.    Chapter 4, "Interlude: BASIC for Beginners," which should give you enough
  947.    perspective on BASIC programming to complete Part 2, "Hands On with
  948.    QuickBASIC."
  949.  
  950.    Part 2, "Hands On with QuickBASIC," is a tutorial that introduces you to
  951.    editing, using on-line help, and debugging in the context of an extended
  952.    program example. In a series of exercises, you will complete the coding of
  953.    QCARDS.BAS, a real application program. Each of these chapters takes one
  954.    to two hours to complete.
  955.  
  956.    Although "Hands On with QuickBASIC" is not a tutorial on programming,
  957.    QCARDS.BAS provides a good model of program structure. You can also use
  958.    the code from QCARDS in other programs you write. But remember, the
  959.    purpose of the QCARDS tutorial is to teach you quickly how to use the
  960.    tools in the QuickBASIC environment.
  961.  
  962.    You don't have to understand all the programming techniques to type in the
  963.    QCARDS code. To learn more about programming, read some of the BASIC
  964.    programming texts listed at the end of Chapter 4, "Interlude: BASIC for
  965.    Beginners." Programming in BASIC, included with this package, presents
  966.    extended examples and explanations of selected programming topics.
  967.  
  968.  If You Already Know BASIC
  969.  
  970.    If you are already familiar with BASIC, you should be able to move quickly
  971.    through Chapter 2, "Using Menus and Commands," and Chapter 3,
  972.    "QuickBASIC's Windows," which teach the fundamentals of menus and windows,
  973.    and opening, clearing, and saving files. You can skip Chapter 4
  974.    completely and move right to Part 2, "Hands On with QuickBASIC," to learn
  975.    the use of QuickBASIC's advanced editing, on-line help, and debugging
  976.    features. Even if you have used a previous version of QuickBASIC, you may
  977.    find some new programming techniques in QCARDS.BAS, the example program
  978.    you will build as you practice advanced environment features. The comments
  979.    in the QCARDS code explain how the program works. If the comments do not
  980.    provide enough information, the programming techniques are discussed in
  981.    Programming in BASIC.
  982.  
  983.  
  984.  If You Use a Mouse
  985.  
  986.    QuickBASIC fully supports pointing devices that are compatible with the
  987.    Microsoft Mouse. See Section 10.7 for complete information on using
  988.    QuickBASIC with a mouse.
  989.  
  990.  
  991.  
  992.  ────────────────────────────────────────────────────────────────────────────
  993.  Chapter 2  Using Menus and Commands
  994.  
  995.    This chapter teaches you how to start Microsoft QuickBASIC and use the
  996.    Easy Menus. A "menu" is a list of commands. In QuickBASIC, you can choose
  997.    between two sets of menus──Easy Menus and Full Menus. Easy Menus, which
  998.    you'll work with here, contain all the commands a novice programmer needs
  999.    to use QuickBASIC. Part 3, "QuickBASIC Menus and Commands" describes the
  1000.    advanced commands on the Full Menus.
  1001.  
  1002.    When you have completed this chapter, you'll know how to
  1003.  
  1004.    ■ Open and use menus and dialog boxes
  1005.  
  1006.    ■ Consult QuickBASIC's on-line help to answer questions
  1007.  
  1008.    ■ Use function keys and shortcut-key combinations
  1009.  
  1010.    This chapter will take one to one and one-half hours to complete.
  1011.  
  1012.  
  1013.  Starting QuickBASIC
  1014.  
  1015.    Start QuickBASIC now:
  1016.  
  1017.    1. Type qb at the DOS prompt. The QuickBASIC screen appears.
  1018.  
  1019.    2. Press ENTER to display essential information about the QuickBASIC
  1020.       environment. You can use PGUP and PGDN to move around in this text.
  1021.  
  1022.    3. Press ESC to clear this information from the screen.
  1023.  
  1024.    ──────────────────────────────────────────────────────────────────────────
  1025.    NOTE
  1026.      If your computer has a monochrome or liquid-crystal display, or if you
  1027.      use a Color Graphics Adapter (CGA) with a black-and-white monitor, see
  1028.      Sections 10.1.1, "The QB Command," and 10.1.2, "The /NOHI Option," for
  1029.      additional QB invocation options.
  1030.        If you start QuickBASIC with the /nohi or /b /nohi option, what are
  1031.        referred to as high-intensity letters in this manual may have a
  1032.        different appearance.
  1033.    ──────────────────────────────────────────────────────────────────────────
  1034.  
  1035.  
  1036.  The QuickBASIC Environment
  1037.  
  1038.    QuickBASIC's programming tools are instantly available. They include
  1039.    features for program organization, editing, syntax checking, file
  1040.    management, printing, and debugging──even customizing the colors of the
  1041.    environment.
  1042.  
  1043.  The Menu Bar
  1044.  
  1045.    The menus on the menu bar at the top of the QuickBASIC screen contain the
  1046.    QuickBASIC environment commands (see Figure 2.1). You'll use them as you
  1047.    write and modify programs in the View window.
  1048.  
  1049.  
  1050.    Menu bar                    Title bar        Scroll bars    View window
  1051.     │                               │                ││            │
  1052.       File  Edit  View  Search  Run │Debug  Options  ││            │    Help
  1053.    ┌┬─────────────────┬────────────└ Untitled ───────┼┼────────────┼─────┤├──
  1054.    ││ New Program     │                              ││            │
  1055.    ││ Open Program... │                              ││            │
  1056.    ││ Save As...      │                              ││
  1057.    │├─────────────────┤                              ││
  1058.    ││ Print...        │                              │└───────────────────────
  1059.    │├─────────────────┤                              │
  1060.    ││ Exit            │                              │
  1061.    │└─────────────────┘                              │
  1062.    │                                                 │
  1063.    │                                                 │
  1064.    │                                                 │
  1065.    │                                                 │
  1066.    │                                                 │
  1067.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  1068.    ├─────────────────────────────── Immediate ────────────────────────────────
  1069.    │
  1070.    │                  │
  1071.     F1=Help    Removes│currently loaded program from memory       CN 00001:001
  1072.             │         │                                         └─┬─┘└───┬───┘
  1073.    Reference bar    Immediate            CAPS LOCK and────────────┘   Row and
  1074.                      window              NUM LOCK indicators  column indicator
  1075.  
  1076.    Figure 2.1  QuickBASIC Invocation Screen
  1077.  
  1078.  The Reference Bar
  1079.  
  1080.    The reference bar at the bottom of the screen tells which keys to press to
  1081.    perform important actions (see Figure 2.1). As you work on a program, the
  1082.    reference bar updates information about the environment and your program.
  1083.    When a command is highlighted, the reference bar briefly describes how to
  1084.    use the command. Row and column counters indicate where you are in your
  1085.    program, and CAPS LOCK and NUM LOCK indicators tell how your keyboard is
  1086.    set.
  1087.  
  1088.  Opening Menus
  1089.  
  1090.    You can execute most QuickBASIC commands by choosing them from the menus.
  1091.    When you press the ALT key, QuickBASIC highlights the file menu, and one
  1092.    letter in each menu name appears in high-intensity video. To open a menu,
  1093.    press the ALT key, then press the key corresponding to the high-intensity
  1094.    letter in the menu name.
  1095.  
  1096.    You can open the menus and move among them using the DIRECTION keys (the
  1097.    UP, DOWN, LEFT, and RIGHT arrow keys) .
  1098.  
  1099.    To open a menu
  1100.  
  1101.    1. Press ALT to select the File menu.
  1102.  
  1103.       When you "select" (highlight) a menu, its name is shown in a
  1104.       reverse-video block. If you press ALT again, the menu name loses the
  1105.       highlight.
  1106.  
  1107.    2. Press ENTER to open the File menu (see Figure 2.2).
  1108.  
  1109.  
  1110.       ┌───────┐
  1111.       │ File  │
  1112.       ├───────┴──────────┐
  1113.       │ New Program      │
  1114.       │ Open Program...  │
  1115.       │ Save As...       │
  1116.       ├──────────────────┤
  1117.       │ Print...         │
  1118.       ├──────────────────┤
  1119.       │ Exit             │
  1120.       └──────────────────┘
  1121.  
  1122.       Figure 2.2  The File Menu
  1123.  
  1124.      ■ Press the UP or DOWN key to select successive commands in an open
  1125.        menu.
  1126.  
  1127.      ■ Press the RIGHT or LEFT key to open adjacent menus.
  1128.  
  1129.    3. Press ESC to close the menu without executing a command. The cursor
  1130.       returns to the View window, the part of the screen where you edit your
  1131.       program. You can always back out of any situation by pressing ESC.
  1132.  
  1133.  
  1134.  QuickBASIC's On-Line Help
  1135.  
  1136.    If you need additional information about menus or other QuickBASIC
  1137.    features, consult on-line help. You can get help on BASIC keywords, the
  1138.    elements of the language, the QuickBASIC environment, and error messages.
  1139.  
  1140.  Using On-Line Help
  1141.  
  1142.    There are several ways to get on-line help in QuickBASIC. For help on menu
  1143.    names or commands, select the name or command, then press F1. If you want
  1144.    help on any part of a program, place the cursor within the word, then
  1145.    press F1.
  1146.  
  1147.    To move around in on-line help, do the following:
  1148.  
  1149.    ■ Press PGDN to see additional screens.
  1150.  
  1151.    ■ Press PGUP to move back through screens you have already seen.
  1152.  
  1153.    ■ Press ESC to cancel on-line help.
  1154.  
  1155.    If you need more information on using any on-line help function, hold down
  1156.    the SHIFT key while pressing F1 for a general description of on-line help.
  1157.  
  1158.  The Help Menu
  1159.  
  1160.    Most on-line help is available through the Help menu. Try this to use
  1161.    on-line help:
  1162.  
  1163.    1. Press ALT to select the File menu without opening it.
  1164.  
  1165.    2. Press LEFT to select the Help menu.
  1166.  
  1167.    3. Press F1. On-line help displays the information shown in Figure 2.3
  1168.       about the Help menu:
  1169.  
  1170.  
  1171.       ┌──────────────────────── HELP:  Help Menu ─────────────────────┐
  1172.       │ ┌───────────────────────────────────────────────────────────┐ │
  1173.       │ │ Use the Help menu to display:                             │ │
  1174.       │ │     ■ a list of BASIC language keywords                   │ │
  1175.       │ │     ■ a list of general topics about QuickBASIC and the   │ │
  1176.       │ │       BASIC programming language                          │ │
  1177.       │ │     ■ detailed, context-sensitive information on the      │ │
  1178.       │ │       program item shown in a topic cursor                │ │
  1179.       │ │                                                           │ │
  1180.       │ │ To use the Help menu commands now                         │ │
  1181.       │ │     1. Press ESC to return to the Help menu               │ │
  1182.       │ │     2. Use the DIRECTION keys to select (highlight) a     │ │
  1183.       │ │        command                                            │ │
  1184.       │ │     3. Press ENTER to execute the command                 │ │
  1185.       │ └───────────────────────────────────────────────────────────┘ │
  1186.       ├───────────────────────────────────────────────────────────────┤
  1187.       │                          <  OK  >                             │
  1188.       └───────────────────────────────────────────────────────────────┘
  1189.  
  1190.       Figure 2.3  Help Dialog Box for the Help Menu
  1191.  
  1192.    4. Press ENTER when you finish reading the text.
  1193.  
  1194.    5. Press DOWN to open the Help menu.
  1195.  
  1196.    You can get help with each of the items on the Help menu by moving the
  1197.    highlight among the commands with the DIRECTION keys, and pressing F1 for
  1198.    explanations.
  1199.  
  1200.    If there is no on-line help available for the current item, or if the
  1201.    necessary help file is unavailable, QuickBASIC either displays a message,
  1202.    beeps, or both.
  1203.  
  1204.    The Help menu has the following commands:
  1205.  
  1206.    Command                  Action
  1207.    ──────────────────────────────────────────────────────────────────────────
  1208.    Index                    Displays an alphabetical listing of all
  1209.                             QuickBASIC keywords. Place the cursor on a
  1210.                             keyword and press F1 to get help on that keyword.
  1211.  
  1212.    Contents                 Displays a visual outline of the on-line help's
  1213.                             contents. For detailed information on any
  1214.                             category listed, place the cursor on the category
  1215.                             and press F1.
  1216.  
  1217.    Topic                    Displays help for any word at the cursor
  1218.                             position. If there is a word at the cursor
  1219.                             position, it appears in the Help menu following
  1220.                             the Topic command. If there is no word at the
  1221.                             cursor position, the Topic command is inactive.
  1222.  
  1223.    Help on Help             Explains how to use on-line help.
  1224.  
  1225.    ──────────────────────────────────────────────────────────────────────────
  1226.  
  1227.  
  1228.  Choosing Commands
  1229.  
  1230.    To "choose" (execute) a command, select the command by pressing the UP or
  1231.    DOWN key, then press ENTER or the high-intensity letter in the command
  1232.    name. (If a command has no high-intensity letter, it is not currently
  1233.    available for you to use.)
  1234.  
  1235.    If a command is followed by three dots (...), a dialog box (description to
  1236.    follow) appears when you choose the command. Commands not followed by dots
  1237.    execute immediately when you choose them.
  1238.  
  1239.    To learn more about a command before choosing it, press F1 for on-line
  1240.    help. After you read the help information, press ESC to clear help, then
  1241.    press ENTER if you want to choose the command. Try the following steps:
  1242.  
  1243.    1. Press ALT, then press O to select the Options menu.
  1244.  
  1245.       This key combination opens the Options menu. In this manual,
  1246.       combinations of keys are written as key names connected with a plus
  1247.       sign. The sequence above is usually shown as ALT+O.
  1248.  
  1249.    2. Press DOWN until Full Menus is highlighted.
  1250.  
  1251.    3. Press F1 to display on-line help while Full Menus is selected.
  1252.  
  1253.    4. Press ESC to clear on-line help.
  1254.  
  1255.    5. Press ENTER to turn off Full Menus if the bullet (■) is present. Press
  1256.       ESC to close the Options menu without executing any of its commands if
  1257.       Full Menus does not have a bullet.
  1258.  
  1259.       The Full Menus command is a "toggle." If it is on (that is, if it has a
  1260.       bullet), then choosing it turns it off. If it is off (no bullet),
  1261.       choosing it turns it on.
  1262.  
  1263.    6. Press ALT+O to open the Options menu again. Make sure there is no
  1264.       bullet beside Full Menus, then press ESC to close the menu.
  1265.  
  1266.    You only need to use DIRECTION keys when you want help with a command. If
  1267.    you don't need help, just choose commands by pressing the letter
  1268.    corresponding to the high-intensity letter in the command name.
  1269.  
  1270.  
  1271.  Using Dialog Boxes
  1272.  
  1273.    A "dialog box" appears when you choose any menu command followed by three
  1274.    dots (...). QuickBASIC uses dialog boxes to prompt you for information it
  1275.    needs before executing a command. Dialog boxes also appear when you
  1276.  
  1277.    ■ Enter a line of code containing a syntax error
  1278.  
  1279.    ■ Run a program that contains an error
  1280.  
  1281.    ■ Choose the Help command button in a dialog box
  1282.  
  1283.    ■ Request help for a menu or menu command
  1284.  
  1285.    ■ Try to end a session without saving your work
  1286.  
  1287.  Anatomy of a Dialog Box
  1288.  
  1289.    Dialog boxes include several devices you can use to give QuickBASIC
  1290.    information (see Figure 2.4).
  1291.  
  1292.  
  1293.                      ┌─Text box                ┌─List boxes
  1294.                      │                         │
  1295.                      │                         │
  1296.                      │                         │
  1297.      ┌───────────────┼────── Open Program ─────┼───────────────────┐
  1298.      │              ┌┴─────────────────────────┼─────────────────┐ │
  1299.      │   File Name: │*.bas                     │                 │ │
  1300.      │              └──────────────────────────┼─────────────────┘ │
  1301.      │                                         │                   │
  1302.      │   C:\QB4.5\DEMO                         │                   │
  1303.      │                  Files               ┌──┴──┐Dirs/Drives     │
  1304.      │  ┌────────────────────────────────────┐   ┌───────────────┐ │
  1305.      │  │ATEST.BAS      REMLINE.BAS          │   │┌──┐            │
  1306.      │  │BL.BAS         SORTDEMO.BAS         │   │ ∙∙            ░ │
  1307.      │  │DEMO1.BAS      TEST.BAS             │   │SOURCE         ░ │
  1308.      │  │DEMO2.BAS      TORUS.BAS            │   │[-A-]          ░ │
  1309.      │  │DEMO3.BAS      VARHELP.BAS          │   │[-B-]          ░ │
  1310.      │  │DEMO4.BAS      VARHELPZ.BAS         │   │[-C-]          ░ │
  1311.      │  │HISTOGRM.BAS                        │   │               ░ │
  1312.      │  │QBFORMAT.BAS                        │   │               ░ │
  1313.      │  │QCARDS.BAS                          │   │                │
  1314.      │  └░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░┘   └───────────────┘ │
  1315.      ├─────────────────────────────────────────────────────────────┤
  1316.      │       <  OK  >         <  Cancel  >         <  Help  >      │
  1317.      └──────────┼───────────────────┼───────────────────┼──────────┘
  1318.                 └────────┬──────────┴───────────────────┘
  1319.                          └Command buttons
  1320.  
  1321.    Figure 2.4  Open Program Dialog Box
  1322.  
  1323.    The following list explains how to use these devices:
  1324.  
  1325.    Device                   Description
  1326.    ──────────────────────────────────────────────────────────────────────────
  1327.    Text box                 Type text, such as a file name, here
  1328.  
  1329.    List box                 Select one item from a group of listed items
  1330.  
  1331.    Command button           Use to confirm entries, get help, or escape from
  1332.                             the dialog box
  1333.    ──────────────────────────────────────────────────────────────────────────
  1334.  
  1335.  Displaying a Dialog Box
  1336.  
  1337.    When you first open a dialog box, it contains "default" settings──the
  1338.    settings people use most often. After that, when you display a dialog box,
  1339.    it reflects the choices you made the last time the box was displayed. The
  1340.    angle brackets on the default command button appear in high intensity.
  1341.    When you press ENTER, the default command button is chosen. You can use
  1342.    ALT key combinations or TAB to move around in a dialog box.
  1343.  
  1344.    Follow these steps to open and examine the File menu's Open Program dialog
  1345.    box:
  1346.  
  1347.    1. Press ESC to close the Options menu if it is still open.
  1348.  
  1349.    2. Press ALT+F, then press O to choose the File menu's Open Program
  1350.       command.
  1351.  
  1352.       The Open Program dialog box (shown in Figure 2.4) appears. It lets you
  1353.       load programs from disk files into the View window.
  1354.  
  1355.    3. Press F1 to choose the Help command button.
  1356.  
  1357.       A help dialog box opens on top of the Open Program dialog box. You can
  1358.       use DIRECTION keys to move through the help text.
  1359.  
  1360.    4. Press ESC to clear the help dialog box and return the cursor to the
  1361.       Open Program dialog box.
  1362.  
  1363.    5. Press ALT to turn on the high-intensity letters you can use in
  1364.       combination with the ALT key.
  1365.  
  1366.    6. Press TAB to move the cursor into the Files list box.
  1367.  
  1368.       If there are numerous entries in the list box, you can move among them
  1369.       either by pressing DIRECTION keys or the initial letter of the item you
  1370.       wish to select.
  1371.  
  1372.    7. Press TAB or ALT+D to move the cursor to the Dirs/Drives list box.
  1373.  
  1374.    8. Press ESC to close the dialog box without opening a program.
  1375.  
  1376.  Other Dialog-Box Features
  1377.  
  1378.    Other dialog-box features include option buttons and check boxes. You'll
  1379.    use these features in the Options menu's Display dialog box (see Figure
  1380.    2.5) to change options──such as screen colors, scroll bars, and the
  1381.    distance between tab stops──chosen when you installed QuickBASIC.
  1382.  
  1383.  
  1384.    ┌──Option buttons.
  1385.    │  Move between them                             ┌List boxes.
  1386.    │  with UP or DOWN key.                          │Select one item.
  1387.    │                                                │
  1388.    │ ┌──────────────────────── Display ─────────────┼────────────────┐
  1389.    │ │ ┌─────────────────────── Colors ─────────────├──────────────┐ │
  1390.    │ │ │                                Foreground  │ Background   │ │
  1391.    │ │ │                                         ┌──┴──┐           │ │
  1392.    │ │ │ ┌                              ┌─────────┐   ┌─────────┐  │ │
  1393.    │ │ │ │ (∙) 1.  Normal Text          │ Black      │ Black     │ │
  1394.    │ │ │ │                              │ White   ░   │ White   ░  │ │
  1395.    └─┼─┼─┤ ( ) 2.  Current Statement    │ Gray    ░   │ Gray    ░  │ │
  1396.      │ │ │                              │ BrWhite ░   │ BrWhite ░  │ │
  1397.      │ │ │ ( ) 3.  Breakpoint Lines     │         ░   │         ░  │ │
  1398.      │ │ └                              │            │           │ │
  1399.      │ │                                └─────────┘   └─────────┘  │ │
  1400.      │ │                                                           │ │
  1401.      │ │                                                           │ │
  1402.      │ └───────────────────────────────────────────────────────────┘ │
  1403.      │                                                               │
  1404.      │ ┌────────────────── Display Options ────────────────────────┐ │
  1405.    ┌─┼─┼──[X] Scroll Bars                         Tab Stops: 8     │ │
  1406.    │ │ └───────────────────────────────────────────────────────────┘ │
  1407.    │ ├───────────────────────────────────────────────────────────────┤
  1408.    │ │       <  OK  >         <  Cancel  >         <  Help  >        │
  1409.    │ └──────────┼──────────────────┼─────────────────────┼───────────┘
  1410.    │            └───────────┬──────┴─────────────────────┘
  1411.    │                        └─Command buttons.
  1412.    └─Check box. Press         Choose to confirm settings,
  1413.      SPACEBAR to set.         get help, or escape.
  1414.  
  1415.    Figure 2.5  Display Dialog Box
  1416.  
  1417.    Option buttons are turned on if a bullet (■) appears within the
  1418.    parentheses. Only one option in each group of option buttons can be turned
  1419.    on at a time. An X within the brackets indicates that a check box is
  1420.    turned on. You can turn on as many check boxes as you like.
  1421.  
  1422.    To set options, do the following:
  1423.  
  1424.    1. Press ALT+O, then press D to choose the Option menu's Display command.
  1425.       The Display dialog box (shown in Figure 2.5) appears.
  1426.  
  1427.    2. Press ALT+T to move the cursor to the Tab Stops text box.
  1428.  
  1429.       Type a new number if you want to change the number of spaces between
  1430.       tab stops while you are editing. For programming, 4 is a good choice.
  1431.  
  1432.    3. Press ALT+S to move the cursor to the Scroll Bars check box. Press
  1433.       SPACEBAR to put an X in an empty check box or remove the X if the box
  1434.       already has one. (Scroll bars, shown on Figure 2.1, are only useful if
  1435.       you have a mouse.)
  1436.  
  1437.    4. Set the three types of foreground and background colors, as follows:
  1438.  
  1439.       a. Press ALT plus the highlighted number (1, 2, or 3) to select the
  1440.          option whose colors you want to change.
  1441.  
  1442.       b. Press TAB to move to the foreground and background test boxes and
  1443.          press UP or DOWN to select the colors.
  1444.  
  1445.       c. Repeat the previous process two steps to change the Current
  1446.          Statement and Breakpoint Lines options.
  1447.  
  1448.    5. Press ENTER to choose the command, confirming any new choices you've
  1449.       just made, or press ESC to return all settings to what they were when
  1450.       the dialog box was first displayed.
  1451.  
  1452.    The Current Statement option determines the attributes of the currently
  1453.    executing line in a running program. The Breakpoint Lines option sets the
  1454.    color for lines at which you set breakpoints. Note that Breakpoint Lines
  1455.    and Current Statement colors show only when you have a program running.
  1456.  
  1457.  
  1458.  Issuing Commands Directly
  1459.  
  1460.    You can use shortcut keys and key combinations to issue commands directly
  1461.    without opening menus to choose items. Shortcut keys are available for
  1462.    many QuickBASIC tasks.
  1463.  
  1464.  Shortcut Keys for Commands
  1465.  
  1466.    If a command has a shortcut key, it is listed beside the command. For
  1467.    example, instead of opening the Edit menu and choosing the Cut, Copy, or
  1468.    Paste commands, you can use SHIFT+DEL, CTRL+INS, and SHIFT+INS instead.
  1469.  
  1470.  Other Key Combinations
  1471.  
  1472.    There are other special keys and key combinations. For example, SHIFT+F1
  1473.    always displays help on help; and F1 displays on-line help for menu names
  1474.    and commands or any keyword or program symbol at the cursor. Other key
  1475.    combinations use function keys, keys on the numeric keypad like INS and
  1476.    DEL, and many combinations of the SHIFT, ALT, or CTRL keys with other
  1477.    keys.
  1478.  
  1479.    For example, you can use the RIGHT and LEFT keys to move the cursor right
  1480.    and left on the screen. To move the cursor to the next word beyond the
  1481.    current cursor position, hold down CTRL and press LEFT or RIGHT.
  1482.  
  1483.    Try this exercise to see how common shortcut keys and key combinations
  1484.    work:
  1485.  
  1486.    1. Press ALT+V to open the View menu.
  1487.  
  1488.       The SUBs command is automatically selected. Note the shortcut key (F2)
  1489.       to the right of the command name.
  1490.  
  1491.    2. Press DOWN to select the Output Screen command. Note that its shortcut
  1492.       key is F4.
  1493.  
  1494.    3. Press F1 to consult on-line help for an explanation of Output Screen
  1495.       (see Figure 2.6).
  1496.  
  1497.  
  1498.       ┌────────────────── HELP:  Output Screen Command ──────────────────┐
  1499.       │ ┌──────────────────────────────────────────────────────────────┐ │
  1500.       │ │ Use the Output Screen command to toggle between the          │ │
  1501.       │ │ QuickBASIC environment screen and the program output         │ │
  1502.       │ │ screen.                                                      │ │
  1503.       │ │                                                              │ │
  1504.       │ │ This enables you to refer to the ouput previously            │ │
  1505.       │ │ generated by your program while you are editing or           │ │
  1506.       │ │ debugging it.                                                │ │
  1507.       │ │                                                              │ │
  1508.       │ │ Press F4 to toggle between screens with one keystroke.       │ │
  1509.       │ └──────────────────────────────────────────────────────────────┘ │
  1510.       ├──────────────────────────────────────────────────────────────────┤
  1511.       │                             <  OK  >                             │
  1512.       └──────────────────────────────────────────────────────────────────┘
  1513.  
  1514.       Figure 2.6  Help on Output Screen Command
  1515.  
  1516.    4. Press ENTER to close the help screen. ENTER is the shortcut key for the
  1517.       default (or currently selected) command button.
  1518.  
  1519.    5. Press ESC to close the View menu.
  1520.  
  1521.  
  1522.  Exiting from QuickBASIC
  1523.  
  1524.    When you end a session, QuickBASIC checks to see if you have any unsaved
  1525.    work in progress. If you do, a dialog box asks if you want to save your
  1526.    work. Because you haven't entered any text in this session, press N if
  1527.    this dialog box appears when you do the following:
  1528.  
  1529.      Press ALT+F, then press X to choose the File menu's Exit command to
  1530.       return to DOS.
  1531.  
  1532.    If you made and confirmed changes in the Displays dialog box, they are
  1533.    saved in a file called QB.INI when you exit. They become the defaults the
  1534.    next time you start QuickBASIC.
  1535.  
  1536.  
  1537.  For More Information
  1538.  
  1539.    For more information on the topics covered in this chapter, see the
  1540.    following:
  1541.  
  1542.    Where to Look                        What You'll Find
  1543.    ──────────────────────────────────────────────────────────────────────────
  1544.    Section 10.1.1, "The QB Command,"   Explanations of QuickBASIC's
  1545.    and 10.1.2, "The /NOHI Option"      invocation options
  1546.  
  1547.    Section 10.8, "Using On-Line Help," Complete description of on-line help
  1548.    and Chapter 21, "The Help Menu"
  1549.  
  1550.    Section 10.2, "Opening Menus and    More information on menus and dialog
  1551.    Choosing Commands," and 10.3,       boxes
  1552.    "Using Dialog Boxes"
  1553.  
  1554.    Section 10.2.2, "Using Shortcut     A listing of the common shortcut keys
  1555.    Keys"
  1556.  
  1557.    Section 12.7, "Summary of Editing   A complete list of key combinations
  1558.    Commands"                            used for editing
  1559.    ──────────────────────────────────────────────────────────────────────────
  1560.  
  1561.  
  1562.  
  1563.  ────────────────────────────────────────────────────────────────────────────
  1564.  Chapter 3  QuickBASIC's Windows
  1565.  
  1566.    In this chapter you will learn how to use Microsoft QuickBASIC's windows
  1567.    as you write a short program. You'll learn how to
  1568.  
  1569.    ■ Open an existing program and move the cursor
  1570.  
  1571.    ■ Activate, move between, and change the window size
  1572.  
  1573.    ■ Execute BASIC statements from the Immediate window
  1574.  
  1575.    ■ Monitor values of variables with the Watch window
  1576.  
  1577.    ■ Use the Help window
  1578.  
  1579.    ■ Save programs as files on disk
  1580.  
  1581.    This chapter takes about one to one and one-half hours to complete.
  1582.  
  1583.  
  1584.  Windows Available with Easy Menus
  1585.  
  1586.    QuickBASIC is called a "window-oriented" environment because the screen is
  1587.    divided into separate areas in which you can perform different tasks. Some
  1588.    windows, such as the View window and the Help window, display material
  1589.    loaded from disk files. Other windows, such as the Watch window, display
  1590.    information QuickBASIC has about the current program. With Easy Menus, the
  1591.    windows shown in Figure 3.1 are available.
  1592.  
  1593.  
  1594.    Watch window                                                Help window
  1595.     │                                                              │
  1596.     │ File  Edit  View  Search  Run  Debug  Options                │    Help
  1597.     └Untitled X = 10:  0                                           │
  1598.    ┌────────────────────── HELP: CLS Statement QuickSCREEN ────────┼─────┤├──
  1599.    │  QuickSCREEN     Details     Example     Contents     Index
  1600.    │─────────────────────────────────────────────────────────────────────────
  1601.    │CLS - a device I/O statement that clears the display screen
  1602.    │
  1603.    │Syntax
  1604.    │  CLS [{0|1|2}]
  1605.    │
  1606.    │  = If all arguments are omitted, either the graphics viewport or the
  1607.    │    text viewport are cleared, depending upon previous uses of the VIEW
  1608.    │    statement.
  1609.    │  = 0 clears the screen of all text and graphics.
  1610.    │  = 1 clears only the graphics viewport, if it is active.
  1611.    │  = 2 clears only the text viewport, leaving the bottom screen line
  1612.    │    unchanged.
  1613.    ├──────────────────────────────── Untitled ───────────────────────────┤├──
  1614.    │CLS
  1615.    │                                                               │
  1616.    │                                                               │
  1617.    │                                                               │
  1618.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│▒▒▒▒▒▒▒▒▒
  1619.    ├─────────────────────────────── Immediate ─────────────────────│──────────
  1620.    │                                                               │
  1621.    │                                                               │
  1622.     <Shift+F1=Help> <F6=Window> <F2=Subs> <F5=Run> <F8=Step>       │ 00001:003
  1623.             │                                                      │
  1624.    Immediate window                                            View window
  1625.  
  1626.    Figure 3.1  Windows Available with Easy Menus
  1627.  
  1628.    Window                   Description
  1629.    ──────────────────────────────────────────────────────────────────────────
  1630.    View                     The window in which you do most of your
  1631.                             programming. When you start QuickBASIC the View
  1632.                             window is the "active window," the one containing
  1633.                             the editing cursor. When you load a disk file,
  1634.                             its contents appear in the View window.
  1635.  
  1636.    Immediate                The window at the bottom of the screen. In it you
  1637.                             can use single lines of BASIC code to test
  1638.                             programming ideas and perform miscellaneous
  1639.                             calculations. You can type in the Immediate
  1640.                             window, but you cannot load disk files into it.
  1641.  
  1642.    Help                     A window that opens at the top of the screen when
  1643.                             you press F1 or SHIFT+F1. Information about
  1644.                             QuickBASIC keywords, symbols you define in your
  1645.                             program, and using help is displayed in the Help
  1646.                             window.
  1647.  
  1648.    Watch                    A window that opens at the top of the screen when
  1649.                             you choose certain commands from the Debug menu.
  1650.    ──────────────────────────────────────────────────────────────────────────
  1651.  
  1652.    You can have several windows open at a time, but only one can be active at
  1653.    a time. By opening multiple windows, you can view different types of
  1654.    information simultaneously. For example, you can have program code in the
  1655.    View window, then display on-line help for the statement you want to use.
  1656.  
  1657.  
  1658.  The View Window
  1659.  
  1660.    The View window is where you do most of your programming. This section
  1661.    explains how to load an existing program from a disk file into the View
  1662.    window and move the cursor around in its text. Then you'll clear that
  1663.    program and write and run some lines of your own code.
  1664.  
  1665.  Loading Programs in the View Window
  1666.  
  1667.    When you load a file from a disk, its text appears in the View window. To
  1668.    load a program
  1669.  
  1670.    1. Start QuickBASIC using the QB command you learned in Chapter 2.
  1671.  
  1672.    2. Press ESC to clear the Welcome dialog box.
  1673.  
  1674.    3. Press ALT+F, then press O to choose the File menu's Open Program
  1675.       command.
  1676.  
  1677.       QuickBASIC displays a dialog box like the one in Figure 3.2.
  1678.  
  1679.  
  1680.         Path-specification line                     Symbol         Name
  1681.         gives path to files listed                  for next       of next
  1682.       ┌─in Files list box.                          highest        lowest
  1683.       │                                           ┌─directory    ┌─directory
  1684.       │                 ┌─Text box                │              │
  1685.       │                 │           List boxes─┐  │              │
  1686.       │                 │                      │  │              │
  1687.       │                 │                      │  │              │
  1688.       │ ┌───────────────┼────── Open Program ──┼──┼──────────────┼────┐
  1689.       │ │              ┌┴──────────────────────┼──┼──────────────┼──┐ │
  1690.       │ │   File Name: │                       │  │              │  │ │
  1691.       │ │              └───────────────────────┼──┼──────────────┼──┘ │
  1692.       │ │                                      │  │              │    │
  1693.       └─┼───C:\QB4.5\DEMO                      │  │              │    │
  1694.         │                                      │  │  Dirs/Drives │    │
  1695.         │  ┌───────────────────────────────────┴┐ │ ┌────────────┼──┐ │
  1696.         │  │ATEST.BAS      REMLINE.BAS  ─┐      │ │ │┌──┐        │   │
  1697.         │  │BL.BAS         SORTDEMO.BAS  │      │ └─┼ ∙∙         │  ░ │
  1698.         │  │DEMO1.BAS      TEST.BAS      │      │   │SOURCE ─────┘  ░ │
  1699.         │  │DEMO2.BAS      TORUS.BAS     │      │   │[-A-]─┐        ░ │
  1700.         │  │DEMO3.BAS      VARHELP.BAS   ├────┐ │   │[-B-] ├─────┐  ░ │
  1701.         │  │DEMO4.BAS      VARHELPZ.BAS  │    │ │   │[-C-]─┘     │  ░ │
  1702.         │  │HISTOGRM.BAS                 │    │ │   │            │  ░ │
  1703.         │  │QBFORMAT.BAS                 │    │ │   │            │  ░ │
  1704.         │  │QCARDS.BAS                   ┘    │ │   │            │   │
  1705.         │  └░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│┘   └────────────┼──┘ │
  1706.         ├─────────────────────────────────────┼──────────────────┼────┤
  1707.         │       <  OK  >         <  Cancel  > │       <  Help  > │    │
  1708.         └─────────────────────────────────────┼──────────────────┼────┘
  1709.           List box contains file names having ┘  Available drives┘
  1710.                   extension shown in text box
  1711.  
  1712.       Figure 3.2  Open Program Dialog Box
  1713.  
  1714.       The cursor is in the text box where *.bas is selected. Anything you
  1715.       type while *.bas is selected replaces it. The *.bas in the text box
  1716.       tells QuickBASIC to list all the files having that extension in the
  1717.       Files list box.
  1718.  
  1719.    This dialog box has the following features:
  1720.  
  1721.    Feature                  Function
  1722.    ──────────────────────────────────────────────────────────────────────────
  1723.    Text box                 Box for typing text, such as a file name
  1724.  
  1725.    Files list box           Box that displays files in the directory
  1726.                             specified on the path-specification line
  1727.  
  1728.    Dirs/Drives list box     Box that shows the directories above and below
  1729.                             the directory specified on the path-specification
  1730.                             line and the drives available on your system
  1731.    ──────────────────────────────────────────────────────────────────────────
  1732.  
  1733.    The files in your list box should include QCARDS.BAS. To open it, type its
  1734.    name in the text box, or use the list box to select it, as described here:
  1735.  
  1736.    1. Press TAB to move the cursor into the Files list box.
  1737.  
  1738.    2. Press DIRECTION keys until the name of the program you want is
  1739.       selected. (Press SPACEBAR if the program you want is the first entry. )
  1740.  
  1741.    3. Select QCARDS.BAS.
  1742.  
  1743.       The name QCARDS.BAS replaces *.bas in the text box.
  1744.  
  1745.    4. Press ENTER to load QCARDS.BAS in the View window.
  1746.  
  1747.       QCARDS is large (almost 40K), so it may take a few moments to load.
  1748.       When it is loaded, the name QCARDS.BAS appears in the View window's
  1749.       title bar.
  1750.  
  1751.  Moving the Cursor
  1752.  
  1753.    You can use the DIRECTION keys on the numeric keypad (the LEFT, RIGHT, UP,
  1754.    and DOWN arrow keys as well as HOME, END, PGUP, and PGDN) to move the
  1755.    cursor in a window. The DIRECTION keys move the cursor a single row or
  1756.    column at a time. HOME and END move the cursor to the first or last column
  1757.    of the current line. However, you can combine the CTRL key with DIRECTION
  1758.    keys to move the cursor in greater increments, as follows:
  1759.  
  1760.    Key Combination          Cursor Movement
  1761.    ──────────────────────────────────────────────────────────────────────────
  1762.    CTRL+RIGHT               Right one word
  1763.  
  1764.    CTRL+LEFT                Left one word
  1765.  
  1766.    CTRL+HOME                First line of current window
  1767.  
  1768.    CTRL+END                 Last line of current window
  1769.    ──────────────────────────────────────────────────────────────────────────
  1770.  
  1771.  Scrolling Text
  1772.  
  1773.    A window can contain far more text than is visible within its on-screen
  1774.    boundaries. "Scrolling" describes the movement of text into and out of the
  1775.    bounded screen area. You can scroll text using the following keys and
  1776.    combinations:
  1777.  
  1778.    Key Combination          Scrolling Action
  1779.    ──────────────────────────────────────────────────────────────────────────
  1780.    PGUP                     Up by one whole screen
  1781.  
  1782.    PGDN                     Down by one whole screen
  1783.  
  1784.    CTRL+PGDN                Right by one whole screen
  1785.  
  1786.    CTRL+PGUP                Left by one whole screen
  1787.    ──────────────────────────────────────────────────────────────────────────
  1788.  
  1789.    ──────────────────────────────────────────────────────────────────────────
  1790.    NOTE
  1791.      The CTRL+PGDN combination can be disorienting if you don't have text
  1792.      between columns 79-159. To confirm your place in a file, check the row
  1793.      and column counters in the lower right corner of the reference bar. You
  1794.      can press HOME to move the cursor to the first column of the current
  1795.      line.
  1796.    ──────────────────────────────────────────────────────────────────────────
  1797.  
  1798.  Starting a New Program
  1799.  
  1800.    When you load an existing program from disk, QuickBASIC clears everything
  1801.    else from memory before loading the program. In this section, you'll clear
  1802.    QCARDS.BAS from QuickBASIC's memory with the New Program command, then
  1803.    you'll type in a simple program. As you type in lines of code, notice that
  1804.    QuickBASIC capitalizes the keywords in the statements when you press
  1805.    ENTER. If you get an error message, press ESC to clear the message, then
  1806.    retype the line at the cursor.
  1807.  
  1808.    Follow these steps to clear QCARDS.BAS, then write and run some code:
  1809.  
  1810.    1. Press ALT+F, then press N to choose the File menu's New Program
  1811.       command.
  1812.  
  1813.    2. Type the following BASIC statements
  1814.  
  1815.       cls
  1816.       print "This is my first QuickBASIC program"
  1817.       print 2 + 2
  1818.  
  1819.    3. Press ALT+R, then press S to choose the Run menu's Start command.
  1820.  
  1821.       If you typed everything correctly, QuickBASIC displays the program's
  1822.       output on the "output screen," which should look like the screen in
  1823.       Figure 3.3.
  1824.  
  1825.  
  1826.         ┌────────────────────────────────────────────────────────┐
  1827.         │This is my first QuickBASIC program                     │
  1828.         │ 4                                                      │
  1829.         │                                                        │
  1830.         │                                                        │
  1831.         │                                                        │
  1832.         │                                                        │
  1833.         │                                                        │
  1834.         │                                                        │
  1835.         │                                                        │
  1836.         │                                                        │
  1837.         │                                                        │
  1838.         │                                                        │
  1839.       ┌─┤Press any key to continue                               │
  1840.       │ └────────────────────────────────────────────────────────┘
  1841.       └─Press a key to return to QuickBASIC environment.
  1842.  
  1843.       Figure 3.3  Output Screen for Code Lines
  1844.  
  1845.       In this program, CLS clears the screen, then the PRINT statement
  1846.       displays the quoted text in the upper left corner of the screen.
  1847.       Because PRINT can display the results of numeric expressions, the sum
  1848.       of the expression 2+2 appears on the next line.
  1849.  
  1850.    4. Press a key to return to QuickBASIC's View window.
  1851.  
  1852.    5. Press ALT+V, then press U to choose the View menu's Output Screen
  1853.       command to take another look at your program's results.
  1854.  
  1855.    6. Press a key to return to QuickBASIC's View window.
  1856.  
  1857.    ──────────────────────────────────────────────────────────────────────────
  1858.    NOTE
  1859.      You can get help for any keywords you don't understand by placing the
  1860.      cursor on the keyword, then pressing F1.
  1861.    ──────────────────────────────────────────────────────────────────────────
  1862.  
  1863.  Changing Window Sizes
  1864.  
  1865.    You can easily increase or decrease the size of the windows on your
  1866.    screen. To increase the size of the active window, press ALT+PLUS once for
  1867.    each line you want to add. To reduce the size by one line, press
  1868.    ALT+MINUS. (Use the PLUS and MINUS keys on the numeric keypad.)
  1869.  
  1870.    To temporarily expand the active window to full screen, press CTRL+F10.
  1871.    You can restore the windows to their previous sizes by pressing this
  1872.    toggle again. The following steps illustrate this and prepare the windows
  1873.    for the exercise in the next section:
  1874.  
  1875.    1. Press ALT+PLUS twice while the cursor is in the View window.
  1876.  
  1877.       This adds lines to the View window and compresses the Immediate window
  1878.       beneath it.
  1879.  
  1880.    2. Press ALT+MINUS seven times to reduce the size of the View window.
  1881.  
  1882.       This decreases the number of lines in the View window while increasing
  1883.       the size of the Immediate window.
  1884.  
  1885.    3. Press CTRL+F10 to expand the size of the current window temporarily to
  1886.       full-screen status.
  1887.  
  1888.    4. Press CTRL+F10 again to restore the screen to its previous proportions.
  1889.  
  1890.  
  1891.  QuickBASIC's Other Windows
  1892.  
  1893.    When you start QuickBASIC and clear the opening dialog box, the View
  1894.    window contains the cursor, so it is the active window. Only one window
  1895.    can be active at a time. However, other windows are available. Note that
  1896.    the title bar of the active window is highlighted.
  1897.  
  1898.  Moving between Windows
  1899.  
  1900.    To move the cursor down one window, press the F6 key. To move the cursor
  1901.    up one window, press SHIFT+F6. If you have used CTRL+F10 to expand the
  1902.    current window, F6 and SHIFT+F6 still make the next and previous windows
  1903.    active.
  1904.  
  1905.  Executing Code in the Immediate Window
  1906.  
  1907.    The Immediate window at the bottom of the screen can be used as a utility
  1908.    window as you program in the View window. For example, if you want to
  1909.    clear the output screen, you can execute the CLS statement from the
  1910.    Immediate window. You can also use the Immediate window for doing
  1911.    calculations, or experimenting with programming ideas and previewing the
  1912.    results. When you exit from QuickBASIC, text in the Immediate window is
  1913.    lost.
  1914.  
  1915.    When you run lines of code in the View window, they are executed
  1916.    sequentially. In the Immediate window, a single line of code is executed
  1917.    whenever you put the cursor anywhere on that line, then press ENTER.You
  1918.    can type in either uppercase or lowercase in the Immediate window. Note
  1919.    that QuickBASIC doesn't capitalize keywords in the Immediate window as it
  1920.    does in the View window.
  1921.  
  1922.    Try the following procedure to execute lines of code in the Immediate
  1923.    window:
  1924.  
  1925.    1. Press F6 to place the cursor in the Immediate window.
  1926.  
  1927.    2. Type the following line:
  1928.  
  1929.       cls : print "This line comes from the Immediate window"
  1930.  
  1931.       This code consists of two BASIC statements separated by a colon.
  1932.       Separating statements with a colon allows you to put more than one
  1933.       statement on a line.
  1934.  
  1935.    3. Press ENTER to execute the code on this line.
  1936.  
  1937.       QuickBASIC displays the output screen.
  1938.  
  1939.    4. Press a key to return to the QuickBASIC environment. The cursor is
  1940.       placed on the next blank line in the Immediate window.
  1941.  
  1942.    5. Type the following line, exactly as shown:
  1943.  
  1944.       CurrentTime$ = ""
  1945.  
  1946.       This defines a variable named CurrentTime$. The $ tells QuickBASIC it
  1947.       is a "string" variable (one consisting of a series of characters). The
  1948.       quotation marks have no space between them, so the string has a length
  1949.       of zero.
  1950.  
  1951.    6. Press ENTER to execute this statement and assign the zero-length string
  1952.       to CurrentTime$.
  1953.  
  1954.    Next, you'll continue working in the Immediate window and use the BASIC
  1955.    TIME$ function to assign a string representing the current time to the
  1956.    variable CurrentTime$:
  1957.  
  1958.    1. Type the following line (exactly as shown) on the next line in the
  1959.       Immediate window:
  1960.  
  1961.       CurrentTime$ = time$
  1962.  
  1963.    2. Press ENTER to execute the assignment statement you just typed.
  1964.  
  1965.    3. Type the following line in the Immediate window, exactly as shown:
  1966.  
  1967.       print CurrentTime$
  1968.  
  1969.       Figure 3.4 shows how the Immediate window should now look:
  1970.  
  1971.  
  1972.          File  Edit  View  Search  Run  Debug  Options                     Hel
  1973.       ┌──────────────────────────────── Untitled ───────────────────────────┤
  1974.       │CLS
  1975.       │PRINT "This is my first QuickBASIC program"
  1976.       │PRINT 2 + 2
  1977.       │
  1978.       │
  1979.       │
  1980.       │
  1981.       │
  1982.       │
  1983.       │
  1984.       │
  1985.       │
  1986.       │
  1987.       │
  1988.       │
  1989.       │
  1990.       ├─────────────────────────────── Immediate ─────────────────────────────
  1991.       │cls : print "This line comes from the Immediate window"
  1992.       │CurrentTime$ = ""
  1993.       │CurrentTime$ = time$
  1994.       │print CurrentTime$
  1995.       │
  1996.        <Shift+F1=Help> <F6=Window> <Enter=Execute Line>              CN 00004:
  1997.  
  1998.       Figure 3.4  Immediate Window Showing Lines Just Entered
  1999.  
  2000.    4. Press ENTER to display the value of CurrentTime$.
  2001.  
  2002.       The value of CurrentTime$ is displayed beneath the first line on the
  2003.       output screen.
  2004.  
  2005.    5. Press a key to return to the environment.
  2006.  
  2007.       You can write up to 10 lines of statements in the Immediate window. If
  2008.       you type an eleventh line, the first line you typed is lost; if you
  2009.       type a twelfth, the second line you typed is lost, and so on. Section
  2010.       10.5 illustrates other ways you can use the Immediate window.
  2011.  
  2012.  Monitoring Variables with the Watch Window
  2013.  
  2014.    When a program doesn't behave the way you expect, it is often because a
  2015.    variable is acquiring a value you did not anticipate. The Watch window
  2016.    lets you monitor the values of expressions while your program is running,
  2017.    so you can be sure their values are within the expected range. Try the
  2018.    following to see how the Watch window works:
  2019.  
  2020.    1. Press F6 to move the cursor to the Immediate window if it is not
  2021.       already there.
  2022.  
  2023.    2. Press ALT+D, then press A to choose the Debug menu's Add Watch command.
  2024.  
  2025.       QuickBASIC displays the Add Watch dialog box.
  2026.  
  2027.    3. Type CurrentTime$, then press ENTER.
  2028.  
  2029.       The Watch window opens at the top of the screen. It contains the name
  2030.       from the View window's title bar, followed by CurrentTime$, the name of
  2031.       the variable you just entered (see Figure 3.5). The cursor returns to
  2032.       the Immediate window.
  2033.  
  2034.  
  2035.       Name from View
  2036.       window's title bar     Variable name                       Watch window
  2037.        │                         │                                    │
  2038.        │ File  Edit  View  Search│ Run  Debug  Options                │    Hel
  2039.        └Untitled CurrentTime$:   │                                    │
  2040.       ┌─────────┴──────┬──────┴──┼───── Untitled ───────────────────────────┤
  2041.       │CLS             └─────────┘
  2042.       │PRINT "This is my first QuickBASIC program"
  2043.       │PRINT 2 + 2
  2044.       │
  2045.       │
  2046.       │
  2047.       │
  2048.       │
  2049.       │
  2050.       │
  2051.       │
  2052.       │
  2053.       ├─────────────────────────────── Immediate ─────────────────────────────
  2054.       │cls : print "This line comes from the Immediate window"
  2055.       │CurrentTime$ = ""
  2056.       │CurrentTime$ = time$
  2057.       │print CurrentTime$
  2058.       │
  2059.        <Shift+F1=Help> <F6=Window> <Enter=Execute Line>              CN 00004:
  2060.  
  2061.       Figure 3.5  Placing Variables in the Watch Window
  2062.  
  2063.    4. Press CTRL+HOME to place the cursor on the first line of the Immediate
  2064.       window, then press ENTER to execute each of the lines in the Immediate
  2065.       window.
  2066.  
  2067.       Look at the Watch window while you press ENTER on each line. As soon as
  2068.       the line CurrentTime$ = time$ is executed, you will notice that the
  2069.       value for CurrentTime$ appears in the Watch window.
  2070.  
  2071.    With the Watch window you can monitor variable values as they change in
  2072.    the running program without having to use PRINT statements to display the
  2073.    value on the output screen.
  2074.  
  2075.  The Help Window
  2076.  
  2077.    Most on-line help appears in the Help window. There are several ways to
  2078.    get help on BASIC keywords, such as PRINT and TIME$, and the QuickBASIC
  2079.    environment. You can use the Help menu or press F1 while an item on screen
  2080.    (or a menu or command) contains the cursor or is highlighted.
  2081.  
  2082.    ──────────────────────────────────────────────────────────────────────────
  2083.    NOTE
  2084.      If you get error messages when you try to access on-line help, check
  2085.      Section 10.8.4, "Help Files," for more information on how to set up
  2086.      help properly.
  2087.    ──────────────────────────────────────────────────────────────────────────
  2088.  
  2089.    Context-Sensitive Help
  2090.  
  2091.    With context-sensitive help, you can get information about BASIC keywords
  2092.    and program symbols. The following steps illustrate the use of
  2093.    context-sensitive help:
  2094.  
  2095.    1. Press ESC to close the Help menu if it is open.
  2096.  
  2097.    2. Use DIRECTION keys to move the cursor anywhere within the word PRINT.
  2098.  
  2099.    3. Press F1.
  2100.  
  2101.       QuickBASIC displays a QuickSCREEN of the PRINT keyword (see Figure
  2102.       3.6).
  2103.  
  2104.  
  2105.          File  Edit  View  Search  Run  Debug  Options                     Hel
  2106.         Untitled CurrentTime$:
  2107.       ┌───────────────────── HELP: PRINT Statement QuickSCREEN ─────────────┤
  2108.       │  QuickSCREEN     Details     Example     Contents     Index
  2109.       │───────────────────────────────────────────────────────────────────────
  2110.       │PRINT - a device I/O statement that outputs data on the screen
  2111.       │
  2112.       │Syntax
  2113.       │  PRINT [expressionlist][{,|;}]
  2114.       │
  2115.       │  = If all arguments are omitted, a blank line is printed.
  2116.       │  = If expressionlist is included, the values of the expressions are
  2117.       │    printed on the screen.
  2118.       │  = The expressions in the list may be numeric or string expressions.
  2119.       │    (String literals must be enclosed in quotation marks.)
  2120.       │  = The optional characters "'" and ";" are details.
  2121.       │
  2122.       │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  2123.       ├─────────────────────────────── Untitled ────────────────────────────┤
  2124.       ├─────────────────────────────── Immediate ─────────────────────────────
  2125.       │cls : print "This line comes from the Immediate window"
  2126.       │CurrentTime$ = ""
  2127.       │CurrentTime$ = time$
  2128.       │print CurrentTime$
  2129.        <Shift+F1=Help> <F6=Window> <Esc=Cancel> <Ctrl+F1=Next> <Alt+F1=Back>
  2130.  
  2131.       Figure 3.6  QuickSCREEN for PRINT Statement
  2132.  
  2133.       The QuickSCREEN briefly describes the statement's action, then gives
  2134.       the syntax and explains each part of it. At the bottom, the QuickSCREEN
  2135.       indicates other uses of the keyword.
  2136.  
  2137.    Hyperlinks
  2138.  
  2139.    At the top of the screen, several bracketed items, called "hyperlinks,"
  2140.    indicate related topics you can investigate. Hyperlinks provide instant
  2141.    connections between related topics. At the bottom of the screen, the other
  2142.    uses of the keyword are also bracketed as hyperlinks. If you want more
  2143.    information on one of them, use the TAB key to move the cursor to the
  2144.    hyperlink, then press F1, as explained here.
  2145.  
  2146.    1. Press F6 until the cursor appears into the Help window.
  2147.  
  2148.    2. Press TAB to move the cursor to the Example hyperlink.
  2149.  
  2150.    3. Press F1 to view the Example screen (see Figure 3.7).
  2151.  
  2152.  
  2153.       Hyperlinks
  2154.       to related topics
  2155.         │
  2156.         │File  Edit  View  Search  Run  Debug  Options                     Hel
  2157.       ┌─┼─────────────── HELP: PRINT Statement Programming Examples ────────┤
  2158.       │ │QuickSCREEN     Details     Example     Contents     Index
  2159.       │─┼──────────────────────┼─────────────┼──────────────┼────────────┼────
  2160.       │ └──────────────────────┴─────────────┴──────────────┴────────────┘
  2161.       │PRINT Statement Programming Examples
  2162.       │
  2163.       │Example 1
  2164.       │
  2165.       │In the following example, the commas in the PRINT statement
  2166.       │print each value at the beginning of the next print zone:
  2167.       │
  2168.       │X=5
  2169.       │PRINT X+5, X-5, X*(-5), X^5
  2170.       │END
  2171.       │
  2172.       │Sample Output
  2173.       │
  2174.       │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  2175.       ├─────────────────────────────── Untitled ────────────────────────────┤
  2176.       ├─────────────────────────────── Immediate ─────────────────────────────
  2177.       │cls : print "This line comes from the Immediate window"
  2178.       │CurrentTime$ = ""
  2179.       │CurrentTime$ = time$
  2180.       │print CurrentTime$
  2181.        <Shift+F1=Help> <F6=Window> <Esc=Cancel> <Ctrl+F1=Next> <Alt+F1=Back>
  2182.  
  2183.       Figure 3.7  Example Screen for PRINT Statement
  2184.  
  2185.       You can scroll within the Help window to examine all the PRINT
  2186.       examples.
  2187.  
  2188.    4. Press ALT+F1 once or twice to return to the screen you linked from.
  2189.  
  2190.    5. Repeat steps 1 and 2 to view the information available through the
  2191.       other bracketed hyperlinks.
  2192.  
  2193.    You can use several successive hyperlinks without returning to the
  2194.    previous screen, QuickBASIC keeps track of the last 20 hyperlinks. You can
  2195.    use ALT+F1 to go back through the sequence of hyperlinks. When you reach
  2196.    the screen from which you started, QuickBASIC beeps if you press ALT+F1.
  2197.    You can press ESC any time to clear the Help window completely, even if
  2198.    you are several levels down in hyperlink screens.
  2199.  
  2200.    For a reminder on which keys or key combinations to use for moving in or
  2201.    among Help screens, choose Contents from the Help menu, then choose the
  2202.    "Help keys" hyperlink. Also, SHIFT+F1 gives a general explanation of help.
  2203.  
  2204.    Even some items that are not bracketed are hyperlinks. Press F1 any time
  2205.    you have a question about anything on the QuickBASIC screen. If QuickBASIC
  2206.    has more information on it, the information appears in the Help window; if
  2207.    no other information is available, QuickBASIC beeps.
  2208.  
  2209.    ──────────────────────────────────────────────────────────────────────────
  2210.    NOTE
  2211.      You cannot edit text in the Help window, but you can edit text in the
  2212.      View window or Immediate window while the Help window is open. In
  2213.      Chapter 8, "Using Example Code from On-Line Help," you'll learn to copy
  2214.      text from the Help window and paste it into your program.
  2215.    ──────────────────────────────────────────────────────────────────────────
  2216.  
  2217.  
  2218.  Exiting from QuickBASIC and Saving Programs
  2219.  
  2220.    The following steps explain how to exit QuickBASIC and return to the DOS
  2221.    command line:
  2222.  
  2223.    1. Press ALT+F, then press X to exit from QuickBASIC.
  2224.  
  2225.       A dialog box appears asking if you want to save the unsaved material in
  2226.       the View window.
  2227.  
  2228.    2. Press ENTER to tell QuickBASIC that you want to save the program in the
  2229.       View window.
  2230.  
  2231.       QuickBASIC displays the Save As dialog box (see Figure 3.8):
  2232.  
  2233.  
  2234.                        ┌─Type your program name here
  2235.                        │
  2236.       ┌────────────────┼───── Save As ──────────────────┐
  2237.       │                │                                │
  2238.       │             ┌──┴───────────────────────────────┐│
  2239.       │ File Name:  │                                  ││
  2240.       │             └──────────────────────────────────┘│
  2241.       │ C:\QB4.5\DEMO                                   │
  2242.       │                                                 │
  2243.       │   Dirs/Drives                                   │
  2244.       │ ┌──────────────┐      ┌─────── Format ────────┐ │
  2245.       │ │..                  │ (∙) QuickBASIC -      │ │
  2246.       │ │SOURCE        ░      │      Fast Load and    │ │
  2247.       │ │[-A-]         ░      │      Save             │ │
  2248.       │ │[-B-]         ░      │                       │ │
  2249.       │ │[-C-]         ░      │ ( ) Text -            │ │
  2250.       │ │[-U-]         ░      │      Readable by      │ │
  2251.       │ │[-Z-]               │      Other Programs   │ │
  2252.       │ └──────────────┘      └───────────────────────┘ │
  2253.       ├─────────────────────────────────────────────────┤
  2254.       │      < OK >            < Cancel >     < Help >  │
  2255.       └─────────────────────────────────────────────────┘
  2256.  
  2257.       Figure 3.8  Save As Dialog Box
  2258.  
  2259.    3. Type program1 in the text box.
  2260.  
  2261.    4. Press ENTER to save the lines in the View window on disk with the file
  2262.       name PROGRAM1.BAS.
  2263.  
  2264.  
  2265.  For More Information
  2266.  
  2267.    For more information on the topics covered in this chapter, see the
  2268.    following:
  2269.  
  2270.    Where to Look                        What You'll Find
  2271.    ──────────────────────────────────────────────────────────────────────────
  2272.    Chapter 9, "Debugging While You     Debugging techniques and using the
  2273.    Program," and Chapter 17,           Watch window
  2274.    "Debugging Concepts and Techniques"
  2275.  
  2276.    Section 10.5, "Using the Immediate  Ways to use the Immediate window
  2277.    Window"
  2278.  
  2279.    Chapter 11, "The File Menu"         Opening, clearing, and saving files
  2280.                                         in QuickBASIC
  2281.    ──────────────────────────────────────────────────────────────────────────
  2282.  
  2283.  
  2284.  
  2285.  ────────────────────────────────────────────────────────────────────────────
  2286.  Chapter 4  Interlude: BASIC for Beginners
  2287.  
  2288.    This chapter introduces the general principles of programming in BASIC.
  2289.    The focus is on the fundamentals, so you can start programming quickly.
  2290.  
  2291.    If you have never programmed before, you should read this chapter
  2292.    carefully. When you finish this chapter, you will be able to write simple
  2293.    BASIC programs. You may want to read some intermediate-level books on
  2294.    BASIC before tackling advanced programming techniques in the following
  2295.    chapters.
  2296.  
  2297.    If you already have programming experience with BASIC, you may want to
  2298.    skim this chapter to get a general idea of the differences between
  2299.    Microsoft BASIC and the BASIC dialect you know.
  2300.  
  2301.    Many brief programming examples are given to show how each element of
  2302.    BASIC works. The quickest way to learn BASIC is to enter and run these
  2303.    examples as you read. You can enter multi-line examples in the View
  2304.    window. Or you can enter single-line examples in QuickBASIC's Immediate
  2305.    window, then press ENTER to see the resulting output. Study each example
  2306.    to understand why it works the way it does. Be sure you grasp the material
  2307.    in one section before going on to the next.
  2308.  
  2309.    When you have completed this chapter, you will understand how to
  2310.  
  2311.    ■ Display words and numbers on the screen
  2312.  
  2313.    ■ Define and use variables
  2314.  
  2315.    ■ Perform calculations and use BASIC's math functions
  2316.  
  2317.    ■ Use arrays of variables
  2318.  
  2319.    ■ Execute sections of your program selectively
  2320.  
  2321.    ■ Repeat a group of instructions a specific number of times or until a
  2322.      condition is met
  2323.  
  2324.  
  2325.  What is a Program?
  2326.  
  2327.    A "program" is a sequence of instructions to the computer, in a language
  2328.    both you and the computer understand. Each instruction is called a
  2329.    "statement" and usually takes up one line in the program.
  2330.  
  2331.    The goal of any program is to perform some useful job, such as word
  2332.    processing, bookkeeping, or playing a game. Programming is the process of
  2333.    deciding what you want the program to do. Then you select and arrange
  2334.    language statements to accomplish the individual tasks needed to reach the
  2335.    overall goal. This process is part science, part art. The science comes
  2336.    from books; the art is learned by writing your own programs and analyzing
  2337.    programs written by others.
  2338.  
  2339.    Many BASIC statements have additional features that are not described in
  2340.    this chapter. If you want more information about a particular statement or
  2341.    language feature, please refer to Chapter 8, "Statement and Function
  2342.    Summary," in Programming in BASIC or consult QuickBASIC's on-line help.
  2343.  
  2344.  
  2345.  Comments
  2346.  
  2347.    Comments are an important part of programming. They explain the program to
  2348.    others, and remind you why you wrote it the way you did. Comments begin
  2349.    with an apostrophe, and can extend to the end of the line, as follows:
  2350.  
  2351.    ' This is a comment.
  2352.  
  2353.    CLS                   ' The CLS statement clears the screen.
  2354.  
  2355.    The apostrophe tells QuickBASIC that everything between the apostrophe and
  2356.    the end of the line is a comment.
  2357.  
  2358.  
  2359.  Displaying Words and Numbers on the Screen
  2360.  
  2361.    You are probably familiar with application software such as Lotus(R)
  2362.    1-2-3(R) or Microsoft Word. These and most other programs communicate with
  2363.    the user by displaying words, numbers, and data on the screen.
  2364.  
  2365.    The PRINT statement is BASIC's command for writing on the screen. Two of
  2366.    the things PRINT can display are strings and numbers.
  2367.  
  2368.    A "string" is any group of characters (letters, numbers, punctuation
  2369.    marks) enclosed in quotes. The following example program shows how the
  2370.    PRINT statement displays a string:
  2371.  
  2372.    1. Start QuickBASIC (if it is not already started) by typing qb and
  2373.       pressing ENTER.
  2374.  
  2375.    2. Type the following line in the Immediate window, then press ENTER:
  2376.  
  2377.       PRINT "Hello, world"
  2378.  
  2379.       The output should appear as follows:
  2380.  
  2381.       Hello, world
  2382.  
  2383.       The quotes that surround a string are not part of the string, so they
  2384.       do not appear in the display.
  2385.  
  2386.    3. Type CLS in the Immediate window and press ENTER to clear the output
  2387.       screen.
  2388.  
  2389.    ──────────────────────────────────────────────────────────────────────────
  2390.    NOTE
  2391.      BASIC is not case sensitive; you don't have to enter the examples with
  2392.      the cases as shown. QuickBASIC automatically capitalizes words that are
  2393.      part of the BASIC language but leaves everything else as you enter it.
  2394.      The examples in this chapter are shown the way QuickBASIC formats them,
  2395.      and each program's output is shown exactly as it appears on the screen.
  2396.    ──────────────────────────────────────────────────────────────────────────
  2397.  
  2398.    The PRINT statement can also display numbers as shown in the following
  2399.    example program:
  2400.  
  2401.    1. Type the following line in the Immediate window, then press ENTER:
  2402.  
  2403.       PRINT 63
  2404.  
  2405.       The output should appear as follows:
  2406.  
  2407.        63
  2408.  
  2409.    2. Type CLS in the Immediate window and press ENTER to clear the output
  2410.       screen.
  2411.  
  2412.  
  2413.  Variables
  2414.  
  2415.    Programs take data from the outside world (input), then process it to
  2416.    produce useful information (output). The input and output data are stored
  2417.    in the computer's memory. Variable names are used to keep track of where
  2418.    the data are stored.
  2419.  
  2420.  Storing Data in Memory
  2421.  
  2422.    Computer memory is divided into storage locations, each of which has a
  2423.    unique "address." The address is a number that gives the memory location,
  2424.    the same way your house address shows where you live on a street. Every
  2425.    piece of data has its own storage location and matching address (see
  2426.    Figure 4.1).
  2427.  
  2428.  
  2429.    ┌─────────────────────────────────────────────────────────┐
  2430.    │                                                         │
  2431.    │   ┌──────┬──────┬──────┬──────┬──────┬──────┬──────┐    │
  2432.    │   │ 1230 │ 1231 │ 1232 │ 1233 │ 1234 │ 1235 │ 1236 │    │
  2433.    │   └──────┴──────┴──────┴──────┴──────┴──────┴──────┘    │
  2434.    │                                                         │
  2435.    └─────────────────────────────────────────────────────────┘
  2436.  
  2437.    Figure 4.1  Addresses in Memory
  2438.  
  2439.    Fortunately, you don't have to keep track of the address for every data
  2440.    item. BASIC uses a "variable name" to associate a word of your choice with
  2441.    a memory location in the computer.
  2442.  
  2443.    BASIC does the associating automatically. Every time you use a variable
  2444.    name that BASIC hasn't seen before, BASIC finds an unused memory location
  2445.    and associates the new variable name with that address. You can then use
  2446.    the variable name without having to know its address.
  2447.  
  2448.    The following example program demonstrates this. Note that Hello, world is
  2449.    not enclosed in quotes in this example.
  2450.  
  2451.    1. Type the following line in the Immediate window, then press ENTER:
  2452.  
  2453.       PRINT Hello, world
  2454.  
  2455.       The output should appear as follows:
  2456.  
  2457.        0             0
  2458.  
  2459.    2. Type CLS in the Immediate window and press ENTER to clear the output
  2460.       screen.
  2461.  
  2462.    When BASIC encounters Hello and world, it has to decide what these words
  2463.    are. They aren't keywords (that is, they aren't part of the BASIC
  2464.    language), as PRINT is. They aren't strings, because they aren't enclosed
  2465.    in quotes. They are definitely not numbers. Therefore, Hello and world
  2466.    must be variables.
  2467.  
  2468.    Once this decision is made, BASIC sets aside storage space for two new
  2469.    variables named Hello and world. New variables are always given an initial
  2470.    value of zero, so the PRINT statement displays two zeros.
  2471.  
  2472.    A variable name can contain digits, but the name cannot begin with a
  2473.    digit. Any word starting with a digit is interpreted as a number.
  2474.  
  2475.    Names allowed in BASIC include:
  2476.  
  2477.    gerbils
  2478.    birthdate
  2479.    name3
  2480.    ep45lp33
  2481.  
  2482.    These are illegal names:
  2483.  
  2484.    5remove
  2485.    4.3less
  2486.  
  2487.  Variable Types
  2488.  
  2489.    Data do not come in just one form. Programming languages, therefore, need
  2490.    different types of variables to hold different types of data. BASIC has
  2491.    three categories of variables: integer, floating point, and string.
  2492.  
  2493.    Integer Variables
  2494.  
  2495.    An integer number is a whole number, without a fractional part. For
  2496.    example, 0, -45, and 1278 are integers. Integer numbers are stored in
  2497.    integer variables. BASIC has two types of integer variables: integer and
  2498.    long integer.
  2499.  
  2500.    A variable name ending in % is an integer variable. Integer variables can
  2501.    have any whole-number value between -32,768 and 32,767. A variable name
  2502.    ending in & is a long-integer variable and can have any whole-number value
  2503.    between -2,147,483,648 and 2,147,483,647.
  2504.  
  2505.    Floating-Point Variables
  2506.  
  2507.    A floating-point number can have a fractional part (though it doesn't have
  2508.    to). For example, 0.123, 78.26, 7.0, and 1922.001234 are all
  2509.    floating-point numbers. Floating-point numbers are stored in
  2510.    floating-point variables. BASIC has two types of floating-point variables:
  2511.    single precision and double precision.
  2512.  
  2513.    A variable name ending in a letter, a digit, or ! is a single-precision
  2514.    floating-point variable. Single-precision floating-point numbers can have
  2515.    values ranging from about -3.4 x 10'38 to 3.4 x 10'38 (that's 34 with 37
  2516.    zeros following). A single-precision floating-point variable is accurate
  2517.    to only about 7 decimal places.
  2518.  
  2519.    A variable name ending in # is a double-precision floating-point variable
  2520.    and can have values from about -1.7 x 10'308 to 1.7 x 10'308 (that's 17
  2521.    with 307 zeros following!). A double-precision floating-point variable can
  2522.    hold much larger numbers than a single-precision variable, and it is also
  2523.    more accurate── to about 15 decimal places.
  2524.  
  2525.    Single-precision floating-point numbers are the kind most often used in
  2526.    calculations, since "real-world" applications usually need numbers with
  2527.    fractional parts. (Prices are a good example.) Since single-precision
  2528.    floating-point variables are so commonly used, they are the "default" data
  2529.    type; that is, if a variable name does not end with a "type" character (%,
  2530.    &, #, !, or $), it is assumed to be a single-precision floating-point
  2531.    variable.
  2532.  
  2533.    Note, however, that calculations with integer variables take much less
  2534.    computer time than those performed with floating-point variables. Integer
  2535.    variables should be used when speed is required.
  2536.  
  2537.    The numerical variables in the remaining examples in this chapter are
  2538.    marked with the appropriate type suffix, either ! or %. Although most of
  2539.    these are single-precision floating-point variables, which need no type
  2540.    suffix, they are given the ! suffix for clarity.
  2541.  
  2542.    String Variables
  2543.  
  2544.    A string variable holds a sequence (a string) of characters. A variable
  2545.    name ending in $ is a string variable. Just as a numeric variable is given
  2546.    an initial value of 0, a newly defined string variable is assigned an
  2547.    initial length of zero. It contains no data at all, not even blank spaces.
  2548.    If blank$ has not previously been given a value, the statement
  2549.  
  2550.    PRINT blank$
  2551.  
  2552.    displays an empty line.
  2553.  
  2554.  
  2555.  Assigning Values to Variables
  2556.  
  2557.    A variable gets its value through an "assignment" statement. An assignment
  2558.    statement has three components: the variable that receives a new value; an
  2559.    equal sign (=); and the number, string, or calculation whose value the
  2560.    variable takes on. These are all valid assignment statements:
  2561.  
  2562.    age% = 41
  2563.    myname$ = "Willie"
  2564.    result! = result3! + leftval! + rightval!
  2565.  
  2566.    In the next example program, two strings are combined with the plus sign
  2567.    (+) to make a longer string. The result is assigned to a third string.
  2568.  
  2569.    1. Choose the File menu's New Program command to clear the View window
  2570.       (press ALT+F, then press N).
  2571.  
  2572.    2. Type the following example in the View window:
  2573.  
  2574.       string1$ = "Hello,"
  2575.       string2$ = " there!"
  2576.       bigstring$ = string1$ + string2$
  2577.       PRINT bigstring$
  2578.  
  2579.    3. Choose the Run menu's Start command (press ALT+R, then press S).
  2580.  
  2581.       The output should look like the following:
  2582.  
  2583.       Hello, there!
  2584.  
  2585.    4. Type CLS in the Immediate window and press ENTER to clear the output
  2586.       screen.
  2587.  
  2588.    Although assignment is shown by the equal sign, it is not the same thing
  2589.    as algebraic equality. To BASIC, the assignment statement means: "Perform
  2590.    all the calculations and data manipulations on the right side of the equal
  2591.    sign. Then give the variable on the left side the result."
  2592.  
  2593.    The same variable name can appear on both sides of the assignment
  2594.    statement. This occurs most often when you want to change the variable's
  2595.    value. Try the following example program:
  2596.  
  2597.    1. Choose the File menu's New Program command to clear the View window.
  2598.  
  2599.    2. Type the following example in the View window:
  2600.  
  2601.       counter% = 6
  2602.       PRINT counter%
  2603.       counter% = counter% - 1
  2604.       PRINT counter%
  2605.  
  2606.    3. Choose the Run menu's Start command.
  2607.  
  2608.       The output should look like the following:
  2609.  
  2610.        6
  2611.        5
  2612.  
  2613.    4. Type CLS in the Immediate window and press ENTER to clear the output
  2614.       screen.
  2615.  
  2616.    You cannot assign numeric values to string variables (or vice versa).
  2617.    Therefore, the following statements are illegal. Either one halts
  2618.    execution and causes the error message Type mismatch when the program
  2619.    runs.
  2620.  
  2621.    strg$ = 3.14159
  2622.    number! = "hi, there"
  2623.  
  2624.  
  2625.  Calculations
  2626.  
  2627.    In BASIC, the mathematical operations of addition, subtraction,
  2628.    multiplication, and division are represented by +, -, * (the asterisk),
  2629.    and / (the slash), respectively. Exponentiation (raising a number to a
  2630.    power) is shown by ' (the caret). You can type each of the following on a
  2631.    line in the Immediate window, then press ENTER to see the results of the
  2632.    operations:
  2633.  
  2634.    Operation                                        Result
  2635.    ──────────────────────────────────────────────────────────────────────────
  2636.    PRINT 2 + 3                                      5
  2637.  
  2638.    PRINT 2 - 3                                      -1
  2639.  
  2640.    PRINT 2 * 3                                      6
  2641.  
  2642.    PRINT 2 / 3                                      .6666667
  2643.  
  2644.    PRINT 2 ' 3                                      8
  2645.    ──────────────────────────────────────────────────────────────────────────
  2646.  
  2647.  Integer Division and the Remainder Operator
  2648.  
  2649.  BASIC has two math operations you may not have seen before, integer division
  2650.  and the remainder operator.
  2651.  
  2652.    Integer division retains the integer (whole-number) part of the division
  2653.    and discards the fractional part. Integer division is represented by \
  2654.    (the backslash). You can type each of the following on a line in the
  2655.    Immediate window, then press ENTER to see the results of the operations:
  2656.  
  2657.    Operation                                        Result
  2658.    ──────────────────────────────────────────────────────────────────────────
  2659.    PRINT 7 \ 3                                      2
  2660.  
  2661.    PRINT 9.6 \ 2.4                                  5
  2662.    ──────────────────────────────────────────────────────────────────────────
  2663.  
  2664.    Both integer division and the remainder operator round off the numbers to
  2665.    be operated on before the calculation is performed. The number 9.6 becomes
  2666.    10 and 2.4 becomes 2. Therefore, the result of the second example above is
  2667.    5, not 4.
  2668.  
  2669.    The remainder operator is the complement of integer division. The
  2670.    whole-number part of the division is discarded, and the remainder is
  2671.    returned. Remainder division is performed by the BASIC keyword MOD. You
  2672.    can type each of the following on a line in the Immediate window, then
  2673.    press ENTER to see the results of the operations:
  2674.  
  2675.    Operation                                        Result
  2676.    ──────────────────────────────────────────────────────────────────────────
  2677.    PRINT 7 MOD 3                                    1
  2678.  
  2679.    PRINT 11 MOD 4                                   3
  2680.    ──────────────────────────────────────────────────────────────────────────
  2681.  
  2682.  Precedence of Operations
  2683.  
  2684.    BASIC evaluates mathematical expressions from left to right, following the
  2685.    rules of algebraic precedence: exponentiation is performed first, then
  2686.    multiplication and division, then addition and subtraction. The following
  2687.    example program illustrates algebraic precedence:
  2688.  
  2689.    1. Type the following line in the Immediate window, then press ENTER:
  2690.  
  2691.       PRINT 2 * 3 + 2 ' 3 - 2 / 3
  2692.  
  2693.       The output should appear as follows:
  2694.  
  2695.        13.33333
  2696.  
  2697.    2. Type CLS in the Immediate window and press ENTER to clear the output
  2698.       screen.
  2699.  
  2700.    Parentheses can confirm or override the normal precedence. Try this
  2701.    example:
  2702.  
  2703.    1. Type the following line in the Immediate window, then press ENTER:
  2704.  
  2705.       PRINT (2 * 3) + (2 ' 3) - (2 / 3)
  2706.  
  2707.       The output should appear as follows:
  2708.  
  2709.        13.33333
  2710.  
  2711.    2. Type CLS in the Immediate window and press ENTER to clear the output
  2712.       screen.
  2713.  
  2714.    The result is the same as in the last example because the precedence of
  2715.    operations dictated by the parentheses is no different from the usual
  2716.    order. However, the next example program produces a different result:
  2717.  
  2718.    1. Type the following line in the Immediate window, then press ENTER:
  2719.  
  2720.       PRINT 2 * (3 + 2) ' (3 - 2 / 3)
  2721.  
  2722.       The output should appear as follows:
  2723.  
  2724.        85.49879
  2725.  
  2726.    2. Type CLS in the Immediate window and press ENTER to clear the output
  2727.       screen.
  2728.  
  2729.    The result here is different because the calculations within parentheses
  2730.    are performed first. Within parentheses, the usual precedence still
  2731.    applies, of course. The expression (3 - 2 / 3) evaluates as (3 -
  2732.    .6666667), not (1 / 3).
  2733.  
  2734.    You might want to use parentheses to control the order of calculations,
  2735.    rather than depending on precedence. Parentheses prevent errors and make
  2736.    your programs easier to understand.
  2737.  
  2738.  Math Functions
  2739.  
  2740.    Along with the addition, subtraction, multiplication, and division
  2741.    operators just presented, BASIC provides a number of common math
  2742.    functions, described briefly below. To use them, follow the function name
  2743.    with the variable or expression you want the function performed on (in
  2744.    parentheses). The expression may be any valid combination of variables,
  2745.    numbers, and math functions. (Expressions are explained further in the
  2746.    following section.)
  2747.  
  2748.    Function                 Description
  2749.    ──────────────────────────────────────────────────────────────────────────
  2750.    ABS                      Returns the absolute value of the expression
  2751.  
  2752.    ATN                      Returns the angle (in radians) whose tangent
  2753.                             equals the expression
  2754.  
  2755.    COS                      Returns the cosine of an angle (in radians)
  2756.  
  2757.    EXP                      Returns e to the power of the expression
  2758.  
  2759.    LOG                      Returns the logarithm of the expression
  2760.  
  2761.    SGN                      Returns -1 if the expression is less than 0;
  2762.                             returns 0 if it is 0; returns +1 if it is greater
  2763.                             than 0
  2764.  
  2765.    SIN                      Returns the sine of an angle (in radians)
  2766.  
  2767.    SQR                      Returns the square root of the expression
  2768.  
  2769.    TAN                      Returns the tangent of an angle (in radians)
  2770.    ──────────────────────────────────────────────────────────────────────────
  2771.  
  2772.    The following example program shows the use of the square-root function:
  2773.  
  2774.    1. Choose the File menu's New Program command to clear the View window.
  2775.  
  2776.    2. Type the following example in the View window:
  2777.  
  2778.       adjacent! = 3.0
  2779.       opposite! = 4.0
  2780.       hypotenuse! = SQR((adjacent! ' 2) + (opposite! ' 2))
  2781.       PRINT "the hypotenuse is:"; hypotenuse!
  2782.  
  2783.    3. Choose the Run menu's Start command.
  2784.  
  2785.       The output should look like the following:
  2786.  
  2787.       the hypotenuse is: 5
  2788.  
  2789.    4. Type CLS in the Immediate window and press ENTER to clear the output
  2790.       screen.
  2791.  
  2792.  
  2793.  Expressions
  2794.  
  2795.    An "expression" is what most people would call a formula. An expression is
  2796.    any combination of numbers, strings, variables, functions, and operators
  2797.    that can be evaluated. For example, 2 + 2 is a simple expression. It
  2798.    evaluates to four. Enter the following statements in the View window to
  2799.    assign a variety of simple expressions to variables, as follows:
  2800.  
  2801.    1. Choose the File menu's New Program command to clear the View window.
  2802.  
  2803.    2. Type the following example in the View window:
  2804.  
  2805.       square% = 3 ' 2
  2806.       root! = SQR(3 ' 2)
  2807.       greeting$ = "Hello," + " world! "
  2808.       strange! = 9 + "cats"
  2809.  
  2810.       The last statement you typed was illegal.
  2811.  
  2812.    3. Choose the Run menu's Start command.
  2813.  
  2814.       QuickBASIC displays the error message Type mismatch. You cannot add a
  2815.       number (or numerical variable) to a string (or string variable).
  2816.  
  2817.    4. Type CLS in the Immediate window and press ENTER to clear the output
  2818.       screen.
  2819.  
  2820.    Expressions may be as complex as you like, with the results of one
  2821.    expression passed to a function, the value returned by a function combined
  2822.    with other expressions, and so on.
  2823.  
  2824.    Almost any place you can use a number or a string, you can use any
  2825.    expression (no matter how complex) that evaluates to a number or a string.
  2826.    This means expressions can be used in BASIC's math functions, PRINT
  2827.    statements, and assignment statements.
  2828.  
  2829.  
  2830.  Displaying Variables and Expressions
  2831.  
  2832.    The PRINT statement was first shown in this chapter as a way to display
  2833.    numbers and strings. The PRINT statement can also display the values of
  2834.    variables and expressions. For example, try this:
  2835.  
  2836.    1. Type the following lines in the Immediate window, then press ENTER:
  2837.  
  2838.       PRINT (2 + 8) / 4 + 1
  2839.  
  2840.       The output should appear as follows:
  2841.  
  2842.        3.5
  2843.  
  2844.    2. Type CLS in the Immediate window and press ENTER to clear the output
  2845.       screen.
  2846.  
  2847.    The PRINT statement is quite flexible; it can display any combination of
  2848.    strings, numbers, variables, and expressions. The items to be displayed
  2849.    are separated by semicolons (;) or commas (,). When a semicolon separates
  2850.    two items, the second item is displayed immediately after the first, as
  2851.    shown in the example program below:
  2852.  
  2853.    1. Type the following line in the Immediate window, then press ENTER:
  2854.  
  2855.       PRINT "Sum of 5.29 and"; 2.79; "is"; 5.29 + 2.79
  2856.  
  2857.       The output should appear as follows:
  2858.  
  2859.       Sum of 5.29 and 2.79 is 8.08
  2860.  
  2861.    2. Type CLS in the Immediate window and press ENTER to clear the output
  2862.       screen.
  2863.  
  2864.    Here's another example program to try:
  2865.  
  2866.    1. Choose the File menu's New Program command to clear the View window.
  2867.  
  2868.    2. Type the following example in the View window:
  2869.  
  2870.       number = 36
  2871.       PRINT "The sum of"; number; "and 4 is"; number + 4
  2872.       PRINT "The square of"; number; "is"; number * number
  2873.  
  2874.    3. Choose the Run menu's Start command.
  2875.  
  2876.       The output should look like the following:
  2877.  
  2878.       The sum of 36 and 4 is 40
  2879.       The square of 36 is 1296
  2880.  
  2881.    4. Type CLS in the Immediate window and press ENTER to clear the output
  2882.       screen.
  2883.  
  2884.    If two items in a PRINT statement are separated by a comma, the second
  2885.    item is positioned at the next preset tab location. (The tab stops are 14
  2886.    columns apart.) Note the difference between the output of the following
  2887.    PRINT statement and that of the similar one with semicolons, above:
  2888.  
  2889.    1. Enter the following lines in the Immediate window, then press ENTER:
  2890.  
  2891.       PRINT "Sum of 5.29 and", 2.79, "is", 5.29 + 2.79
  2892.  
  2893.       The output should appear as follows:
  2894.  
  2895.       Sum of 5.29 and          2.79         is             8.08
  2896.  
  2897.    2. Type CLS in the Immediate window and press ENTER to clear the output
  2898.       screen.
  2899.  
  2900.    Commas and semicolons can be used in the same PRINT statement to position
  2901.    the items any way you like.
  2902.  
  2903.    Each PRINT statement normally places its output on a new line, as the
  2904.    following example program shows:
  2905.  
  2906.    1. Choose the File menu's New Program command to clear the View window.
  2907.  
  2908.    2. Type the following example in the View window:
  2909.  
  2910.       PRINT "How old are you?"
  2911.       PRINT 41
  2912.  
  2913.       The output should appear as follows:
  2914.  
  2915.       How old are you?
  2916.        41
  2917.  
  2918.    3. Choose the Run menu's Start command.
  2919.  
  2920.    4. Type CLS in the Immediate window and press ENTER to clear the output
  2921.       screen.
  2922.  
  2923.    If you want to combine the output of several PRINT statements on the same
  2924.    line, place a semicolon (;) at the end of each PRINT statement. Change the
  2925.    last example program as follows:
  2926.  
  2927.    1. Choose the File menu's New Program command to clear the View window.
  2928.  
  2929.    2. Type the following example in the View window:
  2930.  
  2931.       PRINT "How old are you?";
  2932.  
  2933.       PRINT 41
  2934.  
  2935.    3. Choose the Run menu's Start command.
  2936.  
  2937.       The output should look like the following:
  2938.  
  2939.       How old are you? 41
  2940.  
  2941.    4. Type CLS in the Immediate window and press ENTER to clear the output
  2942.       screen.
  2943.  
  2944.  
  2945.  Entering Data with the INPUT Statement
  2946.  
  2947.    The INPUT statement displays a prompt string, then waits for the user to
  2948.    enter some value. The value entered in response to the prompt is assigned
  2949.    to the variable specified in the INPUT statement.
  2950.  
  2951.    INPUT "enter your age: ", age%
  2952.    PRINT age%
  2953.  
  2954.    If you typed 39 in response to the enter your age: prompt, the value 39
  2955.    would be assigned to the variable age%, and that value would be printed by
  2956.    the following PRINT age% statement.
  2957.  
  2958.    INPUT also accepts strings:
  2959.  
  2960.    INPUT "What is your name? ", yourname$
  2961.    PRINT yourname$
  2962.  
  2963.    A string variable will accept whatever you type, since all entries──even
  2964.    numbers──are actually strings. (When you type 42, you are not typing the
  2965.    number 42, but rather the characters 4 and 2. If the input variable is
  2966.    numerical, BASIC converts this string into a number. If the input variable
  2967.    is a string, the character sequence 42 is simply assigned to the string.)
  2968.  
  2969.    A numeric variable, however, can only be assigned a number. If you type
  2970.    dog when you should have entered a number, BASIC responds with the message
  2971.    Redo from start and a new prompt line.
  2972.  
  2973.  
  2974.  Arrays of Variables
  2975.  
  2976.    If you wanted to keep track of the high temperature for each day in July,
  2977.    you could use 31 floating-point variables, named july1, july2, july3, and
  2978.    so on through july31.
  2979.  
  2980.    However, a group of related but individually named variables is clumsy to
  2981.    work with; each variable has to be handled separately. For example, if you
  2982.    wanted to prompt the user for each temperature in July, you would have to
  2983.    write 31 individual prompt statements.
  2984.  
  2985.    INPUT "What is the temp value for July 1? ", july1
  2986.       .
  2987.       .
  2988.       .
  2989.    INPUT "What is the temp value for July 31? ", july31
  2990.  
  2991.    An analogous problem occurs when you're trying to write a program that
  2992.    retrieves the stored data. You wouldn't want to write a program that
  2993.    displayed all 31 variable names to be able to retrieve the value for any
  2994.    specific one (say, the high temperature for July 4──the value for july4).
  2995.    It would be much more convenient if you could just give the computer the
  2996.    date (the number 4) and the computer would select the right variable and
  2997.    value.
  2998.  
  2999.    The solution is to give the entire set of values the same name (july in
  3000.    our example) and distinguish the individual values by a numerical index
  3001.    called a "subscript." A group of identically named variables distinguished
  3002.    by their subscript values is called an "array." (See Figure 4.2 for an
  3003.    example.) Arrays can be especially powerful when used in conjunction with
  3004.    loops (see the section titled "Repeating Program Operations").
  3005.  
  3006.  
  3007.    ┌─────────────────────────────────────────────────────────────────┐
  3008.    │                                                                 │
  3009.    │  ┌───────────┬───────────┬───────────┬───────────┬───────────┐  │
  3010.    │  │ Price (0) │ Price (1) │ Price (2) │ Price (3) │ Price (4) │  │
  3011.    │  └───────────┴───────────┴───────────┴───────────┴───────────┘  │
  3012.    │                                                                 │
  3013.    └─────────────────────────────────────────────────────────────────┘
  3014.  
  3015.    Figure 4.2  Array Created by the BASIC Statemenet DIM Price (4)
  3016.  
  3017.  Declaring Arrays
  3018.  
  3019.    An array variable must first be "declared" with a DIM statement, which
  3020.    establishes the size of the array. A DIM statement must appear before the
  3021.    array variable can be used.
  3022.  
  3023.    The value given in the DIM statement specifies the maximum value for the
  3024.    variable's subscript. For example, the following statement declares an
  3025.    array of 32 floating-point variables named july, whose subscripts run from
  3026.    0 to 31:
  3027.  
  3028.    DIM july(31)
  3029.  
  3030.    DIM also works with string variables:
  3031.  
  3032.    DIM stringvar$(250)
  3033.  
  3034.  Specifying Array Elements
  3035.  
  3036.    You can specify the nth member (or "element") of an array simply by
  3037.    putting the number n (or a variable or expression with the value n) in
  3038.    parentheses following the variable name. In this way the program can
  3039.    connect a specific variable with a number entered by the user. For
  3040.    example, the fourth element of the july array could be specified by either
  3041.    july(4) or──if d% equals four──july(d%) or even july(SQR(16)).
  3042.  
  3043.    The following code fragment prompts the user for the date, then prints the
  3044.    high temperature for that day in July (assuming that all the temperatures
  3045.    have been assigned to the array july).
  3046.  
  3047.    DIM july(31)
  3048.    INPUT "enter July date: ", date%
  3049.    PRINT "high temperature for July"; date%; "was"; july(date%)
  3050.  
  3051.  
  3052.  Logical Relations Used in Decision-Making
  3053.  
  3054.    BASIC can decide whether two numbers or strings are the same or different.
  3055.    On the basis of such a decision, an appropriate group of program
  3056.    statements can be executed or repeated.
  3057.  
  3058.    For example, suppose the standard income-tax deduction is $2500. If your
  3059.    itemized deductions are less than $2500, you would take the standard
  3060.    deduction. If your itemized deductions are greater than $2500, you would
  3061.    itemize. An income-tax program can make this decision and execute either
  3062.    the part of the program that performs itemized deductions or the part that
  3063.    takes the standard deduction. The user doesn't have to tell the program
  3064.    what to do.
  3065.  
  3066.    The following sections explain how BASIC makes logical decisions that can
  3067.    be used in your programs.
  3068.  
  3069.  Relational Operators
  3070.  
  3071.    Numbers and strings are compared using "relational operators." There are
  3072.    six possible relationships, shown by the following operators:
  3073.  
  3074.    Relational Operator      Meaning
  3075.    ──────────────────────────────────────────────────────────────────────────
  3076.    =                        Equal to
  3077.  
  3078.    <>                       Not equal to
  3079.  
  3080.    >                        Greater than
  3081.  
  3082.    <                        Less than
  3083.  
  3084.    >=                       Greater than or equal to
  3085.  
  3086.    <=                       Less than or equal to
  3087.  
  3088.    ──────────────────────────────────────────────────────────────────────────
  3089.  
  3090.    ──────────────────────────────────────────────────────────────────────────
  3091.    NOTE
  3092.      BASIC uses the equal sign (=) both to assign a value to a variable and
  3093.      also to indicate logical equality. BASIC knows which usage is intended
  3094.      from the context.
  3095.    ──────────────────────────────────────────────────────────────────────────
  3096.  
  3097.    The following list shows how these relationships are evaluated:
  3098.  
  3099.    Relational Operation                 Evaluation
  3100.    ──────────────────────────────────────────────────────────────────────────
  3101.    7 = 35                               False
  3102.  
  3103.    7 <> 6                               True
  3104.  
  3105.    6 > 1                                True
  3106.  
  3107.    4 < 3                                False
  3108.  
  3109.    7 <= 7                               True
  3110.  
  3111.    8 >= 7                               True
  3112.  
  3113.    apples = oranges                     Depends on values of variables
  3114.    ──────────────────────────────────────────────────────────────────────────
  3115.  
  3116.    As for the last statement──apples aren't oranges. But if apples and
  3117.    oranges were variable names, then the truth or falsity of the statement
  3118.    would depend on the values of these variables.
  3119.  
  3120.    The following relational operations compare strings. Are they true or
  3121.    false?
  3122.  
  3123.    "Tarzan" <> "Jane"
  3124.    "Y" = "Y"
  3125.    "Y" = "y"
  3126.    "miss" > "misty"
  3127.  
  3128.    Tarzan and Jane are different strings, so the first assertion is true. Y
  3129.    and Y are the same character, so the second assertion is true. Y and y are
  3130.    not the same character, so the third assertion is false.
  3131.  
  3132.    The last statement may be confusing at first; how can one string be
  3133.    "larger" or "smaller" than another? It can be, and the decision is made
  3134.    this way. The strings are first compared, position by position, until
  3135.    BASIC finds characters that don't match. In this example, the fourth
  3136.    characters are the first nonmatching characters. The decision of "larger"
  3137.    or "smaller" is then based on these differing characters, in the following
  3138.    way.
  3139.  
  3140.    Within the computer, characters are represented by numbers. Letters coming
  3141.    later in the alphabet have numeric values larger than those appearing
  3142.    earlier. Since t follows s in the alphabet, t is a "larger" letter, and
  3143.    the statement is therefore false; misty is "larger" than miss. This
  3144.    ability to determine the relative value of strings makes it easy to write
  3145.    a program that can alphabetize a list of words or names.
  3146.  
  3147.    In most of these examples, numbers were compared with numbers and strings
  3148.    with strings. But any combination of numbers and numerical variables can
  3149.    be compared; the same is true for strings and string variables. The only
  3150.    things you cannot compare are numerical values with string values because
  3151.    the comparison is logically meaningless.
  3152.  
  3153.  Boolean Expressions
  3154.  
  3155.    Logical assertions are called "Boolean expressions" (for George Boole, who
  3156.    formulated some of the rules of mathematical logic). Boolean operations
  3157.    are concerned with only one thing: is a Boolean expression true or false?
  3158.    Unlike mathematical expressions, which evaluate to numbers, Boolean
  3159.    expressions evaluate to one of two values: "true" or "false."
  3160.  
  3161.    Computers use numbers to represent "true" and "false." To see how BASIC
  3162.    codes "true" and "false," enter and run these two lines, as follows:
  3163.  
  3164.    1. Choose the File menu's New Program command to clear the View window.
  3165.  
  3166.    2. Type the following example in the View window:
  3167.  
  3168.       PRINT 5 > 6
  3169.       PRINT 6 > 5
  3170.  
  3171.    3. Choose the Run menu's Start command.
  3172.  
  3173.       The output should look like the following:
  3174.  
  3175.        0
  3176.       -1
  3177.  
  3178.       The display shows 0 on the first line, -1 on the second.
  3179.  
  3180.       The number 5 is not greater than 6, so BASIC prints its value for
  3181.       "false": 0. The number 6 is greater than 5, so BASIC prints its value
  3182.       for "true": -1.
  3183.  
  3184.    4. Type CLS in the Immediate window and press ENTER to clear the output
  3185.       screen.
  3186.  
  3187.  Compound Expressions
  3188.  
  3189.    In BASIC, a compound Boolean expression is created by connecting two
  3190.    Boolean expressions with a "logical operator." The two most commonly used
  3191.    logical operators are AND and OR.
  3192.  
  3193.    The AND operator requires both expressions to be true if the compound
  3194.    expression is to be true. When the OR operator is used, only one of the
  3195.    expressions has to be true for the compound expression to be true.
  3196.  
  3197.    The following examples are compound expressions that combine two simple
  3198.    expressions by using AND or OR:
  3199.  
  3200.    Expression                                       Evaluation
  3201.    ──────────────────────────────────────────────────────────────────────────
  3202.    10 > 5 AND 100 < 200                             True
  3203.  
  3204.    3 < 6 AND 7 > 10                                 False
  3205.  
  3206.    8 < 7 OR 90 > 80                                 True
  3207.  
  3208.    2 < 1 OR 3 > 60                                  False
  3209.  
  3210.    "Y" > "N" AND "yes" <> "no"                      True
  3211.  
  3212.    "Y" < "N" OR 4 <> 4                              False
  3213.    ──────────────────────────────────────────────────────────────────────────
  3214.  
  3215.    The NOT operator reverses the truth or falsity of an expression:
  3216.  
  3217.    Expression                                       Evaluation
  3218.    ──────────────────────────────────────────────────────────────────────────
  3219.    NOT (5 > 10)                                     True
  3220.  
  3221.    NOT (8 < 7 OR 90 > 80)                           False
  3222.  
  3223.    NOT (3 < 6 AND 7 > 10)                           True
  3224.  
  3225.    NOT (0)                                          True
  3226.    ──────────────────────────────────────────────────────────────────────────
  3227.  
  3228.    The logic of the last example may not be immediately obvious. In BASIC,
  3229.    false is zero. Therefore, NOT (0) means "not false," or true. Combinations
  3230.    of AND, OR, and NOT can be used to build up very complex expressions.
  3231.    There is no practical limit to their complexity, except the obvious one of
  3232.    writing an expression that is difficult to read.
  3233.  
  3234.    When Boolean expressions are evaluated, the precedence of evaluation is
  3235.    taken in the same order as arithmetic expressions, with AND equivalent to
  3236.    multiplication and OR equivalent to addition. Evaluation goes from left to
  3237.    right, with all the simple expressions evaluated first. All the
  3238.    AND-connected expressions are evaluated next, followed by the OR-connected
  3239.    expressions. As with arithmetic expressions, parentheses can be used to
  3240.    control the order of evaluation, rather than relying on the rules of
  3241.    precedence.
  3242.  
  3243.    See Chapter 1, "Control-Flow Structures," in Programming in BASIC, for
  3244.    more explanation of why BASIC considers -1 equivalent to true.
  3245.  
  3246.    The next sections show how Boolean expressions are used in programs.
  3247.  
  3248.  
  3249.  Using Logical Statements to Control Program Flow
  3250.  
  3251.    You are always deciding what to do next by evaluating your priorities and
  3252.    desires, asking yourself which is most important at the moment. Similarly,
  3253.    BASIC has a mechanism that allows your program to select which set of
  3254.    operations (that is, which part of the program) will be executed next.
  3255.  
  3256.    This mechanism is the IF...THEN...ELSE statement. If a Boolean expression
  3257.    is true, the statements following THEN are executed. If the expression is
  3258.    false, the statements following ELSE are executed. A Boolean expression
  3259.    must be either true or false, so one or the other group of statements has
  3260.    to execute. Both cannot execute.
  3261.  
  3262.    The process of selecting among two or more possible actions (or sections
  3263.    of program code) is called "branching." The analogy is with the way a tree
  3264.    branch subdivides into more and more branches.
  3265.  
  3266.    This is the syntax of the IF...THEN...ELSE statement:
  3267.  
  3268.    IF booleanexpression THEN
  3269.       statements to do something
  3270.    ELSE
  3271.       statements to do something else
  3272.    END IF
  3273.  
  3274.    Try the following simple example to use the IF...THEN...ELSE statement to
  3275.    decide whether a number entered is greater than, less than, or equal to
  3276.    100:
  3277.  
  3278.    1. Choose the File menu's New Program command to clear the View window.
  3279.  
  3280.    2. Type the following example in the View window:
  3281.  
  3282.       INPUT "enter a number: ", n
  3283.  
  3284.       IF n > 100 THEN
  3285.          PRINT n; "is greater than 100"
  3286.       ELSE
  3287.          PRINT n; "is less than or equal to 100"
  3288.       END IF
  3289.  
  3290.    3. Choose the Run menu's Start command.
  3291.  
  3292.       The logical opposite of "greater than" is "less than or equal to" (not
  3293.       "less than"). Run this example with several values for n, including a
  3294.       value of 100 to verify that the is less than or equal to 100 statement
  3295.       is displayed.
  3296.  
  3297.    4. Type CLS in the Immediate window and press ENTER to clear the output
  3298.       screen.
  3299.  
  3300.    See Chapter 1, "Control-Flow Structures," in Programming in BASIC for a
  3301.    more detailed explanation of the IF...THEN...ELSE statement and other
  3302.    decision structures available in QuickBASIC.
  3303.  
  3304.  
  3305.  Repeating Program Operations
  3306.  
  3307.    BASIC offers several ways to execute a group of program statements
  3308.    repeatedly. You can repeat them a fixed number of times or until a
  3309.    particular logical condition is met. If you want to execute a block of
  3310.    statements 100 times, you need only type them in once. BASIC's control
  3311.    structures then control the repetitions.
  3312.  
  3313.    The ability to repeat program statements has many uses. For example, to
  3314.    raise a number N to the power P, N must be multiplied by itself P times.
  3315.    To enter data for a ten-element array, you must prompt the user ten times.
  3316.  
  3317.  The FOR...NEXT Loop
  3318.  
  3319.    One way to repeat a section of the program is the FOR...NEXT loop. The
  3320.    block of program statements between the FOR and NEXT keywords is executed
  3321.    repeatedly a specified number of times. Try the following:
  3322.  
  3323.    1. Choose the File menu's New Program command to clear the View window.
  3324.  
  3325.    2. Type the following example in the View window:
  3326.  
  3327.       FOR count% = 1 TO 5
  3328.          PRINT "this line is printed 5 times; this is time"; count%
  3329.       NEXT count%
  3330.  
  3331.    3. Choose the Run menu's Start command.
  3332.  
  3333.       The output should look like the following:
  3334.  
  3335.       this line is printed 5 times; this is time 1
  3336.       this line is printed 5 times; this is time 2
  3337.       this line is printed 5 times; this is time 3
  3338.       this line is printed 5 times; this is time 4
  3339.       this line is printed 5 times; this is time 5
  3340.  
  3341.    4. Type CLS in the Immediate window, then press ENTER to clear the output
  3342.       screen.
  3343.  
  3344.    In the example above, the variable count% is called the "loop variable" or
  3345.    "loop counter." The two numbers after the equal sign (separated by the
  3346.    keyword TO) are the start and end values for the loop counter. In this
  3347.    example, 1 is the start value, and 5 is the end value.
  3348.  
  3349.    Before the statements in the FOR...NEXT loop are executed for the first
  3350.    time, the loop counter is given the start value (in this case, 1). After
  3351.    each execution of the statements in the loop, BASIC automatically
  3352.    increments count% by one. This cycle continues until count% is larger than
  3353.    the end value (in this case, 5). The statements between the FOR and NEXT
  3354.    keywords in this example are therefore executed five times.
  3355.  
  3356.    To repeat a FOR...NEXT loop n times, the start and end values would
  3357.    normally be 1 and n. This is not a necessity, though. They can have any
  3358.    two values that differ by n - 1. For example, using -2 and 2 would also
  3359.    cause five repetitions.
  3360.  
  3361.    The counter can be the subscript variable for an array. (Accessing each
  3362.    element in an array is a common use for a FOR...NEXT loop.) The next
  3363.    example prompts the user for the high temperature on each day in July:
  3364.  
  3365.    DIM july!(31)
  3366.  
  3367.    FOR date% = 1 TO 31
  3368.        PRINT "enter the high temp for July"; date%;
  3369.        INPUT " ", july!(date%)
  3370.    NEXT date%
  3371.  
  3372.    Neither the start nor the end value has to be a constant; either or both
  3373.    can be a variable. The following example requests start and end values,
  3374.    then prints out the square root of every value in that range:
  3375.  
  3376.    INPUT "starting value? ", startval%
  3377.    INPUT "ending   value? ", endval%
  3378.    FOR count% = startval% TO endval%
  3379.        PRINT "the square root of"; count%; "is"; SQR(count%)
  3380.    NEXT count%
  3381.  
  3382.    The increment defaults to a value of one if it isn't specified. The STEP
  3383.    statement sets a different increment value, as shown in the following
  3384.    procedure:
  3385.  
  3386.    1. Choose the File menu's New Program command to clear the View window.
  3387.  
  3388.    2. Type the following example in the View window:
  3389.  
  3390.       FOR count% = 5 TO 1 STEP -1
  3391.          PRINT "this line is printed 5 times; this is time"; count%
  3392.       NEXT count%
  3393.  
  3394.    3. Choose the Run menu's Start command.
  3395.  
  3396.       The output should look like the following:
  3397.  
  3398.       this line is printed 5 times; this is time 5
  3399.       this line is printed 5 times; this is time 4
  3400.       this line is printed 5 times; this is time 3
  3401.       this line is printed 5 times; this is time 2
  3402.       this line is printed 5 times; this is time 1
  3403.  
  3404.    4. Type CLS in the Immediate window, then press ENTER to clear the output
  3405.       screen.
  3406.  
  3407.    The step value must be consistent with the start and end values. If the
  3408.    end value is larger than the start value, the step must be positive. If
  3409.    the end value is smaller than the start value, the step must be negative.
  3410.    If the step has the wrong sign, the FOR...NEXT loop doesn't execute even
  3411.    once; it is skipped over.
  3412.  
  3413.  The DO...LOOP
  3414.  
  3415.    You have just seen one way to repeat a section of the program, the
  3416.    FOR...NEXT loop. The FOR...NEXT loop, however, has a serious limitation.
  3417.    Although you can specify the starting and ending points, the loop itself
  3418.    is fixed; it repeats a specific number of times, no more and no less.
  3419.  
  3420.    This caused no problem in the example where you were prompted for the 31
  3421.    high temperatures in July, because July always has 31 days. However, there
  3422.    are times you can't know how often to repeat a calculation or an
  3423.    operation.
  3424.  
  3425.    Suppose you were searching through text, one line at a time, for a
  3426.    specific word. You don't know which line the word is on (if you did, you
  3427.    wouldn't have to search), so you can't specify the number of times to go
  3428.    through a FOR...NEXT loop. You need a flexible (rather than fixed) way to
  3429.    repeat groups of program statements.
  3430.  
  3431.    The DO...LOOP is the more flexible mechanism for repetition needed here.
  3432.    Program statements between the DO and LOOP keywords are repeated an
  3433.    indefinite number of times. Try the following example:
  3434.  
  3435.    1. Choose the File menu's New Program command to clear the View window:
  3436.  
  3437.    2. Type the following example in the View window.
  3438.  
  3439.       DO
  3440.          PRINT "Going around in circles..."
  3441.       LOOP
  3442.  
  3443.    3. Choose the Run menu's Start command.
  3444.  
  3445.       Going around in circles... is printed over and over, without end. (To
  3446.       stop the program, press CTRL+BREAK.)
  3447.  
  3448.    4. Type CLS in the Immediate window and press ENTER to clear the output
  3449.       screen.
  3450.  
  3451.    The simple DO...LOOP shown above is endless. BASIC has a way to terminate
  3452.    the loop at the right time. All you have to do is specify the logical
  3453.    condition you want to cause termination.
  3454.  
  3455.    One way to do this is to use a WHILE condition, which tells the computer
  3456.    to continue executing the loop WHILE some condition is true. Another is to
  3457.    use an UNTIL condition, meaning continue executing the loop UNTIL some
  3458.    condition becomes true.
  3459.  
  3460.    In a DO WHILE loop, the condition starts off true, and the loop executes
  3461.    as long as the condition remains true. In a DO UNTIL loop, the condition
  3462.    starts off false, and the loop executes until the condition becomes true.
  3463.  
  3464.    The user-defined condition is a Boolean expression. This expression
  3465.    usually compares a variable with a constant. When the expression satisfies
  3466.    the logical condition set by the programmer (such as the variable
  3467.    equalling the constant), the loop terminates. (Any comparison is possible,
  3468.    but comparing the loop variable with a number or string is the most
  3469.    common.)
  3470.  
  3471.    The DO WHILE Loop
  3472.  
  3473.    A DO WHILE loop looks like this:
  3474.  
  3475.    DO WHILE booleanexpression
  3476.       statements to be repeated
  3477.    LOOP
  3478.  
  3479.    Here is a simple DO WHILE loop that demonstrates how such a loop operates.
  3480.    The loop termination condition is for big! to equal little!.
  3481.  
  3482.    big! = 256.0
  3483.    little! = 1.0
  3484.    DO WHILE big! <> little!
  3485.       PRINT "big ="; big!; "  little ="; little!
  3486.       big! = big! / 2.0
  3487.       little! = little! * 2.0
  3488.    LOOP
  3489.  
  3490.    Two variables, big! and little!, are initialized outside the loop. Within
  3491.    the loop, their values are first printed, then big! is divided by 2 and
  3492.    little! is multiplied by 2. The process repeats until both are equal to 16
  3493.    and the loop terminates.
  3494.  
  3495.    The initial values of big! and little! were chosen to guarantee that they
  3496.    would eventually be equal. If they are not so chosen, the loop repeats
  3497.    indefinitely. (In practice, the program eventually stops regardless of the
  3498.    values chosen. The variable little! is repeatedly doubled, ultimately
  3499.    becoming so large that its value cannot be represented by a BASIC
  3500.    floating-point variable. The program then halts, displaying an Overflow
  3501.    error message.)
  3502.  
  3503.    Please note that for a DO WHILE loop to execute even once, the Boolean
  3504.    expression must be true. If big! and little! started with the same value,
  3505.    the expression big! <> little! would be false, and the loop would not
  3506.    execute at all; it would be skipped over. Always be sure the variables in
  3507.    the Boolean expression have the values you really want before entering the
  3508.    loop.
  3509.  
  3510.    The DO UNTIL Loop
  3511.  
  3512.    A DO UNTIL loop is identical in form to a DO WHILE loop, except it uses
  3513.    the keyword UNTIL:
  3514.  
  3515.    DO UNTIL booleanexpression
  3516.       statements to be repeated
  3517.    LOOP
  3518.  
  3519.    The loop shown in the last example could also have been written using
  3520.    UNTIL, as shown here:
  3521.  
  3522.    big! = 256.0
  3523.    little! = 1.0
  3524.    DO UNTIL big! = little!
  3525.       PRINT "big ="; big!; "  little ="; little!
  3526.       big! = big! / 2.0
  3527.       little! = little! * 2.0
  3528.    LOOP
  3529.  
  3530.    A DO UNTIL loop continues until the Boolean expression becomes true, so a
  3531.    different terminating condition is needed. In this case, it is the
  3532.    opposite of the condition in the DO WHILE example above: big! = little!.
  3533.  
  3534.    The following is a more practical example of a DO...LOOP. The user is
  3535.    repeatedly prompted for a Yes / No response (indicated by Y or N) until it
  3536.    is supplied:
  3537.  
  3538.    DO UNTIL instring$ = "Y" OR instring$ = "N"
  3539.       INPUT "enter Yes or No (Y/N): ", instring$
  3540.    LOOP
  3541.    PRINT "You typed"; instring$
  3542.  
  3543.    Note that y and n are not accepted, since instring$ is compared only with
  3544.    uppercase characters.
  3545.  
  3546.    ──────────────────────────────────────────────────────────────────────────
  3547.    NOTE
  3548.      In the loop examples given, both the WHILE and UNTIL statements are
  3549.      located after DO. It is also possible to place them following the LOOP
  3550.      keyword. When that is done, the statements in the loop are executed
  3551.      first, then the condition is tested. This assures that the loop will
  3552.      always be executed at least once. See Chapter 1, "Control-Flow
  3553.      Structures," in Programming in BASIC, for an explanation of how this
  3554.      works.
  3555.    ──────────────────────────────────────────────────────────────────────────
  3556.  
  3557.  
  3558.  Writing a Simple BASIC Program
  3559.  
  3560.    If you've worked through the examples, you should now know the
  3561.    fundamentals of programming in BASIC. To demonstrate your understanding,
  3562.    try writing the simple program described below.
  3563.  
  3564.    The program computes the average of several numbers. It could be written
  3565.    in the following sequence:
  3566.  
  3567.    1. Prompt the user for the quantity of numbers to be averaged.
  3568.  
  3569.    2. If the quantity is zero or negative, print a warning message and do
  3570.       nothing else.
  3571.  
  3572.    3. If the quantity is positive, pick a variable name for the running total
  3573.       and set it equal to zero.
  3574.  
  3575.    4. Prompt for the numbers, one at a time. Tell the user each time which
  3576.       value is being entered (number 1, number 2, and so on).
  3577.  
  3578.    5. When all the numbers have been entered, compute and print the average
  3579.       value.
  3580.  
  3581.    This program uses only BASIC language elements that have been explained in
  3582.    this chapter, and no programming "tricks" are needed. A solution is given
  3583.    below, but please try to create your own program before peeking. This is
  3584.    an "open-book" project. If you get stuck, simply reread this chapter to
  3585.    find the program statements you need and to see how they are used.
  3586.  
  3587.    There are many ways to write a program. If your program works, it's
  3588.    correct, even if it differs from the program given here.
  3589.  
  3590.    INPUT "How many numbers do you wish to average? ", howmany%
  3591.  
  3592.    IF howmany% <= 0 THEN
  3593.       PRINT "Not a valid quantity; must be greater than 0."
  3594.    ELSE
  3595.       total! = 0.0                   ' Set running total to zero.
  3596.       FOR count% = 1 TO howmany%
  3597.           PRINT "number"; count%;
  3598.           INPUT " ", value!
  3599.           total! = total! + value!
  3600.    ' Add next value to total.
  3601.       NEXT count%
  3602.       PRINT "The average value is"; total! / howmany%
  3603.    END IF
  3604.  
  3605.  
  3606.  For More Information
  3607.  
  3608.    Now you know how to write simple programs in BASIC. There is, however, a
  3609.    great deal more to BASIC programming.
  3610.  
  3611.    QuickBASIC's manuals and on-line help provide complete information on
  3612.    using the QuickBASIC environment and each of the QuickBASIC statements and
  3613.    functions. However, the documentation does not include a complete
  3614.    introduction to BASIC, and does not teach the general principles of
  3615.    programming, or how to use DOS. The following books contain more
  3616.    information on those subjects. They are listed for your convenience only.
  3617.    With the exception of its own publications, Microsoft Corporation neither
  3618.    endorses these books nor recommends them over others on the same subjects.
  3619.  
  3620.  Books about BASIC
  3621.  
  3622.    Craig, John Clark. Microsoft QuickBASIC Programmer's Toolbox. Redmond,
  3623.    Wash.: Microsoft Press, 1988.
  3624.  
  3625.    Dwyer, Thomas A., and Margot Critchfield. BASIC and the Personal Computer.
  3626.    Reading, Mass.: Addison-Wesley Publishing Co., 1978.
  3627.  
  3628.    Enders, Bernd, and Bob Petersen. BASIC Primer for the IBM PC & XT. New
  3629.    York, N.Y.: New American Library, 1984.
  3630.  
  3631.    Feldman, Phil, and Tom Rugg. Using QuickBASIC 4. Carmel, Ind.: Que
  3632.    Corporation, 1988.
  3633.  
  3634.    Hergert, Douglas. Microsoft QuickBASIC. 2d ed. Redmond, Wash.: Microsoft
  3635.    Press, 1988
  3636.  
  3637.    The first edition of this book discusses programming techniques
  3638.    appropriate for QuickBASIC Versions 2.0 and 3.0. Use the second edition
  3639.    for information on programming in QuickBASIC Version 4.0.
  3640.  
  3641.    Inman, Don, and Bob Albrecht. Using QuickBASIC. Berkeley, Cal.: Osborne
  3642.    McGraw-Hill, 1988.
  3643.  
  3644.  Books about DOS
  3645.  
  3646.    Duncan, Ray. Advanced MS-DOS. Redmond, Wash.: Microsoft Press, 1986.
  3647.  
  3648.    Wolverton, Van. Running MS-DOS. 2d ed. Redmond, Wash.: Microsoft Press,
  3649.    1985.
  3650.  
  3651.    Wolverton, Van. Supercharging MS-DOS. Redmond, Wash.: Microsoft Press,
  3652.    1986.
  3653.  
  3654.  
  3655.  
  3656.  ────────────────────────────────────────────────────────────────────────────
  3657.  PART 2  HANDS ON WITH QUICKBASIC
  3658.  ────────────────────────────────────────────────────────────────────────────
  3659.  
  3660.    Part 2, "Hands On with QuickBASIC" is a tutorial in which you finish a
  3661.    real application program, QCARDS.BAS. Although QCARDS is a model of good
  3662.    structured programming, the purpose of the tutorial is to introduce the
  3663.    Microsoft QuickBASIC environment, rather than teach programming
  3664.    techniques. The comments that describe each code block may be all you need
  3665.    to understand the programming, but you don't have to understand the
  3666.    programming concepts used in each section before moving on to the next.
  3667.    When you finish the tutorial, you will have used three of QuickBASIC's
  3668.    most sophisticated features──the smart editor, on-line help, and
  3669.    debugging──in real programming situations. Then you can review the program
  3670.    comments and code and use QuickBASIC's on-line help and debugging features
  3671.    to understand how each block works.
  3672.  
  3673.    Chapter 5 describes the structure of QCARDS, previews its interface, and
  3674.    shows you how to enter a SUB...END SUB procedure. In Chapter 6 you'll see
  3675.    how the smart editor helps catch and correct programming errors as you
  3676.    enter code. Chapters 7 and 8 give you practice in using on-line help the
  3677.    way you will use it while writing your own programs. In Chapter 9 you
  3678.    will track and fix a bug so QCARDS will run correctly. At the end of
  3679.    Chapter 9, QCARDS is fully functional and ready to use.
  3680.  
  3681.  
  3682.  
  3683.  ────────────────────────────────────────────────────────────────────────────
  3684.  Chapter 5  The QCARDS Program
  3685.  
  3686.    This chapter describes QCARDS.BAS, the program on which the rest of the
  3687.    tutorial on QuickBASIC is based. You'll add some code in the form of a
  3688.    "procedure," a routine you write once and then call from different parts
  3689.    of the program, to perform a specific task. In this chapter, you will
  3690.  
  3691.    ■ Load a program at the same time you invoke QuickBASIC
  3692.  
  3693.    ■ Browse through the QCARDS.BAS code
  3694.  
  3695.    ■ Call procedures from the Immediate window
  3696.  
  3697.    ■ Create and call a SUB procedure
  3698.  
  3699.    This chapter takes about one hour to complete.
  3700.  
  3701.  
  3702.  Building QCARDS
  3703.  
  3704.    As you work through the QuickBASIC tutorial in Chapters 5-9, you'll add
  3705.    lines of code to the QCARDS program. The code-entry sequences that are
  3706.    part of QCARDS appear under special headings, so you know which ones are
  3707.    necessary for finishing the tutorial program. You can save your work as
  3708.    you finish each numbered sequence. If you make a mistake during a
  3709.    code-entry sequence, just reload the previous saved version and repeat the
  3710.    current sequence.
  3711.  
  3712.    ──────────────────────────────────────────────────────────────────────────
  3713.    NOTE
  3714.      As you browse through QCARDS, you may notice some errors in the code.
  3715.      These errors are intentional. You will fix them as you work through the
  3716.      tutorial.
  3717.    ──────────────────────────────────────────────────────────────────────────
  3718.  
  3719.  
  3720.  Loading a Program When You Start QuickBASIC
  3721.  
  3722.    You can start QuickBASIC and load a program at the same time by including
  3723.    the program name as a command-line "argument." An "argument" is
  3724.    information you supply to a command to modify the command.
  3725.  
  3726.    ──────────────────────────────────────────────────────────────────────────
  3727.    NOTE
  3728.      If you don't have a hard disk, copy the files QCARDS.BAS and QCARDS.DAT
  3729.      to an empty removable disk and use that disk to complete the tutorial.
  3730.    ──────────────────────────────────────────────────────────────────────────
  3731.  
  3732.    Type the following line at the DOS prompt to start QuickBASIC and have it
  3733.    automatically load QCARDS.BAS:
  3734.  
  3735.      qb qcards
  3736.  
  3737.    When you start QuickBASIC this way, QuickBASIC searches the current
  3738.    working directory for a file with the name QCARDS and the extension .BAS.
  3739.    If QuickBASIC finds the file, it loads it. If the file is not found,
  3740.    QuickBASIC assumes you are starting a new program that you want to name
  3741.    QCARDS.BAS.
  3742.  
  3743.  
  3744.  A Quick Tour of QCARDS
  3745.  
  3746.    If you completed the computer-based training called QB Express, you'll
  3747.    recognize some of QCARDS. In Chapters 5-9 you'll work with the real
  3748.    QCARDS code.
  3749.  
  3750.    If you are new to programming, some of this material may seem difficult
  3751.    because QCARDS is a real application program. Don't worry──you don't need
  3752.    to master all the material in each section before moving on. This tutorial
  3753.    is designed to teach the programming tools of the QuickBASIC environment,
  3754.    not programming techniques.
  3755.  
  3756.    Even if you have programmed in BASIC before, you may learn some powerful
  3757.    techniques because QCARDS is a structured program that uses procedures. In
  3758.    fact, if you have used a BASIC interpreter (like GW-BASIC(R) or BASICA),
  3759.    you're in for a pleasant surprise.
  3760.  
  3761.  The QCARDS Program
  3762.  
  3763.    QCARDS is a database program. It provides a convenient way to work with
  3764.    many small collections of information (called records), which are stored
  3765.    together in a disk file. QCARDS manages the disk file──opening and closing
  3766.    it and updating the records as you modify, add, or delete specific pieces
  3767.    of information or whole records. The fun part of QCARDS is the
  3768.    "interface," the part of the program where the user interacts with QCARDS
  3769.    (see Figure 5.1).
  3770.  
  3771.  
  3772.                  ┌Records have fields
  3773.                  │such as street and city                       QCARDS' help┐
  3774.      ┌───────────┼──────────────────────────────────────────────────────────┼┐
  3775.      │           │                                                          ││
  3776.      │           │                                                          ││
  3777.      │           ├─────────────────────────────────────┐                    ││
  3778.      │         ┌─┼───────────────────────────────────┐═╡                  ┐ ││
  3779.      │       ┌─┴─┼─────────────────────────────────┐═╡ │Select card with: │ ││
  3780.      │     ┌─┴───┼───────────────────────────────┐═╡ │ │       UP         │ ││
  3781.      │ ┌─┌─┴─────┼─────────────────────────────┐═╡ │ │ │       DOWN       │ ││
  3782.      │ │ ╞═══════╪═════════════════════════════╡ │ │ │ │       PGUP       ├─┘│
  3783.      │ │ │Note:  │_____________________________│ │ │ ├─┘       PGDN       │  │
  3784.    ┌─┼─│ │Birth: │__/__/__  Phone: ___-___-____│ │ ├─┘         HOME       │  │
  3785.    │ │ │ │Street:│\____________________________│ ├─┘           END        │  │
  3786.    │ │ │ │City: ___________ ST: ___ Zip: _____├─┘                        ┘  │
  3787.    │ │ └ └─────────────────────────────────────┘                             │
  3788.    │ │                                                                ┐      │
  3789.    │ │Edit Top  Add New  Copy to New  Delete  Find  Sort  Print  Quit ├──┐   │
  3790.    │ │                                                                ┘  │   │
  3791.    │ └───────────────────────────────────────────────────────────────────┼───┘
  3792.    └──Each card represents a record.                QCARDS' command line─┘
  3793.  
  3794.    Figure 5.1  QCARDS' Interface
  3795.  
  3796.    QCARDS uses the concept of an index-card file to present the data in a
  3797.    familiar way. Each card that appears on screen represents a record in the
  3798.    database. Each card has several "fields" (separate areas on the card) that
  3799.    are used to enter new data or change and reorder existing data.
  3800.  
  3801.    Once you understand QCARDS, you can modify the data (and the program
  3802.    itself) and use it for any kind of information you wish to store. QCARDS
  3803.    is a large program, but it is organized according to structured
  3804.    programming principles (that is, it divides complicated tasks into simpler
  3805.    ones). This means you can learn its programming techniques gradually. As
  3806.    you read the next few sections, scroll down through QCARDS as each part is
  3807.    described.
  3808.  
  3809.  Declarations and Definitions
  3810.  
  3811.    QCARDS begins with a short section describing its purpose. Next comes a
  3812.    section of declarations and definitions. The declarations and definitions
  3813.    use statements like DEFINT, CONST, TYPE...END TYPE, DECLARE, DIM, and
  3814.    REDIM. They let QuickBASIC anticipate the amount of space to reserve in
  3815.    memory for the program's variables. For example,DEFINT A-Z tells
  3816.    QuickBASIC that any variable for which a data type is not explicitly
  3817.    declared should be considered an integer.
  3818.  
  3819.    CONST statements improve program readability by giving descriptive names
  3820.    to values the computer regards only as numbers. For example, the value 0
  3821.    (zero) represents the logical condition "false" in QuickBASIC. At about
  3822.    line 45, a CONST statement defines the symbolic constant FALSE as the
  3823.    value zero. This lets you use the word FALSE to represent the value 0 in
  3824.    logical comparisons.
  3825.  
  3826.    TYPE...END TYPE constructions declare "aggregate" data types. Aggregate
  3827.    data types are those that can include both strings and all types of
  3828.    numeric values. For example, once the PERSON data type is declared (at
  3829.    about line 56), you can define variables to have this user-defined type.
  3830.  
  3831.    Lines that begin with the DECLARE statement allow QuickBASIC to check
  3832.    procedure calls to make sure you use them correctly.
  3833.  
  3834.  Comments
  3835.  
  3836.    After the declarations and definitions comes a large section that contains
  3837.    mostly comments. Each comment block describes a block of executable
  3838.    statements that you will enter as you complete QCARDS. The statements
  3839.    define the program's overall flow of control. This section of QCARDS
  3840.    concludes with an END statement to mark the end of the program's normal
  3841.    execution sequence.
  3842.  
  3843.  Statements Following the END Statement
  3844.  
  3845.    The final section of the program starts after the END statement. Each
  3846.    group of statements in this section is preceded by a "label," a name
  3847.    followed by a colon. (A QuickBASIC label is similar to line numbers in
  3848.    BASIC interpreters.) The statements associated with these labels are
  3849.    executed only if other statements (that contain references to the labels)
  3850.    are executed. The first label (MemoryErr) labels an error handler. If a
  3851.    certain type of error occurs during execution of QCARDS, the statements
  3852.    following MemoryErr display a message on the screen, then end the program.
  3853.    The remaining labeled sections contain DATA statements that are executed
  3854.    when the index cards are drawn on the screen.
  3855.  
  3856.  Calling QCARDS Procedures from the Immediate Window
  3857.  
  3858.    There are two levels of programming in QCARDS. The module level contains
  3859.    the program's most general logic. The procedure level contains many
  3860.    individual procedures that do the program's detailed work.
  3861.  
  3862.    Just as you can use the Immediate Window to see the effects of a BASIC
  3863.    statement, you can use it to call a program's procedures. This lets you
  3864.    see the effects of a procedure without running the entire program. Each
  3865.    procedure performs a specific task. The following steps illustrate how to
  3866.    call procedures that display the QCARDS user interface on the output
  3867.    screen:
  3868.  
  3869.    1. Press F6 to move the cursor into the Immediate window.
  3870.  
  3871.    2. Type CLS and press ENTER to clear the output screen. Then press a key
  3872.       to return the cursor to the Immediate window.
  3873.  
  3874.    3. Type CALL DrawCards and press ENTER.
  3875.  
  3876.       QuickBASIC executes the DrawCards procedure. Calling a procedure is
  3877.       just like executing a BASIC statement. The procedure performs its task,
  3878.       then QuickBASIC waits for the next instruction.
  3879.  
  3880.    4. Press a key to return to the Immediate window, then type the following
  3881.       on the next line in the Immediate window, exactly as shown:
  3882.  
  3883.       CALL ShowCmdLine  : DO : LOOP
  3884.  
  3885.    5. Press ENTER to execute the line you just typed.
  3886.  
  3887.       The ShowCmdLine procedure adds the QCARDS command line to the parts
  3888.       already displayed. This time, however, QuickBASIC does not immediately
  3889.       display the
  3890.  
  3891.       Press any key to continue
  3892.  
  3893.       prompt, because the DO and LOOP statements following ShowCmdLine create
  3894.       an unconditional loop (that is, an infinite loop).
  3895.  
  3896.  Breaking an Unconditional Loop from QCARDS
  3897.  
  3898.    While building QCARDS, you will need to escape from unconditional loops
  3899.    because QCARDS does not yet respond to key presses. However, QuickBASIC
  3900.    checks for one particular key-press combination, CTRL+BREAK, which lets
  3901.    you break out of an infinite loop and return to the QuickBASIC
  3902.    environment. Note that when you finish adding code to QCARDS, a user will
  3903.    be able to press any of the high-intensity letters on the QCARDS command
  3904.    line to execute commands. For example, the Q key will terminate the
  3905.    program and return control to QuickBASIC because QCARDS will check each
  3906.    key the user presses and carry out the requested action. Try this to break
  3907.    an unconditional loop:
  3908.  
  3909.      Press CTRL+BREAK to return control to QuickBASIC.
  3910.  
  3911.       Notice that when you press CTRL+BREAK, the cursor does not return to
  3912.       the Immediate window (where the last statement you executed is
  3913.       located). Instead, it is placed in the View window.
  3914.  
  3915.  The Module-Level Code
  3916.  
  3917.    Every QuickBASIC program has a module level──it's what QuickBASIC displays
  3918.    in the View window when you first open the program. Most of the code you
  3919.    will add to QCARDS is called "module-level code." It uses BASIC statements
  3920.    and functions (in combination with QCARDS procedures), to carry out the
  3921.    program's tasks, which are described in the comments. The module-level
  3922.    code you add to QCARDS defines the general way QCARDS interacts with the
  3923.    user.
  3924.  
  3925.  Structured Programming with Procedures
  3926.  
  3927.    You can write programs that have only a module level. However, the details
  3928.    of each task can obscure the general program logic, making the program
  3929.    difficult to understand, debug, and enhance. For ease of understanding and
  3930.    debugging, QCARDS delegates most processing tasks to procedures (such as
  3931.    DrawCards and ShowCmdLine) that are called when their tasks need to be
  3932.    performed. Figure 5.2 illustrates the relationship between module-level
  3933.    code and procedures and their execution sequences.
  3934.  
  3935.  
  3936.      ┌──────────────────────────────────────────────────────────────────────┐
  3937.    ┌─│                        PROGRAM.BAS Module                            │─
  3938.    │ └──────────────────────────────────────────────────────────────────────┘
  3939.    │   ┌───────────────────────────┐        ┌──────────────────────────────┐
  3940.    │ ┌─│     Module-Level Code     ├─┐    ┌─┤     Procedure-Level Code     ├┐
  3941.    │ │ └───────────────────────────┘ │    │ └──────────────────────────────┘│
  3942.    │ │                               │    │                                 │
  3943.    │ │ (Definitions and declarations)│    │                                 │
  3944.    │ │  ∙                            │    │                                 │
  3945.    │ │  ∙                            │    │                                 │
  3946.    │ │  ∙                            │    │                                 │
  3947.    │ │ (General execution sequence)  \\  \\                                 │
  3948.    │ │  ∙                                                                   │
  3949.    │ │  ∙                                                                   │
  3950.    │ │  ∙                                   ┌────────────────────────┐      │
  3951.    │ │ CALL Procedure1 ════════════════════│SUB Procedure1          │      │
  3952.    │ │  ∙═══════════════════════════════╗  │ ∙                      │      │
  3953.    │ │  ∙                                ║  │ ∙                      │      │
  3954.    │ │  ∙                                ║  │ ∙                      │      │
  3955.    │ │ Return Value=Procedure2═════╗     ║  │ReturnValue=Procedure2 ─┼─┐    │
  3956.    │ │  ∙═══════════════════╗     ║     ║  │ ∙─────────────────────┼─┼──┐ │
  3957.    │ │  ∙                    ║     ║     ║  │ ∙                      │ │  │ │
  3958.    │ │  ∙                    ║     ║     ║  │ ∙                      │ │  │ │
  3959.    │ │                       ║     ║     ╚══│END SUB                 │ │  │ │
  3960.    │ │                       ║     ║        └────────────────────────┘ │  │ │
  3961.    │ │                       ║     ║        ┌────────────────────────┐ │  │ │
  3962.    │ │                       ║     ╚═══════│FUNCTION Procedure2     │┘  │ │
  3963.    │ │                       ║              │ ∙                      │    │ │
  3964.    │ │                       ║              │ ∙                      │    │ │
  3965.    │ │                       ║              │ ∙                      │    │ │
  3966.    │ │                       ║              │Procedure2=returnval    │    │ │
  3967.    │ │                       ║              │ ∙                      │    │ │
  3968.    │ │                       ║              │ ∙                      │    │ │
  3969.    │ │                       ║              │ ∙                      │    │ │
  3970.    │ │                       ╚══════════════│END FUNCTION ───────────┼────┘ │
  3971.    │ │                                      └────────────────────────┘      │
  3972.    │ │                                                                      │
  3973.    │ │ END                           //  // ┌────────────────────────┐      │
  3974.    │ │ (Error handlers and labeled   │    │ │Any number of other SUB │      │
  3975.    │ │  data)                        │    │ │and FUNCTION procedures │      │
  3976.    │ │ ∙                             │    │ │called from module-level│      │
  3977.    │ │ ∙                             │    │ │code and from each other│      │
  3978.    │ │ ∙                             │    │ └────────────────────────┘      │
  3979.    │ │                               │    │                                 │
  3980.    │ └───────────────────────────────┘    └─────────────────────────────────┘
  3981.    └──────────────────────────────────────────────────────────────────────────
  3982.  
  3983.    Figure 5.2  Modules and Procedures
  3984.  
  3985.    A procedure is usually a group of statements that performs a single task.
  3986.    Procedures are saved as part of the same disk file as the module-level
  3987.    code. However, QuickBASIC treats procedures as logically self-contained
  3988.    entities, separate from the module-level code and from each other.
  3989.    Although every program has a module level, a procedure level does not
  3990.    exist until a procedure is actually defined. QuickBASIC executes the
  3991.    statements in a procedure only if the procedure is explicitly invoked. You
  3992.    can invoke procedures from the module-level code, from other procedures,
  3993.    or from the Immediate window.
  3994.  
  3995.  A Profile of the Parts of the Program
  3996.  
  3997.    Even though they are all in the same disk file, QuickBASIC keeps a
  3998.    program's procedures separate from the module-level code and from each
  3999.    other. Therefore, you can't have a procedure and module-level code (or two
  4000.    procedures) in the same window at the same time. To edit these different
  4001.    parts of a program, you move them in and out of the View window using the
  4002.    View menu's SUBs command. The SUBs dialog box lists all the procedures in
  4003.    a program. Try the following to see a profile of all the parts of QCARDS:
  4004.  
  4005.    1. Press ALT+V, then press S to choose the View menu's SUBs command.
  4006.  
  4007.       The SUBs dialog box lets you access all parts of your program (see
  4008.       Figure 5.3). The first entry, QCARDS.BAS, is a file name. It
  4009.       represents the program's module-level code.
  4010.  
  4011.  
  4012.       Name of module containing                    Procedures are indented
  4013.       procedures indented below it                 beneath module name.
  4014.        │                                                  │
  4015.       ┌┼───────────────────────────────── SUBs ───────────┼───────────────────
  4016.       ││                                                  │
  4017.       ││Choose program item to edit                       │
  4018.       ││┌─────────────────────────────────────────────────┼───────────────────
  4019.       │└┼ QCARDS.BAS              PrintLabel              │
  4020.       │ │   AsciiKey              Prompt                  │
  4021.       │ │   CleanUp               SelectField             │
  4022.       │ │   ClearHelp             ShowCards ──────────────┘
  4023.       │ │   DrawCards             ShowCmdLine
  4024.       │ │   EditCard              ShowEditHelp
  4025.       │ │   EditString            ShowTopCard
  4026.       │ │   FindCard              ShowViewHelp
  4027.       │ │   InitIndex             SortIndex
  4028.       │ └─▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  4029.       │┌QCARDS.BAS is the Main Module
  4030.       ││
  4031.       ││  < Edit in Active >                                     < Cancel >
  4032.       ├┼──────────────────────────────────────────────────────────────────────
  4033.       ││   < Delete > ───────────────────┐                        < Help >
  4034.       └┼─────────────────────────────────┼────────────────────────────────────
  4035.        │                                 │
  4036.       Describes the                   Deletes a file from a program,
  4037.       selected item                   or a procedure from its file
  4038.  
  4039.       Figure 5.3  SUBs Dialog Box
  4040.  
  4041.    2. Press DOWN to select the first entry beneath QCARDS.BAS.
  4042.  
  4043.       The first entry beneath QCARDS.BAS is AsciiKey. Each entry indented
  4044.       beneath QCARDS.BAS represents a SUB or FUNCTION procedure used by the
  4045.       program. All these procedures are saved in the QCARDS.BAS disk file.
  4046.  
  4047.    3. Select the DrawCards procedure and press ENTER.
  4048.  
  4049.       QuickBASIC displays the code of the DrawCards procedure in the View
  4050.       window. Note that the View window's title bar contains
  4051.  
  4052.       QCARDS.BAS:DrawCards
  4053.  
  4054.       Use DIRECTION keys to scroll around in DrawCards. Its text is the only
  4055.       text in the View window.
  4056.  
  4057.    4. Press ALT+V, then press S to choose the View Menu's SUBs command and
  4058.       select QCARDS.BAS if it is not already selected.
  4059.  
  4060.    5. Press ENTER to return the module-level code to the View window.
  4061.  
  4062.    QuickBASIC lets you define two types of procedures: SUB and FUNCTION
  4063.    procedures. To include the code of a procedure in your program's execution
  4064.    sequence, place its name wherever you want its task performed. You invoke
  4065.    a SUB procedure by using its name in a CALL statement. FUNCTION procedures
  4066.    are used the way QuickBASIC's intrinsic functions (like TIME$) are.
  4067.    Procedures are an effective way to code tasks that are performed
  4068.    repeatedly.
  4069.  
  4070.  Defining a Procedure in QCARDS
  4071.  
  4072.    You can start learning about procedures by writing simple ones. Do the
  4073.    following to see how QuickBASIC automatically segregates each procedure
  4074.    from the rest of the program. It also shows you how to define and call a
  4075.    simple procedure that you'll use later in QCARDS.
  4076.  
  4077.    QCARDS Code Entry 1
  4078.  
  4079.    1. Place the cursor at a blank line at the end of the declarations and
  4080.       definitions section in the View window (about line 102).
  4081.  
  4082.    2. Press ENTER to create another blank line.
  4083.  
  4084.    3. Type the words SUB Alarm and press ENTER.
  4085.  
  4086.       QuickBASIC opens a new window and starts the procedure with the
  4087.       statements SUB Alarm and END SUB. The statement DEFINT A-Z appears
  4088.       above the SUB statement because when you create a procedure, it
  4089.       inherits the default data type of the module-level code.
  4090.  
  4091.       The title bar in the View window now contains the name of the module
  4092.       (QCARDS.BAS) plus Alarm, the name of the procedure in the View window.
  4093.  
  4094.    4. Type the following comment and code blocks, exactly as shown, between
  4095.       the SUB and END SUB statements:
  4096.  
  4097.       ' The Alarm procedure uses the SOUND statement to send signals
  4098.       ' to the computer's speaker and sound an alarm.
  4099.       '
  4100.       '
  4101.       ' Parameters: None
  4102.       '
  4103.       ' Output: Sends an alarm to the user
  4104.  
  4105.       ' Change the numbers to vary the sound.
  4106.       FOR Tone = 600 TO 2000 STEP 40
  4107.           SOUND Tone, Tone / 7000
  4108.       NEXT Tone
  4109.  
  4110.       You can test the procedure and see what it does by calling it from the
  4111.       Immediate window.
  4112.  
  4113.    5. Move the cursor to the Immediate window. Then type CALL Alarm and press
  4114.       ENTER.
  4115.  
  4116.  
  4117.  Saving Edited Text
  4118.  
  4119.    From now on, each time you save your work you will save the program with
  4120.    the name of the current chapter. When you save a program with a different
  4121.    name, the old version (QCARDS.BAS, in this case) still exists unchanged on
  4122.    disk. Therefore, if something makes a succeeding version of the program
  4123.    unusable, you can reload the previous version of the program and start
  4124.    over again.
  4125.  
  4126.    QCARDS Code Entry 2
  4127.  
  4128.    1. Press ALT+F, then press A to choose the File menu's Save As command.
  4129.  
  4130.       The Save As dialog box appears (see Figure 5.4).
  4131.  
  4132.  
  4133.                        ┌─Type your program name here
  4134.                        │
  4135.       ┌────────────────┼───── Save As ──────────────────┐
  4136.       │                │                                │
  4137.       │             ┌──┴───────────────────────────────┐│
  4138.       │ File Name:  │                                  ││
  4139.       │             └──────────────────────────────────┘│
  4140.       │ C:\QB4.5\DEMO                                   │
  4141.       │                                                 │
  4142.       │   Dirs/Drives                                   │
  4143.       │ ┌──────────────┐      ┌─────── Format ────────┐ │
  4144.       │ │..                  │ (∙) QuickBASIC -      │ │
  4145.       │ │SOURCE        ░      │      Fast Load and    │ │
  4146.       │ │[-A-]         ░      │      Save             │ │
  4147.       │ │[-B-]         ░      │                       │ │
  4148.       │ │[-C-]         ░      │ ( ) Text -            │ │
  4149.       │ │[-U-]         ░      │      Readable by      │ │
  4150.       │ │[-Z-]               │      Other Programs   │ │
  4151.       │ └──────────────┘      └───────────────────────┘ │
  4152.       ├─────────────────────────────────────────────────┤
  4153.       │      < OK >            < Cancel >     < Help >  │
  4154.       └─────────────────────────────────────────────────┘
  4155.  
  4156.       Figure 5.4  Save As Dialog Box
  4157.  
  4158.    2. Type the name chapter5 in the text box and press ENTER.
  4159.  
  4160.       This saves the program QCARDS.BAS as CHAPTER5.BAS on disk. The Alarm
  4161.       procedure that you created is saved as part of CHAPTER5.BAS.
  4162.  
  4163.  
  4164.  For More Information
  4165.  
  4166.    For more information on the topics covered in this chapter, see the
  4167.    following:
  4168.  
  4169.    Where to Look                        What You'll Find
  4170.    ──────────────────────────────────────────────────────────────────────────
  4171.    Chapter 11, "The File Menu"         Complete information on file
  4172.                                         management in QuickBASIC, including
  4173.                                         file-format options and special
  4174.                                         commands for opening types of files
  4175.                                         other than single-file programs.
  4176.  
  4177.    Chapter 13, "The Edit Menu" and     Complete information on creating and
  4178.    Chapter 14, "The View Menu"         viewing procedures in QuickBASIC.
  4179.  
  4180.    Chapter 2, "SUB and FUNCTION         Explanations of BASIC's rules for
  4181.    Procedures," in Programming in BASIC creating all types of SUB and
  4182.                                         FUNCTION procedures.
  4183.    ──────────────────────────────────────────────────────────────────────────
  4184.  
  4185.  
  4186.  
  4187.  ────────────────────────────────────────────────────────────────────────────
  4188.  Chapter 6  Editing in the View Window
  4189.  
  4190.    QuickBASIC's editing features let you write and modify programs quickly,
  4191.    easily and accurately. As you edit, QuickBASIC checks your code to make
  4192.    sure it is valid BASIC syntax. In this chapter you will use the editing
  4193.    tools to
  4194.  
  4195.    ■ Discover QuickBASIC's smart editor
  4196.  
  4197.    ■ Understand QuickBASIC's automatic text formatting
  4198.  
  4199.    ■ Use on-line help to answer questions on the spot
  4200.  
  4201.    ■ Use the Edit menu's Cut, Copy, and Paste commands
  4202.  
  4203.    ■ Search for and replace text
  4204.  
  4205.    You'll enter module-level code in QCARDS. If you have questions about any
  4206.    words you are typing, use on-line help (position the cursor on the word
  4207.    and press F1). On-line help includes complete descriptions and examples of
  4208.    each QuickBASIC statement and function. QuickBASIC also gives information
  4209.    on any variable, procedure, or symbolic constant at the cursor when you
  4210.    press F1. When you finish, press ESC to close the Help window.
  4211.  
  4212.    This chapter requires one to two hours to complete.
  4213.  
  4214.  
  4215.  The Smart Editor
  4216.  
  4217.    One thing that makes editing in QuickBASIC different from using an
  4218.    ordinary word processor is its "smart editor." QuickBASIC recognizes
  4219.    language keywords and warns you when they are being used incorrectly.
  4220.    QuickBASIC also inserts certain types of text into the program for you.
  4221.    For example, when you created the Alarm procedure in the last chapter,
  4222.    QuickBASIC inserted the DEFINT A-Z and END SUB statements for you when you
  4223.    entered the SUB Alarm statement.
  4224.  
  4225.  Automatic Formatting
  4226.  
  4227.    QuickBASIC's smart editor capitalizes keywords and places uniform spacing
  4228.    between operators (such as plus and minus signs) and their operands (the
  4229.    values they operate on). This makes your program easier to read. The
  4230.    following steps illustrate this:
  4231.  
  4232.    QCARDS Code Entry 3
  4233.  
  4234.    1. Start QuickBASIC and open CHAPTER5.BAS (if it is not open).
  4235.  
  4236.    2. Use PGDN and DOWN to move the cursor to the blank line beneath the
  4237.       following comment (at about line 106). Check the line counter on the
  4238.       reference bar to find the line.
  4239.  
  4240.       ' Open data file QCARDS.DAT for random access using file #1
  4241.  
  4242.    3. Press ENTER to create a blank line, then type this statement exactly as
  4243.       shown, including the initial "comment delimiter" (the apostrophe
  4244.       preceding open):
  4245.  
  4246.       'open "qcards.dat" for random as #1 len=len(card)
  4247.  
  4248.    4. Press ENTER.
  4249.  
  4250.       QuickBASIC reads the line as though it were just a comment so no
  4251.       formatting is done.
  4252.  
  4253.    5. Press UP to place the cursor at the comment delimiter.
  4254.  
  4255.    6. Press DEL to delete the comment delimiter.
  4256.  
  4257.    7. Press DOWN to move the cursor off the line.
  4258.  
  4259.       QuickBASIC converts the keywords (OPEN, FOR, RANDOM, AS, and LEN) to
  4260.       capital letters. Spaces are inserted on each side of the equal sign
  4261.       (=).
  4262.  
  4263.    Since it is easier to type in lowercase letters, lines of code are shown
  4264.    in this tutorial with keywords in lowercase. When you type them and press
  4265.    ENTER, QuickBASIC capitalizes the keywords for you. Words that aren't
  4266.    keywords (such as symbolic constants, procedure names, and variable names)
  4267.    appear in mixed case or all uppercase letters.
  4268.  
  4269.    The BASIC language is not "case sensitive." It doesn't distinguish between
  4270.    two versions of the same word by the case of the letters. For instance,
  4271.    the keyword OPEN is the same to the BASIC language as open or OpEn. When
  4272.    the smart editor capitalizes keywords, it is just for appearance. The
  4273.    variable name Card represents the same memory location as CArd or CaRD.
  4274.  
  4275.    The smart editor automatically maintains consistency in the capitalization
  4276.    of specific words in a program listing. Conventions used in this manual
  4277.    and QuickBASIC's handling of text you enter are summarized in the
  4278.    following list:
  4279.  
  4280.    Type of Word       Appearance in     QuickBASIC Action
  4281.                       Manual
  4282.    ──────────────────────────────────────────────────────────────────────────
  4283.    BASIC keywords     Lowercase         Converts them to all uppercase
  4284.                                         letters when you enter the line
  4285.  
  4286.    Variable names and Mixed case        Alters all instances of the name to
  4287.    procedure names                      most recent capitalization
  4288.  
  4289.    Symbolic constants Uppercase         Changes all instances of the name to
  4290.                                         most recent capitalization
  4291.    ──────────────────────────────────────────────────────────────────────────
  4292.  
  4293.    The following steps illustrate the rules in the table above:
  4294.  
  4295.    QCARDS Code Entry 4
  4296.  
  4297.    1. Move the cursor to the line below the following comment (at about line
  4298.       113):
  4299.  
  4300.       ' To count records in file, divide the length of the file by the
  4301.       ' length of a single record; use integer division () instead of
  4302.       ' normal division (/). Assign the resulting value to LastCard.
  4303.  
  4304.    2. Press ENTER to make space, then type the following line exactly as
  4305.       shown:
  4306.  
  4307.       LastCard=LoF(1)Len(Card)
  4308.  
  4309.       Note that the backslash (<|>) operator in BASIC performs integer
  4310.       division, rather than normal division.
  4311.  
  4312.    3. Press ENTER.
  4313.  
  4314.       Keywords are capitalized and spaces are inserted. The previous
  4315.       capitalization of card (in the OPEN statement) is updated to Card, to
  4316.       conform to the way you just typed it. QuickBASIC assumes that the last
  4317.       way you entered the word in the View window is the way you want it
  4318.       everywhere. This is done to all occurrences of the word except those
  4319.       within comments.
  4320.  
  4321.  Syntax Checking
  4322.  
  4323.    When you move the cursor off any code line you edit (either by pressing
  4324.    ENTER or a DIRECTION key), QuickBASIC checks its syntax. If the line is
  4325.    not valid BASIC code, QuickBASIC displays a dialog box describing the
  4326.    error.
  4327.  
  4328.    The following steps show how the smart editor checks your code for syntax
  4329.    errors:
  4330.  
  4331.    QCARDS Code Entry 5
  4332.  
  4333.    1. Move the cursor to the line beneath the following comment block (about
  4334.       line 130):
  4335.  
  4336.       ' Redefine the Index array to hold the records in the file plus
  4337.       ' 20 extra (the extra records allow the user to add cards).
  4338.       ' This array is dynamic - this means the number of elements
  4339.       ' in Index() varies depending on the size of the file.
  4340.       ' Also, Index() is a shared procedure, so it is available to
  4341.       ' all SUB and FUNCTION procedures in the program.
  4342.       '
  4343.       ' Note that an error trap lets QCARDS terminate with an error
  4344.       ' message if the memory available is not sufficient. If no
  4345.       ' error is detected, the error trap is turned off following the
  4346.       ' REDIM statement.
  4347.  
  4348.    2. Press ENTER, then type the following lines exactly as shown (including
  4349.       errors):
  4350.  
  4351.       on error goto MemoryErr
  4352.       redim shared Index(1 to LastCard + 20) as PERSOR
  4353.       on error goto
  4354.  
  4355.    3. Press ENTER after the final line. QuickBASIC displays the following
  4356.       error message (see Figure 6.1):
  4357.  
  4358.  
  4359.          File  Edit  View  Search  Run  Debug  Calls  Options              Hel
  4360.       ┌────────────────────────────── CHAPTER5.BAS ─────────────────────────┤
  4361.       │' Also, Index() is a shared procedure, so it is available to
  4362.       │' all SUB and FUNCTION procedures in the program.
  4363.       │
  4364.       │ON ERROR GOTO MemoryErr
  4365.       │REDIM SHARED Index(1 TO LastCard + 20) AS PERSOR
  4366.       │ON ERROR GOTO ▓▓▓▓
  4367.       │                  ┌────────────────────────────────────────┐
  4368.       │                  │
  4369.       │' Note that an err│                                        │or
  4370.       │' message if the m│  Expected: 0 or label or line number   │
  4371.       │' error is detecte│                                        │ the
  4372.       │' REDIM statement.├────────────────────────────────────────┤
  4373.       │                  │          < OK >     < Help >           │
  4374.       │' Use the block IF└────────────────────────────────────────┘r
  4375.       │' to load the records from the disk file QCARDS.DAT into the
  4376.       │' array of records called Index() declared earlier. In the IF
  4377.       │' part, you will check to see if there are actually records
  4378.       │' in the file. If there are, LastCard will be greater than 0.
  4379.       │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  4380.       ├─────────────────────────────── Immediate ─────────────────────────────
  4381.       │
  4382.       │
  4383.        <Shift+F1=Help> <F6=Window> <F2=Subs> <F5=Run> <F8=Step>      CN 00126:
  4384.  
  4385.       Figure 6.1  Error-Message Dialog Box
  4386.  
  4387.       When you use ON ERROR GOTO to turn off an error trap (as is being done
  4388.       here) QuickBASIC expects it to be followed by the number 0.
  4389.  
  4390.    4. Press ESC to clear the dialog box.
  4391.  
  4392.       QuickBASIC places the cursor at the place the error was detected.
  4393.  
  4394.    5. Add a zero at the end of the line so it looks like this:
  4395.  
  4396.       ON ERROR GOTO 0
  4397.  
  4398.    Once you close an error-message dialog box, QuickBASIC doesn't check that
  4399.    statement's syntax again until you actually change the line. If you don't
  4400.    edit the line at all, QuickBASIC waits until you run the program before
  4401.    reminding you that the error still exists.
  4402.  
  4403.  Errors Detected When You Run Your Program
  4404.  
  4405.    Some errors are not apparent until you actually try to run your code. For
  4406.    example, in the REDIM statement you declared the Index() array as type
  4407.    PERSOR. This was a misspelling of the name of the user-defined type,
  4408.    PERSON, which you saw when you scrolled through the declarations and
  4409.    definitions section of QCARDS in Chapter 5 "The QCARDS Program."
  4410.    QuickBASIC did not detect this error on entry because it assumes that the
  4411.    PERSOR type is declared somewhere, even though it has not yet encountered
  4412.    the declaration.
  4413.  
  4414.    The following step illustrates how these errors are detected:
  4415.  
  4416.      Press ALT+R, then press S to choose the Run menu's Start command to run
  4417.       the lines entered so far.
  4418.  
  4419.       QuickBASIC displays the error message Type not defined and highlights
  4420.       the AS in the REDIM statement as shown in Figure 6.2.
  4421.  
  4422.  
  4423.       File  Edit  View  Search  Run  Debug  Calls  Options              Help
  4424.    ┌────────────────────────────── CHAPTER5.BAS ─────────────────────────┤├──
  4425.    │' Also, Index() is a shared procedure, so it is available to
  4426.    │' all SUB and FUNCTION procedures in the program.
  4427.    │
  4428.    │ON ERROR GOTO MemoryErr
  4429.    │REDIM SHARED Index(1 TO LastCard + 20) AS PERSOR
  4430.    │ON ERROR GOTO 0
  4431.    │
  4432.    │' Note that an error trap ┌────────────────────────┐h an error
  4433.    │' message if the memory av│                        │. If no
  4434.    │' error is detected, the e│    Type not defined    │ollowing the
  4435.    │' REDIM statement.        │                        │
  4436.    │                          ├────────────────────────┤
  4437.    │                          │  < OK >     < Help >   │
  4438.    │' Use the block IF...THEN.└────────────────────────┘e whether
  4439.    │' to load the records from the disk file QCARDS.DAT into the
  4440.    │' array of records called Index() declared earlier. In the IF
  4441.    │' part, you will check to see if there are actually records
  4442.    │' in the file. If there are, LastCard will be greater than 0.
  4443.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  4444.    ├─────────────────────────────── Immediate ────────────────────────────────
  4445.    │
  4446.    │
  4447.     <Shift+F1=Help> <F6=Window> <F2=Subs> <F5=Run> <F8=Step>      CN 00124:040
  4448.  
  4449.    Figure 6.2  Error Message
  4450.  
  4451.    Help for Error Messages
  4452.  
  4453.    Error-message dialog boxes contain a Help button you can choose to get
  4454.    either a description of common causes for the error or the correct syntax
  4455.    plus examples of usage.
  4456.  
  4457.    1. Press F1 to get on-line help for this error message, then choose the
  4458.       Help button in the dialog box.
  4459.  
  4460.       The following dialog box appears (see Figure 6.3):
  4461.  
  4462.  
  4463.          File  Edit  View  Search  Run  Debug  Calls  Options              Hel
  4464.       ┌────────────────────────────── CHAPTER5.BAS ─────────────────────────┤
  4465.       │' Also, Index() is a shared procedure, so it is available to
  4466.       │' all SUB and FUNCTION procedures in the program.
  4467.       │
  4468.       │ON ERROR GOTO MemoryErr
  4469.       │REDIM SHARED Index(1 TO LastCard + 20) AS PERSOR
  4470.       │ON ER┌────────────────────────────────────────────────────────────────┐
  4471.       │     │ ┌────────────────────────────────────────────────────────────┐ │
  4472.       │' Not│ │ No TYPE...END TYPE statement exists in this module for the │ │
  4473.       │' mes│ │ user-defined type.                                         │ │
  4474.       │' err│ │   ■ Did you misspell the user-defined type name?           │ │
  4475.       │' RED│ │   ■ You can use the QuickBASIC Find command to locate all  │ │
  4476.       │     │ │                                                            │ │
  4477.       │     │ └────────────────────────────────────────────────────────────┘ │
  4478.       │' Use├────────────────────────────────────────────────────────────────┤
  4479.       │' to │                             < OK >                             │
  4480.       │' arr└────────────────────────────────────────────────────────────────┘
  4481.       │' part, you will check to see if there are actually records
  4482.       │' in the file. If there are, LastCard will be greater than 0.
  4483.       │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  4484.       ├─────────────────────────────── Immediate ─────────────────────────────
  4485.       │
  4486.       │
  4487.        F1=Help  Enter=Execute  Esc=Cancel  Tab=Next Field  Arrow=Next Item
  4488.  
  4489.       Figure 6.3  Help on Error Message
  4490.  
  4491.       The new dialog box indicates that no TYPE...END TYPE statement was
  4492.       found for PERSOR.
  4493.  
  4494.    2. Press ESC as many times as necessary to clear the dialog boxes.
  4495.  
  4496.    Overtyping the Error
  4497.  
  4498.    Overtyping replaces the text at the cursor and moves the cursor right.
  4499.    Correct the error by overtyping, as follows:
  4500.  
  4501.    QCARDS Code Entry 6
  4502.  
  4503.    1. Place the cursor on the second R in PERSOR.
  4504.  
  4505.    2. Press INS to change from insert to overtype.
  4506.  
  4507.       The INS key is a "toggle." It changes the shape of the cursor from the
  4508.       default (a thin blinking line) to a blinking box. When the cursor is a
  4509.       thin line, text you type is inserted at the cursor position. When the
  4510.       cursor has the box shape, whatever you type "overtypes" (replaces) the
  4511.       text at the current cursor position.
  4512.  
  4513.    3. Overtype the second R in PERSOR with an N so the line looks like this:
  4514.  
  4515.       REDIM SHARED Index(1 TO LastCard + 20) AS PERSON
  4516.  
  4517.    4. Press INS to reset the toggle to its default (the thin line).
  4518.  
  4519.    5. Type the following on the next blank line to call your Alarm procedure:
  4520.  
  4521.       call Alarm
  4522.  
  4523.    6. Press ALT+R, then press S to choose the Run menu's Start command to run
  4524.       the lines.
  4525.  
  4526.       QCARDS doesn't produce any visible output yet, but Alarm produces its
  4527.       sound.
  4528.  
  4529.    7. Press a key to return to the QuickBASIC environment.
  4530.  
  4531.  Automatic Procedure Declarations
  4532.  
  4533.    When QuickBASIC encounters a procedure invocation in a program, it creates
  4534.    the DECLARE statement automatically. Then, it writes the declaration at
  4535.    the first line of the file (when you save your program). The following
  4536.    steps illustrate this:
  4537.  
  4538.    QCARDS Code Entry 7
  4539.  
  4540.    1. Press CTRL+HOME to move the cursor to the beginning of the program.
  4541.  
  4542.    2. Press ALT+F, then press A to choose the File menu's Save As command.
  4543.       The Save As dialog box appears.
  4544.  
  4545.    3. Type chapter6 in the text box, then press ENTER to save the program as
  4546.       CHAPTER6.BAS. QuickBASIC inserts the declaration on the first line of
  4547.       the program, as follows :
  4548.  
  4549.       DECLARE SUB Alarm()
  4550.  
  4551.    This is a good point to take a break. In the next section you'll move the
  4552.    declaration just created and change some of the existing QCARDS code.
  4553.  
  4554.  
  4555.  Working with Selected Text Blocks
  4556.  
  4557.    "Selecting" is the way you highlight a block of text to work with. To
  4558.    select a text block directly, place the cursor at the beginning of a
  4559.    block, then hold down the SHIFT key while pressing the appropriate
  4560.    DIRECTION key.
  4561.  
  4562.    Try the following to select a block of text:
  4563.  
  4564.    QCARDS Code Entry 8
  4565.  
  4566.    1. Start QuickBASIC (if you exited when you took a break) and open
  4567.       CHAPTER6.BAS.
  4568.  
  4569.    2. Press CTRL+HOME to make sure the cursor is at the program's first line.
  4570.  
  4571.       The line should be DECLARE SUB Alarm().
  4572.  
  4573.    3. Press SHIFT+DOWN to select this line.
  4574.  
  4575.    The only way you can remove the highlight from selected text and return it
  4576.    to its unselected state is by pressing one of the DIRECTION keys ( UP,
  4577.    DOWN, LEFT, RIGHT), or by pressing F6 to move to a different window.
  4578.  
  4579.    ──────────────────────────────────────────────────────────────────────────
  4580.    WARNING
  4581.      Be cautious with selected text! If you type any character (even the
  4582.      SPACEBAR) while a line of text is selected, whatever you type replaces
  4583.      all selected text in the active window. The text that was selected is
  4584.      then permanently lost.
  4585.    ──────────────────────────────────────────────────────────────────────────
  4586.  
  4587.  Cutting or Copying Selected Text
  4588.  
  4589.    The Edit menu has commands that let you move a block of selected text to
  4590.    and from a "Clipboard" (a dedicated space in memory). The Cut and Copy
  4591.    commands put selected text on the Clipboard. The Paste command copies
  4592.    whatever text is on the Clipboard to the current cursor position. If a
  4593.    line (or more) of text is selected in the active window when you choose
  4594.    the Paste command, the text on the Clipboard replaces the selected text.
  4595.  
  4596.    When a menu command is available, it is marked with a high-intensity
  4597.    letter. For example, if you open the Edit menu now, the Cut and Copy
  4598.    commands are available because there is text selected in the active
  4599.    window. However, the Paste command is not available unless you have
  4600.    already placed text on the Clipboard. The following steps use the Cut
  4601.    command to transfer the text from its current position to the Clipboard:
  4602.  
  4603.    QCARDS Code Entry 9
  4604.  
  4605.    1. Select the line DECLARE SUB Alarm if it isn't already selected.
  4606.  
  4607.    2. Press ALT+E to open the Edit menu if it is not already open.
  4608.  
  4609.    3. Press T to choose the Cut command.
  4610.  
  4611.    The selected text is transferred to the Clipboard. You can only copy one
  4612.    block at a time to the Clipboard because each new block (regardless of its
  4613.    size) replaces everything that preceded it on the Clipboard.
  4614.  
  4615.    ──────────────────────────────────────────────────────────────────────────
  4616.    IMPORTANT
  4617.      The shortcut-key combination for Cut is SHIFT+DEL. If you just press DEL
  4618.      while text is selected, it is deleted, but not to the Clipboard. You
  4619.      cannot recover text deleted with DEL.
  4620.    ──────────────────────────────────────────────────────────────────────────
  4621.  
  4622.    The Copy command is similar to Cut, but it puts a duplicate of the
  4623.    selected text on the Clipboard and leaves the selected block as is.
  4624.  
  4625.    ──────────────────────────────────────────────────────────────────────────
  4626.    NOTE
  4627.      Copy leaves the original text block selected, so you have to press a
  4628.      DIRECTION key before typing anything or the block will be replaced by
  4629.      what you type.
  4630.    ──────────────────────────────────────────────────────────────────────────
  4631.  
  4632.  Pasting a Text Block
  4633.  
  4634.    Any text you put on the Clipboard remains there until you either put
  4635.    something else on the Clipboard or until you exit from QuickBASIC. Follow
  4636.    these steps to move to the procedure-declarations section of QCARDS and
  4637.    paste in the declaration for Alarm:
  4638.  
  4639.    QCARDS Code Entry 10
  4640.  
  4641.    1. Press ALT+S, then press F to choose the Search menu's Find command.
  4642.  
  4643.       The Find dialog box appears (see Figure 6.4).
  4644.  
  4645.  
  4646.       ┌─────────────────────────Find────────────────────────────────┐
  4647.       │            ┌─────────────────────────────────────────────┐  │
  4648.       │ Find What: │                                             │  │
  4649.       │            └─────────────────────────────────────────────┘  │
  4650.       │                                                             │
  4651.       │                              ┌────────Search─────────────┐  │
  4652.       │ [ ] Match Upper/Lowercase    │( ) 1. Active Window       │  │
  4653.       │ [ ] Whole Word               │(∙) 2. Current Module      │  │
  4654.       │                              │( ) 3. All Modules         │  │
  4655.       │                              └───────────────────────────┘  │
  4656.       │                                                             │
  4657.       ├─────────────────────────────────────────────────────────────┤
  4658.       │        < OK >           < Cancel >        < Help >          │
  4659.       └─────────────────────────────────────────────────────────────┘
  4660.  
  4661.       Figure 6.4  Find Dialog Box
  4662.  
  4663.    2. Type the following line in the text box:
  4664.  
  4665.       This space reserved
  4666.  
  4667.    3. Press ENTER to start the search.
  4668.  
  4669.    4. Press HOME to place the cursor in column 1.
  4670.  
  4671.    5. Press SHIFT+END to select the whole line.
  4672.  
  4673.    6. Press ALT+E, then press P to choose the Edit menu's Paste command.
  4674.  
  4675.       The Paste command is active because there is text on the Clipboard. The
  4676.       text from the Clipboard replaces the selected text.
  4677.  
  4678.    7. Save the program as CHAPTER6.BAS.
  4679.  
  4680.  Manipulating Selected Text
  4681.  
  4682.    You can manipulate selected text in other ways. For instance, you can
  4683.    indent selected text as a block rather than one line at a time. The
  4684.    following steps illustrate this:
  4685.  
  4686.    QCARDS Code Entry 11
  4687.  
  4688.    1. Press ALT+S, then press F to choose the Search menu's Find command.
  4689.       Type the following line in the text box, exactly as shown:
  4690.  
  4691.       ' Define temporary
  4692.  
  4693.       There may be text selected in the text box when the dialog box opens.
  4694.       If so, whatever you type replaces the selected text automatically. You
  4695.       can remove the selection from the text by pressing a DIRECTION key if
  4696.       you want to just change the text in the box rather than completely
  4697.       replacing it.
  4698.  
  4699.    2. Press ENTER. The cursor should move to the following line:
  4700.  
  4701.       ' Define temporary Index() array to illustrate QCARDS screen
  4702.  
  4703.    3. Press SHIFT+DOWN twice so both the following lines are selected:
  4704.  
  4705.       ' Define temporary Index() array to illustrate QCARDS screen
  4706.       REDIM SHARED Index(1) AS PERSON
  4707.  
  4708.    4. Press TAB while this text block is selected. The whole block moves
  4709.       right by one tab stop.
  4710.  
  4711.    5. Press SHIFT+TAB to move the block left by one indentation level.
  4712.  
  4713.    6. Press DEL to delete the entire block permanently.
  4714.  
  4715.    7. Save the program as usual as CHAPTER6.BAS.
  4716.  
  4717.    Note that the text you just deleted was not placed on the Clipboard. This
  4718.    is because you deleted it with DEL rather than SHIFT+DEL (the shortcut key
  4719.    for the Cut command). The temporary Index() array definition is no longer
  4720.    needed because you defined it (with a REDIM statement) in the first part
  4721.    of this chapter.
  4722.  
  4723.  
  4724.  Searching and Replacing Text
  4725.  
  4726.  ────────────────────────────────────────────────────────────────────────────
  4727.  IMPORTANT
  4728.    The remaining sections of this chapter provide practice using QuickBASIC's
  4729.    search and replace feature. The code you enter in the optional code-entry
  4730.    sections below is not necessary to make QCARDS run. You may want to read
  4731.    the rest of the chapter before deciding whether to try the optional
  4732.    code-entry sequences. If you make a mistake entering any of the optional
  4733.    sequences, the final program won't run properly. If you choose to do any
  4734.    of the optional code-entry sequences, you must do all three of them.
  4735.  ────────────────────────────────────────────────────────────────────────────
  4736.  
  4737.    In this section, you'll define the symbolic constant DISKFILE$ to
  4738.    represent "QCARDS.DAT" the name of the disk file that contains QCARDS'
  4739.    data. Then you'll use the Search menu's Change command to replace all
  4740.    instances of the text string "QCARDS.DAT" with the symbolic constant. Once
  4741.    you define the constant DISKFILE$, you can just change the definition of
  4742.    DISKFILE$ if you want to load a different data file in QCARDS (or create a
  4743.    new data file).
  4744.  
  4745.  Defining the Symbolic Constant
  4746.  
  4747.    The first thing to do is define the constant. There is already an
  4748.    appropriate place to do this in the declarations and definitions section.
  4749.    Do the following to find the place and then add the constant:
  4750.  
  4751.    Optional QCARDS Code Entry 1
  4752.  
  4753.    1. Save CHAPTER6.BAS as OPTIONAL.BAS.
  4754.  
  4755.       This way, if you do everything right you can start the next chapter by
  4756.       loading OPTIONAL.BAS, then saving it as CHAPTER7.BAS. If you make an
  4757.       error in one of the optional sections and find you can't correct it,
  4758.       you can start with CHAPTER6.BAS in the next chapter.
  4759.  
  4760.    2. Press CTRL+HOME to move to the beginning of QCARDS.
  4761.  
  4762.    3. Press ALT+S, then press F to choose the Search menu's Find command.
  4763.       Finally, type the following in the text box:
  4764.  
  4765.       TMPFILE
  4766.  
  4767.    4. Press ENTER to place the cursor at the definition of TMPFILE. It looks
  4768.       like this:
  4769.  
  4770.       CONST TMPFILE$ = "$$$87y$.$5$"       ' Unlikely file name
  4771.  
  4772.    5. Press DOWN to remove selection from TMPFILE.
  4773.  
  4774.    6. Press HOME to place the cursor in the leftmost column, then type the
  4775.       following line, exactly as shown, but don't press ENTER:
  4776.  
  4777.       const DISKFILE$ = "QCARDS.DAT"
  4778.  
  4779.    7. Press SHIFT+LEFT until the string "QCARDS.DAT" is completely selected.
  4780.       Be sure both quotation marks are included in the selection.
  4781.  
  4782.    It's important to make sure the quotation marks are selected because you
  4783.    want to replace "QCARDS.DAT" with DISKFILE$.
  4784.  
  4785.  Replacing Multiple Occurrences of Text
  4786.  
  4787.    Using the Change command is much like the Find command, except that
  4788.    QuickBASIC lets you substitute specified text when matching text is found
  4789.    before it searches for the next match. Next you will change "QCARDS.DAT"
  4790.    to DISKFILE$ everywhere except in the definition you wrote in the last
  4791.    section. The Search menu's Change command lets you automate the process.
  4792.  
  4793.    Optional QCARDS Code Entry 2
  4794.  
  4795.    1. Press ALT+S, then press C to choose the Search menu's Change command.
  4796.       The Change dialog box's Change command appears (see Figure 6.5):
  4797.  
  4798.  
  4799.                      Text you want to      This text will replace the
  4800.                     │change goes here.    │text you want to change.
  4801.       ┌─────────────┼─────────────────────┼───────────────────────────┐
  4802.       │            ┌┼─────────────────────┼────────────────────────┐  │
  4803.       │ Find What: │"QCARDS.DAT"          │                        │  │
  4804.       │            └──────────────────────┼────────────────────────┘  │
  4805.       │            ┌──────────────────────┼────────────────────────┐  │
  4806.       │ Change To: │DISKFILE$                                      │  │
  4807.       │            └───────────────────────────────────────────────┘  │
  4808.       │                                                               │
  4809.       │                                                               │
  4810.       │ [ ] Match Upper/Lowercase                                     │
  4811.       │ [ ] Whole Word                                                │
  4812.       │                                                               │
  4813.       ├───────────────────────────────────────────────────────────────┤
  4814.       │  < Find and Verify >   < Change All >   <Cancel >   < Help >  │
  4815.       └───────────────────────────────────────────────────────────────┘
  4816.  
  4817.       Figure 6.5  Change Dialog Box
  4818.  
  4819.       Because "QCARDS.DAT" is selected in the View window, the Find What text
  4820.       box has"QCARDS.DAT"in it.
  4821.  
  4822.    2. Press TAB to move the cursor to the Change To text box.
  4823.  
  4824.       This is where you enter the text you want to substitute for the search
  4825.       text.
  4826.  
  4827.    3. Type DISKFILE$ in this text box.
  4828.  
  4829.    4. Press ENTER to choose the Find and Verify command button (the default).
  4830.  
  4831.    ──────────────────────────────────────────────────────────────────────────
  4832.    WARNING
  4833.      The second command button, Change All, makes all the changes without
  4834.      showing you the occurrences or waiting for confirmation. This option is
  4835.      risky unless you are sure you want to change all the occurrences. Even
  4836.      then, you may inadvertently change words that contain the search text in
  4837.      a way you didn't anticipate. If you have any doubts, use the default
  4838.      option Find and Verify. The Cancel button or ESC aborts the search and
  4839.      replace operation entirely.
  4840.    ──────────────────────────────────────────────────────────────────────────
  4841.  
  4842.    The Find and Verify command button highlights each occurrence of the
  4843.    search text, then displays the Change, Skip, Cancel dialog box (see Figure
  4844.    6.6). In the next section you'll use it to make selective replacements.
  4845.    It contains buttons you can choose when you decide whether to replace the
  4846.    current occurrence:
  4847.  
  4848.  
  4849.    ┌───────────────────────────Change──────────────────────────────┐
  4850.    │                                                               │
  4851.    ├───────────────────────────────────────────────────────────────┤
  4852.    │ < Change >      < Skip >      < Cancel >      < Help >        │
  4853.    └───────────────────────────────────────────────────────────────┘
  4854.  
  4855.    Figure 6.6  Change, Skip, Cancel Dialog Box
  4856.  
  4857.    The Change, Skip, Cancel dialog box should still be on your screen.
  4858.    Replace occurrences of "QCARDS.DAT" with DISKFILE$ as follows:
  4859.  
  4860.    Optional QCARDS Code Entry 3
  4861.  
  4862.    1. Press C to change the first occurrence. It is in the OPEN statement you
  4863.       entered earlier in this chapter.
  4864.  
  4865.       QuickBASIC moves to the next match. It is in a comment line in the
  4866.       CleanUp procedure (check the View window's title bar).
  4867.  
  4868.    2. Press C to make the change.
  4869.  
  4870.       QuickBASIC moves to the next match. It is also in CleanUp in the line
  4871.       KILL "QCARDS.DAT"
  4872.  
  4873.    3. Press C to make the change.
  4874.  
  4875.       QuickBASIC moves to the next match. It is also in CleanUp in the line
  4876.       NAME TMPFILE AS "QCARDS.DAT"
  4877.  
  4878.    4. Press C to make the change.
  4879.  
  4880.       QuickBASIC moves to the next match. It is in a different procedure,
  4881.       InitIndex, in a comment line.
  4882.  
  4883.    5. Press C to make the change.
  4884.  
  4885.       The final match is at CONST DISKFILE$ = "QCARDS.DAT" where you started.
  4886.       You don't want to change this one because this definition is the reason
  4887.       you just made all the other changes.
  4888.  
  4889.    6. Press S to choose the Skip command button.
  4890.  
  4891.       When all occurrences have either been changed or skipped, QuickBASIC
  4892.       displays a dialog box containing ChangeComplete.
  4893.  
  4894.    7. Press ESC to close the dialog box.
  4895.  
  4896.  Checking Your Work
  4897.  
  4898.    Whenever you make a series of changes throughout a program, you should
  4899.    check your work by running the program. If you've made a mistake during
  4900.    editing, you can use QuickBASIC's error messages to help you track down
  4901.    mistakes. Finish this session with the following procedure:
  4902.  
  4903.    1. Press ALT+R, then press S to choose the Run menu's Start command to run
  4904.       the lines.
  4905.  
  4906.       If you get an error message, try to track down the error and fix it
  4907.       before you end the session. Go back over each of the optional QCARDS
  4908.       code-entry sections and compare your work with them.
  4909.  
  4910.    2. Press a key to return to the QuickBASIC environment.
  4911.  
  4912.    3. Save the program. If you renamed it OPTIONAL.BAS, you can just start
  4913.       with that file in the next chapter and rename it CHAPTER7.BAS.
  4914.  
  4915.    The constant DISKFILE$ now represents QCARDS.DAT in the program. Later you
  4916.    may want to modify the program to allow the user to load different files
  4917.    while the program is running. If you do, you can't represent the the file
  4918.    with the constant DISKFILE$, because the point of a constant is that it
  4919.    cannot be changed when the program is running. You would have to remove
  4920.    the CONST part of the definition and just make DISKFILE$ an ordinary
  4921.    string variable.
  4922.  
  4923.  
  4924.  For More Information
  4925.  
  4926.    For more information on the topics covered in this chapter, see the
  4927.    following:
  4928.  
  4929.    Chapter                  Topic
  4930.    ──────────────────────────────────────────────────────────────────────────
  4931.    Chapter 12, "Using the  Complete information on QuickBASIC's editing
  4932.    Editor," and Chapter     features, including the commands found on Full
  4933.    13, "The Edit Menu"     Menus and editing shortcut-key combinations
  4934.  
  4935.    Chapter 2, "SUB and      Defining and using procedures and placement of
  4936.    FUNCTION Procedures,"    automatically generated procedure declarations.
  4937.    in Programming in BASIC
  4938.  
  4939.    Chapter 4, "String       Using strings as symbolic constants
  4940.    Processing," in
  4941.    Programming in Basic
  4942.  
  4943.    Chapter 6, "Error and    Using the ON ERROR statement
  4944.    Event Trapping," in
  4945.    Programming in BASIC
  4946.    ──────────────────────────────────────────────────────────────────────────
  4947.  
  4948.  
  4949.  
  4950.  ────────────────────────────────────────────────────────────────────────────
  4951.  Chapter 7  Programming with On-Line Help
  4952.  
  4953.    You've seen Microsoft QuickBASIC's on-line help features in previous
  4954.    chapters. In this chapter you'll use on-line help to guide you in writing
  4955.    some code for the QCARDS program. You will
  4956.  
  4957.    ■ Use alternative methods to get on-line help for QuickBASIC keywords
  4958.  
  4959.    ■ Access information about on-line program symbols through help
  4960.  
  4961.    ■ Use hyperlinks to get additional information within the Help window
  4962.  
  4963.    This chapter takes about one hour to complete.
  4964.  
  4965.  
  4966.  Using On-Line Help to Construct Statements
  4967.  
  4968.    In this section you'll use the Help menu's Index command to find out how
  4969.    to use statements. Do this first:
  4970.  
  4971.    QCARDS Code Entry 12
  4972.  
  4973.    1. Start QuickBASIC if it is not running and open CHAPTER6.BAS (or
  4974.       OPTIONAL.BAS, whichever is appropriate).
  4975.  
  4976.    2. Save the program immediately as CHAPTER7.BAS.
  4977.  
  4978.  On-Line Help for Keywords
  4979.  
  4980.    If you know the statement you want to use, you can find it quickly by
  4981.    choosing the Index command from the Help menu. You can get information on
  4982.    the first code block you'll enter in this chapter (the IF...THEN...ELSE
  4983.    statement) by doing the following steps:
  4984.  
  4985.    1. Choose the Help menu's Index command (press ALT+H, then press I).
  4986.  
  4987.       Index lists all the QuickBASIC keywords. Scroll down through the list
  4988.       to see what it contains (use DIRECTION keys), or press the initial
  4989.       letter of the keyword you want more information on.
  4990.  
  4991.    2. Select IF... THEN (press I).
  4992.  
  4993.       QuickBASIC places the cursor in the IF...THEN statement
  4994.  
  4995.    3. Get help on IF..THEN (press F1).
  4996.  
  4997.       A QuickSCREEN appears (see Figure 7.1). It includes a brief
  4998.       description of the statement, the syntax for the block form of
  4999.       IF...THEN...ELSE, and a description of the terms used in the block.
  5000.  
  5001.  
  5002.       Syntax block
  5003.        │
  5004.        │ File  Edit  View  Search  Run  Debug  Calls  Options              Hel
  5005.       ┌┼────────────── HELP: IF...THEN...ELSE Statement QuickSCREEN ────────┤
  5006.       ││ QuickSCREEN     Details     Example     Contents     Index
  5007.       │├──────────────────────────────────────────────────────────────────────
  5008.       │IF...THEN...ELSE - a control flow statement that allows conditional
  5009.       ││                  execution or branching, based on the evaluation of
  5010.       ││                  an expression that must be either true or false
  5011.       ││
  5012.       │Block IF...THEN...ELSE Syntax
  5013.       ││┌IF booleanexpression1 THEN
  5014.       │││   [statementblock-1]
  5015.       │││[ELSEIF booleanexpression2 THEN
  5016.       │└┤   [statementblock-2]
  5017.       │ │. . .
  5018.       │ │[ELSE
  5019.       │ │   [statementblock-n]]
  5020.       │ └END IF
  5021.       │
  5022.       │  ■ booleanexpression is an expression that must return non-zero (true)
  5023.       │    or zero (false)
  5024.       │  ■ statementblock consists of any number of statements on one or more
  5025.       │    lines.
  5026.       │
  5027.       │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  5028.        <Shift+F1=Help> <F6=Window> <Esc=Cancel> <Ctrl+F1=Next> <Alt+F1=Back>
  5029.  
  5030.       Figure 7.1  QuickSCREEN for IF...THEN...ELSE Statement
  5031.  
  5032.    4. Make the Help window fill the whole screen (press CTRL+F10).
  5033.  
  5034.    5. Move down to the syntax for the single-line form of IF...THEN...ELSE
  5035.       (press PGDN).
  5036.  
  5037.    6. Move the cursor back to the top of the QuickSCREEN (press CTRL+HOME).
  5038.  
  5039.    7. Restore the View and Immediate windows (press CTRL+F10).
  5040.  
  5041.    If you've used the statement before, the QuickSCREEN help information is
  5042.    usually sufficient to help you write your code.
  5043.  
  5044.  Hyperlinks in On-Line Help
  5045.  
  5046.    The QuickSCREEN includes four hyperlinks across the top. You can move the
  5047.    cursor to any one by pressing the TAB key or the initial letter of the
  5048.    word in the hyperlink. The following list describes what is displayed by
  5049.    each of the hyperlinks:
  5050.  
  5051.    Hyperlink                Information Displayed by Help
  5052.    ──────────────────────────────────────────────────────────────────────────
  5053.    Details                  Gives full explanation of each syntax element and
  5054.                             describes all ways of using the statement
  5055.  
  5056.    Example                  Shows code examples that illustrate syntax use
  5057.  
  5058.    Contents                 Shows all possible categories of on-line help
  5059.                             available in QuickBASIC
  5060.  
  5061.    Index                    Lists QuickBASIC keywords alphabetically
  5062.    ──────────────────────────────────────────────────────────────────────────
  5063.  
  5064.    Try each of the available hyperlinks in turn, pressing ALT+F1 each time to
  5065.    return to the original syntax screen.
  5066.  
  5067.    If you keep choosing several hyperlinks without returning to the previous
  5068.    screen, you can work your way backwards through the hyperlink sequence by
  5069.    pressing ALT+F1 repeatedly (up to a limit of 20 links).
  5070.  
  5071.    Although you can't type in the Help window, you can size it with ALT+PLUS
  5072.    and ALT+MINUS so that the information you need is displayed while you
  5073.    enter text in the View window. When you understand the block
  5074.    IF...THEN...ELSE statement, implement the programming described in the
  5075.    comment block as follows:
  5076.  
  5077.    QCARDS Code Entry 13
  5078.  
  5079.    1. Place the cursor in the View window (press F6).
  5080.  
  5081.    2. Scroll down to the line beneath the following comment block (about line
  5082.       145) and create a line of space (press ENTER):
  5083.  
  5084.       ' Use the block IF...THEN...ELSE statement to decide whether
  5085.       ' to load the records from the disk file QCARDS.DAT into the
  5086.       ' array of records called Index() declared earlier. In the IF
  5087.       ' part, you will check to see if there are actually records
  5088.       ' in the file. If there are, LastCard will be greater than 0
  5089.       ' and you can call the InitIndex procedure to load the records
  5090.       ' into Index(). LastCard is 0 if there are no records in the
  5091.       ' file yet. If there are no records in the file, the ELSE
  5092.       ' clause is executed. The code between ELSE and END IF starts
  5093.       ' the Index() array at card 1.
  5094.  
  5095.    3. Type the following code, exactly as shown:
  5096.  
  5097.       if LastCard <> 0 then
  5098.           call InitIndex(LastCard)
  5099.       else
  5100.           Card.CardNum = 1
  5101.           Index(1) = Card
  5102.           put #1, 1, Card
  5103.       end if
  5104.  
  5105.    4. Save the program as CHAPTER7.BAS. Then place the cursor back on the
  5106.       ELSE keyword.
  5107.  
  5108.    5. Run your program up to the line on which the cursor rests (press F7).
  5109.  
  5110.       The line at the cursor appears in high-intensity video with the colors
  5111.       you chose for the Current Statement option in the Options menu's
  5112.       Display dialog box. This means that the program is still running, but
  5113.       execution is temporarily suspended.
  5114.  
  5115.  On-Line Help for Program Symbols
  5116.  
  5117.    QuickBASIC provides help for all "symbols" in your program. A symbol is
  5118.    anything that is defined, either explicitly or implicitly. For example,
  5119.    QuickBASIC keywords are symbols defined by the language. To get help for
  5120.    the symbols you define in your programs, place the cursor anywhere in the
  5121.    symbol, then press F1. QuickBASIC displays all the information it has
  5122.    about the symbol and where it is used in the program. Try this to find out
  5123.    about Card.CardNum.
  5124.  
  5125.    1. Place the cursor in the word CardNum in Card.CardNum and press F1.
  5126.  
  5127.       The Help window shown in Figure 7.2 appears.
  5128.  
  5129.  
  5130.          File  Edit  View  Search  Run  Debug  Calls  Options              Hel
  5131.       ┌───────────────────────────── HELP: CardNum ─────────────────────────┤
  5132.       │CardNum is a symbol that is used in your program as follows:
  5133.       │
  5134.       │┌  C:\QB4.5\DEMO\DIR1\CHAPTER7.BAS ────
  5135.       ││  An element of a user defined TYPE:
  5136.       ││    TYPE PERSON
  5137.       ││      CardNum AS INTEGER
  5138.       ││      Names AS STRING * 37
  5139.       ││      Note AS STRING * 31
  5140.       ││      Month AS INTEGER
  5141.       ││      Day AS INTEGER
  5142.       ││      Year AS INTEGER
  5143.       ││      Phone AS STRING * 12
  5144.       ││      Street AS STRING * 29
  5145.       ││      City AS STRING * 13
  5146.       ││      State AS STRING * 2
  5147.       ││      Zip AS STRING * 5
  5148.       ││    END TYPE
  5149.       ││
  5150.       │
  5151.       ├────────────────────────────── CHAPTER7.BAS ─────────────────────────┤
  5152.       │   Card.CardNum = 1
  5153.       ├─────────────────────────────── Immediate ─────────────────────────────
  5154.        <Shift+F1=Help> <F5=Continue> <F9=Toggle Bkpt> <F8=Step>         00144:
  5155.  
  5156.       Figure 7.2  Symbol Help for CardNum
  5157.  
  5158.       On-line help describes CardNum as an element of the PERSON user-defined
  5159.       type. The help displays the actual TYPE...END TYPE statement. CardNum
  5160.       is the first element.
  5161.  
  5162.    2. Move the cursor to the left until it is in the word Card on the left
  5163.       side of the period, then press F1. On-line help shows that the name
  5164.       Card is used many places in QCARDS. The specific instance at the cursor
  5165.       when you pressed F1 is described first; it is described as a variable
  5166.       of type PERSON.
  5167.  
  5168.       Note that in several procedures, Card is also used as a variable name,
  5169.       but is a variable of type INTEGER. Also, Card is sometimes described as
  5170.       a parameter of type PERSON.
  5171.  
  5172.    On-line help makes it easy to track the use of variable names throughout
  5173.    your programs. Although on-line help doesn't include the current value of
  5174.    a variable, QuickBASIC makes it easy to determine the current value of a
  5175.    variable in a suspended program. Here's how:
  5176.  
  5177.    1. Close the Help window (press ESC).
  5178.  
  5179.    2. Place the cursor anywhere in the word LastCard (about line 150).
  5180.  
  5181.    3. Choose the Debug menu's Instant Watch command.
  5182.  
  5183.       QuickBASIC displays the Instant Watch dialog box (see Figure 7.3). It
  5184.       contains the name of the variable LastCard and its current value. (The
  5185.       actual value reflects the number of records in the QCARDS.DAT data
  5186.       file.)
  5187.  
  5188.  
  5189.          File  Edit  View  Search  Run  Debug  Calls  Options              Hel
  5190.       ┌────────────────────────────── CHAPTER7.BAS ─────────────────────────┤
  5191.       │    CALL InitIndex(LastCard)
  5192.       │ELSE
  5193.       │    Card.CardNum = 1
  5194.       │    Index(1) = Card
  5195.       │    PUT #1, 1.┌─────────────────────────────────────────────┐
  5196.       │ENDIF         │                                             │
  5197.       │              │  ┌───────────── Expression ──────────────┐  │
  5198.       │              │  │LastCard                               │  │
  5199.       │' Use the Draw│  └───────────────────────────────────────┘  │
  5200.       │' and draw the│                                             │
  5201.       │' card. Finall│  ┌──────────────── Value ────────────────┐  │
  5202.       │' as arguments│  │ 16                                    │  │
  5203.       │' ShowCards pl│  └───────────────────────────────────────┘  │
  5204.       │' card on the ├─────────────────────────────────────────────┤
  5205.       │' information │    < Add Watch >   < Cancel >   < Help >    │
  5206.       │              └─────────────────────────────────────────────┘
  5207.       │
  5208.       │
  5209.       │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  5210.       ├─────────────────────────────── Immediate ─────────────────────────────
  5211.       │
  5212.       │
  5213.        F1=Help  Enter=Execute  Esc=Cancel  Tab=Next Field  Arrow=Next Item
  5214.  
  5215.       Figure 7.3  Instant Watch Dialog Box
  5216.  
  5217.    4. Clear the Instant Watch dialog box (press ESC).
  5218.  
  5219.    Perform the following steps to place the QCARDS cards on the screen and
  5220.    the data from QCARDS.DAT on the cards:
  5221.  
  5222.    QCARDS Code Entry 14
  5223.  
  5224.    1. Place the cursor on the line beneath the following comment (about line
  5225.       163):
  5226.  
  5227.       ' Use the DrawCards procedure to initialize the screen
  5228.       ' and draw the cards. Then, set the first card as the top
  5229.       ' card. Finally, pass the variables TopCard and LastCard
  5230.       ' as arguments to the ShowCards procedure. The call to
  5231.       ' ShowCards places all the data for TopCard on the front
  5232.       ' card on the screen, then it places the top-line
  5233.       ' information (the person's name) on the remaining cards.
  5234.  
  5235.    2. Create a line of space (press ENTER), then type the following code
  5236.       lines exactly as shown:
  5237.  
  5238.       call DrawCards
  5239.       TopCard = 1
  5240.       call ShowCards(TopCard, LastCard)
  5241.  
  5242.    3. Place the cursor back on the last line you entered (the one beginning
  5243.       withCALL ShowCards).
  5244.  
  5245.    4. Execute the program to the line at the cursor (press F7).
  5246.  
  5247.    5. Choose the View menu's Output Screen command to toggle back and forth
  5248.       between the QuickBASIC environment and the QCARDS output screen (press
  5249.       F4).
  5250.  
  5251.    You can use the same techniques as before to get help for the CALL keyword
  5252.    that transfers control to a BASIC SUB procedure. You can also get help for
  5253.    the DrawCards and ShowCards procedures and for the variable named TopCard.
  5254.    Since the program is still running (though suspended) you can also check
  5255.    the values of its variables using the Debug menu's Instant Watch command.
  5256.  
  5257.  
  5258.  Printing Screens from On-Line Help
  5259.  
  5260.    The Print command on the File menu can make hard copies of text from
  5261.    on-line help. If you have a printer connected to the parallel port, you
  5262.    can print hard copy of any of the help screens as follows:
  5263.  
  5264.    1. Choose the Help menu's Index command and move the cursor to the
  5265.       DO...LOOP statement entry. Then move that statement's on-line help into
  5266.       the Help window (press F1).
  5267.  
  5268.    2. Choose the File menu's Print command (press ALT+F, then press P).
  5269.  
  5270.       When the Help window is the active window, you can choose the option to
  5271.       print either specifically selected text or the whole current help
  5272.       screen (see Figure 7.4).
  5273.  
  5274.  
  5275.          File  Edit  View  Search  Run  Debug  Calls  Options              Hel
  5276.       ┌────────────────── HELP: DO...LOOP Statement QuickSCREEN ────────────┤
  5277.       │  QuickSCREEN     Details     Example     Contents     Index
  5278.       │───────────────────────────────────────────────────────────────────────
  5279.       │DO...LOOP - a control flow statement that repeats a block of statements
  5280.       │while a condition is true or until a condition becomes true
  5281.       │
  5282.       │Syntax 1               ┌────────── Print ───────────┐
  5283.       │  DO [{WHILE | UNTIL} b│                            │
  5284.       │    [statementblock]   │     ( ) Selected Text      │
  5285.       │  LOOP                 │     (∙) Active Window      │
  5286.       │                       │                            │
  5287.       │Syntax 2               │                            │
  5288.       │  DO                   │                            │
  5289.       │    [statementblock]   ├────────────────────────────┤
  5290.       │  LOOP [{WHILE | UNTIL}│ < OK > < Cancel > < Help > │
  5291.       │                       └────────────────────────────┘
  5292.       │  ■ booleanexpression is an expression that will return non-zero (true)
  5293.       │    or zero (false).
  5294.       │  ■ statementblock is any number of statements on one or more lines whi
  5295.       │    are to be executed as long as booleanexpression is true.
  5296.       │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  5297.       ├───────────────────────────── CHAPTER7.BAS ──────────────────────────┤
  5298.       ├─────────────────────────────── Immediate ─────────────────────────────
  5299.        F1=Help  Enter=Execute  Esc=Cancel  Tab=Next Field  Arrow=Next Item
  5300.  
  5301.       Figure 7.4  Print Dialog Box (Help)
  5302.  
  5303.    3. Print this help screen if you have a printer (press ENTER), otherwise
  5304.       clear the dialog box (press ESC). (If you try to print when you don't
  5305.       have a printer, a Device unavailable dialog box may be displayed.)
  5306.  
  5307.    4. Choose any hyperlinks you'd like to see, then print them out.
  5308.  
  5309.    5. Close the Help window (press ESC).
  5310.  
  5311.    Use the hard copy of the help text (or on-line help) to understand the
  5312.    programming. In the next steps, you'll insert the unconditional loop.
  5313.  
  5314.    QCARDS Code Entry 15
  5315.  
  5316.    1. Move the cursor to the line below this comment block (about line 178):
  5317.  
  5318.       ' Keep the picture on the screen forever with an unconditional
  5319.       ' DO...LOOP statement. The DO part of the statement goes on
  5320.       ' the next code line. The LOOP part goes just before the END
  5321.       ' statement. This loop encloses the central logic that lets
  5322.       ' a user interact with QCARDS.
  5323.  
  5324.    2. Create a blank line (press ENTER).
  5325.  
  5326.    3. Type the word do then press ENTER.
  5327.  
  5328.    4. Move the cursor down to the line beneath this comment (at about line
  5329.       226):
  5330.  
  5331.       ' This is the bottom of the unconditional DO loop.
  5332.  
  5333.    5. Create a blank line (press ENTER), then type the word loop
  5334.  
  5335.    6. Choose Run menu's Start command.
  5336.  
  5337.       You will need to break out of this unconditional DO loop.
  5338.  
  5339.    7. Press CTRL+BREAK when you want to suspend execution of the
  5340.       unconditional DO loop.
  5341.  
  5342.       While execution is suspended, you can use commands like Instant Watch
  5343.       to examine the variables. Afterwards, you can continue program
  5344.       execution by choosing the Continue command from the Run menu (press
  5345.       ALT+R, then press N).
  5346.  
  5347.    8. Save the program as CHAPTER7.BAS.
  5348.  
  5349.  
  5350.  For More Information
  5351.  
  5352.    For more information on on-line help, see the following:
  5353.  
  5354.    Chapter                  Topic
  5355.    ──────────────────────────────────────────────────────────────────────────
  5356.    Section 10.8, "Using    Information on QuickBASIC's Help menu commands
  5357.    On-Line Help" and        and complete descriptions of all the Help
  5358.    Chapter 21, "The Help   features
  5359.    Menu"
  5360.    ──────────────────────────────────────────────────────────────────────────
  5361.  
  5362.  
  5363.  
  5364.  ────────────────────────────────────────────────────────────────────────────
  5365.  Chapter 8  Using Example Code from On-Line Help
  5366.  
  5367.    You've seen many facets of Microsoft QuickBASIC's on-line help in previous
  5368.    chapters. Each QuickSCREEN and Details screen for each statement and
  5369.    function contains a hyperlink to one or more code examples. In this
  5370.    chapter you will copy example code from on-line help to use in QCARDS.
  5371.    You'll use some of these examples as you
  5372.  
  5373.    ■ Copy example code from on-line help and paste it into the View window
  5374.  
  5375.    ■ Edit text copied from on-line help to work in a specific program
  5376.  
  5377.    This chapter takes about one to one and one-half hours to complete.
  5378.  
  5379.  
  5380.  Copying Example Code from On-Line Help
  5381.  
  5382.    When you use on-line help for keywords, the QuickSCREEN describes the
  5383.    action and syntax of the keyword. If you have used the statement before,
  5384.    the syntax block may give all the information you need to write your code.
  5385.    However, if the statement is new to you, the Details and Example screens
  5386.    clarify how to use the syntax. In the next several code-entry sequences,
  5387.    you'll find an example in on-line help that you can copy and use in
  5388.    QCARDS. Example code from on-line help may not be a perfect match for
  5389.    QCARDS. Some code that you copy conflicts with code in the program. Don't
  5390.    worry──you'll fix it later in the tutorial.
  5391.  
  5392.    QCARDS Code Entry 16
  5393.  
  5394.    1. Place the cursor on the line following this comment block (about line
  5395.       192):
  5396.  
  5397.       ' Get user keystroke with a conditional DO...LOOP statement.
  5398.       ' Within the loop, use the INKEY$ function to capture a user
  5399.       ' keystroke, which is then assigned to a string variable. The
  5400.       ' WHILE part of the LOOP line keeps testing the string
  5401.       ' variable. Until a key is pressed, INKEY$ keeps returning a
  5402.       ' null (that is a zero-length) string, represented by "".
  5403.       ' When a key is pressed, INKEY$ returns a string with a
  5404.       ' length greater than zero, and the loop terminates.
  5405.  
  5406.    2. Create a blank line (press ENTER). Then, type do
  5407.  
  5408.    3. Display the QuickSCREEN for the DO keyword (press F1).
  5409.  
  5410.       When you press F1 when the cursor is on a blank space, QuickBASIC
  5411.       displays context-sensitive help on the symbol at the left of the
  5412.       cursor. Note that the cursor remains in the View window.
  5413.  
  5414.    4. Move the cursor into the Help window (press F6 twice).
  5415.  
  5416.    5. Choose the Example hyperlink (press E, then press F1).
  5417.  
  5418.       The example screen appears in the Help window (see Figure 8.1):
  5419.  
  5420.  
  5421.       File  Edit  View  Search  Run  Debug  Calls  Options              Help
  5422.    ┌───────────── HELP: DO...LOOP Statement Programming Examples ────────┤├──
  5423.    │  QuickSCREEN     Details     Example     Contents     Index
  5424.    │─────────────────────────────────────────────────────────────────────────
  5425.    │DO...LOOP Statement Programming Examples
  5426.    │
  5427.    │Following are four examples. The first two examples show you how
  5428.    │placement of the condition affects the number of times the block
  5429.    │of statements is executed. The third example shows how a loop
  5430.    │can be used to pause a program until the user presses a key. The
  5431.    │fourth example illustrates testing at the end of a loop and presents
  5432.    │a sort subprogram where an ending test is appropriate.
  5433.    │
  5434.    │DO...LOOP Programming Example 1
  5435.    │
  5436.    │In the following example, the test is done at the beginning of the
  5437.    │loop. Because I is not less than 10, the body of the loop (the
  5438.    │statement block) is never executed.
  5439.    │
  5440.    │' DO...LOOP with test at the top of the loop.
  5441.    │' Output shows that loop was not executed.
  5442.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  5443.    ├───────────────────────────── CHAPTER7.BAS ──────────────────────────┤├──
  5444.    ├─────────────────────────────── Immediate ────────────────────────────────
  5445.     <Shift+F1=Help> <F6=Window> <Esc=Cancel> <Ctrl+F1=Next> <Alt+F1=Back>
  5446.  
  5447.    Figure 8.1  Example Screen for DO...LOOP Statement
  5448.  
  5449.    The first paragraph of the screen describes the examples below. The
  5450.    description of the third example corresponds closely to the task you want
  5451.    to code into QCARDS at this point. Follow these steps to place the example
  5452.    code on the Clipboard:
  5453.  
  5454.    QCARDS Code Entry 17
  5455.  
  5456.    1. Scroll down to Example 3. It looks like this:
  5457.  
  5458.       ' DO...LOOP with test at the bottom of the loop.
  5459.         DO
  5460.             Choice$ = INKEY$
  5461.         LOOP WHILE Choice$ = ""
  5462.  
  5463.    2. Select all four of the above lines.
  5464.  
  5465.    3. Choose the Copy command from the Edit menu to place the lines on the
  5466.       Clipboard (press ALT+E, then press C).
  5467.  
  5468.    4. Close the Help window (press ESC).
  5469.  
  5470.    5. Select the DO you typed into the View window just before moving to the
  5471.       Help window (press SHIFT+HOME).
  5472.  
  5473.    6. Choose the Paste command from the Edit menu (press ALT+E, then press
  5474.       P).
  5475.  
  5476.       The text from the Clipboard replaces the text that was selected.
  5477.  
  5478.    7. Choose the Run menu's Start command to check for errors (press ALT+R,
  5479.       then press S), then return to QuickBASIC (press CTRL+BREAK).
  5480.  
  5481.    You can use on-line help to check for potential conflicts between the code
  5482.    you just copied and QCARDS, as follows:
  5483.  
  5484.    1. Place the cursor on Choice$ and press F1.
  5485.  
  5486.    2. On-line help shows you that variables named Choice$ now occur twice in
  5487.       QCARDS, once in the module-level code and once in the EditString
  5488.       procedure. These don't conflict because variables local to a procedure
  5489.       are not known at the module level and vice versa.
  5490.  
  5491.  
  5492.  Indenting a Block of Code
  5493.  
  5494.    The loop you just entered is "nested" within the unconditional loop you
  5495.    entered earlier (in "QCARDS Code Entry 15," in Chapter 7, "Programming
  5496.    with On-Line Help"). This means that it is executed once each time the
  5497.    outer loop is executed. Nested code is usually indented one tab stop to
  5498.    the right of the code encompassing it to show visually the levels of
  5499.    nesting within your program. Here's a reminder of how to indent multiple
  5500.    text lines as a block:
  5501.  
  5502.    1. Select the three code lines you just entered. They look like this:
  5503.  
  5504.       DO
  5505.            Choice$ = INKEY$
  5506.       LOOP WHILE Choice$ = ""
  5507.  
  5508.    2. Move the whole block right one tab stop (press TAB).
  5509.  
  5510.    3. Remove the selection from the block (press any DIRECTION key).
  5511.  
  5512.    The rest of the code you enter in QCARDS is nested within the
  5513.    unconditional DO loop so each block should be similarly indented.
  5514.  
  5515.  
  5516.  Copying Large Code Blocks from On-Line Help
  5517.  
  5518.    The code you copied in the preceding section was short and simple. It
  5519.    contained only one variable name, so the likelihood of a conflict with an
  5520.    existing symbol in QCARDS was small.
  5521.  
  5522.    You can copy larger blocks of example code from on-line help and paste
  5523.    them into programs you write. However, the code you copy may conflict with
  5524.    code you've already written into your program. In this section you'll copy
  5525.    more example code into QCARDS, then customize it significantly. Some of it
  5526.    will conflict, but you'll fix it later.
  5527.  
  5528.    QCARDS Code Entry 18
  5529.  
  5530.    1. Move the cursor to the line beneath the following comment block (about
  5531.       line 222):
  5532.  
  5533.       ' The ELSE clause is only executed if Choice$ is longer than a
  5534.       ' single character (and therefore not a command-line key).
  5535.       ' If Choice$ is not an ASCII key, it represents an "extended"
  5536.       ' key. (The extended keys include the DIRECTION keys on the
  5537.       ' numeric keypad, which is why QCARDS looks for them.) The
  5538.       ' RIGHT$ function is then used to trim away the extra byte,
  5539.       ' leaving a value that may correspond to one of the DIRECTION
  5540.       ' keys. Use a SELECT CASE construction to respond to those key-
  5541.       ' presses that represent numeric-keypad DIRECTION keys.
  5542.  
  5543.    2. Create a blank line (press ENTER), then type
  5544.  
  5545.       select case Choice$
  5546.  
  5547.    3. Press HOME, then display help for the SELECT CASE statement (press F1).
  5548.  
  5549.    4. The help screen shown in Figure 8.2 appears.
  5550.  
  5551.  
  5552.       File  Edit  View  Search  Run  Debug  Calls  Options              Help
  5553.    ┌─────────────────── HELP: SELECT Statement QuickSCREEN ──────────────┤├──
  5554.    │  QuickSCREEN     Details     Example     Contents     Index
  5555.    │─────────────────────────────────────────────────────────────────────────
  5556.    │SELECT CASE - a control flow statement that executes one of several
  5557.    │              statement blocks depending on the value of an expression
  5558.    │
  5559.    │Syntax
  5560.    │  SELECT CASE textexpression
  5561.    │  [CASE expressionlist1]
  5562.    │    [statementblock-1]
  5563.    │  [CASE expressionlist2
  5564.    │    [statementblock-2] ...
  5565.    │
  5566.    │  [CASE ELSE
  5567.    │    [statementblock-n]]
  5568.    │  END SELECT
  5569.    │
  5570.    │  ■ testexpression is any numeric or string expression.
  5571.    │  ■ expressionlist contains one or more expressions of the same type as
  5572.    │    testexpression
  5573.    ├───────────────────────────── CHAPTER7.BAS ──────────────────────────┤├──
  5574.    │            SELECT CASE Choice$
  5575.    ├─────────────────────────────── Immediate ────────────────────────────────
  5576.     <Shift+F1=Help> <F6=Window> <F2=Subs> <F5=Run> <F8=Step>         00214:013
  5577.  
  5578.    Figure 8.2  QuickSCREEN for SELECT CASE Statement
  5579.  
  5580.    The SELECT CASE statement is commonly used like a switchboard in
  5581.    situations where there are numerous possible inputs, and many of them must
  5582.    be handled in unique ways. You don't want to take a unique action for each
  5583.    key a user might press, but with this kind of structure you can add CASE
  5584.    clauses for each key you want to handle. Then you can treat the rest of
  5585.    the possible keys as "none of the above" with CASE ELSE.
  5586.  
  5587.    In the following steps you'll copy a large piece of code from on-line
  5588.    help:
  5589.  
  5590.    QCARDS Code Entry 19
  5591.  
  5592.    1. Move the cursor into the help window (press SHIFT+F6 twice).
  5593.  
  5594.    2. Choose the Example hyperlink at the top of the screen to move the
  5595.       examples into the Help window (press E, then press F1).
  5596.  
  5597.    3. Choose the Search menu's Find command (press ALT+S, then press F), type
  5598.       Example 2 in the text box, then press ENTER.
  5599.  
  5600.    4. Scroll down (about 15 lines) to the line: IF LEN(Choice$) = 1 THEN
  5601.  
  5602.    5. Select this line, and the next 43 lines, all the way down to END IF.
  5603.       (Be careful not to include the final LOOP statement in the selected
  5604.       text.)
  5605.  
  5606.    6. Choose the Copy command from the Edit menu (press ALT+E, then press C).
  5607.  
  5608.    7. Close the Help window (press ESC). This puts the cursor back on SELECT
  5609.       CASE in the View window.
  5610.  
  5611.    8. Select the line SELECT CASE Choice$ (press SHIFT+END).
  5612.  
  5613.    9. Choose the Paste command from the Edit menu (press ALT+E, then press
  5614.       P).
  5615.  
  5616.       The code pasted after the comment block should appear as follows:
  5617.  
  5618.       IF LEN(Choice$) = 1 THEN
  5619.           ' Handle ASCII keys
  5620.               SELECT CASE ASC(Choice$)
  5621.                   CASE ESC
  5622.                       PRINT "Escape key"
  5623.                       END
  5624.                   CASE IS  32, 127
  5625.                       PRINT "Control code"
  5626.                   CASE 30 TO 29
  5627.                       PRINT "Digit: "; Choice$
  5628.                   CASE 65 TO 90
  5629.                       PRINT "Uppercase letter: "; Choice$
  5630.                   CASE 97 TO 122
  5631.                       PRINT "Lowercase letter: "; Choice$
  5632.                   CASE ELSE
  5633.                       PRINT "Punctuation: "; Choice$
  5634.                   END SELECT
  5635.  
  5636.       ELSE
  5637.           ' Convert 2-byte extended code to 1-byte ASCII code and
  5638.           ' handle
  5639.               Choice$ = RIGHT$(Choice$, 1)
  5640.  
  5641.               SELECT CASE Choice$
  5642.                   CASE CHR$(DOWN)
  5643.                       PRINT "DOWN arrow key"
  5644.                   CASE CHR$(UP)
  5645.                       PRINT "UP arrow key"
  5646.                   CASE CHR$(PGDN)
  5647.                       PRINT "PGDN key"
  5648.                   CASE CHR$(PGUP)
  5649.                       PRINT "PGUP key"
  5650.                   CASE CHR$(HOME)
  5651.                       PRINT "HOME key"
  5652.                   CASE CHR$(ENDKEY)
  5653.                       PRINT "END key"
  5654.                   CASE CHR$(RIGHT)
  5655.                       PRINT "RIGHT arrow key"
  5656.                   CASE CHR$(LEFT)
  5657.                       PRINT "LEFT arrow key"
  5658.                   CASE ELSE
  5659.                       BEEP
  5660.               END SELECT
  5661.       END IF
  5662.  
  5663.    Now test your work, then save it:
  5664.  
  5665.    QCARDS Code Entry 20
  5666.  
  5667.    1. Choose the Run menu's Start command (press ALT+R, then press S).
  5668.  
  5669.       As you press keys, their names are printed on the QCARDS output screen.
  5670.  
  5671.    2. Return to the QuickBASIC environment (press ESC).
  5672.  
  5673.       The ESC key case in the code you copied terminates the program.
  5674.  
  5675.    3. Save the program as CHAPTER8.BAS.
  5676.  
  5677.    This example code works into QCARDS easily because handling keyboard input
  5678.    is a common task. You can copy, then adapt, this type of code for your
  5679.    programs.
  5680.  
  5681.  
  5682.  Editing the Block Copied from On-Line Help
  5683.  
  5684.    Examining and analyzing code from other programs is a great way to extend
  5685.    your programming skills. Modifying code from on-line help to work in your
  5686.    programs can also save you time. Each case in the SELECT CASE...END SELECT
  5687.    blocks deals with a key code representing a command the user can choose
  5688.    while using QCARDS. The following steps show you how to modify this block:
  5689.  
  5690.    QCARDS Code Entry 21
  5691.  
  5692.    1. Select the whole first block (below the ' Handle ASCII keys comment,
  5693.       about line 225). It looks like this:
  5694.  
  5695.       SELECT CASE ASC(Choice$)
  5696.                   CASE ESC
  5697.                       PRINT "Escape key"
  5698.                       END
  5699.                   CASE IS < 32, 127
  5700.                       PRINT "Control code"
  5701.                   CASE 30 TO 29
  5702.                       PRINT "Digit: "; Choice$
  5703.                   CASE 65 TO 90
  5704.                       PRINT "Uppercase letter: "; Choice$
  5705.                   CASE 97 TO 122
  5706.                       PRINT "Lowercase letter: "; Choice$
  5707.                   CASE ELSE
  5708.                       PRINT  "Punctuation "; Choice$
  5709.               END SELECT
  5710.  
  5711.       This block displays the category of ASCII key the user presses. QCARDS
  5712.       already has a procedure named AsciiKey that examines the code of the
  5713.       key the user presses, then calls other procedures to carry out the
  5714.       user's commands.
  5715.  
  5716.       When you type in the call to AsciiKey (in the next step), what you type
  5717.       replaces this selected block.
  5718.  
  5719.    2. Type the following line at the cursor:
  5720.  
  5721.       call AsciiKey(Choice$, TopCard, LastCard)
  5722.  
  5723.       The AsciiKey procedure is called with three arguments, which convey
  5724.       information AsciiKey needs to carry out its tasks. Choice$ contains the
  5725.       code for the key the user presses, TopCard contains the number of the
  5726.       card at the front of the screen, and LastCard holds the number
  5727.       representing the last record in the Index()array.
  5728.  
  5729.    3. Indent the line you just entered two tab stops.
  5730.  
  5731.       The edited code should look like this (see Figure 8.3):
  5732.  
  5733.  
  5734.          File  Edit  View  Search  Run  Debug  Calls  Options              Hel
  5735.       ┌────────────────────────────── CHAPTER7.BAS ─────────────────────────┤
  5736.       │' presses that represent numeric-keypad direction keys.
  5737.       │
  5738.       │        IF LEN(Choice$) = 1 THEN
  5739.       │            ' Handle ASCII keys
  5740.       │            CALL AsciiKey(Choice$, TopCard, LastCard)
  5741.       │        ELSE
  5742.       │            ' Convert extended to ASCII and handle
  5743.       │            Choice$ = RIGHT$(Choice$, 1)
  5744.       │            '
  5745.       │            SELECT CASE Choice$
  5746.       │                CASE CHR$(DOWN)
  5747.       │                    PRINT "DOWN arrow key"
  5748.       │                CASE CHR$(UP)
  5749.       │                    PRINT "UP arrow key"
  5750.       │                CASE CHR$(PGDN)
  5751.       │                    PRINT "PGDN key"
  5752.       │                CASE CHR$(PGUP)
  5753.       │                    PRINT "PGUP key"
  5754.       │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  5755.       ├─────────────────────────────── Immediate ─────────────────────────────
  5756.       │
  5757.       │
  5758.        <Shift+F1=Help> <F6=Window> <F2=Subs> <F5=Run> <F8=Step>         00209:
  5759.  
  5760.       Figure 8.3  Code Showing Call to AsciiKey Procedure
  5761.  
  5762.    4. Choose the Run menu's Start command (press ALT+R, then press S).
  5763.  
  5764.    Try issuing some of the QCARDS commands. You should be able to edit the
  5765.    card at the front of the screen. However, if you press the DIRECTION keys,
  5766.    you still just get a description of the key overprinted on the QCARDS
  5767.    screen.
  5768.  
  5769.    To begin to make QCARDS' DIRECTION keys functional, you'll need to edit
  5770.    more of the text you copied from on-line help, as follows:
  5771.  
  5772.    QCARDS Code Entry 22
  5773.  
  5774.    1. Choose the QCARDS Quit command and return to QuickBASIC (press Q).
  5775.  
  5776.    2. Place the cursor in the first column of the line PRINT "DOWN arrow key"
  5777.  
  5778.    3. Select the whole line (press SHIFT+END), then replace it by typing this
  5779.       line:
  5780.  
  5781.       TopCard = TopCard - 1
  5782.  
  5783.       This line is executed when the user presses the DOWN key. It decreases
  5784.       the value of the card representing the data at the front of the screen
  5785.       by one. This is the user's way of telling QCARDS to show the record
  5786.       whose number is one less than the current top card.
  5787.  
  5788.    4. Indent the line, then edit the rest of the cases so the final block
  5789.       looks exactly as follows:
  5790.  
  5791.       SELECT CASE Choice$
  5792.                  CASE CHR$(DOWN)
  5793.                       TopCard = TopCard - 1
  5794.                  CASE CHR$(UP)
  5795.                       TopCard = TopCard + 1
  5796.                  CASE CHR$(PGDN)
  5797.                       TopCard = TopCard - CARDSPERSCREEN
  5798.                  CASE CHR$(PGUP)
  5799.                       TopCard = TopCard + CARDSPERSCREEN
  5800.                  CASE CHR$(HOME)
  5801.                       TopCard = LastCard
  5802.                  CASE CHR$(ENDKEY)
  5803.                       TopCard = 1
  5804.                  CASE ELSE
  5805.                       BEEP
  5806.              END SELECT
  5807.  
  5808.       The final two DIRECTION key cases (RIGHT and LEFT) of the block you
  5809.       copied from on-line help are not needed in QCARDS (since the cards
  5810.       cannot move sideways), so you can delete those cases.
  5811.  
  5812.       The CASE ELSE part of the statement is executed if the QCARDS user
  5813.       presses a key with an extended character code for which no other case
  5814.       is provided.
  5815.  
  5816.    5. Save the program as CHAPTER8.BAS.
  5817.  
  5818.    You can replace the BEEP statement used in the CASE ELSE case of the Help
  5819.    example with a call to the Alarm procedure you created in Chapter 5, "The
  5820.    QCARDS Program." The following steps use the Find command to place an
  5821.    earlier call to the Alarm procedure on the Clipboard, then select this
  5822.    BEEP statement and replace it with CALL Alarm.
  5823.  
  5824.    Optional QCARDS Code Entry 4
  5825.  
  5826.    1. Choose the Search menu's Find command (press ALT+S, then press F), type
  5827.       CALL Alarm in the text box, and press ENTER.
  5828.  
  5829.    2. QuickBASIC searches for and then selects CALL Alarm, which was entered
  5830.       in the program in Chapter 5, "The QCARDS Program."
  5831.  
  5832.    3. Choose the Edit menu's Cut command (press ALT+E, then press T). (The
  5833.       words CALL Alarm are selected, so you don't need to highlight them.)
  5834.  
  5835.    4. Choose the Find command again, type BEEP in the text box, and press
  5836.       ENTER.
  5837.  
  5838.       The match is made with BEEP in the CASE ELSE statement.
  5839.  
  5840.    5. Choose the Edit menu's Paste command to replace BEEP with CALL Alarm
  5841.       (press ALT+E, then press P).
  5842.  
  5843.  
  5844.  Finishing the QCARDS Code
  5845.  
  5846.    The SELECT CASE block changes the value of TopCard when the user presses
  5847.    DIRECTION keys, but doesn't do anything to actually change the information
  5848.    displayed on the cards.
  5849.  
  5850.    The following code lines take care of three eventualities that can arise
  5851.    from certain combinations of DIRECTION key presses, then shows the correct
  5852.    data on the cards:
  5853.  
  5854.    QCARDS Code Entry 23
  5855.  
  5856.    1. Place the cursor on the line beneath the following comment (about line
  5857.       252):
  5858.  
  5859.       ' Adjust the cards according to the key pressed by the user,
  5860.       ' then call the ShowCards procedure to show adjusted stack.
  5861.  
  5862.    2. Create an empty line (press ENTER), then type the following code,
  5863.       exactly as shown:
  5864.  
  5865.       if TopCard < 1 then TopCard = LastCard + TopCard
  5866.       if TopCard > LastCard then TopCard = TopCard - LastCard
  5867.       if TopCard <= 0 then TopCard = 1
  5868.  
  5869.       These three lines use the single line form of IF...THEN to "rotate" the
  5870.       card stack. They prevent TopCard from being passed to ShowCards when it
  5871.       has a value that is beyond the range of the Index()array.
  5872.  
  5873.    3. Now type your final code line:
  5874.  
  5875.       CALL ShowCards(TopCard, LastCard)
  5876.  
  5877.       The ShowCards procedure places the proper data on the front card, and
  5878.       the proper name on each of the cards behind it.
  5879.  
  5880.    4. Save the program now as CHAPTER8.BAS.
  5881.  
  5882.    5. Choose the Run menu's Start command to run QCARDS (press ALT+R, then
  5883.       press S).
  5884.  
  5885.  
  5886.  Using QCARDS
  5887.  
  5888.    The commands on the command line at the bottom of the QCARDS output screen
  5889.    are now fully functional. Take a few minutes to try each feature. The
  5890.    commands are summarized in the following list:
  5891.  
  5892. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  5893.    QCARDS Command           Result
  5894.    ──────────────────────────────────────────────────────────────────────────
  5895.    Edit Top                 Lets you change any or all fields of the card at
  5896.                             the front of the screen.
  5897.  
  5898.    Add New                  Places a "blank card" on the front of the screen
  5899.                             for you to fill in.
  5900.  
  5901.    Copy to New              Duplicates all fields of the current top card on
  5902.                             a new card.
  5903.    QCARDS Command           Result
  5904.    ──────────────────────────────────────────────────────────────────────────
  5905.                            a new card.
  5906.  
  5907.    Delete                   Marks the current top card for deletion. Note
  5908.                             that it is not actually deleted until you choose
  5909.                             Quit. Therefore, if you decide not to delete the
  5910.                             card, you can use CTRL+BREAK to break out of the
  5911.                             program. When you restart, the card will still be
  5912.                             there.
  5913.  
  5914.    Find                     Lets you move to one of the fields, then type
  5915.                             what you want to search for. If an exact match is
  5916.                             found, the card with the exact match is placed in
  5917.                             the first position. If no exact match is found,
  5918.                             QCARDS beeps.
  5919.  
  5920.    Sort                     Orders the cards alphabetically (or numerically)
  5921.                             by the field in which you place the cursor. For
  5922.                             example, if the cursor is in the zip code (Zip)
  5923.                             field, Sort orders the cards in increasing zip
  5924.    QCARDS Command           Result
  5925.    ──────────────────────────────────────────────────────────────────────────
  5926.                            field, Sort orders the cards in increasing zip
  5927.                             code order. If you place the cursor in the state
  5928.                             (ST) field, the cards are ordered alphabetically
  5929.                             by state.
  5930.  
  5931.    Print                    Prints out just the name and address fields (for
  5932.                             use on a mailing label).
  5933.  
  5934.    Quit                     Writes the current Index array to the
  5935.                             random-access disk file. If any cards have been
  5936.                             marked as deleted, they are removed from the file
  5937.                             at this time. Edits to cards and additions to the
  5938.                             file are also made when you quit QCARDS. Quit
  5939.                             then terminates the QCARDS program.
  5940.    ──────────────────────────────────────────────────────────────────────────
  5941.  
  5942.  
  5943.    Try the DIRECTION keys too. Most of the DIRECTION keys work. However, by
  5944.    copying code from Help, you inadvertently incorporated a naming
  5945.    inconsistency that caused a bug in your code. In the next chapter, you'll
  5946.    use QuickBASIC's debugging features to remove the bug.
  5947.  
  5948.  
  5949.  For More Information
  5950.  
  5951.    For more information on on-line help, see the following:
  5952.  
  5953.    Chapter                  Topic
  5954.    ──────────────────────────────────────────────────────────────────────────
  5955.    Section 10.8, "Using    Information on QuickBASIC's Help menu commands
  5956.    On-Line Help" and        and complete descriptions of all the Help
  5957.    Chapter 21, "The Help   features.
  5958.    Menu"
  5959.    ──────────────────────────────────────────────────────────────────────────
  5960.  
  5961.  
  5962.  
  5963.  ────────────────────────────────────────────────────────────────────────────
  5964.  Chapter 9  Debugging While You Program
  5965.  
  5966.  Microsoft QuickBASIC's smart editor keeps your code free of syntax errors as
  5967.  you enter individual statements. But QuickBASIC has other features that help
  5968.  you isolate "bugs"──errors in the general logic or specific details of your
  5969.  program that cause it to behave in unanticipated ways. Some of these
  5970.  features are on the Debug menu, while others are on the Run menu. Still
  5971.  others are controlled completely by function keys. These features let you
  5972.  suspend program execution at any point, control which statements of your
  5973.  program execute, and monitor the values of variables.
  5974.  
  5975.    In this chapter, you'll find a real bug and fix it. You'll practice
  5976.  
  5977.    ■ Using QuickBASIC's debugging features
  5978.  
  5979.    ■ Defining and calling a procedure that has parameters
  5980.  
  5981.    ■ Creating a stand-alone executable file from within QuickBASIC
  5982.  
  5983.    This chapter takes about one to one and one-half hours to complete.
  5984.  
  5985.  
  5986.  Debugging Commands
  5987.  
  5988.    Most QuickBASIC debugging commands are on the Debug menu. However, some of
  5989.    the most useful debugging features are on the Run menu, or are accessible
  5990.    only through function keys.
  5991.  
  5992.  Debug-Menu Commands
  5993.  
  5994.    Commands on the Debug menu let you control program flow and monitor the
  5995.    value of variables in a running program.
  5996.  
  5997.    Command (and Shortcut    Action
  5998.    Key)
  5999.    ──────────────────────────────────────────────────────────────────────────
  6000.    Add Watch                Places a variable you specify into the Watch
  6001.                             window, then continually updates its value.
  6002.  
  6003.    Instant Watch (SHIFT+F9) Gives current value of a highlighted variable;
  6004.                             optionally, places the variable in Watch window.
  6005.  
  6006.    Delete Watch             Deletes the specified variable from Watch window.
  6007.  
  6008.    Toggle Breakpoint (F9)   Sets a "breakpoint" at the cursor if one is not
  6009.                             currently set there. A breakpoint is a specified
  6010.                             location where program execution will halt. If
  6011.                             there is a breakpoint currently set at the
  6012.                             cursor, choosing Toggle Breakpoint turns it off.
  6013.  
  6014.    Clear All Breakpoints    Turns off all breakpoints everywhere in the
  6015.                             program.
  6016.    ──────────────────────────────────────────────────────────────────────────
  6017.  
  6018.  Debugging Commands on the Run Menu
  6019.  
  6020.    Commands from the Run menu control program execution during debugging.
  6021.  
  6022.    Command (and Shortcut    Action
  6023.    Key)
  6024.    ──────────────────────────────────────────────────────────────────────────
  6025.    Start (SHIFT+F5)         Runs the program in the View window beginning
  6026.                             with the first statement.
  6027.  
  6028.    Restart                  Resets all variables to zero (or zero-length
  6029.                             strings), compiles declarations, and sets the
  6030.                             first executable statement as the current
  6031.                             statement.
  6032.  
  6033.    Continue (F5)            Continues execution of a suspended program from
  6034.                             the current statement. In a program that is not
  6035.                             running, the effect is identical to the Start
  6036.                             command.
  6037.    ──────────────────────────────────────────────────────────────────────────
  6038.  
  6039.  Function Keys Used in Debugging
  6040.  
  6041.    The following table shows the debugging commands that are controlled only
  6042.    by function keys:
  6043.  
  6044.    Command                  Action
  6045.    ──────────────────────────────────────────────────────────────────────────
  6046.    F7                       Executes program to statement at the cursor.
  6047.  
  6048.    F8                       Single steps through your program. Each time you
  6049.                             press F8, the execution sequence progresses one
  6050.                             statement. If the current statement is a
  6051.                             procedure invocation, F8 moves the procedure
  6052.                             definition into the View window. If the program
  6053.                             is not already running, F8 acts the same as the
  6054.                             Run menu's Restart command: pressing F8 restarts
  6055.                             the program, making the first executable
  6056.                             statement the current statement. In a suspended
  6057.                             program, F8 executes the current statement in the
  6058.                             execution sequence.
  6059.  
  6060.    F10                      Single steps through your program. F10 steps over
  6061.                             or executes all statements of a procedure as
  6062.                             though they were a single statement without
  6063.                             moving the procedure definition into the View
  6064.                             window. Otherwise, F10 acts the same as F8.
  6065.    ──────────────────────────────────────────────────────────────────────────
  6066.  
  6067.  
  6068.  Debugging a Procedure
  6069.  
  6070.    In this section you'll use everything you've learned so far to turn the
  6071.    SELECT CASE block that handles DIRECTION keys into a procedure. In Chapter
  6072.    5, "The QCARDS Program," you saw how easy it is to define procedures with
  6073.    QuickBASIC. The procedure you create in the next code-entry sequence is
  6074.    defined with parameters. When it is called, it is called with arguments.
  6075.  
  6076.    The following steps tell you how to create a SUB procedure with the name
  6077.    DirectionKey. As noted in Chapter 5, when QuickBASIC's smart editor
  6078.    processes the word sub followed by a procedure name, it opens a window and
  6079.    starts the procedure with the SUB and END SUB statements.
  6080.  
  6081.    QCARDS Code Entry 24
  6082.  
  6083.    1. Start QuickBASIC if it is not already running, and open CHAPTER8.BAS.
  6084.  
  6085.    2. Place the cursor in the leftmost column of the line containing SELECT
  6086.       CASE Choice$ (about line 231), then select the whole block (a total of
  6087.       16 lines) down to and including END SELECT. It looks like this (see
  6088.       Figure 9.1):
  6089.  
  6090.  
  6091.       ┌────────────────────────────────────┐
  6092.       │                                    │
  6093.       │   Figure 9.1 can be found on       │
  6094.       │   page 132 of the printed manual.  │
  6095.       │                                    │
  6096.       └────────────────────────────────────┘
  6097.  
  6098.       Figure 9.1  Selecting the SELECT CASE Choice$ Block
  6099.  
  6100.    3. Choose the Edit menu's Cut command to delete the text and place it on
  6101.       the Clipboard (press ALT+E, then press T).
  6102.  
  6103.    4. Create a blank line above the END IF statement, then move the cursor to
  6104.       column 1 of the new blank line.
  6105.  
  6106.    5. Type
  6107.  
  6108.       sub DirectionKey(Choice$, TopCard%, LastCard%)
  6109.  
  6110.       then press ENTER.
  6111.  
  6112.       Notice that QuickBASIC has started a SUB...END SUB procedure with the
  6113.       name you specified, and has moved it into the View window.
  6114.  
  6115.    6. Put the cursor on the blank line immediately above the END SUB
  6116.       statement (press DOWN).
  6117.  
  6118.    7. Choose the Edit menu's Paste command to paste the text block from the
  6119.       Clipboard. The procedure should look like Figure 9.2.
  6120.  
  6121.  
  6122.       File  Edit  View  Search  Run  Debug  Calls  Options              Help
  6123.    ┌──────────────────────── CHAPTER8.BAS:DirectionKey ──────────────────┤├──
  6124.    │DEFINT A-Z
  6125.    │SUB DirectionKey (Choice$, TopCard%, LastCard%)
  6126.    │        SELECT CASE Choice$
  6127.    │            CASE CHR$(DOWN)
  6128.    │                TopCard = TopCard - 1
  6129.    │            CASE CHR$(UP)
  6130.    │                TopCard = TopCard + 1
  6131.    │            CASE CHR$(PGDN)
  6132.    │                TopCard = TopCard - CARDPERSCREEN
  6133.    │            CASE CHR$(PGUP)
  6134.    │                TopCard = TopCard + CARDPERSCREEN
  6135.    │            CASE CHR$(HOME)
  6136.    │                TopCard = LastCard
  6137.    │            CASE CHR$(ENDKEY)
  6138.    │                TopCard = 1
  6139.    │            CASE ELSE
  6140.    │                CALL Alarm
  6141.    │        END SELECT
  6142.    │
  6143.    │END SUB
  6144.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  6145.    ├─────────────────────────────── Immediate ────────────────────────────────
  6146.     <Shift+F1=Help> <F6=Window> <F2=Subs> <F5=Run> <F8=Step>         00003:013
  6147.  
  6148.    Figure 9.2  DirectionKey Procedure in View Window
  6149.  
  6150.    Now that the procedure is defined, you have to put a CALL statement at the
  6151.    place where you deleted the text. The CALL statement makes the statements
  6152.    in a SUB procedure part of the program's execution sequence. Do the
  6153.    following:
  6154.  
  6155.    QCARDS Code Entry 25
  6156.  
  6157.    1. Choose the View menu's SUBs command (press F2).
  6158.  
  6159.       Note that the fifth entry under CHAPTER8.BAS is now DirectionKey.
  6160.  
  6161.    2. Select CHAPTER8.BAS if it isn't already selected. Press ENTER to return
  6162.       the cursor to the module-level code.
  6163.  
  6164.    3. Move the cursor to the end of the following line (at about line 229):
  6165.  
  6166.       Choice$ = RIGHT$(Choice$, 1)
  6167.  
  6168.    4. Create a blank line (press ENTER). Then, type the following line at the
  6169.       cursor but do not press ENTER:
  6170.  
  6171.       call DirectionKey(Choice$, TopCard, LastCard)
  6172.  
  6173.    The DirectionKey procedure is more complicated than Alarm because it is
  6174.    defined with parameters (the words in parentheses in the SUB statement you
  6175.    created earlier) and called with arguments (the words in parentheses in
  6176.    the CALL statement). You don't have to use the same names for the
  6177.    parameters as you use for the arguments, but it is all right to do so.
  6178.  
  6179.    The DirectionKey procedure makes QCARDS' module-level code easier to
  6180.    follow because the arithmetic for handling DIRECTION keys is now
  6181.    represented by a single statement, rather than 15 lines of statements.
  6182.    Using procedures costs almost nothing in terms of execution speed or
  6183.    program size, so the added program readability is worth the small effort
  6184.    of programming them. Procedures are especially beneficial for tasks that
  6185.    are performed repeatedly in a program.
  6186.  
  6187.  Learning about Procedures
  6188.  
  6189.    You can use QuickBASIC's debugging features to learn about procedures. The
  6190.    cursor should still be on the call you just typed to Direction Key (about
  6191.    line 226). Try the following:
  6192.  
  6193.    1. Execute the program up to the call to DirectionKey (press F7).
  6194.  
  6195.       QCARDS starts to run. In the following step you will press a DIRECTION
  6196.       key while QCARDS is running, causing QuickBASIC to suspend execution at
  6197.       the call to DirectionKey.
  6198.  
  6199.    2. Press a DIRECTION key (preferably PGUP).
  6200.  
  6201.       This returns control to the QuickBASIC environment. The statement CALL
  6202.       DirectionKey appears in high-intensity video. It hasn't been executed
  6203.       yet──it is the current statement.
  6204.  
  6205.    3. Execute the CALL DirectionKey procedure as a single statement (press
  6206.       F10). The END IF statement appears in high-intensity video. It is now
  6207.       the current statement.
  6208.  
  6209.  Continuing a Suspended Program
  6210.  
  6211.    You don't always have to start suspended programs over from the beginning
  6212.    after making edits. Usually you can just choose the Continue command from
  6213.    the Run menu to continue execution from the point of suspension. QCARDS
  6214.    should run as before. When you press DIRECTION keys, the data on the cards
  6215.    should change. Try the following:
  6216.  
  6217.    1. Continue program execution (press F5).
  6218.  
  6219.    2. Press the END key on the numeric keypad to move the data on the cards
  6220.       to the last item. The END key doesn't work. If you did the optional
  6221.       code entry in Chapter 8, the Alarm procedure sounds off because the
  6222.       END key isn't recognized as one of the cases in the SELECT CASE block.
  6223.       (If you didn't do the optional code entry in Chapter 8, QCARDS beeps.)
  6224.       You have a bug.
  6225.  
  6226.    3. Press the UP, DOWN, PGDN, and PGUP keys. They should all work. So there
  6227.       is a bug in the code dealing with the END key.
  6228.  
  6229.    4. Return to QuickBASIC (press CTRL+BREAK).
  6230.  
  6231.       QuickBASIC returns you to the environment and places the cursor at
  6232.       either the Choice$ = INKEY$ statement, or LOOP WHILE Choice$ =
  6233.       statement, whichever was executing when you pressed CTRL+BREAK. Right
  6234.       now you are stuck in this DO loop. You cannot step past it with F8 or
  6235.       F10. You will have to place the cursor on the statement following the
  6236.       loop, then use F7 to execute to it.
  6237.  
  6238.    5. Move the cursor down (about 27 lines) past the big comment block to the
  6239.       following line (at about line 224):
  6240.  
  6241.       IF LEN(Choice$) = 1 THEN
  6242.  
  6243.    6. Execute the program to the statement at the cursor (press F7). The
  6244.       QCARDS screen is displayed.
  6245.  
  6246.    7. Press the END key again.
  6247.  
  6248.       QuickBASIC returns you to the environment. The line you were on when
  6249.       you pressed F7 is highlighted:
  6250.  
  6251.       IF LEN(Choice$) = 1 THEN
  6252.  
  6253.    Usually when you suspend program execution you can press F5 to continue
  6254.    execution from the point of suspension. However, some edits you make to a
  6255.    suspended program prevent simple continuation. In the next few QCARDS
  6256.    code-entry sequences, QuickBASIC may display a dialog box indicating that
  6257.    one of the edits you have made requires restarting the program (see Figure
  6258.    9.3). That is normal. Just press ENTER and continue editing.
  6259.  
  6260.  
  6261.    ┌──────────────────────────────────────────────────────────────────────────
  6262.    │
  6263.    │  You will have to restart your program after this edit. Proceed anyway?
  6264.    │
  6265.    ├──────────────────────────────────────────────────────────────────────────
  6266.    │                      < OK >   < Cancel >   < Help >
  6267.    └──────────────────────────────────────────────────────────────────────────
  6268.  
  6269.    Figure 9.3  Restart Program Error Message
  6270.  
  6271.  
  6272.  Isolating a Bug
  6273.  
  6274.    QuickBASIC's debugging features make coding and logic errors easy to trace
  6275.    and fix because they make it easy to understand the line-by-line workings
  6276.    of your code. In the next QCARDS code-entry sequence, you'll use single
  6277.    stepping to find the bug. You know you pressed a DIRECTION key to suspend
  6278.    the program so you can anticipate that execution will move to the ELSE
  6279.    block when you execute the statement at the cursor.
  6280.  
  6281.    Follow these steps to track down the bug:
  6282.  
  6283.    QCARDS Code Entry 26
  6284.  
  6285.    1. Execute the IF statement and the one that follows and move the cursor
  6286.       to the call to DirectionKey (press F8 twice to single step up to the
  6287.       call).
  6288.  
  6289.    2. Single step into the DirectionKey procedure (press F8).
  6290.  
  6291.       The cursor is placed on the SELECT CASE statement.
  6292.  
  6293.    3. Set a breakpoint (see Figure 9.4) at the current line (press F9).
  6294.  
  6295.  
  6296.                                                           Breakpoint
  6297.                                                                │
  6298.          File  Edit  View  Search  Run  Debug  Calls  Options  │           Hel
  6299.       ┌─────────────────────── CHAPTER8.BAS:DirectionKey ──────┼────────────┤
  6300.       │DEFINT A-Z                                              │
  6301.       │SUB DirectionKey (Choice$, TopCard%, LastCard%)         │
  6302.       │        SELECT CASE Choice$
  6303.       │            CASE CHR$(DOWN)
  6304.       │                TopCard = TopCard - 1
  6305.       │            CASE CHR$(UP)
  6306.       │                TopCard = TopCard + 1
  6307.       │            CASE CHR$(PGDN)
  6308.       │                TopCard = TopCard - CARDPERSCREEN
  6309.       │            CASE CHR$(PGUP)
  6310.       │                TopCard = TopCard + CARDPERSCREEN
  6311.       │            CASE CHR$(HOME)
  6312.       │                TopCard = LastCard
  6313.       │            CASE CHR$(ENDKEY)
  6314.       │                TopCard = 1
  6315.       │            CASE ELSE
  6316.       │                CALL Alarm
  6317.       │        END SELECT
  6318.       │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  6319.       ├─────────────────────────────── Immediate ─────────────────────────────
  6320.       │
  6321.       │
  6322.        <Shift+F1=Help> <F5=Continue> <F9=Toggle Bkpt> <F8=Step>         00017:
  6323.  
  6324.       Figure 9.4  Setting a Breakpoint
  6325.  
  6326.    4. Continue execution of QCARDS (press F5 twice). When the QCARDS output
  6327.       screen appears, press the END key to activate the suspected bug.
  6328.  
  6329.       QuickBASIC returns the cursor to the line on which you set the
  6330.       breakpoint.
  6331.  
  6332.    5. Single step to the CASE ELSE statement (press F8). The CALL Alarm
  6333.       statement appears in reverse video.
  6334.  
  6335.    6. Move the cursor into the word HOME in the CASE CHR$(HOME) statement,
  6336.       then get help (press F1).
  6337.  
  6338.       The Help window opens and describes HOME as a symbolic constant with a
  6339.       value of 71 (see Figure 9.5).
  6340.  
  6341.  
  6342.          File  Edit  View  Search  Run  Debug  Calls  Options              Hel
  6343.       ┌─────────────────────────────── HELP: HOME ──────────────────────────┤
  6344.       │HOME is a symbol that is used in your program as follows:
  6345.       │
  6346.       │┌  C:\QB4.5\DEMO\DIR1\CHAPTER8.BAS ────
  6347.       ││  constant of type: INTEGER   Value = 71
  6348.       ││
  6349.       │
  6350.       │
  6351.       ├─────────────────────── CHAPTER8.BAS:DirectionKey ───────────────────┤
  6352.       │               TopCard = TopCard - CARDPERSCREEN
  6353.       │           CASE CHR$(PGUP)
  6354.       │               TopCard = TopCard + CARDPERSCREEN
  6355.       │           CASE CHR$(HOME)
  6356.       │               TopCard = LastCard
  6357.       │           CASE CHR$(ENDKEY)
  6358.       │               TopCard = 1
  6359.       │           CASE ELSE
  6360.       │               CALL Alarm
  6361.       │       END SELECT
  6362.       │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  6363.       ├─────────────────────────────── Immediate ─────────────────────────────
  6364.       │
  6365.       │
  6366.        <Shift+F1=Help> <F5=Continue> <F9=Toggle Bkpt> <F8=Step>         00012:
  6367.  
  6368.       Figure 9.5  Symbol Help for Symbolic Constant HOME
  6369.  
  6370.    7. Move the cursor down to the CASE CHR$(ENDKEY) statement, place the
  6371.       cursor in the word ENDKEY, and get help (press F1).
  6372.  
  6373.       The Help window opens and describes ENDKEY as a variable of type
  6374.       INTEGER. But ENDKEY should be a symbolic constant, just like HOME.
  6375.  
  6376.    8. Choose the Instant Watch command from the Debug menu.
  6377.  
  6378.       The value of ENDKEY is shown as zero.
  6379.  
  6380.    9. Press ENTER to place ENDKEY in the Watch window.
  6381.  
  6382.    In the program, ENDKEY should be a symbolic constant defined with a CONST
  6383.    statement in the declarations and definitions section of the program (just
  6384.    like HOME). Try this:
  6385.  
  6386.    QCARDS Code Entry 27
  6387.  
  6388.    1. Choose the View menu's SUBs command (press ALT+V, then press S), then
  6389.       choose the first entry (CHAPTER8.BAS) in the list box to move the
  6390.       module-level code of the program into the View window.
  6391.  
  6392.    2. Move the cursor to the top of the module-level code (press CTRL+HOME).
  6393.  
  6394.    3. Choose the Search menu's Find command, then type HOME in the text box
  6395.       and press ENTER.
  6396.  
  6397.    HOME is selected in the declarations and definitions section. Beside it,
  6398.    you can see the cause of the bug. The symbolic constant used to represent
  6399.    the END key is ENDK, whereas the SELECT CASE code you copied from on-line
  6400.    help used ENDKEY to represent the END key (see Figure 9.6).
  6401.  
  6402.  
  6403.       File  Edit  View  Search  Run  Debug  Calls  Options              Help
  6404.      DirectionKey ENDKEY: 0
  6405.    ┌────────────────────────────── HELP: ENDKEY ─────────────────────────┤├──
  6406.    │ENDKEY is a symbol that is used in your program as follows:
  6407.    │
  6408.    │┌  C:\QB4.5\DEMO\DIR1\CHAPTER8.BAS ────
  6409.    ││┌ SUB DirectionKey ───────────────────
  6410.    │││  variable of type: INTEGER
  6411.    ││
  6412.    ├────────────────────────────── CHAPTER8.BAS ─────────────────────────┤├──
  6413.    │CONST SPACE = 32, ESC = 27, ENTER = 13, TABKEY = 9
  6414.    │CONST DOWN = 80, UP = 72, LEFT = 75, RIGHT = 77
  6415.    │CONST HOME = 71, ENDK = 79, PGDN = 81, PGUP = 73
  6416.    │CONST INS = 82, DEL = 83, NULL = 0
  6417.    │CONST CTRLD = 4, CTRLG = 7, CTRLH = 8, CTRLS = 19, CTRLV = 22
  6418.    │
  6419.    │' Define English names for color-specification numbers. Add BRIGHT to
  6420.    │' any color to get bright version.
  6421.    │CONST BLACK = 0, BLUE = 1, GREEN = 2, CYAN = 3, RED = 4, MAGENTA = 5
  6422.    │CONST YELLOW = 6, WHITE = 7, BRIGHT = 8
  6423.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  6424.    ├─────────────────────────────── Immediate ────────────────────────────────
  6425.    │
  6426.    │
  6427.     <Shift+F1=Help> <F5=Continue> <F9=Toggle Bkpt> <F8=Step>         00024:007
  6428.  
  6429.    Figure 9.6  Error in Naming Symbolic Constant for the ENV Key
  6430.  
  6431.    Most of the symbolic-constant names used to represent the DIRECTION keys
  6432.    are the same as those shown on the keys themselves, but you can't
  6433.    represent the END key with the symbolic constant END, because END is a
  6434.    BASIC keyword. The on-line help example used ENDKEY to deal with this
  6435.    problem, QCARDS uses ENDK. It doesn't matter which is used, ENDKEY is just
  6436.    as good as ENDK. What is important is that the word used in the definition
  6437.    be the same as that used elsewhere in the program. Do the following to
  6438.    change ENDKEY to ENDK:
  6439.  
  6440.    QCARDS Code Entry 28
  6441.  
  6442.    1. Choose the Search menu's Change command (press ALT+S, then press C).
  6443.       (If you get a message saying you will have to restart your program,
  6444.       press ENTER.)
  6445.  
  6446.    2. Type ENDKEY in the first text box, then press TAB and type ENDK in the
  6447.       second text box.
  6448.  
  6449.    3. Start the search (press ENTER). The first match is in the DirectionKey
  6450.       procedure.
  6451.  
  6452.    4. Make the change (press C). The search ends. That was the only
  6453.       occurrence of ENDKEY.
  6454.  
  6455.  
  6456.  Closing the Watch Window
  6457.  
  6458.    When the Watch window is open, QuickBASIC executes more slowly than when
  6459.    it is closed. You close the Watch window by repeatedly choosing the Delete
  6460.    Watch command from the Debug menu, then choosing variables from the
  6461.    resulting dialog box until the Watch window closes. You may also want to
  6462.    occasionally choose the Clear All Breakpoints command too.
  6463.  
  6464.    1. Choose the Debug menu's Clear All Breakpoints command (press ALT+D,
  6465.       then press C).
  6466.  
  6467.    2. Choose the Debug menu's Delete Watch command (press ALT+D, then press
  6468.       D).
  6469.  
  6470.    3. Delete the entry (press ENTER).
  6471.  
  6472.    The next step is to run your program and save it. Do the following:
  6473.  
  6474.    QCARDS Code Entry 29
  6475.  
  6476.    1. Choose the Run menu's Start command. QCARDS should run and recognize
  6477.       all the DIRECTION keys as well as all the command-line keys.
  6478.  
  6479.    2. Choose Quit from the QCARDS command line, then press a key to continue.
  6480.  
  6481.    3. Choose the File menu's Save As command and save the program as
  6482.       FINALQ.BAS.
  6483.  
  6484.       QCARDS should now be fully functional.
  6485.  
  6486.  
  6487.  Automatic Procedure Declarations
  6488.  
  6489.    When you save a program, QuickBASIC creates a DECLARE statement for any
  6490.    new procedure. Generally, you should move such DECLARE statements to the
  6491.    declarations and definitions section of your program. QuickBASIC uses
  6492.    procedure declarations to check the number, order, and types of the
  6493.    arguments you pass to a procedure when you call it. DECLARE statements
  6494.    should be toward the end of the declarations and definitions below
  6495.    statements such as DEFtype and TYPE...END TYPE. You should copy the
  6496.    DECLARE statement for the procedure DirectionKey into the
  6497.    procedure-declarations portion of the declarations and definitions (as you
  6498.    did with the declaration for Alarm in Chapter 5). Do the following:
  6499.  
  6500.    QCARDS Code Entry 30
  6501.  
  6502.    1. Move to the beginning of the program (press CTRL+HOME).
  6503.  
  6504.    2. Select the entire DECLARE DirectionKey statement (press SHIFT+END).
  6505.  
  6506.    3. Delete the selected statement from QCARDS and place it on the Clipboard
  6507.       (press ALT+E, then press T).
  6508.  
  6509.    4. Move to the SUB procedure declarations section of the program (about
  6510.       line 74).
  6511.  
  6512.    5. Create a blank line (if necessary) and insert the DECLARE DirectionKey
  6513.       statement (press ALT+E,then press P).
  6514.  
  6515.    6. Save the program again as FINALQ.BAS.
  6516.  
  6517.  
  6518.  Creating a Stand-Alone Executable File
  6519.  
  6520.    1. Choose the Run menu's Make EXE File command (press ALT+R, then press
  6521.       X).
  6522.  
  6523.       If a dialog box appears asking if you want to save your files, press
  6524.       ENTER. The Make EXE File dialog box appears (see Figure 9.7):
  6525.  
  6526.  
  6527.                          Type name of executable file here.
  6528.                           │
  6529.       ┌───────────────────┼──Make EXE File─────────────────────────────┐
  6530.       │               ┌───┼───────────────────────────────────────┐    │
  6531.       │EXE File Name: │FINALQ.EXE                                 │    │
  6532.       │               └───────────────────────────────────────────┘    │
  6533.       │                                   Produce:                     │
  6534.       │  [ ] Produce Debug Code           ( ) EXE Requiring BRUN45.EXE │
  6535.       │                                   (∙) Stand-Alone EXE File     │
  6536.       ├────────────────────────────────────────────────────────────────┤
  6537.       │ < Make EXE >   < Make EXE and Exit >   < Cancel >   < Help >   │
  6538.       └────────────────────────────────────────────────────────────────┘
  6539.  
  6540.       Figure 9.7  Make EXE File Dialog Box
  6541.  
  6542.    2. Type QCARDS in the text box.
  6543.  
  6544.    3. Choose the Make EXE and Exit option (press ALT+E).
  6545.  
  6546.       QuickBASIC creates the EXE file and exits to DOS.
  6547.  
  6548.    4. Run QCARDS (type qcards at the DOS prompt and press ENTER).
  6549.  
  6550.    ──────────────────────────────────────────────────────────────────────────
  6551.    NOTE
  6552.      If you don't have a hard disk, QuickBASIC prompts you to insert a disk
  6553.      containing BC.EXE, and later prompts you for a path for libraries it
  6554.      needs to finish making the executable file. BC.EXE, LINK.EXE and
  6555.      BRUN45.LIB are on disk 3 (Utilities 1). BCOM45.LIB is located on disk 4
  6556.      (Utilities 2). When asked for a path, type in a full path including both
  6557.      drive name and file name.
  6558.    ──────────────────────────────────────────────────────────────────────────
  6559.  
  6560.  
  6561.  Learning about QuickBASIC's Other Menu Items
  6562.  
  6563.    The preceding chapters have familiarized you with most of the commands on
  6564.    QuickBASIC's Easy Menus. Two commands were not covered. The Options menu's
  6565.    Set Paths command lets you change some settings that were made
  6566.    automatically by the Setup program you used to install QuickBASIC. The
  6567.    View menu's Included Lines command is used only in programs that rely on
  6568.    include files. See Sections 20.2, "Set Paths Command," and 14.7,
  6569.    "Included Lines Command," for full discussions of these commands.
  6570.  
  6571.    Easy Menus provides a very functional programming environment for the
  6572.    novice or intermediate BASIC user. QuickBASIC's Full Menus provide
  6573.    additional commands needed for advanced or professional programming. For
  6574.    example, the Full Menus Debug menu contains commands useful for debugging
  6575.    large and complex programs. The Full Menus File menu lets you load
  6576.    multiple files simultaneously, so you can create programs using multiple,
  6577.    separately compiled source files (modules). The uses of these advanced
  6578.    commands are covered in Chapters 10-21 of this manual. The programming
  6579.    techniques are discussed in Programming in BASIC.
  6580.  
  6581.  
  6582.  For More Information
  6583.  
  6584.    For more information on the topics discussed in these chapters, see the
  6585.    following:
  6586.  
  6587.    Chapter                   Topic
  6588.    ──────────────────────────────────────────────────────────────────────────
  6589.    Chapter 2, "SUB and       Complete information on programming with
  6590.    FUNCTION Procedures,"  procedures, including rules for parameters and
  6591.    in Programming in BASIC      arguments.
  6592.  
  6593.    Chapter 17,  "Debugging  Complete rules for using all QuickBASIC's
  6594.    Concepts and              debugging features, including advanced features
  6595.    Procedures," Chapter      such as watchpoints and the Calls menu.
  6596.    18, "The Debug Menu,"
  6597.    and Chapter 19, "The
  6598.    Calls Menu"
  6599.    ──────────────────────────────────────────────────────────────────────────
  6600.  
  6601.  
  6602.  
  6603.  ────────────────────────────────────────────────────────────────────────────
  6604.  PART 3  QUICKBASIC MENUS AND COMMANDS
  6605.  ────────────────────────────────────────────────────────────────────────────
  6606.  
  6607.    Part 3, "QuickBASIC Menus and Commands," is a reference to the Microsoft
  6608.    QuickBASIC menus and commands. Refer to this part when you want detailed
  6609.    information on how a command works or situations in which you might use
  6610.    the command.
  6611.  
  6612.    Chapters 10 and 11 introduce the QuickBASIC environment and working with
  6613.    your files. Chapters 12-16 look at the QuickBASIC features that help you
  6614.    create, edit, and run your programs. Chapters 17-19 cover general
  6615.    debugging techniques and the specific tools available for faster
  6616.    debugging. Chapter 20 discusses how you can customize QuickBASIC to your
  6617.    personal taste, and Chapter 21 reviews the menu commands for accessing
  6618.    the on-line help system.
  6619.  
  6620.  
  6621.  
  6622.  ────────────────────────────────────────────────────────────────────────────
  6623.  Chapter 10  Getting Around in QuickBASIC
  6624.  
  6625.    This chapter introduces the QuickBASIC programming environment and
  6626.    illustrates many of its features. The chapter includes the basic
  6627.    information you'll need to begin using the QuickBASIC program development
  6628.    environment.
  6629.  
  6630.    This chapter tells you how to do the following:
  6631.  
  6632.    ■ Start QuickBASIC
  6633.  
  6634.    ■ Choose commands from menus
  6635.  
  6636.    ■ Choose items in dialog boxes
  6637.  
  6638.    ■ Scroll listings
  6639.  
  6640.    ■ Select text in a dialog box or window
  6641.  
  6642.    ■ Change window size
  6643.  
  6644.    ■ Use the Immediate window
  6645.  
  6646.    ■ Use the Watch window
  6647.  
  6648.    ■ Use the mouse
  6649.  
  6650.    ■ Use on-line help
  6651.  
  6652.  
  6653.  10.1  Starting QuickBASIC
  6654.  
  6655.    This section discusses starting QuickBASIC with and without special
  6656.    options. It also describes the parts of the QuickBASIC screen. If you have
  6657.    not already done so, read Chapter 1, "Setting Up QuickBASIC," to set up
  6658.    QuickBASIC on your computer.
  6659.  
  6660.  10.1.1  The QB Command
  6661.  
  6662.    To start QuickBASIC, type QB at the DOS prompt.
  6663.  
  6664.    The full syntax for the QB command is the following:
  6665.  
  6666.    QB [[[[/RUN]] [[programname]] [[/B]] [[/G]] [[/H]] [[/NOHI]]
  6667.    [[/C:buffersize]] [[/L[[libraryname]]]] [[MBF]] [[/AH]] [[/CMD string]]]]
  6668.  
  6669.    ──────────────────────────────────────────────────────────────────────────
  6670.    NOTE
  6671.      In this manual, the QB command and its options appear in uppercase
  6672.      letters. However, because DOS is not case sensitive, you may use
  6673.      lowercase letters as well.
  6674.    ──────────────────────────────────────────────────────────────────────────
  6675.  
  6676.    The following list describes QuickBASIC's command options. These options
  6677.    can be typed on the DOS command line following the QB command and have the
  6678.    effects described. Use the options in the order listed.
  6679.  
  6680. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  6681.    Option                   Description
  6682.    ──────────────────────────────────────────────────────────────────────────
  6683.    /RUN programname         Causes QuickBASIC to load and run programname
  6684.                             before displaying it.
  6685.  
  6686.    programname              Names the file to be loaded when QuickBASIC
  6687.                             starts.
  6688.  
  6689.    /B                       Allows the use of a composite (black-and-white)
  6690.                             monitor with a color graphics card. The /B option
  6691.                             displays QuickBASIC in black and white if you
  6692.                             have a color monitor.
  6693.  
  6694.    /G                       Sets QuickBASIC to update a CGA screen as fast as
  6695.                             possible. The option works only with machines
  6696.                             using CGA monitors. If you see "snow" (dots
  6697.                             flickering on the screen) when QuickBASIC updates
  6698.                             your screen, then your hardware cannot fully
  6699.                             support the /G option. If you prefer a "clean"
  6700.                             screen, restart QuickBASIC without the option.
  6701.    Option                   Description
  6702.    ──────────────────────────────────────────────────────────────────────────
  6703.                            screen, restart QuickBASIC without the option.
  6704.  
  6705.    /H                       Displays the highest resolution possible on your
  6706.                             hardware.
  6707.  
  6708.    /NOHI                    Allows the use of a monitor that does not support
  6709.                             high intensity. See Section 10.1.2 for a
  6710.                             description of this option.
  6711.  
  6712.    /C:buffersize            Sets the size of the buffer receiving data. This
  6713.                             option works only with an asynchronous
  6714.                             communications card. The default buffer size is
  6715.                             512 bytes; the maximum size is 32,767 bytes.
  6716.  
  6717.    /L libraryname           Loads the Quick library that is specified by
  6718.                             libraryname. If libraryname is not specified, the
  6719.                             default Quick library, QB.QLB, is loaded.
  6720.  
  6721.    /MBF                     Causes the QuickBASIC conversion functions to
  6722.    Option                   Description
  6723.    ──────────────────────────────────────────────────────────────────────────
  6724.   /MBF                     Causes the QuickBASIC conversion functions to
  6725.                             treat IEEE-format numbers as Microsoft Binary
  6726.                             format numbers.
  6727.  
  6728.    /AH                      Allows dynamic arrays of records, fixed-length
  6729.                             strings, and numeric data to be larger than 64K
  6730.                             each.
  6731.  
  6732.    /CMD string              Passes string to the COMMAND$ function. This
  6733.                             option must be the last option on the line.
  6734.    ──────────────────────────────────────────────────────────────────────────
  6735.  
  6736.  
  6737.    For example, type
  6738.  
  6739.    QB /RUN GRAPHIX /G /AH
  6740.  
  6741.    if you want to run a program named GRAPHIX with the following options:
  6742.  
  6743.    ■ Load and run Graphix before displaying it
  6744.  
  6745.    ■ Quickly update CGA screen
  6746.  
  6747.    ■ Allow dynamic arrays to exceed 64K
  6748.  
  6749.    Generally, however, you start QuickBASIC by typing QB and pressing ENTER.
  6750.  
  6751.  10.1.2  The /NOHI Option
  6752.  
  6753.    If you type QB at the DOS level, QuickBASIC assumes you have a monitor
  6754.    that can display high intensity. However, if you use a monitor that does
  6755.    not support high intensity, you will need to tell QuickBASIC how to
  6756.    display on your system. Use the list below to determine any options you
  6757.    may need.
  6758.  
  6759.    Monitor Display                                         Invocation Command
  6760.    ──────────────────────────────────────────────────────────────────────────
  6761.    16 colors (CGA, EGA or VGA)                             QB
  6762.    4-color monochrome (MDA)                                QB
  6763.    8 colors (CGA, EGA or VGA)                              QB /NOHI
  6764.    4-color black-and-white composite (CGA, EGA or VGA)     QB /B
  6765.    2-color black-and-white composite (CGA, EGA or VGA)     QB /B /NOHI
  6766.    ──────────────────────────────────────────────────────────────────────────
  6767.  
  6768.    Laptop computers frequently use liquid crystal displays (LCDs) that are
  6769.    considered 2-color black-and-white composite displays; they require the QB
  6770.    /B /NOHI command.
  6771.  
  6772.  10.1.3  The QuickBASIC Screen
  6773.  
  6774.    The first time you type QB and press ENTER from DOS, a dialog box offers
  6775.    you the opportunity to review the QuickBASIC Survival Guide. If you press
  6776.    ESC to clear the dialog box, you now see the QuickBASIC screen, shown in
  6777.    Figures 10.1 and 10.2. Figure 10.1 shows the top half of the QuickBASIC
  6778.    invocation screen.
  6779.  
  6780.  
  6781.    ┌────────────────────────────────────┐
  6782.    │                                    │
  6783.    │   Figure 10.1 can be found on      │
  6784.    │   page 153 of the printed manual.  │
  6785.    │                                    │
  6786.    └────────────────────────────────────┘
  6787.  
  6788.    Figure 10.1  Top Half of QuickBASIC Invocation Screen
  6789.  
  6790.    The following list describes the items shown in Figure 10.1.
  6791.  
  6792. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  6793.    Item                     Description
  6794.    ──────────────────────────────────────────────────────────────────────────
  6795.    Menu bar                 Names each menu. When you press the ALT key, the
  6796.                             highlighted letter indicates which key "pulls
  6797.                             down" that menu.
  6798.  
  6799.    View window              Displays your program's text.
  6800.  
  6801.    Cursor                   Shows where the text you type will appear. The
  6802.                             cursor appears in the active window.
  6803.  
  6804.    Mouse cursor             Shows current on-screen position of mouse (use
  6805.                             with mouse only).
  6806.    Item                     Description
  6807.    ──────────────────────────────────────────────────────────────────────────
  6808.                            with mouse only).
  6809.  
  6810.    Title bar                Shows the name of the program or procedure.
  6811.  
  6812.    Maximize box             Expands the active window to fill the screen (use
  6813.                             with mouse only).
  6814.  
  6815.    Scroll arrow             Scrolls the text one character or one line at a
  6816.                             time (use with mouse only).
  6817.  
  6818.    Scroll box               Shows cursor's relative position within the file
  6819.                             or procedure.
  6820.    ──────────────────────────────────────────────────────────────────────────
  6821.  
  6822.  
  6823.    Figure 10.2 shows the bottom half of the QuickBASIC invocation screen.
  6824.  
  6825.  
  6826.    ┌────────────────────────────────────┐
  6827.    │                                    │
  6828.    │   Figure 10.2 can be found on      │
  6829.    │   page 154 of the printed manual.  │
  6830.    │                                    │
  6831.    └────────────────────────────────────┘
  6832.  
  6833.    Figure 10.2  Bottom Half of QuickBASIC Invocation Screen
  6834.  
  6835. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  6836.    Item                     Description
  6837.    ──────────────────────────────────────────────────────────────────────────
  6838.    Immediate window         Executes QuickBASIC statements directly; they
  6839.                             need not be entered as part of a program.
  6840.  
  6841.    CAPS LOCK and NUM LOCK   C appears when the CAPS LOCK key is toggled on. N
  6842.    indicators               appears when the NUM LOCK key is toggled on.
  6843.  
  6844.    Scroll bars              Scrolls text in the currently active window (use
  6845.                             with mouse only).
  6846.  
  6847.    Reference bar            Contains reference information.
  6848.    Item                     Description
  6849.    ──────────────────────────────────────────────────────────────────────────
  6850.   Reference bar            Contains reference information.
  6851.                             The first five items are buttons showing a
  6852.                             frequently used shortcut key and the
  6853.                             corresponding menu or option. Clicking a button
  6854.                             with the mouse gives the same result as pressing
  6855.                             the shortcut key shown in the button. Pressing
  6856.                             ALT displays four different reference items.
  6857.  
  6858.    WordStar-style command   'Q appears when you enter CTRL+Q, a
  6859.    indicator                WordStar-style command. 'K appears here when you
  6860.                             are setting a place marker (see Section 12.4,
  6861.                             "Using Placemarkers in Text"). 'P appears here
  6862.                             when you are entering a literal character (see
  6863.                             Section 12.6, "Entering Special Characters").
  6864.  
  6865.    Line and column counters Give current position of cursor within the text
  6866.                             in the active window.
  6867.    ──────────────────────────────────────────────────────────────────────────
  6868.  
  6869.    Item                     Description
  6870.    ──────────────────────────────────────────────────────────────────────────
  6871. 
  6872.  
  6873.    When you start QuickBASIC without specifying a program name, you can begin
  6874.    to write a program, or you can ask for on-line help. To use the QuickBASIC
  6875.    on-line help, press F1 for a general Help window, or use the Help menu for
  6876.    more detailed information (see Section 10.8, "Using On-Line Help," and
  6877.    Chapter 21, "The Help Menu," for more details).
  6878.  
  6879.    To clear a Help window, press the ESC key. Pressing ESC also clears menus,
  6880.    dialog boxes, and error messages from the QuickBASIC screen.
  6881.  
  6882.  
  6883.  10.2  Opening Menus and Choosing Commands
  6884.  
  6885.    QuickBASIC commands are organized in pull-down menus on the menu bar.
  6886.    Figure 10.3 shows one of these, the File menu.
  6887.  
  6888.  
  6889.    ┌──────┐
  6890.    │ File │
  6891.    ├──────┴──────────┐
  6892.    │ New Program     │
  6893.    │ Open Program... │
  6894.    │ Merge...        │
  6895.    │ Save            │
  6896.    │ Save As...      │
  6897.    │ Save All        │
  6898.    ├─────────────────┤
  6899.    │ Create File...  │
  6900.    │ Load File...    │
  6901.    │ Unload File...  │
  6902.    ├─────────────────┤
  6903.    │ Print...        │
  6904.    │ DOS Shell       │
  6905.    ├─────────────────┤
  6906.    │ Exit            │
  6907.    └─────────────────┘
  6908.  
  6909.    Figure 10.3  The File Menu
  6910.  
  6911.    The QuickBASIC environment is designed for fast, simple operation. You can
  6912.    do most operations in QuickBASIC with either of the following techniques:
  6913.  
  6914.    ■ Open menus and choose commands with the keyboard or a mouse. (See
  6915.      Section 10.7, "Using the Mouse," for a summary of mouse techniques.)
  6916.  
  6917.    ■ Execute a command directly with a "shortcut" key, which is one or two
  6918.      keystrokes that perform the same task as a menu command.
  6919.  
  6920.    Menu commands followed by three dots (...) indicate that more information
  6921.    is required before the command can execute. In these cases, a "dialog
  6922.    box"──a box that asks you for additional information──appears on the
  6923.    screen.
  6924.  
  6925.  10.2.1  Keyboard Technique
  6926.  
  6927.    You can choose any command on a QuickBASIC menu by using the keyboard.
  6928.  
  6929.    To open a menu, follow these steps:
  6930.  
  6931.    1. Press and release the ALT key. (Notice that after you press the ALT
  6932.       key, the first letter of each menu is highlighted.)
  6933.  
  6934.    2. Press the first letter of the menu's name.
  6935.  
  6936.    ──────────────────────────────────────────────────────────────────────────
  6937.    NOTE
  6938.      The ALT key is a "toggle," so if you press it again, the highlight
  6939.      disappears. The "press and release" feature of the ALT key is active
  6940.      only within menus. When using key combinations in other circumstances,
  6941.      you must hold down the first key while pressing the rest of the
  6942.      sequence.
  6943.    ──────────────────────────────────────────────────────────────────────────
  6944.  
  6945.    This "selects" (highlights) the entire menu and displays the menu's
  6946.    commands. A command name contains a highlighted letter whenever it is
  6947.    "active" (available).
  6948.  
  6949.    If no letter in a command is highlighted and it appears dimmed, you cannot
  6950.    choose that command until you take some other action. For example, if you
  6951.    are editing a program but have not selected any text to copy or delete,
  6952.    the commands Cut and Copy can have no effect. You can use Cut and Copy
  6953.    only after you select text. (See Section 12.2 to learn how to select text
  6954.    for copying or deleting.)
  6955.  
  6956.    To move from one menu to another, do either of the following:
  6957.  
  6958.    ■ Close the menu by pressing ESC, then repeat steps 1 and 2 above.
  6959.  
  6960.    ■ Press the LEFT or RIGHT direction keys.
  6961.  
  6962.    To choose a command, do one of the following:
  6963.  
  6964.    ■ Press the key corresponding to the highlighted letter.
  6965.  
  6966.    ■ Use the UP or DOWN direction keys to highlight the command you want to
  6967.      execute, then press ENTER.
  6968.  
  6969.    Some commands take effect immediately and cannot be canceled once chosen.
  6970.    However, commands followed by three dots ( ... ) cause QuickBASIC to
  6971.    display a dialog box so you can supply additional information. To cancel a
  6972.    dialog box, press ESC. See Section 10.3 for a discussion of dialog boxes.
  6973.  
  6974.    See Also
  6975.  
  6976.    Section 10.7, "Using the Mouse"
  6977.  
  6978.  10.2.2  Using Shortcut Keys
  6979.  
  6980.    In QuickBASIC the function keys (F1-F10) serve as shortcut keys for many
  6981.    of the menu functions. Shortcut keys allow you to substitute one or two
  6982.    keystrokes for the process of choosing a command through on-screen menus.
  6983.    Shortcut keys for menu commands are listed on the menu, next to the
  6984.    command. If you are new to programming you may prefer to use only the
  6985.    on-screen menus. When you feel comfortable with QuickBASIC commands, you
  6986.    may want to use the shortcut keys.
  6987.  
  6988.    For example, to run a program, you can choose the Start command from the
  6989.    Run menu, or you can bypass the menu and use the shortcut-key combination
  6990.    SHIFT+F5. Table 10.1 lists and explains all of the QuickBASIC shortcut
  6991.    keys and equivalent menu commands.
  6992.  
  6993.    Table 10.1  QuickBASIC Shortcut Keys
  6994. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  6995.    Programming              Action
  6996.    Shortcut Keys            Menu Command
  6997.    ──────────────────────────────────────────────────────────────────────────
  6998.    SHIFT+F1                 Displays general help information
  6999.                             Help on Help command on Help menu
  7000.  
  7001.    F1                       Displays help information on the keyword or
  7002.                             variable nearest to the left of the cursor
  7003.                             Topic command on Help menu
  7004.  
  7005.    ALT+F1                   Displays up to 20 previous help screens
  7006.                             None
  7007.  
  7008.    F2                       Displays a list of loaded SUB or FUNCTION
  7009.                             procedures, modules, include files, or document
  7010.                             files
  7011.                             SUBs command on View menu
  7012.  
  7013.    SHIFT+F2                 Displays next procedure in active window
  7014.                             Next SUB command on View menu
  7015.  
  7016.    Programming              Action
  7017.    Shortcut Keys            Menu Command
  7018.    ──────────────────────────────────────────────────────────────────────────
  7019. 
  7020.    CTRL+F2                  Displays previous procedure in active window
  7021.                             None
  7022.  
  7023.    F3                       Finds next occurrence of previously specified
  7024.                             text
  7025.                             Repeat Last Find command on Search menu
  7026.  
  7027.    F4                       Toggles display of output screen
  7028.                             Output Screen command on View menu
  7029.  
  7030.    F5                       Continues program execution from current
  7031.                             statement
  7032.                             Continue command on Run menu
  7033.  
  7034.    SHIFT+F5                 Starts program execution from beginning
  7035.                             Start command on Run menu
  7036.  
  7037.    Programming              Action
  7038.    Shortcut Keys            Menu Command
  7039.    ──────────────────────────────────────────────────────────────────────────
  7040. 
  7041.    F6                       Makes next window the active window
  7042.                             None
  7043.  
  7044.    SHIFT+F6                 Makes previous window the active window
  7045.                             None
  7046.  
  7047.    F7                       Executes program to current cursor position
  7048.                             None
  7049.  
  7050.    F8                       Executes next program statement, traces through
  7051.                             procedure
  7052.                             None
  7053.  
  7054.    SHIFT+F8                 Steps back in your program through the last 20
  7055.                             program statements recorded by the History On or
  7056.                             Trace On command
  7057.                             None
  7058.    Programming              Action
  7059.    Shortcut Keys            Menu Command
  7060.    ──────────────────────────────────────────────────────────────────────────
  7061.                            None
  7062.  
  7063.    F9                       Toggles breakpoint
  7064.                             Toggle Breakpoint command on Debug menu
  7065.  
  7066.    SHIFT+F9                 Displays Instant Watch dialog box
  7067.                             Instant Watch command on Debug menu
  7068.  
  7069.    F10                      Executes next program statement, traces around
  7070.                             procedure
  7071.                             None
  7072.  
  7073.    SHIFT+F10                Steps forward in your program through the last 20
  7074.                             program statements recorded by the History On or
  7075.                             Trace On command
  7076.                             None
  7077.  
  7078.    CTRL+F10                 Toggles between multiple windows and full screen
  7079.    Programming              Action
  7080.    Shortcut Keys            Menu Command
  7081.    ──────────────────────────────────────────────────────────────────────────
  7082.   CTRL+F10                 Toggles between multiple windows and full screen
  7083.                             for active window
  7084.                             None
  7085.    ──────────────────────────────────────────────────────────────────────────
  7086.  
  7087.  
  7088.    See Also
  7089.  
  7090.    Section 12.7, "Summary of Editing Commands"
  7091.  
  7092.  
  7093.  10.3  Using Dialog Boxes
  7094.  
  7095.    QuickBASIC displays a dialog box when it needs additional information
  7096.    before it can carry out an action. For example, a dialog box might do the
  7097.    following:
  7098.  
  7099.    ■ Prompt you for the name of a file
  7100.  
  7101.    ■ Display a list of options
  7102.  
  7103.    ■ Ask you to verify or cancel a command
  7104.  
  7105.    ■ Alert you to an error
  7106.  
  7107.    Figures 10.4 and 10.5 illustrate the parts of a dialog box.
  7108.  
  7109.  
  7110.    Path-specification    Text box                     List boxes
  7111.    line                  │                               ││
  7112.    ┌┼────────────────────┼─────── Load File ─────────────┼┼───────────────────
  7113.    ││           ┌────────┼───────────────────────────────┼┼─────────────────┐
  7114.    ││File Name: │*.bas                                   ││                 │
  7115.    ││           └────────────────────────────────────────┼┼─────────────────┘
  7116.    │└C:\QB4.5\DEMO                                       ││
  7117.    │                        Files                        ││   Dirs/Drives
  7118.    │ ┌──────────────────────────────────────────────────┐││ ┌───────────────┐
  7119.    │ │ ATEST.BAS        SORTDEMO.BAS                    │││ │ ..            
  7120.    │ │ BL.BAS           TEST.BAS                       ─┼┘└─┼ SOURCE        ▒
  7121.    │ │ DEMO1.BAS        TORUS.BAS                       │   │ [-A-]         ▒
  7122.    │ │ DEMO2.BAS        VARHELP.BAS                     │   │ [-B-]         ▒
  7123.    │ │ DEMO3.BAS        VARHELP2.BAS                    │   │ [-C-]         ▒
  7124.    │ │ QBFORMAT.BAS                                     │   │               ▒
  7125.    │ │ QCARDS.BAS                                       │   │               ▒
  7126.    │ │ REMLINE.BAS                                      │   │               
  7127.    │ └▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒┘   └───────────────┘
  7128.    │ ┌────────────┬───────────┬────────────┐
  7129.    │ │ Load as:  (∙) Module  ( ) Include  ( ) Document
  7130.    ├─┼────────────────────────────────────────────────────────────────────────
  7131.    │ │         < OK >          < Cancel >          < Help >
  7132.    └─┼───────────┼─────────────────┼───────────────────┼──────────────────────
  7133.      │           └──────────┬──────┴───────────────────┘
  7134.     Option buttons        Command buttons
  7135.  
  7136.    Figure 10.4  Load File Dialog Box
  7137.  
  7138.  
  7139.    Option buttons
  7140.     │
  7141.    ┌┼─────────────────────────────── Display ─────────────────────────────────
  7142.    ││ ┌────────────────────────────── Colors ──────────────────────────────┐
  7143.    ││ │                                           Foreground   Background  │
  7144.    ││ │                                          ┌─────────┐  ┌─────────┐  │
  7145.    ││ │ ┌(∙) 1.  Normal Text                     │ Black     │ Black     │
  7146.    ││ │ │                                        │ White   ▒  │ White   ▒  │
  7147.    │└─┼─┤( ) 2.  Current Statement               │ Gray    ▒  │ Gray    ▒  │
  7148.    │  │ │                                        │ BrWhite ▒  │ BrWhite ▒  │
  7149.    │  │ └( ) 3.  Breakpoint Lines                │         ▒  │         ▒  │
  7150.    │  │                                          │         ▒  │         ▒  │
  7151.    │  │                                          │         ▒  │         ▒  │
  7152.    │  │                                          │           │           │
  7153.    │  │                                          └─────────┘  └─────────┘  │
  7154.    │  │                                                                    │
  7155.    │  └────────────────────────────────────────────────────────────────────┘
  7156.    │
  7157.    │  ┌───────────────────────── Display Options ──────────────────────────┐
  7158.    │  │    [X] Scroll Bars                             Tab Stops: 8        │
  7159.    │  └─────┼──────────────────────────────────────────────────────────────┘
  7160.    ├────────┼─────────────────────────────────────────────────────────────────
  7161.    │        │     < OK >           < Cancel >           < Help >
  7162.    └────────┼─────────────────────────────────────────────────────────────────
  7163.             Check box
  7164.  
  7165.    Figure 10.5  Display Dialog Box
  7166.  
  7167.    To move between different parts of a dialog box, use one of the following
  7168.    methods:
  7169.  
  7170.    ■ Press the TAB key.
  7171.  
  7172.    ■ Hold down the ALT key while pressing the key corresponding to the
  7173.      highlighted letter in the item you want selected. When a dialog box
  7174.      opens, it usually contains any options set previously.
  7175.  
  7176.    The different dialog box components are described in the following list:
  7177.  
  7178. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  7179.    Component                Description
  7180.    ──────────────────────────────────────────────────────────────────────────
  7181.    Path-specification line  Displays the path to the current directory.
  7182.                             Change the path by either typing a new path name
  7183.                             in the text box or by selecting the appropriate
  7184.    Component                Description
  7185.    ──────────────────────────────────────────────────────────────────────────
  7186.                            in the text box or by selecting the appropriate
  7187.                             directory in the Dirs/Drives list box.
  7188.  
  7189.    Text box                 Displays typed text.
  7190.  
  7191.    List box                 Lists a group of similar items, such as files or
  7192.                             procedures available, from which you may choose
  7193.                             one. Use the DIRECTION keys to move within list
  7194.                             boxes.
  7195.  
  7196.    Check box                Toggles an option on or off. Once the cursor is
  7197.                             in the checkbox area, press SPACEBAR, or press
  7198.                             ALT and then the highlighted letter of the item
  7199.                             you want to turn on or off.
  7200.  
  7201.                             When an option is on, an X appears in the check
  7202.                             box; when it is off, the check box is empty.
  7203.  
  7204.    Option button            Selects one of a group of options. Only one of
  7205.    Component                Description
  7206.    ──────────────────────────────────────────────────────────────────────────
  7207.   Option button            Selects one of a group of options. Only one of
  7208.                             the group may be chosen at a time. Use the
  7209.                             DIRECTION keys to move among option buttons.
  7210.  
  7211.    Command button           Executes a command. Once the cursor is in the
  7212.                             command button area, use TAB to alter selections.
  7213.                             Press either SPACEBAR or ENTER to execute
  7214.                             commands.
  7215.    ──────────────────────────────────────────────────────────────────────────
  7216.  
  7217.  
  7218.    Note that within dialog boxes you must keep the ALT key pressed while
  7219.    pressing the high-intensity letter. This procedure is slightly different
  7220.    from the one for choosing menu commands, which does not require you to
  7221.    hold the ALT key down while pressing the highlighted letter.
  7222.  
  7223.  
  7224.  10.4  Using Windows
  7225.  
  7226.  Microsoft QuickBASIC uses windows to contain different types of information.
  7227.  There are four window types──View, Immediate, Help, and Watch. This section
  7228.  introduces QuickBASIC's windows and tells how to do the following:
  7229.  
  7230.    ■ Change the active window
  7231.  
  7232.    ■ Move different parts of programs in and out of an active window
  7233.  
  7234.    ■ Change the size of a window
  7235.  
  7236.    ■ Scroll text in a window
  7237.  
  7238.  10.4.1  Window Types
  7239.  
  7240.    QuickBASIC uses different windows to perform different functions. The
  7241.    following list describes the types of windows in QuickBASIC:
  7242.  
  7243. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  7244.    Window                   Description
  7245.    ──────────────────────────────────────────────────────────────────────────
  7246.    View                     The window that appears at the top of the screen
  7247.    Window                   Description
  7248.    ──────────────────────────────────────────────────────────────────────────
  7249.    View                     The window that appears at the top of the screen
  7250.                             when you start QuickBASIC (see Figure 10.1).
  7251.                             When you load a program, the code that is outside
  7252.                             of any FUNCTION or SUB procedure──known as the
  7253.                             "module-level" code──appears in the View window.
  7254.                             The View menu contains commands that let you
  7255.                             easily move different parts of your program in
  7256.                             and out of View windows. For example, to see a
  7257.                             FUNCTION or SUB procedure in the View window,
  7258.                             choose the SUBs command from the View menu, then
  7259.                             select the procedure from the dialog box.
  7260.  
  7261.    Immediate                The window at the bottom of the screen when you
  7262.                             start QuickBASIC. The Immediate window allows you
  7263.                             to execute BASIC statements immediately. (See
  7264.                             Section 17.3.5 for more information on the
  7265.                             Immediate window.)
  7266.  
  7267.    Help                     The window that contains on-line help. You can
  7268.    Window                   Description
  7269.    ──────────────────────────────────────────────────────────────────────────
  7270.   Help                     The window that contains on-line help. You can
  7271.                             copy examples from Help windows and paste them
  7272.                             into your program.
  7273.  
  7274.    Watch                    The window that opens at the top of the screen
  7275.                             when you choose certain commands from the Debug
  7276.                             menu. It displays the values of variables as your
  7277.                             program runs. (See Section 17.3.4 for more
  7278.                             information on using the Watch window for
  7279.                             debugging.)
  7280.    ──────────────────────────────────────────────────────────────────────────
  7281.  
  7282.  
  7283.  10.4.2  Splitting the View Window (Full Menus Only)
  7284.  
  7285.    You can split the View window into upper and lower windows; this allows
  7286.    you to view or edit two parts of a program simultaneously. Because the
  7287.    View window can be split in two (Full Menus only), you can have a total of
  7288.    five windows open at one time (two View windows, the Immediate window, the
  7289.    Help window, and the Watch window), as shown in Figure10.6.
  7290.  
  7291.  
  7292.    Help window           Watch window                           View windows
  7293.     │                         │                                      ││
  7294.     │ File  Edit  View  Search│ Run  Debug  Calls  Options           ││ Help
  7295.     │DEMO2.BAS NUM:           │                                      ││
  7296.     │DEMO2.BAS TOTAL:                                                ││
  7297.    ┌┼───────────────── HELP: DECLARE Statement QuickSCREEN ──────────┼┼──┤├──
  7298.    │└ QuickSCREEN     Details     Example     Contents     Index
  7299.    │─────────────────────────────────────────────────────────────────┼┼──────
  7300.    │DECLARE - a non-executable statement that declares references to ││
  7301.    │          BASIC procedures and invokes argument type checking    ││
  7302.    │Syntax                                                           ││
  7303.    │  DECLARE {FUNCTION | SUB } name [<[parameterlist]>]             ││
  7304.    ├─────────────────────────────── DEMO2.BAS ───────────────────────┼┼──┤├──
  7305.    │DECLARE SUB Bounce (Hi%, Low%)                                   │└
  7306.    │DECLARE SUB Fall (Hi%, Low%, Del%)                               │
  7307.    │DECLARE SUB Siren (Hi%, Rng%)                                    │
  7308.    │DECLARE SUB Klaxon (Hi%, Low%)                                   │
  7309.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│▒▒▒▒▒▒▒
  7310.    ├────────────────────────────── SORTDEMO.BAS ─────────────────────┼───┤├──
  7311.    │' The program also uses SOUND statements to generate different pitches,
  7312.    │' depending on the location of the bar being printed. Note that the SOUND
  7313.    │' statements delay the speed of each sorting algorithm so you can follow
  7314.    │' the progress of the sort. Therefore, the times shown are for comparison
  7315.    ├─────────────────────────────── Immediate ────────────────────────────────
  7316.    │LOCATE 4,5 : PRINT "TEST"
  7317.    │               │
  7318.     <Shift+F1=Help>│<F6=Window> <F2=Subs> <F5=Run> <F8=Step>         00001:001
  7319.                    │
  7320.           Immediate window
  7321.  
  7322.    Figure 10.6  QuickBASIC Screen with Five Windows Open
  7323.  
  7324.    To split the View window, choose the Split command from the View menu. The
  7325.    screen is now divided into two parts. Repeat the process to restore the
  7326.    original screen.
  7327.  
  7328.    See Also
  7329.  
  7330.    Section 14.3 "Split Command"
  7331.  
  7332.  10.4.3  Changing the Active Window
  7333.  
  7334.    The window that contains the cursor is referred to as the "active" window;
  7335.    it is the place where text entered from the keyboard appears.
  7336.  
  7337.    To make another window active, follow these steps:
  7338.  
  7339.    ■ Press F6 to cycle downward through the windows on the screen.
  7340.  
  7341.    ■ Press SHIFT+F6 to cycle upward.
  7342.  
  7343.  10.4.4  Changing Window Size
  7344.  
  7345.    You can increase or decrease the size of a window one line at a time or
  7346.    expand it to fill the whole screen. To change the size of a window, first
  7347.    make it the active window. Then use the following key combinations (hold
  7348.    down the first key while pressing the second) to increase or decrease the
  7349.    window's size. (Use the PLUS and MINUS keys on the keypad.)
  7350.  
  7351.    Key Combination          Result
  7352.    ──────────────────────────────────────────────────────────────────────────
  7353.    ALT+PLUS (+)             Expands the active window one line.
  7354.  
  7355.    ALT+MINUS (-)            Shrinks the active window one line.
  7356.  
  7357.    CTRL+F10                 Expands the active window to fill the screen, or,
  7358.                             if it already occupies the whole screen, returns
  7359.                             the active window to its former size.
  7360.                             If the View window is split in two when you press
  7361.                             CTRL+F10, pressing CTRL+F10 again restores both
  7362.                             windows to the screen.
  7363.    ──────────────────────────────────────────────────────────────────────────
  7364.  
  7365.  10.4.5  Scrolling in the Active Window
  7366.  
  7367.    To look at the parts of a file that do not fit within the boundaries of a
  7368.    View window, you can move the text ("scroll") up, down, right, or left.
  7369.  
  7370.    Once you reach a window's edge, press the appropriate DIRECTION key to
  7371.    begin scrolling. For example, to scroll right one character at a time, go
  7372.    to the rightmost character on the screen and press the RIGHT key.
  7373.  
  7374.    Refer to Table 10.2 for information on scrolling more than one character
  7375.    at a time. The rightmost column in this table shows keystrokes that you
  7376.    may find more convenient if you prefer WordStar-style commands.
  7377.  
  7378.    Table 10.2  Scrolling
  7379.                                                            WordStar-Style
  7380.    Scrolling Action                     Keystrokes         Equivalents
  7381.    ──────────────────────────────────────────────────────────────────────────
  7382.    Beginning of line                    HOME               CTRL+Q+S
  7383.    End of line                          END                CTRL+Q+D
  7384.    Page up                              PGUP               CTRL+R
  7385.    Page down                            PGDN               CTRL+C
  7386.    Left one window                      CTRL+PGUP          ---
  7387.    Right one window                     CTRL+PGDN          ---
  7388.    Beginning of file                    CTRL+HOME          CTRL+Q+R
  7389.    End of file                          CTRL+END           CTRL+Q+C
  7390.    ──────────────────────────────────────────────────────────────────────────
  7391.  
  7392.    You can also set place markers anywhere in your program and jump between
  7393.    them while editing. See Chapter 12, "Using the Editor," for more
  7394.    information.
  7395.  
  7396.  
  7397.  10.5  Using the Immediate Window
  7398.  
  7399.    The Immediate window, the bottom window on the initial QuickBASIC screen,
  7400.    allows direct execution of QuickBASIC statements. Use it to refine short
  7401.    pieces of program code and see the effect immediately. When you are
  7402.    satisfied with the results, you can copy the code into your program.
  7403.  
  7404.    Figure 10.7 shows code being tested in the Immediate window.
  7405.  
  7406.  
  7407.       File  Edit  View  Search  Run  Debug  Calls  Options              Help
  7408.      DEMO2.BAS NUM:
  7409.      DEMO2.BAS TOTAL:
  7410.    ┌─────────────────────────────── DEMO2.BAS ───────────────────────────┤├──
  7411.    │DECLARE SUB Bounce (Hi%, Low%)
  7412.    │DECLARE SUB Fall (Hi%, Low%, Del%)
  7413.    │DECLARE SUB Siren (Hi%, Rng%)
  7414.    │DECLARE SUB Klaxon (Hi%, Low%)
  7415.    │DEFINT A-Z
  7416.    │' QB2 Version of Sound Effects Demo Program
  7417.    │'   (works under most other BASIC compilers)
  7418.    │
  7419.    │' Sound effects menu
  7420.    │WHILE Q$ <> "Q"
  7421.    │    CLS
  7422.    ├─────────────────────────────── Immediate ────────────────────────────────
  7423.    │LOCATE 4,5 : PRINT "TEST"
  7424.    ││
  7425.    ││
  7426.     │<Shift+F1=Help> <F6=Window> <Enter=Execute Line>                00001:026
  7427.     │
  7428.    Code being tested
  7429.  
  7430.    Figure 10.7  Immediate Window
  7431.  
  7432.    You can enter up to ten separate lines in the Immediate window, then move
  7433.    among them with the DIRECTION keys. Each line is limited to 256
  7434.    characters. Multiple statements are permitted on one line, but each
  7435.    complete statement must be separated from the next by a colon (:). When
  7436.    you place the cursor on a line and press ENTER, only the statements on
  7437.    that line execute.
  7438.  
  7439.    As you write your program, you can make the Immediate window active, type
  7440.    and edit statements as you would in the Edit window, then execute them
  7441.    immediately. By testing your ideas before incorporating them into a larger
  7442.    program, you verify that they function properly.
  7443.  
  7444.    The Immediate window is similar to "direct mode" in BASICA, and has the
  7445.    following characteristics:
  7446.  
  7447.    ■ Any statement or group of statements on a line will be executed when you
  7448.      place the cursor anywhere on the line and press ENTER.
  7449.  
  7450.    ■ As many as ten lines can be entered in the Immediate window; you can
  7451.      execute the lines in any order.
  7452.  
  7453.      After you have entered ten lines, each new line scrolls the text in the
  7454.      Immediate window up one line.
  7455.  
  7456.    ■ A line can have a maximum of 256 characters. Statements can be grouped
  7457.      on a line, but must be separated by colons (:).
  7458.  
  7459.    ■ Each line is executed independently of all other lines in the window.
  7460.      However, changes in one line can affect other lines. For example, the
  7461.      following lines contain two assignments to the integer variable x%, so
  7462.      the value printed by the second line corresponds to whichever assignment
  7463.      line was most recently executed:
  7464.  
  7465.      x% = 5
  7466.      print x%
  7467.      x% = 9
  7468.  
  7469.    ■ The Immediate window is expanded when you repeatedly press ALT+PLUS
  7470.      while it is the active window. Pressing CTRL+F10 while the Immediate
  7471.      window is active expands it to the full screen, but no matter how many
  7472.      lines appear, only the first ten are available for use. Press CTRL+F10
  7473.      again to return the window to its previous size.
  7474.  
  7475.    ■ Code written in the Immediate window is not saved to disk by the Save
  7476.      command. Use the Cut or Copy commands from the Edit menu to move the
  7477.      contents of the Immediate window into a View window if you want to save
  7478.      them with the rest of the file.
  7479.  
  7480.    See Also
  7481.  
  7482.    Section 17.2, "Preventing Bugs with QuickBASIC"; Section 17.3.5,
  7483.    "Immediate Window"
  7484.  
  7485.  10.5.1  Statements Not Allowed
  7486.  
  7487.    Most QuickBASIC statements and functions are allowed in the Immediate
  7488.    window. However, an error message will appear if you use the following
  7489.    QuickBASIC keywords in the Immediate window:
  7490.  
  7491.  
  7492.    ──────────────────────────────────────────────────────────────────────────
  7493.    COMMON                   ELSEIF                  OPTION
  7494.  
  7495.    CONST                    END DEF                 REDIM
  7496.  
  7497.    DATA                     END FUNCTION            SHARED
  7498.  
  7499.    DECLARE                  END IF                  $STATIC
  7500.  
  7501.    DEF FN                   END SUB                 STATIC
  7502.  
  7503.    DEFtype                  END TYPE                SUB
  7504.  
  7505.    DIM                      FUNCTION                TYPE
  7506.  
  7507.    DYNAMIC                  $INCLUDE                $DYNAMIC
  7508.  
  7509.    ──────────────────────────────────────────────────────────────────────────
  7510.  
  7511.    ──────────────────────────────────────────────────────────────────────────
  7512.    NOTE
  7513.      Although the END IF statement is not allowed in the Immediate window,
  7514.      you can still use the single-line form of IF...THEN...ELSE there.
  7515.    ──────────────────────────────────────────────────────────────────────────
  7516.  
  7517.  10.5.2  Doing Calculations
  7518.  
  7519.    Use the Immediate window to calculate complicated expressions, then
  7520.    display results with the PRINT statement. Use any of BASIC's intrinsic
  7521.    functions (such as SIN or EXP) in these calculations. Similarly, you can
  7522.    use the Immediate window to print the value returned by FRE(-1). This
  7523.    tells you the amount of memory available after both QuickBASIC and your
  7524.    program are loaded.
  7525.  
  7526.  10.5.3  Testing Screen Output
  7527.  
  7528.    As a program grows in length and complexity, it is useful to test your
  7529.    code before incorporating it into your program. Typing code in the
  7530.    Immediate window and testing it there first avoids having to run a program
  7531.    from the beginning each time you want to modify a small part of code.
  7532.  
  7533.    Examples
  7534.  
  7535.    You can use the following lines in the Immediate window to test the
  7536.    position at which output will be written to the screen:
  7537.  
  7538.    row% = 1 : col% = 4*row% : LOCATE row%,col% : PRINT "."
  7539.  
  7540.    By changing the value of the variable row%, then pressing ENTER, you can
  7541.    position the period in the PRINT statement in different places on the
  7542.    screen.
  7543.  
  7544.    Sometimes a program can leave the output screen in an undesirable mode
  7545.    when it finishes running (for example, a graphics program may end without
  7546.    resetting the screen to 80-column text mode). If this happens, use the
  7547.    Immediate window to put the screen in the output mode you want. For
  7548.    example, the following lines restore the output screen to 80-column text
  7549.    mode and close any text viewport (a restricted horizontal slice of the
  7550.    screen) set in the program:
  7551.  
  7552.    screen 0
  7553.    width 80
  7554.    view print
  7555.  
  7556.  10.5.4  Invoking Procedures
  7557.  
  7558.    You can isolate the effects of any individual SUB or FUNCTION procedure by
  7559.    calling it from the Immediate window. Use the Immediate window to execute
  7560.    only those statements between the SUB and END SUB or FUNCTION and END
  7561.    FUNCTION statements. For example, entering the following line in the
  7562.    Immediate window executes all statements in the procedure SubProgram1,
  7563.    including any calls it makes to other procedures:
  7564.  
  7565.    call SubProgram1
  7566.  
  7567.  10.5.5  Changing the Values of Variables
  7568.  
  7569.    Use the Immediate window to assign a new value to a variable in a running
  7570.    program. Stop the program, assign the variable a new value in the
  7571.    Immediate window, and continue execution. The value you assign in the
  7572.    Immediate window becomes the variable's value when the program continues
  7573.    running.
  7574.  
  7575.    Example
  7576.  
  7577.    The following steps show how you can use the Immediate window to change a
  7578.    variables in a running program:
  7579.  
  7580.    1. Type this program in the View window:
  7581.  
  7582.       FOR i% = 0 TO 10000
  7583.          LOCATE 10, 20 : PRINT i%
  7584.          LOCATE 10, 27 : PRINT "  and still counting"
  7585.       NEXT i%
  7586.  
  7587.    2. Use the Start command on the Run menu to start the program, then use
  7588.       CTRL+BREAK to interrupt it.
  7589.  
  7590.    3. Type
  7591.  
  7592.       i% = 9900
  7593.  
  7594.       in the Immediate window and press ENTER.
  7595.  
  7596.    4. Press F5 to continue the program.
  7597.  
  7598.       The loop now executes from 9900 to 10,000.
  7599.  
  7600.    The Immediate window can access variable values only after those variables
  7601.    have been assigned values; this occurs after statements containing the
  7602.    variables have been executed in the View window. For example, suppose the
  7603.    statement you just executed in the View window gave a variable called x% a
  7604.    value of 3. You then enter PRINT x% in the Immediate window. The number 3
  7605.    will be printed to the screen when you press ENTER.
  7606.  
  7607.    Similarly, if the next statement to be executed in the View window is a
  7608.    module-level statement, you cannot access the variables of a SUB or
  7609.    FUNCTION from the Immediate window.
  7610.  
  7611.  10.5.6  Simulating Run-Time Errors
  7612.  
  7613.    Run-time errors are those that occur while a program is running. Each
  7614.    run-time error is associated with a numeric code. If your program uses
  7615.    error handling (ON ERROR statements), QuickBASIC returns this numeric code
  7616.    to your program.
  7617.  
  7618.    One way to find out which error message is associated with a given code is
  7619.    to refer to Appendix I, "Error Messages," in Programming in BASIC. Another
  7620.    way is to simulate the error itself. You can simulate an error by moving
  7621.    to the Immediate window and entering the given number as an argument to
  7622.    the ERROR statement. QuickBASIC then displays the dialog box for that
  7623.    error, as if the error had actually occurred in a running program. Figure
  7624.    10.8 shows an error-message dialog box on the QuickBASIC screen.
  7625.  
  7626.  
  7627.                           Error-message dialog box
  7628.                                │
  7629.       File  Edit  View  Search │Run  Debug  Calls  Options              Help
  7630.    ┌───────────────────────────┼─── DEMO1.BAS ───────────────────────────┤├──
  7631.    │5 DEFINT A-Z               │
  7632.    │10 ' BASICA/GWBASIC Version│of Sound Effects Demo Program
  7633.    │15 '                       │
  7634.    │20 ' Sound effect menu     │
  7635.    │25 Q = Z                   │
  7636.    │30 WHILE Q >= 1            │
  7637.    │35     CLS                 │
  7638.    │40     PRINT "Sound effect┌┼──────────────────────┐
  7639.    │45     COLOR 15, 0: PRINT ││                      │  "ouncing"
  7640.    │50     COLOR 15, 0: PRINT │  File already exists  │  "alling"
  7641.    │55     COLOR 15, 0: PRINT │                       │  "laxon"
  7642.    │60     COLOR 15, 0: PRINT ├───────────────────────┤  "iren"
  7643.    │65     COLOR 15, 0: PRINT │   < OK >   < Help >   │  "uit"
  7644.    │70     PRINT : PRINT "Sele└───────────────────────┘
  7645.    │75     Q$ = INPUT$(1): Q = I                         Get valid key
  7646.    │80     IF Q = 0 GOTO 75
  7647.    │85     CLS     ' Take action based on key
  7648.    ├─────────────────────────────── Immediate ────────────────────────────────
  7649.    │error 58
  7650.    ││
  7651.    ││
  7652.     │<Shift+F1=Help> <F6=Window> <Enter=Execute Line>             C  00001:001
  7653.     │
  7654.    Error code entered in Immediate window
  7655.  
  7656.    Figure 10.8  Simulated Run-Time Error
  7657.  
  7658.  
  7659.  10.6  Using the Watch Window
  7660.  
  7661.    The Watch window is one of QuickBASIC's advanced debugging features. It
  7662.    displays variables tracked for debugging purposes. The Watch window opens
  7663.    at the top of the screen when you set a watchpoint or add a watch
  7664.    expression. (See Section 17.3.2, "Breakpoints and Watchpoints," and
  7665.    Section 17.3.3, "Watch Expressions.")
  7666.  
  7667.    Figure 10.9 shows the QuickBASIC screen with entries in the Watch window.
  7668.  
  7669.  
  7670.    Location where
  7671.    you added
  7672.    the variable  ┌───Variables (or expressions)       Values (or conditions
  7673.     │            │                                         │
  7674.     │ File  Edit │View  Search  Run  Debug  Calls  Options │            Help
  7675.     │TEST.BAS I:─┤1────────────────────────────────────────┤
  7676.     └TEST.BAS J:─┘12───────────────────────────────────────┘
  7677.    ┌──────────────────────────────── TEST.BAS ───────────────────────────┤├──
  7678.    │FOR I = 1 TO 900
  7679.    │   FOR J = 1 TO 600
  7680.    │      PRINT I
  7681.    │      PRINT J
  7682.    │   NEXT J
  7683.    │NEXT I
  7684.    │END
  7685.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  7686.    ├─────────────────────────────── DEMO1.BAS ───────────────────────────┤├──
  7687.    │5 DEFINT A-Z
  7688.    │10 ' BASICA/GWBASIC Version of Sound Effects Demo Program
  7689.    │15 '
  7690.    │20 ' Sound effect menu
  7691.    │25 Q = Z
  7692.    │30 WHILE Q >= 1
  7693.    │35     CLS
  7694.    │40     PRINT "Sound effects": PRINT
  7695.    ├─────────────────────────────── Immediate ────────────────────────────────
  7696.    │LOCATE 4,5 : PRINT "TEST"
  7697.    │
  7698.     <Shift+F1=Help> <F5=Continue> <F9=Toggle Bkpt> <F8=Step>      C  00004:007
  7699.  
  7700.    Figure 10.9  Watch Window
  7701.  
  7702.    The Watch window opens whenever you choose the Add Watch or Watchpoint
  7703.    command, or when you choose Add from the Instant Watch dialog box. Add
  7704.    Watch, Watchpoint, and Instant Watch are all on the Debug menu. Each Watch
  7705.    window entry contains the following information:
  7706.  
  7707.    ■ Location where you added the variable.
  7708.  
  7709.      This part of the entry names the module or procedure from which you
  7710.      added an expression to the Watch window.
  7711.  
  7712.    ■ Variable or expression.
  7713.  
  7714.      The variable or expression you want to track.
  7715.  
  7716.    ■ Value or condition.
  7717.  
  7718.      In Figure 10.9, the variables I and J have values 1 and 12,
  7719.      respectively. Since the program is currently executing in TEST.BAS and
  7720.      both I and J were added to the Watch window when TEST.BAS was in the
  7721.      View window (indicated by the TEST.BAS entry in front of both I and J),
  7722.      both of their values appear. If they had been added from a different
  7723.      location such as a procedure, then the procedure name would appear in
  7724.      the Watch window and Not watchable would appear in the value location
  7725.      while the program executed in TEST.BAS.
  7726.  
  7727.    See Also
  7728.  
  7729.    Section 17.3.4, "Watch Window"; Chapter 18, "The Debug Menu"
  7730.  
  7731.  
  7732.  10.7  Using the Mouse
  7733.  
  7734.    You can use QuickBASIC with a mouse. Terms associated with the mouse and
  7735.    used in this manual include the following:
  7736.  
  7737.    Mouse Term               Description
  7738.    ──────────────────────────────────────────────────────────────────────────
  7739.    Mouse cursor             Block cursor that moves on the screen as you move
  7740.                             the mouse.
  7741.  
  7742.    Click                    Placing the mouse cursor on an item, and pressing
  7743.                             and releasing the left mouse button.
  7744.  
  7745.    Double click             Placing the cursor on an item and pressing the
  7746.                             left mouse button twice in a row.
  7747.  
  7748.    Drag                     Placing the mouse cursor at the beginning of what
  7749.                             you wish to select. Press the left mouse button
  7750.                             and hold it down. Move the pointer to the end of
  7751.                             your desired selection and release the button.
  7752.                             Use this technique to highlight words, manipulate
  7753.                             window sizes, and use scroll bars.
  7754.    ──────────────────────────────────────────────────────────────────────────
  7755.  
  7756.    To choose commands with the mouse follow these steps:
  7757.  
  7758.    1. Point to the menu name and click the left mouse button.
  7759.  
  7760.    2. Point to the command you want to select and click the left mouse
  7761.       button.
  7762.  
  7763.    ──────────────────────────────────────────────────────────────────────────
  7764.    NOTE
  7765.      Use only the left mouse button to choose QuickBASIC menus or commands.
  7766.      Clicking the right mouse button is the same as pressing F1 (accessing
  7767.      on-line help). For information on how to set the right mouse button to
  7768.      execute your program to the line containing the mouse cursor, see
  7769.      Section 20.3, "Right Mouse Command."
  7770.    ──────────────────────────────────────────────────────────────────────────
  7771.  
  7772.    Table 10.3 explains mouse techniques for accomplishing other tasks.
  7773.  
  7774.    Table 10.3  Mouse Commands
  7775. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  7776.    Task                     Mouse Technique
  7777.    ──────────────────────────────────────────────────────────────────────────
  7778.    Close a menu             Move the mouse cursor off the menu and click the
  7779.                             left button.
  7780.  
  7781.    Make a window active     Click anywhere in the window.
  7782.  
  7783.    Expand or shrink a View  Move the mouse cursor to the title bar and drag
  7784.    or Immediate window      the title bar up or down.
  7785.  
  7786.    Expand the active window Click the maximize box, at the right of the title
  7787.    to occupy the full       bar, or double click the mouse anywhere on the
  7788.    screen                   title bar.
  7789.  
  7790.    Scroll text              Place the cursor on the scroll box and drag it to
  7791.                             a position on the bar that corresponds to the
  7792.                             general location in the file you want.
  7793.    Task                     Mouse Technique
  7794.    ──────────────────────────────────────────────────────────────────────────
  7795.                            general location in the file you want.
  7796.  
  7797.                             To scroll one page at a time, place the mouse
  7798.                             cursor in the scroll bar between the scroll box
  7799.                             and the top or bottom of the scroll bar and click
  7800.                             the left button.
  7801.  
  7802.                             To scroll one line or one character at a time,
  7803.                             click the scroll arrows at either end of the
  7804.                             scroll bars.
  7805.  
  7806.    Select programs and      Double click the file name, click the file name
  7807.    files                    and OK in a list box (use this technique with the
  7808.                             Open Program, Merge, and Load File commands), or
  7809.                             single click to highlight the file name and press
  7810.                             ENTER.
  7811.  
  7812.    Change directories       Double click a directory name to view its
  7813.                             contents. (In most dialog boxes, directories and
  7814.    Task                     Mouse Technique
  7815.    ──────────────────────────────────────────────────────────────────────────
  7816.                            contents. (In most dialog boxes, directories and
  7817.                             drives appear in a separate list to the right of
  7818.                             the file list.) If the current directory is a
  7819.                             subdirectory, two periods (. .) appear in the
  7820.                             list. Double click the two periods to move up one
  7821.                             directory level.
  7822.  
  7823.    Display Instant Watch    Press and hold the SHIFT key while clicking the
  7824.    dialog box               right mouse button.
  7825.    ──────────────────────────────────────────────────────────────────────────
  7826.  
  7827.  
  7828.    ──────────────────────────────────────────────────────────────────────────
  7829.    NOTE
  7830.      To open a program with the mouse, double click the file name in the list
  7831.      box. Clicking an item with a mouse selects that item. Double clicking an
  7832.      item in a list box selects the item, confirms all previous choices, and
  7833.      closes the dialog box.
  7834.    ──────────────────────────────────────────────────────────────────────────
  7835.  
  7836.  
  7837.  10.8  Using On-Line Help
  7838.  
  7839.    QuickBASIC has an extensive on-line help system. Through on-line help, you
  7840.    can get information on virtually any QuickBASIC topic, menu, command, or
  7841.    keyword.
  7842.  
  7843.    See Also
  7844.  
  7845.    Chapter 21, "The Help Menu"
  7846.  
  7847.  10.8.1  Help Features
  7848.  
  7849.    QuickBASIC's on-line help consists of two parts: environment help (for
  7850.    error messages, menus, and commands) and the Microsoft QB Advisor (for
  7851.    language-oriented topics). Press ESC to clear either type of on-line help
  7852.    from your screen.
  7853.  
  7854.    Environment help appears in dialog boxes; the QB Advisor appears in the
  7855.    Help window at the top fo the screen. The following special features are
  7856.    available within the QB Advisor:
  7857.  
  7858.    ■ Hyperlinks connect related topics; they give you immediate access to all
  7859.      related information on a particular topic (see Section 10.8.2).
  7860.  
  7861.    ■ Examples can be copied or pasted directly into your program. You may
  7862.      resize the Help window, use commands such as PGUP and the DIRECTION
  7863.      keys, and scroll. You can even use Find from the Search menu to locate
  7864.      specific information within a particular help screen.
  7865.  
  7866.    ■ Placemarkers can be used. If you use a particular screen frequently, set
  7867.      a placemarker there as you would in program text. Later, you can quickly
  7868.      return to the same screen. (See Section 12.4, "Using Placemarkers in
  7869.      Text.")
  7870.  
  7871.    ■ QuickBASIC remembers up to the last 20 hyperlinks you accessed. Rather
  7872.      than repeatedly search through on-line help, you can press ALT+F1 to
  7873.      trace back through as many as 20 help screens.
  7874.  
  7875.    You can access on-line help in four ways:
  7876.  
  7877.    1. Move the cursor to the word in your program you want help on, and press
  7878.       F1.
  7879.  
  7880.    2. Select the Help button or press F1 when a help dialog box is displayed.
  7881.  
  7882.    3. Use hyperlinks from within Help windows to call up more information on
  7883.       related topics (see Section 10.8.2).
  7884.  
  7885.    4. Select a command from the Help menu.
  7886.  
  7887.  10.8.2  Hyperlinks
  7888.  
  7889.    The QB Advisor provides interconnections called "hyperlinks" between
  7890.    related subjects. With a few keystrokes, you can access all of the
  7891.    information and related material on a particular topic.
  7892.  
  7893.    Hyperlinks appear at the top and bottom of the Help window between
  7894.    highlighted (on monochrome monitors) or green (on most color monitors)
  7895.    triangles. Any BASIC keyword also forms a hyperlink to that keyword's
  7896.    on-line help.
  7897.  
  7898.    To use a hyperlink, make the Help window active (press SHIFT+F6), and
  7899.    press the TAB key to move the cursor to the hyperlink you want to
  7900.    activate. Alternatively, you can enter the first letter of a hyperlink's
  7901.    name and the cursor will jump to that hyperlink. Press F1 to call up the
  7902.    screen associated with that hyperlink.
  7903.  
  7904.    ──────────────────────────────────────────────────────────────────────────
  7905.    NOTE
  7906.      Mouse users can place the mouse cursor on a hyperlink and click the
  7907.      right button, provided the right button function is set to invoke
  7908.      context-sensitive help (the default setting).
  7909.    ──────────────────────────────────────────────────────────────────────────
  7910.  
  7911.    Figure 10.10 shows examples of hyperlinks in the PRINT Help screen. The
  7912.    Remarks and Example hyperlinks provide additional remarks and examples.
  7913.  
  7914.  
  7915.    Inactive hyperlink
  7916.    (screen currently     Hyperlinks to additional       Hyperlinks to
  7917.    displayed)         ┌─ help on PRINT                  general help topics
  7918.     │                 │                                     ┌────┴────┐
  7919.     │ File  Edit  View│ Search  Run  Debug  Options         │         │ Help
  7920.    ┌┼─────────────────┼── HELP: PRINT Statement QuickSCREEN ├─────────┼──┤├──
  7921.    │└ QuickSCREEN   │ Details     Example     Contents     Index
  7922.    │───────────────── └────┴──────────────┘ ─────────────────────────────────
  7923.    │PRINT - a device I/O statement that outputs data on the screen
  7924.    │
  7925.    │Syntax
  7926.    │  PRINT [expressionlist][{,|;}]
  7927.    │
  7928.    │  ■ If expressionlist is omitted, a blank line is printed.
  7929.    │  ■ If expressionlist is included, the values of the expressions are
  7930.    │    printed on the screen.
  7931.    │  ■ The expressions in the list may be numeric or string expressions.
  7932.    │    (String literals must be enclosed in quotation marks.)
  7933.    │
  7934.    │Other Uses of the PRINT Keyword
  7935.    │ ┌PRINT USING - to output formatted text to the screen
  7936.    │ │PRINT # - to output data to a sequential file
  7937.    ││▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  7938.      │
  7939.    Hyperlinks to related statements
  7940.  
  7941.    Figure 10.10  Help on the PRINT Statement
  7942.  
  7943.  10.8.3  Moving in Help Windows
  7944.  
  7945.    You can use the keyboard to move in Help windows. For example, you can use
  7946.    the DIRECTION keys. You can also use the key sequences described in Table
  7947.    10.4.
  7948.  
  7949.    Table 10.4  Help Keys
  7950. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  7951.    Key Sequence             Description
  7952.    ──────────────────────────────────────────────────────────────────────────
  7953.    SHIFT+F1                 Displays Help on Help
  7954.  
  7955.    ESC                      Clears help from the screen
  7956.  
  7957.    TAB                      Moves to next hyperlink
  7958.  
  7959.    SHIFT+TAB                Moves to previous hyperlink
  7960.  
  7961.    Key Sequence             Description
  7962.    ──────────────────────────────────────────────────────────────────────────
  7963. 
  7964.    character                Moves to next hyperlink starting with the letter
  7965.                             character
  7966.  
  7967.    SHIFT+character          Moves to previous hyperlink starting with the
  7968.                             letter character
  7969.  
  7970.    PGUP                     Displays previous screen (if one exists) of
  7971.                             current topic
  7972.  
  7973.    PGDN                     Displays next screen (if one exists) of current
  7974.                             topic
  7975.  
  7976.    CTRL+F1                  Displays help for the topic stored just after the
  7977.                             current help topic
  7978.  
  7979.    SHIFT+CTRL+F1            Displays help for the topic stored just before
  7980.                             the current help topic
  7981.    ──────────────────────────────────────────────────────────────────────────
  7982.    Key Sequence             Description
  7983.    ──────────────────────────────────────────────────────────────────────────
  7984.   ──────────────────────────────────────────────────────────────────────────
  7985.  
  7986.  
  7987.  10.8.4  Help Files
  7988.  
  7989.    When you choose any help command, QuickBASIC searches for the appropriate
  7990.    help file. QuickBASIC searches the current working directory, then the
  7991.    directory specified by the Set Paths command (Options menu), and finally
  7992.    any removable disks present in your system. If QuickBASIC cannot find an
  7993.    appropriate file, it displays the dialog box shown in Figure 10.11. Copy
  7994.    the missing file into the appropriate directory.
  7995.  
  7996.  
  7997.    ┌───────────────────────────────────────────────────────┐
  7998.    │                                                       │
  7999.    │           File QB45QCK.HLP not found.                 │
  8000.    │ Put the floppy disk with this file into the drive and │
  8001.    │ Retry, or change your Help path in Options+Set Paths. │
  8002.    │                                                       │
  8003.    ├───────────────────────────────────────────────────────┤
  8004.    │              < Retry >    < Cancel >                  │
  8005.    └───────────────────────────────────────────────────────┘
  8006.  
  8007.    Figure 10.11  Dialog Box for Missing Help File
  8008.  
  8009.    If you cannot invoke any form of on-line help, you may be missing all of
  8010.    the help files; in this case, you need to check the contents of your
  8011.    QuickBASIC directory or rerun the setup procedure. Or you may have
  8012.    inadequate memory to display on-line help. This situation can occur if you
  8013.    try to run QuickBASIC concurrently with other memory-resident files. In
  8014.    this case, remove one or more memory-resident files and start QuickBASIC
  8015.    again. You may also have inadequate memory if your machine doesn't meet
  8016.    the minimum system requirements (see the introduction to this manual).
  8017.  
  8018.  10.8.5  Hard-Disk System
  8019.  
  8020.    If you use a hard disk, you installed all of the help files in a single
  8021.    directory during your setup (see Chapter 1, "Setting Up Microsoft
  8022.    QuickBASIC," for more information). The Set Paths command on the Options
  8023.    menu specifies the directory path to the help files.
  8024.  
  8025.    When you invoke language-oriented help, you will automatically receive the
  8026.    QB Advisor.
  8027.  
  8028.  10.8.6  Removable-Disk System
  8029.  
  8030.    Microsoft QuickBASIC provides some language help on the same disk that
  8031.    contains QuickBASIC. This file contains statement descriptions and syntax,
  8032.    but not the detailed examples available in the QB Advisor.
  8033.  
  8034.    To use the QB Advisor on a dual removable-disk system, press either the
  8035.    Remarks or Example hyperlinks at the top of the screen. A dialog box asks
  8036.    you to insert the Microsoft QB Advisor disk.
  8037.  
  8038.    Once you insert the Microsoft QB Advisor disk, you can access more
  8039.    detailed help on QuickBASIC's keywords. You may leave the Microsoft QB
  8040.    Advisor disk in the drive until QuickBASIC prompts you for another disk.
  8041.  
  8042.  
  8043.  
  8044.  ────────────────────────────────────────────────────────────────────────────
  8045.  Chapter 11  The File Menu
  8046.  
  8047.    The File menu lets you work with files in QuickBASIC. From the File menu
  8048.    you can create new files, load existing files, modify files, or remove
  8049.    files. You also use the File menu to print files and exit from QuickBASIC.
  8050.  
  8051.    The File menu has the following commands:
  8052.  
  8053.    ■ New Program. Clears any previously loaded program and lets you begin a
  8054.      new program.
  8055.  
  8056.    ■ Open Program. Opens a program; lists system files and directories.
  8057.  
  8058.    ■ Merge. Merges the contents of two files (Full Menus only).
  8059.  
  8060.    ■ Save. Writes the contents of the file in the active View window to a
  8061.      disk file (Full Menus only).
  8062.  
  8063.    ■ Save As. Saves the current file with the name you specify.
  8064.  
  8065.    ■ Save All. Saves all currently loaded files (Full Menus only).
  8066.  
  8067.    ■ Create File. Begins either a new program module, an include file, or a
  8068.      document file as part of the current program (Full Menus only).
  8069.  
  8070.    ■ Load File. Loads an existing file──either a program module, an include
  8071.      file or a document file──into memory (Full Menus only).
  8072.  
  8073.    ■ Unload File. Removes an entire file from memory (Full Menus only).
  8074.  
  8075.    ■ Print. Lets you print all or part of your program.
  8076.  
  8077.    ■ DOS Shell. Returns temporarily to the DOS command level (Full Menus
  8078.      only).
  8079.  
  8080.    ■ Exit. Removes program from memory and returns to the DOS prompt.
  8081.  
  8082.  
  8083.  11.1  New Program Command
  8084.  
  8085.    The New Program command from the File menu clears all previously loaded
  8086.    files so you can begin typing a completely new program. If a loaded
  8087.    program contains unsaved text, QuickBASIC asks if you want to save it
  8088.    before clearing it from memory.
  8089.  
  8090.    A program contains one or more BASIC statements that QuickBASIC will
  8091.    translate into instructions for your computer. BASIC programs can be
  8092.    contained in a single file. However, QuickBASIC also allows you to build
  8093.    programs containing multiple self-contained parts ("modules"). Each module
  8094.    usually contains procedures that are used to perform specific tasks. One
  8095.    such module may be called into several programs. The New Program command
  8096.    creates the main module of a multiple-module program. In a single-module
  8097.    program, the main module is the only module.
  8098.  
  8099.    A program can have four types of files:
  8100.  
  8101.    ■ One main module (required)
  8102.  
  8103.    ■ Other modules
  8104.  
  8105.    ■ Include files
  8106.  
  8107.    ■ Document files (including .MAK files)
  8108.  
  8109.    Modules can contain the following:
  8110.  
  8111.    ■ Module-level code
  8112.  
  8113.    ■ SUB procedures
  8114.  
  8115.    ■ FUNCTION procedures
  8116.  
  8117.    ──────────────────────────────────────────────────────────────────────────
  8118.    NOTE
  8119.      When you are writing a completely new program, use the New Program
  8120.      command. When you are calling up a program that already exists on disk,
  8121.      use the Open Program command.
  8122.    ──────────────────────────────────────────────────────────────────────────
  8123.  
  8124.    See Also
  8125.  
  8126.    Section 11.2, "Open Program Command"; Section 11.7, "Create File
  8127.    Command"
  8128.  
  8129.  
  8130.  11.2  Open Program Command
  8131.  
  8132.    The Open Program command opens an existing program. The dialog box
  8133.    displayed initially lists the files with .BAS extensions in the current
  8134.    working directory. You can also list files in other directories and on
  8135.    other disks on your system.
  8136.  
  8137.    When you choose the Open Program command, the dialog box shown in Figure
  8138.    11.1 appears.
  8139.  
  8140.  
  8141.    Path of currently     Entry determines which           Symbol for next
  8142.    loaded file           files are displayed              highest directory
  8143.    ┌┼────────────────────┼─────── Open Program ───────────┼───────────────────
  8144.    ││           ┌────────┼────────────────────────────────┼─────────────────┐
  8145.    ││File Name: │*.BAS                                    │                 │
  8146.    ││           └─────────────────────────────────────────┼─────────────────┘
  8147.    │└C:\QB4.5\DEMO                                        │
  8148.    │                        Files                         │   Dirs/Drives
  8149.    │ ┌──────────────────────────────────────────────────┐ │ ┌───────────────┐
  8150.    │ │ ATEST.BAS        TEST.BAS      ─┐                │ └─┼─..            
  8151.    │ │ BL.BAS           TORUS.BAS      │                │   │ SOURCE ─┐     ▒
  8152.    │ │ DEMO1.BAS        VARHELP.BAS    │                │   │┌[-A-]   │     ▒
  8153.    │ │ DEMO2.BAS        VARHELP2.BAS   │                │  ┌┼┤[-B-]   │     ▒
  8154.    │ │ DEMO3.BAS                       ├─────┐          │  ││└[-C-]   │     ▒
  8155.    │ │ QBFORMAT.BAS                    │     │          │  ││         │     ▒
  8156.    │ │ QCARDS.BAS                      │     │          │  ││         │     ▒
  8157.    │ │ REMLINE.BAS                     │     │          │  ││         │     ▒
  8158.    │ │ SORTDEMO.BAS                   ─┘     │          │  ││         │     
  8159.    │ └▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│▒▒▒▒▒▒▒▒▒┘  │└─────────┼─────┘
  8160.    ├─────────────────────────────────────────┼─────────────┼──────────┼───────
  8161.    │           < OK >          < Cancel >    │     < Help >│          │
  8162.    └─────────────────────────────────────────┼─────────────┼──────────┼───────
  8163.                                              │             │          │
  8164.                .BAS files in current directory        Drives     Subdirectory
  8165.  
  8166.    Figure 11.1  Open Program Dialog Box
  8167.  
  8168.    If a program consists of several modules, all of the modules belonging to
  8169.    the program are loaded. If a program uses include files (see Section
  8170.    2.5.4.3, "Using Include Files for Declarations," and Appendix F,
  8171.    "Metacommands," in Programming in BASIC), the include files are compiled,
  8172.    but not loaded or displayed.
  8173.  
  8174.  11.2.1  Specifying a File
  8175.  
  8176.    Files are displayed in columns in the Files list box. Directories and
  8177.    available drives appear in the Dirs/Drives list to the right of the Files
  8178.    list. Use the DIRECTION keys or the scroll bars to scroll in either of the
  8179.    list boxes. Note that the Files list box scrolls left and right, and the
  8180.    Dirs/Drives list box scrolls up and down.
  8181.  
  8182.    The Open Program dialog box provides two ways to specify the file you want
  8183.    to load (see Section 10.7, "Using the Mouse," for mouse techniques). Use
  8184.    either of the following two methods:
  8185.  
  8186.    1. Type the name of the program in the text box and press ENTER.
  8187.  
  8188.       If you enter a file name with no extension, QuickBASIC assumes your
  8189.       file has the .BAS extension. If you want to load a file that has no
  8190.       extension, type a period (.) immediately after the file name.
  8191.  
  8192.    2. Press the TAB key to move to the list box, and use the DIRECTION keys
  8193.       to move through the list box until the desired file is highlighted.
  8194.       Then press ENTER.
  8195.  
  8196.       You can also highlight the file name by moving to the list box and
  8197.       pressing the first letter of the name of the file you want to load.
  8198.  
  8199.    In either case, the text of the program appears in a window with the file
  8200.    name in the title bar.
  8201.  
  8202.  11.2.2  Listing Directory Contents
  8203.  
  8204.    You can use the Open Program dialog box to list the contents of any
  8205.    directory on your system. When you choose a directory name in the
  8206.    Dirs/Drives list box, QuickBASIC lists all the subdirectories and .BAS
  8207.    files in the directory you choose. When you enter or choose a file name
  8208.    from the Files list box, that file is loaded into memory. The following
  8209.    list describes several methods you can use to list contents of
  8210.    directories:
  8211.  
  8212.    Task                                 Action
  8213.    ──────────────────────────────────────────────────────────────────────────
  8214.    Listing all files in the current     Type *.* in the text box.
  8215.    directory
  8216.  
  8217.    Listing files in root directory of   Type A:*.* in the text box.
  8218.    drive A
  8219.  
  8220.    Listing all files in a subdirectory  Highlight BIN in the Dirs/Drives list
  8221.    named BIN                            box and press ENTER. Type *.* in the
  8222.                                         text box.
  8223.  
  8224.    Listing all files in the current     Type *.BI in the text box.
  8225.    directory with the .BI extension
  8226.  
  8227.    Listing all files in the directory   Type .. in the text box. Or, press a
  8228.    immediately above the current        DIRECTION key or the period (.) to
  8229.    directory                            select .. if you are already in the
  8230.                                         Dirs/Drives list box. Then type *.*
  8231.                                         in the text box.
  8232.    ──────────────────────────────────────────────────────────────────────────
  8233.  
  8234.    ──────────────────────────────────────────────────────────────────────────
  8235.    NOTE
  8236.      The "current working directory" is the directory shown by the CD command
  8237.      from DOS. In contrast, when you select a directory from a list box, you
  8238.      are only listing the files it contains, not changing the current working
  8239.      directory at the DOS level. If you want to change the current working
  8240.      directory, make the Immediate window active, and use the CHDIR
  8241.      statement.
  8242.    ──────────────────────────────────────────────────────────────────────────
  8243.  
  8244.    See Also
  8245.  
  8246.    Section 11.1, "New Program Command"; Section 11.8, "Load File Command"
  8247.  
  8248.  
  8249.  11.3  The Merge Command (Full Menus Only)
  8250.  
  8251.    The Merge command on the File menu inserts the contents of a file at the
  8252.    beginning of the line the cursor is on. When you choose the Merge command
  8253.    from the File menu, the dialog box shown in Figure 11.2 appears.
  8254.  
  8255.  
  8256.    Path of currently     Entry determines which       Symbol for next
  8257.    loaded file           files are displayed          highest directory
  8258.    ┌┼────────────────────┼────────── Merge ───────────────┼───────────────────
  8259.    ││           ┌────────┼────────────────────────────────┼─────────────────┐
  8260.    ││File Name: │*.bas                                    │                 │
  8261.    ││           └─────────────────────────────────────────┼─────────────────┘
  8262.    │└C:\QB4.5\DEMO                                        │
  8263.    │                        Files                         │   Dirs/Drives
  8264.    │ ┌──────────────────────────────────────────────────┐ │ ┌───────────────┐
  8265.    │ │ ATEST.BAS        TEST.BAS      ─┐                │ └─┼ ..            
  8266.    │ │ BL.BAS           TORUS.BAS      │                │   │ SOURCE ─┐     ▒
  8267.    │ │ DEMO1.BAS        VARHELP.BAS    │                │   │┌[-A-]   │     ▒
  8268.    │ │ DEMO2.BAS        VARHELP2.BAS   │                │  ┌┼┤[-B-]   │     ▒
  8269.    │ │ DEMO3.BAS                       ├─────┐          │  ││└[-C-]   │     ▒
  8270.    │ │ QBFORMAT.BAS                    │     │          │  ││         │     ▒
  8271.    │ │ QCARDS.BAS                      │     │          │  ││         │     ▒
  8272.    │ │ REMLINE.BAS                     │     │          │  ││         │     ▒
  8273.    │ │ SORTDEMO.BAS                   ─┘     │          │  ││         │     
  8274.    │ └▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│▒▒▒▒▒▒▒▒▒┘  │└─────────┼─────┘
  8275.    ├─────────────────────────────────────────┼─────────────┼──────────┼───────
  8276.    │           < OK >          < Cancel >    │     < Help >│          │
  8277.    └─────────────────────────────────────────┼─────────────┼──────────┼───────
  8278.                                              │             │          │
  8279.               .BAS files in current directory        Drives       Subdirectory
  8280.  
  8281.    Figure 11.2  Merge Dialog Box
  8282.  
  8283.    The Merge dialog box operates the same way as the Open Program dialog box.
  8284.    However, the Merge command inserts the specified file into the current
  8285.    file, whereas the Open Program command clears whatever is currently in
  8286.    memory, then loads the program.
  8287.  
  8288.    ──────────────────────────────────────────────────────────────────────────
  8289.    NOTE
  8290.      QuickBASIC cannot merge binary files; the file brought in with the Merge
  8291.      command must be text format.
  8292.    ──────────────────────────────────────────────────────────────────────────
  8293.  
  8294.    See Also
  8295.  
  8296.    Section 11.2, "Open Program Command," and Section 14.1, "SUBs Command,"
  8297.    in this manual; Chapter 7, "Programming with Modules," and Appendix B,
  8298.    "Differences from Previous Versions of QuickBASIC," in Programming in
  8299.    BASIC.
  8300.  
  8301.  
  8302.  11.4  Save Command (Full Menus Only)
  8303.  
  8304.    The Save command saves the contents of the current file (the file being
  8305.    displayed in the active View window) to a disk file.
  8306.  
  8307.    If the file you are saving already has a name, Save overwrites the version
  8308.    on disk. If the file does not have a name, the Save dialog box in Figure
  8309.    11.3 appears to ask you for a name.
  8310.  
  8311.  
  8312.    Path of
  8313.    currently     File name  Subdirectory
  8314.    loaded file           │  │
  8315.    ┌┼────────────────────┼──┼ Save ───────────────────────┐
  8316.    ││           ┌────────┼──┼───────────────────────────┐ │
  8317.    ││File Name: │CALC.BAS   │                           │ │
  8318.    ││           └───────────┼───────────────────────────┘ │
  8319.    │└C:\QB4.5\DEMO          │                             │
  8320.    │   Dirs/Drives          │                             │
  8321.    │                        │                             │
  8322.    │ ┌───────────────┐   ┌──┼──────── Format ───────────┐ │
  8323.    │┌┼ ..               │  │ (∙) QuickBASIC -  ─┐      │ │
  8324.    │││ SOURCE ───────────┼──┘      Fast Load and ├───┐  │ │
  8325.    │││ [-A-]─┐       ▒   │         Save         ─┘   │  │ │
  8326.    │││ [-B-] ├────┐  ▒   │                           │  │ │
  8327.    │││ [-C-]─┘    │  ▒   │    ( ) Text -         ─┐  │  │ │
  8328.    │││            │  ▒   │         Readable by    ├──│  │ │
  8329.    │││            │     │         Other Programs ┘  │  │ │
  8330.    ││└────────────┼──┘   └───────────────────────────┼──┘ │
  8331.    ├┼─────────────┼──────────────────────────────────┼────┤
  8332.    ││    < OK >   │      < Cancel >          < Help >│    │
  8333.    └┼─────────────┼──────────────────────────────────┼────┘
  8334.    Symbol for     │                                  │
  8335.    next highest   Drives               File-format options
  8336.    directory
  8337.  
  8338.    Figure 11.3  Save Dialog Box
  8339.  
  8340.    See Also
  8341.  
  8342.    Section 11.5, "Save As Command"; Section 11.6, "Save All Command"
  8343.  
  8344.  
  8345.  11.5  Save As Command
  8346.  
  8347.    The Save As command saves the current file with the name you specify. It
  8348.    is useful for saving a file under a new name and changing the format in
  8349.    which the file is saved. If you change the name, the old file still exists
  8350.    with the name it had the last time it was saved.
  8351.  
  8352.    When you choose Save As from the File menu, a dialog box like that shown
  8353.    in Figure 11.3 appears. The Save As dialog box lists the existing name of
  8354.    the file you want to save. Enter a new name in the text box to replace the
  8355.    old name. The next time you save the file, the new file name will appear
  8356.    in the text box.
  8357.  
  8358.    The following list describes the file-format options in the Save dialog
  8359.    box:
  8360.  
  8361.    Option                   Purpose
  8362.    ──────────────────────────────────────────────────────────────────────────
  8363.    QuickBASIC──Fast Load    Saves a program in QuickBASIC format. A program
  8364.    and Save                 saved this way loads faster than one saved as a
  8365.                             text file but can be edited only using
  8366.                             QuickBASIC. Because it is a non-ASCII file, you
  8367.                             will not be able to change it using another text
  8368.                             editor. This is QuickBASIC's default format for
  8369.                             saving a program. Files classified as document or
  8370.                             include files with the Create File or Load File
  8371.                             command cannot be saved in this format.
  8372.  
  8373.    Text──Readable by Other  Saves your file to disk as a text (ASCII) file.
  8374.    Programs                 Text files can be read, modified, or printed by
  8375.                             any editor or word processing program that reads
  8376.                             ASCII files. Files classified as document or
  8377.                             include files are always stored in this format.
  8378.    ──────────────────────────────────────────────────────────────────────────
  8379.  
  8380.    See Also
  8381.  
  8382.    Section 11.4, "Save Command"; Section 11.6, "Save All Command"
  8383.  
  8384.  
  8385.  11.6  Save All Command (Full Menus Only)
  8386.  
  8387.    The Save All command saves all currently loaded files that have changed
  8388.    since the last time you saved a file. A currently loaded file is one whose
  8389.    name appears in the dialog box of the View menu's SUBs command. Save All
  8390.    is useful when you are working with multiple files in memory.
  8391.  
  8392.    If the main module you are saving already has a name, Save All overwrites
  8393.    the version on disk. If the main module does not have a name, a dialog box
  8394.    like that shown in Figure 11.3 asks you for a name. Section 11.5
  8395.    explains each of the file-format options.
  8396.  
  8397.    When you save a multiple-module program, QuickBASIC creates a special file
  8398.    on your disk that contains the names of all the modules in the program.
  8399.    The file is given the base name of the main module plus the extension
  8400.    .MAK. QuickBASIC uses the .MAK file as a roadmap to the various program
  8401.    modules the next time you load the program. For more information on .MAK
  8402.    files, see Section 16.7.2.
  8403.  
  8404.    See Also
  8405.  
  8406.    Section 11.4, "Save Command"; Section 14.1, "SUBs Command"
  8407.  
  8408.  
  8409.  11.7  Create File Command (Full Menus Only)
  8410.  
  8411.    The Create File command on the File menu allows you to begin a new file as
  8412.    part of the program currently in memory.
  8413.  
  8414.    When you choose the Create File command from the File menu, a dialog box
  8415.    appears. To create a new file, type the file name in the text box, select
  8416.    the file type, and press ENTER. See Figure 11.4.
  8417.  
  8418.  
  8419.             File name
  8420.                 │
  8421.    ┌────────────┼──── Create File ──────────────────┐
  8422.    │       ┌────┼─────────────────────────────────┐ │
  8423.    │ Name: │CALC.BAS                              │ │
  8424.    │       └──────────────────────────────────────┘ │
  8425.    │┌──┬──────────────┬───────────────┐             │
  8426.    ││ (∙) Module     ( ) Include     ( ) Document   │
  8427.    ├┼───────────────────────────────────────────────┤
  8428.    ││     < OK >       < Cancel >      < Help >     │
  8429.    └┼───────────────────────────────────────────────┘
  8430.     │
  8431.    File-type options
  8432.  
  8433.    Figure 11.4  Create File Dialog Box
  8434.  
  8435.    Select the appropriate file type from the following:
  8436.  
  8437. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  8438.    File Type                Description
  8439.    ──────────────────────────────────────────────────────────────────────────
  8440.    Module                   A discrete program component. A program consists
  8441.                             of at least one module. When you make a program
  8442.                             out of several modules, each module is saved on
  8443.                             disk as a separate file when you save the
  8444.    File Type                Description
  8445.    ──────────────────────────────────────────────────────────────────────────
  8446.                            disk as a separate file when you save the
  8447.                             program. Modules are handy if you have long
  8448.                             programs or use the same groups of procedures
  8449.                             over and over in different programs. QuickBASIC's
  8450.                             smart editor checks syntax and formatting in
  8451.                             modules.
  8452.  
  8453.                             See Section 12.5 in this manual for information
  8454.                             on the smart editor. See Chapter 7 in Programming
  8455.                             in BASIC for more information on modules.
  8456.  
  8457.    Include                  A text file whose statements are compiled into
  8458.                             your program when QuickBASIC encounters the
  8459.                             file's name following a $INCLUDE metacommand.
  8460.                             QuickBASIC's smart editor checks syntax and
  8461.                             formatting in include files as it does in
  8462.                             modules. Although the contents of the include
  8463.                             file are used in your program, the include file
  8464.                             itself is not a part of the program. Its name
  8465.    File Type                Description
  8466.    ──────────────────────────────────────────────────────────────────────────
  8467.                            itself is not a part of the program. Its name
  8468.                             does not appear in the .MAK file of a
  8469.                             multiple-module program.
  8470.  
  8471.    Document                 A text file. QuickBASIC does not treat a file
  8472.                             opened as a document as BASIC code, so the smart
  8473.                             editor does not check document files for syntax
  8474.                             and formatting. However, you can edit a document
  8475.                             file with the QuickBASIC editor just as you would
  8476.                             with a normal word processor. Document file names
  8477.                             never appear in the .MAK file of a
  8478.                             multiple-module program.
  8479.    ──────────────────────────────────────────────────────────────────────────
  8480.  
  8481.  
  8482.    Once you have created any of the preceding kinds of files in QuickBASIC,
  8483.    you can see the file's name in the list box of the View menu's SUBs dialog
  8484.    box.
  8485.  
  8486.    While a file's name appears in this list box, you cannot load it again,
  8487.    even with a different classification. For example, if you create a file as
  8488.    a document, you cannot load it again as an include file until you unload
  8489.    the current copy with the Unload File Command (see Section 11.9, "Unload
  8490.    File Command").
  8491.  
  8492.    ──────────────────────────────────────────────────────────────────────────
  8493.    NOTE
  8494.      Use the Create File command to add a new module to the program currently
  8495.      in memory. Create File differs from Open Program, which loads a file as
  8496.      a module after unloading all other files prior to loading the program.
  8497.      If no other modules are loaded when you use Create File to create a
  8498.      module, it is considered the main module of the program.
  8499.    ──────────────────────────────────────────────────────────────────────────
  8500.  
  8501.    See Also
  8502.  
  8503.    Section 11.1, "New Program Command"; Section 11.2, "Open Program
  8504.    Command"; Section 11.8, "Load File Command"; Section 14.1, "SUBs
  8505.    Command"
  8506.  
  8507.  
  8508.  11.8  Load File Command (Full Menus Only)
  8509.  
  8510.    The Load File command on the File menu loads single program modules──as
  8511.    well as include files and document files──from disk into memory. When you
  8512.    choose Load File, a dialog box appears. To load a file, type the file name
  8513.    in the text box, select the file type, and press ENTER. See Figure 11.5.
  8514.  
  8515.  
  8516.    Path of currently     File to load             .BAS files in
  8517.    loaded file           │                        current directory
  8518.    ┌┼────────────────────┼──────── Load File ─────┼───────────────────────────
  8519.    ││           ┌────────┼────────────────────────┼─────────────────────────┐
  8520.    ││File Name: │DEMO1.BAS                        │                         │
  8521.    ││           └─────────────────────────────────┼─────────────────────────┘
  8522.    │└C:\QB4.5\DEMO                                │
  8523.    │                        Files                 │           Dirs/Drives
  8524.    │ ┌────────────────────────────────────────────┼─────┐   ┌───────────────┐
  8525.    │ │ ATEST.BAS        SORTDEMO.BAS  ─┐          │     │   │ ..            
  8526.    │ │ BL.BAS           TEST.BAS       │          │     │   │ SOURCE        ▒
  8527.    │ │ DEMO1.BAS        TORUS.BAS      │          │     │   │ [-A-]         ▒
  8528.    │ │ DEMO2.BAS        VARHELP.BAS    │          │     │   │ [-B-]         ▒
  8529.    │ │ DEMO3.BAS        VARHELP2.BAS   ├──────────┘     │   │ [-C-]         ▒
  8530.    │ │ QBFORMAT.BAS                    │                │   │               ▒
  8531.    │ │ QCARDS.BAS                      │                │   │               ▒
  8532.    │ │ REMLINE.BAS                    ─┘                │   │               
  8533.    │ └▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒┘   └───────────────┘
  8534.    │ ┌────────────┬───────────┬────────────┐
  8535.    │ │ Load as:  (∙) Module  ( ) Include  ( ) Document
  8536.    ├─┼────────────────────────────────────────────────────────────────────────
  8537.    │ │         < OK >          < Cancel >          < Help >
  8538.    └─┼────────────────────────────────────────────────────────────────────────
  8539.      │
  8540.    File-type options
  8541.  
  8542.    Figure 11.5  Load File Dialog Box
  8543.  
  8544.    You must select the correct file type: Module, Include, or Document. See
  8545.    Section 11.7, "Create File Command," for more details on specific file
  8546.    types.
  8547.  
  8548.    Once you have loaded any type of file into QuickBASIC, you can see the
  8549.    file name in the list box of the View menu's SUBs dialog box.
  8550.  
  8551.    While a file name appears in this list box, you cannot load it again, even
  8552.    with a different classification. For example, if you load a file as a
  8553.    document, you cannot load it again as an include file until you unload it
  8554.    with the Unload File command. See Section 11.9 for more information on
  8555.    Unload File.
  8556.  
  8557.    If you have procedures in other modules (program files) that you want to
  8558.    use in the current program, you can load those modules using Load File.
  8559.    Once the file is loaded, you can reference the procedures it contains
  8560.    anywhere in the current program.
  8561.  
  8562.    Modules from other programs can be added into the program currently in
  8563.    memory as follows:
  8564.  
  8565.    1. Choose the Load File command from the File menu.
  8566.  
  8567.    2. Select the name of the module containing procedures you want to use in
  8568.       the current program.
  8569.  
  8570.    3. Press ENTER to load the file as a module, since the Module option is
  8571.       already chosen.
  8572.  
  8573.    4. Repeat steps 1-3 for each module you want to load.
  8574.  
  8575.    Save the program using the Save All command once all the modules are
  8576.    loaded.
  8577.  
  8578.    See Also
  8579.  
  8580.    Section 11.1, "New Program Command"; Section 11.7, "Create File Command"
  8581.  
  8582.  
  8583.  11.9  Unload File Command (Full Menus Only)
  8584.  
  8585.    The Unload File command removes an include file, document, or entire
  8586.    module from memory. After you unload a module, the disk file containing
  8587.    the module still exists; however, when you save your program, the module
  8588.    is no longer a part of the program.
  8589.  
  8590.    If your program contains more than one module, the name of the unloaded
  8591.    module is removed from the program's .MAK file. If you unload the main
  8592.    module of a multiple-module program, QuickBASIC prompts you to set a new
  8593.    main module before proceeding. Unloading a document or include file leaves
  8594.    any other loaded files in memory.
  8595.  
  8596.    When you choose the Unload File command, the dialog box shown in Figure
  8597.    11.6 appears.
  8598.  
  8599.  
  8600.    File to unload
  8601.    ┌────────── Unload File ──────────┐
  8602.    │  Choose module to unload:       │
  8603.    │  ┌───────────────────────────┐  │
  8604.    │  │ DEMO1.BAS                   │
  8605.    │  │ DEMO2.BAS                 ▒  │
  8606.    │  │ TEST.BAS                  ▒  │
  8607.    │  │                           ▒  │
  8608.    │  │                           ▒  │
  8609.    │  │                           ▒  │
  8610.    │  │                             │
  8611.    │  └───────────────────────────┘  │
  8612.    │                                 │
  8613.    ├─────────────────────────────────┤
  8614.    │  < OK >  < Cancel >  < Help >   │
  8615.    └─────────────────────────────────┘
  8616.  
  8617.    Figure 11.6  Unload File Dialog Box
  8618.  
  8619.    Follow these steps to unload a file:
  8620.  
  8621.    1. Choose the Unload File command from the File menu.
  8622.  
  8623.    2. Select the name of the module, include file, or document that you no
  8624.       longer want in the program.
  8625.  
  8626.    3. Press ENTER.
  8627.  
  8628.    The module is unloaded but still exists as a disk file. You can use Unload
  8629.    File to unload any type of file──a program module, include file, or
  8630.    document file──from memory.
  8631.  
  8632.    See Also
  8633.  
  8634.    Section 11.1, "New Program Command"; Section 16.7.2, "The .MAK File"
  8635.  
  8636.  
  8637.  11.10  The Print Command
  8638.  
  8639.    The Print command on the File menu lets you print selected text, text in
  8640.    the active window, the entire current module, or all currently loaded
  8641.    program modules. To use the Print command, your printer must be connected
  8642.    to your computer's LPT1 port.
  8643.  
  8644.    When you choose the Print command from the File menu, the dialog box shown
  8645.    in Figure 11.7 opens. Select the appropriate option from the Print
  8646.    options box to print your file.
  8647.  
  8648.  
  8649.          Prints                Prints contents of
  8650.          selected text         active window
  8651.              │                 │
  8652.    ┌─────────┼─ Print ─────────┼──┐
  8653.    │         │                 │  │
  8654.    │     ( ) Selected Text     │  │
  8655.    │     ( ) Active Window─────┘  │
  8656.    │     ( ) Current Module──────┐│
  8657.    │     ( ) All Modules         ││
  8658.    │          │                  ││
  8659.    ├──────────┼──────────────────┼┤
  8660.    │  < OK > <│Cancel > < Help > ││
  8661.    └──────────┼──────────────────┼┘
  8662.               │                  │
  8663.         Prints all               Prints module in
  8664.         loaded modules           active window
  8665.  
  8666.    Figure 11.7  Print Dialog Box
  8667.  
  8668.  
  8669.  11.11  DOS Shell Command (Full Menus Only)
  8670.  
  8671.    The DOS Shell command on the File menu lets you return temporarily to the
  8672.    DOS command level, where you can execute other programs and DOS commands.
  8673.    QuickBASIC remains in memory so you can return to the same place in your
  8674.    program, without reloading it.
  8675.  
  8676.    QuickBASIC needs to find the COMMAND.COM file before it can execute the
  8677.    Shell command. QuickBASIC looks for COMMAND.COM first in the directory
  8678.    specified in the COMSPEC environment variable, then in the current
  8679.    directory. See your DOS documentation for more information about
  8680.    COMMAND.COM and COMSPEC.
  8681.  
  8682.    Follow these steps to return to QuickBASIC from the DOS command level:
  8683.  
  8684.    1. Type exit
  8685.  
  8686.    2. Press ENTER
  8687.  
  8688.    The QuickBASIC screen reappears as you left it.
  8689.  
  8690.  
  8691.  11.12  Exit Command
  8692.  
  8693.    The Exit command on the File menu removes QuickBASIC from memory and
  8694.    returns you to the DOS prompt.
  8695.  
  8696.    When you exit from a new or modified program that has not been saved,
  8697.    QuickBASIC displays the dialog box shown in Figure 11.8.
  8698.  
  8699.  
  8700.    ┌──────────────────────────────────────────────────────────┐
  8701.    │                                                          │
  8702.    │  One or more loaded files are not saved. Save them now?  │
  8703.    │                                                          │
  8704.    ├──────────────────────────────────────────────────────────┤
  8705.    │     ┌── < Yes >   < No >   < Cancel >   < Help > ──┐     │
  8706.    └─────┼────────────────┼──────────┼──────────────────┼─────┘
  8707.          │                │          │                  │
  8708.    Saves the      Returns to DOS     Stays in           Provides help on
  8709.    file(s)        without saving     QuickBASIC         the dialog box
  8710.                   the program        environment
  8711.  
  8712.    Figure 11.8  Exit Dialog Box
  8713.  
  8714.    To exit from QuickBASIC after the Exit dialog box has been called up, use
  8715.    one of these procedures:
  8716.  
  8717.    1. To save the program in its current state and then exit, choose Yes or
  8718.       press ENTER.
  8719.  
  8720.       If this is a new program that you haven't named yet, QuickBASIC
  8721.       displays a dialog box similar to the Save dialog box. See Section
  8722.       11.4 for more information on this dialog box.
  8723.  
  8724.    2. To return to DOS without saving the file in its current state, choose
  8725.       No or type N.
  8726.  
  8727.    To stay in the QuickBASIC environment (that is, not exit to DOS after
  8728.    all), press ESC.
  8729.  
  8730.    See Also
  8731.  
  8732.    Section 11.5, "Save As Command"; Section 11.11, "DOS Shell Command"
  8733.  
  8734.  
  8735.  
  8736.  ────────────────────────────────────────────────────────────────────────────
  8737.  Chapter 12  Using the Editor
  8738.  
  8739.    This chapter describes how to enter and edit program text using QuickBASIC
  8740.    editing commands. Before beginning this chapter, you should be familiar
  8741.    with the QuickBASIC screen and the techniques described in Chapter 10,
  8742.    "Getting Around in QuickBASIC."
  8743.  
  8744.    This chapter includes information on
  8745.  
  8746.    ■ Performing simple editing functions such as entering text and moving the
  8747.      cursor
  8748.  
  8749.    ■ Deleting and inserting text
  8750.  
  8751.    ■ Moving and copying blocks of text
  8752.  
  8753.    ■ Searching for and replacing characters, words, or a group of words
  8754.  
  8755.    ■ Copying text from other files
  8756.  
  8757.  
  8758.  12.1  Entering Text
  8759.  
  8760.    New characters are added to the text either by inserting or overtyping. In
  8761.    "insert mode," the QuickBASIC editor inserts each new character to the
  8762.    left of the cursor position. In "overtype mode," each new character
  8763.    replaces the character under the cursor. You switch between insert mode
  8764.    and overtype mode by pressing the INS key or CTRL+V. The cursor is a
  8765.    blinking underscore in insert mode and a blinking box in overtype mode.
  8766.  
  8767.    When typing a QuickBASIC program, you can enter a line (tell QuickBASIC
  8768.    that you have completed one or more BASIC statements) either by pressing
  8769.    the ENTER key at the end of the line or by moving the cursor off the line.
  8770.    If the Syntax Checking command is on (Options menu, Full Menus only),
  8771.    QuickBASIC checks the line for proper statement syntax.
  8772.  
  8773.  
  8774.  12.2  Selecting Text
  8775.  
  8776.    Before you can perform editing functions that manipulate blocks of text
  8777.    (copying and deleting), you must indicate the portion of text you wish to
  8778.    edit by selecting (highlighting) it. Selecting tells both you and the
  8779.    computer which text will be changed by the next command.
  8780.  
  8781.    Hold down the SHIFT key while using the DIRECTION keys or any of the
  8782.    editing shortcut keys (see Section 10.2.2, "Using Shortcut Keys") to
  8783.    select text. For example, press SHIFT+END to select everything from the
  8784.    cursor to the end of a line. To remove highlighting, press any DIRECTION
  8785.    key.
  8786.  
  8787.    ──────────────────────────────────────────────────────────────────────────
  8788.    IMPORTANT
  8789.      If you begin typing while the text is still selected, what you type
  8790.      replaces the selected text.
  8791.    ──────────────────────────────────────────────────────────────────────────
  8792.  
  8793.  
  8794.  12.3  Indenting text
  8795.  
  8796.    Indent text to improve the readability and structured appearance of your
  8797.    program. Appropriate use of indenting can aid debugging. Use the SPACEBAR
  8798.    or TAB key to indent a single line of text. To indent a block of text,
  8799.    select the lines you wish to indent, then press TAB.
  8800.  
  8801.    Indenting is an integral part of well-structured programs──programs that
  8802.    are highly readable, logical and self-explanatory. QuickBASIC offers
  8803.    several indentation controls, listed in Table 12.1
  8804.  
  8805.    Table 12.1  QuickBASIC Indentation Controls
  8806.    Keystrokes               Description
  8807.    ──────────────────────────────────────────────────────────────────────────
  8808.    (Automatic)              Indents each new line automatically, maintaining
  8809.                             the current indentation level.
  8810.  
  8811.    HOME                     Cancels automatic indentation on a blank line and
  8812.                             moves cursor to the left margin.
  8813.  
  8814.    BACKSPACE                Moves indentation back one level.
  8815.  
  8816.    CTRL+Q+S                 Moves cursor to the left margin of a line
  8817.                             containing indented text.
  8818.  
  8819.    SHIFT+TAB                Removes leading spaces for one indentation level.
  8820.                             If a block of text is selected, the whole block
  8821.                             is moved to the left.
  8822.    ──────────────────────────────────────────────────────────────────────────
  8823.  
  8824.    The default tab setting is eight spaces. You can change the tab setting as
  8825.    follows:
  8826.  
  8827.    1. Choose the Display command from the Options menu.
  8828.  
  8829.    2. Select the Tab Stops display option.
  8830.  
  8831.    3. Enter the new tab-stop setting.
  8832.  
  8833.    4. Press ENTER.
  8834.  
  8835.    QuickBASIC uses individual spaces (rather than the literal tab character,
  8836.    ASCII 9) to represent indentation levels. The Tab Stops option in the
  8837.    Option menu's Display dialog box sets the number of spaces per indentation
  8838.    level.
  8839.  
  8840.    Some text editors use literal tab characters to represent multiple spaces
  8841.    when storing text files. Refer to Appendix B, "Differences from Previous
  8842.    Versions of BASIC," in Programming in BASIC if you work with files
  8843.    originally created with such an editor or if you suspect that your text
  8844.    editor uses literal tab characters.
  8845.  
  8846.    See Also
  8847.  
  8848.    Section 20.1, "Display Command"
  8849.  
  8850.  
  8851.  12.4  Using Placemarkers in Text
  8852.  
  8853.    If you are working on different parts of a large program, you can tell
  8854.    QuickBASIC to remember where in the program you are working (set a
  8855.    "place-marker"). This makes it possible to jump between different markers
  8856.    as needed. You can set up to four placemarkers, numbered 0-3, anywhere in
  8857.    your program.
  8858.  
  8859.    Follow these steps to use placemarkers:
  8860.  
  8861.    ■ Put the cursor on the line you want to mark. Press CTRL+K and then n to
  8862.      set placemarker number n.
  8863.  
  8864.    ■ Press CTRL+Q and then n to move to placemarker number n.
  8865.  
  8866.  
  8867.  12.5  The Smart Editor
  8868.  
  8869.    QuickBASIC Version 4.5 combines a text editor, a compiler, and a debugger
  8870.    into a single "smart editor." The smart editor includes special features
  8871.    that make it easier to enter and edit BASIC programs. When the smart
  8872.    editor is on, QuickBASIC performs the following actions each time you
  8873.    enter a line:
  8874.  
  8875.    ■ Checks the line for syntax errors.
  8876.  
  8877.    ■ Formats the line as needed.
  8878.  
  8879.    ■ Translates the line to executable form, if the syntax is correct. This
  8880.      means that each line you enter is ready to run immediately.
  8881.  
  8882.  12.5.1  When Is the Smart Editor On?
  8883.  
  8884.    In most cases, you use the QuickBASIC editor to enter and edit program
  8885.    text. If you start QuickBASIC and begin typing, QuickBASIC assumes that
  8886.    you want to write BASIC statements and turns on the smart editor. The
  8887.    smart editor is also on when you do either of the following:
  8888.  
  8889.    ■ Choose New Program or Open Program from the File menu.
  8890.  
  8891.    ■ Choose Create File or Load File from the File menu, then select the
  8892.      Module or Include option in the dialog box.
  8893.  
  8894.    You may occasionally need to edit a text file consisting of something
  8895.    other than BASIC statements, such as a QuickBASIC .MAK file or document
  8896.    file. For this purpose, you can turn off the smart-editor features and use
  8897.    the environment as an ordinary word processor. Do this by choosing Create
  8898.    File or Load File from the File menu, then selecting the Document option
  8899.    in the dialog box.
  8900.  
  8901.  12.5.2  Automatic Syntax Checking
  8902.  
  8903.    When the smart editor is on, it checks the syntax of each line when it is
  8904.    entered. A syntax error indicates that the line contains a statement that
  8905.    is not meaningful to QuickBASIC. For instance, this line causes a syntax
  8906.    error because the keyword GOTO is not a valid argument for the PRINT
  8907.    statement:
  8908.  
  8909.    PRINT GOTO
  8910.  
  8911.    When an error occurs, QuickBASIC displays an error message. Press ESC or
  8912.    SPACEBAR to clear the message from the screen and position the cursor
  8913.    where the error occurred. You must correct syntax errors before your
  8914.    program will run.
  8915.  
  8916.    ──────────────────────────────────────────────────────────────────────────
  8917.    NOTE
  8918.      When you clear a syntax-error message, the cursor is placed on the
  8919.      statement that caused the error. Press F1 for on-line help with the
  8920.      syntax of the statement.
  8921.    ──────────────────────────────────────────────────────────────────────────
  8922.  
  8923.    Certain typing mistakes are not recognized as syntax errors when entered.
  8924.    For example, no error message appears if you enter the following line
  8925.    instead of the PRINT keyword:
  8926.  
  8927.    pront
  8928.  
  8929.    Although this does not look like a valid BASIC statement, QuickBASIC does
  8930.    not flag the error until you try to run the program. Until then,
  8931.    QuickBASIC interprets the statement as a call to a SUB procedure named
  8932.    pront.
  8933.  
  8934.    Syntax checking is always on unless you choose Create File or Load File
  8935.    commands and choose the Document option. You can toggle syntax checking
  8936.    off and on with the Syntax Checking command from the Options menu. A
  8937.    bullet (■) appears next to the command when syntax checking is toggled on.
  8938.  
  8939.  12.5.3  Error Messages
  8940.  
  8941.    QuickBASIC translates statements to executable code as they are entered,
  8942.    if there are no syntax errors. If there are syntax errors, QuickBASIC
  8943.    displays a dialog box containing the appropriate error message. If
  8944.    QuickBASIC displays an error message that puzzles you, you can get further
  8945.    information. For more information on the error message, choose the Help
  8946.    command button in the dialog box. To get more information on the use of
  8947.    the statement that caused the error, choose OK in the dialog box and do
  8948.    either of the following steps:
  8949.  
  8950.    ■ Choose the Topic command on the Help menu.
  8951.  
  8952.    ■ Press F1
  8953.  
  8954.    Often you will see the error message Syntax error, but some error messages
  8955.    are more specific. For example, suppose you enter the following line,
  8956.    which is missing a file name:
  8957.  
  8958.    OPEN, I, 1,
  8959.  
  8960.    QuickBASIC generates the syntax-error message Expected: expression as
  8961.    shown in Figure 12.1:
  8962.  
  8963.  
  8964.    Incomplete statement
  8965.     │
  8966.     │ File  Edit  View  Search  Run  Debug  Options                     Help
  8967.    ┌┼─────────────────────────────── Untitled ───────────────────────────┤├──
  8968.    │OPEN,I, 1,
  8969.    │
  8970.    │
  8971.    │
  8972.    │
  8973.    │                       ┌────────────────────────┐
  8974.    │                       │                        │
  8975.    │               ┌────── │  Expected: expression  │ ───────┐
  8976.    │               │       │                        │        │
  8977.    │               │       ├────────────────────────┤        │
  8978.    │               │       │   < OK >    < Help >   │        │
  8979.    │               │       └────────────────────────┘        │
  8980.    │               │                                         │
  8981.    │               │                                         │
  8982.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  8983.    ├───────────────┼─────────────── Immediate ───────────────┼───── ──────────
  8984.    │               │                                         │
  8985.    │               │                                         │
  8986.     <Shift+F1=Help>│<F6=Window> <F2=Subs> <F5=Run> <F8=Step> │    C  00001:005
  8987.                    │                                         │
  8988.                Type of syntax error                  Provides help on the erro
  8989.  
  8990.    Figure 12.1  Syntax Error Message
  8991.  
  8992.    In the case above, do the following to get on-line help on the OPEN
  8993.    statement:
  8994.  
  8995.    1. Choose OK in the dialog box.
  8996.  
  8997.    2. Place the cursor in the OPEN keyword.
  8998.  
  8999.    3. Press F1.
  9000.  
  9001.    The initial on-line help screen is displayed, as shown in Figure 12.2.
  9002.  
  9003.  
  9004.    Different usages of OPEN
  9005.     │
  9006.     │ File  Edit  View  Search  Run  Debug  Calls  Options              Help
  9007.    ┌┼───────────── HELP: OPEN (File I/O) Statement QuickSCREEN ──────────┤├──
  9008.    ││ QuickSCREEN     Details     Example     Contents     Index
  9009.    │├────────────────────────────────────────────────────────────────────────
  9010.    │OPEN - a file I/O statement that enables I/O to a file or device
  9011.    ││
  9012.    │Syntax
  9013.    ││ OPEN file [FOR mode1] [ACCESS access] [lock] AS [#]filenum [LEN=reclen]
  9014.    ││┌─
  9015.    │││■ file is a string expression that specifies an optional device name,
  9016.    │└┤  followed by a file name or path name
  9017.    │ │■ filenum is an integer expression whose value is between 1 and 255
  9018.    │ └─
  9019.    │Other Uses of the OPEN Keyword
  9020.    │  OPEN COM - to open a communications channel
  9021.    │
  9022.    │See Also  GET  PUT  SEEK  INPUT #  PRINT #  FREEFILE
  9023.    │
  9024.    ├──────────────────────────────── Untitled ───────────────────────────┤├──
  9025.    │OPEN,I,1,──────┐
  9026.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  9027.    ├───────────────┼─────────────── Immediate ────────────────────────────────
  9028.    │               │
  9029.    │               │
  9030.     <Shift+F1=Help>│<F6=Window> <F2=Subs> <F5=Run> <F8=Step>       C 00001:003
  9031.                    │
  9032.             Program text
  9033.  
  9034.    Figure 12.2  Initial Help Screen on the OPEN Keyword
  9035.  
  9036.    In the screen shown in Figure 12.2, choose the usage you are interested
  9037.    in by putting the cursor anywhere on the appropriate line and pressing F1.
  9038.    Notice that your program text remains visible on the screen when you are
  9039.    using on-line help. To exit on-line help, press ESC.
  9040.  
  9041.    See Also
  9042.  
  9043.    Chapter 8, "Statement and Function Summary," and Appendix I, "Error
  9044.    Messages," in Programming in BASIC.
  9045.  
  9046.  12.5.4  Automatic Formatting
  9047.  
  9048.    In addition to checking for syntax errors, the smart editor automatically
  9049.    standardizes the format of each line as you enter it. The editor makes the
  9050.    following changes:
  9051.  
  9052.    ■ Changes all BASIC keywords to uppercase letters.
  9053.  
  9054.    ■ Inserts spaces before and after all BASIC operators.
  9055.  
  9056.    ■ Keeps capitalization consistent in all references to variables or
  9057.      procedures.
  9058.  
  9059.    ■ Adds punctuation where appropriate. For instance, the smart editor
  9060.      inserts semicolons between consecutive items in a PRINT statement if you
  9061.      do not include them yourself. It also supplies a matching final
  9062.      quotation mark to the argument of a PRINT statement if you forget it.
  9063.  
  9064.    QuickBASIC keeps track of the names of all variables and procedures in
  9065.    your program and capitalizes these names consistently. It changes the
  9066.    capitalization of all occurrences of a variable or procedure name to the
  9067.    reflect the most recently entered version. For example, if you first name
  9068.    a variable MyVar (uppercase M and V), and later enter it as myvar (all
  9069.    lowercase), QuickBASIC changes all instances of MyVar to myvar.
  9070.  
  9071.  
  9072.  12.6  Entering Special Characters
  9073.  
  9074.    QuickBASIC has procedures for entering the literal representations of
  9075.    special characters, including high-order ASCII characters and the literal
  9076.    ASCII characters associated with control sequences. (In general, entering
  9077.    such literal characters makes your programs more readable but less
  9078.    portable. For portability, use the CHR$ function. See Section 9.5,
  9079.    "Summary of String Processing Statements and Functions," in Programming in
  9080.    BASIC.)
  9081.  
  9082.    High-order ASCII characters are those corresponding to decimal 128-255.
  9083.    You can enter them directly in your QuickBASIC program by holding down the
  9084.    ALT key while you type the appropriate decimal code on the numeric keypad.
  9085.    For example, holding down the ALT key while you enter 205 produces the
  9086.    double-line character at the cursor.
  9087.  
  9088.    Many of the low-order ASCII characters corresponding to decimal 1-27 are
  9089.    associated with both literal characters and special actions. For example,
  9090.    the ASCII character represented by ALT+25 is associated with both the
  9091.    down-arrow character (<143>) and 'Y (command to delete the current line).
  9092.    You may want to enter the down arrow in a PRINT statement. One way to do
  9093.    this is to specify decimal 25 as the argument to the CHR$ function. See
  9094.    Appendix D, "Keyboard Scan Codes and ASCII Character Codes," in
  9095.    Programming in BASIC for decimal equivalents of ASCII characters. However,
  9096.    you can also enter the literal character itself by using the following
  9097.    method:
  9098.  
  9099.    1. Hold down the CTRL key while pressing the letter P.
  9100.  
  9101.       This produces the 'P character on the QuickBASIC status bar. While this
  9102.       character is displayed, you can enter a CTRL-key sequence to produce
  9103.       its literal character.
  9104.  
  9105.    2. Hold down the CTRL key again, this time pressing the letter
  9106.       corresponding to the literal character you want.
  9107.  
  9108.       This enters the literal ASCII character (as opposed to the special
  9109.       action of the control sequence) at the cursor.
  9110.  
  9111.    For example, if you want to enter the down-arrow () character within the
  9112.    quotation marks of a PRINT statement, you can enter it as CTRL+P+Y. If you
  9113.    tried to enter it as CTRL+Y or as ALT+25 while 'P was not visible on the
  9114.    reference bar, your line would be deleted. Note that you cannot use this
  9115.    technique for entering the characters corresponding to the following: 'J,
  9116.    'L, 'M, 'U. See Appendix D, "Keyboard Scan Codes and ASCII Character
  9117.    Codes," in Programming in BASIC for a complete list of the ASCII
  9118.    characters.
  9119.  
  9120.  
  9121.  12.7  Summary of Editing Commands
  9122.  
  9123.    QuickBASIC's editor is designed to be flexible; it supports a keyboard
  9124.    interface familiar to users of other Microsoft products such as Microsoft
  9125.    Word. Many combinations of the CTRL key with other keys are familiar to
  9126.    users of WordStar and similar editors. Table 12.2 summarizes all the
  9127.    QuickBASIC editing commands.
  9128.  
  9129.    Table 12.2  Editing Commands
  9130. ╓┌─┌────────────────────────────────────┌──────────────────┌─────────────────╖
  9131.                                                            WordStar-Style
  9132.                                         Keypad Keys        Key Combinations
  9133.    ──────────────────────────────────────────────────────────────────────────
  9134.    Moving Cursor
  9135.    Character left                       LEFT               CTRL+S
  9136.    Character right                      RIGHT              CTRL+D
  9137.                                                            WordStar-Style
  9138.                                         Keypad Keys        Key Combinations
  9139.    ──────────────────────────────────────────────────────────────────────────
  9140.   Character right                      RIGHT              CTRL+D
  9141.    Word left                            CTRL+LEFT          CTRL+A
  9142.    Word right                           CTRL+RIGHT         CTRL+F
  9143.    Line up                              UP                 CTRL+E
  9144.    Line down                            DOWN               CTRL+X
  9145.    First indentation level              HOME               ---
  9146.    Column 1 of current line             ---                CTRL+Q+S
  9147.    Beginning of next line               CTRL+ENTER         CTRL+J
  9148.    End of line                          END                CTRL+Q+D
  9149.    Top of window                        ---                CTRL+Q+E
  9150.    Bottom of file                       ---                CTRL+Q+X
  9151.    Beginning of module/procedure        CTRL+HOME          CTRL+Q+R
  9152.    End of module/procedure              CTRL+END           CTRL+Q+C
  9153.    Set marker                           ---                CTRL+K n
  9154.    Move to marker                       ---                CTRL+Q n
  9155.  
  9156.    Inserting
  9157.    Insert mode on or off                INS                CTRL+V
  9158.                                                            WordStar-Style
  9159.                                         Keypad Keys        Key Combinations
  9160.    ──────────────────────────────────────────────────────────────────────────
  9161.   Insert mode on or off                INS                CTRL+V
  9162.    Line below                           END+ENTER          ---
  9163.    Line above                           ---                HOME CTRL+N
  9164.    Contents of Clipboard                SHIFT+INS          ---
  9165.    Tab at cursor or beginning of each   TAB                CTRL+I
  9166.    selected line
  9167.    Control character at cursorposition  ---                CTRL+P CTRL+key
  9168.  
  9169.    Deleting
  9170.    Current line, saving in Clipboard    ---                CTRL+Y
  9171.    To end of line, saving in Clipboard  ---                CTRL+Q+Y
  9172.    Character left                       BKSP               CTRL+H
  9173.    Character at cursor                  DEL                CTRL+G
  9174.    Word                                 ---                CTRL+T
  9175.    Selected text, saving in Clipboard   SHIFT+DEL          ---
  9176.    Selected text, not saving in         DEL                CTRL+G
  9177.    Clipboard
  9178.    Leading spaces for one indentation   SHIFT+TAB          ---
  9179.                                                            WordStar-Style
  9180.                                         Keypad Keys        Key Combinations
  9181.    ──────────────────────────────────────────────────────────────────────────
  9182.   Leading spaces for one indentation   SHIFT+TAB          ---
  9183.    level of selected lines
  9184.  
  9185.    Copying
  9186.    Save selected text to Clipboard      CTRL+INS           ---
  9187.  
  9188.    Scrolling
  9189.    Up one line                          CTRL+UP            CTRL+W
  9190.    Down one line                        CTRL+DOWN          CTRL+Z
  9191.    Page up                              PGUP               CTRL+R
  9192.    Page down                            PGDN               CTRL+C
  9193.    Left one window                      CTRL+PGUP          ---
  9194.    Right one window                     CTRL+PGDN          ---
  9195.  
  9196.    Selecting
  9197.    Character left                       SHIFT+LEFT         ---
  9198.    Character right                      SHIFT+RIGHT        ---
  9199.    Current line                        SHIFT+DOWN         ---
  9200.                                                            WordStar-Style
  9201.                                         Keypad Keys        Key Combinations
  9202.    ──────────────────────────────────────────────────────────────────────────
  9203.   Current line                        SHIFT+DOWN         ---
  9204.    Line above                           SHIFT+UP           ---
  9205.    Word left                            SHIFT+CTRL+LEFT    ---
  9206.    Word right                           SHIFT+CTRL+RIGHT   ---
  9207.    Screen up                            SHIFT+PGUP         ---
  9208.    Screen down                          SHIFT+PGDN         ---
  9209.    Screen left                          SHIFT+CTRL+PGUP    ---
  9210.    Screen right                         SHIFT+CTRL+PGDN    ---
  9211.    To beginning of module/procedure     SHIFT+CTRL+HOME    ---
  9212.    To end of module/procedure           SHIFT+CTRL+END     ---
  9213.    ──────────────────────────────────────────────────────────────────────────
  9214.  
  9215.  
  9216.  
  9217.  
  9218.  
  9219.  ────────────────────────────────────────────────────────────────────────────
  9220.  Chapter 13  The Edit Menu
  9221.  
  9222.    The Edit menu controls the functions used to build and manipulate your
  9223.    program code (text). Use the Edit menu to cut, copy, and paste text, to
  9224.    undo your last edit, and to create SUB and FUNCTION procedures.
  9225.  
  9226.    The Edit menu has the following commands:
  9227.  
  9228.    ■ Undo. Reverses your last command or action, restoring the current line
  9229.      to its previous state (Full Menus only).
  9230.  
  9231.    ■ Cut. Deletes selected text and places it on the Clipboard.
  9232.  
  9233.    ■ Copy. Places a copy of selected text on the Clipboard.
  9234.  
  9235.    ■ Paste. Inserts the contents of the Clipboard at the cursor.
  9236.  
  9237.    ■ Clear. Deletes selected text permanently (Full Menus only).
  9238.  
  9239.    ■ New SUB. Creates a new SUB procedure in its own window (Full Menus
  9240.      only).
  9241.  
  9242.    ■ New FUNCTION. Creates a new FUNCTION procedure in its own window (Full
  9243.      Menus only).
  9244.  
  9245.  
  9246.  13.1  Understanding the Clipboard
  9247.  
  9248.    The editor in QuickBASIC uses a Clipboard, which is the part of your
  9249.    computer's memory used to temporarily store blocks of text you have cut or
  9250.    copied. If you have used a word processor to cut, copy, and paste text,
  9251.    you are familiar with the Clipboard concept.
  9252.  
  9253.    When you use the Cut or Copy command to move, remove, or duplicate a
  9254.    section of text, that text is stored in the Clipboard. You can then use
  9255.    the Paste command to insert the Clipboard's contents as many times as you
  9256.    like; Paste does not alter the contents of the Clipboard. But any time you
  9257.    use the Cut or Copy command, the contents of the Clipboard are replaced by
  9258.    new contents.
  9259.  
  9260.  
  9261.  13.2  Undo Command (Full Menus Only)
  9262.  
  9263.    The Undo command on the Edit menu reverses any changes made to the current
  9264.    line. Once the cursor moves off the line, however, Undo cannot restore the
  9265.    line to its previous state.
  9266.  
  9267.    Undo works on the current line immediately after you make changes to it.
  9268.    Choosing Undo on an unaltered line has no effect.
  9269.  
  9270.    ──────────────────────────────────────────────────────────────────────────
  9271.    NOTE
  9272.      Undo cannot restore text deleted with CTRL+Y, which removes an entire
  9273.      line. However, a copy of the line is placed on the Clipboard, so you can
  9274.      restore it with the Paste command.
  9275.    ──────────────────────────────────────────────────────────────────────────
  9276.  
  9277.    Shortcut Key
  9278.  
  9279.    ALT+BKSP
  9280.  
  9281.  
  9282.  13.3  Cut Command
  9283.  
  9284.    The Cut command removes selected text from the screen and places it on the
  9285.    Clipboard. When no text is selected, the Cut command is not available.
  9286.  
  9287.    Use Cut and Paste together to relocate lines or blocks of text as follows:
  9288.  
  9289.    1. Select the text you wish to move (it may be as many lines as you wish).
  9290.  
  9291.    2. Choose the Cut command from the Edit menu.
  9292.  
  9293.    3. Move the cursor to the point where you wish to insert the text.
  9294.  
  9295.    4. Choose the Paste command from the Edit menu.
  9296.  
  9297.    You can use this sequence to move entire blocks of a program from one
  9298.    section to another, reducing the time it takes you to write new programs.
  9299.  
  9300.    ──────────────────────────────────────────────────────────────────────────
  9301.    NOTE
  9302.      The Clipboard contains only the most recently cut or copied text.
  9303.    ──────────────────────────────────────────────────────────────────────────
  9304.  
  9305.    Shortcut Key
  9306.  
  9307.    SHIFT+DEL
  9308.  
  9309.    See Also
  9310.  
  9311.    Section 13.4, "Copy Command"; Section 13.5, "Paste Command"; Section
  9312.    13.6, "Clear Command"
  9313.  
  9314.  
  9315.  13.4  Copy Command
  9316.  
  9317.    The Copy command places a copy of selected text on the Clipboard, leaving
  9318.    the original text unchanged. Copying replaces any previous contents on the
  9319.    Clipboard.
  9320.  
  9321.    Use the Copy and Paste commands together to duplicate sections or lines of
  9322.    program code. For example, you can use the following sequence to speed the
  9323.    creation of similar SUB procedures:
  9324.  
  9325.    1. Select the text you wish to duplicate (it may be as many lines as you
  9326.       wish).
  9327.  
  9328.    2. Choose the Copy command from the Edit menu.
  9329.  
  9330.    3. Move the cursor to the point at which you wish to insert the text.
  9331.  
  9332.    4. Choose the Paste command from the Edit menu.
  9333.  
  9334.    5. Customize the copied text for a new line, procedure or section of
  9335.       program text.
  9336.  
  9337.    ──────────────────────────────────────────────────────────────────────────
  9338.    NOTE
  9339.      The Clipboard contains only the most recently cut or copied text.
  9340.    ──────────────────────────────────────────────────────────────────────────
  9341.  
  9342.    Shortcut Key
  9343.  
  9344.    CTRL+INS
  9345.  
  9346.    See Also
  9347.  
  9348.    Section 13.3, "Cut Command"; Section 13.5, "Paste Command"
  9349.  
  9350.  
  9351.  13.5  Paste Command
  9352.  
  9353.    The Paste command inserts a copy of the Clipboard's contents to the right
  9354.    of the cursor.
  9355.  
  9356.    Paste works only when the Clipboard contains text. If you have text
  9357.    selected, the Paste command replaces the selected text with the contents
  9358.    of the Clipboard. If no text is selected, Paste inserts the contents of
  9359.    the Clipboard to the right of the cursor, or above the cursor if the
  9360.    Clipboard contents exceed one line.
  9361.  
  9362.    Shortcut Key
  9363.  
  9364.    SHIFT+INS
  9365.  
  9366.    See Also
  9367.  
  9368.    Section 13.3, "Cut Command"; Section 13.4, "Copy Command"
  9369.  
  9370.  
  9371.  13.6  Clear Command (Full Menus Only)
  9372.  
  9373.    The Clear command completely removes selected text from your file.
  9374.  
  9375.    Cleared text is not transferred onto the Clipboard and cannot be replaced
  9376.    by using the Paste command. Pressing the DEL key without text selected
  9377.    removes the character to the right of the cursor.
  9378.  
  9379.    ──────────────────────────────────────────────────────────────────────────
  9380.    WARNING
  9381.      Use the Clear command with care; you can restore cleared text only by
  9382.      using the Undo command immediately.
  9383.    ──────────────────────────────────────────────────────────────────────────
  9384.  
  9385.    Shortcut Key
  9386.  
  9387.    DEL
  9388.  
  9389.    See Also
  9390.  
  9391.    Section 13.2, "Undo Command"; Section 13.3, "Cut Command"
  9392.  
  9393.  
  9394.  13.7  New SUB Command (Full Menus Only)
  9395.  
  9396.    The Edit menu's New SUB command creates and names a new SUB procedure as
  9397.    part of the module in the active window. The next time you save your
  9398.    program, all new procedures are added to the program's module.
  9399.  
  9400.    SUB procedures can be defined in the main module or other modules, and can
  9401.    be moved from one module to another by using the SUBs command from the
  9402.    View menu.
  9403.  
  9404.    Use SUB procedures for repetitive operations, including ones which
  9405.    manipulate information (arguments) you give the SUB. For example, you
  9406.    might define a SUB procedure CenterText, which centers text on the screen.
  9407.    If you enter the following line in your program:
  9408.  
  9409.    CALL CenterText("Hourly wage")
  9410.  
  9411.    the phrase Hourly wage appears in the center of your screen (the actual
  9412.    SUB code is omitted here).
  9413.  
  9414.    ──────────────────────────────────────────────────────────────────────────
  9415.    IMPORTANT
  9416.      A procedure name can appear only once in a program. An error occurs if
  9417.      the same name appears more than once.
  9418.    ──────────────────────────────────────────────────────────────────────────
  9419.  
  9420.    See Also
  9421.  
  9422.    Chapter 5, "The QCARDS Program," in this manual; Chapter 2, "SUB and
  9423.    FUNCTION Procedures," in Programming in BASIC.
  9424.  
  9425.  13.7.1  Creating a New SUB Procedure
  9426.  
  9427.    Create a new SUB procedure by following these steps:
  9428.  
  9429.    1. Choose New SUB from the Edit menu. A dialog box appears.
  9430.  
  9431.    2. Type the name for the new SUB procedure in the text box, as shown in
  9432.       Figure 13.1.
  9433.  
  9434.  
  9435.          New SUB name
  9436.                 │
  9437.       ┌─────────┼── New SUB ─────────────┐
  9438.       │       ┌─┼──────────────────────┐ │
  9439.       │ Name: │Initvar                 │ │
  9440.       │       └────────────────────────┘ │
  9441.       │                                  │
  9442.       ├──────────────────────────────────┤
  9443.       │  < OK >   < Cancel >   < Help >  │
  9444.       └──────────────────────────────────┘
  9445.  
  9446.       Figure 13.1  New SUB Dialog Box
  9447.  
  9448.    3. Press ENTER.
  9449.  
  9450.    The New SUB command opens a new window with the SUB and END SUB statements
  9451.    already in place, ready for you to enter the procedure. When you complete
  9452.    the procedure, use the SUBs command from the View menu to return to the
  9453.    module-level code, another procedure, or another module.
  9454.  
  9455.    Note that if you type SUB subname, QuickBASIC starts the procedure
  9456.    immediately, bypassing the need to open the menu or dialog box.
  9457.  
  9458.    When you start a new "procedure" (the collective term for SUB and FUNCTION
  9459.    procedures) either by typing SUB or FUNCTION followed by the procedure
  9460.    name or by using the New SUB or New FUNCTION command from the Edit Menu,
  9461.    QuickBASIC displays the procedure in the View window.
  9462.  
  9463.  13.7.2  Default Data Types for Procedures
  9464.  
  9465.    Data type, determined by a DEFtype statement, refers to the type of data a
  9466.    particular range of names will have. The DEFtype statement is a generic
  9467.    term that collectively refers to the data definition statements DEFINT
  9468.    (define integer), DEFSNG (define single precision), DEFDBL (define double
  9469.    precision), DEFLNG (define long integer), and DEFSTR (define string). A
  9470.    range of letters follows the DEFtype statement, indicating the range of
  9471.    names affected by the DEFtype statement. For example, DEFDBL M-Q defines
  9472.    all variables with names beginning with letters in the range M-Q to be
  9473.    double precision.
  9474.  
  9475.    In a new procedure, QuickBASIC automatically inserts a DEFtype statement
  9476.    at the top of the View window, ahead of the line containing the SUB
  9477.    keyword:
  9478.  
  9479.    DEFtype letter1-letter2
  9480.    SUB SubName
  9481.    END SUB
  9482.  
  9483.    or
  9484.  
  9485.    DEFtype letter1-letter2
  9486.    FUNCTION FunctionName
  9487.    END FUNCTION
  9488.  
  9489.    In the preceding example, letter1 and letter2 indicate the letter range
  9490.    the DEFtype statement affects. Note that you may omit letter2 if you want
  9491.    to define only a single letter as a specific data type.
  9492.  
  9493.    Which DEFtype is automatically added to the procedure depends on whether
  9494.    there are DEFtype statements at the module level. If there are no DEFtype
  9495.    statements in the main module, QuickBASIC creates the procedure without a
  9496.    DEFtype statement, and the new procedure defaults all variables to single
  9497.    precision. If there are one or more DEFtype statements at the module
  9498.    level, QuickBASIC includes all DEFtype statements other than DEFSNG in the
  9499.    new procedure. Any variable that falls outside of the letter range
  9500.    indicated by any of the other DEFtype statements defaults to single
  9501.    precision.
  9502.  
  9503.  13.7.3  Changing a Procedure's Default Type
  9504.  
  9505.    If QuickBASIC inserts a DEFtype statement you do not want, you can remove
  9506.    it (in which case the default for that procedure becomes single
  9507.    precision), or you can change it by overtyping.
  9508.  
  9509.    When you have no DEFtype statements in your main module, QuickBASIC omits
  9510.    the DEFtype statement in new procedures (and procedure variables default
  9511.    to single precision). You can add new DEFtype statements to the procedure
  9512.    by placing them in front of the SUB or FUNCTION statement (in insert mode)
  9513.    and pressing ENTER.
  9514.  
  9515.  13.7.4  Saving and Naming Procedures
  9516.  
  9517.    When you save a program, QuickBASIC creates a declaration for each
  9518.    procedure at the beginning of the module containing the procedure. A
  9519.    declaration consists of the DECLARE keyword, followed by the SUB or
  9520.    FUNCTION keyword, then the name of the procedure, and a list of its formal
  9521.    parameters.
  9522.  
  9523.    Procedures are not saved as independent files the way modules are.
  9524.    Therefore procedure names are governed by the naming conventions of
  9525.    QuickBASIC rather than DOS. They are saved within the module in which they
  9526.    are created, or to which they are moved.
  9527.  
  9528.    The rules for naming procedures are the same as those for naming
  9529.    variables. Procedure names can be any valid BASIC name up to 40 characters
  9530.    long. They must be unique. If you give a procedure the same name as a
  9531.    variable, the error message Duplicate definition appears.
  9532.  
  9533.    See Also
  9534.  
  9535.    Section 13.8, "New FUNCTION Command"; Section 14.1, "SUBs Command"
  9536.  
  9537.  
  9538.  13.8  New FUNCTION Command (Full Menus Only)
  9539.  
  9540.    The New FUNCTION command defines (creates and names) a new FUNCTION
  9541.    procedure as a part of the module or program in the active window. When
  9542.    you save the module, any new procedures become part of that module.
  9543.  
  9544.    Create your own FUNCTION procedures whenever you repeatedly calculate
  9545.    similar quantities. For example, you might define a FUNCTION procedure
  9546.    Volume (X) that calculates the volume of a sphere of radius X. Your
  9547.    program then finds the volume of a sphere of any radius very easily:
  9548.  
  9549.    SphereVol = Volume (rad)   ' find volume of a sphere of
  9550.                               ' radius rad
  9551.  
  9552.    QuickBASIC sets the value of X equal to rad when it calculates the volume
  9553.    of the sphere. If you need to calculate the volume of a sphere several
  9554.    times, such a FUNCTION procedure could save you space, time, and debugging
  9555.    efforts.
  9556.  
  9557.    ──────────────────────────────────────────────────────────────────────────
  9558.    IMPORTANT
  9559.      A procedure name can appear only once in a program. An error occurs if
  9560.      the same name appears more than once.
  9561.    ──────────────────────────────────────────────────────────────────────────
  9562.  
  9563.    You can define a new FUNCTION procedure by following these steps:
  9564.  
  9565.    1. Choose New FUNCTION from the Edit menu. A dialog box appears.
  9566.  
  9567.    2. Type the name for the new FUNCTION procedure in the text box. See
  9568.       Figure 13.2.
  9569.  
  9570.  
  9571.          New FUNCTION name
  9572.                 │
  9573.       ┌─────────┼ New FUNCTION ──────────┐
  9574.       │       ┌─┼──────────────────────┐ │
  9575.       │ Name: │Cube                    │ │
  9576.       │       └────────────────────────┘ │
  9577.       │                                  │
  9578.       ├──────────────────────────────────┤
  9579.       │  < OK >   < Cancel >   < Help >  │
  9580.       └──────────────────────────────────┘
  9581.  
  9582.       Figure 13.2  New FUNCTION Dialog Box
  9583.  
  9584.    3. Press ENTER.
  9585.  
  9586.    QuickBASIC opens a new window with the FUNCTION and END FUNCTION
  9587.    statements already in place. When you complete the FUNCTION procedure, use
  9588.    the SUBs command from the View menu to return to the previous module.
  9589.  
  9590.    Keyboard Shortcut
  9591.  
  9592.    Type FUNCTION followed by the name of the new procedure to perform steps
  9593.    1-3 in the previous list automatically.
  9594.  
  9595.    See Also
  9596.  
  9597.    Chapter 5, "The QCARDS Program"; Section 13.7.2, "Default Data Types for
  9598.    Procedures"; Section 13.7.3, "Changing a Procedure's Default Type";
  9599.    Section 13.7.4, "Saving and Naming Procedures"; Section 14.1, "SUBs
  9600.    Command." Also see Chapter 2, "SUB and FUNCTIONS Procedures," in
  9601.    Programming in BASIC."
  9602.  
  9603.  
  9604.  
  9605.  ────────────────────────────────────────────────────────────────────────────
  9606.  Chapter 14  The View Menu
  9607.  
  9608.    The View menu gives the available options for viewing program components.
  9609.    You also use the View menu to move SUB and FUNCTION procedures, modules,
  9610.    include files, and document files in and out of the View window for
  9611.    viewing and editing.
  9612.  
  9613.    The View menu includes the following commands:
  9614.  
  9615.    ■ SUBs. Moves procedures, modules, include files, and document files into
  9616.      and out of windows and moves procedures among modules.
  9617.  
  9618.    ■ Next SUB. Places the next procedure (alphabetical by name) in the active
  9619.      window (Full Menus only).
  9620.  
  9621.    ■ Split. Divides the View window horizontally (Full Menus only).
  9622.  
  9623.    ■ Next Statement. Moves the cursor to the next statement to be executed
  9624.      (Full Menus only).
  9625.  
  9626.    ■ Output Screen. Toggles the screen display between the program output and
  9627.      the QuickBASIC editor.
  9628.  
  9629.    ■ Included File. Loads referenced include files for viewing and editing
  9630.      (Full Menus only).
  9631.  
  9632.    ■ Included Lines. Displays the contents of referenced include files for
  9633.      viewing only.
  9634.  
  9635.  
  9636.  14.1  SUBs Command
  9637.  
  9638.    The SUBs command lets you select among the currently loaded files, their
  9639.    procedures (SUB and FUNCTION), include files, and document files. When you
  9640.    choose a file or procedure, QuickBASIC displays it in the View window.
  9641.  
  9642.    The SUBs dialog box controls file and procedure handling.
  9643.  
  9644.    To use the SUBs command, follow these steps:
  9645.  
  9646.    1. Choose the SUBs command from the View menu. The SUBs dialog box
  9647.       appears, as shown in Figure 14.1.
  9648.  
  9649.  
  9650.       Procedures are indented       Modules are listed       Retains active wi
  9651.       beneath their modules         in uppercase letters     and places select
  9652.        │                              │                      item in new windo
  9653.        │                              │                         │
  9654.       ┌┼──────────────────────────────┼── SUBs ─────────────────┼─────────────
  9655.       ││                              │                         │
  9656.       ││Choose program item to edit   │                         │
  9657.       ││┌─────────────────────────────┼─────────────────────────┼─────────────
  9658.       │││ DEMO1.BAS             ──────┤                         │
  9659.       │││ DEMO2.BAS ──────────────────┤                         │
  9660.       │││  ┌Bounce                    │                         │
  9661.       │└┼──┤Fall                      │                         │
  9662.       │ │  │Klaxon                    │                         │
  9663.       │ │  └Siren                     │                         │
  9664.       │ │ TEST.BAS ───────────────────┘                         │
  9665.       │ │                                                       │
  9666.       │ │                                                       │
  9667.       │ └▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│▒▒▒▒▒▒▒▒▒▒▒▒▒
  9668.       │┌DEMO1.BAS is the Main Module                            │
  9669.       ││                                                        │
  9670.       ││  < Edit in Active >           < Edit in Split > ───────┘   < Cancel >
  9671.       ├┼──────────────────────────────────────────────────────────────────────
  9672.       ││    < Delete >──┐                   < Move >              ┌──< Help >
  9673.       └┼────────────────┼──────────────────────┼──────────────────┼───────────
  9674.        │                │                      │                  │
  9675.       Describes       Unloads a module     Places procedure     Moves procedur
  9676.       item in         from memory or       in active window     from one modul
  9677.       highlighted
  9678.       box
  9679.  
  9680.       Figure 14.1  New SUBs Dialog Box
  9681.  
  9682.    2. Highlight the module, procedure, or include file you want to work with
  9683.       by pressing the DIRECTION keys. Then you can do one of the following:
  9684.  
  9685.      ■ Choose the Edit in Active button to place your selection in the active
  9686.        window.
  9687.  
  9688.      ■ Choose the Edit in Split button to split the window horizontally; the
  9689.        lower (active) window displays the new selection and the upper window
  9690.        contains the contents of the previous window. Use F6 to cycle down
  9691.        through the windows or SHIFT+F6 to cycle up. To close the extra window
  9692.        choose the Split command from the View menu again.
  9693.  
  9694.      ■ Choose the Move button to move the selected procedure to a different
  9695.        module. A dialog box appears with a list of destination modules. See
  9696.        Figure 14.2. (Moving a procedure in a single-module program has no
  9697.        effect.)
  9698.  
  9699.  
  9700.        Current destination module
  9701.         │
  9702.        ┌┼─────────────────────────────────┐
  9703.        ││ Choose destination module:      │
  9704.        ││ ┌────────────────────────────┐  │
  9705.        ││ │ DEMO1.BAS                    │
  9706.        │└─┼ TORUS.BAS                  ▒  │
  9707.        │  │                            ▒  │
  9708.        │  │                            ▒  │
  9709.        │  │                            ▒  │
  9710.        │  │                              │
  9711.        │  └────────────────────────────┘  │
  9712.        │                                  │
  9713.        ├──────────────────────────────────┤
  9714.        │  < OK >   < Cancel >   < Help >  │
  9715.        └──────────────────────────────────┘
  9716.  
  9717.        Figure 14.2  Move Dialog Box
  9718.  
  9719.      ■ Choose the Delete button to remove the selected procedure completely
  9720.        from the module. (Note that deleting a module removes that module and
  9721.        all of its associated procedures from memory but keeps the module on
  9722.        disk.)
  9723.  
  9724.      ■ Choose Cancel to return to the previous active window.
  9725.  
  9726.      ■ Choose Help for more information on using the SUBs dialog box.
  9727.  
  9728.    You are now ready to work with the module, procedure, or include file you
  9729.    selected.
  9730.  
  9731.    Shortcut Key
  9732.  
  9733.    F2
  9734.  
  9735.    See Also
  9736.  
  9737.    Section 11.9, "Unload File Command"; Section 14.2, "Next SUB Command";
  9738.    Section 16.7, "Set Main Module Command"
  9739.  
  9740.  
  9741.  14.2  Next SUB Command (Full Menus Only)
  9742.  
  9743.    The Next SUB command displays the contents of the next procedure
  9744.    (alphabetically by name) in the active window. If the current module
  9745.    contains no procedures, choosing Next SUB has no effect. You may cycle
  9746.    either forward to the next procedure of backward to the previous one.
  9747.  
  9748.    Next SUB is of particular value when working with modules that contain
  9749.    only a few procedures. For programs with many procedures, the SUBs command
  9750.    is generally faster for moving between program parts.
  9751.  
  9752.    Shortcut Keys
  9753.  
  9754.    SHIFT+F2 (forward) and CTRL+F2 (backward)
  9755.  
  9756.    See Also
  9757.  
  9758.    Section 14.1, "SUBs Command"
  9759.  
  9760.  
  9761.  14.3  Split Command (Full Menus Only)
  9762.  
  9763.    The Split command divides the View window horizontally, allowing you to
  9764.    work with two parts of a program simultaneously.
  9765.  
  9766.    To use the Split command follow these steps:
  9767.  
  9768.    1. Choose Split from the View menu.
  9769.  
  9770.    2. Press F6 to cycle down through the windows, making the different
  9771.       windows active, or SHIFT+F6 to cycle up through the windows.
  9772.  
  9773.    3. Choose Split again to fill the screen with the active window and close
  9774.       the inactive window.
  9775.  
  9776.    You can increase or decrease the size of a window or expand it to fill the
  9777.    entire screen. To change the size of a window, make it the active window
  9778.    and use the following key combinations (use the PLUS and MINUS keys on the
  9779.    numeric keypad):
  9780.  
  9781.    Key Combination          Result
  9782.    ──────────────────────────────────────────────────────────────────────────
  9783.    ALT+PLUS (+)             Expands the active window one line.
  9784.  
  9785.    ALT+MINUS (-)            Shrinks the active window one line.
  9786.  
  9787.    CTRL+F10                 Expands the active window to fill the screen. If
  9788.                             it already fills the screen, the window is
  9789.                             returned to its former size.
  9790.    ──────────────────────────────────────────────────────────────────────────
  9791.  
  9792.    See Also
  9793.  
  9794.    Chapter 10, "Getting Around in QuickBASIC"; Section 14.1, "SUBs Command"
  9795.  
  9796.  
  9797.  14.4  Next Statement Command (Full Menus Only)
  9798.  
  9799.    The Next Statement command places the cursor at the next statement to be
  9800.    executed but does not execute the statement.
  9801.  
  9802.    The Next Statement command is typically used after pausing a program for
  9803.    debugging purposes; it allows you to see which statement the Continue
  9804.    command will execute first when you choose it. Next Statement is useful
  9805.    after moving around in a suspended program to return to the original point
  9806.    of suspension.
  9807.  
  9808.    See Also
  9809.  
  9810.    Section 15.1, "Find Command"; Section 16.3, "Continue Command"; Chapter
  9811.    18, "The Debug Menu"
  9812.  
  9813.  
  9814.  14.5  Output Screen Command
  9815.  
  9816.    The Output Screen command causes QuickBASIC to switch between the
  9817.    environment and output screens created by your program.
  9818.  
  9819.    This command is functional at any time during editing, but is most useful
  9820.    after the program sends data to the screen. For example, when you run a
  9821.    program that has screen output, QuickBASIC prints the message
  9822.  
  9823.    Press any key to continue
  9824.  
  9825.    on the bottom of the output screen when the program ends. After returning
  9826.    to the QuickBASIC editor, you can switch back and forth between the editor
  9827.    and output screens by choosing the Output Screen command. This allows you
  9828.    to refer to previous output while editing or debugging your program.
  9829.  
  9830.    Shortcut Key
  9831.  
  9832.    F4
  9833.  
  9834.  
  9835.  14.6  Included File Command (Full Menus Only)
  9836.  
  9837.    The Included File command loads a file referenced with the $INCLUDE
  9838.    metacommand for viewing and editing.
  9839.  
  9840.    When the cursor is on a $INCLUDE metacommand line, choosing the Included
  9841.    File command loads the text of the include file into the active window for
  9842.    editing. QuickBASIC keeps the text of include files separate from the rest
  9843.    of the program text. This is similar to the way in which the text of SUB
  9844.    or FUNCTION procedures is separated from other program text. However,
  9845.    QuickBASIC considers an include file separate from the rest of the
  9846.    program.
  9847.  
  9848.    You may wish to edit an include file without moving the cursor from the
  9849.    line in your program containing the $INCLUDE metacommand. To do so, follow
  9850.    these steps:
  9851.  
  9852.    1. Split the screen with the Split command from the View menu.
  9853.  
  9854.    2. Choose the Load File command from the File menu to load the include
  9855.       file. Be sure to select the Include option.
  9856.  
  9857.    3. Edit the include file.
  9858.  
  9859.    4. Choose Save from the File menu to save any changes made to the include
  9860.       file.
  9861.  
  9862.    5. Press F6 to move back to the program in the other View window.
  9863.  
  9864.    6. Choose the View menu's Split command again to close the extra window.
  9865.  
  9866.    Save the include file to incorporate your changes. QuickBASIC prompts you
  9867.    if you forget.
  9868.  
  9869.  14.6.1  Nesting Include Files
  9870.  
  9871.    You can have any number of $INCLUDE metacommands in a program. However,
  9872.    the "nesting" of include files is limited.
  9873.  
  9874.    Nesting occurs when a $INCLUDE metacommand appears within another include
  9875.    file. Include files can be nested up to five levels. If you have a
  9876.    circular reference in an include file (that is, a $INCLUDE metacommand
  9877.    that references itself or a file in which it is referenced), you get the
  9878.    error message Too many files when you try to run your program.
  9879.  
  9880.  14.6.2  Finding Include Files
  9881.  
  9882.    When QuickBASIC processes a $INCLUDE metacommand, it searches first for
  9883.    the include file in any directory specified in the metacommand, then the
  9884.    working directory, and finally any include-file directory indicated by the
  9885.    Set Paths command. If you refer to a directory in the $INCLUDE metacommand
  9886.    itself, you need to include a full or relative path name. For example, the
  9887.    following directs QuickBASIC to look for the include file named
  9888.    declares.bi in the directory c:include:
  9889.  
  9890.    ' $INCLUDE: 'C:includedeclares.bi'
  9891.  
  9892.    This could also be specified with a relative path, as in the following
  9893.    line:
  9894.  
  9895.    ' $INCLUDE: '..includedeclares.bi'
  9896.  
  9897.    Although any extension, including .BAS, is legal for files incorporated
  9898.    into your program with the $INCLUDE metacommand, it is recommended that
  9899.    include files use some unique extension (such as .BI) to avoid confusion
  9900.    with program modules.
  9901.  
  9902.    See Also
  9903.  
  9904.    Section 14.7, "Included Lines Command"; Section 20.2, "Set Paths
  9905.    Command"
  9906.  
  9907.  
  9908.  14.7  Included Lines Command
  9909.  
  9910.    The Included Lines command lets you view, but not edit, the contents of
  9911.    referenced include files. This command is a toggle; a bullet (■) appears
  9912.    next to the option when it is on. Choosing it again turns it off.
  9913.  
  9914.    The Included Lines command lets you look at the include file's contents,
  9915.    which appear in high-intensity video beneath the appropriate $INCLUDE
  9916.    metacommand. Although you can scroll around in the include file after
  9917.    choosing Included Lines, you cannot edit the include file as long as this
  9918.    option is on. If you try to edit the include file while Included Lines is
  9919.    on, a dialog box appears and asks if you want to edit the include file. If
  9920.    you do, QuickBASIC loads the file into memory and places its text in the
  9921.    active View window.
  9922.  
  9923.    If you try to edit the program file while the Included Lines command is
  9924.    on, a dialog box appears asking if you want to turn the Included Lines
  9925.    command off. If you press ENTER, the include file disappears, and you can
  9926.    then edit the source file in the usual way.
  9927.  
  9928.    For editing files referenced with the $INCLUDE metacommand, use the
  9929.    Included File command or the Load File command on the File menu (remember
  9930.    to choose the Include option).
  9931.  
  9932.    See Also
  9933.  
  9934.    Section 14.6, "Included File Command"
  9935.  
  9936.  
  9937.  
  9938.  ────────────────────────────────────────────────────────────────────────────
  9939.  Chapter 15  The Search Menu
  9940.  
  9941.    The Search menu lets you find specific text──"target" text──anywhere in a
  9942.    program, and replaces it with new text. The Search menu has several uses,
  9943.    particularly in long or complex programs. For instance, to move quickly to
  9944.    a distant part of your program, you can search for a line label or other
  9945.    identifying text you know to be in that section.
  9946.  
  9947.    The Search menu has the following commands:
  9948.  
  9949.    ■ Find. Searches for and locates the nearest occurrence of designated
  9950.      text.
  9951.  
  9952.    ■ Selected Text. Searches for text that matches the currently highlighted
  9953.      text (Full Menus only).
  9954.  
  9955.    ■ Repeat Last Find. Locates the next occurrence of the text specified in
  9956.      the previous search (Full Menus only).
  9957.  
  9958.    ■ Change. Searches for and then replaces target text with new text.
  9959.  
  9960.    ■ Label. Searches for a specified line label (Full Menus only).
  9961.  
  9962.  
  9963.  15.1  Defining Target Text
  9964.  
  9965.    Search procedures require you to specify your target text──the text you
  9966.    want to search for. QuickBASIC uses several methods to specify target
  9967.    text. The word containing the cursor or closest to the left of the cursor
  9968.    becomes the default target text. If the cursor is on a blank line, the
  9969.    target text from the previous search becomes the default. You can alter
  9970.    default target text by typing new text in the Find or Change dialog boxes.
  9971.  
  9972.    All searches begin at the cursor and move forward. If QuickBASIC reaches
  9973.    the end of the active window without finding a match, it returns to the
  9974.    top of the document and continues the search until it either locates the
  9975.    text or reaches the original cursor location. You can also select options
  9976.    that extend the search to the entire current module or all modules loaded.
  9977.  
  9978.  
  9979.  15.2  Find Command
  9980.  
  9981.    The Find command searches for and places the cursor on specified text. The
  9982.    text may consist of a single character, a word, or any combination of
  9983.    words and characters.
  9984.  
  9985.    Enter the text you want to find in the text box of the Find dialog box,
  9986.    shown in Figure 15.1.
  9987.  
  9988.  
  9989.              Text to find
  9990.                   │
  9991.    ┌──────────────┼────────────── Find ────────────────────────────┐
  9992.    │            ┌─┼────────────────────────────────────────────┐   │
  9993.    │ Find What: │sum                                           │   │
  9994.    │            └──────────────────────────────────────────────┘   │
  9995.    │                                                               │
  9996.    │ ┌                               ┌─────────────────────────┐   │
  9997.    │┌┤[ ] Match Upper/Lowercase      │ ( ) 1. Active Window ─┐ │   │
  9998.    │││[ ] Whole Word                 │ (∙) 2. Current Module ├─┼─┐ │
  9999.    ││└                               │ ( ) 3. All Modules   ─┘ │ │ │
  10000.    ││                                └─────────────────────────┘ │ │
  10001.    ├┼────────────────────────────────────────────────────────────┼─┤
  10002.    ││        < OK >         < Cancel >         < Help >          │ │
  10003.    └┼────────────────────────────────────────────────────────────┼─┘
  10004.     │                                                            │
  10005.    Search restrictions                                 Search options
  10006.  
  10007.    Figure 15.1  Find Dialog Box
  10008.  
  10009.    The dialog box also controls the extent of the search (whether the search
  10010.    includes the active window, the current module, or all files currently
  10011.    loaded in QuickBASIC) and any restrictions on the search.
  10012.  
  10013.    To perform a search, do the following:
  10014.  
  10015.    1. Choose Find from the Search menu. A dialog box appears.
  10016.  
  10017.    2. Enter the text you want to find in the Find What text box. (Any default
  10018.       target text appears highlighted.)
  10019.  
  10020.    3. Select any search option buttons by pressing the TAB and DIRECTION
  10021.       keys. (See Table 15.1 for a list of available options.)
  10022.  
  10023.    4. Set any restrictions by pressing the TAB key to select the option and
  10024.       SPACEBAR to turn the option on or off. (See Table 15.2 for a list of
  10025.       restrictions.)
  10026.  
  10027.    5. Press ENTER to begin the search.
  10028.  
  10029.    If it cannot locate the target text, QuickBASIC displays the message Match
  10030.    not found and leaves the cursor where it was when you started the search.
  10031.  
  10032.    Press ENTER or ESC to remove the message and continue.
  10033.  
  10034.    The options available with search commands are listed in the following
  10035.    table:
  10036.  
  10037.    Table 15.1  Search Options
  10038.    Option                   Description
  10039.    ──────────────────────────────────────────────────────────────────────────
  10040.    Active Window            Searches only in the current, active window
  10041.  
  10042.    Current Module           Searches only in the current module (including
  10043.                             procedures)
  10044.  
  10045.    All Modules              Searches all parts of all loaded files
  10046.    ──────────────────────────────────────────────────────────────────────────
  10047.  
  10048.    The following table lists the restrictions you can set with the Find
  10049.    command:
  10050.  
  10051.    Table 15.2  Search Restrictions
  10052.    Restriction              Description
  10053.    ──────────────────────────────────────────────────────────────────────────
  10054.    Match Upper/Lowercase    Searches for text that matches exactly. For
  10055.                             example, if CHR is the specified text, the Match
  10056.                             Upper/Lowercase option finds CHR but not Chr.
  10057.  
  10058.    Whole Word               Locates the target as a separate word. Whole
  10059.                             words include words surrounded by spaces,
  10060.                             punctuation marks, or other characters not
  10061.                             considered parts of words. Word parts include
  10062.                             A$MIZ, a$MIz, 0$MI9, and !, #, $, %, and &
  10063.                             (commonly used in declarations). For example, a
  10064.                             whole word search for CHR would locate CHR: but
  10065.                             not CHR$ or CHARACTER.
  10066.    ──────────────────────────────────────────────────────────────────────────
  10067.  
  10068.    See Also
  10069.  
  10070.    Section 15.5, "Change Command"
  10071.  
  10072.  
  10073.  15.3  Selected Text Command (Full Menus Only)
  10074.  
  10075.    The Selected Text command on the Search menu searches for text that
  10076.    matches text selected in the active window.
  10077.  
  10078.    Follow these steps to use the Selected Text command:
  10079.  
  10080.    1. Select the text you want to find. The text must fit on one line (256
  10081.       characters).
  10082.  
  10083.    2. Choose the Selected Text command from the Search Menu.
  10084.  
  10085.    QuickBASIC highlights the next occurrence of the selected text and puts
  10086.    the cursor at the first character of the string. If there are no other
  10087.    occurrences, the screen remains the same.
  10088.  
  10089.    Shortcut Key
  10090.  
  10091.    CTRL +<FS>
  10092.  
  10093.    See Also
  10094.  
  10095.    Section 15.2, "Find Command"
  10096.  
  10097.  
  10098.  15.4  Repeat Last Find Command (Full Menus Only)
  10099.  
  10100.    The Repeat Last Find command searches for the next occurrence of the text
  10101.    specified in the last search. Text specified in the previous Find or
  10102.    Change command becomes the target text of a Repeat Last Find search.
  10103.  
  10104.    If you have not used the Find or Change commands and you choose the Repeat
  10105.    Last Find command, QuickBASIC uses the word containing the cursor, or the
  10106.    word nearest to the left of the cursor, as the default target text.
  10107.  
  10108.    Shortcut Key
  10109.  
  10110.    F3
  10111.  
  10112.    See Also
  10113.  
  10114.    Section 15.2, "Find Command"
  10115.  
  10116.  
  10117.  15.5  Change Command
  10118.  
  10119.    The Change command searches for one text string and replaces it with
  10120.    another. Either string may consist of a single character, a single word,
  10121.    or any combination of words and characters.
  10122.  
  10123.    Use the Change dialog box, shown in Figure 15.2, to enter the target
  10124.    text, the replacement text, and search attributes and restrictions.
  10125.  
  10126.  
  10127.          Text to change   Replacement text
  10128.                       │   │
  10129.    ┌──────────────────┼───┼───── Change ───────────────────────────┐
  10130.    │            ┌─────┼───┼────────────────────────────────────┐   │
  10131.    │ Find What: │sum ─┘   │                                    │   │
  10132.    │            └─────────┼────────────────────────────────────┘   │
  10133.    │            ┌─────────┼────────────────────────────────────┐   │
  10134.    │ Change To: │total ───┘                                    │   │
  10135.    │            └──────────────────────────────────────────────┘   │
  10136.    │                                                               │
  10137.    │ ┌                               ┌─────────────────────────┐   │
  10138.    │┌┤[ ] Match Upper/Lowercase      │ ( ) 1. Active Window ─┐ │   │
  10139.    │││[ ] Whole Word                 │ (∙) 2. Current Module ├─┼─┐ │
  10140.    ││└                               │ ( ) 3. All Modules   ─┘ │ │ │
  10141.    ││                                └─────────────────────────┘ │ │
  10142.    ├┼────────────────────────────────────────────────────────────┼─┤
  10143.    ││  < Find and Verify >  < Change All >  < Cancel >  < Help > │ │
  10144.    └┼────────────────────────────────────────────────────────────┼─┘
  10145.     │                                                            │
  10146.    Search restrictions                                 Search options
  10147.  
  10148.    Figure 15.2  Change Dialog Box
  10149.  
  10150.    To change text, do the following:
  10151.  
  10152.    1. Choose Change from the Search menu.
  10153.  
  10154.    2. Type the text you want to replace in the Find What text box.
  10155.  
  10156.    3. Type the replacement text in the Change To text box.
  10157.  
  10158.    4. Select any search options you desire (see Table 15.1).
  10159.  
  10160.    5. Set any search restrictions (see Table 15.2).
  10161.  
  10162.    6. Choose Find and Verify or Change All to begin replacing text, or Cancel
  10163.       to cancel the command.
  10164.  
  10165.       ■ Find and Verify finds the target text, then displays four more
  10166.         buttons: Change, Skip, Cancel, and Help. Change executes the change,
  10167.         Skip searches for the next occurrence (without making any changes),
  10168.         and Cancel stops the search and returns to the point at which the
  10169.         search began. Help provides more information about the Find and
  10170.         Verify dialog box. See Figure 15.3.
  10171.  
  10172.  
  10173.                                       Stops search and
  10174.          Executes the change          returns to active window
  10175.                  │                      │
  10176.         ┌────────┼──────────────────────┼───────────────────┐
  10177.         │        │                      │                   │
  10178.         ├────────┼──────────────────────┼───────────────────┤
  10179.         │   < Change >   < Skip >   < Cancel >   < Help >   │
  10180.         └────────────────────┼───────────────────────┼──────┘
  10181.                              │                       │
  10182.                      Searches for       Provides help on change
  10183.                      next occurrence
  10184.  
  10185.         Figure 15.3  Change, Skip, Cancel Dialog Box
  10186.  
  10187.       ■ Change All finds and replaces all occurrences of the target text
  10188.         without asking for confirmation.
  10189.  
  10190.       ■ Cancel returns control to the active window.
  10191.  
  10192.       ■ If it cannot locate the target text, QuickBASIC displays the message
  10193.  
  10194.         Match not found
  10195.  
  10196.         Press ENTER to remove the message and continue.
  10197.  
  10198.    ──────────────────────────────────────────────────────────────────────────
  10199.    IMPORTANT
  10200.      The Undo command on the Edit menu cannot undo a change made with the
  10201.      Change command. Use particular caution with Change All since this
  10202.      command can drastically alter your program.
  10203.    ──────────────────────────────────────────────────────────────────────────
  10204.  
  10205.    See Also
  10206.  
  10207.    Section 15.2, "Find Command"
  10208.  
  10209.  
  10210.  15.6  Label Command (Full Menus Only)
  10211.  
  10212.    The Label command searches for a line label. Since line labels require a
  10213.    colon, QuickBASIC searches for your text-box entry plus a colon.
  10214.    QuickBASIC searches only for the target text followed by a colon. For
  10215.    example, if you enter mylab as your target text in the Label dialog box,
  10216.    QuickBASIC searches for mylab:
  10217.  
  10218.    The Label dialog box is shown in Figure 15.4.
  10219.  
  10220.  
  10221.                     Name of label
  10222.                         │
  10223.    ┌────────────────────┼────── Label ─────────────────────────────┐
  10224.    │            ┌───────┼──────────────────────────────────────┐   │
  10225.    │ Find What: │MyLab ─┘                                      │   │
  10226.    │            └──────────────────────────────────────────────┘   │
  10227.    │                                                               │
  10228.    │ ┌                               ┌─────────────────────────┐   │
  10229.    │┌┤[ ] Match Upper/Lowercase      │ ( ) 1. Active Window ─┐ │   │
  10230.    │││[X] Whole Word                 │ (∙) 2. Current Module ├─┼─┐ │
  10231.    ││└                               │ ( ) 3. All Modules   ─┘ │ │ │
  10232.    ││                                └─────────────────────────┘ │ │
  10233.    ├┼────────────────────────────────────────────────────────────┼─┤
  10234.    ││       < OK >         < Cancel >         < Help >           │ │
  10235.    └┼────────────────────────────────────────────────────────────┼─┘
  10236.     │                                                            │
  10237.    Search restrictions                                 Search options
  10238.  
  10239.    Figure 15.4  Label Dialog Box
  10240.  
  10241.    See Also
  10242.  
  10243.    Section 15.2, "Find Command"; Section 15.3, "Selected Text Command"
  10244.  
  10245.  
  10246.  
  10247.  ────────────────────────────────────────────────────────────────────────────
  10248.  Chapter 16  The Run Menu
  10249.  
  10250.    The Run menu contains commands that let you control program execution
  10251.    within QuickBASIC, compile stand-alone programs with the BC compiler, and
  10252.    create Quick libraries. This allows you to create and debug your program
  10253.    within QuickBASIC, then compile your running program for greater speed. As
  10254.    stand-alone applications, your programs can be run from the DOS command
  10255.    line──without being loaded into QuickBASIC. You also use the Run menu to
  10256.    define main program modules.
  10257.  
  10258.    The Run menu has the following commands:
  10259.  
  10260.    ■ Start. Runs the currently loaded program from within the QuickBASIC
  10261.      environment.
  10262.  
  10263.    ■ Restart. Resets all variables to zero and all string expressions to
  10264.      zero-length strings, and prepares to execute the first statement in the
  10265.      program.
  10266.  
  10267.    ■ Continue. Resumes execution of a suspended program at the statement
  10268.      where execution was stopped (does not reset variables or expressions).
  10269.  
  10270.    ■ Modify COMMAND$. Accesses the string passed to a program via the
  10271.      COMMAND$ function from the DOS command line (Full Menus only).
  10272.  
  10273.    ■ Make EXE File. Creates an executable file from the currently loaded
  10274.      program.
  10275.  
  10276.    ■ Make Library. Creates a custom Quick library (Full Menus only).
  10277.  
  10278.    ■ Set Main Module. Sets a selected module as the main module (Full Menus
  10279.      only).
  10280.  
  10281.  
  10282.  16.1  Start Command
  10283.  
  10284.    The Start command on the Run menu runs the currently loaded program.
  10285.  
  10286.    Once you start a program you may stop it by pressing CTRL+BREAK. To
  10287.    continue running the program from where you stopped, choose the Continue
  10288.    command from the Run menu. To start from the beginning again, choose
  10289.    Start.
  10290.  
  10291.    ──────────────────────────────────────────────────────────────────────────
  10292.    NOTE
  10293.      If you load a BASICA program, some statements require modification to
  10294.      run properly with QuickBASIC. They are described in Appendix
  10295.      A,"Converting BASICA Programs to QuickBASIC," in Programming in BASIC.
  10296.    ──────────────────────────────────────────────────────────────────────────
  10297.  
  10298.    Shortcut Key
  10299.  
  10300.    SHIFT+F5
  10301.  
  10302.    See Also
  10303.  
  10304.    Section 16.2, "Restart Command"; Section16.3, "Continue Command";
  10305.    Section 16.5, "Make EXE File Command"
  10306.  
  10307.  
  10308.  16.2  Restart Command
  10309.  
  10310.    The Restart command on the Run menu resets all variables to zero and all
  10311.    string expressions to zero-length strings. It prepares your program to
  10312.    run, but does not begin execution. Restart also highlights the first
  10313.    executable statement in your program.
  10314.  
  10315.    Restart is generally used during debugging when you do not want to
  10316.    continue execution. It is especially useful if you want to restart a
  10317.    program from the beginning and step through program code (using the F8
  10318.    key) prior to the first breakpoint or watchpoint. (Breakpoints and
  10319.    watchpoints are devices used to halt program execution. See Section 18.3,
  10320.    "Watchpoint Command," and Section 18.8, "Toggle Breakpoint Command.") If
  10321.    you want to execute to the first breakpoint or watchpoint without stepping
  10322.    through code, use the Start command.
  10323.  
  10324.    To run your program from a specific location without resetting any
  10325.    variables or expressions, use the Continue command on the Run menu or the
  10326.    Set Next Statement command on the Debug menu followed by the Continue
  10327.    command.
  10328.  
  10329.    See Also
  10330.  
  10331.    Section 16.1, "Start Command"; Section 16.3, "Continue Command"; Section
  10332.    18.11, "Set Next Statement Command"
  10333.  
  10334.  
  10335.  16.3  Continue Command
  10336.  
  10337.    The Continue command continues an interrupted program from the last
  10338.    statement executed or starts a program from the beginning.
  10339.  
  10340.    The Continue command is particularly useful for debugging. Use Continue to
  10341.    run a program from one breakpoint or watchpoint to another. When execution
  10342.    stops, you can analyze the code and make any corrections. Once you
  10343.    complete the corrections, choose Continue to execute from that point
  10344.    forward. If you make a change that prevents continuation from the current
  10345.    statement, QuickBASIC stops and asks if you want to continue without the
  10346.    change or if you prefer to include the change and restart the program. (If
  10347.    you do not want to restart, you can frequently use the Immediate window to
  10348.    make temporary changes that will allow the program to continue.)
  10349.  
  10350.    Shortcut Key
  10351.  
  10352.    F5
  10353.  
  10354.    See Also
  10355.  
  10356.    Section 16.1, "Start Command"; Section 16.2, "Restart Command"
  10357.  
  10358.  
  10359.  16.4  Modify COMMAND$ Command (Full Menus Only)
  10360.  
  10361.    The Modify COMMAND$ command is a feature helpful to advanced programmers
  10362.    who want to access text strings passed to their programs from the DOS
  10363.    command line via the COMMAND$ function. You only need the Modify COMMAND$
  10364.    command if your program uses the COMMAND$ function.
  10365.  
  10366.    In some applications, you may wish to pass information from the DOS
  10367.    environment to the application. For example, typing QB DEMO1 lets
  10368.    QuickBASIC know that you wish to work within the program DEMO1 in the
  10369.    QuickBASIC environment. DEMO1 is information that is passed to QuickBASIC
  10370.    from the command line.
  10371.  
  10372.    You can pass information to your program from the DOS command-line using
  10373.    the COMMAND$ function. Memory is cleared every time the program starts,
  10374.    and the information from the DOS command line is lost. In the development
  10375.    and debugging process, you will want to test the program without exiting
  10376.    to DOS each time you alter the program. The Modify COMMAND$ command tells
  10377.    QuickBASIC to substitute what you have entered in the dialog box for the
  10378.    string the COMMAND$ function would normally return.
  10379.  
  10380.    In the Modify COMMAND$ dialog box, you indicate the string to be returned
  10381.    by the COMMAND$ function. See Figure 16.1.
  10382.  
  10383.  
  10384.    ┌───────────────────── Modify COMMAND$ ─────────────────────┐
  10385.    │                                                           │
  10386.    │                Enter text for COMMAND$:                   │
  10387.    │                                                           │
  10388.    │   ┌───────────────────────────────────────────────────┐   │
  10389.    │┌─ │SAMPLE.EXE WHITE GREEN BLUE                        │   │
  10390.    ││  └───────────────────────────────────────────────────┘   │
  10391.    ├┼──────────────────────────────────────────────────────────┤
  10392.    ││      < OK >        < Cancel >        < Help >            │
  10393.    └┼──────────────────────────────────────────────────────────┘
  10394.     │
  10395.    Text the COMMAND$ function will return
  10396.  
  10397.    Figure 16.1  Modify COMMAND$ Dialog Box
  10398.  
  10399.  
  10400.  16.5  Make EXE File Command
  10401.  
  10402.    Once your program runs within QuickBASIC, you can use the Make EXE File
  10403.    command to make a version of the program that runs directly from the DOS
  10404.    command line without being loaded into QuickBASIC. The file for such a
  10405.    program is known as an executable file, and has the extension .EXE.
  10406.    Entering the base name (name with no extension) of an executable file
  10407.    after the DOS prompt runs the program.
  10408.  
  10409.    When you create an executable file, QuickBASIC first uses the BASIC
  10410.    command-line compiler (BC) to compile your BASIC source code into an
  10411.    intermediate file (an object file). QuickBASIC then uses a program called
  10412.    the Microsoft Overlay Linker (LINK) to join all the separately compiled
  10413.    modules of your program into a single executable file. LINK also combines
  10414.    the compiled object files created by BC with the supporting routines your
  10415.    program needs to execute properly. These routines are found in the
  10416.    run-time libraries BRUN45.LIB or BCOM45.LIB.
  10417.  
  10418.  16.5.1  Creating Executable Files
  10419.  
  10420.    The files in the following list must be available to QuickBASIC when you
  10421.    create an executable file. Make sure they are in the current directory or
  10422.    available through your PATH or LIB environment variables. You can also use
  10423.    the Options menu's Set Paths command to tell QuickBASIC where to search
  10424.    for these files. (See Section 20.2, "Set Paths Command," for more
  10425.    information on setting environment variables.)
  10426.  
  10427. ╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
  10428.    Program                  Purpose
  10429.    ──────────────────────────────────────────────────────────────────────────
  10430.    BC.EXE                   Creates linkable object files (files with .OBJ
  10431.                             extensions) from your program.
  10432.  
  10433.    LINK.EXE                 Links the object files created by BC.
  10434.  
  10435.    BRUN45.LIB               Provides supporting routines that allow your
  10436.    (Full Menus only)        BASIC program to perform tasks such as accepting
  10437.                             input or printing text on the screen. These
  10438.                             routines are linked with your program by
  10439.    Program                  Purpose
  10440.    ──────────────────────────────────────────────────────────────────────────
  10441.                            routines are linked with your program by
  10442.                             LINK.EXE.
  10443.  
  10444.  
  10445.                             The BRUN45.LIB library is the run-time-module
  10446.                             library. Programs linked with this library have
  10447.                             small executable files, but can only run in
  10448.                             combination with BRUN45.EXE, the run-time module.
  10449.  
  10450.    BCOM45.LIB               Provides supporting routines like BRUN45.LIB,
  10451.                             except that executable files created with this
  10452.                             library do not require BRUN45.EXE (run-time
  10453.                             module) support. Files created with BCOM45.LIB
  10454.                             are larger than those that use BRUN45.EXE, but
  10455.                             will run as stand-alone programs.
  10456.    ──────────────────────────────────────────────────────────────────────────
  10457.  
  10458.  
  10459.    Take the following steps to create an executable file from a program
  10460.    loaded in QuickBASIC:
  10461.  
  10462.    1. Choose the Make EXE File command from the Run menu. The Make EXE File
  10463.       dialog box appears. See Figure 16.2.
  10464.  
  10465.  
  10466.                      Name for executable file
  10467.                              │
  10468.       ┌──────────────────────┼────── Make EXE File ───────────────────────────
  10469.       │                ┌─────┼────────────────────────────────────────────────
  10470.       │ EXE File Name: │DEMO1.EXE
  10471.       │                └──────────────────────────────────────────────────────
  10472.       │
  10473.       │ ┌─[X] Produce Debug Code             Produce:
  10474.       │ │                                 ┌──(∙) EXE Requiring BRUN45.EXE
  10475.       │ │                                 ├──( ) Stand-Alone EXE File
  10476.       ├─┼─────────────────────────────────┼───────────────────────────────────
  10477.       │ │  < Make EXE >     < Make EXE and│Exit >     < Cancel >     < Help >
  10478.       └─┼─────────────────────────────────┼───────────────────────────────────
  10479.         │                                 │
  10480.       Provides additional debugging       Executable-file options
  10481.       information when checked
  10482.  
  10483.       Figure 16.2  Make EXE File Dialog Box
  10484.  
  10485.    2. Type a different base name in the text box if you want to rename your
  10486.       file; otherwise, leave the text box alone.
  10487.  
  10488.    3. Choose either the EXE Requiring BRUN45.EXE option or the Stand-Alone
  10489.       EXE File option.
  10490.  
  10491.       See Section 16.5.3, "Types of Executable Files," for a discussion of
  10492.       these alternatives.
  10493.  
  10494.    4. Choose Produce Debug Code if you want your executable file to include
  10495.       additional error-checking and to report error locations at run time.
  10496.       Also choose Produce Debug Code if you want your program to respond to
  10497.       CTRL+BREAK. Note that Produce Debug Code does not produce
  10498.       CodeView(R)-compatible files and results in larger and slower programs.
  10499.       See Section 16.5.4, "Run-Time Error Checking in Executable Files," for
  10500.       an explanation of errors handled by this option.
  10501.  
  10502.    5. Choose either the Make EXE or the Make EXE and EXIT command button:
  10503.  
  10504.       ■ The Make EXE command button creates the executable file, and then
  10505.         returns you to QuickBASIC.
  10506.  
  10507.       ■ The Make EXE and Exit command button creates the executable file, and
  10508.         then returns you to the DOS prompt.
  10509.  
  10510.  16.5.2  Quick Libraries and Executable Files
  10511.  
  10512.    If your program uses routines from a Quick library, you must load the
  10513.    Quick library when you load your program. If a Quick library is loaded
  10514.    when you choose the Make EXE file command, the BC compiler searches for a
  10515.    stand-alone (.LIB) library that corresponds to the loaded Quick library
  10516.    when it creates an executable file.
  10517.  
  10518.    Quick libraries provide fast access to your own custom library of
  10519.    procedures, but you can use them only inside the QuickBASIC environment.
  10520.    The compiler needs access to the corresponding stand-alone (.LIB) library
  10521.    to include the Quick library's procedures in an executable file.
  10522.    Therefore, it is a good idea to keep both kinds of libraries──Quick
  10523.    libraries and .LIB libraries──in the same directory. You can use the
  10524.    Options menu's Set Paths command to tell QuickBASIC where to look for any
  10525.    .LIB or Quick libraries it needs when creating an executable file. (The
  10526.    Make Library command on the Run menu makes both kinds of libraries
  10527.    automatically. See Section 16.6, "Make Library," in this manual and
  10528.    Appendix H in Programming in BASIC for more information on creating and
  10529.    using Quick libraries.)
  10530.  
  10531.  16.5.3  Types of Executable Files
  10532.  
  10533.    You can create two different types of executable files, depending on
  10534.    whether or not you want your executable program to require access to the
  10535.    run-time module BRUN45.EXE.
  10536.  
  10537.    16.5.3.1  Programs that Use the Run-Time Module
  10538.  
  10539.    Programs compiled with the EXE Requiring BRUN45.EXE option need access to
  10540.    the run-time module BRUN45.EXE when they run. The run-time module contains
  10541.    code needed to implement the BASIC language. Run-time modules provide the
  10542.    following advantages over stand-alone programs:
  10543.  
  10544.    ■ The executable file is much smaller.
  10545.  
  10546.    ■ COMMON variables and open files are preserved across CHAIN statements,
  10547.      allowing programs to share data. Stand-alone programs do not preserve
  10548.      open files or variables listed in COMMON statements when a CHAIN
  10549.      statement transfers control to another program.
  10550.  
  10551.    ■ The BRUN45.EXE run-time module resides in memory, so it does not need to
  10552.      be reloaded for each program in a series of chained programs.
  10553.  
  10554.    16.5.3.2  Stand-Alone Programs
  10555.  
  10556.    When you use the Stand-Alone EXE File option, the executable file does not
  10557.    require access to the run-time module BRUN45.EXE. However, since files
  10558.    created with this option include the support routines found in BRUN45.EXE,
  10559.    they are larger than files created with the EXE Requiring BRUN45.EXE
  10560.    option. Also, files created with the EXE Requiring BRUN45.EXE option do
  10561.    not preserve open files or variables listed in COMMON statements when a
  10562.    CHAIN statement transfers control to another program.
  10563.  
  10564.    Stand-alone files have the following advantages:
  10565.  
  10566.    ■ Slightly faster execution than run-time programs.
  10567.  
  10568.    ■ RAM space may be saved if you have small, simple programs that do not
  10569.      require all the routines in the run-time module.
  10570.  
  10571.    ■ The program does not require the run-time module to run. This allows the
  10572.      program to run by itself on any DOS computer.
  10573.  
  10574.  16.5.4  Run-Time Error Checking in Executable Files
  10575.  
  10576.    If you turn on the Produce Debug Code check box in the Make EXE File
  10577.    dialog box when you make an executable file, the following conditions are
  10578.    checked when the program runs:
  10579.  
  10580.    ■ Arithmetic overflow. All arithmetic operations, both integer and
  10581.      floating-point, are checked for overflow and underflow.
  10582.  
  10583.    ■ Array bounds. Array subscripts are checked to ensure they are within the
  10584.      bounds specified in DIM statements.
  10585.  
  10586.    ■ Line locations. The generated binary code includes additional tables so
  10587.      that run-time error messages indicate the lines on which errors occur.
  10588.  
  10589.    ■ RETURN statements. Each RETURN statement is checked for a prior GOSUB
  10590.      statement.
  10591.  
  10592.    ■ CTRL+BREAK, the keystroke combination to halt program execution. After
  10593.      executing each line, the program checks to see if the user pressed
  10594.      CTRL+BREAK. If so, the program stops.
  10595.  
  10596.      Note that you must compile a program with the Produce Debug Code option
  10597.      turned on if you want it to respond to CTRL+BREAK. Otherwise, CTRL+BREAK
  10598.      halts a program only when one of the following conditions is met:
  10599.  
  10600.     1. A user enters data in response to an INPUT statement's prompt.
  10601.  
  10602.     2. The program's code explicitly checks for CTRL+BREAK.
  10603.  
  10604.    ──────────────────────────────────────────────────────────────────────────
  10605.    WARNING
  10606.      If you don't use the Produce Debug Code option, then array-bound errors,
  10607.      RETURN without GOSUB errors, and arithmetic overflow errors do not
  10608.      generate error messages. Program results may be unpredictable.
  10609.    ──────────────────────────────────────────────────────────────────────────
  10610.  
  10611.  16.5.5  Floating-Point Arithmetic in Executable Files
  10612.  
  10613.    When you compile a program into an executable file, the executable file
  10614.    does floating-point calculations more quickly and efficiently than the
  10615.    same program running in the QuickBASIC environment. Executable files
  10616.    optimize for speed and accuracy by changing the order in which they do
  10617.    certain arithmetic operations. (They also make greater use of a numeric
  10618.    coprocessor chip or emulation of a coprocessor's function.)
  10619.  
  10620.    One side effect of this extra accuracy in the results of relational
  10621.    operations is that you may notice a difference when comparing single- or
  10622.    double-precision values. For example, the following code fragment prints
  10623.    Equal when run in the QuickBASIC environment but Not Equal when it is run
  10624.    as an executable file:
  10625.  
  10626.    B!=1.0
  10627.    A!=B!/3.0
  10628.    .
  10629.    .
  10630.    .
  10631.    IF A!=B!/3.0 THEN PRINT "Equal" ELSE PRINT "Not Equal"
  10632.  
  10633.    This problem results from performing the calculation B!/3.0 inside a
  10634.    comparison. The compiled program stores the result of this calculation on
  10635.    the math coprocessor chip, which gives it a higher degree of accuracy than
  10636.    the value stored in the variable A!, causing the inequality.
  10637.  
  10638.    You can avoid such problems in comparisons by doing all calculations
  10639.    outside of comparisons. The following rewritten code fragment produces the
  10640.    same results when run in the environment and as an executable file:
  10641.  
  10642.    B!=1.0
  10643.    A!=B!/3.0
  10644.    .
  10645.    .
  10646.    .
  10647.    Tmp!=B!/3.0
  10648.    IF A!=Tmp! THEN PRINT "Equal" ELSE PRINT "Not Equal"
  10649.  
  10650.  
  10651.  16.6  Make Library Command (Full Menus Only)
  10652.  
  10653.    The Make Library command creates a custom Quick library for use with
  10654.    compiled programs. A Quick library can contain procedures that you wish to
  10655.    use in more than one program.
  10656.  
  10657.    When you make a library with QuickBASIC, consider whether the library is
  10658.    new or an update of an existing library. If it is an update, start
  10659.    QuickBASIC with the /L command-line option, supplying the name of the
  10660.    library to be updated as a command-line argument (for example, QB /L
  10661.    Mylib). You can also include the name of a program whose modules you want
  10662.    to put in the library. In this case QuickBASIC loads all the modules
  10663.    specified in that program's .MAK file. If it is a new library, start
  10664.    QuickBASIC first, and use Load File to load the files you want to convert
  10665.    into a library.
  10666.  
  10667.    If you load your program when starting QuickBASIC, be sure to unload any
  10668.    modules you do not want in the Quick library, including the main module
  10669.    (unless it contains procedures you want in the library).
  10670.  
  10671.  16.6.1  Unloading and Loading Modules
  10672.  
  10673.    To keep your Quick libraries as compact as possible, remove any
  10674.    nonessential modules currently loaded. To remove ("unload") the unwanted
  10675.    modules, follow these steps:
  10676.  
  10677.    1. Choose the Unload File command from the File menu.
  10678.  
  10679.    2. Select the module you want to unload from the list box, then press
  10680.       ENTER. The module is unloaded, but still exists as a disk file.
  10681.  
  10682.    3. Repeat steps 1 and 2 until you have unloaded all unwanted modules.
  10683.  
  10684.    Alternatively, start QuickBASIC with or without a library specification,
  10685.    and load only those modules you want. In this case, you load each module
  10686.    using the Load File command from the File menu.
  10687.  
  10688.    To load one module at a time, follow these steps:
  10689.  
  10690.    1. Choose the File menu's Load File command.
  10691.  
  10692.    2. Select the name of a module you want to load from the list box.
  10693.  
  10694.    3. Repeat steps 1 and 2 until you have loaded all the modules you want.
  10695.  
  10696.  16.6.2  Creating Libraries
  10697.  
  10698.    Once you load the previous library (if any) and the new modules you want
  10699.    to include in the Quick library, choose the Make Library command on the
  10700.    Run menu. The dialog box shown in Figure 16.3 appears.
  10701.  
  10702.  
  10703.                         Name for library
  10704.                                 │
  10705.    ┌────────────────────────────┼─ Make Library ──────────────────────────────
  10706.    │                          ┌─┼──────────────────────────────────────────┐
  10707.    │ Quick-Library File Name: │prntproc.lib                                │
  10708.    │                          └────────────────────────────────────────────┘
  10709.    │
  10710.    │ ┌─[X] Produce Debug Code
  10711.    ├─┼────────────────────────────────────────────────────────────────────────
  10712.    │ │ < Make Library >   < Make Library and Exit >   < Cancel >   < Help >
  10713.    └─┼────────────────────────────────────────────────────────────────────────
  10714.      │
  10715.    Provides additional debugging information when checked
  10716.  
  10717.    Figure 16.3  Make Library Dialog Box
  10718.  
  10719.    To create a Quick library after you have chosen the Make Library command,
  10720.    do the following:
  10721.  
  10722.    1. Enter the name of the library you wish to create in the Quick-Library
  10723.       File Name text box.
  10724.  
  10725.       If you enter a base name (that is, a file name with no extension),
  10726.       Quick BASIC appends the extension .QLB when it creates the Quick
  10727.       library. If you want your library to have no extension, add a
  10728.       terminating period (.) to the base name. Otherwise, you may enter any
  10729.       unique base name and extension you like, as long as it is consistent
  10730.       with DOS file-name rules.
  10731.  
  10732.    2. Select the Produce Debug Code check box only if you are specifically
  10733.       trying to track a bug you believe to be in a library you are updating.
  10734.       It makes your library larger, your program slower, and gives only a
  10735.       small amount of error information.
  10736.  
  10737.    3. Create the Quick library:
  10738.  
  10739.       ■ Choose the Make Library command button if you want to remain in the
  10740.         environment after the Quick library is created.
  10741.  
  10742.       ■ Choose the Make Library and Exit command button if you want to return
  10743.         to the DOS command level after the Quick library is created.
  10744.  
  10745.    ──────────────────────────────────────────────────────────────────────────
  10746.    NOTE
  10747.      A Quick library that needs to trap events such as keystrokes must
  10748.      contain at least one event-trapping statement in one of its modules.
  10749.      This statement can be as simple as TIMER OFF, but without it, events are
  10750.      not trapped correctly in the Quick library.
  10751.    ──────────────────────────────────────────────────────────────────────────
  10752.  
  10753.  
  10754.  16.7  Set Main Module Command (Full Menus Only)
  10755.  
  10756.    The Set Main Module command lets you select a main module from a list of
  10757.    the currently loaded modules.
  10758.  
  10759.    In a single-module program, the main module is the program. Therefore, as
  10760.    soon as you have typed your first statement and have saved it, you have
  10761.    created a main module. In a multiple-module program, the main module
  10762.    contains the first statement to be executed when the program is run──it is
  10763.    the first entry in any list box (such as the one in the SUBs command
  10764.    dialog box) that shows the modules in a program.
  10765.  
  10766.    If you start QuickBASIC without specifying a file name, the title bar of
  10767.    the View window contains the word Untitled. If you save the contents of
  10768.    that View window, even if it is empty, the name under which you save it
  10769.    becomes the name of the main module of the program.
  10770.  
  10771.    After you name the main module, the name appears in the title bar of the
  10772.    View window.
  10773.  
  10774.  16.7.1  Changing the Main Module
  10775.  
  10776.    A module can be part of many different programs, but it can be the main
  10777.    module of only one program (the program bearing its name).
  10778.  
  10779.    As you are editing your program, you may find that you want to reorganize
  10780.    it and have execution begin with a module other than the one currently
  10781.    designated as the main module. To do this, follow these steps:
  10782.  
  10783.    1. Choose the Set Main Module command from the Run menu. The Set Main
  10784.       Module dialog box contains a list of currently loaded modules.
  10785.  
  10786.    2. Select the module you want to designate as the main module, and press
  10787.       ENTER. See Figure 16.4.
  10788.  
  10789.  
  10790.    Becomes new main module
  10791.    ┌─────── Set Main Module ───────┐
  10792.    │  Choose new main module:      │
  10793.    │  ┌─────────────────────────┐  │
  10794.    │  │ DEMO1.BAS                 │
  10795.    │  │ TEST.BAS                ▒  │
  10796.    │  │ TORUS.BAS               ▒  │
  10797.    │  │ DEMO2.BAS               ▒  │
  10798.    │  │                         ▒  │
  10799.    │  │                         ▒  │
  10800.    │  │                         ▒  │
  10801.    │  │                           │
  10802.    │  └─────────────────────────┘  │
  10803.    │                               │
  10804.    ├───────────────────────────────┤
  10805.    │  < OK >  < Cancel > < Help >  │
  10806.    └───────────────────────────────┘
  10807.  
  10808.    Figure 16.4  Set Main Module DIalog Box
  10809.  
  10810.  16.7.2  The .MAK File
  10811.  
  10812.    When you save a multiple-module program QuickBASIC creates a special file
  10813.    containing the names of all the program modules. This file has the base
  10814.    name of the main module plus the extension .MAK.
  10815.  
  10816.    When you reload the program, QuickBASIC uses the .MAK file to locate all
  10817.    of the modules. For this reason, do not delete a .MAK file. If you move a
  10818.    multiple-module program to another directory, you also need to move the
  10819.    .MAK file.
  10820.  
  10821.    Only program modules are included in a .MAK file. The main program module
  10822.    is the first .MAK file entry. QuickBASIC does not add other types of files
  10823.    to the .MAK list. If your program relies on include files, the program
  10824.    must specify each file as an argument to a $INCLUDE metacommand.
  10825.  
  10826.    The .MAK file is a text file. If you wish to edit it, load it into
  10827.    QuickBASIC using the Document option of the File menu's Load File command.
  10828.  
  10829.    You can remove modules from a program's .MAK file without editing the .MAK
  10830.    file directly. With the program loaded, follow the module-unloading
  10831.    procedure outlined in Section 16.6.1, "Unloading and Loading Modules."
  10832.    When you save the program, the names of any unloaded modules are removed
  10833.    from the .MAK file.
  10834.  
  10835.  
  10836.  
  10837.  ────────────────────────────────────────────────────────────────────────────
  10838.  Chapter 17  Debugging Concepts and Procedures
  10839.  
  10840.    This chapter introduces the topic of debugging your programs with
  10841.    QuickBASIC. QuickBASIC can help you track down errors that result from
  10842.    flaws in the logic of a program.
  10843.  
  10844.    This chapter provides the following information on debugging:
  10845.  
  10846.    ■ Using QuickBASIC to prevent bugs as you are writing your program
  10847.  
  10848.    ■ Debugging terms and concepts
  10849.  
  10850.    See Chapter 18, "The Debug Menu," for more information on debugging.
  10851.  
  10852.  
  10853.  17.1  Debugging with QuickBASIC
  10854.  
  10855.    QuickBASIC simplifies debugging with advanced features such as
  10856.    breakpoints, watchpoints, instant watch, and watch expressions. Other
  10857.    fundamental tools include the STOP, PRINT, CONT, TRON, and TROFF
  10858.    statements.
  10859.  
  10860.    With QuickBASIC, you do not need to use separate tools or invoke any
  10861.    special options to debug your program. When you notice a bug, you can
  10862.    start tracking it immediately. The QuickBASIC environment contains
  10863.    everything you need.
  10864.  
  10865.    Additionally, QuickBASIC does not require you to recompile or relink a
  10866.    program after making a change. You can usually run a program to the point
  10867.    where a problem occurs, suspend execution, fix the problem, and continue
  10868.    running the program as though it never stopped. In QuickBASIC, you debug
  10869.    as you program.
  10870.  
  10871.  
  10872.  17.2  Preventing Bugs with QuickBASIC
  10873.  
  10874.    Preventing bugs is the best way to have a bug-free program. Here are three
  10875.    ways to prevent bugs:
  10876.  
  10877.    1. Design your program carefully.
  10878.  
  10879.       An important rule in good program design is to isolate different tasks
  10880.       by writing SUB or FUNCTION procedures to perform those tasks. A small
  10881.       procedure is much easier to debug than a large program without
  10882.       procedures.
  10883.  
  10884.       An additional benefit of using procedures is that you can save groups
  10885.       of procedures in a separate file called a module, then use them in
  10886.       other programs that perform the same tasks. (See Chapter 2, "SUB and
  10887.       FUNCTION Procedures," in Programming in BASIC for more information on
  10888.       procedures and modules.)
  10889.  
  10890.    2. Use the Immediate window.
  10891.  
  10892.       As you program, use the Immediate window at the bottom of the
  10893.       QuickBASIC screen to isolate and test small pieces of the program. See
  10894.       Section 17.3.5 for more information on the Immediate window. When
  10895.       these pieces work on their own, move them into the View window.
  10896.  
  10897.    3. Run your program often.
  10898.  
  10899.       Because QuickBASIC checks and translates each statement to executable
  10900.       code (instructions understood by the computer) after you type a line
  10901.       and press ENTER, you can continually test-run the program as you add
  10902.       new pieces. This helps catch simple bugs that could be difficult to
  10903.       track in a finished program.
  10904.  
  10905.    Suppose you have written a program that contains the following code:
  10906.  
  10907.    DIM Array$(1 TO 20)
  10908.    .
  10909.    .
  10910.    .
  10911.    I% = 1
  10912.    DO
  10913.       INPUT Temp$
  10914.       IF Temp$ <> "" THEN
  10915.          Array$(I%) = Temp$
  10916.          I% = I + 1
  10917.       END IF
  10918.    LOOP UNTIL Temp$ = "" OR I% > 20
  10919.  
  10920.    You believe you have designed a logical loop. Now you can test the code by
  10921.    doing the following:
  10922.  
  10923.    1. Execute the loop and enter text when prompted. (To end the loop, press
  10924.       ENTER instead of entering text.)
  10925.  
  10926.    2. Type the following in the Immediate window:
  10927.  
  10928.       For I% = 1 to 20: PRINT Array$(I%): NEXT
  10929.  
  10930.    Your output will alert you to a flaw in your program──the variable I% is
  10931.    not incrementing. Upon closer inspection, you notice that you must change
  10932.    the line
  10933.  
  10934.    I% = I + 1
  10935.  
  10936.    to
  10937.  
  10938.    I% = I% + 1
  10939.  
  10940.    Along with designing your program carefully, using the Immediate window,
  10941.    and running your program often, another debugging technique is setting a
  10942.    "watch expression." This allows you to "watch" (monitor) the value of the
  10943.    variable I% as you trace through the loop. Section 17.3.3, "Watch
  10944.    Expressions," and Section 17.3.4, "Watch Window," tell how to watch an
  10945.    expression while a program is executing.
  10946.  
  10947.  
  10948.  17.3  QuickBASIC's Debugging Features
  10949.  
  10950.    This section defines some key debugging terms and concepts. See Chapter
  10951.    18, "The Debug Menu," for information on the Debug menu and how to use
  10952.    QuickBASIC's debugging commands.
  10953.  
  10954.  17.3.1  Tracing (Full Menus Only)
  10955.  
  10956.    The Trace On command highlights each statement as it executes. If the
  10957.    program manipulates the screen, QuickBASIC switches back and forth between
  10958.    the highlighted statements and the output screen (this is referred to as
  10959.    "animated execution"). For example, with tracing on you can follow
  10960.    branching in an IF...THEN...ELSE statement. QuickBASIC's tracing options
  10961.    let you run the entire program at once (normal tracing), one statement at
  10962.    a time (single stepping), or one procedure at a time (procedure stepping).
  10963.    See Section 17.3.6, "Other Debugging Features," for a discussion of
  10964.    single stepping and procedure stepping.
  10965.  
  10966.    Turning on tracing automatically enables QuickBASIC's History On command.
  10967.    History records the last 20 statements executed so you can stop execution
  10968.    and trace backward and forward through the 20 previous statements with
  10969.    History Back and History Forward. The history feature allows you to answer
  10970.    the question, "How did I get here?"
  10971.  
  10972.    See Also
  10973.  
  10974.    Section 18.6, "Trace On Command"; Section 18.7, "History On Command"
  10975.  
  10976.  17.3.2  Breakpoints and Watchpoints
  10977.  
  10978.    A breakpoint is a location in your program where you want execution to
  10979.    pause. With breakpoints, you can set your program to execute only as far
  10980.    as you want, letting you test one segment of your program at a time. You
  10981.    can also use breakpoints to stop the program at strategic places and then
  10982.    examine a variable's value.
  10983.  
  10984.    A watchpoint is an expression that stops a program when the expression
  10985.    becomes true (nonzero). You might use a watchpoint, for example, if your
  10986.    program crashes in a loop that increments X from 1 to 50. A watchpoint of
  10987.    X=49 stops the program when X becomes 49. You can then single step the
  10988.    program through the forty-ninth loop to locate the particular statement
  10989.    that causes the crash.
  10990.  
  10991.    Watchpoints appear in the Watch window. The Watch window displays all of
  10992.    the current watchpoints and watch expressions.
  10993.  
  10994.    See Also
  10995.  
  10996.    Section 17.3.4, "Watch Window"; Section 18.1, "Add Watch Command";
  10997.    Section 18.8, "Toggle Breakpoint Command"
  10998.  
  10999.  17.3.3  Watch Expressions
  11000.  
  11001.    Watch expressions, which are entered with the Add Watch command, let you
  11002.    observe the value of a variable (a number or text string) or the condition
  11003.    of an expression (true or false) in an executing program.
  11004.  
  11005.    For example, if you want to watch the value of a variable MyVar and an
  11006.    expression X=1, QuickBASIC places MyVar and X=1 in the Watch window. As
  11007.    the program runs, QuickBASIC displays the changing values of MyVar and the
  11008.    condition of X=1 (-1 for true, 0 for false) in the Watch window. If a
  11009.    program MYPROG.BAS initially assigns MyVar a value of 10 and X a value of
  11010.    1, then the Watch window displays
  11011.  
  11012.    MYPROG.BAS  MyVar:  10
  11013.    MYPROG.BAS  X=1:    -1
  11014.  
  11015.    If the program later changes MyVar to 99 and X to 3, the Watch window will
  11016.    then display
  11017.  
  11018.    MYPROG.BAS  MyVar:  99
  11019.    MYPROG.BAS  X=1:    0
  11020.  
  11021.    The Instant Watch command displays the value of the variable or expression
  11022.    containing the cursor in a dialog box──you do not need to open the Watch
  11023.    window. However, the Instant Watch dialog box does give you the option of
  11024.    adding the variable or expression to the Watch window.
  11025.  
  11026.    See Also
  11027.  
  11028.    Section 17.3.4, "Watch Window"; Section 18.1, "Add Watch Command";
  11029.    Section 18.2, "Instant Watch Command"
  11030.  
  11031.  17.3.4  Watch Window
  11032.  
  11033.    The Watch window is the window that opens at the top of the QuickBASIC
  11034.    screen to let you track watchpoint conditions or watched expressions
  11035.    during program execution.
  11036.  
  11037.    The current value or condition (true or false) of a variable or expression
  11038.    can be displayed in the Watch window only when the program is executing in
  11039.    the part of the program in which the watchpoint or watch expression was
  11040.    added. The message Not watchable is displayed at all other times.
  11041.  
  11042.    For example, suppose you create a watch expression to monitor the value of
  11043.    a variable MyVal while you are working on a procedure called MySub. The
  11044.    value of MyVal will appear in the Watch window only when the program
  11045.    executes the MySub procedure. At any other time──when execution is in the
  11046.    module-level code or other procedures──the message Not watchable appears
  11047.    after MyVal in the Watch window.
  11048.  
  11049.    Even if a program uses a SHARED statement to share a variable between the
  11050.    module level and the procedure level, that variable is watchable only at
  11051.    the level that was active when the variable was added to the Watch window.
  11052.  
  11053.    Nothing is watchable while a DEF FN function is active.
  11054.  
  11055.    See Also
  11056.  
  11057.    Section 17.3.3, "Watch Expressions"; Section 18.1, "Add Watch Command";
  11058.    Section 18.2, "Instant Watch Command"
  11059.  
  11060.  17.3.5  Immediate Window
  11061.  
  11062.    The Immediate window is the window at the bottom of the screen. In it you
  11063.    can execute BASIC statements directly to gain information useful in
  11064.    debugging.
  11065.  
  11066.    Note, however, that the Immediate window can access information only about
  11067.    those variables in the part of the program (module or procedure) that is
  11068.    currently active.
  11069.  
  11070.    For example, if you suspend a program in a procedure, you may use the
  11071.    Immediate window to access local and global variables and expressions
  11072.    (indicated by the SHARED statement) but not ones local only to the
  11073.    module-level code or another procedure.
  11074.  
  11075.    See also
  11076.  
  11077.    Section 10.5, "Using the Immediate Window"
  11078.  
  11079.  17.3.6  Other Debugging Features
  11080.  
  11081.    Table 17.1 describes several additional debugging features available in
  11082.    QuickBASIC Version 4.5. Some are intended to be used together, while
  11083.    others are generally used by themselves.
  11084.  
  11085.    Table 17.1  Additional Debugging Features
  11086. ╓┌─┌──────────────┌──────────────┌───────────────────────────────────────────╖
  11087.    Feature        How to Execute Description
  11088.    ──────────────────────────────────────────────────────────────────────────
  11089.    Break on       Choose from    Locates errors in programs using error
  11090.    Feature        How to Execute Description
  11091.    ──────────────────────────────────────────────────────────────────────────
  11092.    Break on       Choose from    Locates errors in programs using error
  11093.    Errors command the Debug menu handling. Break on Errors disables error
  11094.                                  handling and halts execution when an error
  11095.                                  occurs. Press SHIFT<|>+<|>F8 (History Back)
  11096.                                  to see the error-causing statement.
  11097.  
  11098.    Execute to     Press F7       Executes from the beginning of a program up
  11099.    cursor                        to and including the line containing the
  11100.                                  cursor, and then halts execution. Use this
  11101.                                  feature to quickly execute to a
  11102.                                  problem-causing section of code, and then
  11103.                                  single step to find the error.
  11104.  
  11105.    Set Next       Choose from    Changes the execution sequence of an
  11106.    Statement      the Debug menu interrupted program so that the next
  11107.    command                       statement to execute will be the one at the
  11108.                                  cursor. If your program encounters an error
  11109.                                  that you can correct immediately, use Set
  11110.                                  Next Statement to tell QuickBASIC to begin
  11111.    Feature        How to Execute Description
  11112.    ──────────────────────────────────────────────────────────────────────────
  11113.                                 Next Statement to tell QuickBASIC to begin
  11114.                                  executing from the corrected line when you
  11115.                                  choose Continue.
  11116.  
  11117.    Single         Press F8       Executes a single statement. This is a
  11118.    stepping                      powerful tool for debugging code. By single
  11119.                                  stepping and using the Watch window
  11120.                                  together, you can gain a thorough
  11121.                                  understanding of how each statement affects
  11122.                                  your variables.
  11123.  
  11124.    Procedure      Press F10      Executes a procedure call and the procedure
  11125.    stepping                      as a single statement. If you are single
  11126.                                  stepping and encounter a procedure you know
  11127.                                  works properly, procedure stepping lets you
  11128.                                  execute the entire procedure at once (rather
  11129.                                  than single stepping through it).
  11130.    ──────────────────────────────────────────────────────────────────────────
  11131.  
  11132.    Feature        How to Execute Description
  11133.    ──────────────────────────────────────────────────────────────────────────
  11134. 
  11135.  
  11136.    See Also
  11137.  
  11138.    Section 18.10, "Break On Errors Command"; Section 18.11, "Set Next
  11139.    Statement Command"
  11140.  
  11141.  
  11142.  ────────────────────────────────────────────────────────────────────────────
  11143.  Chapter 18  The Debug Menu
  11144.  
  11145.    The Debug menu controls features that speed program debugging. These
  11146.    features let you watch variables and expressions as they change, trace
  11147.    program execution, stop the program at specified locations or on specified
  11148.    conditions, and alter the restart location of a suspended program.
  11149.  
  11150.    The Debug menu contains the following commands:
  11151.  
  11152.    ■ Add Watch. Displays the values of variables and expressions in the Watch
  11153.      window as a program executes.
  11154.  
  11155.    ■ Instant Watch. Displays the value of a variable or expression.
  11156.  
  11157.    ■ Watchpoint. Allows you to halt program execution when a condition you
  11158.      specify becomes true (Full Menus only).
  11159.  
  11160.    ■ Delete Watch. Removes an item from the Watch window.
  11161.  
  11162.    ■ Delete All Watch. Removes all entries in the Watch window and closes the
  11163.      window (Full Menus only).
  11164.  
  11165.    ■ Trace On. Steps through the program in slow motion, highlighting the
  11166.      currently executing statement (Full Menus only).
  11167.  
  11168.    ■ History On. Records the last 20 lines executed by the program (Full
  11169.      Menus only).
  11170.  
  11171.    ■ Toggle Breakpoint. Turns breakpoints on and off.
  11172.  
  11173.    ■ Clear All Breakpoints. Removes all previously set breakpoints.
  11174.  
  11175.    ■ Break on Errors. Sets an implicit breakpoint at the most recent
  11176.      error-handling statement (Full Menus only).
  11177.  
  11178.    ■ Set Next Statement. Changes the program execution sequence so that the
  11179.      next statement executed is the one at the cursor (Full Menus only).
  11180.  
  11181.  
  11182.  18.1  Add Watch Command
  11183.  
  11184.    The Add Watch command displays the values of variables and expressions as
  11185.    the program executes. QuickBASIC opens a Watch window at the top of the
  11186.    screen to accommodate the variables.
  11187.  
  11188.    To use the command, choose Add Watch on the Debug Menu. A dialog box
  11189.    appears. Type in the name of the variable or expression you want to watch.
  11190.    See Figure 18.1.
  11191.  
  11192.  
  11193.                       Variable or expression
  11194.                                │
  11195.       File  Edit  View  Search │Run  Debug  Calls  Options              Help
  11196.      SORTDEMO.BAS Z > 100:     │
  11197.      SORTDEMO.BAS Length > 50: │
  11198.    ┌───────────────────────────┼── SORTDEMO.BAS ─────────────────────────┤├──
  11199.    │' Define the data type used│to hold the information for each colored bar:
  11200.    │  TYPE SortType            │
  11201.    │     Length┌───────────────┼────── Add Watch ───────────────────────┐
  11202.    │           │               │                                        │
  11203.    │     ColorV│     Enter expression to be added to Watch window:      │
  11204.    │     BarStr│               │                                        │
  11205.    │  ENDTYPE  │  ┌────────────┼─────────────────────────────────────┐  │
  11206.    │           │  │COLORVAL ───┘                                     │  │
  11207.    │' Declare g│  └──────────────────────────────────────────────────┘  │
  11208.    │  CONST FAL├────────────────────────────────────────────────────────┤
  11209.    │  CONST NUM│       < OK >        < Cancel >        < Help >         │
  11210.    │           └────────────────────────────────────────────────────────┘
  11211.    │' Declare global variables, and allocate storage space for them. SortArray
  11212.    │' and SortBackup are both arrays of the data type SortType defined above:
  11213.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  11214.    ├─────────────────────────────── Immediate ────────────────────────────────
  11215.    │
  11216.    │
  11217.     F1=Help  Enter=Execute  Esc=Cancel  Tab=Next Field  Arrow=Next Item
  11218.  
  11219.    Figure 18.1  Add Watch Dialog Box
  11220.  
  11221.    Watching a variable in the Watch window avoids repeated use of PRINT
  11222.    statements for tracking the variable's value. You can also watch the
  11223.    condition (true or false) of an expression in the Watch window. True is
  11224.    represented by -1; false by 0. The variables or expressions you are
  11225.    watching are easily removed from the Watch window when debugging is
  11226.    complete.
  11227.  
  11228.    During program execution, a value in the Watch window changes when its
  11229.    value in the program changes. Sometimes the message Not watchable may
  11230.    appear rather than a value. This means that the debugger cannot currently
  11231.    access the variable because program execution is not in the part of the
  11232.    program (the procedure- or module-level code) from which the variable was
  11233.    added to the Watch window. A variable is watchable only when the program
  11234.    is executing in the part of the program from which the variable was added
  11235.    to the Watch window.
  11236.  
  11237.    Note that if you are interested in only one or two instances of a
  11238.    variable's value, it may be easier to use the Instant Watch command,
  11239.    described in Section 18.2.
  11240.  
  11241.    Example
  11242.  
  11243.    The following example calculates the nth number in a sequence known as the
  11244.    Fibonacci sequence. In the Fibonacci sequence, each number is the sum of
  11245.    the two preceding numbers, beginning with 1 and 2. The first 10 Fibonacci
  11246.    numbers are 1, 2, 3, 5, 8, 13, 21, 34, 55, and 89. This example uses the
  11247.    Add Watch command and animated tracing (the process of switching back and
  11248.    forth between highlighted statements in your program and the output
  11249.    screen).
  11250.  
  11251.    1. Start QuickBASIC or choose the New Program command from the File menu,
  11252.       and type:
  11253.  
  11254.       DEFINT A-Z
  11255.       INPUT  n
  11256.       PRINT Fib(n)
  11257.       END
  11258.  
  11259.    2. Choose the Add Watch command from the Debug menu, then enter n in the
  11260.       text box. This displays the value n has at the module level.
  11261.  
  11262.    3. Create a FUNCTION procedure called Fib by choosing the New FUNCTION
  11263.       command from the Edit menu and typing Fib in the dialog box. (DEFINT
  11264.       A-Z is automatically added above the first line of the FUNCTION
  11265.       definition because of the DEFtype statement you typed in step 1.) Now
  11266.       enter the procedure as follows:
  11267.  
  11268.       FUNCTION Fib(n)
  11269.           IF n > 2 THEN
  11270.               Fib = Fib(n - 1) + Fib(n - 2)
  11271.           ELSE Fib = n
  11272.           END IF
  11273.       END FUNCTION
  11274.  
  11275.    4. Choose the Add Watch command on the Debug menu, and again add n to the
  11276.       Watch window. This displays the value of n within the Fib procedure.
  11277.  
  11278.    5. Choose the Trace On command on the Debug menu.
  11279.  
  11280.    6. Choose Start on the Run menu to execute the program.
  11281.  
  11282.    7. Enter 8 after the input prompt. Observe the Watch window to see how n
  11283.       changes as the procedure recursively calls itself to calculate the
  11284.       eighth number in the Fibonacci sequence.
  11285.  
  11286.    8. Choose the Output Screen command (or press F4) to see the program
  11287.       results.
  11288.  
  11289.    See Also
  11290.  
  11291.    Section 17.3.3, "Watch Expressions"; Section 17.3.4, "Watch Window"
  11292.  
  11293.  
  11294.  18.2  Instant Watch Command
  11295.  
  11296.    The Instant Watch command displays the value of a variable or the
  11297.    condition of an expression (true or false) in a dialog box.
  11298.  
  11299.    Use the command by moving the cursor within (or to the right of) a
  11300.    variable or selecting an expression and then choosing Instant Watch on the
  11301.    Debug menu. QuickBASIC displays a dialog box with the variable or
  11302.    expression in the upper text box and the value or condition (-1 for true,
  11303.    0 for false) in the lower text box. See Figure 18.2.
  11304.  
  11305.  
  11306.                       Variable or expression
  11307.                                │
  11308.       File  Edit  View  Search │Run  Debug  Calls  Options              Help
  11309.      SORTDEMO.BAS Z > 100:     │
  11310.      SORTDEMO.BAS Length > 50: │
  11311.    ┌───────────────────────────┼── SORTDEMO.BAS ─────────────────────────┤├──
  11312.    │' Define the data type used│to hold the information for each colored bar:
  11313.    │  TYPE SortTyp┌────────────┼────── Add Watch ─────────────────┐
  11314.    │     Length AS│            │                                  │ed
  11315.    │              │  ┌─────────┼───────────────────────────────┐  │
  11316.    │     ColorVal │  │Colorval─┘                               │  │
  11317.    │     BarString│  └─────────────────────────────────────────┘  │ters)
  11318.    │  ENDTYPE     │                                               │
  11319.    │              │  ┌─────────────────────────────────────────┐  │
  11320.    │' Declare glob│  │ 0 ──┐                                   │  │
  11321.    │  CONST FALSE │  └─────┼───────────────────────────────────┘  │
  11322.    │  CONST NUMOP ├────────┼──────────────────────────────────────┤
  11323.    │             T│   < Add│Watch >    < Cancel >    < Help >     │
  11324.    │' Declare glob└────────┼──────────────────────────────────────┘. SortArray
  11325.    │' and SortBackup are both arrays of the data type SortType defined above:
  11326.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  11327.    ├───────────────────────┼─────── Immediate ────────────────────────────────
  11328.    │                       │
  11329.    │                       │
  11330.     F1=Help  Enter=Execute │Esc=Cancel  Tab=Next Field  Arrow=Next Item
  11331.                            │
  11332.                      Value or condition
  11333.  
  11334.    Figure 18.2  Instant Watch Dialog Box
  11335.  
  11336.    Use the Instant Watch command for debugging assignment statements and for
  11337.    checking variables or expressions. If you need to watch a variable or
  11338.    expression constantly, use the Add Watch command (or press the Add Watch
  11339.    button in the Instant Watch dialog box) to add the item to the Watch
  11340.    window.
  11341.  
  11342.    The Instant Watch command is convenient for displaying a value or
  11343.    condition in a suspended or stopped program.
  11344.  
  11345.    Shortcut Key
  11346.  
  11347.    SHIFT+F9
  11348.  
  11349.    See Also
  11350.  
  11351.    Section 17.3.3, "Watch Expressions"; Section 17.3.4, "Watch Window"
  11352.  
  11353.  
  11354.  18.3  Watchpoint Command (Full Menus Only)
  11355.  
  11356.    The Watchpoint command allows you to set a watchpoint──an expression that
  11357.    halts program execution when the expression becomes true (for example,
  11358.    when the value of a variable X equals 100). QuickBASIC displays the
  11359.    watchpoint in the Watch window.
  11360.  
  11361.    When you choose the Watchpoint command a dialog box appears. You can enter
  11362.    any variable name or expression along with relational operators in the
  11363.    Watchpoint text box. See Figure 18.3.
  11364.  
  11365.  
  11366.       File  Edit  View  Search  Run  Debug  Calls  Options              Help
  11367.      SORTDEMO.BAS Z > 100:
  11368.      SORTDEMO.BAS Length > 50:
  11369.    ┌────────────────────────────── SORTDEMO.BAS ─────────────────────────┤├──
  11370.    │' Define the data type used to hold the information for each colored bar:
  11371.    │  TYPE SortType
  11372.    │     Length┌───────────────────── Watchpoint ───────────────────────┐
  11373.    │           │                                                        │
  11374.    │     ColorV│        Enter expression (will break when TRUE):        │
  11375.    │     BarStr│                                                        │
  11376.    │  ENDTYPE  │  ┌──────────────────────────────────────────────────┐  │
  11377.    │        ┌──┼──COLORVAL = 10                                     │  │
  11378.    │' Declar│ g│  └──────────────────────────────────────────────────┘  │
  11379.    │  CONST │AL├────────────────────────────────────────────────────────┤
  11380.    │  CONST │UM│       < OK >        < Cancel >        < Help >         │
  11381.    │        │  └────────────────────────────────────────────────────────┘
  11382.    │' Declar│ global variables, and allocate storage space for them. SortArray
  11383.    │' and So│tBackup are both arrays of the data type SortType defined above:
  11384.    │▒▒▒▒▒▒▒│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  11385.    ├────────│────────────────────── Immediate ────────────────────────────────
  11386.    │        │
  11387.    │        │
  11388.     F1=Help │Enter=Execute  Esc=Cancel  Tab=Next Field  Arrow=Next Item
  11389.             │
  11390.    Condition that will halt the program
  11391.  
  11392.    Figure 18.3  Watchpoint Dialog Box
  11393.  
  11394.    QuickBASIC's relational operators include =, <>, >, <, >=, and <=. If an
  11395.    expression is entered without a relational statement, QuickBASIC assumes
  11396.    the relation <> 0. QuickBASIC then suspends execution of the program as
  11397.    soon as the expression becomes a nonzero value.
  11398.  
  11399.    If you set a watchpoint in a SUB or FUNCTION procedure, the Watch window
  11400.    describes the given expression as TRUE or FALSE only when the program is
  11401.    executing in that procedure. At all other times the message Not watchable
  11402.    will appear beside the watchpoint in the Watch window. Similarly,
  11403.    watchpoints at the module level display the message Not watchable when
  11404.    execution is in a procedure.
  11405.  
  11406.    See Also
  11407.  
  11408.    Section 17.3.2, "Breakpoints and Watchpoints"; Section 18.1, "Add Watch
  11409.    Command"; Section 18.4, "Delete Watch Command"
  11410.  
  11411.  
  11412.  18.4  Delete Watch Command
  11413.  
  11414.    The Delete Watch command removes an item from the Watch window. The Delete
  11415.    Watch dialog box, shown in Figure 18.4, displays the current Watch-window
  11416.    items and allows you to select which Watch-window item to delete.
  11417.  
  11418.  
  11419.    List of items currently in Watch window
  11420.    │
  11421.    │  File  Edit  View  Search  Run  Debug  Calls  Options              Help
  11422.    │┌SORTDEMO.BAS Z > 100:  0
  11423.    └┤SORTDEMO.BAS ColorVal:  0
  11424.     └SORTDEMO.BAS Length < 50: -1
  11425.    ┌──────────────┌───────────────── Delete Watch ────────────────┐──────┤├──
  11426.    │' Define the d│  ┌─────────────────────────────────────────┐  │lored bar:
  11427.    │  TYPE SortTyp│  │   SORTDEMO.BAS Z > 100:                   │
  11428.    │     Length AS│  │   SORTDEMO.BAS ColorVal:                ▒  │ed
  11429.    │              │  │ │ SORTDEMO.BAS Length < 50:             ▒  │
  11430.    │     ColorVal │  │ │                                       ▒  │
  11431.    │     BarString│  │ │                                       ▒  │ters)
  11432.    │  ENDTYPE     │  │ │                                       ▒  │
  11433.    │              │  │ │                                       ▒  │
  11434.    │' Declare glob│  │ │                                       ▒  │
  11435.    │  CONST FALSE │  │ │                                         │
  11436.    │  CONST NUMOP │  └─┼───────────────────────────────────────┘  │
  11437.    │             T│    │                                          │
  11438.    │' Declare glob├────┼──────────────────────────────────────────┤. SortArray
  11439.    │' and SortBack│    │  < OK >     < Cancel >     < Help >      │ned above:
  11440.    │▒▒▒▒▒▒▒▒▒▒▒▒▒└────┼──────────────────────────────────────────┘▒▒▒▒▒▒▒▒▒▒
  11441.    ├───────────────────┼─────────── Immediate ────────────────────────────────
  11442.    │                   │
  11443.     F1=Help  Enter=Execute  Esc=Cancel  Tab=Next Field  Arrow=Next Item
  11444.                        │
  11445.                    Item to remove
  11446.  
  11447.    Figure 18.4  Delete Watch Dialog Box
  11448.  
  11449.    Use the Delete All Watch command to remove all Watch-window items at once.
  11450.  
  11451.    See Also
  11452.  
  11453.    Section 18.5, "Delete All Watch Command"
  11454.  
  11455.  
  11456.  18.5  Delete All Watch Command (Full Menus Only)
  11457.  
  11458.    The Delete All Watch command in the Debug menu removes all of the
  11459.    Watch-window entries and closes the window. You typically use the Delete
  11460.    All Watch command when the section of program code you are working on runs
  11461.    properly.
  11462.  
  11463.    If you want to selectively remove Watch-window items, use the Delete Watch
  11464.    command.
  11465.  
  11466.    See Also
  11467.  
  11468.    Section 18.4, "Delete Watch Command"
  11469.  
  11470.  
  11471.  18.6  Trace On Command (Full Menus Only)
  11472.  
  11473.    The Trace On command steps through the program in slow motion,
  11474.    highlighting the executing statement. When this command is active, a
  11475.    bullet (■) appears next to the Trace On command on the Debug menu.
  11476.    Choosing Trace On again toggles the feature off.
  11477.  
  11478.    Trace On is a useful method for determining whether the general flow of
  11479.    your program is what you intended, especially if you use it in combination
  11480.    with watchpoints, breakpoints, and CTRL+BREAK (which suspends execution).
  11481.    Trace On also records the last 20 statements executed, so you can review
  11482.    them with the History Back and History Forward commands (see Sections
  11483.    18.7.1 and 18.7.2).
  11484.  
  11485.    If a program sends output to the screen, running it with Trace On active
  11486.    causes the screen to flash back and forth between QuickBASIC and the
  11487.    output screen. You can use the Output Screen command from the View menu to
  11488.    control which screen appears during program suspension (see Section
  11489.    14.5).
  11490.  
  11491.    See Also
  11492.  
  11493.    Section 18.1, "Add Watch Command"; Section 18.7, "History On Command";
  11494.    Section 18.8, "Toggle Breakpoint Command"
  11495.  
  11496.  
  11497.  18.7  History On Command (Full Menus Only)
  11498.  
  11499.    Choose the History On command from the Debug menu to record the last 20
  11500.    lines executed by the program the next time it runs. When this command is
  11501.    active, a bullet (■) appears next to the History On command on the Debug
  11502.    menu. Execution speed is slower with this feature active.
  11503.  
  11504.    The History On command allows you to trace backward and forward through
  11505.    the last 20 statements executed by the program. This is particularly
  11506.    useful when you get a run-time error and you want to see which 20
  11507.    statements were executed immediately preceding the error. Checking the
  11508.    execution history also lets you review the specific branching of a program
  11509.    through nested sequences of conditional structures like IF...THEN...ELSE
  11510.    statements. Use History On in conjunction with breakpoints to review
  11511.    groups of up to 20 consecutive statements in your program.
  11512.  
  11513.    You use History On with the History Back and History Forward commands (see
  11514.    Sections 18.7.1 and 18.7.2).
  11515.  
  11516.    ──────────────────────────────────────────────────────────────────────────
  11517.    NOTE
  11518.      The History commands do not execute statements. They just show the
  11519.      previous execution sequence.
  11520.    ──────────────────────────────────────────────────────────────────────────
  11521.  
  11522.  18.7.1  History Back
  11523.  
  11524.    Activated with SHIFT+F8, History Back steps back in your program through
  11525.    the last 20 program statements recorded by either the History On or Trace
  11526.    On command.
  11527.  
  11528.    When you wish to review the flow of a program, interrupt the program
  11529.    execution by pressing CTRL+BREAK; then press SHIFT+F8 to check back
  11530.    through the last 20 statements executed. This shows you the program flow
  11531.    through statements and is particularly useful for following conditional
  11532.    branches.
  11533.  
  11534.  18.7.2  History Forward
  11535.  
  11536.    Activated with SHIFT+F10, History Forward lets you step forward in your
  11537.    program through the last 20 program statements. You can use History
  11538.    Forward only after using History Back. Because History Back shows the
  11539.    reverse execution order, step backward first, and then watch the execution
  11540.    sequence using History Forward.
  11541.  
  11542.    See Also
  11543.  
  11544.    Section 18.6, "Trace On Command"
  11545.  
  11546.  
  11547.  18.8  Toggle Breakpoint Command
  11548.  
  11549.    The Toggle Breakpoint command turns a breakpoint (a specific location in
  11550.    the program where execution stops) on and off. The Toggle Breakpoint
  11551.    command affects the line containing the cursor. Lines on which breakpoints
  11552.    are set appear in reverse video.
  11553.  
  11554.    Use a breakpoint to pause at points where you suspect problems in your
  11555.    program, then test the values of variables to confirm or refute your
  11556.    suspicion (in the Immediate window). Alternately, insert a breakpoint
  11557.    prior to a problem area and then use single stepping (see Section 17.3.6,
  11558.    "Other Debugging Features," for a description of single stepping) or use
  11559.    the Instant Watch command for a detailed view of program flow and variable
  11560.    values.
  11561.  
  11562.    Clear a breakpoint on the current cursor line by selecting Toggle
  11563.    Breakpoint again.
  11564.  
  11565.    Shortcut Key
  11566.  
  11567.    F9
  11568.  
  11569.    See Also
  11570.  
  11571.    Section 17.3.2, "Breakpoints and Watchpoints"; Section 18.9, "Clear All
  11572.    Breakpoints Command"
  11573.  
  11574.  
  11575.  18.9  Clear All Breakpoints Command
  11576.  
  11577.    The Clear All Breakpoints command removes all breakpoints in a program.
  11578.    Remove individual breakpoints (while leaving others in place) with the
  11579.    Toggle Breakpoint command.
  11580.  
  11581.    You typically use the Clear All Breakpoints command when you know a
  11582.    section of program code runs properly.
  11583.  
  11584.    See Also
  11585.  
  11586.    Section 17.3.2, "Breakpoints and Watchpoints"; Section 18.8, "Toggle
  11587.    Breakpoint Command"
  11588.  
  11589.  
  11590.  18.10  Break on Errors Command (Full Menus Only)
  11591.  
  11592.    The advanced debugging command Break on Errors allows you to trace an
  11593.    error-causing statement in a program that uses error handling. When
  11594.    toggled on (indicated by a bullet beside the command), Break on Errors
  11595.    sets an implicit breakpoint after the label specified in the most recently
  11596.    executed error-handling (ON ERROR) statement. If you do not use error
  11597.    handling, you will not need this command.
  11598.  
  11599.    When an error occurs in a program with error handlers, QuickBASIC routes
  11600.    execution to the label specified in the appropriate ON ERROR statement. If
  11601.    there is no ON ERROR statement that explicitly addresses the type of error
  11602.    QuickBASIC encounters, finding the source of the error can be difficult.
  11603.    Break on Errors solves this error-finding problem.
  11604.  
  11605.    The Break on Errors command enables History On and records the statement
  11606.    that caused the error. Choosing History Back (SHIFT+F8) shows you the
  11607.    error-causing statement.
  11608.  
  11609.    In the following program fragment, an error occurs at the line Y=5/X. This
  11610.    example demonstrates how QuickBASIC uses Break on Errors to stop after the
  11611.    label specified in the most recent ON ERROR statement:
  11612.  
  11613.    ON ERROR GOTO  FirstHandler  'First error handler
  11614.    ON ERROR GOTO  NextHandler   'Second error handler
  11615.    ON ERROR GOTO  LastHandler   'Third and last error handler
  11616.    .
  11617.    X = 0
  11618.    Y = 5/X
  11619.    .
  11620.    LastHandler:  'Label in most recently executed error handler
  11621.    .             'QuickBASIC stops immediately after label
  11622.    .
  11623.  
  11624.    With Break on Errors on, an error transfers program flow to LastHandler
  11625.    and execution stops. History Back will now show you the statement that
  11626.    caused the error.
  11627.  
  11628.    See Also
  11629.  
  11630.    Section 18.7, "History On Command"
  11631.  
  11632.  
  11633.  18.11  Set Next Statement Command
  11634.  
  11635.    When you want to skip over or rerun a section of a program, halt
  11636.    execution, then use the Set Next Statement command.
  11637.  
  11638.    The Set Next Statement command changes program execution sequence so that
  11639.    the next statement executed is the one at the cursor. QuickBASIC ignores
  11640.    any intervening program code. Use the Set Next Statement command with
  11641.    care; skipping code can lead to undefined variables and result in errors.
  11642.  
  11643.    The effect of the Set Next Statement command is similar to that of a GOTO
  11644.    statement, and the same restrictions apply. For example, you cannot branch
  11645.    to the middle of a procedure from the module level of a program.
  11646.  
  11647.    Note that the Next Statement command on the View menu moves the cursor to
  11648.    the next statement to be executed when the program continues to run, while
  11649.    the Set Next Statement command on the Debug menu allows you to establish
  11650.    (set) the next statement to be executed. Next Statement is used to
  11651.    indicate which statement will execute next if no changes are made; Set
  11652.    Next Statement allows you to alter this by choosing a new resumption point
  11653.    for program execution.
  11654.  
  11655.    See Also
  11656.  
  11657.    Section 14.4, "Next Statement Command"
  11658.  
  11659.  
  11660.  
  11661.  ────────────────────────────────────────────────────────────────────────────
  11662.  Chapter 19  The Calls Menu (Full Menus Only)
  11663.  
  11664.    The Calls menu is an advanced feature that shows all of the procedure
  11665.    calls that led to the current execution location. It lets you do the
  11666.    following:
  11667.  
  11668.    ■ See the sequence of nested procedure calls your program executed in
  11669.      order to arrive at the current procedure.
  11670.  
  11671.    ■ Continue your program from the point execution stopped to any listed
  11672.      procedure.
  11673.  
  11674.    Use the Calls menu to see which procedures execution passed through.
  11675.    During debugging, you can use the Calls menu and single stepping
  11676.    (described in Section 17.3.6, "Other Debugging Features") together to
  11677.    execute up to an error, recreating the same variable values and conditions
  11678.    that led to a program crash.
  11679.  
  11680.    If your procedures do not call other procedures, the Calls menu shows only
  11681.    the name of the main module and any currently executing procedure. In any
  11682.    program, the Calls menu displays only the program name prior to running.
  11683.  
  11684.  
  11685.  19.1  Using the Calls Menu
  11686.  
  11687.    The Calls menu shows calls between procedures. The following example
  11688.    illustrates the use of the Calls menu for both debugging and executing.
  11689.  
  11690.    Suppose you want to write a program to draw histograms (bar charts) on the
  11691.    screen, and you want your user to specify the fraction of the screen the
  11692.    chart will fill. Since you believe strongly in the use of structured
  11693.    programming, you break the process into several procedures.
  11694.  
  11695.    Your main module prompts your user for data and then calls a procedure
  11696.    DrawHisto to draw the chart. DrawHisto then sends the task of drawing the
  11697.    chart's bars to a separate procedure, DrawBars. Since the number of bars
  11698.    in the chart can vary (depending on the data your user entered), DrawBars
  11699.    farms out the job of calculating how wide each bar will be to the
  11700.    procedure CalcBarWidth. However, before CalcBarWidth can determine how
  11701.    wide each bar needs to be, it needs to know the width of the histogram.
  11702.    So, CalcBarWidth calls the procedure CalcHistoWidth which calculates the
  11703.    width of the screen to be used in the histogram.
  11704.  
  11705.    During execution, DrawHisto calls DrawBars, DrawBars calls CalcBarWidth,
  11706.    and CalcBarWidth calls CalcHistoWidth. If your program stops running
  11707.    inCalcHistoWidth, the Calls menu items appear in the order shown in Figure
  11708.    19.1.
  11709.  
  11710.  
  11711.    ┌──────────────────────────────────────────────────────────────────────────
  11712.    │
  11713.    │  ┌───────┐
  11714.    │  │ Calls │
  11715.    │  ├───────┴────────┐
  11716.    │  │ CalcHistoWidth─┼─────Procedure in which the program stopped running
  11717.    │  │ CalcBarWidth   │
  11718.    │  │ DrawBars       │
  11719.    │  │ DrawHisto      │
  11720.    │  │ HISTOGRM.BAS───┼─────Location of first call
  11721.    │  └────────────────┘
  11722.    │
  11723.    │  HISTOGRM.BAS─DrawHisto─DrawBars─CalcBarWidth─CalcHistoWidth
  11724.    │
  11725.    └──────────────────────────────────────────────────────────────────────────
  11726.  
  11727.    Figure 19.1  Sequence of Procedures on Calls Menu
  11728.  
  11729.    The Calls menu provides you with a "trail" you can follow to understand
  11730.    how your program executed to the CalcHistoWidth procedure; it is
  11731.    particularly valuable when your program stops in a series of deeply nested
  11732.    procedures (as in the histogram example). The order of the items in the
  11733.    Calls menu tells you the order in which the procedures were called; the
  11734.    item at the top of the list was called by the second item, the second item
  11735.    was called by the third item, the third item was called by the fourth
  11736.    item, etc. The first menu item is the one that was most recently executed.
  11737.  
  11738.    When a procedure crashes, the Calls menu gives you the sequence of
  11739.    procedures that led to the crash.
  11740.  
  11741.    Suppose the program you write to draw histograms (described earlier in
  11742.    this section) crashes in the CalcHistoWidth procedure. The Calls menu can
  11743.    help you continue the program or recreate the conditions that led to the
  11744.    crash.
  11745.  
  11746.    To continue the program through the rest of the CalcHistoWidth procedure,
  11747.    follow these steps:
  11748.  
  11749.    1. Use the Immediate window to change any variables necessary to allow the
  11750.       program to run (that is, correct the error that caused the program to
  11751.       crash).
  11752.  
  11753.    2. Choose CalcBarWidth from the Calls menu and press ENTER. This places
  11754.       the CalcBarWidth procedure in the View window, with the cursor on the
  11755.       line just after the line that called CalcHistoWidth.
  11756.  
  11757.    3. Press F7. This runs the program from the current execution point (the
  11758.       statement where the program crashed) to the current cursor location
  11759.       (just after the call to CalcHistoWidth). The remaining code is executed
  11760.       in the CalcHistoWidth procedure and stops executing at the cursor in
  11761.       CalcBarWidth.
  11762.  
  11763.    4. Use the Watch window, Immediate window, or Instant Watch command to
  11764.       verify that the variables have the values you desire, or use the Output
  11765.       Screen command to check any screen changes. Either way, you can verify
  11766.       that the program──with the changes you made in step 1──now runs
  11767.       properly.
  11768.  
  11769.    To recreate the conditions that led to the crash:
  11770.  
  11771.    1. Move the cursor to the beginning of the program and choose the Set Next
  11772.       Statement command on the Debug menu. This prepares the program to run.
  11773.  
  11774.    2. Choose CalcBarWidth in the Calls menu and press ENTER. QuickBASIC
  11775.       displays the CalcBarWidth procedure, with the cursor on the line below
  11776.       the call to CalcHistoWidth. Move the cursor to the line above the call
  11777.       to CalcHistoWidth.
  11778.  
  11779.    3. Press F7. This runs the program from the current execution point (the
  11780.       first executable statement in the program) to the current cursor
  11781.       location.
  11782.  
  11783.    4. Single step (press F8) from CalcBarWidth into CalcHistoWidth until you
  11784.       find the error-causing statement.
  11785.  
  11786.    5. Use the Instant Watch command or other debugging techniques to resolve
  11787.       the error.
  11788.  
  11789.    In complex programs, using the Calls menu can simplify debugging.
  11790.  
  11791.  
  11792.  19.2  Active Procedures
  11793.  
  11794.    The procedure at the top of the Calls menu is the currently active
  11795.    procedure. The one directly below it is the procedure that called the
  11796.    active procedure (and the one to which control returns when QuickBASIC
  11797.    leaves the active procedure). You can execute your program to any
  11798.    procedure in the Calls menu by choosing the procedure's name and pressing
  11799.    F7.
  11800.  
  11801.    Consider the procedures shown in Figure 19.1. Since CalcBarWidth is
  11802.    high-lighted, pressing ENTER and then F7 executes code from the beginning
  11803.    of the program to the statement in CalcBarWidth that follows the call to
  11804.    CalcHistoWidth. Note that QuickBASIC tracks only the most recent execution
  11805.    with the Calls menu, so that DrawBars would now be at the top of the list
  11806.    and CalcBarWidth and CalcHistoWidth would be removed (they were not
  11807.    involved in the most recent program execution).
  11808.  
  11809.    The Calls menu is a "stack" in that it displays the most recently called
  11810.    procedure on the top of the list. The Calls menu displays only the eight
  11811.    most recent procedures; any deeper nesting is not displayed until you
  11812.    start executing to return through the sequence of procedure calls.
  11813.  
  11814.    You can experiment with the characteristics of the call stack using the
  11815.    Fibonacci example at the end of Section 18.1, "Add Watch Command."
  11816.    Because the Fib procedure is recursive, the number you enter at the prompt
  11817.    determines the depth of the call stack and the number of procedures in the
  11818.    Calls menu. After interrupting execution (either by using a watchpoint or
  11819.    pressing CTRL+BREAK), you can display the Calls menu and use the methods
  11820.    described above to see the different iterations of the Fib procedure.
  11821.    Since the procedure is recursive, all the procedure names are identical.
  11822.    Each one listed represents another instance of the call.
  11823.  
  11824.  
  11825.  
  11826.  ────────────────────────────────────────────────────────────────────────────
  11827.  Chapter 20  The Options Menu
  11828.  
  11829.    The Options menu controls some of QuickBASIC's special features, including
  11830.    those that customize the QuickBASIC screen, set default search paths,
  11831.    determine the function for the right mouse button, toggle syntax checking
  11832.    off and on, and switch between Full Menus and Easy Menus.
  11833.  
  11834.    The Option menu commands are listed below:
  11835.  
  11836.    ■ Display. Customizes the appearance of the QuickBASIC environment
  11837.      (colors, scroll bars, tab stops).
  11838.  
  11839.    ■ Set Paths. Sets default search paths depending on file type.
  11840.  
  11841.    ■ Right Mouse. Changes effect of clicking the right mouse button (Full
  11842.      Menus only).
  11843.  
  11844.    ■ Syntax Checking. Toggles syntax checking on and off (Full Menus only).
  11845.  
  11846.    ■ Full Menus. Toggles Full Menus on and off.
  11847.  
  11848.    When you alter the QuickBASIC environment, either by starting QuickBASIC
  11849.    with a command-line option (described in Section 10.1.1, "The QB
  11850.    Command") or by using the Options menu, QuickBASIC saves your
  11851.    modifications in a file that is called QB.INI. If the file already exists
  11852.    when you make changes, it is updated; if it does not exist, QuickBASIC
  11853.    creates it. QuickBASIC uses its default settings in the absence of the
  11854.    QB.INI file.
  11855.  
  11856.  
  11857.  20.1  Display Command
  11858.  
  11859.    When you choose the Display command, the Display dialog box appears. It
  11860.    allows you to set the background color, foreground color, and the number
  11861.    of spaces the TAB key advances the cursor in the View window. The dialog
  11862.    box also lets you decide whether or not scroll bars appear in the View
  11863.    window. See Figure 20.1.
  11864.  
  11865.  
  11866.    Types of text to change              Color options for        Color options
  11867.     │                                   foreground text          for backgroun
  11868.    ┌┼─────────────────────────────── Display ──┼──────────────────────────┼───
  11869.    ││ ┌────────────────────────────── Colors ──┼──────────────────────────┼┐
  11870.    ││ │                                        │  Foreground   Background ││
  11871.    ││ │                                        │ ┌─────────┐  ┌─────────┐ ││
  11872.    ││ │ ┌(∙) 1.  Normal Text                   │┌┼─Black     │ Black   ┐││
  11873.    ││ │ │                                      └┤│ White   ▒  │ White   ▒├┘│
  11874.    │└─┼─┤( ) 2.  Current Statement              ││ Gray    ▒  │ Gray    ▒│ │
  11875.    │  │ │                                       └┼─BrWhite ▒  │ BrWhite ▒┘ │
  11876.    │  │ └( ) 3.  Breakpoint Lines                │         ▒  │         ▒  │
  11877.    │  │                                          │         ▒  │         ▒  │
  11878.    │  │                                          │         ▒  │         ▒  │
  11879.    │  │                                          │           │           │
  11880.    │  │                                          └─────────┘  └─────────┘  │
  11881.    │  │                                                                    │
  11882.    │  └────────────────────────────────────────────────────────────────────┘
  11883.    │
  11884.    │  ┌───────────────────────── Display Options ──────────────────────────┐
  11885.    │  │    [X] Scroll Bars                             Tab Stops: 8        │
  11886.    │  └─────┼─────────────────────────────────────────────────────┼────────┘
  11887.    ├────────┼─────────────────────────────────────────────────────┼───────────
  11888.    │        │     < OK >           < Cancel >           < Help >  │
  11889.    └────────┼─────────────────────────────────────────────────────┼───────────
  11890.    Turn scroll bars on when checked      Number of spaces the TAB key advances
  11891.  
  11892.    Figure 20.1  Display Dialog Box
  11893.  
  11894.    Follow these steps to change the background and foreground colors:
  11895.  
  11896.    1. Move the cursor to the parentheses preceding the color setting you want
  11897.       to change (Normal Text, Current Statement, or Breakpoint Lines).
  11898.  
  11899.    2. Press TAB. The cursor moves to the Foreground Color list box. Use the
  11900.       DIRECTION keys to select the new foreground color for the item you
  11901.       chose in step 1. The list box item you have selected changes to reflect
  11902.       the colors you choose.
  11903.  
  11904.    3. Press TAB again to move to the Background Color list box, then repeat
  11905.       the color selection process in step 2 for the background color.
  11906.  
  11907.    4. Press ENTER.
  11908.  
  11909.    QuickBASIC now reflects your changes.
  11910.  
  11911.    The Display Options portion of the Display dialog box controls the scroll
  11912.    bar and TAB key settings. You can turn the View window's scroll bars on
  11913.    and off by pressing the SPACEBAR when your cursor is in the Scroll Bars
  11914.    check box (the default setting is "on"). The Tab Stops option controls the
  11915.    number of spaces the TAB key advances the cursor. Use the setting you find
  11916.    most helpful for improving the readability of your programs.
  11917.  
  11918.  
  11919.  20.2  Set Paths Command
  11920.  
  11921.    The Set Paths command changes the default search paths for specified types
  11922.    of files.
  11923.  
  11924.    You may want to keep all files of a particular type within a single
  11925.    directory for organizational purposes. For example, you might wish to keep
  11926.    all of QuickBASIC's libraries and any of your own Quick libraries within a
  11927.    specific subdirectory or subdirectories of your QuickBASIC disk or
  11928.    directory. Since the environment requires access to its libraries, you
  11929.    would ordinarily need to provide a path name for each library used.
  11930.  
  11931.    The Set Paths dialog box lets you type in a search path (up to 127
  11932.    characters) for your files. This saves you from fully qualifying each path
  11933.    name every time you access a library or other files not in the current
  11934.    working directory.
  11935.  
  11936.    For example, suppose you keep all of your include files and programs in a
  11937.    directory named QB──BI, which is in a directory named QB──45 on a disk in
  11938.    your A drive. You would take the following steps to direct QuickBASIC to
  11939.    automatically look in that directory any time it searched for a file with
  11940.    the .BI or .BAS extension:
  11941.  
  11942.    1. Choose the Set Paths command on the Options menu. A dialog box appears.
  11943.  
  11944.    2. Press the TAB key to move the cursor to the Include files text box.
  11945.  
  11946.    3. Type in the path name:
  11947.  
  11948.       A: QB──45QB──BI
  11949.  
  11950.       See Figure 20.2.
  11951.  
  11952.  
  11953.                                           Path to directory
  11954.                                           containing files
  11955.                                                   │
  11956.       ┌───────────────────────────── Set Paths ───┼───────────────────────────
  11957.       │  Search Path For:                         │
  11958.       │ ┌─                 ┌──────────────────────┼───────────────────────────
  11959.       │ │Executable files: │                      │
  11960.       │ │ (.EXE, .COM)     └──────────────────────┼───────────────────────────
  11961.       │ │                                         │
  11962.       │ │                  ┌──────────────────────┼───────────────────────────
  11963.       │ │Include files:    │A;\QB_45\QB_BI ───────┘
  11964.       │ │ (.BI, .BAS)      └──────────────────────────────────────────────────
  11965.       │┌┤
  11966.       │││                  ┌──────────────────────────────────────────────────
  11967.       │││Library files:    │
  11968.       │││ (.LIB, .QLB)     └──────────────────────────────────────────────────
  11969.       │││
  11970.       │││                  ┌──────────────────────────────────────────────────
  11971.       │││Help file:        │
  11972.       ││└─(.HLP)           └──────────────────────────────────────────────────
  11973.       ├┼──────────────────────────────────────────────────────────────────────
  11974.       ││            < OK >            < Cancel >            < Help >
  11975.       └┼──────────────────────────────────────────────────────────────────────
  11976.        │
  11977.       File types
  11978.  
  11979.       Figure 20.2  Set Paths Dialog Box
  11980.  
  11981.    4. Press ENTER.
  11982.  
  11983.    ──────────────────────────────────────────────────────────────────────────
  11984.    NOTE
  11985.      The search paths you enter in the Set Paths dialog box do not change
  11986.      paths or environment variables previously set at the DOS level with the
  11987.      DOS PATH and SET commands. However, paths set with Set Paths are in
  11988.      effect whenever you are using QuickBASIC.
  11989.    ──────────────────────────────────────────────────────────────────────────
  11990.  
  11991.  
  11992.  20.3  Right Mouse Command (Full Menus Only)
  11993.  
  11994.    The Right Mouse command lets you change the effect of clicking the right
  11995.    mouse button.
  11996.  
  11997.    When you choose the Right Mouse command, the dialog box in Figure 20.3
  11998.    appears.
  11999.  
  12000.  
  12001.                                  Functions for
  12002.                                  right mouse button
  12003.    ┌─────────────── Right Mouse ──────────┼─────┐
  12004.    │                                      │     │
  12005.    │  On right mouse button click:        │     │
  12006.    │                                  ──┐ │     │
  12007.    │        (∙) Context-sensitive Help  │ │     │
  12008.    │                                    ├─┘     │
  12009.    │        ( ) Execute up to this line │       │
  12010.    │                                  ──┘       │
  12011.    ├────────────────────────────────────────────┤
  12012.    │     < OK >     < Cancel >     < Help >     │
  12013.    └────────────────────────────────────────────┘
  12014.  
  12015.    Figure 20.3  Right Mouse Dialog Box
  12016.  
  12017.    The Right Mouse dialog box lets you select one of two functions for the
  12018.    right mouse button:
  12019.  
  12020.    ■ Invoking on-line help (same function as the Topic command on the Help
  12021.      menu). This is the default setting.
  12022.  
  12023.    ■ Executing the program from the beginning of the program to the current
  12024.      cursor location.
  12025.  
  12026.    Both functions have advantages in different situations. You may find the
  12027.    Help function more useful when you are writing your program, especially if
  12028.    you are new to QuickBASIC. During debugging, you may find the execution
  12029.    feature more valuable.
  12030.  
  12031.    If you use the Context-sensitive Help option, remember that the subject of
  12032.    the help is the word containing the cursor.
  12033.  
  12034.  
  12035.  20.4  Syntax Checking Command(Full Menus Only)
  12036.  
  12037.    The Syntax Checking command on the Options menu toggles automatic syntax
  12038.    checking on and off.
  12039.  
  12040.    QuickBASIC defaults to the "on" setting, indicated by a bullet (■) next to
  12041.    the command. To turn syntax checking off, choose the Syntax Checking
  12042.    command; the bullet disappears. QuickBASIC records your options when you
  12043.    quit. If you exit QuickBASIC with syntax-checking off, it will remain off
  12044.    the next time you start QuickBASIC.
  12045.  
  12046.    When on, this feature checks the syntax of each line when it is entered.
  12047.  
  12048.    See Also
  12049.  
  12050.    Section 12.5.2, "Automatic Syntax Checking"
  12051.  
  12052.  
  12053.  20.5  Full Menus Command
  12054.  
  12055.    The Full Menus command toggles QuickBASIC's extended menus on and off.
  12056.    When Full Menus is toggled on, a bullet (■) appears next to the command.
  12057.  
  12058.    You can use QuickBASIC's menus in either their "easy" or "full" form. In
  12059.    their easy form, the menus contain all of the functions necessary to
  12060.    create beginning to intermediate-level programs. Some advanced features do
  12061.    not appear under Easy Menus in order to simplify the use of the
  12062.    environment for programmers new to QuickBASIC. Full Menus include an
  12063.    additional item (the Calls menu) and more commands under each of the other
  12064.    menus. Once you are comfortable with QuickBASIC and need advanced
  12065.    features, use the Full Menus option.
  12066.  
  12067.    When you exit, QuickBASIC saves all of the options you have selected,
  12068.    including Display options, Search Paths, Syntax Checking, and Full Menus.
  12069.    When you next return to QuickBASIC your choices will still be active.
  12070.  
  12071.  
  12072.  
  12073.  ────────────────────────────────────────────────────────────────────────────
  12074.  Chapter 21  The Help Menu
  12075.  
  12076.    Choosing commands on the Help menu is one way to access QuickBASIC's
  12077.    on-line help. (For information on other methods of accessing on-line help,
  12078.    see Section 10.8, "Using Help.")
  12079.  
  12080.    The Help menu contains the following commands:
  12081.  
  12082.    ■ Index. Displays an alphabetical list of QuickBASIC keywords and a brief
  12083.      description of each.
  12084.  
  12085.    ■ Contents. Displays a visual outline of the on-line help contents.
  12086.  
  12087.    ■ Topic. Provides syntax and usage information on specific variables and
  12088.      QuickBASIC keywords.
  12089.  
  12090.    ■ Help On Help. Describes how to use on-line help and common keyboard
  12091.      shortcuts.
  12092.  
  12093.  
  12094.  21.1  Index Command
  12095.  
  12096.    The Index command displays an alphabetical list of the QuickBASIC
  12097.    keywords. To receive information on a particular keyword, move the cursor
  12098.    to the line containing that keyword and press F1. QuickBASIC displays the
  12099.    Help window for that keyword.
  12100.  
  12101.    You can scroll through the keyword list or jump directly to a specific
  12102.    letter in the list. For example, if you type G, QuickBASIC moves the
  12103.    cursor to GET, the first keyword beginning with the letter "G." See Figure
  12104.    21.1.
  12105.  
  12106.  
  12107.    ┌──────────────── HELP: QuickBASIC Language Keyword Index ────────────┤├──
  12108.    │                                                               ╔═══╗
  12109.    │═══════════════════════════════════════════════════════════════╣ G ║
  12110.    │                                                               ╚═══╝
  12111.    │    GET Statement
  12112.    │    GOSUB Statement
  12113.    │    GOTO Statement
  12114.    │                                                               ╔═══╗
  12115.    ╞═══════════════════════════════════════════════════════════════╣ H ║
  12116.    │                                                               ╚═══╝
  12117.    │    HEX$ Function
  12118.    │                                                               ╔═══╗
  12119.    ╞═══════════════════════════════════════════════════════════════╣ I ║
  12120.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  12121.  
  12122.    Figure 21.1  Index Entries for Help
  12123.  
  12124.    See Also
  12125.  
  12126.    Section 21.3, "Topic Command"
  12127.  
  12128.  
  12129.  21.2  Contents Command
  12130.  
  12131.    The Contents command displays a table of contents for on-line help. It
  12132.    provides hints on using the QuickBASIC environment and the BASIC language,
  12133.    along with useful tables. From here you can transfer to the subject that
  12134.    interests you. See Figure 21.2.
  12135.  
  12136.  
  12137.       File  Edit  View  Search  Run  Debug  Calls  Options              Help
  12138.    ┌──────────────────────── HELP: Table of Contents ────────────────────┤├──
  12139.    │  Help on Help  Contents  Index  Product Support  Copyright
  12140.    │──────────────────────────────────────────────────────────────────────────
  12141.    │Using QuickBASIC                   BASIC Programming Language
  12142.    │
  12143.    │     Shortcut Key Summary               Functional Keyword Lists
  12144.    │         Edit Keys                      Syntax Notation Conventions
  12145.    │         View Keys
  12146.    │         Search Keys                    Fundamental Building Blocks
  12147.    │         Run and Debug Keys             Data Types
  12148.    │         Help Keys                      Expressions and Operators
  12149.    │                                          Modules and Procedures
  12150.    │     Limits to QuickBASIC               Programs
  12151.    │     VErsion 4.5 Differences
  12152.    │                                          ASCII Character Codes
  12153.    │     Survival Guide                     Keyboard Scan Codes
  12154.    │
  12155.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  12156.  
  12157.    Figure 21.2  Table of Contents for Help
  12158.  
  12159.    For detailed information on a particular topic, place your cursor on the
  12160.    topic and press F1. QuickBASIC displays on-line help on that topic.
  12161.  
  12162.    For example, the Table of Contents window shows several entries under
  12163.    "Using QuickBASIC." If you move the cursor to "Editing keys" and press F1,
  12164.    a screen appears with the most frequently used editing shortcut keys.
  12165.  
  12166.  
  12167.  21.3  Topic Command
  12168.  
  12169.    The Topic command provides specific information on the syntax and usage of
  12170.    the QuickBASIC variable, symbol, keyword, menu, command, or dialog box at
  12171.    or containing the cursor. When the Topic command is active, the subject on
  12172.    which it will provide on-line help appears after the word Topic. Choosing
  12173.    the Topic command is the same as pressing F1.
  12174.  
  12175.    You can get help on any keyword or variable at any time by typing the word
  12176.    or name and immediately choosing the Topic command.
  12177.  
  12178.    If you choose the Topic command whenever you encounter a syntax error, you
  12179.    can immediately correct the usage of your statement. For example, suppose
  12180.    you enter the line below, which is missing the word TO and instead
  12181.    contains a comma:
  12182.  
  12183.    FOR i% = 1,10
  12184.  
  12185.    QuickBASIC flags the syntax error with the message Expected: TO. Press F1
  12186.    or the Help button for help on the error itself. For information on the
  12187.    keyword FOR, move the cursor to the FOR statement and choose the Topic
  12188.    command. QuickBASIC keeps your program code visible at the bottom of the
  12189.    screen. See Figure 21.3.
  12190.  
  12191.  
  12192.       File  Edit  View  Search  Run  Debug  Calls  Options              Help
  12193.    ┌───────────────── HELP: FOR...NEXT Statement QuickSCREEN ────────────┤├──
  12194.    │  QuickSCREEN     Detail      Example      Contents     Index
  12195.    │──────────────────────────────────────────────────────────────────────────
  12196.    │FOR...NEXT - a control flow statement that repeats a block of
  12197.    │             statements a specified number of times
  12198.    │Syntax
  12199.    │  FOR counter = start TO and [STEP increment]
  12200.    │    [statements]
  12201.    │  NEXT [counter [,counter...]]
  12202.    │
  12203.    │  ■ counter is a numeric variable used as the loop counter
  12204.    │  ■ start is the initial value and end is the final value of the counter
  12205.    │  ■ increment is the amount the counter is incremented each time
  12206.    │    through the loop
  12207.    │
  12208.    │See Also  EXIT FOR  DO...LOOP  WHILE...WEND
  12209.    │
  12210.    ├──────────────────────────────── Untitled ───────────────────────────┤├──
  12211.    │FOR i% = 1,10
  12212.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  12213.    ├─────────────────────────────── Immediate ────────────────────────────────
  12214.    │
  12215.    │
  12216.     <Shift+F1=Help> <F6=Window> <F2=Subs> <F5=Run> <F8=Step>      C  00001:003
  12217.  
  12218.    Figure 21.3  Help on the FOR...NEXT Statement
  12219.  
  12220.    To copy sample code from the FOR help screen into your program, do the
  12221.    following:
  12222.  
  12223.    1. Choose the Example hyperlink at the top of the window.
  12224.  
  12225.    2. Select the example code and choose Copy from the Edit menu.
  12226.  
  12227.    3. Press ESC to close the Help window.
  12228.  
  12229.    4. Move the cursor to the place in your program you want the text to
  12230.       appear, and choose Paste from the Edit menu.
  12231.  
  12232.    You can customize the pasted code or use it as it is.
  12233.  
  12234.    Shortcut Key
  12235.  
  12236.    F1
  12237.  
  12238.  
  12239.  21.4  Help On Help Command
  12240.  
  12241.    The Help on Help command describes how to use the QuickBASIC on-line help
  12242.    system.
  12243.  
  12244.    The Help on Help screen gives a description of the main help features. For
  12245.    more specific information, press ESC to exit Help on Help, and use the
  12246.    Topic command on the Help menu or press F1.
  12247.  
  12248.  
  12249.       File  Edit  View  Search  Run  Debug  Calls  Options              Help
  12250.    ┌─────────────────────────── HELP: Help on Help ──────────────────────┤├──
  12251.    │  Help on Help  Contents  Index  Product Support
  12252.    │──────────────────────────────────────────────────────────────────────────
  12253.    │  Use Help as follows:
  12254.    │
  12255.    │    ■ To get help anytime, press F1 or click the right mouse button.
  12256.    │    ■ To get help on any part of a BASIC statement, a QuickBASIC menu item
  12257.    │      or dialog box, position the cursor there press F1.
  12258.    │    ■ To remove the help information from the screen, press ESC.
  12259.    │    ■ To scroll help information, press PGDN.
  12260.    │
  12261.    │  Look for the help display in either
  12262.    │    ■ The Help window at the top of the screen
  12263.    │    ■ A dialog box which pops up in the center of the screen
  12264.    │
  12265.    │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  12266.  
  12267.    Figure 21.4  Help on Help Screen
  12268.  
  12269.    Shortcut Key
  12270.  
  12271.    SHIFT+F1
  12272.  
  12273.  
  12274.  
  12275.  ────────────────────────────────────────────────────────────────────────────
  12276.  Glossary
  12277.  
  12278.    The purpose of this glossary is to define unique terms used in all the
  12279.    manuals that accompany QuickBASIC Version 4.5. Neither the individual
  12280.    definitions nor the list of terms is intended to be a comprehensive
  12281.    dictionary of computer-science terminology.
  12282.  
  12283.  8087, 80287, or 80387 coprocessor   Intel(R) hardware products dedicated to
  12284.      very fast number processing.
  12285.  
  12286.  absolute coordinates  Horizontal and vertical distances from the screen's
  12287.      upper-left corner, which has the coordinates (0,0). Absolute coordinates
  12288.      are measured in pixels. See also "physical coordinates."
  12289.  
  12290.  address  A location in memory.
  12291.  
  12292.  algorithm  A step-by-step procedure for solving a problem or computing a
  12293.      result.
  12294.  
  12295.  animation  A QuickBASIC debugging feature in which each line in a running
  12296.      program is highlighted as it executes. The Trace On command from the
  12297.      Debug menu turns on animation.
  12298.  
  12299.  argument  A data item supplied to a BASIC statement, function, procedure, or
  12300.      program. In the following example, the string "Hello" is an argument to
  12301.      the BASIC statement PRINT: "Hello". An argument may be a constant or a
  12302.      variable. Arguments are often used to pass information from one part of
  12303.      a program to another. Use the COMMAND$ function to make DOS command line
  12304.      arguments available to the programs.
  12305.  
  12306.  arithmetic conversion   Converting numbers between integral and
  12307.      floating-point types.
  12308.  
  12309.  array   A sequentially numbered set of elements with the same type.
  12310.  
  12311.  array bounds   The upper and lower limits of the dimensions of an array.
  12312.  
  12313.  ASCII (American Standard Code for Information Interchange)  A set of 256
  12314.      codes that many computers use to represent letters, digits, special
  12315.      characters, and other symbols. Only the first 128 of these codes are
  12316.      standardized; the remaining 128 are special characters that are defined
  12317.      by the computer manufacturer.
  12318.  
  12319.  aspect ratio  The ratio of a video screen's width to its height. This term
  12320.      is also frequently used to describe pixels. If you think of a pixel as
  12321.      being rectangular, its aspect ratio would be the ratio of its width to
  12322.      height. A typical IBM PC display has an aspect ratio of about 4:3.
  12323.  
  12324.  assignment  The process of transferring a value to a variable name. The
  12325.      statement X = 3 assigns x a value of 3.
  12326.  
  12327.  attributes  Color, intensity, blinking, and other displayed characteristics
  12328.      of characters or pixels.
  12329.  
  12330.  automatic variable  A variable in a SUB or FUNCTION procedure whose value is
  12331.      not saved between invocations of the procedure. Automatic variables are
  12332.      frequently used in recursive procedures where you do not want values
  12333.      saved between calls.
  12334.  
  12335.  base name  The part of a file name before the extension. For example, SAMPLE
  12336.      is the base name of the file SAMPLE.BAS.
  12337.  
  12338.  binary  A mathematical term referring to the base-two numbering system,
  12339.      which uses only two digits: 0 and 1.
  12340.  
  12341.  binary file  In input/output operations, files or data that contain
  12342.      nonprinting characters as well as ordinary ASCII characters. Binary file
  12343.      access is the ability to access any byte within a file, treating it as a
  12344.      numeric value rather than as text.
  12345.  
  12346.  BIOS (Basic Input/Output System)  Machine-language programs built into a
  12347.      computer. These programs provide the lowest level of operations in a
  12348.      computer system. You can use the BIOS programs directly with the
  12349.      INTERRUPT and CALL INTERRUPTX statements.
  12350.  
  12351.  bit  The smallest unit of information used with computers; corresponds to a
  12352.      binary digit (either 0 or 1). Eight bits make up one byte.
  12353.  
  12354.  block  A sequence of declarations, definitions, and statements.
  12355.  
  12356.  breakpoint  A specified location where program execution will halt during
  12357.      debugging. See "watchpoint" for a description of variable breakpoints.
  12358.  
  12359.  byte  The unit of measure used for computer memory and data storage. One
  12360.      byte contains eight bits and can store one character (a letter, number,
  12361.      punctuation mark, or other symbol).
  12362.  
  12363.  call by reference  See "pass by reference."
  12364.  
  12365.  call by value   See "pass by value."
  12366.  
  12367.  CGA (Color Graphics Adapter)   A video adapter capable of displaying text
  12368.      characters or graphics pixels. Color can also be displayed with the
  12369.      appropriate display monitor.
  12370.  
  12371.  character string  A group of characters enclosed in quotation marks ( " " ).
  12372.  
  12373.  check box  A pair of brackets on a QuickBASIC dialog box where you turn an
  12374.      option on or off. An X appears in the box when the option is on.
  12375.  
  12376.  choose  To carry out a command by performing an action such as using a
  12377.      command button from a dialog box or an item from a menu.
  12378.  
  12379.  click  To press and release one of the mouse buttons (usually while pointing
  12380.      the mouse cursor at an object on the screen).
  12381.  
  12382.  Clipboard  A storage area that holds copied or cut text. Text does not
  12383.      accumulate in the Clipboard: new text added to the Clipboard replaces
  12384.      any text that was already there. You can use the Paste command to insert
  12385.      text from the Clipboard into a file.
  12386.  
  12387.  communications port  See "port."
  12388.  
  12389.  compile  To translate statements into a form that the computer can execute.
  12390.  
  12391.  compiler  A program that translates statements into a language understood by
  12392.      the computer.
  12393.  
  12394.  constant  A value that does not change during program execution.
  12395.  
  12396.  current directory  The directory in which DOS looks for files unless
  12397.      otherwise instructed.
  12398.  
  12399.  current drive  The drive containing the disk on which DOS looks for a
  12400.      directory or file unless otherwise instructed.
  12401.  
  12402.  cursor  The blinking line or box on the screen. The cursor indicates the
  12403.      current location where text from the keyboard will appear.
  12404.  
  12405.  data  The numbers and text processed by a computer in doing its work.
  12406.  
  12407.  data file  A file that contains the data used or generated by a program;
  12408.      data can be numbers, text, or a combination of the two.
  12409.  
  12410.  debugger  A program that helps to locate the source of problems discovered
  12411.      during run-time testing of a program.
  12412.  
  12413.  declaration  A construct that associates the name and characteristics of a
  12414.      variable, function, or type.
  12415.  
  12416.  DEF FN function  The object defined by a single-line DEF FN statement or by
  12417.      a DEF FN...END DEF block. (A FUNCTION procedure is generally preferred
  12418.      to a DEF FN function because a procedure is more portable and modular.)
  12419.  
  12420.  default  A setting that is assumed unless you specify otherwise.
  12421.  
  12422.  default data type  The type that BASIC uses for data unless you use a
  12423.      DEFtype statement to specify otherwise. The default type for numeric
  12424.      data is single precision.
  12425.  
  12426.  DEFtype  A name used in these manuals for the group of BASIC statements that
  12427.      redefine a program's default variable type (DEFDBL, DEFINT, DEFLNG,
  12428.      DEFSNG, DEFSTR).
  12429.  
  12430.  device  A piece of computer equipment, such as a display or a printer, that
  12431.      performs a specific task.
  12432.  
  12433.  device name  The name by which DOS refers to a device (for example, PRN,
  12434.      LPT1, LPT2, or LPT3 for a printer). Device names are treated like file
  12435.      names by DOS.
  12436.  
  12437.  dialog box  A box that appears when you choose a menu command that requires
  12438.      additional information.
  12439.  
  12440.  dimension  The number of subscripts required to specify a single array
  12441.      element. For instance, the statement DIM A$(4,12) declares a
  12442.      two-dimensional array, while DIM B$(16,4,4) declares a three-dimensional
  12443.      array.
  12444.  
  12445.  DIRECTION keys  A set of keys, found on many computer keyboards, that move
  12446.      the cursor left, right, up, or down on the screen. These keys usually
  12447.      have arrows on their key tops.
  12448.  
  12449.  directory  The index of files that DOS maintains on a disk.
  12450.  
  12451.  document  A way of classifying a file as text when you load it into the
  12452.      QuickBASIC editor. Loading a file as a document turns off syntax
  12453.      checking, capitalization of keywords, and other smart-editor features.
  12454.      You can load a BASIC program as a document if you want to edit it as you
  12455.      would with a word processor.
  12456.  
  12457.  double click  To press the mouse button twice quickly (usually while
  12458.      pointing the mouse cursor at an object on the screen).
  12459.  
  12460.  double precision  A real (floating-point) value that occupies eight bytes of
  12461.      memory. Double-precision values are accurate to 15 or 16 digits.
  12462.  
  12463.  drag  Pointing the mouse cursor at an object on the screen and pressing a
  12464.      mouse button, then moving the mouse while holding the button down. The
  12465.      object moves in the direction of the mouse movement. When the item is
  12466.      where you want it, release the button.
  12467.  
  12468.  dynamic array  An array whose memory location is allocated when the program
  12469.      runs. The locations are not predetermined and can change during the
  12470.      course of program execution.
  12471.  
  12472.  EGA (Enhanced Graphics Adapter)  A video adapter capable of displaying in
  12473.      all the modes of the color graphics adapter (CGA) and many additional
  12474.      modes. The EGA supports both text and graphics at medium resolution in
  12475.      up to 64 colors.
  12476.  
  12477.  emulator  A floating-point math package that uses software to perform the
  12478.      same operations as a hardware math coprocessor.
  12479.  
  12480.  enabled event  An event for which QuickBASIC actively checks. Events are
  12481.      enabled by the ON event statements.
  12482.  
  12483.  event  An action the computer can be programmed to detect. Events include
  12484.      items such as mouse clicks, menu selections, keyboard activity, and time
  12485.      passage.
  12486.  
  12487.  event trapping  To detect and respond to events, for example, to branch to
  12488.      an appropriate routine.
  12489.  
  12490.  executable file  A file with the extension .EXE, .COM, or .BAT. Executable
  12491.      files can be run by typing the file name at the DOS prompt.
  12492.  
  12493.  execute  To run a program or carry out a specific statement in the Immediate
  12494.      window.
  12495.  
  12496.  exponentiation  The raising of a number x to a power y; the number x is
  12497.      multiplied by itself y times. For example, 2^3 is 2 * 2 * 2, or 2 raised
  12498.      to the power of 3.
  12499.  
  12500.  expression  A combination of operands and operators that yields a single
  12501.      value.
  12502.  
  12503.  extension  The part of a file name following the period. For example, .DAT
  12504.      is the extension in the file name TEST.DAT.
  12505.  
  12506.  far address  A memory location specified by using a segment (a location of a
  12507.      64K block) and an offset from the beginning of the segment. Far
  12508.      addresses require four bytes──two for the segment, and two for the
  12509.      offset. A far address is also known as a segmented address.
  12510.  
  12511.  file buffer   An area in memory in which temporary data are stored.
  12512.      QuickBASIC keeps a copy of the file in a buffer and changes it as you
  12513.      edit. This buffer is copied to disk when you save the file.
  12514.  
  12515.  filespec  The complete specification of a file. The filespec can include a
  12516.      drive letter, path name, file name, and extension.
  12517.  
  12518.  flags register  A register containing information about the status of the
  12519.      central processing unit and the last operation performed.
  12520.  
  12521.  floating point  Notation, similar to scientific notation, that is a
  12522.      convenient method for expressing very large numbers, very small numbers,
  12523.      or numbers with fractions. A floating-point number has two parts: an
  12524.      exponent and a fractional part known as the mantissa. See "IEEE format."
  12525.  
  12526.  formal parameters  Variables that receive the arguments passed to a function
  12527.      or subprogram. See "parameter."
  12528.  
  12529.  FUNCTION  A block of statements beginning with FUNCTION and ending with END
  12530.      FUNCTIONthat defines a procedure. FUNCTION procedures can be used
  12531.      instead of the DEF FN functions used in older forms of BASIC.
  12532.  
  12533.  function declaration  A declaration that establishes the name and type of a
  12534.      function. The function itself is defined explicitly elsewhere in the
  12535.      program.
  12536.  
  12537.  function definition  A statement block that specifies a function's name, its
  12538.      formal parameters, and the declarations and statements that define what
  12539.      it does (i.e., carry out the function).
  12540.  
  12541.  global constant  A constant available throughout a program. Symbolic
  12542.      constants defined in the module-level code are global constants.
  12543.  
  12544.  global symbol  A symbol available throughout a program. Function names are
  12545.      always global symbols. See also "symbol" and "local symbol."
  12546.  
  12547.  global variable  A variable available throughout a program. Global variables
  12548.      can be declared in COMMON, DIM, or REDIM statements by using the SHARED
  12549.      attribute.
  12550.  
  12551.  heap  An area of random-access memory used by BASIC to store, among other
  12552.      things, variables and arrays.
  12553.  
  12554.  hexadecimal  The base-16 numbering system whose digits are 0 through F (the
  12555.      letters A through F represent the digits 10 through 15). Hexadecimal
  12556.      numbers are often used in computer programming because they are easily
  12557.      converted to and from binary, the base-2 numbering system the computer
  12558.      itself uses.
  12559.  
  12560.  highlight  A reverse-video area in a text box, window, or menu marking the
  12561.      current command chosen or the text that has been selected for copying or
  12562.      deleting.
  12563.  
  12564.  hyperlink  A link between two related pieces of information. Hyperlinks
  12565.      appear between two triangles in help screens.
  12566.  
  12567.  I/O redirection  See "redirect."
  12568.  
  12569.  IEEE format  An international standard method of representing floating-point
  12570.      numbers in the computer's hardware. IEEE format gives more accurate
  12571.      results than the Microsoft Binary format used in earlier versions of
  12572.      QuickBASIC and makes it easier to use a math coprocessor. The acronym
  12573.      IEEE stands for Institute of Electrical and Electronics Engineers, the
  12574.      organization that developed this standard. See "floating point."
  12575.  
  12576.  Immediate window  The area at the bottom of the QuickBASIC screen used to
  12577.      enter statements and execute them immediately.
  12578.  
  12579.  include file  A text file that is translated into a program with the
  12580.      $INCLUDE metacommand.
  12581.  
  12582.  input/output (I/O)  A term that refers to the devices and processes involved
  12583.      in the computer's reading (input) and writing (output) data.
  12584.  
  12585.  input  The data that a program reads.
  12586.  
  12587.  insert mode  A mode for inputting data to the QuickBASIC environment. In
  12588.      this mode, you can insert new characters rather than replace characters
  12589.      already in the file as they are entered.
  12590.  
  12591.  integer  A whole number represented inside the machine as a 16-bit two's
  12592.      complement binary number. An integer has a range of -32,768 to +32,767.
  12593.      See "long integer."
  12594.  
  12595.  interface  The boundary between two systems or entities, such as a disk
  12596.      drive and the computer, or the user and a program.
  12597.  
  12598.  interpreter  A program that translates and executes one BASIC statement at a
  12599.      time. An interpreter translates a statement every time it executes the
  12600.      statement. BASICA is a language interpreter. By comparison, a compiler
  12601.      translates all statements prior to executing any.
  12602.  
  12603.  keyword  The name of a BASIC statement, function, or operator. Examples of
  12604.      keywords are MOD, OPEN, OR, PRINT, and SIN.
  12605.  
  12606.  label  An identifying string that marks, precedes, or denotes a specific
  12607.      location in a program. Labels are used by GOTO statements.
  12608.  
  12609.  link  To resolve references among the modules in a program and from the
  12610.      program to library routines. The link step results in a complete program
  12611.      ready for execution.
  12612.  
  12613.  list box  A box that lists a series of items. For example, the box that
  12614.      lists files in the Open Program dialog box is a list box. See also
  12615.      "dialog box."
  12616.  
  12617.  local constant  A constant whose scope is limited to a particular unit of
  12618.      code, such as the module-level code, or a procedure within a module. All
  12619.      constants defined in CONST statements inside a procedure are local
  12620.      constants. See "global constant."
  12621.  
  12622.  local symbol  A symbol that has value only within a particular function. A
  12623.      function argument or a variable declared as static within a function can
  12624.      be a local symbol. See also "global symbol."
  12625.  
  12626.  local variable  A variable whose scope is confined to a particular unit of
  12627.      code, such as the module-level code, or a procedure within a module. All
  12628.      variables in a procedure are local unless they appear in a SHARED
  12629.      statement within the procedure, or in a COMMON SHARED, DIM SHARED, or
  12630.      REDIM SHARED statement at the module level of the module containing the
  12631.      procedure definition. See "global constant."
  12632.  
  12633.  logical device  A symbolic name for a device that the user can cause to be
  12634.      mapped to any physical (actual) device.
  12635.  
  12636.  long integer  A whole number represented inside the machine by a 32-bit
  12637.      two's complement value. Long integers have a range of -2,147,483,648 to
  12638.      +2,147,483,647. See "integer."
  12639.  
  12640.  LPT1, LPT2, LPT3  Abbreviations for line printer. The names refer to the
  12641.      three ports to which parallel printers can be attached.
  12642.  
  12643.  main module  The module containing the first executable statement (the
  12644.      program's entry point). See "module."
  12645.  
  12646.  math coprocessor  An optional hardware component, such as an 8087, 80287, or
  12647.      80387 chip, that improves the speed of floating-point arithmetic.
  12648.      QuickBASIC automatically takes advantage of a math coprocessor if it is
  12649.      present, or emulates it in software if it is not. See "floating point."
  12650.  
  12651.  MCGA (Multicolor Graphics Array)  A printed-circuit card that controls the
  12652.      display. The MCGA card, located in the system unit of a computer, shows
  12653.      both text and graphics at low to medium resolution in up to 256 colors.
  12654.  
  12655.  MDA (Monochrome Display Adapter)  A printed-circuit card that controls the
  12656.      display. The MDA shows text only at medium resolution in one color.
  12657.  
  12658.  menu bar  The bar at the top of the QuickBASIC display containing the menu
  12659.      titles.
  12660.  
  12661.  metacommands  Special commands, enclosed in comments in a source file, that
  12662.      tell the compiler to take certain actions while it is compiling the
  12663.      program. For example, the $INCLUDE metacommand tells the compiler to
  12664.      translate statements found in a specified file. See "include file."
  12665.  
  12666.  Microsoft Binary format  A method of representing floating-point numbers
  12667.      internally. Microsoft Binary format is used by versions of QuickBASIC
  12668.      prior to Version 3.0. See "floating point" and "IEEE format."
  12669.  
  12670.  modular programming  An approach to programming in which the program is
  12671.      divided into functional blocks, each performing a specific task.
  12672.  
  12673.  module  A section of program code that is stored in a separate file and can
  12674.      be separately compiled. Every program has at least one module (the main
  12675.      module).
  12676.  
  12677.  module-level code  Program statements within any module that are outside
  12678.      a FUNCTION or SUB definition. Error- or event-handling code and
  12679.      declarative statements such asCOMMON, DECLARE, and TYPE can appear only
  12680.      at the module level.
  12681.  
  12682.  mouse  A pointing device that fits under your hand and rolls in any
  12683.      direction on a flat surface. By moving the mouse, you move the mouse
  12684.      cursor in a corresponding direction on the screen.
  12685.  
  12686.  mouse cursor  The reverse-video rectangle that moves to indicate the current
  12687.      position of the mouse. The mouse cursor appears only if a mouse is
  12688.      installed.
  12689.  
  12690.  multidimensional array  An array of with more than one subscript, for
  12691.      example, x(5,35). A multidimensional array is sometimes referred to as
  12692.      an array of arrays.
  12693.  
  12694.  near address  A memory location specified by using only the offset from the
  12695.      start of the segment. A near address requires only two bytes of memory.
  12696.      See also "far address."
  12697.  
  12698.  null character  The ASCII character encoded as the value 0.
  12699.  
  12700.  object file  A file (with the extension .OBJ) containing relocatable machine
  12701.      code produced by compiling a program and used by the linker to generate
  12702.      an executable file.
  12703.  
  12704.  offset  The number of bytes from the beginning of a segment in memory to a
  12705.      particular byte in that segment.
  12706.  
  12707.  operand  A constant or variable value that is manipulated in an expression.
  12708.  
  12709.  operator  One or more symbols that specify how the operand or operands of an
  12710.      expression are manipulated.
  12711.  
  12712.  output  The result of a program's processing, usually based on some form of
  12713.      input data.
  12714.  
  12715.  output screen  The screen where output appears when you run a program in the
  12716.      QuickBASIC environment. The output screen is the same as it would be if
  12717.      you ran the debugged program outside of QuickBASIC.
  12718.  
  12719.  overflow  An error condition that occurs when the value assigned to a
  12720.      numeric variable falls outside the allowable range for that variable's
  12721.      type.
  12722.  
  12723.  overlay  Part of a program that is read into memory from disk only if and
  12724.      when it is needed.
  12725.  
  12726.  palette  The displayable colors for a given video mode. The CGA mode
  12727.      operates with a set of predetermined palette colors. The EGA, MCGA, and
  12728.      VGA color modes operate with a redefinable palette of colors.
  12729.  
  12730.  parallel port  The port to which the printer is usually attached.
  12731.  
  12732.  parameter  A variable symbol in a DEF FN, FUNCTION, or SUB statement.
  12733.      Parameters are replaced by actual variables and values when you invoke
  12734.      the function or subprogram.
  12735.  
  12736.  pass by reference  To transfer the address of an argument to a SUB or
  12737.      FUNCTION. Passing by reference allows a procedure to change the values
  12738.      of arguments passed to it.
  12739.  
  12740.  pass by value  To transfer the value (rather than the address) of an
  12741.      argument to a SUB or FUNCTION.
  12742.  
  12743.  path name  The complete specification that gives the location of a file. A
  12744.      path name usually includes a drive letter followed by a colon, one or
  12745.      more directory names, and a file name.
  12746.  
  12747.  physical coordinates  The screen coordinates. The physical coordinates (0,0)
  12748.      refer to the upper-left corner of the screen, unless you have defined a
  12749.      graphics viewport with a VIEW statement, in which case (0,0) are the
  12750.      coordinates of the upper-left corner of the viewport. The range of the
  12751.      physical coordinates depends on the display adapter, the monitor, and
  12752.      the specifications set by the SCREEN statement. Units are pixels. See
  12753.      also "absolute coordinates" and "view coordinates."
  12754.  
  12755.  place marker  A location in the program code to which you can return by
  12756.      pressing a control code.
  12757.  
  12758.  pointer  See "mouse cursor."
  12759.  
  12760.  port  An electrical connection through which the computer sends and receives
  12761.      data to and from devices or other computers.
  12762.  
  12763.  precedence  The relative position of an operator in the hierarchy that
  12764.      determines the order in which expressions are evaluated.
  12765.  
  12766.  procedure  A general term for a SUB or FUNCTION. See "FUNCTION" and "SUB."
  12767.  
  12768.  procedure call  A call to a SUB or FUNCTION.
  12769.  
  12770.  program  One or more modules linked together to form a complete set of
  12771.      executable instructions.
  12772.  
  12773.  program step  To highlight and execute the next instruction.
  12774.  
  12775.  prompt  A request displayed by the computer for you to provide some
  12776.      information or perform an action.
  12777.  
  12778.  QB Advisor  The detailed, context-sensitive on-line help on the BASIC
  12779.      language.
  12780.  
  12781.  Quick library  A file produced with the Make Library command or with the /Q
  12782.      option of the LINK command. A Quick library contains procedures for use
  12783.      in the QuickBASIC environment as the program is developed. Quick
  12784.      libraries were known in previous versions of QuickBASIC as user
  12785.      libraries; however, user libraries cannot be used as Quick libraries,
  12786.      and vice versa.
  12787.  
  12788.  random-access file  A file that can be read or written in any order. See
  12789.      "sequential file."
  12790.  
  12791.  read-only file  A file whose read-only attribute is set so that its contents
  12792.      can be displayed and read, but not changed.
  12793.  
  12794.  record  A series of fields treated as a meaningful unit in a data file or a
  12795.      variable declared as having a user-defined type. See "user-defined
  12796.      type."
  12797.  
  12798.  recursion  The practice of having a subprogram call itself; some algorithms
  12799.      can be coded quickly and efficiently by using recursion.
  12800.  
  12801.  redirect  To specify a device (other than the default device) from which a
  12802.      program will receive input or to which it will send output. Normally
  12803.      program input comes from the keyboard, and program output goes to the
  12804.      screen.
  12805.  
  12806.  reference bar  The line on the bottom of the QuickBASIC environment screen
  12807.      containing frequently used commands and keyboard shortcuts.
  12808.  
  12809.  relational database  A database in which any field or record can be
  12810.      associated with any other field or record.
  12811.  
  12812.  registers  Areas in the processor where data can be temporarily stored
  12813.      during machine-level processing. The registers used in the 8086-family
  12814.      of processors are: AX, BX, CX, DX, SP, BP, SI, DI, DS, ES, SS, CS, IP,
  12815.      and the flags register. See "flags register."
  12816.  
  12817.  root directory  The main directory that DOS creates on each disk. The root
  12818.      directory is the top directory in a hierarchical file system.
  12819.  
  12820.  run time  The time during which a program is executing. Run time refers to
  12821.      the execution time of a program, rather than to the execution time of
  12822.      the compiler or the linker. Some errors──known as run-time errors──can
  12823.      be detected only while the program is running.
  12824.  
  12825.  run-time library  A file containing the routines required to implement
  12826.      certain language functions.
  12827.  
  12828.  run-time module  A module containing most of the routines needed to
  12829.      implement a language. In QuickBASIC, the run-time module is an
  12830.      executable file named BRUN45.EXE and is, for the most part, a library of
  12831.      routines.
  12832.  
  12833.  scope  The range of statements over which a variable or constant is defined.
  12834.      See "global constant," "global variable," "local constant," and "local
  12835.      variable."
  12836.  
  12837.  scroll  To move text up and down, or left and right, to see parts that
  12838.      cannot fit within a single screen.
  12839.  
  12840.  scroll bars  The bars that appear at the right side and bottom of the View
  12841.      window and some list boxes. Scroll bars allow you to scroll the contents
  12842.      of a View window or text box with the mouse.
  12843.  
  12844.  segment  An area of memory, less than or equal to 64K, containing code or
  12845.      data.
  12846.  
  12847.  select  To pick items, such as option buttons, in a dialog box. This verb
  12848.      also describes the action of highlighting areas of text or graphics to
  12849.      edit.
  12850.  
  12851.  sequential file  A file that can be read or written only in order from first
  12852.      byte to last. See "random-access file."
  12853.  
  12854.  serial port  The communications port (COM1, COM2, COM3, or COM4) to which
  12855.      devices, such as a modem or a serial printer, can be attached.
  12856.  
  12857.  simple variable  A BASIC variable that is not an array. Simple variables can
  12858.      be of numeric, string, or user-defined types.
  12859.  
  12860.  single precision  A real (floating-point) value that occupies four bytes of
  12861.      memory. Single-precision values are accurate to seven decimal places.
  12862.  
  12863.  smart editor  Collective term for QuickBASIC's advanced editing features,
  12864.      including syntax checking, automatic keyword capitalization, and
  12865.      automatic procedure declaration.
  12866.  
  12867.  source file  A text file containing BASIC statements. Although all modules
  12868.      are source files, not all source files are modules (include files, for
  12869.      example).
  12870.  
  12871.      QuickBASIC uses source files in two different formats. Source files
  12872.      saved in the QuickBASIC format load quickly but cannot be directly read
  12873.      or manipulated by an ordinary text editor. Source files saved as text
  12874.      files (ASCII files) can be read or changed by any text editor.
  12875.  
  12876.  stack  An area of random-access memory used by BASIC to store data (e.g.,
  12877.      information), such as intermediate results of some arithmetic
  12878.      computations, automatic variables in procedures, and procedure
  12879.      invocation information.
  12880.  
  12881.  stand-alone file  An executable file that can be run without a run-time
  12882.      file──a compiled program linked with BCOM45.LIB.
  12883.  
  12884.  standard input  The device from which a program reads its input unless the
  12885.      input is redirected. In normal DOS operation, standard input is the
  12886.      keyboard.
  12887.  
  12888.  standard output  The device to which a program sends its output unless
  12889.      redirected. In normal DOS operation, standard output is the display.
  12890.  
  12891.  statement  A combination of one or more BASIC keywords, variables, and
  12892.      operators that the compiler or interpreter treats as a single unit. A
  12893.      BASIC statement can stand by itself on a single program line. The term
  12894.      statement refers to one-line statements such as OPEN or INPUT as well as
  12895.      entire multiline compound statements such as IF...END IF or SELECT
  12896.      CASE...END SELECT. Parts of compound statements such as ELSE or CASE are
  12897.      referred to as clauses.
  12898.  
  12899.  static array  An array whose memory location is allocated when the program
  12900.      is compiled. The memory location of a static array does not change while
  12901.      the program runs.
  12902.  
  12903.  stop bit  A signal used in serial communications that marks the end of a
  12904.      character.
  12905.  
  12906.  string  A sequence of characters, often identified by a symbolic name. In
  12907.      this example, Hello is a string: PRINT "Hello". A string may be a
  12908.      constant or a variable.
  12909.  
  12910.  SUB  A unit of code delimited by the SUB and END SUB statements. A SUB
  12911.      (usually called a SUB procedure) provides an alternative to the older
  12912.      BASIC GOSUB type of subroutine.
  12913.  
  12914.  subprogram  See "SUB."
  12915.  
  12916.  subroutine  A unit of BASIC code terminated by the RETURN statement. Program
  12917.      control is transferred to a subroutine with a GOSUB statement. (Also
  12918.      called a GOSUBblock.)
  12919.  
  12920.  symbol  A name that identifies a location in memory.
  12921.  
  12922.  symbolic constant  A constant represented by a symbol rather than the
  12923.      literal constant itself. Symbolic constants are defined using the CONST
  12924.      statement.
  12925.  
  12926.  text  Ordinary, printable characters, including the uppercase and lowercase
  12927.      letters of the alphabet, the numerals 0 through 9, and punctuation
  12928.      marks.
  12929.  
  12930.  text box  A box in which you type information needed to carry out a command.
  12931.      A text box appears within a dialog box.
  12932.  
  12933.  text editor  A program that you use to create or change text files.
  12934.  
  12935.  text file  A file containing text only.
  12936.  
  12937.  tiling  The filling of a figure with a pattern (instead of a solid color) by
  12938.      using the graphics statement PAINT.
  12939.  
  12940.  title bar  A bar, located at the top of a View window, that shows the name
  12941.      of the text file or module (and procedure, if appropriate) currently
  12942.      displayed in that window.
  12943.  
  12944.  toggle  A function key or menu selection that turns a feature off, if it is
  12945.      on, or turns the feature on, if it is off. When used as a verb, toggle
  12946.      means to reverse the status of a feature. For example, the Trace On
  12947.      command on the Debug menu toggles tracing on or off.
  12948.  
  12949.  two's complement  A type of base-2 notation used to represent positive and
  12950.      negative in which negative values are formed by complementing all bits
  12951.      and adding 1 to the results.
  12952.  
  12953.  type  The numeric format of a variable. Types include integer, long integer,
  12954.      single precision, and double precision. Types may also be user-defined.
  12955.  
  12956.  type checking  An operation in which the compiler verifies that the operands
  12957.      of an operator are valid or that the actual arguments in a function call
  12958.      are of the same types as the corresponding formal parameters in the
  12959.      function definition.
  12960.  
  12961.  type declaration  A declaration that defines variable names as members of a
  12962.      particular data structure or type.
  12963.  
  12964.  underflow  An error condition caused when a calculation produces a result
  12965.      too small for the computer to handle internally.
  12966.  
  12967.  unresolved external  A procedure declared in one module, but not defined in
  12968.      another module that is linked with it. Unresolved external references
  12969.      are usually caused by misspellings or by omitting the name of the module
  12970.      containing the procedure from the LINK command line.
  12971.  
  12972.  user-defined type  A composite data structure that can contain both string
  12973.      and numeric variables (similar to a C-language structure or Pascal
  12974.      record). User-defined types are defined with TYPE statements. The data
  12975.      structure is defined by a TYPE...END TYPE statement.
  12976.  
  12977.  variable  A value that can──and usually does──change during program
  12978.      execution.
  12979.  
  12980.  view coordinates  Pairs of numbers (for example, x and y) that uniquely
  12981.      define any point in two-dimensional space. The numbers x and y can be
  12982.      any real numbers. View coordinates can be mapped to the screen with the
  12983.      graphics WINDOW statement. View coordinates let you plot data using
  12984.      coordinates appropriate to the graph or picture without worrying about
  12985.      the actual screen coordinates. See "physical coordinates."
  12986.  
  12987.  View window  The main editing window and the window into which programs
  12988.      load.
  12989.  
  12990.  VGA (Video Graphics Array)  A printed-circuit card that controls the
  12991.      display. A VGA card shows both text and graphics at medium to high
  12992.      resolution in up to 256 colors.
  12993.  
  12994.  Watch window  A window that displays information about variables or
  12995.      expressions that you are monitoring during program execution. For each
  12996.      watched item, the Watch window displays the item's originating location,
  12997.      its name, and its current value if the item is watchable.
  12998.  
  12999.  watchable  A debugging term that describes whether a variable or expression
  13000.      can be watched in the current execution location. An item is watchable
  13001.      only during execution of the part of the program from which you entered
  13002.      the item in the Watch window.
  13003.  
  13004.  watchpoint  An expression (such as X = 3) that stops program execution when
  13005.      it becomes true. Watchpoints can slow program execution. See
  13006.      "breakpoint."
  13007.  
  13008.  wild card  One of the DOS characters (? and *) that can be expanded into one
  13009.      or more characters in file-name references.
  13010.  
  13011.  window  An area on the screen used to display part of a file or to enter
  13012.      statements. Window refers only to the area on the screen, and does not
  13013.      refer to what is displayed in the area. The term window also refers to
  13014.      the portion of a view coordinate system mapped to the physical
  13015.      coordinates by the WINDOW graphics statement. See "Immediate window,"
  13016.      "View window,"and "Watch window."
  13017.  
  13018.  
  13019.  ────────────────────────────────────────────────────────────────────────────
  13020.  Index
  13021.  
  13022.  
  13023.  Symbols
  13024.  
  13025.  . (dot) beside command
  13026.  ... (ellipsis dots) with menu item
  13027.  
  13028.  Numbers
  13029.  
  13030.  80287
  13031.  80387
  13032.  8087
  13033.  
  13034.  A
  13035.  
  13036.  Absolute coordinates
  13037.  Active window
  13038.    changing
  13039.    changing size
  13040.    described
  13041.    line and column counters
  13042.    switching
  13043.  Add Watch command
  13044.  Address
  13045.    defined
  13046.    near
  13047.  Advisor. See QB Advisor
  13048.  Algorithms
  13049.  ALT key
  13050.    described
  13051.  ALT key
  13052.    dialog boxes, use in
  13053.    entering high-order ASCII characters
  13054.    menus and commands
  13055.  Altering text
  13056.  AND operator
  13057.  Animation
  13058.  Apostrophe (')
  13059.  Arguments
  13060.  Arithmetic
  13061.    conversion
  13062.    floating point
  13063.    overflow
  13064.  Array bounds
  13065.    checking
  13066.    defined
  13067.  Array elements, specifying
  13068.  Array variables
  13069.  Arrays
  13070.    defined
  13071.    dynamic
  13072.    multidimensional
  13073.    static
  13074.  Arrow keys. See DIRECTION keys
  13075.  ASCII characters
  13076.    corresponding to control sequences
  13077.    entering high-order
  13078.    set
  13079.  Aspect ratio
  13080.  Assignment
  13081.  Assignment statement
  13082.  Attributes
  13083.  Automatic formatting
  13084.  Automatic syntax checking
  13085.  
  13086.  B
  13087.  
  13088.  /B option (QB)
  13089.  Bar, menu
  13090.  Base name
  13091.  BASIC command-line compiler. See BC
  13092.  BASICA programs, running with QuickBASIC
  13093.  BC
  13094.  BCOM45.LIB
  13095.  BIOS
  13096.  Bit, defined
  13097.  Black-and-white monitors. See Monitors, monochrome
  13098.  Block
  13099.  Boolean expressions
  13100.    compound
  13101.    precedence of evaluation
  13102.    simple
  13103.  Branching
  13104.  Break on Errors command
  13105.  Breaking out of programs
  13106.  Breakpoints
  13107.    defined
  13108.    deleting
  13109.    described
  13110.    setting
  13111.  Breaks, checking at run time
  13112.  BRUN45.EXE
  13113.  BRUN45.LIB
  13114.  Buffer
  13115.  Bugs
  13116.  Buttons, right mouse
  13117.  Byte
  13118.  
  13119.  C
  13120.  
  13121.  /C option (QB)
  13122.  Calculations
  13123.    floating point
  13124.    Immediate window
  13125.  Call by reference. See Passing by reference
  13126.  Call by value. See Passing by value
  13127.  Calls menu
  13128.  Calls, procedure
  13129.  Canceling commands
  13130.  CAPS LOCK/NUM LOCK indicator
  13131.    illus
  13132.    described
  13133.  Case sensitivity
  13134.  CGA. See Color Graphics Adapter
  13135.  CHAIN statement
  13136.  Change command
  13137.    described
  13138.    dialog box, illus.
  13139.  Changing
  13140.    active window
  13141.    default search paths
  13142.    main modules
  13143.    programs
  13144.    screen display
  13145.    text
  13146.    values of variables
  13147.    window size
  13148.  Character strings
  13149.  Check boxes
  13150.    defined
  13151.    described
  13152.    illus.
  13153.  Checking
  13154.    syntax
  13155.    types
  13156.  Choosing
  13157.    commands
  13158.      Easy Menus
  13159.      ENTER key
  13160.      keyboard
  13161.      menus
  13162.      mouse
  13163.    defined
  13164.  CHR$ function
  13165.  Clear All Breakpoints command
  13166.  Clear command
  13167.  Clearing
  13168.    screens
  13169.    View window
  13170.  Clicking
  13171.  Clipboard
  13172.  Closing Help
  13173.  /CMD option (QB)
  13174.  Code
  13175.    module level
  13176.  Color Graphics Adapter (CGA), defined
  13177.  Colors. See Screen colors
  13178.  Column counter, illus.
  13179.  Command buttons
  13180.    described
  13181.    Example
  13182.    Help
  13183.    illus.
  13184.    Make EXE
  13185.    Make EXE and Exit
  13186.    Make Library and Exit
  13187.    Program
  13188.    Remarks
  13189.  COMMAND$ function
  13190.  Commands
  13191.    Add Watch
  13192.    availability
  13193.    Break on Errors
  13194.    canceling
  13195.    Change
  13196.    choosing
  13197.      Easy Menus
  13198.      ENTER key
  13199.      keyboard
  13200.      menus
  13201.      mouse
  13202.    Clear
  13203.    Clear All Breakpoints
  13204.    Contents
  13205.    Continue
  13206.    Copy
  13207.    Create File
  13208.    Cut
  13209.    debugging
  13210.      Debug menu
  13211.      described
  13212.      F10
  13213.      F7
  13214.      F8
  13215.      F9
  13216.      function keys
  13217.      (table)
  13218.      table
  13219.    Delete Watch
  13220.    Display
  13221.    DOS Shell
  13222.    editing (table)
  13223.    Execute to cursor
  13224.    Exit
  13225.    Find
  13226.    Full Menus
  13227.    Help
  13228.    Help on Help
  13229.    History On
  13230.    Include File
  13231.    Include Lines
  13232.    Index
  13233.    Instant Watch
  13234.    Label
  13235.    Load File
  13236.    Make EXE File
  13237.      dialog box, illus.
  13238.      introduction
  13239.    Make Library
  13240.    Merge
  13241.    New FUNCTION
  13242.    New Program
  13243.    New SUB
  13244.    Next Statement
  13245.    Next SUB
  13246.    Open Program
  13247.    Output Screen
  13248.    Paste
  13249.    Print
  13250.      defined
  13251.      dialog box, illus.
  13252.      Help
  13253.    procedure stepping
  13254.    QB
  13255.    Repeat Last Find
  13256.    Restart
  13257.    Right Mouse
  13258.    Save
  13259.    Save All
  13260.    Save As
  13261.    Selected Text
  13262.    Set Main Module
  13263.    Set Next Statement
  13264.    Set Paths
  13265.    shortcut keys
  13266.    single stepping
  13267.    Split
  13268.    Start
  13269.    starting QuickBASIC
  13270.    SUBs
  13271.      defined
  13272.      moving procedures
  13273.    Syntax Checking
  13274.    Toggle Breakpoint
  13275.    Topic
  13276.    Trace On
  13277.    Undo
  13278.    Unload File
  13279.  Comments, appearing in QCARDS
  13280.  COMMON statement
  13281.  Compile
  13282.  Compiler
  13283.  Compiler/environment differences
  13284.  Constants
  13285.    defined
  13286.    local
  13287.    symbolic
  13288.  Contents command
  13289.  Context
  13290.    debugging
  13291.    execution
  13292.  Context-sensitive help
  13293.  Continue command
  13294.  Continuing suspended programs
  13295.  Control-sequence characters
  13296.  Conventions, document
  13297.  Conversion, arithmetic
  13298.  Coordinates
  13299.    absolute
  13300.    physical
  13301.  Coprocessor
  13302.  Copy command
  13303.  Copying
  13304.    examples from help
  13305.    text
  13306.  Create File command
  13307.  Creating
  13308.    executable files
  13309.    FUNCTION procedures
  13310.    libraries
  13311.    main modules
  13312.    new subprograms
  13313.    procedures
  13314.  CTRL key, entering special characters
  13315.  CTRL+BREAK
  13316.  Current directory
  13317.  Current drives
  13318.  Current Statement option (Display command)
  13319.  Cursor
  13320.    defined
  13321.    illus.
  13322.    moving
  13323.  Customizing screen display
  13324.  Cut command
  13325.  
  13326.  D
  13327.  
  13328.  Data
  13329.  Data types, default
  13330.    changing
  13331.    defined
  13332.    for procedures
  13333.  Database
  13334.  Debug menu
  13335.    commands (list)
  13336.    illus.
  13337.    (table)
  13338.  Debugger
  13339.    defined
  13340.    symbolic
  13341.  Debugging
  13342.    breakpoints
  13343.    commands
  13344.      debug menu
  13345.      F10
  13346.      F7
  13347.      F8
  13348.      F9
  13349.      function keys
  13350.      Run menu
  13351.    context, illus.
  13352.    Continue command
  13353.    features
  13354.    Immediate window
  13355.    introduction
  13356.    Next Statement command
  13357.    procedures
  13358.    watch variables
  13359.    Watch window
  13360.    while writing code
  13361.  Debugging features (table)
  13362.  Decision-making
  13363.  Declarations
  13364.    defined
  13365.    procedures, automatic
  13366.  DECLARE statement, procedure declarations
  13367.  DEF FN function
  13368.    defined
  13369.    Watch window
  13370.  Default
  13371.  Default data types
  13372.    changing in procedures
  13373.    for procedures
  13374.  Default search paths
  13375.  DEFtype
  13376.    defined
  13377.    introduction
  13378.  Delete Watch command
  13379.    closing Watch window
  13380.    deleting variables
  13381.  Deleting
  13382.    breakpoints
  13383.    modules
  13384.    text, command summary
  13385.    variables from Watch Window
  13386.  Details command button
  13387.  Devices
  13388.    defined
  13389.    logical
  13390.    names
  13391.  Dialog boxes
  13392.    clearing
  13393.    defined
  13394.    illus.
  13395.    Merge command
  13396.    Print command
  13397.    selecting items
  13398.    setting options
  13399.    text box
  13400.  DIM statement
  13401.  Dimensions
  13402.  DIRECTION keys
  13403.    defined
  13404.    use with menus
  13405.  Directories
  13406.    changing from within QuickBASIC
  13407.    changing search paths
  13408.    current
  13409.    defined
  13410.    listing
  13411.    root
  13412.  Display command
  13413.  Division
  13414.  DO statement, Help, illus.
  13415.  Document
  13416.  Document conventions
  13417.  DO...LOOP
  13418.    defined
  13419.    terminating condition
  13420.    UNTIL version
  13421.    WHILE version
  13422.  DOS, returning to
  13423.  DOS Shell command
  13424.  Dots, marking command
  13425.  Double precision
  13426.  Double-click
  13427.  Drag
  13428.  Drives
  13429.  Duplicating text. See Copying
  13430.  Dynamic arrays
  13431.  
  13432.  E
  13433.  
  13434.  Easy Menus
  13435.    commands, choosing
  13436.    described
  13437.    vs. full
  13438.    windows available with
  13439.  Edit menu
  13440.    Clear command
  13441.    commands (list)
  13442.    Copy command
  13443.    Cut command
  13444.    New FUNCTION command
  13445.    New SUB command
  13446.    Syntax Checking command
  13447.    Undo command
  13448.  Editing
  13449.    commands (table)
  13450.    include files
  13451.    material from Help
  13452.  Editor
  13453.    automatic formatting
  13454.    entering text
  13455.    selecting text
  13456.    syntax checking
  13457.    text
  13458.  EGA. See Enhanced Graphics Adapter
  13459.  Ellipsis dots (...) with menu item
  13460.  Emptying View window
  13461.  Emulator
  13462.  Enabled events
  13463.  Enhanced Graphics Adapter (EGA)
  13464.  Entering
  13465.    special characters
  13466.    text
  13467.  Environment/compiler differences
  13468.  Error checking, executable files
  13469.  ERROR function
  13470.  Error messages
  13471.    clearing
  13472.    help for
  13473.  Errors
  13474.    correcting
  13475.    running programs
  13476.    run-time
  13477.      checking
  13478.      line numbers
  13479.      reporting locations
  13480.      simulating
  13481.    syntax, checking
  13482.    typing
  13483.  Closing menus, Esc key
  13484.  ESC key
  13485.  Event trapping
  13486.    defined
  13487.    Quick libraries
  13488.  Events
  13489.  Example code
  13490.    copying from Help
  13491.    Help hyperlinks
  13492.  Example command button
  13493.  EXE requiring BRUN45.EXE option
  13494.    Executable files
  13495.  Executable files
  13496.    creating
  13497.    defined
  13498.    Quick libraries
  13499.    stand-alone
  13500.  Execute option (QB)
  13501.  Execute to cursor command
  13502.  Executing
  13503.    all statements of procedures
  13504.    commands. See Choosing commands
  13505.    programs
  13506.      right mouse button
  13507.      suspending
  13508.      to cursor
  13509.  Exit command
  13510.  Exiting QuickBASIC
  13511.  Expressions
  13512.    defined
  13513.    simple
  13514.    use
  13515.    watch
  13516.  
  13517.  F
  13518.  
  13519.  F1 key
  13520.  Falsity, representation
  13521.  Fibonacci sequence
  13522.  File menu
  13523.    commands (list)
  13524.    Create File command
  13525.    DOS Shell command
  13526.    Exit command
  13527.    illus.
  13528.    Load File command
  13529.    Merge command
  13530.    Open Program command
  13531.    Print command
  13532.    Save All command
  13533.    Save As command
  13534.    Save command
  13535.    Unload File command
  13536.  Files
  13537.    changing default search paths
  13538.    data
  13539.    executable
  13540.      creating
  13541.      defined
  13542.      error checking in
  13543.      Quick libraries
  13544.      stand-alone, creating
  13545.    include
  13546.      defined
  13547.      finding
  13548.      nesting
  13549.      viewing and editing
  13550.      viewing only
  13551.    inserting in active window
  13552.    loading
  13553.    .MAK
  13554.    merging
  13555.    object
  13556.    printing
  13557.    QB.INI
  13558.    read only
  13559.    saving
  13560.    sequential
  13561.    source
  13562.    stand-alone
  13563.    text
  13564.  filespec
  13565.  Find command
  13566.    described
  13567.    dialog box, illus.
  13568.    options (table)
  13569.    restrictions (table)
  13570.  FindingSearching
  13571.    include files
  13572.    text
  13573.  Fixed disk based Help
  13574.  Flags
  13575.  Floating point
  13576.    defined
  13577.  Floating-point
  13578.    arithmetic, executable files
  13579.    variables
  13580.  Floppy disk-based Help
  13581.  Floppy disk-based QB Advisor
  13582.  Flow, programs, tracing
  13583.  Formal parameters
  13584.  Formats
  13585.    IEEE
  13586.    Microsoft binary
  13587.  Formatting, automatic
  13588.  FOR...NEXT loop
  13589.  Full Menus
  13590.  Function declarations
  13591.  Function definitions
  13592.  Function keys, debugging
  13593.  FUNCTION procedures
  13594.    creating
  13595.    default data type
  13596.    naming
  13597.    viewing
  13598.  Functions, conversion option (QB)
  13599.  
  13600.  G
  13601.  
  13602.  /G option (QB)
  13603.  Global symbols
  13604.  Global variables
  13605.  GOSUB statement
  13606.  
  13607.  H
  13608.  
  13609.  /H option (QB)
  13610.  Hard disk-based help
  13611.  Hardware needed for running QuickBASIC
  13612.  Heap
  13613.  Help
  13614.    command buttons
  13615.    constructing statements with
  13616.    context sensitive
  13617.    copying examples from
  13618.    copying syntax blocks from
  13619.    described
  13620.    editing material from
  13621.    error messages
  13622.    examples
  13623.    files
  13624.    floppy-disk system
  13625.    hard-disk system
  13626.    help with
  13627.    hyperlinks
  13628.    invoking on line
  13629.    keys (table)
  13630.    keywords
  13631.      command button
  13632.      described
  13633.      illus.
  13634.      listing with Index
  13635.    language
  13636.    missing Help files
  13637.    on-line
  13638.    outline of system
  13639.    place markers in
  13640.    printing text from
  13641.    QB Advisor
  13642.    right mouse button
  13643.    sample programs
  13644.    searching for Help files
  13645.    Set Paths command for files
  13646.    syntax
  13647.    trouble evoking
  13648.    using
  13649.  Help menu
  13650.    commands (list)
  13651.    Contents command
  13652.    Help on Help command
  13653.    Index command
  13654.    introduction
  13655.    Topic command
  13656.  Help On Help command
  13657.  Help on Help command
  13658.  Help, on-lineHelp
  13659.  Help window
  13660.    described
  13661.    illus.
  13662.    moving in
  13663.  Hexadecimal, defined
  13664.  Hierarchical filing system (HFS)
  13665.  Highlight
  13666.  High-order ASCII characters
  13667.  High-resolution-display option (QB)
  13668.  History Back
  13669.  History Forward
  13670.  History On command
  13671.  Hyperlinks
  13672.  
  13673.  I
  13674.  
  13675.  IEEE format
  13676.  IF...THEN...ELSE statement
  13677.    defined
  13678.    help, illus.
  13679.    syntax
  13680.  Immediate window
  13681.    calculations
  13682.    calling procedures from
  13683.    capacity
  13684.    changing, active window
  13685.    context
  13686.    debugging in
  13687.    defined
  13688.    described
  13689.    illus.
  13690.    limits
  13691.    running statements in
  13692.    run-time error messages
  13693.    run-time errors, simulating
  13694.    size, changing
  13695.    statements not supported
  13696.    testing programs
  13697.    variable values, changing
  13698.  Implicit links
  13699.  #INCLUDE metacommand
  13700.  Include files
  13701.    defined
  13702.    finding
  13703.    nesting
  13704.    viewing and editing
  13705.    viewing only
  13706.  Included File command
  13707.  Included Lines command
  13708.  Indentation controls
  13709.  Indenting
  13710.    program blocks
  13711.    text
  13712.  Index command
  13713.    described
  13714.    screen, illus.
  13715.    using
  13716.  Input
  13717.    defined
  13718.    standard
  13719.  INPUT statement
  13720.  Input/output (I/O), defined
  13721.  Insert mode
  13722.    defined
  13723.    described
  13724.  Inserting
  13725.    commands, summary
  13726.    text
  13727.  Installing QuickBASIC
  13728.  Instant Watch command
  13729.    dialog box, illus.
  13730.    symbol help
  13731.  Integer variables
  13732.  Integers
  13733.  Interface
  13734.  Interpreter
  13735.  I/OInput/output
  13736.  
  13737.  K
  13738.  
  13739.  Key combinations
  13740.    See also Shortcut keys
  13741.    cursor movement
  13742.    described
  13743.    scrolling
  13744.  Keyboard
  13745.    choosing commands from
  13746.    moving in Help windows
  13747.  Keys
  13748.    control (CTRL)
  13749.    CTRL+BREAK
  13750.    DIRECTION
  13751.    F10
  13752.    F7
  13753.    F8
  13754.    F9
  13755.    Help (table)
  13756.    shortcut
  13757.      editing commands
  13758.      (table)
  13759.  Keywords
  13760.    capitalization of
  13761.    defined
  13762.    help
  13763.  
  13764.  L
  13765.  
  13766.  /L option (QB)
  13767.  Label command
  13768.  Labels
  13769.  Language help
  13770.  Leaving QuickBASIC. See Quitting QuickBASIC
  13771.  Libraries
  13772.    creating
  13773.    Quick
  13774.      creating
  13775.      defined
  13776.      described
  13777.      non-library modules, used with
  13778.    run-time
  13779.    stand-alone, executable files
  13780.  line
  13781.  Line counter, illus.
  13782.  Line-number checking
  13783.  Lines, setting attributes
  13784.  Linker, BRUN45.EXE, advantage of
  13785.  Linking
  13786.  Links, implicit
  13787.  List boxes
  13788.    defined
  13789.    described
  13790.    illus.
  13791.    scroll bar, illus.
  13792.  Listing directories
  13793.  Load File command
  13794.  Loading
  13795.    files
  13796.    modules
  13797.  Local
  13798.    constants
  13799.    symbols
  13800.    variables
  13801.  Logical devices
  13802.  Logical operators
  13803.  Logical relations
  13804.  Long integers
  13805.  Loop counters
  13806.  Loop variables
  13807.  Loops
  13808.    DO
  13809.    FOR...NEXT
  13810.  LPT1
  13811.  
  13812.  M
  13813.  
  13814.  Main modules
  13815.  .MAK file
  13816.  Make EXE and Exit command button
  13817.  Make EXE command button
  13818.  Make EXE File command, dialog box, illus.
  13819.  Make Library and Exit command button
  13820.  Make Library command
  13821.  Math coprocessor
  13822.  Math functions
  13823.  /MBF option (QB)
  13824.  MCGA. See Multicolor Graphics Array
  13825.  MDA. See Monochrome Display Adapter
  13826.  Menu bar
  13827.  Menu-item description, illus.
  13828.  Menus
  13829.    browsing
  13830.    Calls
  13831.    clearing
  13832.    closing
  13833.    commands, choosing
  13834.    Debug
  13835.    Easy
  13836.      described
  13837.      vs. full
  13838.    File
  13839.      commands (list)
  13840.      illus.
  13841.    Full
  13842.    Help
  13843.    opening
  13844.    Options
  13845.    Run
  13846.    selecting
  13847.    setup
  13848.  Merge command
  13849.  Metacommands
  13850.    defined
  13851.    #INCLUDE
  13852.  Microsoft Binary format
  13853.  Microsoft Overlay Linker (LINK)
  13854.  Modes
  13855.    insert
  13856.    overtype
  13857.  Modular programming
  13858.  Module-level code
  13859.    defined
  13860.    described
  13861.  Modules
  13862.    defined
  13863.    deleting
  13864.    existing
  13865.    loading and unloading
  13866.    main
  13867.      changing
  13868.      defined
  13869.    new
  13870.    printing
  13871.    run-time
  13872.  Monitors, monochrome
  13873.    use with Color Graphics Adapter
  13874.  Monochrome Display Adapter (MDA)
  13875.  Mouse
  13876.    compatibility with QuickBASIC
  13877.    cursor
  13878.    defined
  13879.    Hyper Links, using with
  13880.    pointer, illus.
  13881.    QuickBASIC, using with
  13882.    scrolling with
  13883.    setting right button
  13884.  Moving
  13885.    procedures
  13886.      Help windows
  13887.      SUBs command
  13888.      View window
  13889.    text
  13890.  Multicolor Graphics Array (MCGA)
  13891.  Multidimensional arrays
  13892.  Multiple-module programs
  13893.  
  13894.  N
  13895.  
  13896.  Names
  13897.    base
  13898.    device
  13899.    path
  13900.  Naming procedures
  13901.  Near address
  13902.  Nested procedures
  13903.  Nesting Include files
  13904.  New FUNCTION command
  13905.  New Program command
  13906.  New SUB command
  13907.  Next Statement command
  13908.  Next SUB command
  13909.  NOT operator
  13910.  Not watchable message
  13911.  Null characters
  13912.  NUM LOCK/CAPS LOCK indicator
  13913.    illus
  13914.    described
  13915.  Numeric coprocessor. See Coprocessor
  13916.  
  13917.  O
  13918.  
  13919.  Object files
  13920.    compiling with BC
  13921.    defined
  13922.  Offset
  13923.  On-line help
  13924.    See also Help
  13925.  Open Program command
  13926.  Opening
  13927.    menus
  13928.    programs
  13929.    screen, illus.
  13930.  Operand
  13931.  Operators
  13932.    arithmetic
  13933.    defined
  13934.    logical
  13935.  Option boxes, illus.
  13936.  Option buttons
  13937.    described
  13938.    illus.
  13939.  Options Menu
  13940.    Right Mouse command
  13941.    Set Paths command
  13942.  Options menu
  13943.    commands (list)
  13944.    Display command
  13945.    Full Menus command
  13946.    Set Paths command
  13947.    Syntax Checking command
  13948.  Options, QB command
  13949.  OR operator
  13950.  Organizing QuickBASIC files
  13951.  OutputPRINT statement
  13952.    defined
  13953.    program, how displayed
  13954.    standard
  13955.  Output screen
  13956.    defined
  13957.    viewing
  13958.  Output Screen command
  13959.  Outputting
  13960.    low-order ASCII control sequences
  13961.  Overflow
  13962.  Overlay
  13963.  Overtyping text
  13964.  
  13965.  P
  13966.  
  13967.  PACKING.LST
  13968.  Palette
  13969.  Parallel ports
  13970.  Parameters
  13971.    defined
  13972.    formal
  13973.  Parentheses, used to establish precedence
  13974.  Passing by reference
  13975.  Passing by value
  13976.  Paste command
  13977.  Pasting text
  13978.  Path names
  13979.  Paths, changing default search
  13980.  Path-specification line
  13981.  PGDOWN key
  13982.  PGUP key
  13983.  Physical coordinates
  13984.  Placemarkers
  13985.    defined
  13986.    using
  13987.  Pointers
  13988.  Ports
  13989.    parallel
  13990.    serial
  13991.  Precedence
  13992.    defined
  13993.    introduction
  13994.  Preventing bugs
  13995.  Print command
  13996.    described
  13997.    dialog box, illus.
  13998.    Help
  13999.  PRINT statement
  14000.    combining
  14001.    numeric expressions
  14002.    tabbing
  14003.    use
  14004.  Problems, software, reporting
  14005.  Procedure declarations, automatic
  14006.  Procedure stepping
  14007.  Procedures
  14008.    calling from Immediate window
  14009.    changing default data type
  14010.    creating
  14011.    creating FUNCTION
  14012.    creating SUB
  14013.    debugging
  14014.    declaring
  14015.    default data types
  14016.    defined
  14017.    described
  14018.    executing all statements of
  14019.    naming
  14020.    nested
  14021.    sequence of
  14022.    SUB
  14023.    View window, illus.
  14024.    viewing
  14025.  Produce Debug Code check box
  14026.  Produce debug code check box
  14027.  Program command button
  14028.  Program execution, right mouse button
  14029.  Program statements
  14030.  Program symbols. See Symbols
  14031.  Programming environment, described
  14032.  Programming, modular
  14033.  Programs
  14034.    BASICA, running with QuickBASIC
  14035.    blocks, indenting
  14036.    continuing
  14037.    continuing if suspended
  14038.    defined
  14039.    executing to cursor
  14040.    execution
  14041.      continuing
  14042.      suspending
  14043.    existing, starting
  14044.    exiting
  14045.    flow, tracing
  14046.    instructions
  14047.    multiple module
  14048.    new, starting
  14049.    output
  14050.    resetting variables
  14051.    restarting
  14052.    restarting at first executable statement
  14053.    running
  14054.    run-time module required with
  14055.    sample, on disk
  14056.    selecting
  14057.    setup
  14058.    stand-alone
  14059.    starting
  14060.    steps
  14061.    stopping execution
  14062.    structured
  14063.    suspending execution
  14064.    testing
  14065.  Prompts, defined
  14066.  
  14067.  Q
  14068.  
  14069.  QB AdvisorHelp
  14070.  QB command
  14071.  QB Express
  14072.  QB.INI file
  14073.  QCARDS program
  14074.  Quick libraries
  14075.    See also Libraries
  14076.    defined
  14077.    file naming
  14078.    updating previous
  14079.  QuickBASIC
  14080.    debugging features
  14081.    installing
  14082.    keywords
  14083.    manuals, how to use
  14084.    mouse use
  14085.    options
  14086.    starting
  14087.  QuickBASIC environment, returning to
  14088.  QuickBASIC, Fast Load and Save option
  14089.  Quick-library loading option (QB)
  14090.  Quitting QuickBASIC
  14091.  
  14092.  R
  14093.  
  14094.  RAM space, saving with executable files
  14095.  README.DOC
  14096.  Read-only files
  14097.  Records
  14098.  Recursion
  14099.  Redirection
  14100.  Reference bar
  14101.    described
  14102.    illus.
  14103.  Reference, passing by
  14104.  Registers
  14105.  Relational operators
  14106.  Relational statements
  14107.  Remote-reception buffer-size option (QB)
  14108.  RemovingDeleting
  14109.    modules
  14110.    text
  14111.  Renaming programs
  14112.  Repeat Last Find command
  14113.  Repeat previous search
  14114.  Repeating program statements
  14115.  Replacing text
  14116.    See also Pasting text
  14117.  Reserved words. See Keywords
  14118.  Resetting variables
  14119.  Restart command
  14120.  RETURN statement
  14121.  RETURN without GOSUB error, cause
  14122.  Right Mouse command
  14123.  Row/column counters
  14124.  /RUN option (QB)
  14125.  Run menu
  14126.    debugging commands
  14127.    Make EXE File command
  14128.    Make Library command
  14129.      described
  14130.    Set Main Module command
  14131.  Run time
  14132.    defined
  14133.    errors
  14134.      checking
  14135.      hint regarding
  14136.      reporting locations
  14137.      simulating
  14138.  Running programs
  14139.    debugging commands
  14140.    errors in
  14141.    new
  14142.  Run-time libraries
  14143.    defined
  14144.    executable files
  14145.  Run-time module
  14146.    defined
  14147.    programs using
  14148.  
  14149.  S
  14150.  
  14151.  Save All command
  14152.  Save As command
  14153.    described
  14154.    dialog box, illus.
  14155.    Fast Load and Save option
  14156.    QuickBASIC option
  14157.    Text option
  14158.  Save command
  14159.  Saving
  14160.    files
  14161.    .MAK files
  14162.    procedures
  14163.  Saving programs
  14164.  Scope
  14165.  Screen
  14166.    clearing
  14167.    colors, setting
  14168.    display, customizing
  14169.    displaying data on
  14170.    illus.
  14171.    QuickBASIC
  14172.  Screen-update-speed option (QB)
  14173.  Scroll arrow, illus.
  14174.  Scroll bars
  14175.    defined
  14176.    illus.
  14177.    option (Display command)
  14178.    setting
  14179.  Scroll box
  14180.  Scrolling
  14181.    defined
  14182.    keyboard commands
  14183.    keys, summary of
  14184.    mouse
  14185.    text in a window
  14186.  Search menu
  14187.    Change command
  14188.    commands (list)
  14189.    Find command
  14190.    Label command
  14191.    Repeat Last Find command
  14192.    Selected Text command
  14193.  Search Paths command
  14194.  Searching
  14195.    labels
  14196.    procedures
  14197.    text
  14198.  Segments
  14199.  SELECT CASE statement
  14200.    described
  14201.    help screen, illus.
  14202.  Selected Text command
  14203.  Selecting
  14204.    menus
  14205.    programs
  14206.    text
  14207.      cautions
  14208.      described
  14209.      editing functions
  14210.      removing selection
  14211.      summary of
  14212.  Sequence of procedures
  14213.  Sequential files
  14214.  Serial ports
  14215.  Set Main Module command
  14216.  Set Next Statement command
  14217.  Set Paths command
  14218.  Setting
  14219.    breakpoints
  14220.    screen attributes, currently executing lines
  14221.    screen colors
  14222.    scroll bars
  14223.    tab stops
  14224.  Setting up QuickBASIC
  14225.  Setup menu
  14226.  Setup program
  14227.  SHARED
  14228.  Shortcut keys
  14229.    commands
  14230.    described
  14231.    introduction
  14232.    (table)
  14233.  Simple variables
  14234.  Single precision
  14235.  Single stepping
  14236.  Smart editor
  14237.    See also Editor
  14238.    automatic procedure declarations
  14239.    defined
  14240.    described
  14241.    syntax checking
  14242.  Source files
  14243.  SPACEBAR, using in dialog boxes
  14244.  Special characters, methods for entering
  14245.  Split command
  14246.  Splitting windows
  14247.  Stack
  14248.    Calls menu
  14249.    defined
  14250.  Stand-alone EXE File option
  14251.  Stand-alone files
  14252.  Stand-alone libraries. See Libraries
  14253.  Stand-alone programs, advantages
  14254.  Standard input and output
  14255.  Start command
  14256.  StartingLoading
  14257.    programs
  14258.      at specific statement
  14259.      existing
  14260.      new
  14261.    QuickBASIC
  14262.  Starting QuickBASIC
  14263.    monitors, monochrome
  14264.  Statement checking. See Syntax checking
  14265.  Statements
  14266.    beginning execution from
  14267.    CHAIN
  14268.    COMMON
  14269.    DECLARE
  14270.    defined
  14271.    DIM
  14272.    DO, Help, illus.
  14273.    ERROR
  14274.    GOSUB
  14275.    IF...THEN...ELSE, help, illus.
  14276.    INPUT
  14277.    next to execute
  14278.    PRINT
  14279.    RETURN
  14280.    SELECT CASE
  14281.      described
  14282.      help screen, illus.
  14283.    STEP
  14284.    using help to construct
  14285.  Static arrays
  14286.  STEP statement
  14287.  Stop bits
  14288.  Stopping programs
  14289.  String variables
  14290.  Strings
  14291.    character
  14292.    combining
  14293.    defined
  14294.    passing to QuickBASIC
  14295.  Structured programming
  14296.  SUB procedures
  14297.    creating
  14298.    default data type
  14299.    defined
  14300.    naming
  14301.    viewing
  14302.  Subprograms
  14303.    creating
  14304.    defined
  14305.  Subroutines
  14306.  SUBS command
  14307.    described
  14308.    dialog box, illus.
  14309.    illus.
  14310.    moving procedures
  14311.  Subscripts, defined
  14312.  Suspending program execution
  14313.  Switching active window
  14314.  Symbol help
  14315.  Symbolic constants
  14316.  Symbolic debuggers
  14317.  Symbols
  14318.    defined
  14319.    global
  14320.    help
  14321.    local
  14322.    using
  14323.  Syntax
  14324.    checking
  14325.    errors, checking
  14326.    help
  14327.  Syntax Checking command
  14328.    described
  14329.    introduction
  14330.    turning off
  14331.  
  14332.  T
  14333.  
  14334.  Tab
  14335.  TAB key, dialog boxes, using in
  14336.  Tab stops, setting
  14337.  Testing, programs
  14338.  Text
  14339.    changing
  14340.    copying
  14341.    defined
  14342.    deleting
  14343.    editors
  14344.    entering
  14345.    finding
  14346.    indenting
  14347.    inserting
  14348.    moving
  14349.    option, Save As command
  14350.    overtyping
  14351.    pasting
  14352.    removing
  14353.    replacing
  14354.    searching for
  14355.    selecting
  14356.  Text boxes
  14357.    defined
  14358.    described
  14359.    errors, correcting
  14360.    illus.
  14361.  Text files
  14362.  Tiling
  14363.  Title bar
  14364.    defined
  14365.    described
  14366.    illus
  14367.  Toggle Breakpoint command
  14368.  Toggles
  14369.  Tokens
  14370.  Topic command
  14371.  Trace On command
  14372.  Tracing
  14373.    backwards
  14374.    forward
  14375.    introduction
  14376.    procedure steps
  14377.    program flow
  14378.  Tracing through Help screens
  14379.  Trapping events, defined
  14380.  Truth, representation
  14381.  Tutorial, how to use
  14382.  Two's complement
  14383.  Types
  14384.  Typing mistakes
  14385.  Typographic conventions
  14386.  
  14387.  U
  14388.  
  14389.  Underflow
  14390.  Undo command
  14391.  Unload File command
  14392.  Unloading modules
  14393.  Unresolved externals
  14394.  UNTIL keyword
  14395.  User-defined types
  14396.  Using help
  14397.  
  14398.  V
  14399.  
  14400.  Value, passing by
  14401.  Values, changing in running programs
  14402.  Variables
  14403.    arrays
  14404.    automatic
  14405.    default type
  14406.    defined
  14407.    deleting from Watch window
  14408.    displaying
  14409.    floating-point
  14410.    global
  14411.    help
  14412.    illegal assignments
  14413.    initialization
  14414.    integer
  14415.    local
  14416.    naming conventions
  14417.    resetting
  14418.    simple
  14419.    string
  14420.    types
  14421.    values
  14422.      changing
  14423.      current
  14424.      determining
  14425.    watch
  14426.  Video Graphics Array (VGA)
  14427.  View menu
  14428.    commands (list)
  14429.    Include File command
  14430.    Included Lines command
  14431.    Next Statement command
  14432.    Next SUB command
  14433.    Output Screen command
  14434.    Split command
  14435.    SUBs command
  14436.  View window
  14437.    clearing
  14438.    defined
  14439.    described
  14440.    illus.
  14441.    loading a program in
  14442.    moving procedures
  14443.    procedures in
  14444.    programming in
  14445.    splitting
  14446.  Viewing procedures
  14447.  
  14448.  W
  14449.  
  14450.  Watch expressions
  14451.  Watch variables, debugging
  14452.  Watch window
  14453.    closing
  14454.    commands
  14455.    debugging programs
  14456.    defined
  14457.    deleting variables from
  14458.    described
  14459.    illus.
  14460.    monitoring variable values
  14461.    placing variable into
  14462.    watchpoints
  14463.  Watchable
  14464.  Watching expressions, in Watch window
  14465.  Watchpoints
  14466.  WHILE keyword
  14467.  WIndows
  14468.    activating
  14469.  Windows
  14470.    active
  14471.      changing
  14472.      described
  14473.    available with Easy Menus
  14474.    defined
  14475.    Help
  14476.      described
  14477.      illus.
  14478.      moving in
  14479.    Immediate
  14480.      calculations
  14481.      calling procedures from
  14482.      capacity
  14483.      debugging in
  14484.      defined
  14485.      described
  14486.      illus.
  14487.      running statements in
  14488.      run-time errors, simulating
  14489.      statements not supported
  14490.      testing programs
  14491.      variable values, changing
  14492.      window size, changing
  14493.    moving between
  14494.    size, changing
  14495.    splitting
  14496.    View
  14497.      defined
  14498.      described
  14499.      illus.
  14500.      loading a program
  14501.      procedures in
  14502.      programming in
  14503.      splitting
  14504.    Watch
  14505.      closing
  14506.      commands
  14507.      debugging programs
  14508.      defined
  14509.      deleting variables from
  14510.      described
  14511.      monitoring variable values
  14512.      placing variable into
  14513.      watchpoints
  14514.    watch
  14515.      described
  14516.  WordStar-style command indicator, illus.
  14517.