home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft_Programmers_Library.7z / MPL / basic / b71lang.txt next >
Encoding:
Text File  |  2013-11-08  |  1.0 MB  |  34,551 lines

Text Truncated. Only the first 1MB is shown below. Download the file for the complete contents.
  1.  BASIC Language Reference
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  ────────────────────────────────────────────────────────────────────────────
  10.  
  11.                     Microsoft(R) BASIC Language Reference
  12.                for IBM(R) Personal Computers and Compatibles
  13.  
  14.  ────────────────────────────────────────────────────────────────────────────
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  Information in this document is subject to change without notice and
  25.  does not represent a commitment on the part of Microsoft Corporation.
  26.  The software described in this document is furnished under a license
  27.  agreement or nondisclosure agreement. The software may be used or copied
  28.  only in accordance with the terms of the agreement. It is against the
  29.  law to copy the software on any medium except as specifically allowed in
  30.  the license or nondisclosure agreement. No part of this manual may be
  31.  reproduced or transmitted in any form or by any means, electronic or
  32.  mechanical, including photocopying and recording, for any purpose
  33.  without the express written permission of Microsoft.
  34.  
  35.  Copyright 1989, Microsoft Corporation. All rights reserved.
  36.  
  37.  Simultaneously published in the U.S. and Canada.
  38.  
  39.  Printed and bound in the United States of America.
  40.  
  41.  
  42.  
  43.  Microsoft, MS, MS-DOS, and CodeView are registered trademarks of
  44.  Microsoft Corporation.
  45.  
  46.  Apple and Macintosh are registered trademarks of Apple Computer,
  47.  Inc.
  48.  
  49.  Helvetica and Times Roman are registered trademarks of Linotype AG
  50.  and its subsidiaries.
  51.  
  52.  Hercules is a registered trademark and InColor is a trademark of
  53.  Hercules Computer Technology.
  54.  
  55.  IBM is a registered trademark of International Business Machines
  56.  Corporation.
  57.  
  58.  Intel is a registered trademark of Intel Corporation.
  59.  
  60.  Olivetti is a registered trademark of Ing. C. Olivetti.
  61.  
  62.  WordStar is a registered trademark of MicroPro International
  63.  Corporation.
  64.  
  65.  
  66.  
  67.  Document No. DB0118-700-R00-1089
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  Introduction
  74.  ────────────────────────────────────────────────────────────────────────────
  75.  
  76.  
  77.  The printed documentation for Microsoft BASIC 7.0 Professional Development
  78.  System consists of three books: Getting Started, the BASIC Language
  79.  Reference, and the Programmer's Guide.
  80.  
  81.  Getting Started contains detailed information on setting up and customizing
  82.  Microsoft BASIC to optimize program size and speed. It also introduces new
  83.  features of this version of Microsoft BASIC and provides a brief
  84.  introduction to the new Microsoft Advisor online Help system.
  85.  
  86.  The  BASIC Language Reference has these parts:
  87.  
  88.    ■   Part 1, "Language Reference," contains reference material and
  89.        programming examples for each BASIC function, statement, and
  90.        metacommand, organized alphabetically.
  91.  
  92.    ■   Part 2, "Add-On-Library Reference," contains reference material on the
  93.        SUB and  FUNCTION procedures that are supported by the add-on
  94.        libraries included with Microsoft BASIC. These add-on libraries give
  95.        you date/time, financial, and format functions.
  96.  
  97.    ■   Part 3, "BASIC Toolbox Reference," contains reference material on the
  98.        SUB and  FUNCTION procedures that are supported by the toolbox files
  99.        included with Microsoft BASIC. The toolboxes are Matrix Math,
  100.        Presentation Graphics, Font, and User Interface.
  101.  
  102.    ■   The appendixes include a list of keyboard scan and ASCII character
  103.        codes, a list of BASIC reserved words, a command-line tools quick
  104.        reference, reference information on error messages, and international
  105.        character sort order tables.
  106.  
  107.  
  108.  
  109.  The  Programmer's Guide contains topical information about programming
  110.  concepts and techniques and command-line tools.
  111.  
  112.  
  113.  Document Conventions
  114.  
  115.  This manual uses the following typographic conventions:
  116.  
  117.  Part 1 is a reference for each function, statement, and metacommand in the
  118.  BASIC language. Each entry is listed alphabetically and describes the action
  119.  performed, and the syntax to use. Arguments, options, and typical usage are
  120.  explained further under "Remarks." The "See Also" sections refer you to
  121.  related entries. In addition, example programs are included with the
  122.  descriptions so you can see exactly how a function or statement works.
  123.  In the beginning of Part 1 are summary tables for selected BASIC functions
  124.  and statements. Each table contains entries that perform related tasks.
  125.  Within each table, you can quickly see specific tasks you can accomplish,
  126.  the functions or statements to use, and the actions that result.
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  BASIC Functions and Statements
  134.  
  135.  The sections in this chapter are made up of related BASIC functions and
  136.  statements that have been grouped together according to programming tasks.
  137.  Each group's functions and statements are presented in tabular form, listing
  138.  the type of task performed by each function or statement (for example,
  139.  looping or searching), and the corresponding program action that takes
  140.  place.
  141.  
  142.  The following topics are summarized:
  143.  *    Control-flow functions and statements
  144.  *    Procedure-related statements
  145.  *    Standard I/O functions and statements
  146.  *    File I/O functions and statements
  147.  *    ISAM File I/O functions and statements
  148.  *    String-processing functions and statements
  149.  *    Graphics functions and statements
  150.  *    Trapping functions and statements
  151.  
  152.  You can use these tables both as a reference guide to what each statement or
  153.  function does and as a way to identify related statements.
  154.  
  155.  
  156.  Note
  157.  Not all BASIC functions and statements are listed in these tables, only
  158.  those recommended for structured programming. For complete information on
  159.  all functions and statements, see the alphabetic entries that follow these
  160.  tables.
  161.  
  162.  
  163.  
  164.  Control-Flow Functions and Statements
  165.  
  166.  
  167.  Looping
  168.  -------
  169.  FOR...NEXT
  170.  Repeats statements between FOR and NEXT a specific number of times.
  171.  
  172.  EXIT FOR
  173.  Provides an alternative way to exit a FOR...NEXT loop.
  174.  
  175.  DO...LOOP
  176.  Repeats statements between DO and LOOP, either until a given condition is
  177.  true (DO...LOOP UNTIL condition), or while a given condition is true
  178.  (DO...LOOP WHILE condition).
  179.  
  180.  EXIT DO
  181.  Provides an alternative way to exit a DO...LOOP loop.
  182.  
  183.  WHILE...WEND
  184.  Repeats statements between WHILE and WEND while a given condition is true
  185.  (similar to DO WHILE condition...LOOP).
  186.  
  187.  
  188.  Making decisions
  189.  ----------------
  190.  IF...THEN...ELSE
  191.  END IF
  192.  Conditionally executes or branches to different statements.
  193.  
  194.  SELECT CASE
  195.  END SELECT
  196.  Conditionally executes different statements.
  197.  
  198.  
  199.  Managing the stack
  200.  ------------------
  201.  STACK Function
  202.  Returns maximum stack size that can be allocated.
  203.  
  204.  STACK Statement
  205.  Sets stack to new size.
  206.  
  207.  
  208.  Exiting the program
  209.  -------------------
  210.  END number
  211.  SYSTEM number
  212.  STOP number
  213.  Exit the program and set error level defined by number. If number is not
  214.  present, exit the program with error level set to 0.
  215.  
  216.  
  217.  Procedure-Related Statements
  218.  
  219.  
  220.  Defining a procedure
  221.  --------------------
  222.  FUNCTION...
  223.  END FUNCTION
  224.  Marks the beginning and end, respectively, of a FUNCTION procedure.
  225.  
  226.  SUB...END SUB
  227.  Marks the beginning and end, respectively, of a SUB procedure.
  228.  
  229.  
  230.  Calling a procedure
  231.  -------------------
  232.  CALL
  233.  Transfers control to a BASIC SUB procedure, or to a procedure written in
  234.  another programming language and compiled separately. (The CALL keyword is
  235.  optional if a DECLARE statement is used.)
  236.  
  237.  
  238.  Exiting from a procedure
  239.  ------------------------
  240.  EXIT FUNCTION
  241.  Provides an alternative way to exit a FUNCTION procedure.
  242.  
  243.  EXIT SUB
  244.  Provides an alternative way to exit a SUB procedure.
  245.  
  246.  
  247.  Declaring a reference to a procedure
  248.  ------------------------------------
  249.  DECLARE
  250.  Declares a FUNCTION or SUB procedure and, optionally, specifies the number
  251.  and type of its parameters.
  252.  
  253.  
  254.  Sharing variables among modules, procedures, or programs
  255.  --------------------------------------------------------
  256.  COMMON
  257.  Shares variables among separate modules. When used with the SHARED
  258.  attribute, COMMON blocks share variables among different procedures in the
  259.  same module. When used with a blank (unnamed) COMMON block, variables pass
  260.  from current program to new program when control is transferred with the
  261.  CHAIN statement.
  262.  
  263.  SHARED
  264.  When used with the COMMON, DIM, or REDIM statement at the module level (for
  265.  example, DIM SHARED), shares variables with every SUB or FUNCTION procedure
  266.  in a single module.
  267.  When used by itself within a procedure, shares variables between that
  268.  procedure and the module-level code.
  269.  
  270.  Preserving variable values
  271.  --------------------------
  272.  STATIC
  273.  Forces variables to be local to a procedure or DEF FN function and preserves
  274.  the value stored in the variable if the procedure or function is exited,
  275.  then called again.
  276.  
  277.  
  278.  Standard I/O Functions and Statements
  279.  
  280.  Printing text on the screen
  281.  ---------------------------
  282.  PRINT
  283.  Outputs text to the screen. Using PRINT with no arguments creates a blank
  284.  line.
  285.  
  286.  PRINT USING
  287.  Outputs formatted text to the screen.
  288.  
  289.  Changing the width of the output line
  290.  -------------------------------------
  291.  WIDTH
  292.  Changes the width of the screen to either 40 columns or 80 columns. Also, on
  293.  computers with an EGA or VGA, controls the number of lines on the screen (25
  294.  or 43).
  295.  
  296.  
  297.  WIDTH "SCRN:"
  298.  Assigns a maximum length to lines output to the screen when used before an
  299.  OPEN "SCRN:" statement.
  300.  
  301.  Getting input from the keyboard
  302.  -------------------------------
  303.  INKEY$
  304.  Reads a character from the keyboard (or a null string if no character is
  305.  waiting).
  306.  
  307.  INPUT$
  308.  Reads a specified number of characters from the keyboard and stores them in
  309.  a single string variable.
  310.  
  311.  INPUT
  312.  Reads input from the keyboard and stores it in a list of variables.
  313.  
  314.  LINE INPUT
  315.  Reads a line of input from the keyboard and stores it in a single string
  316.  variable.
  317.  
  318.  Positioning the cursor on the screen
  319.  ------------------------------------
  320.  LOCATE
  321.  Moves the cursor to a specified row and column. Also sets cursor size and
  322.  turns it on and off.
  323.  
  324.  SPC
  325.  Skips a specified number of spaces in printed output.
  326.  
  327.  TAB
  328.  Displays printed output in a given column.
  329.  
  330.  Getting information on cursor location
  331.  --------------------------------------
  332.  CSRLIN
  333.  Tells which row or line position the cursor is in.
  334.  
  335.  POS(n)
  336.  Tells which column the cursor is in.
  337.  
  338.  Creating a text viewport
  339.  ------------------------
  340.  VIEW PRINT
  341.  Sets the top and bottom rows for displaying text output.
  342.  
  343.  
  344.  File I/O Functions and Statements
  345.  
  346.  Creating a new file or accessing an existing file or device
  347.  -----------------------------------------------------------
  348.  OPEN
  349.  Opens a file or device for retrieving or storing records (I/O).
  350.  
  351.  Closing a file or device
  352.  ------------------------
  353.  CLOSE
  354.  Ends I/O to a file or device.
  355.  
  356.  
  357.  Storing data in a file
  358.  ----------------------
  359.  PRINT #
  360.  Stores a list of variables as record fields in a previously opened file.1
  361.  
  362.  PRINT # USING
  363.  Similar to PRINT #, except PRINT # USING formats the record fields.1
  364.  
  365.  WRITE #
  366.  Stores a list of variables as record fields in a previously opened file.1
  367.  
  368.  WIDTH #
  369.  Specifies a standard width for each record in a file.1
  370.  
  371.  PUT
  372.  Stores the contents of a user-defined variable in a previously opened file.2
  373.  
  374.  
  375.  Retrieving data from a file
  376.  ---------------------------
  377.  INPUT #
  378.  Reads fields from a record and assigns each field in the record to a program
  379.  variable.1
  380.  
  381.  INPUT$
  382.  Reads a string of characters from a file.
  383.  
  384.  LINE INPUT #
  385.  Reads a record and stores it in a single string variable.1
  386.  
  387.  GET
  388.  Reads data from a file and assigns the data to elements of a user-defined
  389.  variable.2
  390.  
  391.  
  392.  Getting information about a file
  393.  --------------------------------
  394.  EOF
  395.  Tests whether all data has been read from a file.
  396.  
  397.  FILEATTR
  398.  Returns the number assigned by the operating system to an open file and a
  399.  number that indicates the mode in which the file was opened (input, output,
  400.  append, binary, random, or ISAM).
  401.  
  402.  LOC
  403.  Gives the current position within a file. With binary access, this is the
  404.  byte position. With sequential access, this is the byte position divided by
  405.  128. With random access, this is the record number of the last record read
  406.  or written.
  407.  
  408.  LOF
  409.  Gives number of bytes in open file.
  410.  
  411.  SEEK Function
  412.  Gives the location where the next I/O operation will take place. With random
  413.  access, this is the number of the next record to be read or written. With
  414.  all other kinds of file access, this is the byte position of the next byte
  415.  to be read or written.
  416.  
  417.  
  418.  Moving around in a file
  419.  -----------------------
  420.  SEEK Statement
  421.  Sets the byte position or record number for the next read or write operation
  422.  in an open file.
  423.  
  424.  
  425.  Managing disk drives, directories, and files
  426.  --------------------------------------------
  427.  CHDRIVE
  428.  Changes the current drive.
  429.  
  430.  CURDIR$
  431.  Gives current directory specifica-tion for specified drive (or current drive
  432.  if no drive is specified).
  433.  
  434.  DIR$
  435.  On first call, returns the first file that matches the file specification.
  436.  On successive calls (with no argument), returns remaining files matching the
  437.  file specification.
  438.  
  439.  FILES
  440.  Prints a listing of the files in a specified directory.
  441.  
  442.  FREEFILE
  443.  Returns next available file number.
  444.  
  445.  KILL
  446.  Deletes a file from the disk.
  447.  
  448.  NAME
  449.  Changes a file's name.
  450.  1     For use with sequential files.
  451.  2     For use with binary or random-access files.
  452.  
  453.  
  454.  ISAM File I/O Functions and Statements
  455.  
  456.  
  457.  Opening and closing tables and databases
  458.  ----------------------------------------
  459.  OPEN database$ FOR ISAM tabletype tablename$
  460.     AS #█ filenumber%
  461.  Opens a database or creates a new database, opens a table or creates a new
  462.  table.
  463.  
  464.  CLOSE
  465.  Closes a specified table.
  466.  
  467.  TYPE tabletype
  468.  columnname AS tablename
  469.  {columnname AS typename}
  470.  END TYPE
  471.  Declares the type of the record that is used to build the table.
  472.  
  473.  
  474.  Managing the data dictionary
  475.  ----------------------------
  476.  CREATEINDEX
  477.  Creates an index.
  478.  
  479.  DELETEINDEX
  480.  Deletes an index.
  481.  
  482.  
  483.  Positioning
  484.  -----------
  485.  MOVEFIRST
  486.  Makes the first record current.
  487.  
  488.  MOVELAST
  489.  Makes the last record current.
  490.  
  491.  MOVENEXT
  492.  Makes the next record current.
  493.  
  494.  MOVEPREVIOUS
  495.  Makes the previous record current.
  496.  
  497.  SEEKEQ
  498.  SEEKGE
  499.  SEEKGT
  500.  Makes matching record current.
  501.  
  502.  SETINDEX
  503.  Makes the named index the current index.
  504.  
  505.  
  506.  Getting information about a table
  507.  ---------------------------------
  508.  BOF
  509.  Returns TRUE when the current position is beyond the first record of the
  510.  current index.
  511.  
  512.  EOF
  513.  Returns TRUE when the current position is beyond the last record of the
  514.  current index.
  515.  
  516.  FILEATTR
  517.  Returns information about an open ISAM table.
  518.  
  519.  GETINDEX$
  520.  Returns name of the current index.
  521.  
  522.  LOF
  523.  Returns the number of records in a table.
  524.  
  525.  
  526.  Exchanging data
  527.  ---------------
  528.  INSERT
  529.  Inserts a record in a table.
  530.  
  531.  RETRIEVE
  532.  Retrieves the current record.
  533.  
  534.  UPDATE
  535.  Overwrites current record.
  536.  
  537.  DELETE
  538.  Deletes the current record.
  539.  
  540.  
  541.  Transaction processing
  542.  ----------------------
  543.  BEGINTRANS
  544.  Marks the beginning of a transaction.
  545.  
  546.  CHECKPOINT
  547.  Saves all currently open databases to disk.
  548.  
  549.  COMMITTRANS
  550.  Commits all changes since the most recent BEGINTRANS.
  551.  
  552.  ROLLBACK
  553.  Rolls back data to its state at the savepoint.
  554.  
  555.  ROLLBACK ALL
  556.  Rolls back state of database to beginning of current transaction.
  557.  
  558.  SAVEPOINT%
  559.  Defines a savepoint and returns savepoint's reference number.
  560.  
  561.  Comparing text
  562.  --------------
  563.  TEXTCOMP
  564.  Compares two strings as they would be compared by ISAM.
  565.  
  566.  
  567.  String-Processing Functions and Statements
  568.  
  569.  
  570.  Getting part of a string
  571.  ------------------------
  572.  LEFT$
  573.  Returns given number of characters from the left side of a string.
  574.  
  575.  RIGHT$
  576.  Returns given number of characters from the right side of a string.
  577.  
  578.  LTRIM$
  579.  Returns a copy of a string with leading spaces stripped away.
  580.  
  581.  RTRIM$
  582.  Returns a copy of a string with trailing spaces stripped away.
  583.  
  584.  MID$ function
  585.  Returns given number of characters from anywhere in a string.
  586.  
  587.  
  588.  Calculating available memory space
  589.  ----------------------------------
  590.  FRE(a$)
  591.  For far strings, returns the space remaining in a$'s segment. For near
  592.  strings, compacts string storage space and returns space remaining in
  593.  DGROUP.
  594.  
  595.  FRE(literal string)
  596.  For far strings, returns the space remaining in the temporary string
  597.  segment. For near strings, compacts string storage space and returns space
  598.  remaining in DGROUP.
  599.  
  600.  FRE(number)
  601.  Measures available storage for strings, nonstring arrays, or the stack.
  602.  
  603.  
  604.  Searching strings
  605.  -----------------
  606.  INSTR
  607.  Searches for a string within another string.
  608.  
  609.  
  610.  Converting to uppercase or lowercase letters
  611.  --------------------------------------------
  612.  LCASE$
  613.  Returns a copy of a string with all uppercase letters (A-Z) converted to
  614.  lowercase letters (a-z); leaves lowercase letters and other characters
  615.  unchanged.
  616.  
  617.  UCASE$
  618.  Returns a copy of a string with all lowercase letters (a-z) converted to
  619.  uppercase letters (A-Z); leaves uppercase letters and other characters
  620.  unchanged.
  621.  
  622.  
  623.  Changing strings
  624.  ----------------
  625.  MID$ Statement
  626.  Replaces part of a string with another string.
  627.  
  628.  LSET
  629.  Left justifies a string within a fixed-length string.
  630.  
  631.  RSET
  632.  Right justifies a string within a fixed-length string.
  633.  
  634.  
  635.  Converting between numbers and strings
  636.  --------------------------------------
  637.  STR$
  638.  Returns the string representation of the value of a numeric expression.
  639.  
  640.  VAL
  641.  Returns the numeric value of a string expression.
  642.  
  643.  
  644.  Creating strings of repeating characters
  645.  ----------------------------------------
  646.  SPACE$
  647.  Returns a string of blank characters of a specified length.
  648.  
  649.  STRING$
  650.  Returns a string consisting of one repeated character.
  651.  
  652.  
  653.  Getting the length of a string
  654.  ------------------------------
  655.  LEN
  656.  Tells how many characters are in a string.
  657.  
  658.  
  659.  Working with ASCII values
  660.  -------------------------
  661.  ASC
  662.  Returns the ASCII value of the given character.
  663.  
  664.  CHR$
  665.  Returns the character with the given ASCII value.
  666.  
  667.  
  668.  Creating string pointers
  669.  ------------------------
  670.  SSEG
  671.  Returns the segment of the string data.
  672.  
  673.  SADD
  674.  Returns the offset of the string data.
  675.  
  676.  SSEGADD
  677.  Returns a far pointer to the string data.
  678.  
  679.  VARPTR
  680.  Returns the offset address of a variable or string descriptor.
  681.  
  682.  VARSEG
  683.  Returns the segment address of a variable or string descriptor.
  684.  
  685.  
  686.  Graphics Functions and Statements
  687.  
  688.  Setting screen- display characteristics
  689.  ---------------------------------------
  690.  SCREEN Statement
  691.  Specifies a BASIC screen mode, which determines screen characteristics such
  692.  as graphics capability, resolution, and color-number range.
  693.  
  694.  SCREEN Function
  695.  Returns a character's ASCII value or its color from a specified screen
  696.  location.
  697.  
  698.  
  699.  Plotting or erasing a single point
  700.  ----------------------------------
  701.  PSET
  702.  Draws a pixel on the screen in the specified color, using the screen's
  703.  foreground color as default.
  704.  
  705.  PRESET
  706.  Draws a pixel on the screen in the specified color, using the screen's
  707.  background color as default.
  708.  
  709.  Drawing shapes
  710.  --------------
  711.  LINE
  712.  Draws a straight line or a box.
  713.  
  714.  CIRCLE
  715.  Draws a circle, ellipse, arc, or pie.
  716.  
  717.  DRAW
  718.  Draws an object. Combines many of the features of other BASIC graphics
  719.  statements into a graphics macro language.
  720.  
  721.  
  722.  Defining screen coordinates
  723.  ---------------------------
  724.  VIEW
  725.  Specifies a rectangle on the screen (or viewport) as the area for graphics
  726.  output.
  727.  
  728.  WINDOW
  729.  Defines the dimensions of the current viewport.
  730.  
  731.  PMAP
  732.  Maps view coordinates to window coordinates, or vice versa.
  733.  
  734.  POINT(number)
  735.  Returns the screen coordinates of the graphics cursor, or the color of a
  736.  specified pixel.
  737.  
  738.  
  739.  Using color
  740.  -----------
  741.  COLOR
  742.  Sets the default colors used in graphics output.
  743.  
  744.  PALETTE
  745.  Assigns different attributes to color numbers. Works only on systems
  746.  equipped with an EGA or VGA.
  747.  
  748.  POINT(x, y)
  749.  Returns the color number of a pixel whose screen coordinates are x and y.
  750.  
  751.  
  752.  Painting enclosed shapes
  753.  ------------------------
  754.  PAINT
  755.  Fills an area on the screen with a color or pattern.
  756.  
  757.  
  758.  Animating
  759.  ---------
  760.  GET
  761.  Copies a rectangular area on the screen by translating the image to numeric
  762.  data and storing the data in a numeric array.
  763.  
  764.  PUT
  765.  Displays an image on the screen that was previously copied with GET.
  766.  
  767.  PCOPY
  768.  Copies one screen page to another.
  769.  
  770.  
  771.  
  772.  Trapping Functions and Statements
  773.  
  774.  
  775.  Trapping errors while a program is running
  776.  ------------------------------------------
  777.  ON ERROR GOTO line
  778.  At the module level, causes a program to branch to line, where line refers
  779.  to either a line number or line label. Branching takes place whenever an
  780.  error occurs during execution.
  781.  
  782.  ON LOCAL ERROR
  783.  GOTO line
  784.  At the procedure level, causes a program to branch to line, where line
  785.  refers to either a line number or line label. Branching takes place whenever
  786.  an error occurs during execution of the procedure.
  787.  
  788.  ON ERROR RESUME NEXT
  789.  At the module level, causes an implicit error trap, then RESUME NEXT.
  790.  Returns the error number in ERR.
  791.  
  792.  ON LOCAL ERROR RESUME NEXT
  793.  At the procedure level, causes an implicit error trap, then RESUME NEXT.
  794.  Returns the error number in ERR.
  795.  
  796.  RESUME
  797.  Returns control to the program after executing an error-handling routine.
  798.  The program resumes at either the statement causing the error (RESUME), the
  799.  statement after the one causing the error (RESUME NEXT), or the line
  800.  identified by line (RESUME line)
  801.  
  802.  
  803.  Getting error-status data
  804.  -------------------------
  805.  ERR Function
  806.  Returns the code for an error that occurs at run time.
  807.  
  808.  ERR Statement
  809.  Sets ERR to an integer.
  810.  
  811.  ERL
  812.  Returns the number of the line on which an error occurred (if program has
  813.  line numbers).
  814.  
  815.  ERDEV
  816.  Returns a device-specific error code for the last device (such as a printer)
  817.  for which the system detected an error.
  818.  
  819.  ERDEV$
  820.  Returns the name of the last device for which the system detected an error.
  821.  
  822.  
  823.  Defining your own error codes
  824.  -----------------------------
  825.  ERROR
  826.  Simulates the occurrence of a BASIC error; can also be used to define an
  827.  error not trapped by BASIC.
  828.  
  829.  
  830.  Trapping events while a program is running
  831.  ------------------------------------------
  832.  ON event GOSUB line
  833.  Causes a branch to the subroutine starting with line, where line refers
  834.  either to a line number or line label, whenever event occurs during
  835.  execution.
  836.  
  837.  event ON
  838.  Enables trapping of event.
  839.  
  840.  event OFF
  841.  Disables trapping of event.
  842.  
  843.  event STOP
  844.  Suspends trapping of event.
  845.  
  846.  EVENT ON
  847.  Enables event trapping.
  848.  
  849.  EVENT OFF
  850.  Disables event trapping.
  851.  
  852.  RETURN
  853.  Returns control to the program after executing an event-handling subroutine.
  854.  The program resumes at either the statement immediately following the
  855.  statement that called the subroutine (RETURN), or the line that is
  856.  identified by line (RETURN line).
  857.  
  858.  
  859.  
  860.  
  861.  ABS Function
  862.  ────────────────────────────────────────────────────────────────────────────
  863.  
  864.  
  865.  Action
  866.  
  867.  Returns the absolute value of a numeric expression.
  868.  
  869.  
  870.  Syntax
  871.  
  872.   ABS( numeric-expression#)
  873.  
  874.  
  875.  Remarks
  876.  
  877.  The absolute value is the unsigned magnitude of its argument. For example,
  878.  ABS(-1) and ABS(1) are both 1.
  879.  
  880.  
  881.  Example
  882.  
  883.  The following example finds an approximate value for a cube root. It uses
  884.  ABS to find the difference between two guesses to see if the current
  885.  guess is accurate.  DEFDBL establishes the default data type for
  886.  all variables.
  887.  
  888.  DEFDBL A-Z
  889.  Precision = .0000001#
  890.  CLS                               ' Clear the screen.
  891.  INPUT "Enter a value: ", Value    ' Prompt for input.
  892.  ' Make the first two guesses.
  893.  X1 = 0#: X2 = Value
  894.  ' Loop until the difference between guesses is
  895.  ' less than the required precision.
  896.  DO UNTIL ABS(X1 - X2) < Precision
  897.      X = (X1 + X2) / 2#
  898.      ' Adjust the guesses.
  899.      IF X * X * X - Value < 0# THEN
  900.          X1 = X
  901.      ELSE
  902.          X2 = X
  903.      END IF
  904.  LOOP
  905.  PRINT "The cube root is "; X
  906.  
  907.  
  908.  Output
  909.  
  910.  Enter a value: 27
  911.  
  912.  The cube root is  2.99999997206032
  913.  
  914.  
  915.  
  916.  
  917.  Absolute Routine
  918.  ────────────────────────────────────────────────────────────────────────────
  919.  
  920.  
  921.  Action
  922.  
  923.  Transfers control to a machine-language procedure.
  924.  
  925.  
  926.  Syntax
  927.  
  928.   CALL  Absolute (« argumentlist,»  integervariable%)
  929.  
  930.  
  931.  Remarks
  932.  
  933.  The  Absolute routine uses the following arguments:
  934.  
  935. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  936.  Argument                                Description
  937.  ────────────────────────────────────────────────────────────────────────────
  938.   argumentlist                           Arguments passed to a
  939.                                          machine-language procedure as
  940.                                          offsets (near pointers) from the
  941.                                          current data segment. Although
  942.                                          arguments are passed as offsets,
  943.                                          the machine-language program is
  944.                                          invoked with a far call.
  945.  
  946.   integervariable%                       The offset from the current code
  947.  Argument                                Description
  948.  ────────────────────────────────────────────────────────────────────────────
  949.  integervariable%                       The offset from the current code
  950.                                          segment, set by  DEF SEG, to the
  951.                                          starting location of the procedure.
  952.                                          The argument  integervariable% is
  953.                                          not passed to the procedure. Your
  954.                                          program may need to execute a  DEF
  955.                                          SEG statement before executing
  956.                                          Absolute to set the code segment
  957.                                          for the called routine. Using a
  958.                                          noninteger value for
  959.                                          integervariable% produces
  960.                                          unpredictable results.
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  Note
  968.  
  969.  The  Absolute routine is provided to maintain compatibility with earlier
  970.  versions of BASIC. Mixed-language programming using the  CALL and  DECLARE
  971.  statements provides a simpler way to use assembly language with BASIC.
  972.  
  973.  When using the  Absolute routine in OS/2 protected mode, be careful not to
  974.  refer to an illegal memory address. Before it executes the  Absolute
  975.  routine, BASIC attempts to get an executable-code-segment alias for the code
  976.  you wish to access. If this operation fails, BASIC generates the error
  977.  message Permission denied. A safe place to store user-written machine code
  978.  is in memory allocated for a conventional BASIC object, such as an array.
  979.  
  980.  To use the  Absolute routine in the QBX environment, use the QBX.QLB Quick
  981.  library.
  982.  
  983.  To use the  Absolute routine outside of the QBX environment, link your progra
  984.  with the QBX.LIB file.
  985.  
  986.  The QBX.BI header file contains the necessary declarations for the  Absolute
  987.  routine.
  988.  
  989.  
  990.  Basica
  991.  
  992.  Assembly-language programs that are invoked from BASICA and that have string
  993.  arguments must be changed, because string descriptors are now 4 bytes long.
  994.  For a near-string descriptor, the 4 bytes are the low byte and high byte of
  995.  the string length, followed by the low byte and high byte of the string
  996.  address. Far-string descriptors also are 4 bytes long, but their structure
  997.  is proprietary. For more information on using far-string descriptors, see
  998.  Chapter 12, "Mixed-Language Programming" and Chapter 13, "Mixed-Language
  999.  Programming with Far Strings" in the  Programmer's Guide.
  1000.  
  1001.  
  1002.  See Also
  1003.  
  1004.  CALL, CALLS Statements (Non-Basic)
  1005.  
  1006.  
  1007.  Example
  1008.  
  1009.  The following example uses  Absolute to execute a machine-language program
  1010.  stored in an array. The program indicates whether a math coprocessor is
  1011.  installed.
  1012.  
  1013.  CONST nASMBYTES = 14
  1014.  DEFINT A-Z
  1015.  DIM AsmProg(1 TO (nASMBYTES / 2))
  1016.  
  1017.  ' The machine-language program stored as data to read into the array.
  1018.  AsmBytes:
  1019.  DATA &H55  : ' PUSH BPSave base pointer.
  1020.  DATA &H8B, &HEC: ' MOV  BP,SP Get our own.
  1021.  DATA &HCD, &H11: ' INT  11HMake the ROM-BIOS call.
  1022.  DATA &H8B, &H5E, &H06: ' MOV  BX,[BP+6]Get argument address.
  1023.  DATA &H89, &H07: ' MOV  [BX],AXSave list in argument.
  1024.  DATA &H5D  : ' POP  BPRestore base pointer.
  1025.  DATA &HCA, &H02, &H00: ' RET  2Pop argument off stack
  1026.  'and make far return.
  1027.  
  1028.  ' Poke the machine-language program into the array.
  1029.  P = VARPTR(AsmProg(1))' Get the starting offset of the array.
  1030.  DEF SEG = VARSEG(AsmProg(1)) ' Change the segment.
  1031.  FOR I = 0 TO nASMBYTES - 1
  1032.  READ J
  1033.  POKE (P + I), J
  1034.  NEXT I
  1035.  
  1036.  ' Execute the program. The program expects a single integer argument.
  1037.  CALL Absolute(X%, VARPTR(AsmProg(1)))
  1038.  DEF SEG' Restore the segment.
  1039.  ' X% now contains bit-encoded equipment list returned by the system.
  1040.  ' Mask off all but the coprocessor bit (bit 2).
  1041.  CoProcessor = X% AND &H2
  1042.  IF CoProcessor = 2 THEN
  1043.  PRINT "Math coprocessor present."
  1044.  ELSE
  1045.  PRINT "No math coprocessor."
  1046.  END IF
  1047.  
  1048.  
  1049.  ASC Function
  1050.  ────────────────────────────────────────────────────────────────────────────
  1051.  
  1052.  
  1053.  Action
  1054.  
  1055.  Returns a numeric value that is the ASCII code for the first character in a
  1056.  string expression.
  1057.  
  1058.  
  1059.  Syntax
  1060.  
  1061.   ASC( stringexpression$)
  1062.  
  1063.  Remarks
  1064.  
  1065.  If the argument  stringexpression$ is null,  Basic generates the run-time
  1066.  error message Illegal function call.
  1067.  
  1068.  
  1069.  See Also
  1070.  
  1071.   CHR$; Appendix A, "Keyboard Scan Codes and ASCII Character Codes"
  1072.  
  1073.  
  1074.  Example
  1075.  
  1076.  The following example uses  ASC to calculate a hash value -- an index
  1077.  value for a table or file -- from a string:
  1078.  
  1079.  CONST HASHTABSIZE = 101
  1080.  CLS                             ' Clear the screen.
  1081.  INPUT "Enter a name: ",Nm$      ' Prompt for input.
  1082.  TmpVal = 0
  1083.  FOR I=1 TO LEN(Nm$)
  1084.      ' Convert the string to a number by summing the values
  1085.      ' of individual letters.
  1086.      TmpVal = TmpVal + ASC(MID$(Nm$,I,1))
  1087.  NEXT I
  1088.      ' Divide the sum by the size of the table.
  1089.      HashValue = TmpVal MOD HASHTABSIZE
  1090.  PRINT "The hash value is "; HashValue
  1091.  
  1092.  
  1093.  Output
  1094.  
  1095.  Enter a name: Bafflegab
  1096.  
  1097.  The hash value is  66
  1098.  
  1099.  
  1100.  ATN Function
  1101.  ────────────────────────────────────────────────────────────────────────────
  1102.  
  1103.  
  1104.  Action
  1105.  
  1106.  Returns the arctangent of a numeric expression.
  1107.  
  1108.  
  1109.  Syntax
  1110.  
  1111.   ATN( numeric-expression)
  1112.  
  1113.  
  1114.  Remarks
  1115.  
  1116.  The argument  numeric-expression can be of any numeric type.
  1117.  
  1118.   ATN (arctangent) is the inverse of  TAN (tangent).  ATN takes the ratio of
  1119.  two sides of a right triangle ( numeric-expression) and returns the
  1120.  corresponding angle. The ratio is the ratio of the lengths of the side
  1121.  opposite the angle and the side adjacent to the angle.
  1122.  
  1123.  The result is given in radians and is in the range π/2 to π/2 radians,
  1124.  where π = 3.141593 and π/2 radians = 90 degrees.  ATN is calculated in single
  1125.  precision if  numeric-expression is an integer or single-precision value. If
  1126.  you use any other numeric data type,  ATN is calculated in double precision.
  1127.  
  1128.  To convert values from degrees to radians, multiply the angle (in degrees)
  1129.  times π/180
  1130.  (or .0174532925199433). To convert a radian value to degrees, multiply it by
  1131.  180/π (or 57.2957795130824). In both cases, π ≈ 3.141593.
  1132.  
  1133.  
  1134.  See Also
  1135.  
  1136.   COS,  SIN,  TAN
  1137.  
  1138.  
  1139.  Example
  1140.  
  1141.  The following example first finds the tangent of PI/4 and then takes the
  1142.  arctangent of the value. The result is PI/4.
  1143.  
  1144.  CONST PI=3.141592653
  1145.  PRINT ATN(TAN(PI/4.0)), PI/4.0
  1146.  
  1147.  
  1148.  Output
  1149.  
  1150.  78539816325  .78539816325
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  BEEP Statement
  1156.  ────────────────────────────────────────────────────────────────────────────
  1157.  
  1158.  
  1159.  Action
  1160.  
  1161.  Makes a sound through the speaker.
  1162.  
  1163.  
  1164.  Syntax
  1165.  
  1166.   BEEP
  1167.  
  1168.  
  1169.  Remarks
  1170.  
  1171.  The  BEEP statement makes a sound through the loudspeaker. This statement
  1172.  makes the same sound as the following statement:
  1173.  
  1174.  PRINT CHR$(7)
  1175.  
  1176.  
  1177.  Example
  1178.  
  1179.  The following example uses  BEEP to indicate an error in the response:
  1180.  
  1181.  CLS                ' Clear the screen.
  1182.  DO
  1183.     INPUT "Hear a beep (Y or N)"; Response$
  1184.     R$ = UCASE$ (MID$ (Response$,1,1))
  1185.     IF R$ <> "Y" OR R$ = "N" THEN EXIT DO
  1186.     BEEP
  1187.  LOOP
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  BEGINTRANS Statement
  1193.  ────────────────────────────────────────────────────────────────────────────
  1194.  
  1195.  
  1196.  Action
  1197.  
  1198.  Indicates the beginning of a transaction (a series of ISAM database
  1199.  operations).
  1200.  
  1201.  
  1202.  Syntax
  1203.  
  1204.   BEGINTRANS
  1205.  
  1206.  
  1207.  Remarks
  1208.  
  1209.  Transactions are a way to group a series of ISAM operations so that you can
  1210.  commit them
  1211.  as a whole, rescind them all, or rescind operations since a designated
  1212.  savepoint. Use the  COMMITTRANS statement to commit a transaction. Use the
  1213.  SAVEPOINT function to designate a savepoint. Use the  ROLLBACK and  ROLLBACK
  1214.   ALL statements to rescind all or part of a transaction's operations.
  1215.  
  1216.  If you attempt to use  BEGINTRANS when there already is a transaction
  1217.  pending, BASIC generates the error message Illegal function call.
  1218.  
  1219.  Any ISAM operation that closes a table causes transactions to be committed.
  1220.  For example, if a type mismatch occurs while you are opening an ISAM table,
  1221.  the table is closed and a pending transaction is committed.
  1222.  
  1223.  You may wish to code your programs so they open all tables, then perform all
  1224.  transactions, then close tables. Make sure any operation that can close a
  1225.  table occurs outside a transaction.
  1226.  
  1227.  
  1228.  See Also
  1229.  
  1230.   COMMITTRANS,  ROLLBACK,  SAVEPOINT
  1231.  
  1232.  
  1233.  Example
  1234.  
  1235.  The following example uses the  DELETE statement to remove records from an
  1236.  ISAM file. It creates a transaction with the  BEGINTRANS and  COMMITTRANS
  1237.  statements, and uses  SAVEPOINT and  ROLLBACK to provide rollback of any or
  1238.  all of the deletions.
  1239.  
  1240.  The program uses the file called BOOKS.MDB, which SETUP copies to your disk.
  1241.  
  1242.  DEFINT A-Z
  1243.  TYPE Borrower
  1244.  Cardnum AS LONG             ' Card number.
  1245.  TheName AS STRING * 36      ' Name.
  1246.  Address AS STRING * 50      ' Address.
  1247.  City AS STRING * 26         ' City.
  1248.  State AS STRING * 2         ' State.
  1249.  Zip AS LONG                 ' Zip code.
  1250.  END TYPE
  1251.  
  1252.  DIM People AS Borrower          ' Record structure variable.
  1253.  CONST Database = "BOOKS.MDB"    ' Name of the disk file.
  1254.  CONST Tablename = "Cardholders" ' Name of the table.
  1255.  CONST viewbottom = 17, viewtop = 3, msgtxt = " *** Deleted: Savepoint "
  1256.  DIM SavePts(viewbottom - viewtop + 1)
  1257.  TableNum = FREEFILE
  1258.  OPEN Database FOR ISAM Borrower Tablename AS TableNum
  1259.  ' Loop until user chooses to quit.
  1260.  DO
  1261.  VIEW PRINT
  1262.  CLS : COLOR 15, 0
  1263.  PRINT SPC(34); "Card Holders"
  1264.  PRINT "Card#"; SPC(2); "Name"; SPC(13); "Address";
  1265.  PRINT SPC(20); "City"; SPC(6); "State"; SPC(2); "Zip"
  1266.  LOCATE 24, 1: PRINT "Choose a key:    ";
  1267.  PRINT "D - Delete this record    N - Next record    Q - Quit";
  1268.  MOVEFIRST TableNum
  1269.  VIEW PRINT viewtop TO viewbottom: COLOR 7, 0: CLS
  1270.  vPos = viewtop
  1271.  
  1272.  ' Loop through a screenful of records.
  1273.  DO
  1274.  ' For each record, display and ask user what to do with it.
  1275.  RETRIEVE TableNum, People
  1276.  LOCATE vPos, 1
  1277.  PRINT USING ("#####"); People.Cardnum;
  1278.  PRINT "  "; LEFT$(People.TheName, 15); "  ";
  1279.  PRINT LEFT$(People.Address, 25); "  ";
  1280.  PRINT LEFT$(People.City, 10); "  "; People.State; "   ";
  1281.  PRINT USING ("#####"); People.Zip
  1282.  
  1283.  ' Get keystroke from user.
  1284.  validkeys$ = "DNQ"
  1285.  DO
  1286.  keychoice$ = UCASE$(INKEY$)
  1287.  LOOP WHILE INSTR(validkeys$, keychoice$) = 0 OR keychoice$ = ""
  1288.  
  1289.  ' Process keystroke.
  1290.  SELECT CASE keychoice$
  1291.  CASE "D"
  1292.  IF NOT inTransaction THEN
  1293.  inTransaction = -1
  1294.  BEGINTRANS
  1295.  END IF
  1296.  NumSavePts = NumSavePts + 1
  1297.  SavePts(NumSavePts) = SAVEPOINT
  1298.  DELETE TableNum
  1299.  LOCATE vPos, 7: PRINT msgtxt; NumSavePts; SPC(79 - POS(0));
  1300.  CASE "Q"
  1301.  EXIT DO
  1302.  CASE "N"
  1303.  MOVENEXT TableNum
  1304.  END SELECT
  1305.  vPos = vPos + 1
  1306.  LOOP UNTIL EOF(TableNum) OR vPos = viewbottom
  1307.  
  1308.  ' If user didn't delete any records, simply quit.
  1309.  IF NumSavePts = 0 THEN EXIT DO
  1310.  ' Allow user to commit deletions, or roll back some or all of them.
  1311.  VIEW PRINT: LOCATE 24, 1: PRINT "Choose a key:    ";
  1312.  PRINT "R - Rollback to a savepoint   A - Rollback all deletions"
  1313.  PRINT SPC(17); "Q - commit deletions and Quit";
  1314.  validkeys$ = "RAQ"
  1315.  DO
  1316.  keychoice$ = UCASE$(INKEY$)
  1317.  LOOP WHILE INSTR(validkeys$, keychoice$) = 0 OR keychoice$ = ""
  1318.  SELECT CASE keychoice$
  1319.  CASE "R"
  1320.  VIEW PRINT 24 TO 25: PRINT : PRINT
  1321.  DO
  1322.  PRINT "Roll back to which savepoint ( 1 -"; NumSavePts; ")";
  1323.  INPUT RollbackPt
  1324.  LOOP UNTIL RollbackPt > 0 AND RollbackPt <= NumSavePts
  1325.  ROLLBACK SavePts(RollbackPt)
  1326.  NumSavePts = RollbackPt - 1
  1327.  CASE "A"
  1328.  NumSavePts = 0
  1329.  ROLLBACK ALL
  1330.  CASE "Q"
  1331.  EXIT DO
  1332.  END SELECT
  1333.  LOOP
  1334.  
  1335.  IF inTransaction THEN COMMITTRANS
  1336.  CLOSE
  1337.  END
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  BLOAD Statement
  1343.  ────────────────────────────────────────────────────────────────────────────
  1344.  
  1345.  
  1346.  Action
  1347.  
  1348.  Loads a memory-image file created by  BSAVE into memory from an input file
  1349.  or device.
  1350.  
  1351.  
  1352.  Syntax
  1353.  
  1354.   BLOAD  filespec$«,  offset%»
  1355.  
  1356.  
  1357.  Remarks
  1358.  
  1359.  The  BLOAD statement allows a program or data saved as a memory-image file
  1360.  to be loaded anywhere in memory. A memory-image file is a byte-for-byte copy
  1361.  of what was originally in memory.
  1362.  
  1363.  The  BLOAD statement uses the following arguments:
  1364.  
  1365. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  1366.  Argument                                Description
  1367.  Argument                                Description
  1368.  ────────────────────────────────────────────────────────────────────────────
  1369.   filespec$                              A string expression that specifies
  1370.                                          the file or device from which to
  1371.                                          load a memory-image file.
  1372.  
  1373.   offset%                                The offset of the address where
  1374.                                          loading is to start.
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  The starting address for loading is determined by the specified offset and
  1381.  the most recent  DEF SEG statement. If  offset% is omitted, the segment
  1382.  address and offset contained in the file (the address used in the  BSAVE
  1383.  statement) are used. Thus, the file is loaded at the address used when
  1384.  saving the file.
  1385.  
  1386.  If you supply an offset, the segment address used is the segment set by the
  1387.  most recently executed  DEF SEG statement. If there has been no  DEF SEG
  1388.  statement, the BASIC data segment (DGROUP) is used as the default.
  1389.  
  1390.  If the offset is a long integer, or a single-precision or double-precision
  1391.  number, it is converted to an integer. If the offset is a negative number
  1392.  between -1 and -32,768, inclusive, it is treated as an unsigned 2-byte
  1393.  offset.
  1394.  
  1395.  
  1396.  Note
  1397.  
  1398.  Programs written in earlier versions of BASIC no longer work if they use
  1399.  VARPTR to access numeric arrays.
  1400.  
  1401.  Because  BLOAD does not perform an address-range check, it is possible to
  1402.  load a file anywhere in memory. You must be careful not to write over BASIC
  1403.  or the operating system.
  1404.  
  1405.  Because different screen modes use memory differently, do not load graphic
  1406.  images in a screen mode other than the one used when they were created.
  1407.  
  1408.  Because BASIC program code and data items are not stored in the same
  1409.  locations as they were in BASICA, do not use  BLOAD with files created by
  1410.  BASICA programs.
  1411.  
  1412.  
  1413.  BLOAD and Expanded Memory Arrays
  1414.  
  1415.  Do not use  BLOAD to load a file into an expanded memory array. If you start
  1416.  QBX with the /Ea switch, any of these arrays may be stored in expanded
  1417.  memory:
  1418.  
  1419.    ■   Numeric arrays less than 16K in size.
  1420.  
  1421.    ■   Fixed-length string arrays less than 16K in size.
  1422.  
  1423.    ■   User-defined-type arrays less than 16K in size.
  1424.  
  1425.  
  1426.  If you want to use  BLOAD to load a file into an array, first start QBX
  1427.  without the /Ea switch.  (Without the /Ea switch, no arrays are stored in
  1428.  expanded memory.)
  1429.  
  1430.  For more information on using expanded memory, see "Memory Management for
  1431.  QBX" in  Getting Started.
  1432.  
  1433.  
  1434.  BASICA
  1435.  
  1436.   BLOAD does not support the cassette device.
  1437.  
  1438.  
  1439.  See Also
  1440.  
  1441.   BSAVE;  DEF  SEG;  SSEG;  VARPTR,  VARSEG
  1442.  
  1443.  
  1444.  Example
  1445.  
  1446.  The following example uses  BLOAD to retrieve and display a drawing of a
  1447.  magenta cube inside a box. The  BSAVE statement programming example shows
  1448.  how the drawing was created and saved on disk in a file named MAGCUBE.GRH.
  1449.  
  1450.  You must create the file MAGCUBE.GRH using the  BSAVE statement programming
  1451.  example before you can run this program.
  1452.  
  1453.  DIM Cube(1 TO 675)
  1454.  ' Set the screen mode. The mode should be the same as the
  1455.  ' mode used to create the original drawing.
  1456.  SCREEN 1
  1457.  ' Set segment to the array Cube's segment and load
  1458.  ' the graphic file into Cube.
  1459.  DEF SEG = VARSEG(Cube(1))
  1460.  BLOAD "MAGCUBE.GRH", VARPTR(Cube(1))
  1461.  DEF SEG               ' Restore default BASIC segment.
  1462.  ' Put the drawing on the screen.
  1463.  PUT (80, 10), Cube
  1464.  
  1465.  
  1466.  
  1467.  
  1468.  BOF Function
  1469.  
  1470.  
  1471.  Action
  1472.  
  1473.  Tests whether the current position is at the beginning of an ISAM table.
  1474.  
  1475.  
  1476.  Syntax
  1477.  
  1478.   BOF( filenumber%)
  1479.  
  1480.  
  1481.  Remarks
  1482.  
  1483.   BOF returns true (nonzero) if the current position is at the beginning of
  1484.  the table. The beginning of an ISAM table is the position before the first
  1485.  record according to the current index. The argument  filenumber% is the
  1486.  number used in the  OPEN statement to open the table.
  1487.  
  1488.  
  1489.  See Also
  1490.  
  1491.   EOF,  LOC,  LOF,  OPEN
  1492.  
  1493.  
  1494.  Example
  1495.  
  1496.  See the  CREATEINDEX statement programming example, which uses the  BOF
  1497.  function.
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  BSAVE Statement
  1503.  ────────────────────────────────────────────────────────────────────────────
  1504.  
  1505.  
  1506.  Action
  1507.  
  1508.  Transfers the contents of an area of memory to an output file or device.
  1509.  
  1510.  
  1511.  Syntax
  1512.  
  1513.   BSAVE  filespec$,  offset%,  length%
  1514.  
  1515.  
  1516.  Remarks
  1517.  
  1518.  The  BSAVE statement uses the following arguments:
  1519.  
  1520. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  1521.  Argument                                Description
  1522.  ────────────────────────────────────────────────────────────────────────────
  1523.   filespec$                              A string expression that specifies
  1524.                                          the name of the file or device on
  1525.                                          which to save a memory-image file.
  1526.  
  1527.   offset%                                The offset of the starting address
  1528.                                          of the area in memory to be saved.
  1529.  
  1530.   length%                                The number of bytes to save. This
  1531.                                          is a numeric expression that
  1532.                                          returns an unsigned integer
  1533.                                          between 0 and 65,535, inclusive.-
  1534.  
  1535.  Argument                                Description
  1536.  ────────────────────────────────────────────────────────────────────────────
  1537. 
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  The  BSAVE statement allows data or programs to be saved as memory-image
  1543.  files on disk. A memory-image file is a byte-for-byte copy of what is in
  1544.  memory along with control information used by  BLOAD to load the file.
  1545.  
  1546.  The starting address of the area saved is determined by the offset and the
  1547.  most recent  DEF SEG statement.
  1548.  
  1549.  
  1550.  Note
  1551.  
  1552.  Programs written in earlier versions of BASIC no longer work if they use
  1553.  VARPTR to access numeric arrays.
  1554.  
  1555.  Because different screen modes use memory differently, do not load graphic
  1556.  images in a screen mode other than the one used when they were created.
  1557.  
  1558.  
  1559.  
  1560.  If no  DEF SEG statement is executed before the  BSAVE statement, the
  1561.  program uses the default BASIC data segment (DGROUP). Otherwise,  BSAVE
  1562.  begins saving at the address specified by the offset and by the segment set
  1563.  in the most recent  DEF SEG statement.
  1564.  
  1565.  If the offset is a long integer, or single- or double-precision
  1566.  floating-point value, it is converted to an integer. If the offset is a
  1567.  negative number between -1 and -32,768, inclusive, it is treated
  1568.  as an unsigned 2-byte offset.
  1569.  
  1570.  
  1571.  BSAVE and Expanded Memory Arrays
  1572.  
  1573.  Do not use  BSAVE to transfer an expanded memory array to an output file.
  1574.  (If you start QBX with the /Ea switch, any of these arrays may be stored in
  1575.  expanded memory:
  1576.  
  1577.    ■   Numeric arrays less than 16K in size.
  1578.  
  1579.    ■   Fixed-length string arrays less than 16K in size.
  1580.  
  1581.    ■   User-defined-type arrays less than 16K in size.
  1582.  
  1583.  
  1584.  If you want to use  BSAVE to transfer an array to an output file, first
  1585.  start QBX without the /Ea switch. (Without the /Ea switch, no arrays are
  1586.  stored in expanded memory.)
  1587.  
  1588.  For more information on using expanded memory, see "Memory Management for
  1589.  QBX" in  Getting Started.
  1590.  
  1591.  
  1592.  BASICA
  1593.  
  1594.   BSAVE does not support the cassette device.
  1595.  
  1596.  
  1597.  See Also
  1598.  
  1599.   BLOAD,  DEF SEG
  1600.  
  1601.  
  1602.  Example
  1603.  
  1604.  The following example draws a magenta cube inside a white box and then uses
  1605.  BSAVE to store the drawing in the file MAGCUBE.GRH. The  BLOAD statement
  1606.  programming example shows how you can retrieve and display the drawing after
  1607.  you create it.
  1608.  
  1609.  DIM Cube(1 TO 675)
  1610.  SCREEN 1
  1611.  ' Draw a white box.
  1612.  LINE (140, 25)-(140 + 100, 125), 3, B
  1613.  ' Draw the outline of a magenta cube inside the box.
  1614.  DRAW "C2 BM140,50 M+50,-25 M+50,25 M-50,25"
  1615.  DRAW "M-50,-25 M+0,50 M+50,25 M+50,-25 M+0,-50 BM190,75 M+0,50"
  1616.  ' Save the drawing in the array Cube.
  1617.  GET (140, 25)-(240, 125), Cube
  1618.  ' Set segment to the array Cube's segment and store the drawing
  1619.  ' in the file MAGCUBE.GRH. Note: 2700 is the number of bytes
  1620.  ' in Cube (4 bytes per array element * 675).
  1621.  DEF SEG = VARSEG(Cube(1))
  1622.  BSAVE "MAGCUBE.GRH", VARPTR(Cube(1)), 2700
  1623.  DEF SEG                 ' Restore default BASIC segment.
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  CALL Statement (BASIC Procedures)
  1630.  ────────────────────────────────────────────────────────────────────────────
  1631.  
  1632.  
  1633.  Action
  1634.  
  1635.  Transfers control to a BASIC  SUB procedure. To invoke a non-BASIC
  1636.  procedure, use the  CALL, CALLS statements (non-BASIC).
  1637.  
  1638.  
  1639.  Syntax 1
  1640.  
  1641.   CALL  name «( argumentlist)»
  1642.  
  1643.  
  1644.  Syntax 2
  1645.  
  1646.   name «( argumentlist)»
  1647.  
  1648.  
  1649.  Remarks
  1650.  
  1651.  The  CALL statement uses the following arguments:
  1652.  
  1653. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  1654.  Argument                                Description
  1655.  ────────────────────────────────────────────────────────────────────────────
  1656.   name                                   The name, limited to no more than
  1657.                                          40 characters, of the BASIC  SUB
  1658.                                          procedure being called.
  1659.  
  1660.   argumentlist                           The variables or constants passed
  1661.  Argument                                Description
  1662.  ────────────────────────────────────────────────────────────────────────────
  1663.  argumentlist                           The variables or constants passed
  1664.                                          to the procedure. Arguments in the
  1665.                                          list are separated by commas.
  1666.                                          Arguments are passed by reference
  1667.                                          (which means they can be changed
  1668.                                          by the procedure).
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  If  argumentlist includes an array argument, the array is specified by the
  1675.  array name followed by empty parentheses:
  1676.  
  1677.  DIM IntArray(1 TO 20)
  1678.  .
  1679.  .
  1680.  .
  1681.  CALL ShellSort(IntArray())
  1682.  
  1683.  If you omit the optional  CALL keyword, you must declare the procedure in a
  1684.  DECLARE statement and omit the parentheses around  argumentlist. For more
  1685.  information, see Chapter 2,  "SUB and FUNCTION Procedures" in the
  1686.  Programmer's Guide.
  1687.  
  1688.  The  CALL statement passes arguments only by reference, which means that the
  1689.  procedure is given the address of the argument. This allows procedures to
  1690.  change the argument values.
  1691.  
  1692.  Although the  CALL statement does not pass arguments by value, you can
  1693.  simulate that by enclosing the argument in parentheses. This makes the
  1694.  argument an expression. (If an argument is passed by value, the procedure is
  1695.  given the value of the argument.)
  1696.  
  1697.  For example, the following statement calls a procedure and passes a single
  1698.  argument:
  1699.  
  1700.  CALL SolvePuzzle((StartValue))
  1701.  
  1702.  Because StartValue is in parentheses, BASIC evaluates it as an expression.
  1703.  The result is stored in a temporary location, and the address of the
  1704.  temporary location is passed to the  SUB procedure. Any change made by the
  1705.  procedure SolvePuzzle is made to the temporary location only, and not to
  1706.  StartValue itself.
  1707.  
  1708.  
  1709.  See Also
  1710.  
  1711.   Absolute Routine;  CALL,  CALLS (Non-BASIC);  DECLARE (BASIC)
  1712.  
  1713.  
  1714.  Example
  1715.  
  1716.  The following example uses the  CALL statement to call a  SUB procedure that
  1717.  prints a message on the 25th line of the display:
  1718.  
  1719.  CLS' Clear screen.
  1720.  message$ = "The quick brown fox jumped over the lazy yellow dog."
  1721.  CALL PrintMessage(message$)
  1722.  END
  1723.  
  1724.  SUB PrintMessage (message$)
  1725.      LOCATE 24, 1 ' Move cursor to 25th line of display.
  1726.      PRINT message$;
  1727.  END SUB
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  CALL, CALLS Statements (Non-BASIC Procedures)
  1733.  ────────────────────────────────────────────────────────────────────────────
  1734.  
  1735.  
  1736.  Action
  1737.  
  1738.  Transfer control to a procedure written in another language. To invoke a
  1739.  BASIC procedure, use the  CALL statement (BASIC).
  1740.  
  1741.  
  1742.  Syntax 1
  1743.  
  1744.   CALL  name «( call-argumentlist)»
  1745.  
  1746.  
  1747.  Syntax 2
  1748.  
  1749.   name « call-argumentlist»
  1750.  
  1751.  
  1752.  Syntax 3
  1753.  
  1754.   CALLS  name «( calls-argumentlist)»
  1755.  
  1756.  
  1757.  Remarks
  1758.  
  1759.  The  CALL keyword is optional when you use the  CALL statement. When you
  1760.  omit  CALL, you must declare the procedure in a  DECLARE statement. When you
  1761.  omit  CALL, you omit the parentheses around the argument list. For more
  1762.  information about invoking procedures without the  CALL keyword, see Chapter
  1763.  2, "SUB and FUNCTION Procedures" in the  Programmer's Guide.
  1764.  
  1765.   CALLS is the same as using  CALL with a  SEG before each argument: every
  1766.  argument in a  CALLS statement is passed as a segmented address.
  1767.  
  1768.  The  CALL and  CALLS statements use the following arguments:
  1769.  
  1770. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  1771.  Argument                                Description
  1772.  ────────────────────────────────────────────────────────────────────────────
  1773.   name                                   The name of the non-BASIC
  1774.                                          procedure being called.
  1775.  
  1776.   call-argumentlist                      The variables, arrays, or
  1777.                                          expressions passed to the
  1778.                                          procedure.
  1779.  
  1780.   calls-argumentlist                     The variables or expressions
  1781.                                          CALLS passes to the procedure.
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  The  call-argumentlist has two forms of syntax. In the first form,  argument
  1788.  is a variable:
  1789.  
  1790.  ««{BYVAL|SEG}»argument» «,«{BYVAL|SEG}»argument»...
  1791.  
  1792.  If  argument is an array, parentheses are required:
  1793.  
  1794.  «argument«( )»» «,  argument «( )»»...
  1795.  
  1796.  The following list describes the parts of  call-argumentlist:
  1797.  
  1798. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  1799.  Part                                    Description
  1800.  ────────────────────────────────────────────────────────────────────────────
  1801.   BYVAL                                  Indicates the argument is passed
  1802.                                          by value rather than by near
  1803.                                          reference (the default is by
  1804.                                          reference).  BYVAL cannot be used
  1805.                                          if the argument is an array.
  1806.  
  1807.   SEG                                    Passes the argument as a segmented
  1808.  Part                                    Description
  1809.  ────────────────────────────────────────────────────────────────────────────
  1810.  SEG                                    Passes the argument as a segmented
  1811.                                          (far) address.  SEG cannot be used
  1812.                                          if the argument is an array.
  1813.  
  1814.   argument                               A BASIC variable, array, or
  1815.                                          expression passed to a procedure.
  1816.  
  1817.  
  1818.  
  1819.  
  1820.  
  1821.  Use the first syntax if
  1822.   argument is not an array; use the second if  argument is an array. The
  1823.  array is specified by the array name and a pair of parentheses. For example:
  1824.  
  1825.  
  1826.  DIM IntArray(20) AS INTEGER
  1827.  .
  1828.  .
  1829.  .
  1830.  CALL ShellSort(IntArray) AS INTEGER
  1831.  
  1832.  The argument  calls-argumentlist has the following syntax, where  argument
  1833.  is a BASIC variable or expression:
  1834.  
  1835.  « argument» «,  argument»...
  1836.  
  1837.  These arguments are passed by reference as far addresses, using the segment
  1838.  and offset of the variable. Whole array arguments cannot be passed by calls.
  1839.  
  1840.  The result of the  BYVAL keyword differs from BASIC's pass by value:
  1841.  
  1842.  CALL Difference (BYVAL A,(B))
  1843.  
  1844.  For the first argument, only the  value of A is passed to Difference. In
  1845.  contrast, (B) is evaluated, a temporary location is created for the value,
  1846.  and the address of the temporary location is passed to Difference.
  1847.  
  1848.  You can use BASIC's pass by value for an argument, but the procedure in the
  1849.  other language must accept an address (because the address of the temporary
  1850.  location is passed).
  1851.  
  1852.  
  1853.  Note
  1854.  
  1855.  If the argument  name refers to an assembly-language procedure, it must be a
  1856.  name declared with  PUBLIC (symbol).
  1857.  
  1858.  
  1859.  Be careful using the  SEG keyword to pass elements of arrays because BASIC
  1860.  may move arrays in memory before the called routine begins execution.
  1861.  Anything in an argument list that causes memory movement may create
  1862.  problems. You can safely pass variables using  SEG if the  CALL statement's
  1863.  argument list contains only simple variables, arithmetic expressions, or
  1864.  arrays indexed without the use of intrinsic or defined functions.
  1865.  
  1866.  
  1867.  See Also
  1868.  
  1869.   CALL (BASIC);  DECLARE (BASIC);  DECLARE (Non-BASIC)
  1870.  
  1871.  
  1872.  Example
  1873.  
  1874.  See the  VARPTR function programming example, which uses a  CALL statement
  1875.  to invoke a C function.
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  CCUR Function
  1881.  ────────────────────────────────────────────────────────────────────────────
  1882.  
  1883.  
  1884.  Action
  1885.  
  1886.  Converts a numeric expression to a currency value.
  1887.  
  1888.  
  1889.  Syntax
  1890.  
  1891.   CCUR( numeric-expression)
  1892.  
  1893.  
  1894.  Remarks
  1895.  
  1896.  The argument  numeric-expression can be any numeric expression.
  1897.  
  1898.  
  1899.  See Also
  1900.  
  1901.   CDBL,  CINT,  CLNG,  CSNG
  1902.  
  1903.  
  1904.  Example
  1905.  
  1906.  The following example passes a double-precision, floating-point value to a
  1907.  FUNCTION procedure that returns the sales tax, as a currency value, for the
  1908.  passed value. The returned value has four digits of precision, but it is
  1909.  displayed in conventional currency value format with two places to the right
  1910.  of the decimal.  CCUR is used to convert from double-precision to currency
  1911.  data type.
  1912.  
  1913.  DECLARE FUNCTION GetSalesTax@ (Amount#, percent!)
  1914.  ' $INCLUDE: 'FORMAT.BI'
  1915.  CONST percent! = 8.1
  1916.  CLS    ' Clear screen.
  1917.  INPUT "What is the taxable currency amount"; Amount#
  1918.  PRINT
  1919.  USCurFmt$ = FormatC$(GetSalesTax@(Amount#, percent!), "$#,###,###,##0.00")
  1920.  SetFormatCC (49)    ' West Germany
  1921.  WGCurFmt$ = FormatC$(GetSalesTax@(Amount#, percent!), "#.###.###.##0,00")
  1922.  WGCurFmt$ = WGCurFmt$ + " DM"
  1923.  
  1924.  PRINT "In the United States, currency is displayed with commas as"
  1925.  PRINT "numerical separators and a period serves to separate whole from"
  1926.  PRINT "fractional currency amounts. In some European countries, the"
  1927.  PRINT "numerical separator is a period, and the comma serves to separate"
  1928.  PRINT "whole from fractional currency amounts."
  1929.  PRINT
  1930.  PRINT "In the US, the tax on $"; Amount#; "at"; percent!; "percent is "
  1931.  PRINT "displayed as "; USCurFmt$
  1932.  PRINT
  1933.  PRINT "In West Germany, the tax on"; Amount#; "DM at"; percent!; "percent"
  1934.  PRINT "is displayed as "; WGCurFmt$
  1935.  END
  1936.  
  1937.  FUNCTION GetSalesTax@ (Amount#, percent!)
  1938.      GetSalesTax@ = CCUR(Amount# * (percent! * .01))
  1939.  END FUNCTION
  1940.  
  1941.  
  1942.  
  1943.  
  1944.  CDBL Function
  1945.  ────────────────────────────────────────────────────────────────────────────
  1946.  
  1947.  
  1948.  Action
  1949.  
  1950.  Converts a numeric expression to a double-precision value.
  1951.  
  1952.  
  1953.  Syntax
  1954.  
  1955.   CDBL( numeric-expression)
  1956.  
  1957.  
  1958.  Remarks
  1959.  
  1960.  The argument  numeric-expression can be any numeric expression. This
  1961.  function has the same effect as assigning the numeric expression to a
  1962.  double-precision variable.
  1963.  
  1964.  The results of  CDBL are no more accurate than the original expression. The
  1965.  added digits of precision are not significant unless the expression is
  1966.  calculated with double-precision accuracy.
  1967.  
  1968.  
  1969.  See Also
  1970.  
  1971.   CCUR,  CINT,  CLNG,  CSNG
  1972.  
  1973.  
  1974.  Example
  1975.  
  1976.  The following example demonstrates how the precision of the argument affects
  1977.  the value returned by  CDBL:
  1978.  
  1979.  X = 7/9
  1980.  X# = 7/9
  1981.  PRINT X
  1982.  ' Both X# and CDBL(X) will be accurate to only 7 decimal
  1983.  ' places, because 7/9 is evaluated in single precision.
  1984.  PRINT X#
  1985.  PRINT CDBL(X)
  1986.  PRINT 7#/9#' Accurate to 15 decimal places.
  1987.  
  1988.  
  1989.  Output
  1990.  
  1991.  .7777778
  1992.  .7777777910232544
  1993.  .7777777910232544
  1994.  .7777777777777778
  1995.  
  1996.  
  1997.  
  1998.  
  1999.  CHAIN Statement
  2000.  ────────────────────────────────────────────────────────────────────────────
  2001.  
  2002.  
  2003.  Action
  2004.  
  2005.  Transfers control from the current program to another program.
  2006.  
  2007.  
  2008.  Syntax
  2009.  
  2010.   CHAIN  filespec$
  2011.  
  2012.  
  2013.  Remarks
  2014.  
  2015.  The argument  filespec$ is a string expression that represents the program
  2016.  to which control is passed. It may include a path. (With DOS 2.1 or earlier
  2017.  versions, you cannot use  CHAIN unless  filespec$ provides a complete path,
  2018.  including drive. Also under DOS 2.1, if the run-time module is in the root
  2019.  directory, the root directory must be listed in the PATH environment
  2020.  variable.) Programs running within the QBX environment assume a .BAS
  2021.  extension (if no extension is given) and cannot chain to executable files
  2022.  (files with a .COM or .EXE extension). Programs running outside the BASIC
  2023.  environment assume a .EXE extension and cannot chain to BASIC source files
  2024.  (files with a .BAS extension).
  2025.  
  2026.  You can pass variables between programs using the  COMMON statement to set
  2027.  up a blank common block. For more information on passing variables, see the
  2028.  entry for the  COMMON statement.
  2029.  
  2030.  When you compile a program outside the QBX environment, the BCL70efr.LIB
  2031.  object-module library does not support  COMMON. There are two ways to use
  2032.  COMMON with chained programs outside the environment:
  2033.  
  2034.    ■   Use the default (BRT70EFR.EXE for DOS and OS/2 real mode; BRT70EFR.DLL
  2035.        for OS/2 protected mode) by compiling the programs using the option in
  2036.        the Make EXE dialog box called "EXE Requiring BRT Module."
  2037.  
  2038.    ■   Use BRT70EFR.LIB by compiling from the command line without the /O
  2039.        option. For more information, see Appendix C, "Command-Line Tools
  2040.        Quick Reference."
  2041.  
  2042.  
  2043.  Note
  2044.  
  2045.  When programs use BRT70EFR.EXE or BRT70EFR.DLL, files are left open during
  2046.  chaining unless they are explicitly closed with a  CLOSE statement. The
  2047.  filenames BCL70efr.LIB, BRT70EFR.EXE, and BRT70EFR.DLL assume that you
  2048.  selected these compiler options when you installed BASIC: emulator
  2049.  floating-point math, far strings, and real mode. If you used different
  2050.  options, see Chapter 17, "About Linking and Libraries" in the  Programmer's
  2051.  Guide for information about other compiler options.
  2052.  
  2053.  
  2054.   CHAIN is similar to  RUN. The main differences are that  RUN closes all
  2055.  open files and does not support data blocks declared with  COMMON.
  2056.  
  2057.  
  2058.  BASICA
  2059.  
  2060.  BASICA assumes the extension .BAS. The current version of BASIC assumes an
  2061.  extension of either .BAS or .EXE, depending on whether the program is run
  2062.  within the QBX environment or compiled and run outside the environment. If
  2063.  you omit the file extension,  CHAIN works the same in BASICA and in the
  2064.  current version of BASIC.
  2065.  
  2066.  The current version of BASIC does not support the all, merge, or delete
  2067.  option available in BASICA, nor does it allow you to specify a line number.
  2068.  
  2069.  Without the line-number option, execution always starts at the beginning of
  2070.  the chained-to program. Thus, a chained-to program that chains back to a
  2071.  carelessly written chaining program can cause an endless loop.
  2072.  
  2073.  
  2074.  See Also
  2075.  
  2076.   CALL (BASIC), Common,  RUN
  2077.  
  2078.  
  2079.  Example
  2080.  
  2081.  In the following example, the  COMMON statement is used to pass variables
  2082.  between two chained programs. The first program reads in a series of numeric
  2083.  values, stores the values in an array, then uses the  CHAIN statement to
  2084.  load and run the other program. The second program finds and prints the
  2085.  average of the values. The first two statements initialize the variables
  2086.  that are passed to PROG2.
  2087.  
  2088.  DIM values(1 TO 50)
  2089.  COMMON values(), NumValues%
  2090.  
  2091.  ' PROG2 creation section.
  2092.  ' The following few lines of code create the second program on the
  2093.  ' disk so that it can load and run with the CHAIN statement. It uses
  2094.  ' PRINT # statements to put the proper BASIC statements in a file.
  2095.  OPEN "PROG2.BAS" FOR OUTPUT AS #1
  2096.  PRINT #1, "' PROG2 for the CHAIN and COMMON statements example."
  2097.  PRINT #1, "DIM X(1 TO 50)"
  2098.  PRINT #1, "COMMON X(), N%"
  2099.  PRINT #1, "PRINT"
  2100.  PRINT #1, "IF N% > 0 THEN"
  2101.  PRINT #1, "   Sum% = 0"
  2102.  PRINT #1, "   FOR I% = 1 TO N%"
  2103.  PRINT #1, "      Sum% = Sum% + X(I%)"
  2104.  PRINT #1, "   NEXT I%"
  2105.  PRINT #1, "   PRINT "; CHR$(34); "The average of the values is";
  2106.  PRINT #1, CHR$(34); "; Sum% / N%"
  2107.  PRINT #1, "END IF"
  2108.  PRINT #1, "END"
  2109.  CLOSE #1
  2110.  ' End of PROG2 creation section.
  2111.  
  2112.  CLS
  2113.  PRINT "Enter values one per line. Type 'END' to quit."
  2114.  NumValues% = 0
  2115.  DO
  2116.     INPUT "-> ", N$
  2117.     IF I% >= 50 OR UCASE$(N$) = "END" THEN EXIT DO
  2118.     NumValues% = NumValues% + 1
  2119.     values(NumValues%) = VAL(N$)
  2120.  LOOP
  2121.  PRINT "Press any key to continue... "
  2122.  DO WHILE INKEY$ = ""
  2123.  LOOP
  2124.  CHAIN "PROG2.BAS"
  2125.  END
  2126.  
  2127.  
  2128.  
  2129.  
  2130.  CHDIR Statement
  2131.  ────────────────────────────────────────────────────────────────────────────
  2132.  
  2133.  
  2134.  Action
  2135.  
  2136.  Changes the current default directory for the specified drive.
  2137.  
  2138.  
  2139.  Syntax
  2140.  
  2141.   CHDIR  pathname$
  2142.  
  2143.  
  2144.  Remarks
  2145.  
  2146.  The argument  pathname$ is a string expression identifying the directory
  2147.  that is to become the default directory. The  pathname$  expression must
  2148.  have fewer than 64 characters. It has the following syntax:
  2149.  
  2150.  «drive:»«\»directory«\ directory»...
  2151.  
  2152.  The argument  drive is an optional drive specification. If you omit  drive,
  2153.  CHDIR changes the default directory on the current drive.
  2154.  
  2155.   CHDIR cannot be shortened to CD.
  2156.  
  2157.  The  CHDIR statement changes the default directory but not the default
  2158.  drive. For example, if the default drive is C, the following statement
  2159.  changes the default directory on drive D, but C remains the default drive:
  2160.  
  2161.  CHDIR "D:\TMP"
  2162.  
  2163.  Use  CURDIR$ to return the current directory and  CHDRIVE to change the
  2164.  default drive.
  2165.  
  2166.  
  2167.  See Also
  2168.  
  2169.   MKDIR,  RMDIR
  2170.  
  2171.  
  2172.  Example
  2173.  
  2174.  This example uses the MKDIR statement to create a subdirectory. The AddADir
  2175.  procedure uses the CHDIR statement with the ON ERROR statement to check if
  2176.  the subdirectory already exists. If it does not exist, the error-handling
  2177.  routine traps error 76, prompts the user, and creates the directory.
  2178.  
  2179.  DECLARE SUB AddADir (DstDir$)
  2180.  
  2181.  CLS
  2182.  AddADir "TESTDIR"
  2183.  
  2184.  SUB AddADir (DestDir$)
  2185.  ON LOCAL ERROR GOTO ErrHandler'Set up the local error handler.
  2186.  CurDirName$ = CURDIR$'Preserve the name of the current directory.
  2187.  CHDIR$ DestDir$'Change to DestDir$ - Error 76 if not exist.
  2188.  CHDIR$ CurDirName$'Change back to original directory.
  2189.  EXIT SUB
  2190.  
  2191.  ErrHandler:
  2192.  IF ERR = 76 THEN
  2193.  PRINT "Directory does not exist. Create ?";
  2194.  Ans$ = INPUT(1)
  2195.  PRINT Ans$
  2196.  IF UCASE$(Ans$) = "Y" THEN
  2197.  MKDIR DestDir$'Make the directory.
  2198.  PRINT DestDir$; "directory created."
  2199.  RESUME NEXT
  2200.  ELSE
  2201.  PRINT DestDir$; "directory not created."
  2202.  END IF'Return control to caller.
  2203.  END IF
  2204.  RESUME NEXT'Just continue.
  2205.  END SUB
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  CHDRIVE Statement
  2211.  ────────────────────────────────────────────────────────────────────────────
  2212.  
  2213.  
  2214.  Action
  2215.  
  2216.  Changes the current drive.
  2217.  
  2218.  
  2219.  Syntax
  2220.  
  2221.   CHDRIVE  drive$
  2222.  
  2223.  
  2224.  Remarks
  2225.  
  2226.  The argument  drive$ is a string expression that specifies a new default
  2227.  drive. It must correspond to an existing drive and must be in the range A to
  2228.   lastdrive, where  lastdrive is the maximum drive letter you set in your
  2229.  CONFIG.SYS file.
  2230.  
  2231.  If you supply a null argument ("") for  drive$, the current drive does not
  2232.  change. If the argument  drive$ is a string,  CHDRIVE uses only the first
  2233.  letter. If you omit  drive$, BASIC generates the error message Expected:
  2234.  Expression (in QBX) or String expression required (outside of QBX).
  2235.  
  2236.   CHDRIVE is not case sensitive. "C" is the same as "c."
  2237.  
  2238.  
  2239.  See Also
  2240.  
  2241.   CHDIR,  CURDIR$
  2242.  
  2243.  
  2244.  Example
  2245.  
  2246.  The following example demonstrates use of the  CHDRIVE statements. It calls
  2247.  a  SUB procedure that evaluates a file specification and changes the
  2248.  currently logged drive if necessary.
  2249.  
  2250.  DECLARE SUB ChangeDataDrive (filespec$)
  2251.  ON ERROR RESUME NEXT
  2252.  filespec$ = "A:"
  2253.  ChangeDataDrive filespec$
  2254.  filespec$ = "C:\DOS"
  2255.  ChangeDataDrive filespec$
  2256.  SUB ChangeDataDrive (filespec$)
  2257.      curdrive$ = LEFT$(CURDIR$, 2)        ' Get the current drive.
  2258.      ' Determine if there is a drive name on the filespec.
  2259.      IF INSTR(1, filespec$, ":") = 2 THEN
  2260.          newdrive$ = LEFT$(filespec$, 2)
  2261.      ELSE
  2262.          newdrive$ = curdrive$
  2263.      END IF
  2264.      ' Ensure that the new drive is different from the
  2265.      ' currently logged drive.
  2266.      IF newdrive$ <> curdrive$ THEN
  2267.          CHDRIVE newdrive$           ' It isn't, so change it.
  2268.          PRINT "Logged drive changed from "; curdrive$; " to "; newdrive$
  2269.      ELSE                            ' It is, so don't change it.
  2270.          PRINT "New drive same as logged drive. No change occurred."
  2271.      END IF
  2272.  END SUB
  2273.  
  2274.  
  2275.  
  2276.  
  2277.  CHECKPOINT Statement
  2278.  ────────────────────────────────────────────────────────────────────────────
  2279.  
  2280.  
  2281.  Action
  2282.  
  2283.  Writes all open ISAM database buffers to disk in their current state.
  2284.  
  2285.  
  2286.  Syntax
  2287.  
  2288.   CHECKPOINT
  2289.  
  2290.  
  2291.  See Also
  2292.  
  2293.   ROLLBACK,  SAVEPOINT
  2294.  
  2295.  
  2296.  Example
  2297.  
  2298.  See the programming example for the  SEEKGT,  SEEKGE,  SEEKEQ statements,
  2299.  which uses the  CHECKPOINT statement.
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  CHR$ Function
  2305.  ────────────────────────────────────────────────────────────────────────────
  2306.  
  2307.  
  2308.  Action
  2309.  
  2310.  Returns a one-character string whose ASCII code is the argument.
  2311.  
  2312.  
  2313.  Syntax
  2314.  
  2315.   CHR$( code%)
  2316.  
  2317.  
  2318.  Remarks
  2319.  
  2320.   CHR$ is commonly used to send a special character to the screen or printer.
  2321.  For example, you can send a form feed (CHR$(12)) to clear the screen and
  2322.  return the cursor to the home position.
  2323.  
  2324.   CHR$ also can be used to include a double quotation mark (") in a string.
  2325.  The following line adds a double-quotation-mark character to the beginning
  2326.  and the end of the string:
  2327.  
  2328.  Msg$=CHR$(34)+"Quoted string"+CHR$(34)
  2329.  
  2330.  
  2331.  See Also
  2332.  
  2333.   ASC; Appendix A, "Keyboard Scan Codes and ASCII Character Codes"
  2334.  
  2335.  
  2336.  Example
  2337.  
  2338.  The following example uses  CHR$ to display graphics characters in the
  2339.  extended character set and uses these characters to draw boxes on the
  2340.  screen:
  2341.  
  2342.  DEFINT A-Z
  2343.  ' Display two double-sided boxes.
  2344.  CALL DBox(5,22,18,40)
  2345.  CALL DBox(1,4,4,50)
  2346.  END
  2347.  
  2348.  ' SUB procedure to display boxes.
  2349.  ' Parameters:
  2350.  '  Urow%, Ucol%: Row and column of upper-left corner.
  2351.  '  Lrow%, Lcol%: Row and column of lower-right corner.
  2352.  CONST VERT=186, HORZ=205     ' Extended ASCII graphics characters.
  2353.  CONST ULEFTC=201, URIGHTC=187, LLEFTC=200, LRIGHTC=188
  2354.  SUB DBox (Urow%, Ucol%, Lrow%, Lcol%) STATIC
  2355.     LOCATE Urow%, Ucol% : PRINT CHR$(ULEFTC);' Draw top of box.
  2356.     LOCATE ,Ucol%+1 : PRINT STRING$(Lcol%-Ucol%,CHR$(HORZ));
  2357.     LOCATE ,Lcol% : PRINT CHR$(URIGHTC);
  2358.     FOR I=Urow%+1 TO Lrow%-1' Draw body of box.
  2359.        LOCATE I,Ucol% : PRINT CHR$(VERT);
  2360.        LOCATE  ,Lcol% : PRINT CHR$(VERT);
  2361.     NEXT I
  2362.     LOCATE Lrow%, Ucol% : PRINT CHR$(LLEFTC);' Draw bottom of box.
  2363.     LOCATE ,Ucol%+1 : PRINT STRING$(Lcol%-Ucol%,CHR$(HORZ));
  2364.     LOCATE ,Lcol% : PRINT CHR$(LRIGHTC);
  2365.  END SUB
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  CINT Function
  2371.  ────────────────────────────────────────────────────────────────────────────
  2372.  
  2373.  
  2374.  Action
  2375.  
  2376.  Converts a numeric expression to an integer by rounding the fractional part
  2377.  of the expression.
  2378.  
  2379.  
  2380.  Syntax
  2381.  
  2382.   CINT( numeric-expression)
  2383.  
  2384.  
  2385.  Remarks
  2386.  
  2387.  If  numeric-expression is not between -32,768 and 32,767, inclusive,
  2388.  BASIC generates the run-time error message Overflow.
  2389.  
  2390.   CINT differs from the  FIX and  INT functions, which truncate, rather than
  2391.  round, the fractional part. See the example for the  INT function for an
  2392.  illustration of the differences among these functions.
  2393.  
  2394.  
  2395.  See Also
  2396.  
  2397.   CCUR,  CDBL,  CLNG,  CSNG,  FIX,  INT
  2398.  
  2399.  
  2400.  Example
  2401.  
  2402.  The following example converts an angle in radians to an angle in degrees
  2403.  and minutes:
  2404.  
  2405.  ' Set up constants for converting radians to degrees.
  2406.  CONST PI=3.141593, RADTODEG=180./PI
  2407.  INPUT "Angle in radians = ",Angle' Get the angle in radians.
  2408.  Angle = Angle * RADTODEG' Convert radian input to degrees.
  2409.  Min = Angle - INT(Angle)' Get the fractional part.
  2410.  ' Convert fraction to value between 0 and 60.
  2411.  Min = CINT(Min * 60)
  2412.  Angle = INT(Angle)' Get whole number part.
  2413.  IF Min = 60 THEN' 60 minutes = 1 degree.
  2414.     Angle = Angle + 1
  2415.     Min = 0
  2416.  END IF
  2417.  PRINT "Angle equals"; Angle; "degrees"; Min; "minutes"
  2418.  
  2419.  
  2420.  Output
  2421.  
  2422.  Angle in radians = 1.5708
  2423.  Angle equals 90 degrees 0 minutes
  2424.  
  2425.  
  2426.  
  2427.  
  2428.  CIRCLE Statement
  2429.  ────────────────────────────────────────────────────────────────────────────
  2430.  
  2431.  
  2432.  Action
  2433.  
  2434.  Draws an ellipse or circle with a specified center and radius.
  2435.  
  2436.  
  2437.  Syntax
  2438.  
  2439.   CIRCLE «STEP» (x!,y!), radius!«, «color&» «, «start!» «, «end!» «, aspect!»»
  2440.  
  2441.  Remarks
  2442.  
  2443.  The following list describes the parts of the  CIRCLE statement:
  2444.  
  2445. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  2446.  Part                                    Description
  2447.  ────────────────────────────────────────────────────────────────────────────
  2448.   STEP                                   The  STEP option specifies that
  2449.                                          x! and  y! are offsets relative to
  2450.                                          current graphics cursor position,
  2451.                                          enabling use of relative
  2452.                                          coordinates.
  2453.  
  2454.   x!, y!                                 The screen coordinates for the
  2455.                                          center of the circle or ellipse.
  2456.  
  2457.   radius!                                The radius of the circle or
  2458.                                          ellipse in the units of the
  2459.  Part                                    Description
  2460.  ────────────────────────────────────────────────────────────────────────────
  2461.                                         ellipse in the units of the
  2462.                                          current coordinate system, which
  2463.                                          is determined by the most recently
  2464.                                          executed  SCREEN statement, along
  2465.                                          with any  VIEW or  WINDOW
  2466.                                          statements.
  2467.  
  2468.   color&                                 The attribute of the desired color.
  2469.                                          See the entries for the  COLOR and
  2470.                                           SCREEN statements for more
  2471.                                          information. The default color is
  2472.                                          the foreground color.
  2473.  
  2474.   start!,  end!                          The  start! and  end! angles, in
  2475.                                          radians, for the arc to draw. The
  2476.                                          start! and  end! arguments are
  2477.                                          used to draw partial circles or
  2478.                                          ellipses. The arguments may range
  2479.                                          in value from -2π radians to 2π
  2480.  Part                                    Description
  2481.  ────────────────────────────────────────────────────────────────────────────
  2482.                                         in value from -2π radians to 2π
  2483.                                          radians, where π ≈ 3.141593. The
  2484.                                          default value for  start! is 0
  2485.                                          radians. The default value for
  2486.                                          end! is 2π radians.
  2487.  
  2488.                                          To convert values from degrees to
  2489.                                          radians, multiply the angle (in
  2490.                                          degrees) by π/180 (which equals
  2491.                                          .0174532925199433).
  2492.  
  2493.                                          If  start! is negative,  CIRCLE
  2494.                                          draws a radius to  start! and
  2495.                                          treats the angle as positive. If
  2496.                                          end! is negative,  CIRCLE draws a
  2497.                                          radius to  end! and treats the
  2498.                                          angle as positive. If both  start!
  2499.                                          and  end! are negative,  CIRCLE
  2500.                                          draws a radius to both  start! and
  2501.  Part                                    Description
  2502.  ────────────────────────────────────────────────────────────────────────────
  2503.                                         draws a radius to both  start! and
  2504.                                           end! and treats the angle as
  2505.                                          positive.
  2506.  
  2507.                                          The  start! angle can be less than
  2508.                                          the  end! angle. If you specify
  2509.                                          end! but not  start!, the arc is
  2510.                                          drawn from zero to  end!; if you
  2511.                                          specify  start! but not  end!, the
  2512.                                          statement draws an arc from
  2513.                                          start! to 2π.
  2514.  
  2515.   aspect!                                The aspect ratio, or the ratio of
  2516.                                          the  y! radius to the  x! radius.
  2517.                                          The default value for  aspect! is
  2518.                                          the value required to draw a round
  2519.                                          circle in the screen mode. This
  2520.                                          value is calculated as follows:
  2521.  
  2522.  Part                                    Description
  2523.  ────────────────────────────────────────────────────────────────────────────
  2524. 
  2525.                                           aspect! = 4 * ( ypixels/xpixels
  2526.                                          )/3
  2527.  
  2528.                                          In this formula,  xpixels by
  2529.                                          ypixels is the screen resolution.
  2530.                                          For example, in screen mode 1,
  2531.                                          where the resolution is 320 x 200,
  2532.                                          the default for  aspect! is 4 *
  2533.                                          (200/320)/3, or 5/6.
  2534.  
  2535.                                          If the aspect ratio is less than
  2536.                                          one,  radius! is the  x! radius.
  2537.                                          If aspect is greater than one,
  2538.                                          radius! is equal to the  y! radius.
  2539.  
  2540.  
  2541.  
  2542.  
  2543.  To draw a radius to angle 0 (a horizontal line segment to the right), do not
  2544.  give the angle as -0. Instead, use a very small non-zero value as
  2545.  shown in the following code fragment, which draws a one-quarter wedge of a
  2546.  circle.
  2547.  
  2548.  SCREEN 2
  2549.  CIRCLE (200,100),60,,-.0001,-1.57
  2550.  
  2551.  You can omit an argument in the middle of the statement, but you must
  2552.  include the argument's comma. In the following statement,  color& has been
  2553.  omitted:
  2554.  
  2555.  CIRCLE STEP (150,200),94,,0.0,6.28
  2556.  
  2557.  If you omit a trailing argument, do not include its corresponding comma in
  2558.  the statement.
  2559.  
  2560.  The  CIRCLE statement updates the graphics cursor position to the center of
  2561.  the ellipse or circle after drawing is complete.
  2562.  
  2563.  You can use coordinates that are outside the screen or viewport. You can
  2564.  show coordinates as absolutes, or you can use the  STEP option to show the
  2565.  position of the center point in relation to the previous point of reference.
  2566.  For example, if the previous point of reference were (10,10), the statement
  2567.  below would draw a circle with radius 75 and center offset 10 from the
  2568.  current x coordinate and 5 from the current y coordinate. The circle's
  2569.  center would be (20,15).
  2570.  
  2571.  CIRCLE STEP (10,5), 75
  2572.  
  2573.  
  2574.  Example
  2575.  
  2576.  The following example first draws a circle with the upper-left quarter
  2577.  missing. It then uses relative coordinates to position a second circle
  2578.  within the missing quarter circle. Finally, it uses a different aspect ratio
  2579.  to draw a small ellipse inside the small circle.
  2580.  
  2581.  CONST PI=3.141593
  2582.  SCREEN 2
  2583.  ' Draw a circle with the upper-left quarter missing.
  2584.  ' Use negative numbers so radii are drawn.
  2585.  CIRCLE (320,100), 200,, -PI, -PI/2
  2586.  ' Use relative coordinates to draw a circle within the missing
  2587.  ' quarter.
  2588.  CIRCLE STEP (-100,-42),100
  2589.  ' Draw a small ellipse inside the circle.
  2590.  CIRCLE STEP(0,0), 100,,,, 5/25
  2591.  ' Display the drawing until a key is pressed.
  2592.  LOCATE 25,1 : PRINT "Press any key to end.";
  2593.  DO
  2594.  LOOP WHILE INKEY$=""
  2595.  
  2596.  
  2597.  
  2598.  
  2599.  CLEAR Statement
  2600.  ────────────────────────────────────────────────────────────────────────────
  2601.  
  2602.  
  2603.  Action
  2604.  
  2605.  Reinitializes all program variables, closes any open files, and optionally
  2606.  sets the stack size.
  2607.  
  2608.  
  2609.  Syntax
  2610.  
  2611.   CLEAR «,,  stack&»
  2612.  
  2613.  
  2614.  Remarks
  2615.  
  2616.  The  CLEAR statement performs the following actions:
  2617.  
  2618.    ■   Closes all files and releases the file buffers.
  2619.  
  2620.    ■   Clears all common variables.
  2621.  
  2622.    ■   Sets numeric variables and arrays to zero.
  2623.  
  2624.    ■   Sets all string variables to null.
  2625.  
  2626.    ■   Reinitializes the stack and, optionally, changes its size.
  2627.  
  2628.  The  stack& parameter sets aside stack space for your program.  BASIC
  2629.  takes the amount of stack space it requires, adds the number of bytes
  2630.  specified by  stack&, and sets the stack size to the result.
  2631.  
  2632.  
  2633.  Note
  2634.  
  2635.  Two commas are used before  stack& to keep BASIC compatible with BASICA.
  2636.  BASICA included an additional argument that set the size of the data
  2637.  segment. Because BASIC automatically manages the data segment, the first
  2638.  parameter is no longer required.
  2639.  
  2640.  
  2641.  If your program has deeply nested subroutines or procedures, or if you use
  2642.  recursive procedures, you may want to use a  CLEAR statement to increase the
  2643.  stack size. You also may want to increase the stack size if your procedures
  2644.  have a large number of arguments.
  2645.  
  2646.  Clearing the stack destroys the return addresses placed on the stack during
  2647.  a  GOSUB operation. This makes it impossible to execute a  RETURN statement
  2648.  correctly, and BASIC generates a  RETURN without GOSUB run-time error
  2649.  message. If you use a  CLEAR statement in a  SUB or  FUNCTION declaration,
  2650.  BASIC  generates the run-time error message Illegal function call.
  2651.  
  2652.  
  2653.  BASICA
  2654.  
  2655.  BASICA programs using  CLEAR may require modification. In BASICA programs,
  2656.  any  DEF FN functions or data types declared with  DEF type statements are
  2657.  lost after a  CLEAR statement. In compiled programs, this information is not
  2658.  lost because these declarations are fixed at compile time.
  2659.  
  2660.  
  2661.  See Also
  2662.  
  2663.   ERASE,  FRE,  SETMEM,  STACK Function
  2664.  
  2665.  
  2666.  Example
  2667.  
  2668.  The following statement clears all program variables and sets aside 2,000
  2669.  bytes on the stack for the program:
  2670.  
  2671.  CLEAR ,,2000
  2672.  
  2673.  
  2674.  
  2675.  
  2676.  CLNG Function
  2677.  ────────────────────────────────────────────────────────────────────────────
  2678.  
  2679.  
  2680.  Action
  2681.  
  2682.  Converts a numeric expression to a long (4-byte) integer by rounding the
  2683.  fractional part of the expression.
  2684.  
  2685.  
  2686.  Syntax
  2687.  
  2688.   CLNG( numeric-expression)
  2689.  
  2690.  
  2691.  Remarks
  2692.  
  2693.  If  numeric-expression is not between -2,147,483,648 and
  2694.  2,147,483,647, inclusive, BASIC generates the error message Overflow.
  2695.  
  2696.  
  2697.  See Also
  2698.  
  2699.   CCUR,  CDBL,  CINT,  CSNG
  2700.  
  2701.  
  2702.  Example
  2703.  
  2704.  The following example shows how  CLNG rounds before converting the number:
  2705.  
  2706.  A=32767.45
  2707.  B=32767.55
  2708.  PRINT CLNG(A); CLNG(B)
  2709.  
  2710.  
  2711.  Output
  2712.  
  2713.  32767  32768
  2714.  
  2715.  
  2716.  
  2717.  
  2718.  CLOSE Statement
  2719.  ────────────────────────────────────────────────────────────────────────────
  2720.  
  2721.  
  2722.  Action
  2723.  
  2724.  Concludes I/O to a file, device, or ISAM table.
  2725.  
  2726.  
  2727.  Syntax
  2728.  
  2729.   CLOSE««#»filenumber%«,«#»filenumber%»»...
  2730.  
  2731.  
  2732.  Remarks
  2733.  
  2734.  The  CLOSE statement complements the  OPEN statement.
  2735.  
  2736.  The argument  filenumber% is the number used in the  OPEN statement to open
  2737.  the file, device, or ISAM table. A  CLOSE statement with no arguments closes
  2738.  all open files and devices, including all open ISAM tables.
  2739.  
  2740.  The association of a file, device, or ISAM table with  filenumber% ends when
  2741.  a  CLOSE statement is executed. You then can reopen the file, device, or
  2742.  table using the same or a different file number.
  2743.  
  2744.  Any ISAM operation that closes a table causes transactions to be committed.
  2745.  For example, if a type mismatch occurs while you are opening an ISAM table,
  2746.  the table is closed and a pending transaction is committed.
  2747.  
  2748.  You may wish to code your programs so they first open all tables, then
  2749.  perform all transactions, then close tables. Make sure any operation that
  2750.  can close a table occurs outside a transaction.
  2751.  
  2752.  Using a  CLOSE statement for a file or device that was opened for sequential
  2753.  output writes the final buffer of output to that file or device.  CLOSE
  2754.  releases all buffer space associated with the closed file, device, or table.
  2755.  
  2756.  
  2757.  The  CLEAR,  END,  RESET,  RUN, and  SYSTEM statements, and the  CHAIN
  2758.  statement when used with the /O command-line option, also close all files,
  2759.  devices, and tables.
  2760.  
  2761.  
  2762.  Note
  2763.  
  2764.   CLOSE commits any pending ISAM transactions.
  2765.  
  2766.  
  2767.  See Also
  2768.  
  2769.   END,  OPEN,  RESET,  STOP
  2770.  
  2771.  
  2772.  Example
  2773.  
  2774.  See the  FREEFILE function programming example, which uses the  CLOSE
  2775.  statement.
  2776.  
  2777.  
  2778.  
  2779.  
  2780.  CLS Statement
  2781.  ────────────────────────────────────────────────────────────────────────────
  2782.  
  2783.  
  2784.  Action
  2785.  
  2786.  Clears various parts of the display screen.
  2787.  
  2788.  
  2789.  Syntax
  2790.  
  2791.   CLS «{ 0 |  1 |  2}»
  2792.  
  2793.  
  2794.  Remarks
  2795.  
  2796.  There are several ways to use the  CLS statement, as described in the
  2797.  following table:
  2798.  
  2799. ╓┌──────────┌───────────────────────────────┌────────────────────────────────╖
  2800.  Statement  Condition                       Operations performed
  2801.  ────────────────────────────────────────────────────────────────────────────
  2802.   CLS       Graphics-screen mode no         Clears default graphics
  2803.             user-defined graphics viewport  viewport; regenerates bottom
  2804.                                             text line; returns cursor to
  2805.                                             the upper-left corner of the
  2806.                                             screen.
  2807.  
  2808.             Graphics-screen mode            Clears user-defined graphics
  2809.             user-defined viewport           viewport; does not regenerate
  2810.                                             bottom text line; does not
  2811.                                             return the cursor to the
  2812.                                             upper-left corner of the screen.
  2813.  
  2814.             In screen mode 0 (text mode)    Clears text viewport;
  2815.                                             regenerates bottom text line;
  2816.  Statement  Condition                       Operations performed
  2817.  ────────────────────────────────────────────────────────────────────────────
  2818.                                            regenerates bottom text line;
  2819.                                             returns the text cursor to the
  2820.                                             upper-left corner of the screen.
  2821.  
  2822.   CLS 0     Any screen mode, combination    Clears the screen of all text
  2823.             of viewports                    and graphics, except bottom
  2824.                                             text line; clears graphics
  2825.                                             viewport; regenerates bottom
  2826.                                             text line; returns the cursor
  2827.                                             to the upper-left corner of the
  2828.                                             screen.
  2829.  
  2830.   CLS 1     Graphics-screen mode with no    Clears default graphics
  2831.             user-defined graphics viewport  viewport; does not clear text
  2832.                                             viewport; regenerates bottom
  2833.                                             text line; returns the cursor
  2834.                                             to upper-left corner of the
  2835.                                             screen.
  2836.  
  2837.  Statement  Condition                       Operations performed
  2838.  ────────────────────────────────────────────────────────────────────────────
  2839. 
  2840.             Graphics-screen mode with        Clears user-defined graphics
  2841.             user-defined graphics viewport  viewport; does not clear text
  2842.                                             viewport; does not regenerate
  2843.                                             bottom text line; does not
  2844.                                             return the cursor to the
  2845.                                             upper-left corner of the screen.
  2846.  
  2847.             In screen mode 0 (text mode)    Has no effect.
  2848.  
  2849.   CLS 2     Any screen mode                 Clears the text viewport (even
  2850.                                             if the user-defined text
  2851.                                             viewport includes the bottom
  2852.                                             line of text, it will not be
  2853.                                             cleared); does not clear the
  2854.                                             graphics viewport; does not
  2855.                                             regenerate the bottom text
  2856.                                             line; returns the cursor to
  2857.                                             upper-left corner of the screen.
  2858.  Statement  Condition                       Operations performed
  2859.  ────────────────────────────────────────────────────────────────────────────
  2860.                                            upper-left corner of the screen.
  2861.  
  2862.  
  2863.  
  2864.  
  2865.  The behavior of a particular  CLS statement depends on:
  2866.  
  2867.    ■   The  CLS statement argument: 0, 1, 2, or none.
  2868.  
  2869.    ■   The current screen mode.
  2870.  
  2871.    ■   Whether a  VIEW statement has been executed that has changed the
  2872.        graphics viewport from the default of the entire screen.
  2873.  
  2874.    ■   Whether a  VIEW  PRINT statement has been executed that established a
  2875.        user-defined viewport.
  2876.  
  2877.    ■   Whether a  KEY  ON statement has been executed that established the
  2878.        bottom text line as a list of function-key assignments. The bottom
  2879.        line on the screen may be 25, 30, 43, or 60, depending upon the
  2880.        current screen mode.
  2881.  
  2882.  
  2883.  The following fundamentals about the graphics and text viewports determine
  2884.  how the  CLS statement works:
  2885.  
  2886.  
  2887.    ■   Screen mode 0 has only a text viewport. All other screen modes have
  2888.        both a text and graphics viewport.
  2889.  
  2890.    ■   The default graphics viewport is the entire screen.
  2891.  
  2892.    ■   The default text viewport is the entire screen, except for the bottom
  2893.        line of text.
  2894.  
  2895.    ■   After a user-defined graphics viewport (or "clipping region") has been
  2896.        established by execution of a  VIEW statement, it is reset to the
  2897.        default by execution of any of these statements:  VIEW without
  2898.        arguments;  CLEAR; any  SCREEN statement that changes the screen
  2899.        resolution.
  2900.  
  2901.    ■   After a user-defined text viewport has been established by execution
  2902.        of a  VIEW  PRINT statement, it is reset to the default by execution
  2903.        of either a  VIEW  PRINT statement without arguments, or any
  2904.        text-oriented statement, such as  WIDTH, that changes the number of
  2905.        text columns or text lines on the screen.
  2906.  
  2907.    ■   If the  KEY  ON statement has been executed and the  CLS statement
  2908.        regenerates the bottom screen line, the  CLS statement regenerates the
  2909.        function-key assignment list. If the  KEY  ON statement has not been
  2910.        executed, the  CLS statement generates a line of blank characters.
  2911.  
  2912.  
  2913.  See Also
  2914.  
  2915.   VIEW,  VIEW PRINT,  WINDOW
  2916.  
  2917.  
  2918.  Example
  2919.  
  2920.  The following example draws random circles in a graphics viewport and prints
  2921.  to a text viewport. The graphics viewport is cleared after 30 circles have
  2922.  been drawn. The program clears the text viewport after printing to it 45
  2923.  times.
  2924.  
  2925.  RANDOMIZE TIMER
  2926.  SCREEN 1
  2927.  ' Set up a graphics viewport with a border.
  2928.  VIEW (5,5)-(100,80),3,1
  2929.  ' Set up a text viewport.
  2930.  VIEW PRINT 12 TO 24
  2931.  LOCATE 25,1 : PRINT "Press any key to stop."
  2932.  ' Outside the text viewport.
  2933.  Count=0
  2934.  DO
  2935.  CIRCLE (50,40),INT((35-4) * RND + 5),(Count MOD 4)
  2936.  ' Clear graphics viewport every 30 times.
  2937.  IF (Count MOD 30)=0 THEN CLS 1
  2938.  PRINT "Hello. ";
  2939.  ' Clear text viewport every 45 times.
  2940.  IF (Count MOD 45)=0 THEN CLS 2
  2941.  Count=Count+1
  2942.  LOOP UNTIL INKEY$ <> ""
  2943.  
  2944.  
  2945.  
  2946.  
  2947.  COLOR Statement
  2948.  ────────────────────────────────────────────────────────────────────────────
  2949.  
  2950.  
  2951.  Action
  2952.  
  2953.  Sets the foreground and background colors for the display.
  2954.  
  2955.  
  2956.  Syntax 1
  2957.  
  2958.   COLOR  «foreground&»«, «background&»«, border&»»  Screen mode 0 (text only)
  2959.  
  2960.  Syntax 2
  2961.  
  2962.   COLOR «background&»«, palette%»                   Screen mode 1
  2963.  
  2964.  Syntax 3
  2965.  
  2966.   COLOR  «foreground&»                              Screen mode 4
  2967.  
  2968.  Syntax 4
  2969.  
  2970.   COLOR  «foreground&»«, background&»               Screen modes 7-10
  2971.  
  2972.  Syntax 5
  2973.  
  2974.   COLOR  «foreground&»                              Screen modes 12,13
  2975.  
  2976.  
  2977.  Remarks
  2978.  
  2979.  With the COLOR statement, you can set the foreground or background colors
  2980.  for the display. In screen mode 0, a border color also can be selected. In
  2981.  screen mode 1, no foreground color can be selected, but one of two
  2982.  three-color palettes can be selected for use with graphic statements. In
  2983.  screen modes 4, 12, and 13, only the foreground color can be set.
  2984.  
  2985.  The  COLOR statement does not determine the range of available colors. The
  2986.  combination of adapter, display, and screen mode determines the color range.
  2987.  If you use  COLOR statement arguments outside these valid ranges, BASIC
  2988.  generates the error message Illegal function call. For more information, see
  2989.  the entry for the  SCREEN statement.
  2990.  
  2991.  The  COLOR statement uses the following arguments:
  2992.  
  2993. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  2994.  Argument                                Description
  2995.  ────────────────────────────────────────────────────────────────────────────
  2996.   foreground&                            Text color attribute in screen
  2997.                                          mode 0; text or line-drawing
  2998.                                          display color in screen mode 4;
  2999.                                          text and line-drawing color
  3000.                                          attribute in screen modes
  3001.                                          7-10, 12, and 13.
  3002.  
  3003.   background&                            Color code or color attribute for
  3004.                                          screen background.
  3005.  Argument                                Description
  3006.  ────────────────────────────────────────────────────────────────────────────
  3007.                                         screen background.
  3008.  
  3009.   border&                                Color code for the area
  3010.                                          surrounding the screen.
  3011.  
  3012.   palette%                               In screen mode 1, one of two
  3013.                                          three-color palettes: is green,
  3014.                                          red, and brown; 1 is cyan, magenta,
  3015.                                          and bright white.
  3016.  
  3017.  
  3018.  
  3019.  
  3020.  
  3021.  The different versions of syntax and their effects in different screen modes
  3022.  are described in the following table:
  3023.  
  3024. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  3025.  Screen mode                             Syntax and description
  3026.  Screen mode                             Syntax and description
  3027.  ────────────────────────────────────────────────────────────────────────────
  3028.  0                                        COLOR «foreground&»«, «
  3029.                                          background&»«,  border&»»
  3030.  
  3031.                                          Modifies the current default text
  3032.                                          foreground and background colors
  3033.                                          and the screen border. The
  3034.                                          foreground& color value must be an
  3035.                                          integer expression between 0 and
  3036.                                          31, inclusive. It determines the
  3037.                                          foreground color in text mode --
  3038.                                          the default color of text. Sixteen
  3039.                                          colors can be selected with the
  3040.                                          integers 0-15. A blinking version
  3041.                                          of a color is specified by adding
  3042.                                          16 to the color number. For
  3043.                                          example, a blinking color 7 is
  3044.                                          equal to 7 + 16, or 23.
  3045.  
  3046.                                          The  background& color value is an
  3047.  Screen mode                             Syntax and description
  3048.  ────────────────────────────────────────────────────────────────────────────
  3049.                                         The  background& color value is an
  3050.                                          integer expression between 0 and 7,
  3051.                                          inclusive, and is the color of the
  3052.                                          background for each text character.
  3053.                                          Blinking background colors are not
  3054.                                          supported.
  3055.  
  3056.                                          The  border& color, which fills
  3057.                                          the screen area outside the text
  3058.                                          area, is an integer expression
  3059.                                          between 0 and 15, inclusive. Note
  3060.                                          that the  border& argument has no
  3061.                                          effect with the following
  3062.                                          adapters: the IBM Enhanced
  3063.                                          Graphics Adapter (EGA), the IBM
  3064.                                          Video Graphics Array adapter (VGA),
  3065.                                          and the IBM Multicolor Graphics
  3066.                                          Array adapter (MCGA).
  3067.  
  3068.  Screen mode                             Syntax and description
  3069.  ────────────────────────────────────────────────────────────────────────────
  3070. 
  3071.  1                                        COLOR «background&»«, palette%»
  3072.  
  3073.                                          The  background& color value must
  3074.                                          be an integer expression between 0
  3075.                                          and 3, inclusive.
  3076.  
  3077.                                          The argument  palette% is an
  3078.                                          integer expression with an odd or
  3079.                                          even value between 0 and 255,
  3080.                                          inclusive. An even value makes
  3081.                                          available one set of three default
  3082.                                          foreground colors, and an odd
  3083.                                          value makes available a different
  3084.                                          default set.
  3085.  
  3086.                                          The default colors for  palette%
  3087.                                          are equivalent to the following
  3088.                                          PALETTE statements on a system
  3089.  Screen mode                             Syntax and description
  3090.  ────────────────────────────────────────────────────────────────────────────
  3091.                                         PALETTE statements on a system
  3092.                                          equipped with an EGA:
  3093.  
  3094.  
  3095.  ' Definition of the even palette-number set.
  3096.  COLOR ,0' In screen mode 1, an even palette
  3097.  '   number is equivalent to:
  3098.  PALETTE 1,2 ' EGA Attribute 1 = color 2 (green)
  3099.  PALETTE 2,4 ' EGA Attribute 2 = color 4 (red)
  3100.  PALETTE 3,6 ' EGA Attribute 3 = color 6 (yellow)
  3101.  
  3102.  ' Definition of the odd palette-number set.
  3103.  COLOR ,1' In screen mode 1, an odd palette
  3104.  '   number is equivalent to:
  3105.  PALETTE 1,3 ' EGA Attribute 1 = color 3 (cyan)
  3106.  PALETTE 2,5 ' EGA Attribute 2 = color 5 (magenta)
  3107.  PALETTE 3,7 ' EGA Attribute 3 = color 7 (white)
  3108.  
  3109. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  3110.  Screen mode                             Syntax and description
  3111.  ────────────────────────────────────────────────────────────────────────────
  3112.                                          Note that in screen mode 1, a
  3113.                                          COLOR statement overrides  PALETTE
  3114.                                          statements that were executed
  3115.                                          previously.
  3116.  
  3117.  4                                        COLOR  «foreground&»
  3118.  
  3119.                                          The screen  foreground& color
  3120.                                          value must be an integer
  3121.                                          expression between 0 and 15,
  3122.                                          inclusive. This expression sets
  3123.                                          the display color associated with
  3124.                                          color attribute 1 only. The screen
  3125.                                          background color is fixed as black.
  3126.  
  3127.  7-10                                     COLOR  «foreground&»«,
  3128.                                          background&»
  3129.  
  3130.                                          The argument  foreground&, the
  3131.  Screen mode                             Syntax and description
  3132.  ────────────────────────────────────────────────────────────────────────────
  3133.                                         The argument  foreground&, the
  3134.                                          line-drawing color, is a color
  3135.                                          attribute. The argument
  3136.                                          background&, the screen color, is
  3137.                                          a display color.
  3138.  
  3139.  12, 13                                   COLOR  «foreground&»
  3140.  
  3141.                                          The argument  foreground&, the
  3142.                                          line drawing color, is a color
  3143.                                          attribute.
  3144.  
  3145.  
  3146.  
  3147.  
  3148.  BASIC generates the error message Illegal function call if the  COLOR
  3149.  statement is used in screen modes 2, 3, or 11. Use the  PALETTE statements
  3150.  to set the color in screen mode 11.
  3151.  
  3152.  The foreground can be the same color as the background, making characters
  3153.  and graphics invisible. The default background color is black for all
  3154.  display hardware configurations and all screen modes. This background is
  3155.  produced by the default display color of 0 associated with the background
  3156.  color attribute of 0.
  3157.  
  3158.  In screen modes 12 and 13 you can set the background color by assigning a
  3159.  color to attribute 0 with a  PALETTE statement. For example, to make the
  3160.  background color 8224 (an olive drab), you would use the following  PALETTE
  3161.  statement:
  3162.  
  3163.  PALETTE 0,8224
  3164.  
  3165.  To make the background color bright red-violet, use the following  PALETTE
  3166.  statement:
  3167.  
  3168.  PALETTE 0, 4128831
  3169.  
  3170.  In screen mode 11 you can set both the foreground and background color by
  3171.  assigning a color to attribute 0 with a  PALETTE statement.
  3172.  
  3173.  With an EGA, VGA, or MCGA installed, the  PALETTE statement gives you
  3174.  flexibility in assigning different display colors to the color-attribute
  3175.  ranges for the  foreground&,  background&, and  border& colors. For more
  3176.  information, see the  PALETTE statement.
  3177.  
  3178.  
  3179.  See Also
  3180.  
  3181.   PAINT,  PALETTE,  SCREEN Statement
  3182.  
  3183.  
  3184.  Example
  3185.  
  3186.  The following series of examples show  COLOR statements and their effects in
  3187.  the various screen modes:
  3188.  
  3189.  SCREEN 0    ' Text mode only.
  3190.  ' Foreground& = 1 (blue), background& = 2 (green), border& = 3 (cyan).
  3191.  ' EGA and VGA boards do not support the border& argument.
  3192.  COLOR 1, 2, 3
  3193.  CLS
  3194.  LOCATE 12, 25: PRINT "Press any key to continue..."
  3195.  DO : LOOP WHILE INKEY$ = ""
  3196.  SCREEN 1    ' Set screen to 320 x 200 graphics.
  3197.  ' Background& = 1 (blue).
  3198.  ' Foreground& = even palette number (red, green, yellow).
  3199.  COLOR 1, 0
  3200.  LINE (20, 20)-(300, 180), 3, B    ' Draw a brown box.
  3201.  LOCATE 12, 7: PRINT "Press any key to continue..."
  3202.  DO : LOOP WHILE INKEY$ = ""
  3203.  ' Background& = 2 (green).
  3204.  ' Foreground& = odd palette number (white, magenta, cyan).
  3205.  COLOR 2, 1
  3206.  LINE (20, 20)-(300, 180), 3, B    ' Draw a bright white box.
  3207.  LOCATE 12, 7: PRINT "Press any key to continue..."
  3208.  DO : LOOP WHILE INKEY$ = ""
  3209.  SCREEN 0    ' Set screen to text mode.
  3210.  ' Foreground& = 7 (white), background& = 0 (black), border& = 0
  3211.  ' (black).
  3212.  COLOR 7, 0, 0
  3213.  CLS
  3214.  END
  3215.  
  3216.  
  3217.  
  3218.  
  3219.  ────────────────────────────────────────────────────────────────────────────
  3220.  COM Statements
  3221.  
  3222.  
  3223.  Action
  3224.  
  3225.  Enable, disable, or suspend event trapping at the COM port.
  3226.  
  3227.  
  3228.  Syntax
  3229.  
  3230.   COM( n%)  ON
  3231.   COM( n%)  OFFn%)
  3232.   COM( n%)  STOP
  3233.  
  3234.  
  3235.  Remarks
  3236.  
  3237.  The argument  n% specifies the number of the COM (serial) port;  n% can be
  3238.  either 1 or 2.
  3239.  
  3240.   COM( n%)  ON enables communications-event trapping on COM port  n%. If a
  3241.  character arrives at a communications port after a  COM( n%)  ON statement,
  3242.  the routine specified in the  ON  COM statement is executed.
  3243.  
  3244.   COM( n%)  OFF disables communications-event trapping on COM port  n%. No
  3245.  communications trapping takes place until another  COM( n%)  ON statement is
  3246.  executed. Events occurring while trapping is off are ignored.
  3247.  
  3248.   COM( n%)  STOP suspends communications-event trapping on COM port  n%. No
  3249.  trapping takes place until a  COM( n%)  ON statement is executed. Events
  3250.  occurring while trapping is suspended are remembered and processed when the
  3251.  next  COM( n%)  ON statement is executed. However, remembered events are
  3252.  lost if  COM( n%)  OFF is executed
  3253.  
  3254.  When a communications-event trap occurs (that is, the  GOSUB operation is
  3255.  performed), an automatic  COM( n%)  STOP is executed so that recursive traps
  3256.  cannot take place. The  RETURN statement from the trapping routine
  3257.  automatically executes a  COM( n%)  ON statement unless an explicit  COM(
  3258.  n%)  OFF was performed inside the routine.
  3259.  
  3260.  For more information, see Chapter 9, "Event Handling" in the  Programmer's
  3261.  Guide.
  3262.  
  3263.  
  3264.  See Also
  3265.  
  3266.   ON  event
  3267.  
  3268.  
  3269.  Example
  3270.  
  3271.  
  3272.  The following example opens COM1 and then monitors the COM1 port for input.
  3273.  It uses the  ON COM statement to trap communications events.
  3274.  
  3275.  CLS
  3276.  ' Set up error handling in case COM1 doesn't exist.
  3277.  ON ERROR GOTO ErrHandler
  3278.  OPEN "COM1:9600,N,8,1,BIN" FOR INPUT AS #1
  3279.  
  3280.  COM(1) ON ' Turn on COM event processing.
  3281.  ON COM(1) GOSUB Com1Handler' Set up COM event handling.
  3282.  ' Wait for a COM event to occur or a key to be pressed.
  3283.  DO : LOOP WHILE INKEY$ = ""
  3284.  COM(1) OFF' Turn off COM event handling.
  3285.  CLS
  3286.  END
  3287.  
  3288.  Com1Handler:
  3289.      PRINT A$; "Something was typed on the terminal attached to COM1."
  3290.      RETURN
  3291.  
  3292.  ErrHandler:
  3293.      SELECT CASE ERR
  3294.          CASE 68: PRINT "COM1 is unavailable on this computer.": END
  3295.          CASE ELSE: END
  3296.      END SELECT
  3297.  
  3298.  
  3299.  
  3300.  
  3301.  COMMAND$ Function
  3302.  ────────────────────────────────────────────────────────────────────────────
  3303.  
  3304.  
  3305.  Action
  3306.  
  3307.  Returns the command line used to invoke the program.
  3308.  
  3309.  
  3310.  Syntax
  3311.  
  3312.   COMMAND$
  3313.  
  3314.  
  3315.  Remarks
  3316.  
  3317.  The  COMMAND$ function returns the complete command line entered after your
  3318.  BASIC program name, including optional parameters.  COMMAND$ removes all
  3319.  leading blanks from the command line and converts all letters to uppercase
  3320.  (capital letters).
  3321.  
  3322.  The  COMMAND$ function can be used in stand-alone executable files or, if
  3323.  you are executing from the QBX environment, by using the /CMD command-line
  3324.  option, or by selecting Modify COMMAND$ on the Run menu.
  3325.  
  3326.  
  3327.  Examples
  3328.  
  3329.  The following example breaks the command line into separate arguments and
  3330.  stores them in an array. Each argument is separated from adjoining arguments
  3331.  by one or more blanks or tabs on the command line.
  3332.  
  3333.  ' Default variable type is integer in this module.
  3334.  DEFINT A-Z
  3335.  
  3336.  ' Declare the Comline subprogram, as well as the number and
  3337.  ' type of its parameters.
  3338.  DECLARE SUB Comline(N, A$(),Max)
  3339.  
  3340.  DIM A$(1 TO 15)
  3341.  ' Get what was typed on the command line.
  3342.  CALL Comline(N,A$(),10)
  3343.  ' Print out each part of the command line.
  3344.  PRINT "Number of arguments = ";N
  3345.  PRINT "Arguments are: "
  3346.  FOR I=1 TO N : PRINT A$(I) : NEXT I
  3347.  
  3348.  ' SUB procedure to get command line and split into arguments.
  3349.  ' Parameters:  NumArgs : Number of command-line args found.
  3350.  '              Args$() : Array in which to return arguments.
  3351.  '              MaxArgs : Maximum number of arguments array can return.
  3352.  SUB Comline(NumArgs,Args$,MaxArgs) STATIC
  3353.  CONST TRUE=-1, FALSE=0
  3354.  NumArgs=0 : In=FALSE
  3355.  Cl$=COMMAND$' Get the command line using the COMMAND$ function.
  3356.  L=LEN(Cl$)' Go through the command line a character at a time.
  3357.  FOR I=1 TO L
  3358.  C$=MID$(Cl$,I,1)
  3359.  ' Test for character being a blank or a tab.
  3360.  IF (C$<>" " AND C$<>CHR$(9)) THEN' Neither blank nor tab.
  3361.  ' Test to see if you're already inside an argument.
  3362.  IF NOT In THEN' You've found the start of a new argument.
  3363.  ' Test for too many arguments.
  3364.  IF NumArgs=MaxArgs THEN EXIT FOR
  3365.  NumArgs=NumArgs+1
  3366.  In=TRUE
  3367.  END IF
  3368.  ' Add the character to the current argument.
  3369.  Args$(NumArgs)=Args$(NumArgs)+C$
  3370.  ELSE' Found a blank or a tab.
  3371.  ' Set "Not in an argument" flag to FALSE.
  3372.  In=FALSE
  3373.  END IF
  3374.  NEXT I
  3375.  END SUB
  3376.  
  3377.  
  3378.  The following is a sample command line and output for a stand-alone
  3379.  executable file (assumes program name is arg.exe):
  3380.  
  3381.  arg one  two   three    four     five      six
  3382.  
  3383.  
  3384.  Output
  3385.  
  3386.  Number of arguments =  6
  3387.  Arguments are:
  3388.  ONE
  3389.  TWO
  3390.  THREE
  3391.  FOUR
  3392.  FIVE
  3393.  SIX
  3394.  
  3395.  
  3396.  
  3397.  
  3398.  COMMITTRANS Statement
  3399.  ────────────────────────────────────────────────────────────────────────────
  3400.  
  3401.  
  3402.  Action
  3403.  
  3404.  Commits all ISAM database operations since the most recent  BEGINTRANS
  3405.  statement.
  3406.  
  3407.  
  3408.  Syntax
  3409.  
  3410.   COMMITTRANS
  3411.  
  3412.  
  3413.  Remarks
  3414.  
  3415.   COMMITTRANS commits a pending transaction (a series of ISAM database
  3416.  operations).
  3417.  
  3418.  Transactions are a way to group a series of operations so that you can
  3419.  commit them as a whole, rescind them all, or rescind operations since a
  3420.  designated savepoint. Use  BEGINTRANS to indicate the beginning of a
  3421.  transaction. Use Savepoint to designate a savepoint. Use  ROLLBACK and
  3422.  ROLLBACK  ALL to rescind all or part of a transaction's operations.
  3423.  
  3424.  If you attempt to use  COMMITTRANS when there is no transaction pending,
  3425.  BASIC generates the error message Illegal function call.
  3426.  
  3427.   COMMITTRANS commits only ISAM operations. It does not affect other BASIC
  3428.  variables or file types.
  3429.  
  3430.  Any ISAM operation that closes a table causes transactions to be committed.
  3431.  For example, if a type mismatch occurs while you are opening an ISAM table,
  3432.  the table is closed and a pending transaction is committed.
  3433.  
  3434.  You may wish to code your programs so they first open all tables, then
  3435.  perform all transactions, then close tables. Make sure any operation that
  3436.  can close a table occurs outside a transaction.
  3437.  
  3438.  
  3439.  See Also
  3440.  
  3441.   BEGINTRANS, checkpoint,  ROLLBACK,  SAVEPOINT
  3442.  
  3443.  
  3444.  Example
  3445.  
  3446.  See the  BEGINTRANS statement programming example, which uses the
  3447.  COMMITTRANS statement.
  3448.  
  3449.  
  3450.  COMMON Statement
  3451.  ────────────────────────────────────────────────────────────────────────────
  3452.  
  3453.  
  3454.  Action
  3455.  
  3456.  Defines global variables for sharing between modules or for chaining to
  3457.  another program.
  3458.  
  3459.  
  3460.  Syntax
  3461.  
  3462.   COMMON «SHARED»«/blockname/» variablelist
  3463.  
  3464.  
  3465.  Remarks
  3466.  
  3467.  The following list describes the parts of the  COMMON statement:
  3468.  
  3469. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  3470.  Part                                    Description
  3471.  ────────────────────────────────────────────────────────────────────────────
  3472.   SHARED                                 An optional attribute that
  3473.                                          indicates the variables are shared
  3474.                                          with all  SUB or  FUNCTION
  3475.                                          procedures in the module. The
  3476.                                          SHARED attribute can eliminate the
  3477.                                          need for a  SHARED statement
  3478.                                          inside  SUB or  FUNCTION
  3479.                                          procedures.
  3480.  
  3481.   blockname                              A valid BASIC identifier (up to 40
  3482.                                          characters) that identifies a
  3483.                                          group of variables. Use  blockname
  3484.                                          to share only specific groups of
  3485.                                          variables. You cannot use a
  3486.                                          type-declaration character ( %,  &,
  3487.                                           !,  #,  @, or  $) in the
  3488.  Part                                    Description
  3489.  ────────────────────────────────────────────────────────────────────────────
  3490.                                          !,  #,  @, or  $) in the
  3491.                                          identifier.
  3492.  
  3493.                                          When  blockname is used, the
  3494.                                          COMMON block is a named  COMMON
  3495.                                          block. When  blockname is omitted,
  3496.                                          the block is a blank  COMMON block.
  3497.                                          Items in a named  COMMON block are
  3498.                                          not preserved across a chain to a
  3499.                                          new program. See "Using Named
  3500.                                          COMMON" and "Using COMMON with
  3501.                                          CHAIN" later in this entry.
  3502.  
  3503.   variablelist                           A list of variables to be shared
  3504.                                          between modules or chained-to
  3505.                                          programs. The same variable cannot
  3506.                                          appear in more than one  COMMON
  3507.                                          statement in a module.
  3508.  
  3509.  Part                                    Description
  3510.  ────────────────────────────────────────────────────────────────────────────
  3511. 
  3512.  
  3513.  
  3514.  
  3515.  The syntax of  variablelist is:
  3516.  
  3517.   variable«( )» «AS type»«, variable«( )» «AS type»»...
  3518.  
  3519.  The following list describes the parts of  variablelist:
  3520.  
  3521. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  3522.  Part                                    Description
  3523.  ────────────────────────────────────────────────────────────────────────────
  3524.   variable                               Any valid BASIC variable name. It
  3525.                                          is either an array name followed
  3526.                                          by ( ), or a variable name.
  3527.  
  3528.   AS  type                               Declares the type of the variable.
  3529.                                          The type may be  INTEGER,  LONG,
  3530.  Part                                    Description
  3531.  ────────────────────────────────────────────────────────────────────────────
  3532.                                         The type may be  INTEGER,  LONG,
  3533.                                          SINGLE,  DOUBLE,  STRING (for
  3534.                                          variable-length strings),  STRING
  3535.                                          * length (for fixed-length
  3536.                                          strings),  CURRENCY, or a
  3537.                                          user-defined type.
  3538.  
  3539.  
  3540.  
  3541.  
  3542.  Note
  3543.  
  3544.  Older versions of BASIC required the number of dimensions to appear after
  3545.  the name of a dynamic array in a  COMMON statement. The number of dimensions
  3546.  is no longer required, although BASIC accepts the older syntax to maintain
  3547.  compatibility with earlier versions.
  3548.  
  3549.  
  3550.  A  COMMON statement establishes storage for variables in a special area that
  3551.  allows them to be shared between modules or with other programs invoked with
  3552.  a  CHAIN statement.
  3553.  
  3554.  Because  COMMON statements establish global variables for an entire program,
  3555.  they must appear before any executable statements. All statements are
  3556.  executable, except the following:
  3557.  
  3558.  COMMON                       OPTION BASE
  3559.  CONST                        REM
  3560.  DATA                         SHARED
  3561.  DECLARE                      STATIC
  3562.  DEFtype                      TYPE...END TYPE
  3563.  DIM (for static arrays)      All metacommands
  3564.  
  3565.  Variables in  COMMON blocks are matched by
  3566.  position and type, not by name. Therefore, variable order is significant in
  3567.  COMMON statements. In the following fragment, it is the order of the
  3568.  variables in the  COMMON statements that links the variables, not the names:
  3569.  
  3570.  ' Main program.
  3571.  COMMON A, D, E
  3572.  A = 5 : D = 8 : E = 10
  3573.  .
  3574.  .
  3575.  .
  3576.  ' Common statement in another module.
  3577.  COMMON A, E, D ' A = 5, E = 8, D = 10
  3578.  .
  3579.  .
  3580.  .
  3581.  
  3582.  Both static and dynamic arrays are placed in  COMMON by using the array name
  3583.  followed by parentheses. The dimensions for a static array must be set with
  3584.  integer-constant subscripts in a  DIM statement preceding the  COMMON
  3585.  statement. The dimensions for a dynamic array must be set in a later  DIM or
  3586.   REDIM statement. The elements of a dynamic array are not allocated in the
  3587.  COMMON block. Only an array descriptor is placed in common. For more
  3588.  information about static and dynamic arrays, see Appendix B, "Data Types,
  3589.  Constants, Variables, and Arrays" in the  Programmer's Guide.
  3590.  
  3591.  The size of a common area can be different from that in another module or
  3592.  chained program if a blank  COMMON block has been used. When a BASIC program
  3593.  shares  COMMON blocks with a routine in the user library, the calling
  3594.  program may not redefine the  COMMON block to a larger size.
  3595.  
  3596.  Errors caused by
  3597.  mismatched  COMMON statements are subtle and difficult to find. An easy way
  3598.  to avoid mismatched  COMMON statements is to place  COMMON declarations in a
  3599.  single include file and use the  $INCLUDE metacommand in each module.
  3600.  
  3601.  
  3602.  The following program fragments show how to use the  $INCLUDE metacommand to
  3603.  share a file containing  COMMON statements among programs:
  3604.  
  3605.  ' This file is menu.bas.
  3606.  ' $INCLUDE: 'COMDEF.BI'
  3607.  .
  3608.  .
  3609.  .
  3610.  CHAIN "PROG1"
  3611.  END
  3612.  
  3613.  ' This file is prog1.bas.
  3614.  ' $INCLUDE: 'COMDEF.BI'
  3615.  .
  3616.  .
  3617.  .
  3618.  END
  3619.  
  3620.  ' This file is COMDEF.BI.
  3621.  DIM A(100),B$(200)
  3622.  COMMON I,J,K,A()
  3623.  COMMON A$,B$(),X,Y,Z
  3624.  
  3625.  The next sections discuss using named  COMMON blocks and using  COMMON when
  3626.  chaining programs.
  3627.  
  3628.  
  3629.  Using Named Common
  3630.  
  3631.  A named  COMMON block provides a convenient way to group variables so that
  3632.  different modules have access only to the common variables they need.
  3633.  
  3634.  The following program
  3635.  fragment, which calculates the volume and density of a rectangular prism,
  3636.  uses named  COMMON blocks to share different sets of data with two  SUB
  3637.  procedures. The  SUB procedure Volume needs to share only the variables
  3638.  representing the lengths of the sides (in  COMMON block Sides). The  SUB
  3639.  procedure Density also needs variables representing the weight (in  COMMON
  3640.  block Weight).
  3641.  
  3642.  ' Main program.
  3643.  DIM S(3)
  3644.  COMMON /Sides/ S()
  3645.  COMMON /Weight/ C
  3646.  C=52
  3647.  S(1)=3:S(2)=3:S(3)=6
  3648.  CALL Volume
  3649.  CALL Density
  3650.  END
  3651.  
  3652.  ' SUB procedure Volume in a separate module.
  3653.  DIM S(3)
  3654.  COMMON SHARED /Sides/ S()
  3655.  
  3656.  SUB Volume STATIC
  3657.  Vol=S(1)*S(2)*S(3)
  3658.  .
  3659.  .
  3660.  .
  3661.  END SUB
  3662.  
  3663.  ' SUB procedure Density in a separate module.
  3664.  DIM S(3)
  3665.  COMMON SHARED /Sides/ S()
  3666.  COMMON SHARED /Weight/ W
  3667.  SUB Density STATIC
  3668.  Vol=S(1)*S(2)*S(3)
  3669.  Dens=W/Vol
  3670.  .
  3671.  .
  3672.  .
  3673.  END SUB
  3674.  
  3675.  
  3676.  Note
  3677.  
  3678.  Named  COMMON blocks are not preserved across chained programs. Use blank
  3679.  COMMON blocks to pass variables to a chained program.
  3680.  
  3681.  
  3682.  Using Common with CHAIN
  3683.  
  3684.  The  COMMON statement provides the only way to pass the values of variables
  3685.  directly to a chained program. To pass variables, both programs must contain
  3686.   COMMON statements. Remember that variable order and type are significant,
  3687.  not variable names. The order and type of variables must be the same for all
  3688.   COMMON statements communicating between chaining programs.
  3689.  
  3690.  Although the order and type of variables is critical for making sure the
  3691.  right values are passed, the  COMMON blocks do not have to be the same size.
  3692.  If the  COMMON block in the chained-to program is smaller than the  COMMON
  3693.  block in the chaining program, the extra  COMMON variables in the chaining
  3694.  program are discarded. If the size of the  COMMON block in the chained-to
  3695.  program is larger, then additional  COMMON numeric variables are initialized
  3696.  to zero. Additional string variables are initialized to null strings.
  3697.  
  3698.  Static arrays passed in a  COMMON block by the chaining program must be
  3699.  declared as static in the chained-to program. Similarly, dynamic arrays
  3700.  placed in common by the chaining program must be dynamic in the chained-to
  3701.  program.
  3702.  
  3703.  
  3704.  Note
  3705.  
  3706.  When you compile a program with the /O option, common variables are not
  3707.  preserved across the chain. To preserve values across a chain, you must
  3708.  compile without the /O option (using BC) or by selecting the EXE Requiring
  3709.  BRT Module option in the Make EXE File dialog box (using QBX).
  3710.  
  3711.  
  3712.  See Also
  3713.  
  3714.   CALL (BASIC),  CHAIN,  FUNCTION,  SUB
  3715.  
  3716.  
  3717.  Example
  3718.  
  3719.  See the  CHAIN statement programming example, which uses the  COMMON
  3720.  statement.
  3721.  
  3722.  
  3723.  
  3724.  
  3725.  CONST Statement
  3726.  
  3727.  
  3728.  Action
  3729.  
  3730.  Declares symbolic constants for use in place of values.
  3731.  
  3732.  
  3733.  Syntax
  3734.  
  3735.   CONST  constantname =  expression , « constantname =  expression»...
  3736.  
  3737.  
  3738.  Remarks
  3739.  
  3740.  The  CONST statement uses the following arguments:
  3741.  
  3742. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  3743.  Argument                                Description
  3744.  ────────────────────────────────────────────────────────────────────────────
  3745.   constantname                           A name that follows the same rules
  3746.                                          as a BASIC variable. You can add a
  3747.                                          type-declaration character ( %,  &,
  3748.                                           !,  #,  @, or  $) to
  3749.                                          indicate its type, but this
  3750.                                          character is not part of the name.
  3751.  
  3752.   expression                             An expression that consists of
  3753.                                          literals (such as 1.0), other
  3754.                                          constants, or any of the
  3755.                                          arithmetic and logical operators
  3756.                                          except exponentiation (^). You
  3757.                                          also can use a single literal
  3758.                                          string such as "Error on input".
  3759.                                          You cannot use string
  3760.                                          concatenation, variables,
  3761.  Argument                                Description
  3762.  ────────────────────────────────────────────────────────────────────────────
  3763.                                         concatenation, variables,
  3764.                                          user-defined functions, or
  3765.                                          intrinsic functions--such as
  3766.                                          SIN or  CHR$--in expressions
  3767.                                          assigned to constants.
  3768.  
  3769.  
  3770.  
  3771.  
  3772.  If you use a type-declaration character in the name, you can omit the
  3773.  character when the name is used, as shown in the following example:
  3774.  
  3775.  CONST MAXDIM% = 250
  3776.  .
  3777.  .
  3778.  .
  3779.  DIM AccountNames$(MAXDIM)
  3780.  
  3781.  If you omit the type-declaration character, the constant is given a type
  3782.  based on the expression in the  CONST statement. Strings always yield a
  3783.  string constant. With numeric expressions, the expression is evaluated and
  3784.  the constant is given the simplest type that can represent the constant. For
  3785.  example, if the expression gives a result that can be represented as an
  3786.  integer, the constant is given an integer type.
  3787.  
  3788.  
  3789.  Note
  3790.  
  3791.  Names of constants are not affected by  DEF type statements such as  DEFINT.
  3792.  A constant's type is determined either by an explicit type-declaration
  3793.  character or by the type of the expression.
  3794.  
  3795.  Constants must be
  3796.  defined before they are referred to. The following example produces an error
  3797.  because the constant ONE is not defined before it is used to define TWO
  3798.  (constants are defined from left to right):
  3799.  
  3800.  CONST TWO = ONE + ONE, ONE = 1
  3801.  
  3802.  
  3803.  Note
  3804.  
  3805.  You cannot use ASCII 01 and 02 in string constants if you are going to
  3806.  compile to an executable program. The compiler (BC.EXE) uses ASCII 01 and 02
  3807.  internally to represent End-of-Statement and End-of-Line, respectively. You
  3808.  can, however, still use 1 and 2 within the QBX environment.
  3809.  
  3810.  
  3811.  Constants declared in a  SUB or  FUNCTION procedure are local to that
  3812.  procedure. A constant declared outside a procedure is defined throughout the
  3813.  module. You can use constants anywhere that you would use an expression.
  3814.  
  3815.  A common programming practice is to use a statement such as the following
  3816.  (any non-zero value represents "true"):
  3817.  
  3818.  TRUE=-1
  3819.  
  3820.  Using constants offers several advantages over using variables for constant
  3821.  values:
  3822.  
  3823.    ■   You only need define constants once for an entire module.
  3824.  
  3825.    ■   Constants cannot be inadvertently changed.
  3826.  
  3827.    ■   In stand-alone programs, using constants produces faster and often
  3828.        smaller code than
  3829.        variables.
  3830.  
  3831.    ■   Constants make programs easier to modify.
  3832.  
  3833.  
  3834.  Example
  3835.  
  3836.  The following example uses the  CONST statement to declare symbolic
  3837.  constants for the ASCII values of nonprinting characters such as tab and
  3838.  line feed. Constants also make programs easier to modify. The program counts
  3839.  words, lines, and characters in a text file. A word is any sequence of
  3840.  nonblank characters.
  3841.  
  3842.  DEFINT a-z
  3843.  CONST BLANK = 32, ENDFILE = 26, CR = 13, LF = 10
  3844.  CONST TABC = 9, YES = -1, NO = 0
  3845.  CLS    ' Clear screen.
  3846.  ' Get the filename from the command line.
  3847.  FileName$=COMMAND$
  3848.  IF FileName$="" THEN
  3849.     INPUT "Enter input filename: ",FileName$
  3850.     IF FileName$="" THEN END
  3851.  END IF
  3852.  
  3853.  OPEN FileName$ FOR INPUT AS #1
  3854.  Words=0
  3855.  Lines=0
  3856.  Characters=0
  3857.  ' Set a flag to indicate you're not looking at a
  3858.  ' word, then get the first character from the file.
  3859.  InaWord=NO
  3860.  DO UNTIL EOF(1)
  3861.     C=ASC(INPUT$(1,#1))
  3862.     Characters=Characters+1
  3863.     IF C=BLANK or C=CR or C=LF or C=TABC THEN
  3864.        ' If the character is a blank, carriage return,
  3865.        ' line feed, or tab, you're not in a word.
  3866.        IF C=CR THEN Lines=Lines+1
  3867.        InaWord=NO
  3868.     ELSEIF InaWord=NO THEN
  3869.        ' The character is a printing character,
  3870.        ' so this is the start of a word.
  3871.        InaWord=YES' Count the word and set the flag.
  3872.        Words=Words+1
  3873.     END IF
  3874.  LOOP
  3875.  PRINT Characters, Words, Lines
  3876.  END
  3877.  
  3878.  
  3879.  
  3880.  
  3881.  COS Function
  3882.  ────────────────────────────────────────────────────────────────────────────
  3883.  
  3884.  
  3885.  Action
  3886.  
  3887.  Returns the cosine of an angle given in radians.
  3888.  
  3889.  
  3890.  Syntax
  3891.  
  3892.   COS( x)
  3893.  
  3894.  
  3895.  Remarks
  3896.  
  3897.  The argument  x can be of any numeric type.
  3898.  
  3899.  The cosine of an angle in a right triangle is the ratio between the length
  3900.  of the side adjacent to the angle and the length of the hypotenuse.
  3901.  
  3902.   COS is calculated in single precision if  x is an integer or
  3903.  single-precision value. If you use any other numeric data type,  COS is
  3904.  calculated in double precision.
  3905.  
  3906.  To convert values from degrees to radians, multiply the angle (in degrees)
  3907.  times π/180
  3908.  (or .0174532925199433). To convert a radian value to degrees, multiply it by
  3909.  180/π (or 57.2957795130824). In both cases, π ≈ 3.141593.
  3910.  
  3911.  
  3912.  See Also
  3913.  
  3914.   ATN,  SIN,  TAN
  3915.  
  3916.  
  3917.  Example
  3918.  
  3919.  The following example plots the graph of the polar equation r = nq for
  3920.  values of n from 0.1-1.1. This program uses the conversion factors x =
  3921.  cos(q) and y = sin(q) to change polar coordinates to Cartesian coordinates.
  3922.  The figure plotted is sometimes known as the Spiral of Archimedes.
  3923.  
  3924.  CONST PI = 3.141593
  3925.  SCREEN 1 : COLOR 7' Gray background.
  3926.  WINDOW (-4,-6)-(8,2) ' Define window large enough for biggest spiral.
  3927.  LINE (0,0)-(2.2 * PI,0),1' Draw line from origin to the right.
  3928.  
  3929.  ' Draw 10 spirals.
  3930.  FOR N = 1.1 TO .1 STEP -.1
  3931.     PSET (0,0)' Plot starting point.
  3932.     FOR Angle = 0 TO 2 * PI STEP .04
  3933.        R = N * Angle' Polar equation for spiral.
  3934.        ' Convert polar coordinates to Cartesian coordinates.
  3935.        X = R * COS(Angle)
  3936.        Y = R * SIN(Angle)
  3937.        LINE -(X,Y),1' Draw line from previous point to new point.
  3938.     NEXT Angle
  3939.  NEXT N
  3940.  
  3941.  
  3942.  
  3943.  
  3944.  CREATEINDEX Statement
  3945.  ────────────────────────────────────────────────────────────────────────────
  3946.  
  3947.  
  3948.  Action
  3949.  
  3950.  Creates an index consisting of one or more columns of an ISAM table.
  3951.  
  3952.  
  3953.  Syntax
  3954.  
  3955.   CREATEINDEX «#»filenumber%, indexname$, unique%, columnname$«,
  3956.  columnname$»...
  3957.  
  3958.  
  3959.  Remarks
  3960.  
  3961.  The  CREATEINDEX statement uses the following arguments:
  3962.  
  3963. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  3964.  Argument                                Description
  3965.  ────────────────────────────────────────────────────────────────────────────
  3966.   filenumber%                            The number used in the  OPEN
  3967.                                          statement to open the table.
  3968.  
  3969.   indexname$                             The  indexname$ is the name of the
  3970.                                          index until the index is
  3971.  Argument                                Description
  3972.  ────────────────────────────────────────────────────────────────────────────
  3973.                                         index until the index is
  3974.                                          explicitly deleted. It follows the
  3975.                                          ISAM naming conventions (details
  3976.                                          are provided later in this entry).
  3977.  
  3978.   unique%                                A non-zero value for  unique%
  3979.                                          indicates the index is
  3980.                                          unique--no two indexed values
  3981.                                          can be the same. A value of zero
  3982.                                          for  unique% means the indexed
  3983.                                          values need not be unique.
  3984.  
  3985.   columnname$                            Names the column or columns to be
  3986.                                          indexed. The name follows the ISAM
  3987.                                          naming conventions. If more than
  3988.                                          one column name is given,
  3989.                                          CREATEINDEX defines an index based
  3990.                                          on the combination of their values.
  3991.                                          The argument  columnname$ must
  3992.  Argument                                Description
  3993.  ────────────────────────────────────────────────────────────────────────────
  3994.                                         The argument  columnname$ must
  3995.                                          appear in the  TYPE statement used
  3996.                                          when the table was created.
  3997.  
  3998.  
  3999.  
  4000.  When you initially open a table, the current index is the null index. The
  4001.  null index  represents the order in which records were added to the file.
  4002.  Once an index has been created, it can be used any number of times until it
  4003.  is deleted from the database.
  4004.  
  4005.  Use  SETINDEX to make an index the current index and impose its order on the
  4006.  presentation of records in a table.
  4007.  
  4008.  
  4009.  Note
  4010.  
  4011.  Columns that are arrays, user-defined types, or strings longer than 255
  4012.  characters cannot be indexed.
  4013.  
  4014.  
  4015.  ISAM names use the following conventions:
  4016.  
  4017.    ■   They have no more than 30 characters.
  4018.  
  4019.    ■   They use only alphanumeric characters (A-Z, a-z, 0-9).
  4020.  
  4021.    ■   They begin with an alphabetic character.
  4022.  
  4023.    ■   They include no BASIC special characters.
  4024.  
  4025.  
  4026.  See Also
  4027.  
  4028.   DELETEINDEX,  GETINDEX$,  SETINDEX
  4029.  
  4030.  
  4031.  Example
  4032.  
  4033.  This example uses the  CREATEINDEX,  SETINDEX and  DELETEINDEX statements to
  4034.  index an ISAM file in several ways. It displays records from the file using
  4035.  the  GETINDEX$ and  BOF functions and the  MOVEFIRST,  MOVELAST,  MOVENEXT,
  4036.  and  MOVEPREVIOUS statements.
  4037.  
  4038.  The program uses a file called BOOKS.MDB, the sample ISAM file that SETUP
  4039.  copies to your disk.
  4040.  
  4041.  DEFINT A-Z
  4042.  TYPE BookRec
  4043.      IDNum AS DOUBLE             ' Unique ID number for each book.
  4044.      Title AS STRING * 50        ' Book's title.
  4045.      Publisher AS STRING * 50    ' Book's publisher.
  4046.      Author AS STRING * 36       ' Book's author.
  4047.      Price AS CURRENCY           ' Book's price.
  4048.  END TYPE
  4049.  
  4050.  DIM Library AS BookRec          ' Record structure variable.
  4051.  DIM msgtxt AS STRING
  4052.  
  4053.  CONST Database = "BOOKS.MDB"    ' Name of the disk file.
  4054.  CONST TableName = "BooksStock"  ' Name of the table.
  4055.  tablenum = FREEFILE             ' File number.
  4056.  
  4057.  OPEN Database FOR ISAM BookRec TableName AS tablenum
  4058.  CREATEINDEX tablenum, "A", 0, "Author"
  4059.  CREATEINDEX tablenum, "I", 1, "IDnum"
  4060.  CREATEINDEX tablenum, "T", 0, "Title"
  4061.  CREATEINDEX tablenum, "C", 0, "Price"
  4062.  
  4063.  ' Display static instructions.
  4064.  CLS : LOCATE 13, 30
  4065.  PRINT "Choose a key:"
  4066.  PRINT SPC(9); "Move to:"; TAB(49); "Order by: X"
  4067.  PRINT : PRINT SPC(9); "F - First record"; TAB(49); "A - Author"
  4068.  PRINT : PRINT SPC(9); "L - Last record"; TAB(49); "I - ID Number"
  4069.  PRINT : PRINT SPC(9); "N - Next record"; TAB(49); "T - Title"
  4070.  PRINT : PRINT SPC(9); "P - Previous record"; TAB(49); "C - Cost"
  4071.  PRINT : PRINT SPC(9); "Q - Quit"; TAB(49); "X - No order"
  4072.  LOCATE 3, 1: PRINT TAB(37); "Books"
  4073.  PRINT STRING$(80, "-");
  4074.  VIEW PRINT 5 TO 10          ' Set viewport for displaying records.age.
  4075.  MOVEFIRST tablenum
  4076.  DO
  4077.      ' Display current record.
  4078.      CLS
  4079.      RETRIEVE tablenum, Library
  4080.      PRINT "Author:    "; Library.Author;
  4081.      PRINT TAB(49); "ID #"; Library.IDNum
  4082.      PRINT "Title:     "; Library.Title
  4083.      PRINT "Publisher: "; Library.Publisher
  4084.      PRINT "Cost:     "; Library.Price
  4085.      PRINT SPC(30); msgtxt
  4086.      PRINT STRING$(64, "-");
  4087.      IF GETINDEX$(tablenum) = "" THEN
  4088.          PRINT STRING$(15, "-");
  4089.      ELSE
  4090.          PRINT "Index in use: "; GETINDEX$(tablenum);
  4091.      END IF
  4092.  
  4093.      ' Get keystroke from user.
  4094.      validkeys$ = "FLNPQATICX"
  4095.      DO
  4096.          Keychoice$ = UCASE$(INKEY$)
  4097.      LOOP WHILE INSTR(validkeys$, Keychoice$) = 0 OR Keychoice$ = ""
  4098.      msgtxt = ""
  4099.  
  4100.      ' Move to appropriate record, or change indexes.
  4101.      SELECT CASE Keychoice$
  4102.      CASE "F"
  4103.          MOVEFIRST tablenum
  4104.      CASE "L"
  4105.          MOVELAST tablenum
  4106.      CASE "N"
  4107.          MOVENEXT tablenum
  4108.          IF EOF(tablenum) THEN
  4109.              MOVELAST tablenum
  4110.              BEEP: msgtxt = "** At last record **"
  4111.          END IF
  4112.      CASE "P"
  4113.          MOVEPREVIOUS tablenum
  4114.          IF BOF(tablenum) THEN
  4115.              MOVEFIRST tablenum
  4116.              BEEP: msgtxt = "** At first record **"
  4117.          END IF
  4118.      CASE "Q"
  4119.          EXIT DO
  4120.      CASE ELSE           'User chose an index.
  4121.          VIEW PRINT
  4122.          LOCATE 13, 59: PRINT Keychoice$;
  4123.          VIEW PRINT 5 TO 10
  4124.          IF Keychoice$ = "X" THEN Keychoice$ = ""
  4125.          SETINDEX tablenum, Keychoice$
  4126.          MOVEFIRST tablenum
  4127.      END SELECT
  4128.  LOOP
  4129.  
  4130.  ' User wants to quit, so reset viewport, delete indexes and close files.
  4131.  VIEW PRINT
  4132.  DELETEINDEX tablenum, "A"
  4133.  DELETEINDEX tablenum, "I"
  4134.  DELETEINDEX tablenum, "T"
  4135.  DELETEINDEX tablenum, "C"
  4136.  CLOSE
  4137.  END
  4138.  
  4139.  
  4140.  
  4141.  
  4142.  CSNG Function
  4143.  ────────────────────────────────────────────────────────────────────────────
  4144.  
  4145.  
  4146.  Action
  4147.  
  4148.  Converts a numeric expression to a single-precision value.
  4149.  
  4150.  
  4151.  Syntax
  4152.  
  4153.   CSNG( numeric-expression)
  4154.  
  4155.  
  4156.  Remarks
  4157.  
  4158.  The  CSNG function has the same effect as assigning  numeric-expression to a
  4159.  single-precision variable.
  4160.  
  4161.   CSNG rounds the value, if necessary, before converting it.
  4162.  
  4163.  
  4164.  See Also
  4165.  
  4166.   CCUR,  CDBL,  CINT,  CLNG
  4167.  
  4168.  
  4169.  Example
  4170.  
  4171.  The following example shows how  CSNG rounds before converting the value:
  4172.  
  4173.  A#=975.3421115#
  4174.  B#=975.3421555#
  4175.  PRINT A#; CSNG(A#); B#; CSNG(B#)
  4176.  
  4177.  
  4178.  Output
  4179.  
  4180.  975.3421115  975.3421  975.3421555  975.3422
  4181.  
  4182.  
  4183.  
  4184.  
  4185.  CSRLIN Function
  4186.  ────────────────────────────────────────────────────────────────────────────
  4187.  
  4188.  
  4189.  Action
  4190.  
  4191.  Returns the current line (row) position of the cursor.
  4192.  
  4193.  
  4194.  Syntax
  4195.  
  4196.   CSRLIN
  4197.  
  4198.  
  4199.  Remarks
  4200.  
  4201.  To return the current column position, use the  POS function.
  4202.  
  4203.  
  4204.  See Also
  4205.  
  4206.   LOCATE,  POS
  4207.  
  4208.  
  4209.  Example
  4210.  
  4211.  The following example uses a  SUB procedure that prints a message on the
  4212.  screen without disturbing the current cursor position:
  4213.  
  4214.  ' Move cursor to center of screen, then print message.
  4215.  ' Cursor returned to center of screen.
  4216.  LOCATE 12,40
  4217.  CALL MsgNoMove("A message not to be missed.",9,35)
  4218.  INPUT "Enter anything to end: ",A$
  4219.  
  4220.  ' Print a message without disturbing current cursor position.
  4221.  SUB MsgNoMove (Msg$,Row%,Col%) STATIC
  4222.     CurRow%=CSRLIN ' Save the current line.
  4223.     CurCol%=POS(0) ' Save the current column.
  4224.     ' Print the message at the given position.
  4225.     LOCATE Row%,Col% : PRINT Msg$;
  4226.     ' Move the cursor back to original position.
  4227.     LOCATE CurRow%, CurCol%
  4228.  END SUB
  4229.  
  4230.  
  4231.  
  4232.  
  4233.  CURDIR$ Function
  4234.  ────────────────────────────────────────────────────────────────────────────
  4235.  
  4236.  
  4237.  Action
  4238.  
  4239.  Returns the path currently in use for the specified drive.
  4240.  
  4241.  
  4242.  Syntax
  4243.  
  4244.   CURDIR$«( drive$)»
  4245.  
  4246.  
  4247.  Remarks
  4248.  
  4249.  The argument  drive$ is a string expression that specifies a drive.
  4250.  
  4251.  The argument  drive$ must be in the range A to  lastdrive, where  lastdrive
  4252.  is  the maximum drive letter you set in your CONFIG.SYS file.
  4253.  
  4254.  If no drive is specified or if  drive$ is a null string,  CURDIR$ returns
  4255.  the path for the currently selected drive. This is similar to using the
  4256.  CHDIR command at the system prompt without specifying a path.
  4257.  
  4258.  BASIC generates an error if the first character in  drive$ lies outside the
  4259.  range A to  lastdrive, unless you are working in a networked environment.
  4260.  BASIC also generates an error if the first character in  drive$ corresponds
  4261.  to a drive that does not exist, or if the first character of  drive$ is not
  4262.  a letter.
  4263.  
  4264.   CURDIR$ is not case sensitive. "C" is the same as "c."
  4265.  
  4266.  
  4267.  See Also
  4268.  
  4269.   CHDIR,  CHDRIVE,  DIR$
  4270.  
  4271.  
  4272.  Example
  4273.  
  4274.  See the example for the  CHDRIVE statement, which uses the  CURDIR$
  4275.  function.
  4276.  
  4277.  
  4278.  
  4279.  
  4280.  CVI, CVL, CVS, CVD, and CVC Functions
  4281.  ────────────────────────────────────────────────────────────────────────────
  4282.  
  4283.  
  4284.  Action
  4285.  
  4286.  Converts strings containing numeric values to numbers.
  4287.  
  4288.  
  4289.  Syntax
  4290.  
  4291.   CVI( 2-byte-string)
  4292.  
  4293.   CVL( 4-byte-string)
  4294.  
  4295.   CVS( 4-byte-string)
  4296.  
  4297.   CVD( 8-byte-string)
  4298.  
  4299.   CVC( 8-byte-string)
  4300.  
  4301.  
  4302.  Remarks
  4303.  
  4304.   CVI,  CVL,  CVS,  CVD, and  CVC are used with a  FIELD statement to read
  4305.  numbers from a random-access file. These functions take strings defined in
  4306.  the  FIELD statement and convert them to a value of the corresponding
  4307.  numeric type. The functions are the inverse of  MKI$,  MKL$,  MKS$,  MKD$,
  4308.  and  MKC$.
  4309.  
  4310.  The following table describes these string conversion functions:
  4311.  
  4312. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  4313.  Function                                Description
  4314.  ────────────────────────────────────────────────────────────────────────────
  4315.   CVSMBF                                 Converts  4-byte-string containing
  4316.                                          a Microsoft-Binary-format number
  4317.                                          to a single-precision IEEE-format
  4318.                                          number.
  4319.  
  4320.   CVDMBF                                 Converts  8-byte-string containing
  4321.                                          a Microsoft-Binary-format number
  4322.                                          to a double-precision IEEE-format
  4323.                                          number.
  4324.  
  4325.  
  4326.  
  4327.  
  4328.  
  4329.  DATA Statement
  4330.  ────────────────────────────────────────────────────────────────────────────
  4331.  
  4332.  
  4333.  Action
  4334.  
  4335.  Stores the numeric and string constants used by a program's  READ
  4336.  statements.
  4337.  
  4338.  
  4339.  Syntax
  4340.  
  4341.   DATA  constant«,  constant»...
  4342.  
  4343.  
  4344.  Remarks
  4345.  
  4346.  The  constant arguments can be any valid numeric or string constant.
  4347.  
  4348.  
  4349.  Note
  4350.  
  4351.  You cannot use ASCII 01 and 02 in data strings if you are going to compile
  4352.  to an executable program. The compiler (BC.EXE) uses ASCII 01 and 02
  4353.  internally to represent End-of-Statement and End-of-Line respectively. You
  4354.  can, however, still use 1 and 2 within the QBX environment.
  4355.  
  4356.  
  4357.  Names of symbolic constants (defined in a  CONST statement) that appear in
  4358.  DATA statements are interpreted as strings, rather than as names of
  4359.  constants. For example, in the following program fragment, the second data
  4360.  item is a string, PI, and not the value 3.141593:
  4361.  
  4362.  CONST PI=3.141593
  4363.  .
  4364.  .
  4365.  .
  4366.  DATA 2.20, PI,45,7
  4367.  .
  4368.  .
  4369.  .
  4370.  
  4371.  A  DATA statement can contain as many constants as will fit on a line. The
  4372.  constants are separated by commas. You can use any number of  DATA
  4373.  statements.
  4374.  
  4375.  
  4376.  Note
  4377.  
  4378.  If a string constant contains commas, colons, or leading or trailing spaces,
  4379.  enclose the string in double quotation marks.
  4380.  
  4381.  
  4382.  Null data items (indicated by a missing value) can appear in a data list as
  4383.  shown below:
  4384.  
  4385.  DATA 1,2,,4,5
  4386.  
  4387.  When a null item is read into a numeric variable, the variable has the value
  4388.  0. When a null item is read into a string variable, the variable has the
  4389.  null string value ("").
  4390.  
  4391.  When working in the QBX environment,  DATA statements can be entered only in
  4392.  the module-level code. BASIC moves all  DATA statements not in the
  4393.  module-level code to the module-level code when it reads a source file.
  4394.  READ statements can appear anywhere in the program.
  4395.  
  4396.   DATA statements are used in the order in which they appear in the source
  4397.  file. You may think of the items in several  DATA statements as one
  4398.  continuous list of items, regardless of how many items are in a statement or
  4399.  where the statement appears in the program.
  4400.  
  4401.  You can reread  DATA statements by using the  RESTORE statement.
  4402.  
  4403.   REM statements that appear at the end of  DATA statements must be preceded
  4404.  by a colon. Without a colon, BASIC interprets trailing  REM statements as
  4405.  string data.
  4406.  
  4407.  
  4408.  See Also
  4409.  
  4410.   READ,  RESTORE
  4411.  
  4412.  
  4413.  Examples
  4414.  
  4415.  The first example displays the current date by converting the date returned
  4416.  by the  DATE$ function:
  4417.  
  4418.  ' Use VAL to find the month from the string returned by DATE$.
  4419.  C$ = DATE$
  4420.  FOR I% = 1 TO VAL(C$)
  4421.      READ Month$
  4422.  NEXT
  4423.  DATA January, February, March, April, May, June, July
  4424.  DATA August, September, October, November, December
  4425.  
  4426.  ' Get the day.
  4427.  Day$ = MID$(C$, 4, 2)
  4428.  IF LEFT$(Day$, 1) = "0" THEN Day$ = RIGHT$(Day$, 1)
  4429.  ' Get the year.
  4430.  Year$ = RIGHT$(C$, 4)
  4431.  
  4432.  PRINT "Today is "; Month$; " "; Day$; ", "; Year$
  4433.  
  4434.  
  4435.  
  4436.  Output
  4437.  
  4438.  Today is September 21, 1989
  4439.  
  4440.  The following example shows how null data items are handled:
  4441.  
  4442.  DATA abc,,def
  4443.  DATA 1,,2
  4444.  READ A$, B$, C$       ' B$ = ""
  4445.  PRINT A$, B$, C$
  4446.  PRINT
  4447.  READ A, B, C          ' B = 0
  4448.  PRINT A, B, C
  4449.  
  4450.  
  4451.  Output
  4452.  
  4453.  abc                     def
  4454.  1           0           2
  4455.  
  4456.  
  4457.  
  4458.  
  4459.  DATE$ Function
  4460.  ────────────────────────────────────────────────────────────────────────────
  4461.  
  4462.  
  4463.  Action
  4464.  
  4465.  Returns a string containing the current date.
  4466.  
  4467.  
  4468.  Syntax
  4469.  
  4470.   DATE$
  4471.  
  4472.  
  4473.  Remarks
  4474.  
  4475.  The  DATE$ function returns a 10-character string in the form  mm-dd-yyyy,
  4476.  where  mm is the month (01-12),  dd is the day (01-31), and
  4477.  yyyy is the year (1980-2099).
  4478.  
  4479.  
  4480.  See Also
  4481.  
  4482.   DATE$ Statement
  4483.  
  4484.  
  4485.  Example
  4486.  
  4487.  Note that the  DATE$ function in the following example prints a zero in
  4488.  front of the month:
  4489.  
  4490.  PRINT DATE$
  4491.  
  4492.  
  4493.  
  4494.  Output
  4495.  
  4496.  04-21-1989
  4497.  
  4498.  
  4499.  
  4500.  
  4501.  DATE$ Statement
  4502.  ────────────────────────────────────────────────────────────────────────────
  4503.  
  4504.  
  4505.  Action
  4506.  
  4507.  Sets the current date in your computer's system.
  4508.  
  4509.  
  4510.  Syntax
  4511.  
  4512.   DATE$ =  stringexpression$
  4513.  
  4514.  
  4515.  Remarks
  4516.  
  4517.  The  DATE$ statement is the complement of the  DATE$ function.
  4518.  
  4519.  If you use the  DATE$ statement to set the date, the change remains in
  4520.  effect until you change it again or reboot your computer.
  4521.  
  4522.  The  stringexpression$ must have one of the following forms, where  mm
  4523.  (01-12) and  dd (01-31) are the month and day, and  yy or  yyyy
  4524.  (1980-2099) is the year:
  4525.  
  4526.   mm-dd-yy
  4527.  mm-dd-yyyy
  4528.  mm/dd/yy
  4529.  mm/dd/yyyy
  4530.  
  4531.  
  4532.  See Also
  4533.  
  4534.   DATE$ Function , TIME$ Statement
  4535.  
  4536.  
  4537.  Example
  4538.  
  4539.  The following example prompts you to supply the month, date, and year, then
  4540.  resets the system date on your computer. Note that if you change the system
  4541.  date, any files you create or revise will be stamped with the new date.
  4542.  
  4543.  PRINT "Enter the date below (default year is 1989)."
  4544.  INPUT "    Month:   ",Month$
  4545.  INPUT "    Date:    ",Day$
  4546.  INPUT "    Year:    ",Year$
  4547.  IF Year$ = "" THEN Year$ = "89"
  4548.  DATE$ = Month$ + "/" + Day$ + "/" + Year$
  4549.  
  4550.  
  4551.  
  4552.  
  4553.  DECLARE Statement (BASIC Procedures)
  4554.  ────────────────────────────────────────────────────────────────────────────
  4555.  
  4556.  
  4557.  Action
  4558.  
  4559.  Declares references to BASIC procedures and invokes argument type checking.
  4560.  
  4561.  
  4562.  Syntax
  4563.  
  4564.   DECLARE { FUNCTION |  SUB}  name «(« parameterlist»)»
  4565.  
  4566.  
  4567.  Remarks
  4568.  
  4569.  The  DECLARE statement uses the following arguments:
  4570.  
  4571. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  4572.  Argument                                Description
  4573.  ────────────────────────────────────────────────────────────────────────────
  4574.   name                                   The name that will be used to
  4575.                                          invoke the procedure. The argument
  4576.                                           name is limited to 40 characters.
  4577.                                           FUNCTION procedure names can end
  4578.                                          in one of the type-declaration
  4579.                                          characters ( %,  &,  !,  #,  @, %
  4580.  Argument                                Description
  4581.  ────────────────────────────────────────────────────────────────────────────
  4582.                                         characters ( %,  &,  !,  #,  @, %
  4583.                                          or  $) to indicate the type
  4584.                                          of value returned.
  4585.  
  4586.   parameterlist                          A list of parameters that
  4587.                                          indicates the number and type of
  4588.                                          arguments to be used to call the
  4589.                                          procedure. Syntax is shown below.
  4590.                                          Only the number and type of the
  4591.                                          arguments are significant.
  4592.  
  4593.  
  4594.  
  4595.  For calls within BASIC, the  DECLARE statement is required only if you call
  4596.  SUB procedures without the  CALL keyword, or if you invoke a  FUNCTION
  4597.  procedure defined in another module. For more information about invoking
  4598.  procedures without the  CALL keyword,  see Chapter 2, "SUB and FUNCTION
  4599.  Procedures" in the  Programmer's Guide.
  4600.  
  4601.  A  DECLARE statement also causes the compiler to check the number and type
  4602.  of arguments used to invoke the procedure. QBX automatically generates
  4603.  DECLARE statements when you save your program while working in the
  4604.  environment. The  DECLARE statement can appear only in module-level code
  4605.  (not in a  SUB or  FUNCTION procedure) and affects the entire module.
  4606.  
  4607.  The  parameterlist serves as a prototype for checking the number and type of
  4608.  the arguments in  SUB and  FUNCTION procedure calls. It has the following
  4609.  syntax:
  4610.  
  4611.   variable«AS type»«, variable «AS type»»...
  4612.  
  4613.  The argument  variable is any
  4614.  valid BASIC variable name. If the variable is an array, it can be followed
  4615.  by the number of dimensions in parentheses, as in this fragment:
  4616.  
  4617.  DECLARE SUB DisplayText (A(2) AS STRING)
  4618.  DIM Text$(100,5)
  4619.  .
  4620.  .
  4621.  .
  4622.  CALL DisplayText(Text$())
  4623.  
  4624.  The number of dimensions is optional.
  4625.  
  4626.  The  type is either  INTEGER,  LONG,  SINGLE,  DOUBLE,  CURRENCY,  STRING,
  4627.  or a user-defined type. Again, only the number and types of arguments are
  4628.  significant.
  4629.  
  4630.  
  4631.  Note
  4632.  
  4633.  You cannot have fixed-length strings in  DECLARE statements, because only
  4634.  variable-length strings can be passed to  SUB and  FUNCTION procedures.
  4635.  Fixed-length strings can appear in an argument list but are converted to
  4636.  variable-length strings before being passed.
  4637.  
  4638.  
  4639.  A variable's type also can be indicated by including an explicit type
  4640.  character ( %,  &,  !,  #,  @, or  $) or by relying on the default type.
  4641.  
  4642.  The form of the parameter list determines whether or not argument checking
  4643.  is done, as shown in the following list:
  4644.  
  4645.  DECLARE SUB First
  4646.  
  4647.  You can omit the parentheses only if the  SUB or  FUNCTION procedure is
  4648.  separately compiled. No argument checking is done.
  4649.  
  4650.  DECLARE SUB First ()
  4651.  
  4652.  First has no parameters. If you use arguments in a call to First, BASIC
  4653.  generates an error. An empty parameter list indicates that the  SUB or
  4654.  FUNCTION procedure has no parameters and that argument checking should be
  4655.  done.
  4656.  
  4657.  DECLARE SUB First (X AS LONG)
  4658.  
  4659.  First has one long-integer parameter. The number and type of the arguments
  4660.  in each call or invocation are checked when the parameter list appears in
  4661.  the  DECLARE statement.
  4662.  
  4663.  DECLARE also can be used to declare references to
  4664.  procedures written in other programming languages, such as C. See the entry
  4665.  for the  DECLARE statement (Non-BASIC).
  4666.  
  4667.  
  4668.  See Also
  4669.  
  4670.   CALL (BASIC),  DECLARE (Non-BASIC),  FUNCTION,  SUB
  4671.  
  4672.  
  4673.  Example
  4674.  
  4675.  
  4676.  In this program, use of the  DECLARE statement allows a  SUB procedure to be
  4677.  invoked without using the  CALL keyword:
  4678.  
  4679.  ' Generate 20 random numbers, store them in an array, and sort.
  4680.  DECLARE SUB Sort (A() AS INTEGER, N AS INTEGER)
  4681.  DIM Array1(1 TO 20) AS INTEGER
  4682.  DIM I AS INTEGER
  4683.  ' Generate 20 random numbers.
  4684.  RANDOMIZE TIMER
  4685.  
  4686.  CLS
  4687.  FOR I% = 1 TO 20
  4688.     Array1(I%) = INT(RND * 100)
  4689.  NEXT I%
  4690.  
  4691.  ' Sort the array, calling Sort without the CALL keyword.
  4692.  ' Notice the absence of parentheses around the arguments in
  4693.  ' the call to Sort.
  4694.  Sort Array1(), 20
  4695.  
  4696.  ' Print the sorted array.
  4697.  FOR I% = 1 TO 20
  4698.     PRINT Array1(I%)
  4699.  NEXT I%
  4700.  END
  4701.  
  4702.  ' Sort subroutine.
  4703.  SUB Sort (A%(), N%)
  4704.     FOR I% = 1 TO N% - 1
  4705.        FOR J% = I% + 1 TO N%
  4706.           IF A%(I%) > A%(J%) THEN SWAP A%(I%), A%(J%)
  4707.        NEXT J%
  4708.     NEXT I%
  4709.  END SUB
  4710.  
  4711.  
  4712.  
  4713.  
  4714.  DECLARE Statement (Non-BASIC Procedures)
  4715.  ────────────────────────────────────────────────────────────────────────────
  4716.  
  4717.  
  4718.  Action
  4719.  
  4720.  Declares calling sequences for external procedures written in other
  4721.  languages.
  4722.  
  4723.  
  4724.  Syntax
  4725.  
  4726.   DECLARE FUNCTION name «CDECL» «ALIAS "aliasname"» «(«parameterlist»)»
  4727.  
  4728.   DECLARE SUB name «CDECL» «ALIAS "aliasname"» «(«parameterlist»)»
  4729.  
  4730.  
  4731.  Remarks
  4732.  
  4733.  The following list describes the parts of the  DECLARE statement:
  4734.  
  4735. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  4736.  Part                                    Description
  4737.  ────────────────────────────────────────────────────────────────────────────
  4738.   FUNCTION                               Indicates that the external
  4739.                                          procedure returns a value and can
  4740.                                          be used in an expression.
  4741.  
  4742.   SUB                                    Indicates that the external
  4743.                                          procedure is invoked in the same
  4744.                                          way as a BASIC  SUB procedure.
  4745.  
  4746.   name                                   The name used in the BASIC program
  4747.                                          to invoke the procedure. Names can
  4748.  Part                                    Description
  4749.  ────────────────────────────────────────────────────────────────────────────
  4750.                                         to invoke the procedure. Names can
  4751.                                          have up to 40 characters.
  4752.                                          FUNCTION procedure names can
  4753.                                          include an explicit type character
  4754.                                          ( %,  &,  !,  #,  @, or  $)
  4755.                                          indicating the type of value the
  4756.                                          procedure returns.
  4757.  
  4758.   CDECL                                  Indicates that the procedure uses
  4759.                                          the C-language argument order and
  4760.                                          naming conventions.  CDECL passes
  4761.                                          the arguments from right to left,
  4762.                                          rather than using the BASIC
  4763.                                          convention of left to right.,
  4764.  
  4765.                                           CDECL also affects the name used
  4766.                                          in searches of object files and
  4767.                                          libraries. If there is no  ALIAS
  4768.                                          clause in the  DECLARE statement,
  4769.  Part                                    Description
  4770.  ────────────────────────────────────────────────────────────────────────────
  4771.                                         clause in the  DECLARE statement,
  4772.                                          the type-declaration character is
  4773.                                          removed from the name of the
  4774.                                          procedure, and an underscore is
  4775.                                          added to the beginning. This
  4776.                                          becomes the name used when
  4777.                                          searching libraries and external
  4778.                                          files. If  CDECL is used with
  4779.                                          ALIAS,  aliasname is used as is.
  4780.  
  4781.   ALIAS                                  Indicates that the procedure being
  4782.                                          called has another name in the
  4783.                                          .OBJ or library file..
  4784.  
  4785.   aliasname                              The name the procedure has in the
  4786.                                          file or library.
  4787.  
  4788.   parameterlist                          The parameters to be passed to the
  4789.                                          invoked procedure.
  4790.  Part                                    Description
  4791.  ────────────────────────────────────────────────────────────────────────────
  4792.                                         invoked procedure.
  4793.  
  4794.  
  4795.  
  4796.  The argument parameterlist has the following syntax:
  4797.  
  4798.  «{BYVAL|SEG}» variable «AS type» «, «{BYVAL|SEG}» variable «AS type»»...
  4799.  
  4800.  
  4801.  The following list describes the parts of  parameterlist:
  4802.  
  4803. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  4804.  Part                                    Description
  4805.  ────────────────────────────────────────────────────────────────────────────
  4806.   BYVAL                                  Indicates the parameter is passed
  4807.                                          by value, not reference. Reference
  4808.                                          is the default.  BYVAL can be used
  4809.                                          only with  INTEGER,  LONG,  SINGLE,
  4810.                                           DOUBLE, and  CURRENCY types.
  4811.  Part                                    Description
  4812.  ────────────────────────────────────────────────────────────────────────────
  4813.                                          DOUBLE, and  CURRENCY types.
  4814.  
  4815.                                          When  BYVAL appears in front of a
  4816.                                          parameter, the actual argument is
  4817.                                          converted to the type indicated in
  4818.                                          the  DECLARE statement before
  4819.                                          being passed.
  4820.  
  4821.   SEG                                    Indicates the parameter is passed
  4822.                                          as a segmented address (far
  4823.                                          address).
  4824.  
  4825.   variable                               A valid BASIC variable name. Only
  4826.                                          the variable's type is significant.
  4827.                                          If the variable is an array, it
  4828.                                          can be followed by the number of
  4829.                                          dimensions in parentheses (to
  4830.                                          maintain compatibility with older
  4831.                                          versions of BASIC). For example:
  4832.  Part                                    Description
  4833.  ────────────────────────────────────────────────────────────────────────────
  4834.                                         versions of BASIC). For example:
  4835.  
  4836.                                          DECLARE SUB EigenValue (A(2) AS
  4837.                                          DOUBLE)
  4838.  
  4839.   AS type                                Indicates the variable's type. The
  4840.                                          argument  type can be  INTEGER,
  4841.                                          LONG,  SINGLE,  DOUBLE,  STRING,
  4842.                                          CURRENCY,  ANY, or a user-defined
  4843.                                          type. You also can indicate the
  4844.                                          variable's type by including an
  4845.                                          explicit type character ( %,  &,
  4846.                                          !,  #,  @, or  $) in the
  4847.                                          variable name or by relying on the
  4848.                                          default type.
  4849.  
  4850.                                          When declaring external procedures
  4851.                                          written in other languages, you
  4852.                                          can use the  ANY keyword in the
  4853.  Part                                    Description
  4854.  ────────────────────────────────────────────────────────────────────────────
  4855.                                         can use the  ANY keyword in the
  4856.                                          AS clause.  ANY overrides type
  4857.                                          checking for that argument. You
  4858.                                          cannot use  ANY with arguments
  4859.                                          passed by value.
  4860.  
  4861.  
  4862.  
  4863.  
  4864.  When neither  BYVAL nor  SEG is used, arguments are passed as near addresses
  4865.  (offsets).
  4866.  
  4867.  This form of the  DECLARE statement lets you refer to procedures written in
  4868.  other languages. The  DECLARE statement also causes the compiler to check
  4869.  the number and type of arguments used to invoke the procedure. A  DECLARE
  4870.  statement can appear only in module-level code and affects the entire source
  4871.  file.
  4872.  
  4873.  The form of the parameter list determines whether or not argument type
  4874.  checking is done, as described in the following declarations:
  4875.  
  4876. ╓┌─────────────────────────────────────┌─────────────────────────────────────╖
  4877.  Declaration                           Meaning
  4878.  ────────────────────────────────────────────────────────────────────────────
  4879.  DECLARE SUB First CDECL               No argument checking is done when
  4880.                                        there is no parameter list.
  4881.  
  4882.  DECLARE SUB First CDECL ()            First has no parameters. If you use
  4883.                                        arguments in a call to First, BASIC
  4884.                                        generates an error. Empty
  4885.                                        parentheses indicate that the  SUB
  4886.                                        or  FUNCTION procedure has no
  4887.                                        parameters and that argument
  4888.                                        checking should be done.
  4889.  
  4890.  DECLARE SUB First CDECL (X AS LONG)   First takes one long-integer
  4891.                                        argument. When a parameter list
  4892.                                        appears, the number and type of
  4893.                                        arguments are checked each
  4894.                                        invocation.
  4895.  Declaration                           Meaning
  4896.  ────────────────────────────────────────────────────────────────────────────
  4897.                                       invocation.
  4898.  
  4899.  
  4900.  
  4901.  A procedure in a  DECLARE statement can be invoked without the  CALL
  4902.  keyword.
  4903.  
  4904.  
  4905.  Note
  4906.  
  4907.  You cannot have fixed-length strings in  DECLARE statements because only
  4908.  variable-length strings can be passed to  SUB and  FUNCTION procedures.
  4909.  Fixed-length strings can appear in an argument list but are converted to
  4910.  variable-length strings before being passed.
  4911.  
  4912.  
  4913.  Be careful when using the  SEG keyword to pass arrays, because BASIC may
  4914.  move variables in memory before the called routine begins execution.
  4915.  Anything in a  CALL statement's argument list that causes memory movement
  4916.  may create problems. You can safely pass variables using  SEG if the  CALL
  4917.  statement's argument list contains only simple variables, arithmetic
  4918.  expressions, or arrays indexed without the use of intrinsic or user-defined
  4919.  functions.
  4920.  
  4921.  
  4922.  See Also
  4923.  
  4924.   CALL,  CALLS Statements  (Non-BASIC);  DECLARE (BASIC)
  4925.  
  4926.  
  4927.  Example
  4928.  
  4929.  The following example shows a BASIC program that calls a short C function.
  4930.  The C program is compiled separately and stored in a Quick library or
  4931.  explicitly linked to form the .EXE file.
  4932.  
  4933.  DEFINT A-Z
  4934.  DECLARE FUNCTION addone CDECL (BYVAL n AS INTEGER)
  4935.  INPUT x
  4936.  y = addone(x)
  4937.  PRINT "x and y are "; x; y
  4938.  END
  4939.  
  4940.  
  4941.  The following function uses C argument passing and takes a single integer
  4942.  argument passed by value.
  4943.  
  4944.  /* C function addone. Returns one more than its integer argument. */
  4945.  int far addone(int n)
  4946.  {
  4947.     return(n+1);
  4948.  }
  4949.  
  4950.  
  4951.  
  4952.  
  4953.  DEF FN Statement
  4954.  ────────────────────────────────────────────────────────────────────────────
  4955.  
  4956.  
  4957.  Action
  4958.  
  4959.  Defines and names a function.
  4960.  
  4961.  
  4962.  Syntax 1
  4963.  
  4964.   DEF FNname«(parameterlist)» = expression
  4965.  
  4966.  
  4967.  Syntax 2
  4968.  
  4969.   DEF FNname«(parameterlist)»
  4970.      « statementblock»
  4971.       FNname =  expression
  4972.      « statementblock»
  4973.      « EXIT DEF»
  4974.      « statementblock»
  4975.   END DEF
  4976.  
  4977.  
  4978.  Remarks
  4979.  
  4980.  The  DEF FN statement uses the following arguments:
  4981.  
  4982. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  4983.  Argument                                Description
  4984.  ────────────────────────────────────────────────────────────────────────────
  4985.   name                                   A legal variable name, which is
  4986.                                          always prefixed with  FN (for
  4987.                                          example: FNShort). The name
  4988.                                          (including the  FN prefix) can be
  4989.                                          up to 40 characters long and can
  4990.                                          include an explicit
  4991.                                          type-declaration character to
  4992.                                          indicate the type of value
  4993.                                          returned. Names that are the same
  4994.                                          except for the type-declaration
  4995.                                          character are distinct names. For
  4996.                                          example, the following are names
  4997.                                          of three different  DEF FN
  4998.                                          functions:
  4999.  
  5000.  Argument                                Description
  5001.  ────────────────────────────────────────────────────────────────────────────
  5002. 
  5003.                                          FNString$
  5004.                                          FNString%
  5005.                                          FNString#
  5006.  
  5007.                                          To return a value from a function
  5008.                                          defined by  DEF FN, assign the
  5009.                                          value to the full function name:
  5010.  
  5011.                                          FNString$ = "No answer."
  5012.  
  5013.   parameterlist                          A list of variable names,
  5014.                                          separated by commas. The syntax is
  5015.                                          explained below. When the function
  5016.                                          is called, BASIC assigns the value
  5017.                                          of each argument to its
  5018.                                          corresponding parameter. Function
  5019.                                          arguments are passed by value.
  5020.                                          Functions defined by  DEF FN do
  5021.  Argument                                Description
  5022.  ────────────────────────────────────────────────────────────────────────────
  5023.                                         Functions defined by  DEF FN do
  5024.                                          not accept arrays, records, or
  5025.                                          fixed-length strings as arguments.
  5026.  
  5027.   expression                             In both versions of syntax,
  5028.                                          expression is evaluated and the
  5029.                                          result is the function's value. In
  5030.                                          Syntax 1,  expression is the
  5031.                                          entire body of the function and is
  5032.                                          limited to one logical line.
  5033.  
  5034.                                          When no expression is assigned to
  5035.                                          the name, the default return
  5036.                                          values are 0 for a numeric  DEF
  5037.                                          FN function, and the null string
  5038.                                          ("") for a string  DEF FN function.
  5039.  
  5040.  
  5041.  
  5042.  The argument  parameterlist has the following syntax:
  5043.  
  5044.   variable « AS  type» «,  variable « AS  type»»...
  5045.  
  5046. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  5047.  Argument                                Description
  5048.  ────────────────────────────────────────────────────────────────────────────
  5049.   variable                               Any valid BASIC variable name.
  5050.  
  5051.   AS  type                               The argument  type is  INTEGER,
  5052.                                          LONG,  SINGLE,  DOUBLE,  CURRENCY,
  5053.                                          or  STRING. You also can indicate
  5054.                                          a variable's type by including a
  5055.                                          type-declaration character ( %,  &,
  5056.                                           !,  #,  @, or  $) in the
  5057.                                          name.
  5058.  
  5059.  
  5060.  
  5061.  
  5062.  Note
  5063.  
  5064.  The  FUNCTION procedure offers greater flexibility and control than the  DEF
  5065.  FN statement. For more information, see the  FUNCTION entry in this book and
  5066.  Chapter 2, "SUB and FUNCTION Procedures" in the  Programmer's Guide.
  5067.  
  5068.  
  5069.   DEF FN must define a function before the function is used. If you call a
  5070.  DEF FN function before it is defined, BASIC generates the error message
  5071.  Function not defined.  DEF FN function definitions cannot appear inside
  5072.  other  DEF FN definitions. In addition, functions defined by  DEF  FN cannot
  5073.  be recursive.
  5074.  
  5075.  
  5076.  The  EXIT DEF statement causes an immediate exit from the executing  DEF FN
  5077.  function. Program execution continues where the  DEF FN function was
  5078.  invoked.
  5079.  
  5080.   DEF FN functions can be used only in the module in which they are defined.
  5081.  
  5082.  A function defined by  DEF FN can share variables with the module-level
  5083.  code. Variables not in  parameterlist are global--their values are
  5084.  shared with the module-level code. To keep a variable value local to a
  5085.  function definition, declare it in a  STATIC statement.
  5086.  
  5087.   DEF FN can return either numeric or string values.  DEF FN returns a string
  5088.  value if  name is a string-variable name, and a numeric value if  name is a
  5089.  numeric-variable name. If you assign a numeric value to a string function
  5090.  name or assign a string value to a numeric function name, BASIC generates
  5091.  the error message Type mismatch.
  5092.  
  5093.  If the function is numeric,  DEF FN name returns a value with the precision
  5094.  specified by  name. For example, if  name specifies a double-precision
  5095.  variable, then the value returned by  DEF FN name is double precision,
  5096.  regardless of the precision of  expression.
  5097.  
  5098.  
  5099.  Because BASIC may
  5100.  rearrange arithmetic expressions for greater efficiency, avoid using
  5101.  functions defined by  DEF FN that change program variables in expressions
  5102.  that may be reordered. The following example may give unpredictable results:
  5103.  
  5104.  DEF FNShort
  5105.  I=10
  5106.  FNShort=1
  5107.  END DEF
  5108.  I=1 : PRINT FNShort + I + I
  5109.  
  5110.  If BASIC reorders the expression so FNShort is called after calculating
  5111.  (I+I) , the result is 3 rather than 21. You usually can avoid this problem
  5112.  by isolating the  DEF FN function call:
  5113.  
  5114.  I = 1 : X = FNShort : PRINT X + I + I
  5115.  
  5116.  Embedding I/O operations in  DEF FN-defined  functions used in I/O
  5117.  statements, or embedding graphics operations in  DEF FN-defined functions in
  5118.  graphics statements, may cause similar problems.
  5119.  
  5120.  
  5121.  See Also
  5122.  
  5123.   FUNCTION,  STATIC
  5124.  
  5125.  
  5126.  Example
  5127.  
  5128.  The following program uses a function defined by  DEF  FN to calculate the
  5129.  factorial of a number (for example, the factorial of 3 is 3 times 2 times
  5130.  1):
  5131.  
  5132.  DEF FNFactorial# (X%)
  5133.     STATIC Tmp#, I%
  5134.     Tmp# = 1
  5135.     FOR I% = 2 TO X%
  5136.        Tmp# = Tmp# * I%
  5137.     NEXT I%
  5138.     FNFactorial# = Tmp#
  5139.  END DEF
  5140.  
  5141.  INPUT "Enter an integer: ", Num%
  5142.  PRINT : PRINT Num%; "factorial is"; FNFactorial#(Num%)
  5143.  
  5144.  
  5145.  
  5146.  
  5147.  DEFtype Statements
  5148.  ────────────────────────────────────────────────────────────────────────────
  5149.  
  5150.  
  5151.  Action
  5152.  
  5153.  Set the default data type for variables,  DEF FN functions, and  FUNCTION
  5154.  procedures.
  5155.  
  5156.  
  5157.  Syntax
  5158.  
  5159.   DEFINT  letterrange «,  letterrange»...
  5160.   DEFLNG  letterrange«,  letterrange»...
  5161.   DEFSNG  letterrange«,  letterrange»...
  5162.   DEFDBL  letterrange«,  letterrange»...
  5163.   DEFCUR  letterrange«,  letterrange»...
  5164.   DEFSTR  letterrange «,  letterrange»...
  5165.  
  5166.  
  5167.  Remarks
  5168.  
  5169.  The  letterrange argument has the form:
  5170.  
  5171.   letter1 «- letter2»
  5172.  
  5173.  The arguments  letter1 and  letter2 are any of the uppercase or lowercase
  5174.  letters of the alphabet. Names beginning with the letters in  letterrange
  5175.  have the type specified by the last three letters of the statement: integer
  5176.  ( INT), long integer ( LNG), single precision ( SNG), double precision (
  5177.  DBL), currency ( CUR), or  string ( STR). For example, in the following
  5178.  program fragment,  Message is a string variable:
  5179.  
  5180.  DEFSTR A-Q
  5181.  .
  5182.  .
  5183.  .
  5184.  Message="Out of stack space."
  5185.  
  5186.  
  5187.  The case of the letters in  letterrange is not significant. These three
  5188.  statements are equivalent:
  5189.  
  5190.  DEFINT I-N
  5191.  DEFINT i-n
  5192.  DEFINT i-N
  5193.  
  5194.  A type-declaration character ( %,  &,  !,  #,  @, or  $) always takes
  5195.  precedence over a  DEF type statement.  DEF type statements do not affect
  5196.  record elements.
  5197.  
  5198.  
  5199.  Note
  5200.  
  5201.  I%, I&, I!, I#, I@, and I$ all are distinct variables, and each may hold a
  5202.  different value.
  5203.  
  5204.  
  5205.  BASICA
  5206.  
  5207.  BASICA handles default data types differently. BASICA scans each statement
  5208.  before executing it. If the statement contains a variable without an
  5209.  explicit type (indicated by  %,  &,  !,  #,  @, or  $), the interpreter uses
  5210.  the current default type.
  5211.  
  5212.  In contrast, BASIC scans the text once only and after a variable appears in
  5213.  a program line, its type cannot be changed.
  5214.  
  5215.  
  5216.  Example
  5217.  
  5218.  See the  ABS function programming example, which uses the  DEFDBL statement.
  5219.  
  5220.  
  5221.  
  5222.  
  5223.  DEF SEG Statement
  5224.  ────────────────────────────────────────────────────────────────────────────
  5225.  
  5226.  
  5227.  Action
  5228.  
  5229.  Sets the current segment address for a subsequent  PEEK function,  BLOAD,
  5230.  BSAVE,  Absolute routine, or  POKE statement.
  5231.  
  5232.  
  5233.  Syntax
  5234.  
  5235.   DEF SEG «= address»
  5236.  
  5237.  
  5238.  Remarks
  5239.  
  5240.  For  Absolute,  BLOAD,  BSAVE,  PEEK, and  POKE,  address is used as the
  5241.  segment. The argument  address is a numeric expression with an unsigned
  5242.  integer value between 0 and 65,535, inclusive. If you use a value outside
  5243.  this range, BASIC generates the error message Illegal function call. The
  5244.  previous segment is retained if an error occurs. If  address is omitted,
  5245.  DGROUP is used.
  5246.  
  5247.   DEF SEG remains in effect until changed. To reset the current segment to
  5248.  the default data segment (DGROUP), use  DEF SEG without any argument.
  5249.  
  5250.  Be sure to separate  DEF and  SEG with a space. Otherwise, BASIC interprets
  5251.  the statement to mean "assign a value to the variable DEFSEG."
  5252.  
  5253.  To set the current segment address to the address of data stored in far
  5254.  memory, you can use  DEF SEG with the  SSEG or  VARSEG functions ( SSEG
  5255.  returns the current segment address of a string;  VARSEG returns the current
  5256.  segment address of numeric data). For example, this statement sets the
  5257.  current address for a far string named a$ :
  5258.  
  5259.  DEF SEG = SSEG(a$)
  5260.  
  5261.  When using  DEF SEG in OS/2 protected mode, any  DEF SEG statement must
  5262.  refer only to a valid selector. The  DEF SEG statement itself does not
  5263.  generate any memory references using the selector, nor does it attempt to
  5264.  validate the selector. If a misdirected  DEF SEG statement causes your
  5265.  program to refer to an illegal memory address, the operating system may
  5266.  generate a protection exception, or BASIC may generate the error message
  5267.  Permission denied. The default  DEF SEG segment always constitutes a valid
  5268.  memory reference. Use caution when altering this reference in protected
  5269.  mode.
  5270.  
  5271.  DEF SEG and Expanded Memory Arrays
  5272.  Do not use  DEF  SEG to set the segment of
  5273.  an expanded memory array. If you start QBX with the /Ea switch, any of these
  5274.  arrays may be stored in expanded memory:
  5275.  
  5276.    ■         Numeric arrays less than 16K in size.
  5277.  
  5278.    ■         Fixed-length string arrays less than 16K in size.
  5279.  
  5280.    ■         User-defined-type arrays less than 16K in size.
  5281.  
  5282.  If you want to use  DEF  SEG to set the segment of an array, first start QBX
  5283.  without the /Ea switch. (Without the /Ea switch, no arrays are stored in
  5284.  expanded memory.)
  5285.  
  5286.  For more information on using expanded memory, see "Memory Management for
  5287.  QBX" in  Getting Started.
  5288.  
  5289.  
  5290.  BASICA
  5291.  
  5292.  In this version of BASIC, the  CALL and  CALLS statements do not use the
  5293.  segment address set by  DEF SEG.
  5294.  
  5295.  
  5296.  See Also
  5297.  
  5298.   SADD;  SSEG;  VARPTR,  VARSEG
  5299.  
  5300.  
  5301.  Example
  5302.  
  5303.  The following example uses  DEF  SEG,  PEEK, and  POKE to turn the Caps Lock
  5304.  key on and off.
  5305.  
  5306.  This program contains hardware-specific instructions. It works correctly on
  5307.  IBM PC, XT, and AT computers.
  5308.  
  5309.  DECLARE SUB CapsOn ()
  5310.  DECLARE SUB CapsOff ()
  5311.  DECLARE SUB PrntMsg (R%, C%, M$)
  5312.  CLS
  5313.  CapsOn
  5314.  PrntMsg 24, 1, "<Caps Lock On>"
  5315.  LOCATE 12, 10
  5316.  LINE INPUT "Enter a string (all characters are caps): ", S$
  5317.  CapsOff
  5318.  PrntMsg 24, 1, "              "
  5319.  PrntMsg 25, 1, "Press any key to continue..."
  5320.  DO WHILE INKEY$ = "": LOOP
  5321.  CLS
  5322.  END
  5323.  
  5324.  SUB CapsOff STATIC' Turn the Caps Lock key off.
  5325.     DEF SEG = 0' Set segment to low memory.
  5326.        POKE &H417, PEEK(&H417) AND &HBF' Turn off bit 6 of &H0417.
  5327.     DEF SEG ' Restore segment.
  5328.  END SUB
  5329.  
  5330.  SUB CapsOn STATIC' Turn Caps Lock on.
  5331.     DEF SEG = 0' Set segment to low memory.
  5332.        POKE &H417, PEEK(&H417) OR &H40' Turn on bit 6 of &H0417.
  5333.     DEF SEG ' Restore segment.
  5334.  END SUB
  5335.  
  5336.  SUB PrntMsg (Row%, Col%, Message$) STATIC
  5337.  ' Print message at Row%, Col% without changing cursor.
  5338.     CurRow% = CSRLIN: CurCol% = POS(0)' Save cursor position.
  5339.     LOCATE Row%, Col%: PRINT Message$;
  5340.     ' Restore cursor.
  5341.     LOCATE CurRow%, CurCol%
  5342.  END SUB
  5343.  
  5344.  
  5345.  
  5346.  
  5347.  DELETE Statement
  5348.  ────────────────────────────────────────────────────────────────────────────
  5349.  
  5350.  
  5351.  Action
  5352.  
  5353.  Removes the current record from an ISAM table.
  5354.  
  5355.  
  5356.  Syntax
  5357.  
  5358.   DELETE «#»  filenumber%
  5359.  
  5360.  
  5361.  Remarks
  5362.  
  5363.  The argument  filenumber% is the number used in the  OPEN statement to open
  5364.  the table.
  5365.  
  5366.  If the record you delete is the last record according to the table's current
  5367.  index, the current position is at the end of the table and there is no
  5368.  current record. When you delete any other record in the table, the record
  5369.  following the deleted record becomes current.  The record preceding the
  5370.  deleted record remains the previous record.
  5371.  
  5372.  
  5373.  See Also
  5374.  
  5375.   DELETEINDEX, DELETETABLE,  INSERT
  5376.  
  5377.  
  5378.  Example
  5379.  
  5380.  See the  BEGINTRANS statement programming example, which uses the  DELETE
  5381.  statement.
  5382.  
  5383.  
  5384.  
  5385.  
  5386.  DELETEINDEX Statement
  5387.  ────────────────────────────────────────────────────────────────────────────
  5388.  
  5389.  
  5390.  Action
  5391.  
  5392.  Permanently removes an index from an ISAM database.
  5393.  
  5394.  
  5395.  Syntax
  5396.  
  5397.   DELETEINDEX «#»  filenumber%,  indexname$
  5398.  
  5399.  
  5400.  Remarks
  5401.  
  5402.  The  DELETEINDEX statement uses the following arguments:
  5403.  
  5404. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  5405.  Argument                                Description
  5406.  ────────────────────────────────────────────────────────────────────────────
  5407.   filenumber%                            The number of the open ISAM table
  5408.                                          that was used in the  OPEN
  5409.                                          statement.
  5410.  
  5411.   indexname$                             The name used in the  CREATEINDEX
  5412.                                          statement to create the index.
  5413.  
  5414.  
  5415.  
  5416.  
  5417.  See Also
  5418.  
  5419.   CREATEINDEX,  GETINDEX$, SETINDEX
  5420.  
  5421.  
  5422.  Example
  5423.  
  5424.  See the  CREATEINDEX statement programming example, which uses the
  5425.  DELETEINDEX statement.
  5426.  
  5427.  
  5428.  
  5429.  
  5430.  DELETETABLE Statement
  5431.  ────────────────────────────────────────────────────────────────────────────
  5432.  
  5433.  
  5434.  Action
  5435.  
  5436.  Removes a table and deletes any indexes based on the table from an ISAM
  5437.  database.
  5438.  
  5439.  
  5440.  Syntax
  5441.  
  5442.   DELETETABLE  database$,  tablename$
  5443.  
  5444.  
  5445.  Remarks
  5446.  
  5447.  The  DELETETABLE statement uses the following arguments:
  5448.  
  5449. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  5450.  Argument                                Description
  5451.  ────────────────────────────────────────────────────────────────────────────
  5452.   database$                              A database filename or path. The
  5453.                                          argument  database$ specifies an
  5454.                                          optional device, followed by a
  5455.                                          filename or path conforming to the
  5456.                                          DOS naming conventions. The
  5457.                                          database$ specification must be
  5458.                                          the name of an ISAM file.
  5459.  
  5460.   tablename$                             The name used in the  OPEN
  5461.                                          statement to open the table.
  5462.  Argument                                Description
  5463.  ────────────────────────────────────────────────────────────────────────────
  5464.                                         statement to open the table.
  5465.  
  5466.  
  5467.  
  5468.  If the specified file is not an ISAM database file, BASIC generates the
  5469.  error message Bad file mode.
  5470.  
  5471.  
  5472.  Warning
  5473.  
  5474.  Use  DELETETABLE with caution.  DELETETABLE  permanently removes the
  5475.  specified table from the database.
  5476.  
  5477.  
  5478.  See Also
  5479.  
  5480.   CLOSE,  DELETE,  DELETEINDEX,  OPEN
  5481.  
  5482.  
  5483.  Example
  5484.  
  5485.  See the programming example for the  SEEKGT,  SEEKGE, and  SEEKEQ
  5486.  statements, which uses the  DELETETABLE statement.
  5487.  
  5488.  
  5489.  
  5490.  
  5491.  DIM Statement
  5492.  ────────────────────────────────────────────────────────────────────────────
  5493.  
  5494.  
  5495.  Action
  5496.  
  5497.  Declares a variable and allocates storage space.
  5498.  
  5499.  
  5500.  Syntax
  5501.  
  5502.   DIM «SHARED» variable«(subscripts)» «AS type» «, variable«(subscripts)» «AS
  5503.  type»»...
  5504.  
  5505.  
  5506.  Remarks
  5507.  
  5508.  The following list describes the parts of the  DIM statement:
  5509. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  5510.  Part                                    Description
  5511.  ────────────────────────────────────────────────────────────────────────────
  5512.   SHARED                                 The optional  SHARED attribute
  5513.                                          allows all procedures in a module
  5514.                                          to share arrays and simple
  5515.                                          variables. This differs from the
  5516.                                          SHARED statement, which affects
  5517.                                          only variables within a single
  5518.                                          SUB or  FUNCTION procedure.
  5519.  
  5520.   variable                               A BASIC variable name.
  5521.  
  5522.   subscripts                             The dimensions of the array.
  5523.                                          Multiple dimensions can be
  5524.                                          declared. The subscript syntax is
  5525.  Part                                    Description
  5526.  ────────────────────────────────────────────────────────────────────────────
  5527.                                         declared. The subscript syntax is
  5528.                                          described below.
  5529.  
  5530.   AS  type                               Declares the type of the variable.
  5531.                                          The type may be  INTEGER,  LONG,
  5532.                                          SINGLE,  DOUBLE,  STRING (for
  5533.                                          variable-length strings),  STRING
  5534.                                          *  length (for fixed-length
  5535.                                          strings),  CURRENCY, or a
  5536.                                          user-defined type.
  5537.  
  5538.  
  5539.  The argument  subscript in the  DIM statement has the following form:
  5540.  
  5541.  « lower%  TO»  upper% «,« lower%  TO»  upper%»...
  5542.  
  5543.  The  TO keyword provides a way to indicate both the lower and the upper
  5544.  bounds of an array's subscripts. The following statements are equivalent (if
  5545.  there is no  OPTION  BASE statement):
  5546.  
  5547.  DIM A(8,3)
  5548.  DIM A(0 TO 8, 0 TO 3)
  5549.  DIM A(8,0 TO 3)
  5550.  
  5551.  Subscripts can be negative.  TO can be used to specify any range of
  5552.  subscripts between -32,768 and 32,767, inclusive:
  5553.  
  5554.  DIM A(-4 TO 10)
  5555.  DIM B(-99 TO -5,-3 TO 0)
  5556.  
  5557.  If you use an implicitly dimensioned array (that is, any array that has not
  5558.  been declared with the  DIM statement), the maximum value of each subscript
  5559.  in the array is 10. If you use a subscript that is greater than the
  5560.  specified maximum and if run-time error checking is in effect, BASIC
  5561.  generates the error message Subscript out of range.
  5562.  
  5563.  
  5564.  Note
  5565.  
  5566.  Run-time error checking is in effect when:
  5567.  
  5568.    ■   You run a program from the QBX environment.
  5569.  
  5570.    ■   You have created an .EXE file in the QBX environment and you have
  5571.        selected the Run-Time Error Checking option in the Make EXE File
  5572.        dialog box.
  5573.  
  5574.    ■   You have compiled your program with BC using the /D option to select
  5575.        run-time error checking.
  5576.  
  5577.  
  5578.  The  DIM statement initializes all elements of numeric arrays to zero and
  5579.  all the elements of string arrays to null strings. The fields of record
  5580.  variables are initialized to zero, including fixed-string fields. The
  5581.  maximum number of dimensions allowed in a  DIM statement is 60.
  5582.  
  5583.  If you try to declare a dimension for an array variable with a  DIM
  5584.  statement after you have referred to the array, BASIC generates the error
  5585.  message Array already dimensioned. It is good programming practice to put
  5586.  the required  DIM statements at the beginning of a program, outside of any
  5587.  loops.
  5588.  
  5589.  Static and Dynamic Arrays
  5590.  How you declare an array also determines whether it
  5591.  is static (allocated when the program is translated) or dynamic (allocated
  5592.  when the program is run):
  5593. ╓┌───────────────────────────────────────────────────────────────┌───────────╖
  5594.  How array is declared                                           Allocation
  5595.  ────────────────────────────────────────────────────────────────────────────
  5596.  Declared first in a  COMMON statement                           Dynamic
  5597.  
  5598.  Implicitly dimensioned arrays                                   Static
  5599.  
  5600.  Dimensioned with numeric constants or CONST statement           Static
  5601.  constants
  5602.  
  5603.  Dimensioned with variables as subscripts                        Dynamic
  5604.  
  5605.  
  5606.  The following list shows examples of different  DIM statements and results:
  5607. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  5608.  Statement                               Result
  5609.  Statement                               Result
  5610.  ────────────────────────────────────────────────────────────────────────────
  5611.  DIM A(0 TO 9)                           The array A is allocated as a
  5612.                                          static array if  $DYNAMIC is not
  5613.                                          in effect.
  5614.  
  5615.  DIM A(MAXDIM)                           If MAXDIM is defined in a  CONST
  5616.                                          statement, A is a static array. If
  5617.                                          MAXDIM is a variable, the array is
  5618.                                          a dynamic array and is allocated
  5619.                                          only when the program reaches the
  5620.                                          DIM statement.
  5621.  
  5622.  
  5623.  
  5624.  For more information about static and dynamic arrays, see Appendix B, "Data
  5625.  Types, Constants, Variables, and Arrays" in the  Programmer's Guide.
  5626.  
  5627.  
  5628.  Note
  5629.  
  5630.  If the array size exceeds 64K, if the array is not dynamic, and if the /AH
  5631.  option was not used, BASIC may generate the error message Subscript out of
  5632.  range or Array too big. Reduce the size of the array or make the array
  5633.  dynamic and use the /AH command-line option.
  5634.  
  5635.  
  5636.  Type Declarations
  5637.  In addition to declaring the dimensions of an array, the
  5638.  DIM statement also can be used to declare the type of a variable. For
  5639.  example, the following statement declares the variable to be an integer,
  5640.  even though there is no type-declaration character or  DEFINT statement:
  5641.  
  5642.  DIM NumberOfBytes AS INTEGER
  5643.  
  5644.  The  DIM statement provides a way to declare specific variables to be
  5645.  records. In the following example, the variable TopCard is declared as a
  5646.  record variable:
  5647.  
  5648.  TYPE Card
  5649.  Suit AS STRING * 9
  5650.  Value AS INTEGER
  5651.  END TYPE
  5652.  
  5653.  DIM TopCard AS Card
  5654.  
  5655.  You also can declare arrays of records:
  5656.  
  5657.  TYPE Card
  5658.  Suit AS STRING * 9
  5659.  Value AS INTEGER
  5660.  END TYPE
  5661.  
  5662.  DIM Deck(1 TO 52) AS Card
  5663.  
  5664.  
  5665.  Note
  5666.  
  5667.  BASIC now supports the  CURRENCY data type (type suffix  @). This can be
  5668.  used in the  AS  type clause of the  DIM statement. Also, BASIC now supports
  5669.  static arrays in user-defined types.
  5670.  
  5671.  
  5672.  BASICA
  5673.  
  5674.  BASICA executes a  DIM statement when it encounters the statement in the
  5675.  program. The array is allocated only when the statement is executed, so all
  5676.  arrays in BASICA are dynamic.
  5677.  
  5678.  
  5679.  See Also
  5680.  
  5681.   ERASE,  OPTION  BASE,  REDIM
  5682.  
  5683.  
  5684.  Example
  5685.  
  5686.  The following example finds and prints the maximum and minimum of a set of
  5687.  values:
  5688.  
  5689.  ' Declare the dimensions for an array to hold the values.
  5690.  CONST MAXDIM=20
  5691.  DIM A(1 TO MAXDIM)
  5692.  ' Use DIM to set up two integer variables. Other variables are SINGLE.
  5693.  DIM NumValues AS INTEGER, I AS INTEGER
  5694.  
  5695.  ' Get the values.
  5696.  NumValues=0
  5697.  PRINT "Enter values one per line. Type END to end."
  5698.  DO
  5699.     INPUT A$
  5700.     IF UCASE$(A$)="END" OR NumValues>=MAXDIM THEN EXIT DO
  5701.     NumValues=NumValues+1
  5702.     A(NumValues)=VAL(A$)
  5703.  LOOP
  5704.  
  5705.  ' Find the maximum and minimum values.
  5706.  IF NumValues>0 THEN
  5707.     Max=A(1)
  5708.     Min=A(1)
  5709.     FOR I=1 TO NumValues
  5710.        IF A(I)>Max THEN Max=A(I)
  5711.        IF A(I)<Min THEN Min=A(I)
  5712.     NEXT I
  5713.     PRINT "The maximum is ";Max;" The minimum is ";Min
  5714.  ELSE
  5715.     PRINT "Too few values."
  5716.  END IF
  5717.  
  5718.  
  5719.  Output
  5720.  
  5721.  Enter values one per line. Type END to end.
  5722.  ? 23.2
  5723.  ? 11.3
  5724.  ? 1.6
  5725.  ? end
  5726.  The maximum is  23.2  The minimum is  1.6
  5727.  
  5728.  
  5729.  
  5730.  
  5731.  DIR$ Function
  5732.  ────────────────────────────────────────────────────────────────────────────
  5733.  
  5734.  
  5735.  Action
  5736.  
  5737.  Returns a filename that matches the specified pattern.
  5738.  
  5739.  
  5740.  Syntax
  5741.  
  5742.   DIR$«( filespec$)»
  5743.  
  5744.  
  5745.  Remarks
  5746.  
  5747.  The argument  filespec$ is a string expression that specifies a filename or
  5748.  path.
  5749.  
  5750.  The path and filename can include a drive and DOS wildcard characters.
  5751.  
  5752.  BASIC generates the error message Illegal function call if you don't specify
  5753.   filespec$ when you first call  DIR$.
  5754.  
  5755.   DIR$ returns the first filename that matches  filespec$. To retrieve
  5756.  additional filenames that match the  filespec$ pattern, call  DIR$ again
  5757.  with no argument. When no filenames match,  DIR$ returns a null string.
  5758.  
  5759.  You do not have to retrieve all of the filenames that match a given
  5760.  filespec$ before calling  DIR$ again with a new  filespec$.
  5761.  
  5762.  Because filenames are retrieved in no particular order, you may want to
  5763.  store filenames in a dynamic array and sort the array.
  5764.  
  5765.   DIR$ is not case sensitive. "C" is the same as "c."
  5766.  
  5767.  
  5768.  See Also
  5769.  
  5770.   CURDIR$
  5771.  
  5772.  
  5773.  Example
  5774.  
  5775.  The following example demonstrates use of the  DIR$ function:
  5776.  
  5777.  DECLARE FUNCTION GetFileCount& (filespec$)
  5778.  filespec$ = "*.*"
  5779.  count = GetFileCount(filespec$)
  5780.  PRINT count; "files match the file specification."
  5781.  
  5782.  ' Function that returns number of files that match file specification.
  5783.  FUNCTION GetFileCount& (filespec$)
  5784.  DIM FileCount AS LONG
  5785.      IF LEN(DIR$(filespec$)) = 0 THEN     ' Ensure filespec$ is valid.
  5786.          FileCount& = 0
  5787.      ELSE
  5788.          FileCount = 1
  5789.          DO WHILE LEN(DIR$) > 0
  5790.              FileCount& = FileCount& + 1
  5791.          LOOP
  5792.      END IF
  5793.      GetFileCount = FileCount&
  5794.  END FUNCTION
  5795.  
  5796.  
  5797.  
  5798.  
  5799.  DO...LOOP Statement
  5800.  ────────────────────────────────────────────────────────────────────────────
  5801.  
  5802.  
  5803.  Action
  5804.  
  5805.  Repeats a block of statements while a condition is true or until a condition
  5806.  becomes true.
  5807.  
  5808.  
  5809.  Syntax 1
  5810.  
  5811.   DO «{ WHILE |  UNTIL}  condition»
  5812.      « statementblock»
  5813.      « EXIT DO»
  5814.      « statementblock»
  5815.   LOOP
  5816.  
  5817.  Syntax 2
  5818.  
  5819.   DO
  5820.      « statementblock»
  5821.      « EXIT DO»
  5822.      « statementblock»
  5823.   LOOP «{ WHILE |  UNTIL}  condition»
  5824.  
  5825.  
  5826.  Remarks
  5827.  
  5828.  The argument  condition is a numeric expression that BASIC evaluates as true
  5829.  (nonzero) or false (zero).
  5830.  
  5831.  The program lines between the  DO and  LOOP statements will be repeated as
  5832.  long as  condition is true.
  5833.  
  5834.  You can use a  DO... LOOP statement instead of a  WHILE... WEND statement.
  5835.  The  DO... LOOP is more versatile because it can test for a condition at the
  5836.  beginning or at the end of a loop.
  5837.  
  5838.  
  5839.  Examples
  5840.  
  5841.  The following examples show how placement of the condition affects the
  5842.  number of times the block of statements is executed:
  5843.  
  5844.  ' Test at the beginning of the loop. Because I is not less than 10,
  5845.  ' the body of the loop (the statement block) is never executed.
  5846.  I = 10
  5847.  PRINT "Example 1:": PRINT
  5848.  PRINT "Value of I at beginning of loop is  "; I
  5849.  DO WHILE I < 10
  5850.     I = I + 1
  5851.  LOOP
  5852.  PRINT "Value of I at end of loop is  "; I
  5853.  
  5854.  ' Test at the end of the loop, so the statement block executes
  5855.  ' at least once.
  5856.  I = 10
  5857.  PRINT : PRINT : PRINT "Example 2:": PRINT
  5858.  DO
  5859.     PRINT "Value of I at beginning of loop is  "; I
  5860.     I = I + 1
  5861.  LOOP WHILE I < 10
  5862.  PRINT "Value of I at end of loop is  "; I
  5863.  
  5864.  
  5865.  The following sort program tests at the end of the loop because the entire
  5866.  array must be examined at least once to see if it is in order. The program
  5867.  illustrates testing at the end of a loop:
  5868.  
  5869.  CONST NOEXCH = -1' Set up a value to indicate no exchanges.
  5870.  DIM Exes(12)
  5871.  DIM I AS INTEGER
  5872.  ' Load the array and mix it up.
  5873.  FOR I = 1 TO 12 STEP 2
  5874.     Exes(I) = 13 - I
  5875.     Exes(I + 1) = 0 + I
  5876.  NEXT I
  5877.  Limit = 12
  5878.  PRINT
  5879.  PRINT "This is the list of numbers to sort in ascending order:"
  5880.  PRINT
  5881.  FOR I = 1 TO 12
  5882.     PRINT USING " ### "; Exes(I);
  5883.  NEXT I
  5884.  PRINT
  5885.  
  5886.  ' In the following DO...LOOP, INKEY$ is tested at the bottom of
  5887.  ' the loop. When the user presses a key, INKEY$ is no longer a
  5888.  ' null string and the loop terminates, continuing program execution.
  5889.  PRINT : PRINT "Press any key to continue."
  5890.  DO
  5891.  LOOP WHILE INKEY$ = ""
  5892.  
  5893.  DO
  5894.     Exchange = NOEXCH
  5895.     FOR I = 1 TO Limit - 1            ' Make one pass over the array.
  5896.        IF Exes(I) > Exes(I + 1) THEN
  5897.           SWAP Exes(I), Exes(I + 1)   ' Exchange array elements.
  5898.           Exchange = I                ' Record location of most
  5899.        END IF                         ' recent exchange.
  5900.     NEXT I
  5901.     Limit = Exchange                  ' Sort on next pass only to where
  5902.                                       ' last exchange was done.
  5903.  LOOP UNTIL Exchange = NOEXCH         ' Sort until no elements are
  5904.                                       ' exchanged.
  5905.  PRINT : PRINT "Sorting is completed. This is the sorted list:": PRINT
  5906.  FOR I = 1 TO 12
  5907.     PRINT USING " ### "; Exes(I);
  5908.  NEXT I
  5909.  END
  5910.  
  5911.  
  5912.  
  5913.  
  5914.  DRAW Statement
  5915.  ────────────────────────────────────────────────────────────────────────────
  5916.  
  5917.  
  5918.  Action
  5919.  
  5920.  Draws an object described by a string of drawing commands.
  5921.  
  5922.  
  5923.  Syntax
  5924.  
  5925.   DRAW  stringexpression$
  5926.  
  5927.  
  5928.  Remarks
  5929.  
  5930.  The argument  stringexpression$ contains one or more drawing commands. The
  5931.  drawing commands combine many of the capabilities of the other graphics
  5932.  statements (such as  LINE and  COLOR) into a graphics macro language, as
  5933.  described below.
  5934.  
  5935.  There are three types of drawing commands:
  5936.  
  5937.    ■         Line-drawing and cursor-movement commands.
  5938.  
  5939.    ■         Rotation, color, and scale-factor commands.
  5940.  
  5941.    ■         The substring command.
  5942.  
  5943.  
  5944.  
  5945.  Cursor-Movement Commands
  5946.  The following prefix commands can precede any of the movement commands:
  5947. ╓┌────────────┌──────────────────────────────────────────────────────────────╖
  5948.  Prefix       Description
  5949.  ────────────────────────────────────────────────────────────────────────────
  5950.  B            Move, but do not plot any points.
  5951.  N            Plot, but return to original position when done.
  5952.  
  5953.  
  5954.  The following commands specify movement in terms of units. The default unit
  5955.  size is one pixel. Unit size can be modified by the S command, which sets
  5956.  the scale factor (see "Rotation, Color, and Scale-Factor Commands" later in
  5957.  this entry). If no unit argument is supplied, the graphics cursor is moved
  5958.  one unit.
  5959.  
  5960.  Each of the cursor-movement commands initiate movement from the current
  5961.  graphics position, which is usually the coordinate of the last graphics
  5962.  point plotted with a  DRAW macro-language command or another graphics
  5963.  command (such as  LINE or  PSET). The current position defaults to the
  5964.  center of the screen when a program begins execution. The cursor-movement
  5965.  commands have the following effects:
  5966. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  5967.  Command                                 Effects
  5968.  ────────────────────────────────────────────────────────────────────────────
  5969.  U « n»                                  Move up  n units.
  5970.  
  5971.  D « n»                                  Move down  n units.
  5972.  
  5973.  L « n»                                  Move left  n units.
  5974.  
  5975.  R « n»                                  Move right  n units.
  5976.  
  5977.  E « n»                                  Move diagonally up and right  n
  5978.                                          units.
  5979.  
  5980.  F « n»                                  Move diagonally down and right  n
  5981.                                          units.
  5982.  
  5983.  G « n»                                  Move diagonally down and left  n
  5984.                                          units.
  5985.  
  5986.  H « n»                                  Move diagonally up and left  n
  5987.  Command                                 Effects
  5988.  ────────────────────────────────────────────────────────────────────────────
  5989. H « n»                                  Move diagonally up and left  n
  5990.                                          units. .
  5991.  
  5992.  M «{ +|  -}»  x,  y                     Move absolute or relative:
  5993.  
  5994.                                          If  x is preceded by a plus ( +)
  5995.                                          or minus ( -), the movement is
  5996.                                          relative to the current point;
  5997.                                          that is,  x and  y are added to
  5998.                                          (or subtracted from) the
  5999.                                          coordinates of the current
  6000.                                          graphics position and movement is
  6001.                                          to that point.
  6002.  
  6003.                                          If no sign precedes  x, the
  6004.                                          movement is absolute. Movement is
  6005.                                          from the current cursor position
  6006.                                          to the point with coordinates  x,
  6007.                                          y.
  6008.  Command                                 Effects
  6009.  ────────────────────────────────────────────────────────────────────────────
  6010.                                         y.
  6011.  
  6012.  
  6013.  
  6014.  Rotation, Color, and Scale-Factor Commands
  6015.  The following commands let you change the appearance of a drawing by
  6016.  rotating it, changing colors, or scaling it:
  6017. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  6018.  Command                                 Description
  6019.  ────────────────────────────────────────────────────────────────────────────
  6020.  A  n                                    Set angle rotation. The value of
  6021.                                          n may range from 0 to 3, where 0
  6022.                                          is 0, 1 is 90, 2 is 180, and 3 is
  6023.                                          270.  Figures rotated 90 or 270
  6024.                                          are scaled so they appear the same
  6025.                                          size on a monitor screen with a
  6026.                                          4:3 aspect ratio.
  6027.  
  6028.  TA  n                                   Turn an angle of  n degrees. The
  6029.  Command                                 Description
  6030.  ────────────────────────────────────────────────────────────────────────────
  6031. TA  n                                   Turn an angle of  n degrees. The
  6032.                                          value of  n must be between  -360
  6033.                                          and 360. If  n is positive,
  6034.                                          rotation is counterclockwise; if
  6035.                                          n is negative, rotation is
  6036.                                          clockwise. The following example
  6037.                                          uses TA to draw spokes:
  6038.  
  6039.                                          SCREEN 1
  6040.                                          FOR D = 0 TO 360 STEP 10
  6041.                                           DRAW "TA=" + VARPTR$(D) + "NU50"
  6042.                                          NEXT D
  6043.  
  6044.  C  n                                    Set the drawing (foreground) color
  6045.                                          to n. See the COLOR, PALETTE,
  6046.                                          and SCREEN statements for
  6047.                                          discussion of valid colors,
  6048.                                          numbers, and attributes.
  6049.  
  6050.  Command                                 Description
  6051.  ────────────────────────────────────────────────────────────────────────────
  6052. 
  6053.  P  p,  b                                The value  p is the paint color
  6054.                                          for the figure's interior, while
  6055.                                          b is the paint color for the
  6056.                                          figure's border. See the PAINT
  6057.                                          statement for more information
  6058.                                          about painting an area with a
  6059.                                          graphic pattern.
  6060.  
  6061.  S  n                                    Set scale factor  n, which can
  6062.                                          range from 0 to 255, inclusive.
  6063.                                          Increase or decrease length of
  6064.                                          moves. The default for n is 4,
  6065.                                          which causes no scaling. The scale
  6066.                                          factor multiplied by
  6067.                                          movement-command arguments
  6068.                                          (divided by 4) gives the actual
  6069.                                          distance moved.
  6070.  
  6071.  Command                                 Description
  6072.  ────────────────────────────────────────────────────────────────────────────
  6073. 
  6074.  X  stringexpression$                    Execute substring. This command
  6075.                                          allows you to execute a second
  6076.                                          substring from a DRAW command
  6077.                                          string. You can have one string
  6078.                                          expression execute another, which
  6079.                                          executes a third, and so on.
  6080.  
  6081.                                          Numeric arguments to macro
  6082.                                          commands within stringexpression$
  6083.                                          can be constants or variable names.
  6084.                                          BASIC requires the following
  6085.                                          syntax:
  6086.  
  6087.                                          "X" + VARPTR$(stringexpression)
  6088.  
  6089.  
  6090.  
  6091.  
  6092.  BASICA
  6093.  
  6094.  Some  DRAW statements that are allowable in BASICA programs require
  6095.  modification when used with the BASIC compiler. Specifically, the compiler
  6096.  requires the  VARPTR$ form for variables. One example is this
  6097.  BASICA statement (in which ANGLE is a variable):
  6098.  
  6099.  DRAW "TA = Angle"
  6100.  
  6101.  For the BASIC compiler, you would change that to:
  6102.  
  6103.  DRAW "TA =" + VARPTR$(Angle)
  6104.  
  6105.  The compiler does not support the BASICA X  stringexpression$ command.
  6106.  However, you can execute a substring by appending the character form of the
  6107.  address to X. For example, the following two statements are equivalent. The
  6108.  first statement works when within the environment and when using the
  6109.  compiler, while the second works only within the QBX environment.
  6110.  
  6111.  DRAW "X" + VARPTR$(A$)
  6112.  DRAW "XA$"
  6113.  
  6114.  
  6115.  See Also
  6116.  
  6117.   PALETTE,  SCREEN Statement,  VARPTR$
  6118.  
  6119.  
  6120.  Examples
  6121.  
  6122.  The first example draws the outline of a triangle in magenta and paints the
  6123.  interior cyan:
  6124.  
  6125.  SCREEN 1
  6126.  DRAW "C2"             ' Set color to magenta.
  6127.  DRAW "F60 L120 E60"   ' Draw a triangle.
  6128.  DRAW "BD30"           ' Move down into the triangle.
  6129.  DRAW "P1,2"           ' Paint interior.
  6130.  
  6131.  The next example shows how to use the M macro command with absolute and
  6132.  relative movement, and with string- and numeric-variable arguments:
  6133.  
  6134.  SCREEN 2
  6135.  PRINT "Press any key to continue..."
  6136.  
  6137.  ' Absolute movement.
  6138.  DRAW "M 50,80"
  6139.  DRAW "M 80,50"
  6140.  LOCATE 2, 30: PRINT "Absolute movement"
  6141.  DO : LOOP WHILE INKEY$ = ""
  6142.  
  6143.  ' Relative movement.
  6144.  DRAW "M+40,-20"
  6145.  DRAW "M-40,-20"
  6146.  DRAW "M-40,+20"
  6147.  DRAW "M+40,+20"
  6148.  LOCATE 3, 30: PRINT "Relative movement"
  6149.  DO : LOOP WHILE INKEY$ = ""
  6150.  
  6151.  ' Using a string variable.
  6152.  X$ = "400": Y$ = "190"
  6153.  DRAW "M" + X$ + "," + Y$
  6154.  LOCATE 4, 30: PRINT "String variable"
  6155.  DO : LOOP WHILE INKEY$ = ""
  6156.  
  6157.  ' Using numeric variables (note the two "=" signs).
  6158.  A = 300: B = 120
  6159.  DRAW "M=" + VARPTR$(A) + ",=" + VARPTR$(B)
  6160.  LOCATE 5, 30: PRINT "Numeric variables"
  6161.  
  6162.  This program draws a clock on the screen using the  TIME$ unction:
  6163.  
  6164.  @AS@%' Declare procedure.
  6165.  DECLARE SUB Face (Min$)
  6166.  
  6167.  ' Select 640 x 200 pixel high-resolution graphics screen.
  6168.  SCREEN 2
  6169.  DO
  6170.     CLS
  6171.     Min$ = MID$(TIME$, 4, 2)' Get string containing minutes value.
  6172.     Face Min$' Draw clock face.
  6173.     ' Wait until minute changes or a key is pressed.
  6174.     DO
  6175.        ' Print time at top of screen.
  6176.        LOCATE 2, 37
  6177.        PRINT TIME$
  6178.        Test$ = INKEY$' Test for a key press.
  6179.     LOOP WHILE Min$ = MID$(TIME$, 4, 2) AND Test$ = ""
  6180.  LOOP WHILE Test$ = ""' End program when a key is pressed.
  6181.  END
  6182.  
  6183.  SUB Face (Min$) STATIC' Draw the clock face.
  6184.     LOCATE 23, 30
  6185.     PRINT "Press any key to end"
  6186.     CIRCLE (320, 100), 175
  6187.     ' Convert strings to numbers.
  6188.     Hr = VAL(TIME$)
  6189.     Min = VAL(Min$)
  6190.     ' Convert numbers to angles.
  6191.     Little = 360 - (30 * Hr + Min / 2)
  6192.     Big = 360 - (6 * Min)
  6193.     ' Draw the hands.
  6194.     DRAW "TA=" + VARPTR$(Little) + "NU40"
  6195.     DRAW "TA=" + VARPTR$(Big) + "NU70"
  6196.  END SUB
  6197.  
  6198.  
  6199.  
  6200.  
  6201.  END Statement
  6202.  ────────────────────────────────────────────────────────────────────────────
  6203.  
  6204.  
  6205.  Action
  6206.  
  6207.  Stops a BASIC program, procedure, or block.
  6208.  
  6209.  
  6210.  Syntax 1
  6211.  
  6212.   END «{ DEF |  FUNCTION |  IF |  SELECT |  SUB |  TYPE}»
  6213.  
  6214.  Syntax 2
  6215.  
  6216.   END « n%»
  6217.  
  6218.  
  6219.  Remarks
  6220.  
  6221.  There are a number of ways to use the  END statement, as described in the
  6222.  following list:
  6223. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  6224.  Statement                               Description
  6225.  ────────────────────────────────────────────────────────────────────────────
  6226.   END  DEF                               Ends a multiline  DEF FN function
  6227.                                          definition. You must use  END  DEF
  6228.                                          with a multiline  DEF FN.
  6229.  
  6230.   END  FUNCTION                          Ends a  FUNCTION procedure
  6231.                                          definition. You must use  END
  6232.                                          FUNCTION with  FUNCTION.
  6233.  
  6234.   END  IF                                Ends a block  IF... THEN... ELSE
  6235.                                          statement. You must use  END  IF
  6236.                                          with block  IF... THEN... ELSE.
  6237.  
  6238.   END  SELECT                            Ends a  SELECT CASE block. You
  6239.  Statement                               Description
  6240.  ────────────────────────────────────────────────────────────────────────────
  6241.  END  SELECT                            Ends a  SELECT CASE block. You
  6242.                                          must use  END  SELECT with a
  6243.                                          SELECT CASE statement.
  6244.  
  6245.   END  SUB                               Ends a BASIC  SUB procedure. You
  6246.                                          must use  END  SUB with  SUB.
  6247.  
  6248.   END  TYPE                              Ends a user-defined type
  6249.                                          definition ( TYPE statement). You
  6250.                                          must use  END  TYPE with  TYPE.
  6251.  
  6252.   n%                                     Ends a program and returns the
  6253.                                          value  n% to the operating system
  6254.                                          (if  n% is omitted, the value of
  6255.                                          n% is set to 0).  END is not
  6256.                                          required at the end of a program.
  6257.                                          In Syntax 2,  n% accepts a range
  6258.                                          of integers from -32768 through
  6259.                                          32767, inclusive.
  6260.  Statement                               Description
  6261.  ────────────────────────────────────────────────────────────────────────────
  6262.                                         32767, inclusive.
  6263.  
  6264.                                          The value  n% can be used by DOS
  6265.                                          or OS/2 batch files or by
  6266.                                          non-BASIC programs. Untrapped
  6267.                                          errors and fatal errors set the
  6268.                                          value of  n% to -1.
  6269.  
  6270.  
  6271.  
  6272.  By itself, the  END statement stops program execution and closes all files.
  6273.  In a stand-alone program,  END returns control to the operating system. In
  6274.  the QBX environment,  END returns to that environment. You can place an  END
  6275.  statement anywhere in the program to terminate execution.
  6276.  
  6277.  
  6278.  See Also
  6279.  
  6280.   DEF  FN,  FUNCTION,  IF... THEN... ELSE,  SELECT CASE,  STOP,  SUB,
  6281.  SYSTEM,  TYPE
  6282.  
  6283.  
  6284.  Example
  6285.  
  6286.  See the on error statement programming example, which uses the  END
  6287.  statement.
  6288.  
  6289.  
  6290.  
  6291.  
  6292.  ENVIRON$ Function
  6293.  ────────────────────────────────────────────────────────────────────────────
  6294.  
  6295.  
  6296.  Action
  6297.  
  6298.  Returns an environment string from the DOS or OS/2 environment-string table.
  6299.  
  6300.  
  6301.  Syntax 1
  6302.  
  6303.   ENVIRON$ ( environmentstring$)
  6304.  
  6305.  Syntax 2
  6306.  
  6307.   ENVIRON$ ( n%)
  6308.  
  6309.  
  6310.  Remarks
  6311.  
  6312.  The  ENVIRON$ function uses the following arguments:
  6313.  
  6314. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  6315.  Argument                                Description
  6316.  ────────────────────────────────────────────────────────────────────────────
  6317.   environmentstring$                     A string constant or variable that
  6318.                                          contains the name of an
  6319.                                          environment variable. The name of
  6320.                                          the environment variable must be
  6321.                                          uppercase. For example, ENVIRON$
  6322.                                          ("PATH") returns the path
  6323.  Argument                                Description
  6324.  ────────────────────────────────────────────────────────────────────────────
  6325.                                         ("PATH") returns the path
  6326.                                          environment variable; ENVIRON$
  6327.                                          ("path") returns a null string.
  6328.  
  6329.   n%                                     a numeric expression that
  6330.                                          indicates that the  nth string
  6331.                                          from the environment string table
  6332.                                          should be returned.
  6333.  
  6334.  
  6335.  
  6336.  If you specify an environment-string name, but it cannot be found in the envi
  6337.  
  6338.  Otherwise,  ENVIRON$ returns the text following the equal sign in the environ
  6339.  
  6340.  If you specify a numeric argument ( n%), the  nth string in the environment-s
  6341.  
  6342.  In this case, the string includes all of the text, including  environmentstri
  6343.  
  6344.  If the  nth string does not exist,  ENVIRON$ returns a null string. The argum
  6345.  
  6346.  
  6347.  See Also
  6348.  
  6349.   ENVIRON Statement
  6350.  
  6351.  
  6352.  Example
  6353.  
  6354.  See the ENVIRON statement programming example, which uses the
  6355.  ENVIRON$ function.
  6356.  
  6357.  
  6358.  
  6359.  
  6360.  ENVIRON Statement
  6361.  ────────────────────────────────────────────────────────────────────────────
  6362.  
  6363.  
  6364.  Action
  6365.  
  6366.  Modifies or adds a parameter in the DOS or OS/2 environment-string table.
  6367.  
  6368.  
  6369.  Syntax
  6370.  
  6371.   ENVIRON  stringexpression$
  6372.  
  6373.  
  6374.  Remarks
  6375.  
  6376.  The argument  stringexpression$ is a string constant or variable that
  6377.  contains the name of the environment variable, such as PATH or PROMPT. It
  6378.  can have the form  parameterID= text, or  parameterID  text. Everything to
  6379.  the left of the equal sign or space is assumed to be a parameter, and
  6380.  everything to the right, text.
  6381.  
  6382.  The argument  parameterID must contain all uppercase letters. For example:
  6383. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  6384.  This statement:                         Has this effect:
  6385.  ────────────────────────────────────────────────────────────────────────────
  6386.  This statement:                         Has this effect:
  6387.  ────────────────────────────────────────────────────────────────────────────
  6388.  ENVIRON "PATH=C:\SALES"                 Changes the path.
  6389.  
  6390.  ENVIRON "path=C:\SALES"                 Does not change the path. (It
  6391.                                          creates a new environment
  6392.                                          parameter not usable by the
  6393.                                          operating system.)
  6394.  
  6395.  
  6396.  
  6397.  If  parameterID did not previously exist in the environment-string table, it
  6398.  is appended to the end of the table. If  parameterID exists in the table
  6399.  when the  ENVIRON statement is executed, it is deleted and the new
  6400.  parameterID value is appended to the end of the table.
  6401.  
  6402.  The text string is the new parameter text. If the text is a null string ("")
  6403.  or a semicolon (";"), the existing parameter is removed from the
  6404.  environment-string table and the remaining body of the table is compressed.
  6405.  
  6406.  DOS or OS/2 discards the environment-string table modified by this function
  6407.  when your program ends. The environment-string table is then the same as it
  6408.  was before your program ran.
  6409.  
  6410.  
  6411.  Note
  6412.  
  6413.  You cannot increase the size of the environment-string table when using the
  6414.  ENVIRON statement. This means that before you can add a new environment
  6415.  variable or increase the size of an existing environment variable you must
  6416.  first delete or decrease the size of existing environment variable(s).
  6417.  
  6418.  
  6419.  You can use this statement to change the PATH parameter for a "child"
  6420.  process (a program or command started by a  SHELL statement) or to pass
  6421.  parameters to a child process by creating a new environment variable.
  6422.  
  6423.  BASIC generates the error message Out of memory when no more space can be
  6424.  allocated to the environment-string table. The amount of free space in the
  6425.  table usually is quite small.
  6426.  
  6427.  
  6428.  See Also
  6429.  
  6430.   ENVIRON$,  SHELL Function
  6431.  
  6432.  
  6433.  Example
  6434.  
  6435.  The following example uses the  ENVIRON$ function to get a copy of the
  6436.  current DOS path variable. The path variable is then changed using the
  6437.  ENVIRON statement. The contents of the environment-string table are then
  6438.  displayed using the  ENVIRON$ function.
  6439.  
  6440.  DEFINT A-Z
  6441.  ' Initialize variables.
  6442.  Path$ = "PATH="
  6443.  I% = 1
  6444.  ' Store the old PATH.
  6445.  OldPath$ = ENVIRON$("PATH")
  6446.  ENVIRON "PATH=C:\BIN;C:\DOS;C:\BUSINESS\ACCOUNTING\RECEIVABLES\MAY"
  6447.  ' Display the entire environment-string table.
  6448.  PRINT "Your current environment settings are:"
  6449.  PRINT
  6450.  DO WHILE ENVIRON$(I%) <> ""
  6451.      PRINT ENVIRON$(I%)
  6452.      I% = I% + 1
  6453.  LOOP
  6454.  ' Change the PATH back to original.
  6455.  ENVIRON Path$ + OldPath$
  6456.  ' Verify the change.
  6457.  PRINT
  6458.  PRINT "Your PATH has been restored to:"
  6459.  PRINT
  6460.  PRINT ENVIRON$("PATH")
  6461.  
  6462.  
  6463.  
  6464.  
  6465.  EOF Function
  6466.  ────────────────────────────────────────────────────────────────────────────
  6467.  
  6468.  
  6469.  Action
  6470.  
  6471.  For an ISAM table, tests whether the current position is at the end of a
  6472.  table. For a non-ISAM file, tests for the end-of-file condition.
  6473.  
  6474.  
  6475.  Syntax
  6476.  
  6477.   EOF( filenumber%)
  6478.  
  6479.  
  6480.  Remarks
  6481.  
  6482.  The argument  filenumber% is the number used in the  OPEN statement to open
  6483.  the file or ISAM table.
  6484.  
  6485.  The  EOF function returns true (nonzero) if the end of a non-ISAM file has
  6486.  been reached or if the current position in an ISAM table is at the end of
  6487.  the table. The end of an ISAM table is the position immediately following
  6488.  the last record according to the current index. Use the  EOF function with
  6489.  sequential files to test for the end of a file. This helps you avoid the
  6490.  Input past end of file error message.
  6491.  
  6492.  When used with random-access or binary files,  EOF returns true if the last
  6493.  executed  GET statement was unable to read an entire record.
  6494.  
  6495.  When you use  EOF with a communications device, the definition of the
  6496.  end-of-file condition depends on the mode (ASCII or binary) in which you
  6497.  opened the device. In ASCII mode,  EOF is false until you receive Ctrl+Z,
  6498.  after which it remains true until you close the device. In binary mode,  EOF
  6499.  is true when the input queue is empty ( LOC( filenumber%)=0), where
  6500.  filenumber% is the number of the device. It becomes false when the input
  6501.  queue is not empty.
  6502.  
  6503.  
  6504.  Note
  6505.  
  6506.   EOF cannot be used with the BASIC devices SCRN, KYBD, CONS, LPT n, or PIPE.
  6507.  
  6508.  
  6509.  See Also
  6510.  
  6511.   BOF,  LOC,  LOF,  OPEN
  6512.  
  6513.  
  6514.  Example
  6515.  
  6516.  See the  INPUT# statement programming example, which uses the  EOF function.
  6517.  
  6518.  
  6519.  
  6520.  
  6521.  ERASE Statement
  6522.  ────────────────────────────────────────────────────────────────────────────
  6523.  
  6524.  
  6525.  Action
  6526.  
  6527.  Reinitializes the elements of static arrays; deallocates dynamic arrays.
  6528.  
  6529.  
  6530.  Syntax
  6531.  
  6532.   ERASE  arrayname «,  arrayname»...
  6533.  
  6534.  
  6535.  Remarks
  6536.  
  6537.  The  arrayname arguments are the names of arrays to erase. It is important
  6538.  to know if this array is static or dynamic.  ERASE sets the elements of an
  6539.  array as follows:
  6540. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  6541.  If type of array is:                    ERASE sets array elements to:
  6542.  ────────────────────────────────────────────────────────────────────────────
  6543.  Numeric static array                    Zeros.
  6544.  
  6545.  String static array                     Null strings ("").
  6546.  
  6547.  Array of records                        Zeros [mdash] all elements of each
  6548.                                          record, including fixed-string
  6549.                                          elements.
  6550.  
  6551.  
  6552.  Using  ERASE on a dynamic array frees the memory used by the array. Before
  6553.  your program can refer to the dynamic array again, it must redeclare the
  6554.  array's dimensions with a  DIM or  REDIM statement. If you redeclare the
  6555.  array's dimensions with a  DIM statement without first erasing it, BASIC
  6556.  generates the run-time error message Array already dimensioned. The  ERASE
  6557.  statement is not required when dimensions are redeclared with  REDIM.
  6558.  
  6559.  
  6560.  See Also
  6561.  
  6562.   CLEAR,  DIM,  REDIM
  6563.  
  6564.  
  6565.  Example
  6566.  
  6567.  The following example shows the use of  ERASE with the  $DYNAMIC and
  6568.  $STATIC metacommands:
  6569.  
  6570.  REM $DYNAMIC
  6571.  DIM A(100, 100)
  6572.  ' Deallocate array A.
  6573.  ERASE A
  6574.  ' Redeclare dimensions for array A.
  6575.  REDIM A(5, 5)
  6576.  
  6577.  REM $STATIC
  6578.  DIM B(50, 50)
  6579.  ' Set all elements of B equal to zero. (B still has the dimensions
  6580.  ' assigned by DIM.)
  6581.  ERASE B
  6582.  
  6583.  
  6584.  
  6585.  
  6586.  ERDEV, ERDEV$ Functions
  6587.  ────────────────────────────────────────────────────────────────────────────
  6588.  
  6589.  
  6590.  Action
  6591.  
  6592.  Provide device-specific status information after an error.
  6593.  
  6594.  
  6595.  Syntax
  6596.  
  6597.   ERDEV
  6598.  ERDEV$
  6599.  
  6600.  
  6601.  Remarks
  6602.  
  6603.   ERDEV is an integer function that returns an error code from the last
  6604.  device that generated a critical error.  ERDEV$ is a string function that
  6605.  returns the name of the device that generated the error. Because  ERDEV and
  6606.  ERDEV$ return meaningful information only after an error, they usually are
  6607.  used in error-handling routines specified by an  ON ERROR statement.
  6608.  
  6609.   ERDEV$ contains the 8-byte character device name if the error is on a
  6610.  character device, such as a printer, or the 2-byte block name (A:, B:, etc.)
  6611.  if the device is not a character device. It contains the 3-byte block name
  6612.  (COM) if the communications port experiences a timeout.
  6613.  
  6614.   ERDEV is set by the critical error handler (interrupt 24H) when DOS detects
  6615.  a critical DOS call error. It also is set by a timeout error on the
  6616.  communications port and indicates which option in the  OPEN  COM statement
  6617.  (CD, CS, or DS) is experiencing the timeout.
  6618.  
  6619.   ERDEV returns an integer value that contains information about the error.
  6620.  For block and character device errors, the low byte of  ERDEV contains the
  6621.  DOS error code. For block devices only, the high byte contains
  6622.  device-attribute information.
  6623.  
  6624.  For  COM timeout errors,  ERDEV returns a value corresponding to the source
  6625.  of the timeout. For more information, see the entry for the  OPEN  COM
  6626.  statement.
  6627.  
  6628.  Assuming an  ERDEV return value of x, the following program lines generate
  6629.  the DOS error code (low byte) and device attribute information (high byte).
  6630.  
  6631.  DosErrCode = x AND &HFF' Low byte of ERDEV.
  6632.  DevAttr = (x AND &HFF00) \ 256   ' High byte of ERDEV.
  6633.  
  6634.  For more information about device-attribute words, see the  Microsoft MS-DOS
  6635.   Programmer's  Reference, or books such as  The Peter Norton Guide to the
  6636.  IBM PC or  Advanced MS-DOS.
  6637.  
  6638.  
  6639.  Use  ERDEV only in DOS.
  6640.  
  6641.  
  6642.  Example
  6643.  
  6644.  The following example prints the values of  ERDEV and  ERDEV$ after the
  6645.  program generates an error attempting to open a file:
  6646.  
  6647.  DEFINT A-Z
  6648.  ON ERROR GOTO ErrorHandler' Indicate first line of error handler.
  6649.  OPEN "A:JUNK.DAT" FOR INPUT AS #1' Attempt to open the file.
  6650.  END
  6651.  
  6652.  ErrorHandler:
  6653.  PRINT "ERDEV value is "; ERDEV
  6654.  PRINT "Device name is "; ERDEV$
  6655.  ON ERROR GOTO 0
  6656.  
  6657.  Output
  6658.  Running the program with drive A unlatched produces the following output (2 i
  6659.  
  6660.  ERDEV value is  2
  6661.  Device name is A:
  6662.  
  6663.  
  6664.  
  6665.  
  6666.  ERR, ERL Functions
  6667.  ────────────────────────────────────────────────────────────────────────────
  6668.  
  6669.  
  6670.  Action
  6671.  
  6672.  Return error status.
  6673.  
  6674.  
  6675.  Syntax
  6676.  
  6677.   ERR
  6678.  
  6679.   ERL
  6680.  
  6681.  
  6682.  Remarks
  6683.  
  6684.  After an error, the  ERR function returns an integer that is the run-time
  6685.  code for the error. The  ERL function returns an integer that is the line
  6686.  number where the error occurred, or the closest line number before the line
  6687.  where the error occurred. Because  ERR and  ERL return mean-ingful values
  6688.  only after an error, they usually are used in error-handling routines to
  6689.  determine the error and the corrective action.
  6690.  
  6691.  The value returned by the  ERR function can be directly set by using the
  6692.  ERR statement. Both the values returned by  ERR and  ERL can be set
  6693.  indirectly with the  ERROR statement.
  6694.  
  6695.  The  ERL function returns only the line number, not line labels, located at
  6696.  or before the line producing the error. If your program has no line numbers,
  6697.  or there is no line number in the program before the point where the error
  6698.  occurred,  ERL returns 0.
  6699.  
  6700.   ERL values differ between programs compiled with BC and those run under
  6701.  QBX. In programs compiled with BC,  ERL is set to the last numbered line in
  6702.  the source file preceding the line where the error occurred. When QBX
  6703.  detects an error in a procedure, it looks for a line number only within the
  6704.  immediate procedure. If the procedure doesn't contain a numbered line, QBX
  6705.  returns 0 for  ERL.
  6706.  
  6707.  You can make your programs run identically with both BC and QBX by always
  6708.  including a line number at the beginning of a procedure where an error might
  6709.  occur.
  6710.  
  6711.  
  6712.  See Also
  6713.  
  6714.   ERROR;  ON  ERROR;  RESUME; Table 4.1, "Run-Time Error Codes"
  6715.  
  6716.  
  6717.  Example
  6718.  
  6719.  See the  ON ERROR statement programming example, which uses the  ERR
  6720.  function.
  6721.  
  6722.  
  6723.  
  6724.  
  6725.  ERR Statement
  6726.  ────────────────────────────────────────────────────────────────────────────
  6727.  
  6728.  
  6729.  Action
  6730.  
  6731.  Sets  ERR to a specific value.
  6732.  
  6733.  
  6734.  Syntax
  6735.  
  6736.   ERR =  n%
  6737.  
  6738.  
  6739.  
  6740.  Remarks
  6741.  
  6742.  The argument  n% is an integer expression with a value between 1 and 255,
  6743.  inclusive, that specifies a run-time error code, or 0.
  6744.  
  6745.  When running an application program, BASIC uses  ERR to record whether or
  6746.  not a run-time error has occurred and what the error was. When a program
  6747.  starts running,  ERR is 0; when and if a run-time error occurs, BASIC sets
  6748.  ERR to the error code for that error.
  6749.  
  6750.  You may want to use the  ERR statement to set  ERR to a non-zero value to
  6751.  communicate error information between procedures. For example, you might use
  6752.  one of the run-time codes not used by BASIC as an application-specific error
  6753.  code. See Table 4.1, "Run-Time Error Codes," for a list of the run-time
  6754.  error codes that BASIC uses; they are a subset of the integers between 1 and
  6755.  255, inclusive.
  6756.  
  6757.  Besides the  ERR statement, the following BASIC statements set  ERR whenever
  6758.  they execute:
  6759.  
  6760.    ■   Any form of the  RESUME statement sets  ERR to 0.
  6761.  
  6762.    ■    EXIT  SUB,  EXIT  FUNCTION, or  EXIT  DEF sets  ERR to 0 if executed
  6763.        within a procedure-level error handler.
  6764.  
  6765.    ■   All uses of the  ON ERROR or  ON  LOCAL  ERROR statements syntax set
  6766.        ERR to 0.
  6767.  
  6768.    ■   The  ERROR statement can be used to set  ERR to any value as part of
  6769.        simulating any run-time error.
  6770.  
  6771.  
  6772.  See Also
  6773.  
  6774.   ERR,  ERL;  ERROR; Table 4.1, "Run-Time Error Codes"
  6775.  
  6776.  
  6777.  Example
  6778.  
  6779.  See the  ON ERROR statement programming example, which uses the  ERR
  6780.  statement.
  6781.  
  6782.  
  6783.  
  6784.  
  6785.  ERROR Statement
  6786.  ────────────────────────────────────────────────────────────────────────────
  6787.  
  6788.  
  6789.  Action
  6790.  
  6791.  Simulates the occurrence of a BASIC error or a user-defined error.
  6792.  
  6793.  
  6794.  Syntax
  6795.  
  6796.   ERROR  integerexpression%
  6797.  
  6798.  
  6799.  Remarks
  6800.  
  6801.  The argument  integerexpression% represents the error code. It must be
  6802.  between 1 and 255, inclusive. If  integerexpression% is an error code
  6803.  already used by BASIC, the  ERROR statement simulates the occurrence of that
  6804.  error.
  6805.  
  6806.  To define your own error code, use a value that is greater than any used by
  6807.  the standard BASIC error codes. (Start at 255 and work down to avoid
  6808.  compromising compatibility with future Microsoft BASIC error codes.) In
  6809.  general, the error codes used by BASIC are between 1 and 100 (although not
  6810.  all these are used).
  6811.  
  6812.  If an error statement is executed when no error-handling routine is enabled,
  6813.  BASIC generates an error message and stops program execution. If the  ERROR
  6814.  statement specified an error code that is not used by BASIC, the message
  6815.  Unprintable error is generated.
  6816.  
  6817.  
  6818.  See Also
  6819.  
  6820.   ERR,  ERL;  ON ERROR;  RESUME
  6821.  
  6822.  
  6823.  Example
  6824.  
  6825.  See the  ON ERROR statement programming example, which uses the  ERROR
  6826.  statement.
  6827.  
  6828.  
  6829.  
  6830.  
  6831.  EVENT Statements
  6832.  ────────────────────────────────────────────────────────────────────────────
  6833.  
  6834.  
  6835.  Action
  6836.  
  6837.  Enable or disable trapping of events.
  6838.  
  6839.  
  6840.  Syntax
  6841.  
  6842.   EVENT ON
  6843.  
  6844.   EVENT OFF
  6845.  
  6846.  
  6847.  Remarks
  6848.  
  6849.   EVENT  ON enables trapping of events until BASIC encounters the next  EVENT
  6850.  OFF statement.
  6851.  
  6852.   EVENT OFF disables trapping of events until BASIC encounters the next
  6853.  EVENT ON statement.
  6854.  
  6855.  The  EVENT statements affect compiled code generation. When  EVENT OFF is in
  6856.  effect, the compiler will not generate any event-checking code between
  6857.  statements.  EVENT OFF is equivalent to compiling a program without /V or
  6858.  /W.  EVENT OFF can be used to create small and fast code that still supports
  6859.  event trapping.
  6860.  
  6861.  If your program contains event-handling statements and you are compiling
  6862.  from the BC command line, use the BC /W or /V option. (The /W option checks
  6863.  for events at every label or line number; the /V option checks at every
  6864.  statement.) If you do not use these options and your program contains event
  6865.  traps, BASIC generates the error message ON event without /V or /W on
  6866.  command line.
  6867.  
  6868.   EVENT OFF and  EVENT ON can be used to bracket sections of code where
  6869.  events do not need to be detected and trapped, and fast performance is
  6870.  required. Events still could be detected and tracked if a subroutine using
  6871.  EVENT ON were called from a section of  EVENT OFF code.
  6872.  
  6873.  If an event occurs while  EVENT OFF is in effect, this event still is
  6874.  remembered and then is handled as soon as an  EVENT ON block is entered.
  6875.  
  6876.  
  6877.  See Also
  6878.  
  6879.   ON  event
  6880.  
  6881.  
  6882.  Example
  6883.  
  6884.  See the  STRIG statements programming example, which uses the  EVENT
  6885.  statements.
  6886.  
  6887.  
  6888.  
  6889.  
  6890.  EXIT Statement
  6891.  ────────────────────────────────────────────────────────────────────────────
  6892.  
  6893.  
  6894.  Action
  6895.  
  6896.  Exits a  DEF FN function, a  DO... LOOP or  FOR... NEXT loop, or a  FUNCTION
  6897.  or  SUB procedure.
  6898.  
  6899.  
  6900.  Syntax
  6901.  
  6902.   EXIT { DEF |  DO |  FOR |  FUNCTION |  SUB}
  6903.  
  6904.  
  6905.  Remarks
  6906.  
  6907.  There are a number of ways to use the  EXIT statement, as described in the
  6908.  following list:
  6909.  
  6910. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  6911.  Statement                               Description
  6912.  ────────────────────────────────────────────────────────────────────────────
  6913.   EXIT DEF                               Causes an immediate exit from the
  6914.                                          executing  DEF FN function.
  6915.                                          Program execution continues where
  6916.                                          the  DEF FN function was invoked.
  6917.  
  6918.   EXIT DO                                Provides an alternative exit from
  6919.                                          a  DO... LOOP statement.  Can be
  6920.                                          used only inside a  DO... LOOP
  6921.                                          statement;  EXIT DO transfers
  6922.                                          control to the statement following
  6923.                                          the  LOOP statement. When used
  6924.                                          within nested  DO... LOOP
  6925.                                          statements, transfers out of the
  6926.                                          immediately enclosing loop.
  6927.  
  6928.   EXIT FOR                               Provides another way to exit a
  6929.                                          FOR... NEXT loop. May appear only
  6930.                                          in a  FOR... NEXT loop; transfers
  6931.                                          control to the statement following
  6932.  Statement                               Description
  6933.  ────────────────────────────────────────────────────────────────────────────
  6934.                                         control to the statement following
  6935.                                          the  NEXT statement. When used
  6936.                                          within nested  FOR... NEXT loops,
  6937.                                          transfers out of the immediately
  6938.                                          enclosing loop.
  6939.  
  6940.   EXIT FUNCTION                          Causes an immediate exit from a
  6941.                                          FUNCTION procedure. Program
  6942.                                          execution continues where the
  6943.                                          procedure was invoked. Can be used
  6944.                                          only in a  FUNCTION procedure.
  6945.  
  6946.   EXIT SUB                               Immediately exits a  SUB procedure.
  6947.                                          Program execution continues with
  6948.                                          the statement after the  CALL
  6949.                                          statement. Can be used only in a
  6950.                                          SUB procedure.
  6951.  
  6952.  
  6953.  
  6954.  None of the  EXIT statements defines the end of the structure in which it is
  6955.  used.  EXIT statements provide only an alternative exit from the structure.
  6956.  
  6957.  
  6958.  See Also
  6959.  
  6960.   DEF FN,  DO... LOOP,  FOR... NEXT,  FUNCTION,  SUB
  6961.  
  6962.  
  6963.  Example
  6964.  
  6965.  The following example demonstrates the use of a variety of  EXIT statements.
  6966.  A loop is continuously executed until a key is pressed. Once a key is
  6967.  pressed, the next  EXIT statement that executes will cause the program to
  6968.  end.
  6969.  
  6970.  DECLARE SUB ExitDemo ()
  6971.  CLS
  6972.  DO
  6973.  PRINT : PRINT "Entering/Re-entering ExitDemo"
  6974.  ExitDemo
  6975.  SLEEP 1
  6976.  LOOP WHILE INKEY$ = ""
  6977.  PRINT "Exiting EXIT statement programming example."
  6978.  END
  6979.  
  6980.  SUB ExitDemo
  6981.  DO
  6982.  FOR I% = 1 TO 1000
  6983.  Num% = INT(RND * 100)
  6984.  SELECT CASE Num%
  6985.  CASE 7
  6986.  PRINT "Exiting FOR...NEXT loop in ExitDemo SUB"
  6987.  EXIT FOR
  6988.  CASE 29
  6989.  PRINT "Exiting DO...LOOP in ExitDemo SUB"
  6990.  EXIT DO
  6991.  CASE 54
  6992.  PRINT "Exiting ExitDemo SUB"
  6993.  EXIT SUB
  6994.  CASE ELSE
  6995.  END SELECT
  6996.  NEXT I%
  6997.  LOOP
  6998.  END SUB
  6999.  
  7000.  
  7001.  
  7002.  
  7003.  EXP Function
  7004.  ────────────────────────────────────────────────────────────────────────────
  7005.  
  7006.  
  7007.  Action
  7008.  
  7009.  Calculates the exponential function.
  7010.  
  7011.  
  7012.  Syntax
  7013.  
  7014.   EXP( x)
  7015.  
  7016.  
  7017.  Remarks
  7018.  
  7019.  The  EXP function returns  e (the base of natural logarithms) to the power
  7020.  of  x.
  7021.  
  7022.  The exponent  x must be less than or equal to 88.02969 when you are using
  7023.  single-precision values and less than or equal to 709.782712893 when you are
  7024.  using double-precision values. If you use a value of  x that isn't within
  7025.  those limits, BASIC generates the error message Overflow.
  7026.  
  7027.   EXP is calculated in single precision if  x is an integer or
  7028.  single-precision value. If you use any other numeric data type,  EXP is
  7029.  calculated in double precision.
  7030.  
  7031.  
  7032.  See Also
  7033.  
  7034.   LOG
  7035.  
  7036.  
  7037.  Example
  7038.  
  7039.  The following example uses the  EXP function to calculate the growth of a
  7040.  bacterial colony over a 15-day period. The program prompts you for an
  7041.  initial population and the rate of growth.
  7042.  
  7043.  CLS    ' Clear screen.
  7044.  INPUT "Initial bacterial population"; Colony0
  7045.  INPUT "Growth rate per day as a percentage of population"; Rate
  7046.  R = Rate / 100 : Form$ = "##  ###,###,###,###"
  7047.  PRINT : PRINT "Day        Population"
  7048.  FOR T = 0 TO 15 STEP 5
  7049.      PRINT USING Form$; T, Colony0 * EXP(R * T)
  7050.  NEXT
  7051.  
  7052.  
  7053.  Output
  7054.  
  7055.  Initial bacterial population? 10000
  7056.  Growth rate per day as a percentage of population? 10
  7057.  
  7058.  Day        Population
  7059.   0           10,000
  7060.   5           16,487
  7061.  10           27,183
  7062.  15           44,817
  7063.  
  7064.  
  7065.  FIELD Statement
  7066.  ────────────────────────────────────────────────────────────────────────────
  7067.  
  7068.  
  7069.  Action
  7070.  
  7071.  Allocates space for variables in a random-access file buffer.
  7072.  
  7073.  
  7074.  Syntax
  7075.  
  7076.   FIELD «#»  filenumber%,   fieldwidth%  ASstringvariable$ «,   fieldwidth%
  7077.  ASstringvariable$»...
  7078.  
  7079.  
  7080.  Remarks
  7081.  
  7082.  The  FIELD statement uses the following arguments:
  7083.  
  7084. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  7085.  Argument                                Description
  7086.  ────────────────────────────────────────────────────────────────────────────
  7087.   filenumber%                            The number used in the  OPEN
  7088.                                          statement to open the file.
  7089.  
  7090.   fieldwidth%                            The number of characters in a
  7091.                                          field.
  7092.  
  7093.   stringvariable$                        The string variable that contains
  7094.                                          the data read from a record, or
  7095.                                          data that is used in an assignment
  7096.                                          when information is written to a
  7097.                                          record.
  7098.  
  7099.  
  7100.  
  7101.  The total number of bytes that you allocate in a  FIELD statement must not
  7102.  exceed the record length you specified when opening the file. Otherwise,
  7103.  BASIC generates an error message that reads FIELD overflow. (The default
  7104.  record length is 128 bytes.)
  7105.  
  7106.  Any number of  FIELD statements can be executed for the same file. All
  7107.  FIELD statements that have been executed remain in effect at the same time.
  7108.  
  7109.  All field definitions for a file are removed when the file is closed; that
  7110.  is, all strings defined as fields associated with the file are set to null.
  7111.  
  7112.  
  7113.  Note
  7114.  
  7115.  Do not use a variable name defined as a field in an  INPUT or assignment
  7116.  statement if you want the variable to remain a field. Once a variable name
  7117.  is a field, it points to the correct place in the random-access file buffer.
  7118.  If a subsequent  INPUT or assignment statement with that variable name is
  7119.  executed, the variable's pointer no longer refers to the random-access
  7120.  record buffer, but to string space.
  7121.  
  7122.  
  7123.  BASIC's record variables and extended  OPEN statement syntax provide a more
  7124.  convenient way to use random-access files. See Chapter 3, "File and Device
  7125.  I/O" in the  Programmer's Guide for an extended discussion of using record
  7126.  variables for file I/O.
  7127.  
  7128.  
  7129.  BASICA
  7130.  
  7131.  When a random-access file is closed with a  CLOSE or  RESET statement in a
  7132.  compiled program, all variables that are fields associated with that file
  7133.  are reset to null strings. When a random-access file is closed in a BASICA
  7134.  program, variables that are fields retain the last value assigned to them by
  7135.  a  GET statement.
  7136.  
  7137.  
  7138.  See Also
  7139.  
  7140.   GET (File I/O),  LSET,  PUT (File I/O),  RSET
  7141.  Example
  7142.  
  7143.  The example below illustrates a random-access file buffer with multiple
  7144.  definitions.
  7145.  
  7146.  In the first  FIELD statement, the 67-byte buffer is broken up into five
  7147.  separate variables for name, address, city, state, and zip code. In the
  7148.  second  FIELD statement, the same buffer is assigned entirely to one
  7149.  variable, Plist$.
  7150.  
  7151.  The remainder of this example checks to see if Zip$, which contains the zip
  7152.  code, falls within a certain range; if it does, the complete address string
  7153.  is printed.
  7154.  
  7155.  TYPE Buffer
  7156.     FuName AS STRING * 25
  7157.     Addr   AS STRING * 25
  7158.     City   AS STRING * 10
  7159.     State  AS STRING * 2
  7160.     Zip    AS STRING * 5
  7161.  END TYPE
  7162.  DIM RecBuffer AS Buffer
  7163.  
  7164.  ' This part of the program creates a random-access file for use by the
  7165.  ' second part of the program, which demonstrates the FIELD statement.
  7166.  OPEN "MAILLIST.DAT" FOR RANDOM AS #1 LEN = LEN(RecBuffer)
  7167.  CLS
  7168.  RESTORE
  7169.  READ FuName$, Addr$, City$, State$, Zip$
  7170.  I = 0
  7171.  DO WHILE UCASE$(FuName$) <> "END"
  7172.     I = I + 1
  7173.     RecBuffer.FuName = FuName$
  7174.     RecBuffer.Addr = Addr$
  7175.     RecBuffer.City = City$
  7176.     RecBuffer.State = State$
  7177.     RecBuffer.Zip = Zip$
  7178.     PUT #1, I, RecBuffer
  7179.     READ FuName$, Addr$, City$, State$, Zip$
  7180.     IF FuName$ = "END" THEN EXIT DO
  7181.  LOOP
  7182.  CLOSE #1
  7183.  DATA "Bob Hartzell","1200 Liberty St.","Bow","WA","98232"
  7184.  DATA "Alice Provan","123 B St.","Bellevue","WA","98005"
  7185.  DATA "Alex Landow","14900 123rd","Bothell","WA","98011"
  7186.  DATA "Walt Riley","33 Minnow Lake Road","Lyman","WA","98263"
  7187.  DATA "Georgette Gump","400 15th W.","Bellevue","WA","98007"
  7188.  DATA "END",0,0,0,0,0
  7189.  
  7190.  ' Define field and record lengths with constants.
  7191.  CONST FU = 25, AD = 25, CT = 10, ST = 2, ZP = 5
  7192.  CONST RECLEN = FU + AD + CT + ST + ZP
  7193.  
  7194.  OPEN "MAILLIST.DAT" FOR RANDOM AS #1 LEN = RECLEN
  7195.  FIELD #1, FU AS FuName$, AD AS Addr$, CT AS City$, ST AS State$, ZP AS Zip$
  7196.  FIELD #1, RECLEN AS Plist$
  7197.  GET #1, 1
  7198.  ' Read the file, looking for zip codes in the range 98000 to 98015.
  7199.  DO WHILE NOT EOF(1)
  7200.     Zcheck$ = Zip$
  7201.     IF (Zcheck$ >= "98000" AND Zcheck$ <= "98015") THEN
  7202.        Info$ = Plist$
  7203.        PRINT LEFT$(Info$, 25)
  7204.        PRINT MID$(Info$, 26, 25)
  7205.        PRINT RIGHT$(Info$, 17)
  7206.        PRINT
  7207.     END IF
  7208.     GET #1
  7209.  LOOP
  7210.  CLOSE #1
  7211.  
  7212.  
  7213.  
  7214.  
  7215.  FILEATTR Function
  7216.  ────────────────────────────────────────────────────────────────────────────
  7217.  
  7218.  
  7219.  Action
  7220.  
  7221.  Returns information about an open file or ISAM table.
  7222.  
  7223.  
  7224.  Syntax
  7225.  
  7226.   FILEATTR( filenumber%,  attribute%)
  7227.  
  7228.  
  7229.  Remarks
  7230.  
  7231.   FILEATTR returns information about an open file or ISAM table, such as the
  7232.  DOS file handle and whether the file was opened for input, output, random,
  7233.  append, or ISAM binary mode.
  7234.  
  7235.  The  FILEATTR function uses the following arguments:
  7236.  
  7237. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  7238.  Argument                                Description
  7239.  ────────────────────────────────────────────────────────────────────────────
  7240.   filenumber%                            The number used in the  OPEN
  7241.                                          statement to open the file or ISAM
  7242.                                          table. You can use a numeric
  7243.                                          expression as long as BASIC
  7244.                                          evaluates it to the number of an
  7245.                                          open file, device, or ISAM table.
  7246.  
  7247.  Argument                                Description
  7248.  ────────────────────────────────────────────────────────────────────────────
  7249. 
  7250.   attribute%                             Indicates the type of information
  7251.                                          to return about the file or table.
  7252.                                          When  attribute% is 1,  FILEATTR
  7253.                                          returns a value indicating the
  7254.                                          file's mode (see below). When
  7255.                                          attribute% is 2 and  filenumber%
  7256.                                          indicates a file,  FILEATTR
  7257.                                          returns the DOS handle for the
  7258.                                          file. When  attribute% is 2 and
  7259.                                          filenumber% indicates an ISAM
  7260.                                          table,  FILEATTR returns 0.
  7261.  
  7262.  
  7263.  
  7264.  The following table lists the return values and corresponding file modes
  7265.  when  attribute% is 1:
  7266.  
  7267. ╓┌────────────────────────────┌──────────────────────────────────────────────╖
  7268.  Return value                 Mode
  7269.  ────────────────────────────────────────────────────────────────────────────
  7270.  1                            Input
  7271.  2                            Output
  7272.  4                            Random access
  7273.  8                            Append
  7274.  32                           Binary
  7275.  64                           ISAM
  7276.  
  7277.  
  7278.  See Also
  7279.  
  7280.   OPEN (File I/O)
  7281.  
  7282.  
  7283.  Example
  7284.  
  7285.  The following example opens a file and displays its DOS file handle and
  7286.  mode:
  7287.  
  7288.  OPEN "tempfile.dat" FOR APPEND AS #1
  7289.  PRINT "Handle: "; FILEATTR(1,2); "      Mode: "; FILEATTR(1,1)
  7290.  
  7291.  Output
  7292.  
  7293.  Handle:  5      Mode:  8
  7294.  
  7295.  
  7296.  
  7297.  
  7298.  FILES Statement
  7299.  ────────────────────────────────────────────────────────────────────────────
  7300.  
  7301.  
  7302.  Action
  7303.  
  7304.  Prints the names of files residing on the specified disk.
  7305.  
  7306.  
  7307.  Syntax
  7308.  
  7309.   FILES  «filespec$»
  7310.  
  7311.  
  7312.  Remarks
  7313.  
  7314.  The argument  filespec$ is a string variable or constant that includes
  7315.  either a filename or a path, and an optional device name.
  7316.  
  7317.  If no argument is specified, the  FILES statement lists all the files in the
  7318.  current directory. You can use the DOS wildcard characters -- question
  7319.  marks ( ?) or asterisks (*). A question mark matches any single character in
  7320.  the filename or extension. An asterisk matches one or more characters
  7321.  starting at that position.
  7322.  
  7323.  If you use  filespec$ without an explicit path, the current directory is the
  7324.  default.
  7325.  
  7326.  
  7327.  Examples
  7328.  
  7329.  The statements below illustrate the use of  FILES.
  7330.  
  7331.  Note that execution halts if you try to run this example without a disk in
  7332.  drive B or if the specified files cannot be found.
  7333.  
  7334.  FILES' Show all files on the current directory.
  7335.  FILES "*.BAS" ' Show all files with the extension .BAS.
  7336.  FILES "B:*.*" ' Show all files in current directory of drive B.
  7337.  FILES "B:" ' Equivalent to "B:*.*".
  7338.  FILES "TEST?.BAS" ' Show all five-letter files whose names start
  7339.  ' with "TEST" and end with the .BAS extension.
  7340.  FILES "SALES\"' If SALES is a directory, this statement
  7341.  ' displays all files in SALES.
  7342.  
  7343.  
  7344.  
  7345.  
  7346.  FIX Function
  7347.  ────────────────────────────────────────────────────────────────────────────
  7348.  
  7349.  
  7350.  Action
  7351.  
  7352.  Returns the truncated integer part of a numeric expression.
  7353.  
  7354.  
  7355.  Syntax
  7356.  
  7357.   FIX( x#)
  7358.  
  7359.  
  7360.  Remarks
  7361.  
  7362.  The argument  x# is a numeric expression.  FIX( x#) is equivalent to SGN(
  7363.  x#)*INT(ABS( x#)) . The difference between  FIX and  INT is that for
  7364.  negative  x#,  FIX returns the first negative integer greater than  x#,
  7365.  while  INT returns the first negative integer less than  x#.
  7366.  
  7367.  
  7368.  See Also
  7369.  
  7370.   CINT,  INT
  7371.  
  7372.  
  7373.  Example
  7374.  
  7375.  The following statements illustrate the differences between  INT and  FIX:
  7376.  
  7377.  PRINT INT(-99.8)
  7378.  PRINT FIX(-99.8)
  7379.  PRINT INT(-99.2)
  7380.  PRINT FIX(-99.2)
  7381.  
  7382.  Output
  7383.  
  7384.  -100
  7385.  -99
  7386.  -100
  7387.  -99
  7388.  
  7389.  
  7390.  
  7391.  
  7392.  FOR...NEXT Statement
  7393.  ────────────────────────────────────────────────────────────────────────────
  7394.  
  7395.  
  7396.  Action
  7397.  
  7398.  Repeats a group of instructions a specified number of times.
  7399.  
  7400.  
  7401.  Syntax
  7402.  
  7403.   FOR  counter =  start  TO  end   «STEP  increment»
  7404.      « statementblock»
  7405.      « EXIT  FOR»
  7406.      « statementblock»
  7407.   NEXT   «counter «,  counter»...»
  7408.  
  7409.  
  7410.  Remarks
  7411.  
  7412.  The  FOR statement takes the following arguments:
  7413.  
  7414. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  7415.  Argument                                Description
  7416.  ────────────────────────────────────────────────────────────────────────────
  7417.   counter                                A numeric variable used as the
  7418.                                          loop counter. The variable cannot
  7419.                                          be an array element or a record
  7420.                                          element.
  7421.  
  7422.   start                                  The initial value of the counter.
  7423.  
  7424.   end                                    The final value of the counter.
  7425.  
  7426.   increment                              The amount the counter is changed
  7427.                                          each time through the loop. If you
  7428.                                          do not specify  STEP,  increment
  7429.                                          defaults to one.
  7430.  
  7431.  
  7432.  
  7433.  A  FOR... NEXT loop executes only if  start and  end are consistent with
  7434.  increment. If  end is greater than  start,  increment must be positive. If
  7435.  end is less than  start,  increment must be negative. BASIC checks this at
  7436.  run time by comparing the sign of ( end -  start) with the sign of
  7437.  step. If both have the same sign, the  FOR... NEXT loop is entered. If not,
  7438.  the entire loop is skipped.
  7439.  
  7440.  Within the  FOR... NEXT loop, the program lines following the  FOR statement
  7441.  are executed until the  NEXT statement is encountered. Then  counter is
  7442.  changed by the amount specified by  STEP, and compared with the final value,
  7443.   end.
  7444.  
  7445.  If  start and  end have the same value, the loop executes once, regardless
  7446.  of the value of  STEP. Otherwise,  STEP value controls the loop as follows:
  7447.  
  7448. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  7449.  STEP value                              Loop execution
  7450.  ────────────────────────────────────────────────────────────────────────────
  7451.  Positive                                If  counter is less than or equal
  7452.                                          to  end, control returns to the
  7453.                                          statement after the  FOR statement
  7454.                                          and the process repeats. If
  7455.                                          counter is greater than  end, the
  7456.                                          loop is exited; execution
  7457.  STEP value                              Loop execution
  7458.  ────────────────────────────────────────────────────────────────────────────
  7459.                                         loop is exited; execution
  7460.                                          continues with the statement
  7461.                                          following the  NEXT statement.
  7462.  
  7463.  Negative                                The loop repeats until  counter is
  7464.                                          less than  end.
  7465.  
  7466.  Zero                                    The loop repeats indefinitely.
  7467.  
  7468.  
  7469.  Avoid changing the
  7470.  value of  counter within the loop. Changing the loop counter is poor
  7471.  programming practice; it can make the program more difficult to read and
  7472.  debug.
  7473.  
  7474.  You can nest  FOR... NEXT loops; that is, you can place a  FOR... NEXT loop
  7475.  within another  FOR... NEXT loop. To ensure that nested loops work properly,
  7476.  give each loop a unique variable name as its counter. The  NEXT statement
  7477.  for the inside loop must appear before the  NEXT statement for the outside
  7478.  loop. The following construction is correct:
  7479.  
  7480.  FOR I = 1 TO 10
  7481.     FOR J = 1 TO 10
  7482.        FOR K = 1 TO 10
  7483.        .
  7484.        .
  7485.        .
  7486.        NEXT K
  7487.     NEXT J
  7488.  NEXT I
  7489.  
  7490.  A  NEXT statement with the form NEXT K, J, I is equivalent to the following
  7491.  sequence of statements:
  7492.  
  7493.  NEXT K
  7494.  NEXT J
  7495.  NEXT I
  7496.  
  7497.  The  EXIT FOR statement is a convenient alternative exit from  FOR... NEXT
  7498.  loops. See the entry for  EXIT.
  7499.  
  7500.  
  7501.  Note
  7502.  
  7503.  If you omit the variable in a  NEXT  statement, the  NEXT statement matches
  7504.  the most recent  FOR statement. If a  NEXT statement is encountered before
  7505.  its corresponding  FOR statement, BASIC generates the error message NEXT
  7506.  without FOR.
  7507.  
  7508.  
  7509.  BASICA
  7510.  
  7511.  Unlike BASICA, BASIC supports double-precision control values ( start,  end,
  7512.  and  counter) in its  FOR...NEXT loops. However, if the control values fall
  7513.  within the range for integers, you should use integer control values for
  7514.  maximum speed.
  7515.  
  7516.  
  7517.  Example
  7518.  
  7519.  The following example prints the first 11 columns of Pascal's Triangle, in
  7520.  which each number is the sum of the number immediately above it and the
  7521.  number immediately below it in the preceding column:
  7522.  
  7523.  DEFINT A-Z
  7524.  CLS ' Clear screen.
  7525.  CONST MAXCOL = 11
  7526.  DIM A(MAXCOL, MAXCOL)
  7527.  PRINT "Pascal's Triangle"
  7528.  FOR M = 1 TO MAXCOL
  7529.      A(M, 1) = 1: A(M, M) = 1' Top and bottom of each column is 1.
  7530.  NEXT
  7531.  FOR M = 3 TO MAXCOL
  7532.     FOR N = 2 TO M - 1
  7533.        A(M, N) = A(M - 1, N - 1) + A(M - 1, N)
  7534.     NEXT
  7535.  NEXT
  7536.  Startrow = 13 ' Go to the middle of the screen.
  7537.  FOR M = 1 TO MAXCOL
  7538.     Col = 6 * M
  7539.     Row = Startrow
  7540.     FOR N = 1 TO M
  7541.        LOCATE Row, Col: PRINT A(M, N)
  7542.        Row = Row + 2' Go down 2 rows to print next number.
  7543.     NEXT
  7544.     PRINT
  7545.     Startrow = Startrow - 1' Next column starts 1 row above
  7546.  NEXT' preceding column.
  7547.  
  7548.  Output
  7549.  
  7550.  Pascal's Triangle
  7551.  
  7552.                                                                 1
  7553.                                                         1
  7554.                                                   1            10
  7555.                                             1           9
  7556.                                       1           8            45
  7557.                                 1           7           36
  7558.                           1           6           28          120
  7559.                     1           5           21          84
  7560.               1           4           15          56          210
  7561.         1           3           10          35          126
  7562.   1           2           6           20          70          252
  7563.         1           3           10          35          126
  7564.               1           4           15          56          210
  7565.                     1           5           21          84
  7566.                           1           6           28          120
  7567.                                 1           7           36
  7568.                                       1           8            45
  7569.                                             1           9
  7570.                                                   1            10
  7571.                                                         1
  7572.                                                                 1
  7573.  
  7574.  
  7575.  
  7576.  
  7577.  FRE Function
  7578.  ────────────────────────────────────────────────────────────────────────────
  7579.  
  7580.  
  7581.  Action
  7582.  
  7583.  Returns a value representing the amount of available memory, depending upon
  7584.  a given argument.
  7585.  
  7586.  
  7587.  Syntax 1
  7588.  
  7589.   FRE( numeric- expression%)
  7590.  
  7591.  Syntax 2
  7592.  
  7593.   FRE( stringexpression$)
  7594.  
  7595.  
  7596.  Remarks
  7597.  
  7598.  The argument for  FRE can be either a string or numeric expression . The
  7599.  argument  stringexpression$ can be a string literal or a string variable.
  7600.  
  7601.  The values returned for the different types of arguments depend on whether
  7602.  you are using near strings or far strings, as described in the following
  7603.  table:
  7604. ╓┌──────────────────────┌─────────────────────────┌──────────────────────────╖
  7605.  Function               Value returned if using   Value returned if using
  7606.                         near strings              far strings
  7607.  ────────────────────────────────────────────────────────────────────────────
  7608.  FRE(a$)                Remaining space inDGROUP  Remaining space in  a$'s
  7609.                         (in bytes)                segment (in bytes)
  7610.  
  7611.  FRE("string literal")  Remaining space inDGROUP  Remaining space for
  7612.                         (in bytes)                temporary strings (in
  7613.                                                   bytes)
  7614.  
  7615.  FRE(0)                 Remaining space in        Error message: Illegal
  7616.                         DGROUP (in bytes)         function call
  7617.  
  7618.  FRE(-1)                For DOS, remaining space  For DOS, remaining space
  7619.                         (in bytes) in far         (in bytes) in far memory;
  7620.                         memory; for OS/2, long    for OS/2, long integer
  7621.                         integer 2147483647        2147483647
  7622.  
  7623.  FRE(-2)                Remaining stack space     Remaining stack space (in
  7624.                         (in bytes)                bytes)
  7625.  Function               Value returned if using   Value returned if using
  7626.                         near strings              far strings
  7627.  ────────────────────────────────────────────────────────────────────────────
  7628.                        (in bytes)                bytes)
  7629.  
  7630.  FRE(-3)                Remaining space in        Remaining space in
  7631.                         expanded memory (in       expanded memory (in
  7632.                         kilobytes)                kilobytes)
  7633.  
  7634.  FRE(any other no.)     Error message: Illegal    Error message: Illegal
  7635.                         function call             function call
  7636.  
  7637.  
  7638.  
  7639.  
  7640.  FRE(-2) returns the amount of stack space that was never used by the
  7641.  program. For example, suppose a program uses a lot of stack space in a
  7642.  recursive procedure and then returns to the main level to execute a FRE(-2).
  7643.  The value returned will be the amount of stack space that was never used by
  7644.  the program. Any space used by the recursive procedure is considered "used"
  7645.  So FRE(-2) enables you to find out at the completion of your program what
  7646.  the worst-case stack usage was for that program.
  7647.  
  7648.  
  7649.  Using FRE(-3) and Expanded Memory
  7650.  If expanded memory is not available, FRE(-3) generates the error message
  7651.  Feature unavailable.
  7652.  
  7653.  If you start QBX without the /E: n switch, you will be using all of the
  7654.  expanded memory available on your computer. If you start QBX with the /E: n
  7655.  switch, you can limit the amount of expanded memory available to your
  7656.  program. For example, if your computer has 5 megabytes of expanded memory
  7657.  but you want to use only 4 megabytes of expanded memory, you would start QBX
  7658.  with this command line:
  7659.  
  7660.  QBX /E:4096
  7661.  
  7662.  If you have specified 4 megabytes of expanded memory as shown above, and
  7663.  then you use 2 megabytes of expanded memory in your program, FRE(-3) will
  7664.  return 2048.
  7665.  
  7666.  If you are using BC to run a program with expanded memory overlays, the
  7667.  value returned by FRE(-3) is based on the total amount of expanded memory
  7668.  available. (When using overlays, you cannot limit the amount of expanded
  7669.  memory used by your program.)
  7670.  
  7671.  For more information on using expanded memory, see "Memory Management for
  7672.  QBX" in  Getting Started.
  7673.  
  7674.  
  7675.  Note
  7676.  
  7677.  FRE(-2) returns meaningful values only when a program is executing. Values
  7678.  returned by FRE(-2) are not accurate when the function is called from the
  7679.  Immediate window, during program tracing, or when monitoring a variable.
  7680.  
  7681.  
  7682.  Example
  7683.  
  7684.  The following example demonstrates use of the  FRE function to report the
  7685.  availability of memory resources. It also uses the  STACK function to
  7686.  allocate stack space.
  7687.  
  7688.  DECLARE SUB MakeSubString ()
  7689.  DECLARE SUB Printit (A$)
  7690.  DECLARE SUB Recursive (n!)
  7691.  PRINT "Remaining space to begin with is:"
  7692.  CALL Printit(A$)
  7693.  String1$ = STRING$(32767, 90)' Create a 32K string.
  7694.  PRINT " The remaining space after creating a 32K far string is:"
  7695.  CALL Printit(String1$)
  7696.  MakeSubString ' Make a substring and give report.
  7697.  PRINT "The remaining space after returning from a SUB is:"
  7698.  CALL Printit(String2$)
  7699.  n = 50 ' Do 50 recursive calls to a SUB procedure.
  7700.  CALL Recursive(n)
  7701.  STACK (2048)
  7702.  PRINT "After allocating 2K for the stack, the space is:"
  7703.  CALL Printit(A$)
  7704.  n = 50 ' Do another 50 recursive calls to a SUB procedure.
  7705.  CALL Recursive(n)
  7706.  'Dimension a 1001-element dynamic array in EMS.
  7707.  REDIM A%(999)
  7708.  PRINT "After dimensioning a 1000-element integer array, the space is:"
  7709.  CALL Printit(A$)
  7710.  PRINT "After dimensioning a second 1000-element integer array:"
  7711.  CALL Printit(A$)
  7712.  
  7713.  PRINT "Stack reset to default value: "; STACK
  7714.  
  7715.  SUB MakeSubString
  7716.  SHARED String1$
  7717.      String2$ = STRING$(32767, 90)
  7718.      PRINT "The space remaining after creating a 32K sub string is:"
  7719.      CALL Printit(String1$)
  7720.  END SUB
  7721.  
  7722.  SUB Printit (A$)
  7723.      PRINT : PRINT "Far Memory"; TAB(15); "Stack"; TAB(25);
  7724.      PRINT "String Segment";TAB(45);"Temporary Segment";TAB(65);"EMS Memory"
  7725.      PRINT FRE(-1); TAB(15); FRE(-2); TAB(25); FRE(A$); TAB(45); FRE("")
  7726.      PRINT TAB(65); FRE(-3); "K"
  7727.  END SUB
  7728.  
  7729.  SUB Recursive (n)
  7730.  SHARED String1$
  7731.      n = n - 1
  7732.      IF n = 0 THEN
  7733.          PRINT "The remaining space after 50 recursive calls is:"
  7734.          CALL Printit(String1$)
  7735.          EXIT SUB
  7736.      ELSE
  7737.          CALL Recursive(n)
  7738.      END IF
  7739.  END SUB
  7740.  
  7741.  
  7742.  
  7743.  
  7744.  FREEFILE Function
  7745.  ────────────────────────────────────────────────────────────────────────────
  7746.  
  7747.  
  7748.  Action
  7749.  
  7750.  Returns the next valid unused file number.
  7751.  
  7752.  
  7753.  Syntax
  7754.  
  7755.   FREEFILE
  7756.  
  7757.  
  7758.  Remarks
  7759.  
  7760.  Use  FREEFILE when you need to supply a file number and you want to ensure
  7761.  that the file number is not already in use.
  7762.  
  7763.  
  7764.  See Also
  7765.  
  7766.   OPEN (File I/O)
  7767.  
  7768.  
  7769.  Example
  7770.  
  7771.  The following example uses  FREEFILE to obtain the next available file
  7772.  number for opening a sequential file.  OPEN,  CLOSE, and  KILL also are
  7773.  used.
  7774.  
  7775.  DIM Filenum AS INTEGER
  7776.  CLS
  7777.  INPUT "Enter filename: ", filename$
  7778.  Filenum% = FREEFILE
  7779.  OPEN filename$ FOR OUTPUT AS Filenum%
  7780.  PRINT
  7781.  PRINT UCASE$(filename$); " opened for output as File #"; Filenum%
  7782.  ' Put something out to the file.
  7783.  PRINT #Filenum%, "The quick brown fox jumped over the lazy dog."
  7784.  ' Close the file just opened.
  7785.  CLOSE Filenum%
  7786.  Filenum% = FREEFILE
  7787.  OPEN filename$ FOR INPUT AS Filenum%
  7788.  PRINT : PRINT UCASE$(filename$); " has been reopened for input."
  7789.  LINE INPUT #Filenum%, L$
  7790.  PRINT : PRINT "The contents of the file are:"; L$
  7791.  CLOSE Filenum%
  7792.  ' Remove the file from disk.
  7793.  KILL filename$
  7794.  
  7795.  
  7796.  
  7797.  
  7798.  FUNCTION Statement
  7799.  ────────────────────────────────────────────────────────────────────────────
  7800.  
  7801.  
  7802.  Action
  7803.  
  7804.  Declares the name, the parameters, and the return type of a  FUNCTION
  7805.  procedure.
  7806.  
  7807.  
  7808.  Syntax
  7809.  
  7810.   FUNCTION  name «( parameterlist») « STATIC»
  7811.      « statementblock»
  7812.      « name =  expression»
  7813.      « statementblock»
  7814.      « EXIT  FUNCTION»
  7815.      « statementblock»
  7816.   END FUNCTION
  7817.  
  7818.  
  7819.  Remarks
  7820.  
  7821.  The following list describes the parts of the  FUNCTION statement:
  7822. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  7823.  Part                                    Description
  7824.  ────────────────────────────────────────────────────────────────────────────
  7825.   name                                   The name of the function.
  7826.                                          FUNCTION procedure names follow
  7827.                                          the same rules as are used for
  7828.                                          naming BASIC variables and can
  7829.                                          include a type-declaration
  7830.                                          character  (%,  &,  !,  #,  @,
  7831.                                          or  $). Note that the type of the
  7832.                                          name determines the data type the
  7833.                                          function returns. For example, to
  7834.                                          create a function that returns a
  7835.  Part                                    Description
  7836.  ────────────────────────────────────────────────────────────────────────────
  7837.                                         create a function that returns a
  7838.                                          string, you would include a dollar
  7839.                                          sign in the name or give it a name
  7840.                                          defined as a string name by a
  7841.                                          DEFSTR statement.
  7842.  
  7843.   parameterlist                          The list of variables,
  7844.                                          representing parameters, that will
  7845.                                          be passed to the function
  7846.                                          procedure when it is called.
  7847.                                          Multiple variables are separated
  7848.                                          by commas. Parameters are passed
  7849.                                          by reference, so any change to a
  7850.                                          parameter's value inside the
  7851.                                          function changes its value in the
  7852.                                          calling program.
  7853.  
  7854.   STATIC                                 Indicates that the function's
  7855.                                          local variables are to be saved
  7856.  Part                                    Description
  7857.  ────────────────────────────────────────────────────────────────────────────
  7858.                                         local variables are to be saved
  7859.                                          between calls. Without  STATIC,
  7860.                                          the local variables are allocated
  7861.                                          each time the function is invoked,
  7862.                                          and the variables' values are lost
  7863.                                          when the function returns to the
  7864.                                          calling program. The  STATIC
  7865.                                          attribute does not affect
  7866.                                          variables that are used in a
  7867.                                          FUNCTION procedure but declared
  7868.                                          outside the procedure in  DIM or
  7869.                                          COMMON statements using the
  7870.                                          SHARED statement.
  7871.  
  7872.   expression                             The return value of the function.
  7873.                                          A  FUNCTION procedure returns a
  7874.                                          value by assigning a value to the
  7875.                                          function name. If no value is
  7876.                                          assigned to the  FUNCTION name,
  7877.  Part                                    Description
  7878.  ────────────────────────────────────────────────────────────────────────────
  7879.                                         assigned to the  FUNCTION name,
  7880.                                          the procedure returns a default
  7881.                                          value: a numeric function returns
  7882.                                          zero, and a string function
  7883.                                          returns the null string ("").
  7884.  
  7885.   EXIT FUNCTION                          Causes an immediate exit from a
  7886.                                          FUNCTION procedure. Program
  7887.                                          execution continues where the
  7888.                                          procedure was invoked. For more
  7889.                                          information, see the entry for the
  7890.                                           EXIT statement.
  7891.  
  7892.  
  7893.  
  7894.  The argument  parameterlist has the following syntax:
  7895.  
  7896.   variable «()» « AS  type» «,  variable«()» « AS  type»»...
  7897.  
  7898.  The following list describes the parts of  parameterlist :
  7899. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  7900.  Argument                                Description
  7901.  ────────────────────────────────────────────────────────────────────────────
  7902.   variable                               A BASIC variable name. Previous
  7903.                                          versions of BASIC required the
  7904.                                          number of dimensions in
  7905.                                          parentheses after an array name.
  7906.                                          In the current version of BASIC,
  7907.                                          the number of dimensions is not
  7908.                                          required.
  7909.  
  7910.   AS  type                               The type of the variable:  INTEGER,
  7911.                                           LONG,  SINGLE,  DOUBLE,  STRING,
  7912.                                          CURRENCY, or a user-defined type.
  7913.                                          You cannot use a fixed-length
  7914.                                          string, or an array of
  7915.                                          fixed-length strings, as a
  7916.                                          parameter. However, you can use a
  7917.                                          simple fixed-length string as an
  7918.                                          argument in a  CALL statement;
  7919.  Argument                                Description
  7920.  ────────────────────────────────────────────────────────────────────────────
  7921.                                         argument in a  CALL statement;
  7922.                                          BASIC converts a simple
  7923.                                          fixed-length string argument to a
  7924.                                          variable-length string argument
  7925.                                          before passing the string to a
  7926.                                          FUNCTION procedure.
  7927.  
  7928.  
  7929.  
  7930.  
  7931.  Earlier versions of BASIC required the number of dimensions in parentheses
  7932.  after an array name. The number of dimensions is no longer required. Only
  7933.  the parentheses are required to indicate the parameter is an array. For
  7934.  example, the following statement indicates that both Keywords$ and
  7935.  KeywordTypes are arrays:
  7936.  
  7937.  FUNCTION ParseLine(Keywords$(),KeywordTypes())
  7938.  
  7939.  A  FUNCTION procedure is like a  SUB procedure: it can accept parameters,
  7940.  perform a series of statements, and change the values of its parameters.
  7941.  Unlike a  SUB procedure, a  FUNCTION procedure is used in an expression in
  7942.  the same manner as a BASIC intrinsic function.
  7943.  
  7944.  Like  SUB procedures,  FUNCTION procedures use local variables. Any variable
  7945.  referred to within the body of the function is local to the  FUNCTION
  7946.  procedure unless one of the following conditions is true:
  7947.  
  7948.    ■         The variable is declared within the function as a shared
  7949.              variable with a  SHARED statement.
  7950.  
  7951.    ■         The variable appears in a  DIM or  COMMON statement with the
  7952.              SHARED attribute at the module level.
  7953.  
  7954.  To return a value from a function, assign the value to the function name.
  7955.  For example, in a function named BinarySearch, you might assign the value of
  7956.  the constant FALSE to the name to indicate the value was not found:
  7957.  
  7958.  FUNCTION BinarySearch(...)
  7959.  CONST FALSE=0
  7960.  .
  7961.  .
  7962.  .
  7963.  ' Value not found. Return a value of FALSE.
  7964.  IF Lower>Upper THEN
  7965.  BinarySearch=FALSE
  7966.  EXIT FUNCTION
  7967.  END IF
  7968.  .
  7969.  .
  7970.  .
  7971.  END FUNCTION
  7972.  
  7973.  Using the  STATIC attribute increases execution speed slightly.  STATIC
  7974.  usually is not used with recursive  FUNCTION procedures.
  7975.  
  7976.  
  7977.  Note
  7978.  
  7979.  Avoid using I/O statements in a  FUNCTION procedure called from an I/O
  7980.  statement; they can cause unpredictable results. Also, because BASIC may
  7981.  rearrange arithmetic expressions to attain greater efficiency, avoid using
  7982.  FUNCTION procedures that change program variables in arithmetic expressions.
  7983.  
  7984.  
  7985.   FUNCTION procedures are recursive -- they can call themselves to
  7986.  perform a given task. See the example for more information.
  7987.  
  7988.  
  7989.  See Also
  7990.  
  7991.   DECLARE (BASIC),  DEF FN,  STATIC Statement,  SUB
  7992.  
  7993.  
  7994.  Example
  7995.  
  7996.  The following example uses a recursive  FUNCTION procedure (a procedure that
  7997.  calls itself) to find, and return as an integer, the length of a string:
  7998.  
  7999.  DECLARE FUNCTION StrgLng% (X$).
  8000.  INPUT "Enter a string: "; InString$
  8001.  PRINT "The string length is"; StrgLng%(InString$)
  8002.  
  8003.  FUNCTION StrgLng% (X$)
  8004.     IF X$ = "" THEN
  8005.        StrLng% = 0 ' The length of a null string is zero.
  8006.     ELSE
  8007.        StrgLng% = 1 + StrgLng%(MID$(X$, 2))  ' Make a recursive call.
  8008.     END IF
  8009.  END FUNCTION
  8010.  
  8011.  
  8012.  
  8013.  
  8014.  GET Statement (File I/O)
  8015.  ────────────────────────────────────────────────────────────────────────────
  8016.  
  8017.  
  8018.  Action
  8019.  
  8020.  Reads from a disk file into a random-access buffer or variable.
  8021.  
  8022.  
  8023.  Syntax
  8024.  
  8025.   GET «#» filenumber%«,« recordnumber%» «,  variable»»
  8026.  
  8027.  
  8028.  Remarks
  8029.  
  8030.  Do not use  GET on ISAM files.
  8031.  
  8032.  The  GET statement uses the following arguments:
  8033. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  8034.  Argument                                Description
  8035.  ────────────────────────────────────────────────────────────────────────────
  8036.   filenumber%                            The number used in the  OPEN
  8037.                                          statement to open the file.
  8038.  
  8039.   recordnumber%                          For random-access files, the
  8040.                                          number of the record to be read.
  8041.                                          For binary-mode files, the byte
  8042.                                          position where reading starts. The
  8043.                                          first record or byte position in a
  8044.                                          file is 1. If you omit
  8045.  Argument                                Description
  8046.  ────────────────────────────────────────────────────────────────────────────
  8047.                                         file is 1. If you omit
  8048.                                          recordnumber%, the next record or
  8049.                                          byte (the one after the last  GET
  8050.                                          or  PUT statement, or the one
  8051.                                          pointed to by the last  SEEK) is
  8052.                                          read into the buffer. The largest
  8053.                                          possible record number is 2to31 -1,
  8054.                                          or 2,147,483,647.
  8055.  
  8056.   variable                               The variable used to receive input
  8057.                                          from the file. If you specify a
  8058.                                          variable, you do not need to use
  8059.                                          CVI,  CVL,  CVS,  CVD, or  CVC to
  8060.                                          convert record fields to numbers.
  8061.                                          You cannot use a  FIELD statement
  8062.                                          with the file if you use the
  8063.                                          variable argument.
  8064.  
  8065.                                          For random-access files, you can
  8066.  Argument                                Description
  8067.  ────────────────────────────────────────────────────────────────────────────
  8068.                                         For random-access files, you can
  8069.                                          use any variable as long as the
  8070.                                          length of the variable is less
  8071.                                          than or equal to the length of the
  8072.                                          record. Usually, a record variable
  8073.                                          defined to match the fields in a
  8074.                                          data record is used.
  8075.  
  8076.                                          For binary-mode files, you can use
  8077.                                          any variable. The  GET statement
  8078.                                          reads as many bytes as there are
  8079.                                          in the variable.
  8080.  
  8081.                                          When you use a variable-length
  8082.                                          string variable, the statement
  8083.                                          reads as many bytes as there are
  8084.                                          characters in the string's value.
  8085.                                          For example, the following two
  8086.                                          statements read 10 bytes from file
  8087.  Argument                                Description
  8088.  ────────────────────────────────────────────────────────────────────────────
  8089.                                         statements read 10 bytes from file
  8090.                                          number 1:
  8091.  
  8092.                                          VarStrings$=STRING$ (10, " ")
  8093.                                          GET #1,,VarString$
  8094.  
  8095.                                          See the examples for more
  8096.                                          information about using variables
  8097.                                          rather than  FIELD statements for
  8098.                                          random-access files.
  8099.  
  8100.  
  8101.  
  8102.  A record cannot be longer than 32,767 bytes.
  8103.  
  8104.  You can omit  recordnumber%,  variable, or both. If you omit  recordnumber%
  8105.  but include a variable, you must still include the commas:
  8106.  
  8107.  GET #4,,FileBuffer
  8108.  
  8109.  If you omit both arguments, do not include the commas:
  8110.  
  8111.  GET #4
  8112.  
  8113.   GET and  PUT statements allow fixed-length input and output for BASIC
  8114.  communication files. Use  GET carefully, because if there is a communication
  8115.  failure,  GET waits indefinitely.
  8116.  
  8117.  
  8118.  Note
  8119.  
  8120.  When you use  GET with the  FIELD statement, you can use  INPUT # or  LINE
  8121.  INPUT # after a  GET statement to read characters from the random-access
  8122.  file buffer. You can use the  EOF function after a  GET statement to see if
  8123.  the  GET operation went beyond the end of the file.
  8124.  
  8125.  
  8126.  See Also
  8127.  
  8128.   CVI,  CVL,  CVS,  CVD,  CVC;  LSET;  MKI$,  MKL$,  MKS$,  MKD$,  MKC$; OPEN
  8129.  (File I/O);  PUT (File I/O)
  8130.  
  8131.  
  8132.  Example
  8133.  
  8134.  The following example creates a random-access test file that contains five
  8135.  names and corresponding test scores. It then displays the contents of the
  8136.  file using the  GET statement.
  8137.  
  8138.  ' Define record fields.
  8139.  TYPE TestRecord
  8140.      NameField  AS STRING * 20
  8141.      ScoreField AS SINGLE
  8142.  END TYPE
  8143.  ' Define a variable of the user type.
  8144.  DIM Rec AS TestRecord
  8145.  DIM I AS LONG
  8146.  
  8147.  ' This part of the program creates a random-access file to be used by
  8148.  ' the second part of the program, which demonstrates the GET statement.
  8149.  OPEN "TESTDAT2.DAT" FOR RANDOM AS #1 LEN = LEN(Rec)
  8150.  CLS
  8151.  RESTORE
  8152.  READ NameField$, ScoreField
  8153.  I = 0
  8154.  DO WHILE NameField$ <> "END"
  8155.      I = I + 1
  8156.      Rec.NameField = NameField$
  8157.      Rec.ScoreField = ScoreField
  8158.      PUT #1, I, Rec
  8159.      READ NameField$, ScoreField
  8160.  LOOP
  8161.  CLOSE #1
  8162.  DATA "John Simmons", 100
  8163.  DATA "Allie Simpson", 95
  8164.  DATA "Tom Tucker", 72
  8165.  DATA "Walt Wagner", 90
  8166.  DATA "Mel Zucker", 92
  8167.  DATA "END", 0
  8168.  
  8169.  ' Open the test data file.
  8170.  DIM FileBuffer AS TestRecord
  8171.  DIM Max AS LONG
  8172.  OPEN "TESTDAT2.DAT" FOR RANDOM AS #1 LEN = LEN(FileBuffer)
  8173.  'Calculate number of records in the file.
  8174.  Max = LOF(1) \ LEN(FileBuffer)
  8175.  
  8176.  ' Read and print contents of each record.
  8177.  FOR I = 1 TO Max
  8178.      GET #1, I, FileBuffer
  8179.      PRINT FileBuffer.NameField, FileBuffer.ScoreField
  8180.  NEXT I
  8181.  CLOSE #1
  8182.  ' Remove file from disk.
  8183.  KILL "TESTDAT2.DAT"
  8184.  END
  8185.  
  8186.  
  8187.  
  8188.  
  8189.  GET Statement (Graphics)
  8190.  ────────────────────────────────────────────────────────────────────────────
  8191.  
  8192.  
  8193.  Action
  8194.  
  8195.  Stores graphic images from the screen.
  8196.  
  8197.  
  8198.  Syntax
  8199.  
  8200.  
  8201.   GET   STEP( x1!,  y1!) -  STEP( x2!,  y2!),  arrayname(
  8202.  indexes%)
  8203.  
  8204.  
  8205.  Remarks
  8206.  
  8207.  The list below describes the parts of the  GET statement:
  8208.  
  8209. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  8210.  Part                                    Description
  8211.  ────────────────────────────────────────────────────────────────────────────
  8212.  ( x1!,  y1!),( x2!,  y2!)               Coordinates that mark a
  8213.  Part                                    Description
  8214.  ────────────────────────────────────────────────────────────────────────────
  8215.  ( x1!,  y1!),( x2!,  y2!)               Coordinates that mark a
  8216.                                          rectangular area on the screen; an
  8217.                                          image within this rectangle will
  8218.                                          be stored. The  x1!,   y1!,   x2!,
  8219.                                          and  y2! are numeric expressions.
  8220.                                          The coordinates ( x1!,  y1!) and (
  8221.                                          x2!,  y2!) are the coordinates of
  8222.                                          diagonally opposite corners of the
  8223.                                          rectangle.
  8224.  
  8225.   STEP                                   Keyword indicating that
  8226.                                          coordinates are relative to the
  8227.                                          most recently plotted point. For
  8228.                                          example, if the last point plotted
  8229.                                          were (10,10), the actual
  8230.                                          coordinates referred to by STEP
  8231.                                          (5,10) would be (5+10,10+10) or
  8232.                                          (15,20). If the second coordinate
  8233.                                          pair in a  GET statement has a
  8234.  Part                                    Description
  8235.  ────────────────────────────────────────────────────────────────────────────
  8236.                                         pair in a  GET statement has a
  8237.                                          STEP argument, it is relative to
  8238.                                          the first coordinate pair in the
  8239.                                          statement.
  8240.  
  8241.   arrayname                              Name assigned to the array that
  8242.                                          holds the image. This array can be
  8243.                                          of any numeric type; its
  8244.                                          dimensions must be large enough to
  8245.                                          hold the entire image.
  8246.  
  8247.   indexes%                               Numeric constants or variables
  8248.                                          indicating the element of the
  8249.                                          array where the saved image starts.
  8250.  
  8251.  
  8252.  
  8253.  
  8254.  
  8255.  The  GET statement transfers a screen image into the array specified by
  8256.  arrayname. The  PUT statement, associated with  GET, transfers the image
  8257.  stored in the array onto the screen.
  8258.  
  8259.  The following formula gives the required size of the array in bytes:
  8260.  
  8261.  size = 4 + INT((( x2! -  x1! + 1) * ( bits-per-pixel-per-plane) +
  8262.  7)/8) *  planes * ((  y2! -  y1!) + 1)
  8263.  
  8264.  The  bits-per-pixel-per-plane and  planes values depend on the screen mode
  8265.  set by the  SCREEN statement. The following table shows the number of
  8266.  bits-per-pixel-per-plane and the number of planes for each screen mode:
  8267. ╓┌────────────────────────┌─────────────────────────┌────────────────────────╖
  8268.  Screen mode              Bits per pixel per plane  Planes
  8269.  ────────────────────────────────────────────────────────────────────────────
  8270.  1                        2                         1
  8271.  2                        1                         1
  8272.  7                        1                         4
  8273.  8                        1                         4
  8274.  9 (64K of EGA  memory)   1                         2
  8275.  9 (> 64K of EGA memory)  1                         4
  8276.  Screen mode              Bits per pixel per plane  Planes
  8277.  ────────────────────────────────────────────────────────────────────────────
  8278. 9 (> 64K of EGA memory)  1                         4
  8279.  10                       1                         2
  8280.  11                       1                         1
  8281.  12                       1                         4
  8282.  13                       8                         1
  8283.  
  8284.  
  8285.  The bytes per element of an array are as follows:
  8286.  
  8287.    ■         Two bytes for an integer array element.
  8288.  
  8289.    ■         Four bytes for a long-integer array element.
  8290.  
  8291.    ■         Four bytes for a single-precision array element.
  8292.  
  8293.    ■         Eight bytes for a double-precision array element.
  8294.  
  8295.    ■         Eight bytes for a currency array element.
  8296.  
  8297.  For example, suppose you wanted to use the  GET statement to store an image
  8298.  in high resolution (SCREEN 2).  If the coordinates of the upper-left corner
  8299.  of the image are (0,0), and the coordinates of the lower-right corner are
  8300.  (32,32), then the required size of the array in bytes is 4 + INT((33 * 1 +
  8301.  7)/8) * 1 * (33), or 169. This means an integer array with 85 elements would
  8302.  be large enough to hold the image.
  8303.  
  8304.  Unless the array type is integer or long, the contents of an array after a
  8305.  GET operation appear meaningless when inspected directly. Examining or
  8306.  manipulating noninteger arrays containing graphics images may cause run-time
  8307.  errors.
  8308.  
  8309.   GET and  PUT statements operating on the same image should be executed in
  8310.  matching screen modes. These modes can be either the same screen mode or any
  8311.  screen modes with the same values for planes and bits-per-pixel-per-plane.
  8312.  
  8313.  One of the most useful things that can be done with  GET and  PUT statements
  8314.  is animation. See Chapter 5, "Graphics" in the  Programmer's Guide for a
  8315.  discussion of animation.
  8316.  
  8317.  
  8318.  See Also
  8319.  
  8320.   PUT (Graphics)
  8321.  
  8322.  
  8323.  Example
  8324.  
  8325.  See the  BSAVE statement programming example, which uses the  GET statement.
  8326.  
  8327.  
  8328.  
  8329.  
  8330.  GETINDEX$ Function
  8331.  ────────────────────────────────────────────────────────────────────────────
  8332.  
  8333.  
  8334.  Action
  8335.  
  8336.  Returns the name of the current index for an ISAM table.
  8337.  
  8338.  
  8339.  Syntax
  8340.  
  8341.   GETINDEX$ ( filenumber%)
  8342.  
  8343.  
  8344.  Remarks
  8345.  
  8346.  The  filenumber% is the number used in the  OPEN statement to open the
  8347.  table.
  8348.  
  8349.   GETINDEX$ takes the number of an open ISAM table and returns the name of
  8350.  the current index. If the current index is the null index , the value
  8351.  returned is a null string.
  8352.  
  8353.  
  8354.  See Also
  8355.  
  8356.   CREATEINDEX,  DELETEINDEX,  OPEN (File I/O),  SETINDEX
  8357.  
  8358.  
  8359.  Example
  8360.  
  8361.  See the  CREATEINDEX statement programming example, which uses the
  8362.  GETINDEX$ function.
  8363.  
  8364.  
  8365.  
  8366.  
  8367.  GOSUB...RETURN Statements
  8368.  ────────────────────────────────────────────────────────────────────────────
  8369.  
  8370.  
  8371.  Action
  8372.  
  8373.  Branch to, and return from, a subroutine.
  8374.  
  8375.  
  8376.  Syntax
  8377.  
  8378.   GOSUB { linelabel1 |  linenumber1}
  8379.   .
  8380.   .
  8381.   .
  8382.   RETURN  «{ linelabel2 |  linenumber2}»
  8383.  
  8384.  
  8385.  Remarks
  8386.  
  8387.  The  GOSUB... RETURN statements use the following arguments:
  8388.  
  8389. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  8390.  Argument                                Description
  8391.  ────────────────────────────────────────────────────────────────────────────
  8392.   linelabel1, linenumber1                The line label or line number that
  8393.                                          is the first line of the
  8394.                                          subroutine.
  8395.  
  8396.   linelabel2, linenumber2                The line label or line number
  8397.                                          where the subroutine returns.
  8398.  
  8399.  
  8400.  
  8401.  
  8402.  
  8403.  Note
  8404.  
  8405.  BASIC's  SUB and  FUNCTION procedures provide a  better-structured
  8406.  alternative to  GOSUB... RETURN subroutines.
  8407.  
  8408.  
  8409.  In addition to  RETURN with no argument, BASIC supports  RETURN with a line
  8410.  label or line number. This allows a return from a subroutine to the
  8411.  statement having the specified line label or number, instead of returning to
  8412.  the statement after the  GOSUB statement. Use this line-specific type of
  8413.  return with care.
  8414.  
  8415.  You can call a subroutine any number of times in a program. You also can
  8416.  call a subroutine from within another subroutine. How deeply you can nest
  8417.  subroutines is limited only by the available stack space (you can increase
  8418.  the stack space with the  CLEAR statement). Subroutines that call themselves
  8419.  (recursive subroutines) can easily run out of stack space.  RETURN with a
  8420.  line label or line number can return control to a statement in the
  8421.  module-level code only, not in procedure-level code. See the example
  8422.  program.
  8423.  
  8424.  A subroutine can contain more than one  RETURN statement. A simple  RETURN
  8425.  statement (without the  linelabel2,  linenumber2 option) in a subroutine
  8426.  makes BASIC branch back to the statement following the most recent  GOSUB
  8427.  statement.
  8428.  
  8429.  Subroutines can appear anywhere in the program, but it is good programming
  8430.  practice to make them readily distinguishable from the main program. To
  8431.  prevent inadvertent entry into a subroutine, precede it with a  STOP,  END,
  8432.  or  GOTO statement that directs program control around the subroutine.
  8433.  
  8434.  
  8435.  Note
  8436.  
  8437.  The preceding discussion of subroutines applies only to the targets of
  8438.  GOSUB  statements, not procedures delimited by  SUB statements. For
  8439.  information on entering and exiting  SUB procedures, see the entry for the
  8440.  CALL statement (BASIC procedures).
  8441.  
  8442.  
  8443.  See Also
  8444.  
  8445.   RETURN,  SUB
  8446.  
  8447.  
  8448.  Example
  8449.  
  8450.  The following example shows the use of the  GOSUB and  RETURN statements.
  8451.  
  8452.  Note the  END statement before the module-level subroutine. If it is not
  8453.  present, the PrintMessage subroutine will be executed after the return to
  8454.  Label1. BASIC will generate the error message RETURN without GOSUB.
  8455.  
  8456.  CLS
  8457.  GOSUB PrintMessage
  8458.  PRINT "This message is in module-level code"
  8459.  GOSUB Sub1
  8460.  PRINT "This line in module-level code should be skipped."
  8461.  Label1:
  8462.     PRINT "This message is back in module-level code"
  8463.  END
  8464.  
  8465.  PrintMessage:
  8466.     PRINT "This program uses the GOSUB and RETURN statements."
  8467.     PRINT
  8468.     RETURN
  8469.  
  8470.  Sub1:
  8471.     PRINT "This message is in Sub1."
  8472.     GOSUB Sub2
  8473.     PRINT "This line in Sub1 should be skipped."
  8474.  Label2:
  8475.     PRINT "This message is back in Sub1."
  8476.     RETURN Label1
  8477.  
  8478.  Sub2:
  8479.     PRINT "This message is in Sub2."
  8480.     RETURN Label2   ' Cannot return from here to module-level
  8481.                     ' code-only to SUB1.
  8482.  
  8483.  
  8484.  
  8485.  
  8486.  GOTO Statement
  8487.  ────────────────────────────────────────────────────────────────────────────
  8488.  
  8489.  
  8490.  Action
  8491.  
  8492.  Branches unconditionally to the specified line.
  8493.  
  8494.  
  8495.  Syntax
  8496.  
  8497.   GOTO { linelabel |  linenumber}
  8498.  
  8499.  
  8500.  Remarks
  8501.  
  8502.  The argument  linelabel or  linenumber indicates the line to execute next.
  8503.  This line must be at the same level of the program. The  GOTO statement
  8504.  provides a means for branching unconditionally to another line ( linelabel
  8505.  or  linenumber). A  GOTO statement can branch only to another statement at
  8506.  the same level within a program. You cannot use  GOTO to enter or exit a
  8507.  SUB or  FUNCTION procedure or multiline  DEF FN function. You can, however,
  8508.  use  GOTO to control program flow within any of these program structures.
  8509.  
  8510.  It is good programming practice to use structured control statements ( DO...
  8511.  LOOP,  FOR... NEXT,  IF... THEN... ELSE,  SELECT CASE) instead of  GOTO
  8512.  statements, because a program with many  GOTO statements can be difficult to
  8513.  read and debug.
  8514.  
  8515.  
  8516.  Example
  8517.  
  8518.  The following example calculates the area of a circle. The program uses the
  8519.  GOTO statement to repeat the operation.
  8520.  
  8521.  CLS      ' Clear screen.
  8522.  PRINT "Input 0 to end."
  8523.  Start:
  8524.     INPUT R
  8525.     IF R = 0 THEN
  8526.       END
  8527.     ELSE
  8528.        A = 3.14 * R ^ 2
  8529.        PRINT "Area ="; A
  8530.     END IF
  8531.  GOTO Start
  8532.  
  8533.  Output
  8534.  
  8535.  Input 0 to end.
  8536.  ? 5
  8537.  Area = 78.5
  8538.  ? 0
  8539.  
  8540.  
  8541.  
  8542.  
  8543.  HEX$ Function
  8544.  ────────────────────────────────────────────────────────────────────────────
  8545.  
  8546.  
  8547.  Action
  8548.  
  8549.  Returns a string that represents the hexadecimal value of the decimal
  8550.  argument.
  8551.  
  8552.  
  8553.  Syntax
  8554.  
  8555.   HEX$( numeric-expression&)
  8556.  
  8557.  
  8558.  Remarks
  8559.  
  8560.  The argument  numeric-expression&, which has a decimal value,  is rounded to
  8561.  an integer or, if it is outside the integer range, a long integer, before
  8562.  the  HEX$ function evaluates it.
  8563.  
  8564.  
  8565.  See Also
  8566.  
  8567.   OCT$
  8568.  
  8569.  
  8570.  Example
  8571.  
  8572.  The following example displays the hexadecimal value of a decimal number:
  8573.  
  8574.  CLS          ' Clear screen.
  8575.  INPUT X
  8576.  A$ = HEX$(X)
  8577.  PRINT X; "decimal is "; A$; " hexadecimal."
  8578.  
  8579.  Output
  8580.  
  8581.  ? 32
  8582.   32 decimal is 20 hexadecimal.
  8583.  
  8584.  
  8585.  
  8586.  
  8587.  IF...THEN...ELSE Statement
  8588.  ────────────────────────────────────────────────────────────────────────────
  8589.  
  8590.  
  8591.  Action
  8592.  
  8593.  Allows conditional execution, based on the evaluation of a Boolean
  8594.  expression.
  8595.  
  8596.  
  8597.  Syntax 1
  8598.  
  8599.   IF  condition  THEN  thenpart  « ELSE  elsepart»
  8600.  
  8601.  Syntax 2
  8602.  
  8603.   IF  condition1  THEN
  8604.      « statementblock-1»
  8605.  « ELSEIF  condition2  THEN
  8606.      « statementblock-2»»
  8607.  « ELSE
  8608.      « statementblock-n»»
  8609.   END  IF
  8610.  
  8611.  
  8612.  Remarks
  8613.  
  8614.  Single-Line IF...THEN...ELSE
  8615.  The single-line form of the statement (Syntax 1) is best used for short,
  8616.  straightforward tests where only one action is taken.
  8617.  
  8618.  The single-line form is never required. Any program using single-line  IF...
  8619.  THEN... ELSE statements can be written using block form.
  8620.  
  8621.  The following list describes the parts of the single-line form:
  8622.  
  8623. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  8624.  Part                                    Description
  8625.  ────────────────────────────────────────────────────────────────────────────
  8626.   condition                              Any expression that BASIC
  8627.                                          evaluates as true (nonzero) or
  8628.                                          false (zero).
  8629.  
  8630.   thenpart,  elsepart                    The statements or branches
  8631.                                          performed when  condition is true
  8632.                                          ( thenpart) or false ( elsepart).
  8633.  Part                                    Description
  8634.  ────────────────────────────────────────────────────────────────────────────
  8635.                                         ( thenpart) or false ( elsepart).
  8636.                                          Both parts have the same syntax,
  8637.                                          which is described below.
  8638.  
  8639.  
  8640.  
  8641.  The  thenpart and the  elsepart fields both have the following syntax:
  8642.  
  8643.  { statements |  « GOTO»  linenumber |  GOTO  linelabel }
  8644.  
  8645.  The following list describes the parts of the  thenpart and  elsepart
  8646.  syntax:
  8647. ╓┌───────────────┌───────────────────────────────────────────────────────────╖
  8648.  Part            Description
  8649.  ────────────────────────────────────────────────────────────────────────────
  8650.   statements     One or more BASIC statements, separated by colons.
  8651.   linenumber     A valid BASIC program line number.
  8652.   linelabel      A valid BASIC program line label.
  8653.  
  8654.  
  8655.  Note that  GOTO is optional with a line number, but is required with a line
  8656.  label.
  8657.  
  8658.  The  thenpart is executed if  condition is true; if  condition is false,
  8659.  elsepart is executed. If the  ELSE clause is not present, control passes to
  8660.  the next statement in the program.
  8661.  
  8662.  You can have multiple statements with a condition, but they must be on the
  8663.  same line and separated by colons, as in the following statement:
  8664.  
  8665.  IF A > 10 THEN A=A+1:B=B+A:LOCATE 10,22:PRINT B,A
  8666.  
  8667.  Block IF...THEN...ELSE
  8668.  The block form (Syntax 2) provides several advantages:
  8669.  
  8670.    ■         The block form provides more structure and flexibility than the
  8671.              single-line form by allowing conditional branches across several
  8672.              lines.
  8673.  
  8674.    ■         With the block form, more complex conditions can be tested.
  8675.  
  8676.    ■         The block form lets you use longer statements and structures
  8677.              within the  THEN... ELSE portion of the statement.
  8678.  
  8679.    ■         The block form allows your program's structure to be guided by
  8680.              logic rather than by how many statements fit on a line.
  8681.  
  8682.  Programs that use block  IF... THEN... ELSE are usually easier to read,
  8683.  maintain, and debug.
  8684.  
  8685.  The following list describes the parts of the block  IF... THEN... ELSE:
  8686. ╓┌─────────────────────────────────────┌─────────────────────────────────────╖
  8687.  ────────────────────────────────────────────────────────────────────────────
  8688.   condition1,  condition2              Any expression that BASIC evaluates
  8689.                                        as true (nonzero) or false (zero).
  8690.  
  8691.   statementblock-1,  statementblock-2   One or more BASIC statements on one
  8692.  , statementblock-n                    or more lines.
  8693.  
  8694.  
  8695.  In executing a block  IF, BASIC tests  condition1, the first Boolean
  8696.  expression. If the Boolean expression is true (nonzero), the statements
  8697.  following  THEN are executed. If the first Boolean expression is false
  8698.  (zero), BASIC begins evaluating each  ELSEIF condition in turn. When BASIC
  8699.  finds a true condition, the statements following the associated  THEN are
  8700.  executed. If none of the  ELSEIF conditions is true, the statements
  8701.  following the  ELSE are executed. After the statements following a  THEN or
  8702.  ELSE are executed, the program continues with the statement following the
  8703.  END IF.
  8704.  
  8705.  The  ELSE and  ELSEIF blocks are both optional. You can have as many  ELSEIF
  8706.  clauses as you would like in a block  IF. Any of the statement blocks can
  8707.  contain nested block  IF statements.
  8708.  
  8709.  BASIC looks at what appears after the  THEN keyword to determine whether or
  8710.  not an  IF statement is a block  IF. If anything other than a comment
  8711.  appears after  THEN, the statement is treated as a single-line  IF
  8712.  statement.
  8713.  
  8714.  A block  IF statement
  8715.  must be the first statement on a line. The  ELSE,  ELSEIF, and  END IF parts
  8716.  of the statement can have only a line number or line label in front of them.
  8717.  The block  must end with an  END IF statement.
  8718.  
  8719.  For more information, see Chapter 1, "Control-Flow Structures" in the
  8720.  Programmer's Guide.
  8721.  
  8722.  
  8723.  See Also
  8724.  
  8725.   SELECT CASE
  8726.  
  8727.  
  8728.  Examples
  8729.  
  8730.  The following examples show the use of single-line and block  IF... THEN...
  8731.  ELSE statements.
  8732.  
  8733.  Here is the single-line form:
  8734.  
  8735.  CLS    ' Clear screen.
  8736.  DO
  8737.     INPUT "Enter a number greater than 0 and less than 10,000:", X
  8738.     IF X >= 0 AND X < 10000 THEN EXIT DO ELSE PRINT X; "out of range"
  8739.  LOOP
  8740.  IF X<10 THEN Y=1 ELSE IF X<100 THEN Y=2 ELSE IF X<1000 THEN Y=3 ELSE Y=4
  8741.  PRINT "The number has"; Y; "digits"
  8742.  
  8743.  
  8744.  Here is the block form, which is easier to read and more powerful:
  8745.  
  8746.  CLS    ' Clear screen.
  8747.  DO
  8748.     INPUT "Enter a number greater than 0 and less than 100,000:", X
  8749.     IF X >= 0 AND X < 100000 THEN
  8750.        EXIT DO
  8751.     ELSE
  8752.        PRINT X; "out of range"
  8753.     END IF
  8754.  LOOP
  8755.  
  8756.  IF X < 10 THEN
  8757.     Y = 1
  8758.  ELSEIF X < 100 THEN
  8759.     Y = 2
  8760.  ELSEIF X < 1000 THEN
  8761.     Y = 3
  8762.  ELSEIF X < 10000 THEN
  8763.     Y = 4
  8764.  ELSE
  8765.     Y = 5
  8766.  END IF
  8767.  PRINT "The number has"; Y; "digits"
  8768.  
  8769.  
  8770.  
  8771.  
  8772.  $INCLUDE Metacommand
  8773.  ────────────────────────────────────────────────────────────────────────────
  8774.  
  8775.  
  8776.  Action
  8777.  
  8778.  Instructs the compiler to include statements from another file.
  8779.  
  8780.  
  8781.  Syntax 1
  8782.  
  8783.   REM  $INCLUDE: 'filespec'
  8784.  
  8785.  Syntax 2
  8786.  
  8787.   ' $INCLUDE: 'filespec'
  8788.  
  8789.  
  8790.  Remarks
  8791.  
  8792.  The argument  filespec is the name of a BASIC program file, which can
  8793.  include a path. Use single quotation marks around  filespec. The metacommand
  8794.   $INCLUDE instructs the compiler to:
  8795.  
  8796.    ■   1. Temporarily switch from processing one file.
  8797.  
  8798.    ■   2. Read program statements from the BASIC file named in  filespec.
  8799.  
  8800.    ■   3. Return to processing the original file when the end of the included
  8801.           file is reached.
  8802.  
  8803.  Because compilation begins with the line immediately following the line in
  8804.  which  $INCLUDE occurred,  $INCLUDE should be the last statement on the
  8805.  line. For example:
  8806.  
  8807.  DEFINT I-N  ' $INCLUDE: 'COMMON.BAS'
  8808.  
  8809.  When you are running a program from the QBX environment, included files must
  8810.  not contain  SUB or  FUNCTION statements. When you are compiling a program
  8811.  from the BC command line, included files can contain  SUB or  FUNCTION
  8812.  statements. Included files created with BASICA must be saved with the , A
  8813.  option. Included files created with QBX must be in a text (not binary)
  8814.  format.
  8815.  
  8816.  
  8817.  Example
  8818.  
  8819.  See the  DateSerial# function programming example, which uses the  $INCLUDE
  8820.  metacommand. The  DateSerial# entry is in Part 2, "Add-On-Library
  8821.  Reference."
  8822.  
  8823.  
  8824.  
  8825.  
  8826.  INKEY$ Function
  8827.  ────────────────────────────────────────────────────────────────────────────
  8828.  
  8829.  
  8830.  Action
  8831.  
  8832.  Returns a character from the keyboard or some other standard input device.
  8833.  
  8834.  
  8835.  Syntax
  8836.  
  8837.   INKEY$
  8838.  
  8839.  
  8840.  Remarks
  8841.  
  8842.  The  INKEY$ function returns a 1- or 2-byte string that contains a character
  8843.  read from the standard input device, which usually is the keyboard. A null
  8844.  string is returned if there is no character to return. A one-character
  8845.  string contains the actual character read from the standard input device,
  8846.  while a two-character string indicates an extended code, the first character
  8847.  of which is hexadecimal 00. For a complete list of these codes, see Appendix
  8848.  A, "Keyboard Scan Codes and ASCII Character Codes."
  8849.  
  8850.  The character returned by the  INKEY$ function is never displayed on the
  8851.  screen; instead, all characters are passed through to the program except for
  8852.  these key combinations:
  8853.  
  8854. ╓┌─────────────┌──────────────────────────────┌──────────────────────────────╖
  8855.  Character     Running under QBX              Stand-alone .EXE file
  8856.  ────────────────────────────────────────────────────────────────────────────
  8857.  Ctrl+Break    Halts program execution.       Halts program execution if
  8858.                                               compiled with the /D option;
  8859.                                               otherwise, passed through to
  8860.                                               program.,
  8861.  
  8862.  Ctrl+NumLock  Causes program execution to    Same as running under QBX if
  8863.                pause until a key is pressed;  compiled with the /D option;
  8864.  Character     Running under QBX              Stand-alone .EXE file
  8865.  ────────────────────────────────────────────────────────────────────────────
  8866.               pause until a key is pressed;  compiled with the /D option;
  8867.                then the next key pressed is   otherwise, it is ignored (the
  8868.                passed through to the program.  program does not pause and no
  8869.                                               keystroke is passed).
  8870.  
  8871.  Shift+PrtSc   Prints the screen contents.    Prints the screen contents.
  8872.  
  8873.  Ctrl+Alt+Del  Reboots the system.            Reboots the system.
  8874.  
  8875.  
  8876.  If you have assigned a string to a function key using the  KEY statement and
  8877.  you press that function key when  INKEY$ is waiting for a keystroke,  INKEY$
  8878.  passes the string to the program. Enabled keystroke trapping takes
  8879.  precedence over the  INKEY$ function.
  8880.  
  8881.  When you use  INKEY$ with ISAM programs, BASIC performs implicit  CHECKPOINT
  8882.  operations to minimize data loss in the event of a power failure. The
  8883.  CHECKPOINT is performed if  INKEY$ fails to successfully retrieve a
  8884.  character after 65,535 calls, and 20 seconds has expired. A  CHECKPOINT
  8885.  writes open database buffers to disk.
  8886.  
  8887.  
  8888.  Example
  8889.  
  8890.  The following example shows a common use of  INKEY$. The program pauses
  8891.  until the user presses a key:
  8892.  
  8893.  PRINT "Press any key to continue..."
  8894.  
  8895.  
  8896.  DO
  8897.  
  8898.  
  8899.  LOOP WHILE INKEY$=""
  8900.  
  8901.  
  8902.  INP Function
  8903.  ────────────────────────────────────────────────────────────────────────────
  8904.  
  8905.  
  8906.  Action
  8907.  
  8908.  Returns the byte read from a hardware I/O port.
  8909.  
  8910.  
  8911.  Syntax
  8912.  
  8913.   INP( port)
  8914.  
  8915.  
  8916.  Remarks
  8917.  
  8918.  The  INP function complements the  OUT statement, which sends a byte to a
  8919.  hardware I/O port.
  8920.  
  8921.  The argument  port identifies the hardware I/O port from which to read the
  8922.  byte. It must be a numeric expression with an integer value between 0 and
  8923.  65,535, inclusive.
  8924.  
  8925.  The  INP function and the  OUT statement give a BASIC program direct control
  8926.  over the system hardware through the I/O ports.  INP and  OUT must be used
  8927.  carefully because they  directly manipulate the system hardware.
  8928.  
  8929.  
  8930.  Note
  8931.  
  8932.  The  INP function is not available in OS/2 protected mode.
  8933.  
  8934.  
  8935.  See Also
  8936.  
  8937.   OUT,  WAIT
  8938.  
  8939.  
  8940.  Example
  8941.  
  8942.  See the  OUT statement programming example, which uses the  INP function.
  8943.  
  8944.  
  8945.  INPUT$ Function
  8946.  ────────────────────────────────────────────────────────────────────────────
  8947.  
  8948.  
  8949.  Action
  8950.  
  8951.  Returns a string of characters read from the specified file.
  8952.  
  8953.  
  8954.  Syntax
  8955.  
  8956.   INPUT$( n , #  filenumber% )
  8957.  
  8958.  
  8959.  Remarks
  8960.  
  8961.  The  INPUT$ statement uses the following arguments:
  8962. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  8963.  Argument                                Description
  8964.  ────────────────────────────────────────────────────────────────────────────
  8965.   n                                      The number of characters (bytes)
  8966.                                          to read from the file.
  8967.  
  8968.   filenumber%                            The number that was used in the
  8969.  Argument                                Description
  8970.  ────────────────────────────────────────────────────────────────────────────
  8971.  filenumber%                            The number that was used in the
  8972.                                          OPEN statement to open the file.
  8973.  
  8974.  
  8975.  
  8976.  
  8977.  
  8978.  If the file is opened for random access, the argument  n must be less than
  8979.  or equal to the record length set by the  LEN clause in the  OPEN statement
  8980.  (or less than or equal to 128 if the record length is not set). If the given
  8981.  file is opened for binary or sequential access,  n must be less than or
  8982.  equal to 32,767.
  8983.  
  8984.  If  filenumber% is omitted, the characters are read from the standard input
  8985.  device. (If input has not been redirected, the keyboard is the standard
  8986.  input device.)
  8987.  
  8988.  You can use the DOS redirection symbols (<, >, or >>) or the pipe symbol ( |
  8989.  ) to redefine the standard input or standard output for an executable file
  8990.  created with BASIC. (See your operating-system manual for a complete
  8991.  discussion of redirection and pipes.)
  8992.  
  8993.  Unlike the  INPUT # statement,  INPUT$ returns all characters it reads.
  8994.  
  8995.  
  8996.  Example
  8997.  
  8998.  The following example uses I NPUT$ to read one character at a time from a
  8999.  file. The input character is converted to standard printable ASCII, if
  9000.  necessary, and displayed on the screen.
  9001.  
  9002.  ' ASCII codes for tab and line feed.
  9003.  
  9004.  
  9005.  DEFINT A-Z
  9006.  
  9007.  
  9008.  CONST HTAB = 9, LFEED = 10
  9009.  
  9010.  
  9011.  CLS    ' Clear screen.
  9012.  
  9013.  
  9014.  INPUT "Display which file"; Filename$
  9015.  
  9016.  
  9017.  OPEN Filename$ FOR INPUT AS #1
  9018.  
  9019.  
  9020.  DO WHILE NOT EOF(1)
  9021.  
  9022.  
  9023.      ' Input a single character from the file.
  9024.  
  9025.  
  9026.      S$ = INPUT$(1, #1)
  9027.  
  9028.  
  9029.      ' Convert the character to an integer and turn off the high bit
  9030.  
  9031.  
  9032.      ' so WordStar files can be displayed.
  9033.  
  9034.  
  9035.      C = ASC(S$) AND &H7F
  9036.  
  9037.  
  9038.      ' Is it a printable character?
  9039.  
  9040.  
  9041.      IF (C >= 32 AND C <= 126) OR C = HTAB OR C = LFEED THEN PRINT CHR$(C);
  9042.  
  9043.  
  9044.  LOOP
  9045.  
  9046.  
  9047.  END
  9048.  
  9049.  
  9050.  INPUT Statement
  9051.  ────────────────────────────────────────────────────────────────────────────
  9052.  
  9053.  
  9054.  Action
  9055.  
  9056.  Allows input from the keyboard during program execution.
  9057.  
  9058.  
  9059.  Syntax
  9060.  
  9061.  
  9062.  
  9063.   INPUT ; " promptstring"{;|,}  variablelist
  9064.  
  9065.  Remarks
  9066.  
  9067.  
  9068.  The following list describes the parts of the  INPUT statement:
  9069.  
  9070. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  9071.  Part                                    Description
  9072.  ────────────────────────────────────────────────────────────────────────────
  9073.  ;                                       Determines screen location of the
  9074.  Part                                    Description
  9075.  ────────────────────────────────────────────────────────────────────────────
  9076.  ;                                       Determines screen location of the
  9077.                                          text cursor after the program user
  9078.                                          enters the last character of input.
  9079.                                          A semicolon immediately after
  9080.                                          INPUT keeps the cursor at the next
  9081.                                          character position. Otherwise, the
  9082.                                          cursor skips to the next line.
  9083.  
  9084.   promptstring                           A literal string that will be
  9085.                                          displayed on the screen before the
  9086.                                          program user enters data items
  9087.                                          into the data input field.
  9088.  
  9089.  ;                                       Prints a question mark at the end
  9090.                                          of  promptstring.
  9091.  
  9092.  ,                                       Prints  promptstring without a
  9093.                                          question mark.
  9094.  
  9095.  Part                                    Description
  9096.  ────────────────────────────────────────────────────────────────────────────
  9097. 
  9098.   variablelist                           An ordered list of variables that
  9099.                                          will hold the data items as they
  9100.                                          are entered.
  9101.  
  9102.  
  9103.  
  9104.  
  9105.  
  9106.  The  INPUT statement causes a running program to pause and wait for the user
  9107.  to enter data from the keyboard.
  9108.  
  9109.  The number and type of data items required from the user is determined by
  9110.  the structure of  variablelist. The variables in  variablelist can be made
  9111.  up of one or more variable names, each separated from the next by a comma.
  9112.  Each name may refer to:
  9113.  
  9114.    ■   A simple numeric variable.
  9115.  
  9116.    ■   A simple string variable.
  9117.  
  9118.    ■   A numeric or string array element.
  9119.  
  9120.    ■   A record element.
  9121.  
  9122.  The number of entered data items must be the same as the number of variables
  9123.  in the list. The type of each entered data item must agree with the type of
  9124.  the variable. If either of these rules is violated, the program will display
  9125.  the prompt Redo from start and no assignment of input values will be made.
  9126.  
  9127.  The  INPUT statement determines the number of entered data items in a list
  9128.  as follows: The first character encountered after a comma that is not a
  9129.  space, carriage return, or line feed is assumed to be the start of a new
  9130.  item. If this first character is a quotation mark ("), the item is typed as
  9131.  string data and will consist of all characters between the first quotation
  9132.  mark and the second. Not all strings have to start with a quotation mark,
  9133.  however. If the first character of the string is not a quotation mark, it
  9134.  terminates on a comma, carriage return, or line feed.
  9135.  
  9136.  
  9137.  Input stored in a record must be entered as single elements. For example:
  9138.  
  9139.  TYPE Demograph
  9140.  
  9141.  FullName AS STRING * 25
  9142.  
  9143.  Age AS INTEGER
  9144.  
  9145.  END TYPE
  9146.  
  9147.  
  9148.  DIM Person AS Demograph
  9149.  
  9150.  INPUT "Enter name and age: "; Person.FullName, Person.Age
  9151.  
  9152.  
  9153.  You may want to instruct the user on how it is possible to edit a line of
  9154.  input before pressing the Enter key to submit the line to the program. The
  9155.  following list describes the key combinations that allow you to move the
  9156.  cursor, delete text, and insert text on the input line:
  9157. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  9158.  Keystrokes                              Edit function
  9159.  ────────────────────────────────────────────────────────────────────────────
  9160.  Ctrl+M or Enter                         Store input line.
  9161.  
  9162.  Ctrl+H or Backspace                     Delete the character to the left
  9163.                                          of the cursor, unless the cursor
  9164.                                          is at the beginning of the input,
  9165.                                          in which case it deletes the
  9166.                                          character at the cursor.
  9167.  
  9168.  Ctrl+\ or Right Arrow                   Move cursor one character to the
  9169.                                          right.
  9170.  
  9171.  Ctrl+] or Left Arrow                    Move cursor one character to the
  9172.                                          left..
  9173.  
  9174.  Ctrl+F or Ctrl+Right Arrow              Move cursor one word to the right.
  9175.  
  9176.  Ctrl+B or Ctrl+Left Arrow               Move cursor one word to the left.
  9177.  
  9178.  Ctrl+K or Home                          Move cursor to beginning of input
  9179.  Keystrokes                              Edit function
  9180.  ────────────────────────────────────────────────────────────────────────────
  9181. Ctrl+K or Home                          Move cursor to beginning of input
  9182.                                          line.
  9183.  
  9184.  Ctrl+N or End                           Move cursor to end of input line.
  9185.  
  9186.  Ctrl+R or Ins                           Toggle insert mode on and off.
  9187.  
  9188.  Ctrl+I or Tab                           Tab right and insert (insert mode
  9189.                                          on), or tab right and overwrite
  9190.                                          (insert mode off).
  9191.  
  9192.  Del                                     Delete the character at the cursor.
  9193.  
  9194.  Ctrl+E or Ctrl+End                      Delete to the end of the line.
  9195.  
  9196.  Ctrl+U or Esc                           Delete entire line, regardless of
  9197.                                          cursor position.
  9198.  
  9199.  Ctrl+T                                  Toggle function key label display
  9200.  Keystrokes                              Edit function
  9201.  ────────────────────────────────────────────────────────────────────────────
  9202. Ctrl+T                                  Toggle function key label display
  9203.                                          on and off at bottom of screen.
  9204.  
  9205.  Ctrl+C or Ctrl+Break                    Terminate input (exit compiled
  9206.                                          program).
  9207.  
  9208.  
  9209.  
  9210.  When you use  INPUT with ISAM programs, BASIC performs a  CHECKPOINT
  9211.  operation every 20 seconds during an  INPUT polling loop. A  CHECKPOINT
  9212.  writes open database buffers to disk.
  9213.  
  9214.  
  9215.  If the user can be limited to using the Enter and Backspace keys for
  9216.  editing, you can reduce the size of the .EXE file by linking with the stub
  9217.  file NOEDIT.OBJ.
  9218.  
  9219.  If the user will be entering decimal integers only, you can save between
  9220.  1.6K and 11K in the size of a non-stand-alone .EXE file by linking with the
  9221.  stub file NOFLTIN.OBJ. This places the following restrictions on user input:
  9222.  
  9223.    ■   Decimal numbers only (no leading &H, &O, or & base specifiers).
  9224.  
  9225.    ■   No trailing type specifiers ( %,  &,  !,  #,  @, or  $).
  9226.  
  9227.    ■   No decimal point, E, or D (for example 1.E2 cannot be used instead of
  9228.        the integer 100).
  9229.  
  9230.  
  9231.  See Also
  9232.  
  9233.   INKEY$
  9234.  
  9235.  
  9236.  Example
  9237.  
  9238.  This example calculates the area of a circle from its radius. The program
  9239.  uses the  INPUT statement to allow the user to supply values of the
  9240.  variable.
  9241.  
  9242.  
  9243.  
  9244.  CLS
  9245.  
  9246.  
  9247.  PI = 3.141593: R = -1
  9248.  
  9249.  
  9250.  DO WHILE R
  9251.  
  9252.  
  9253.  PRINT "Enter radius (or 0 to quit)."
  9254.  
  9255.  
  9256.  INPUT ; "If radius = ", R
  9257.  
  9258.  
  9259.  IF R > 0 THEN
  9260.  
  9261.  
  9262.  A = PI * R ^ 2
  9263.  
  9264.  
  9265.  PRINT ", the area of the circle ="; A
  9266.  
  9267.  
  9268.  END IF
  9269.  
  9270.  
  9271.  PRINT
  9272.  
  9273.  
  9274.  LOOP
  9275.  
  9276.  
  9277.  
  9278.  
  9279.  Output
  9280.  Enter radius (or 0 to quit).
  9281.  
  9282.  
  9283.  If radius = 3, the area of the circle = 28.27434
  9284.  
  9285.  
  9286.  
  9287.  
  9288.  
  9289.  Enter radius (or 0 to quit).
  9290.  
  9291.  
  9292.  If radius = 4, the area of the circle = 50.26549
  9293.  
  9294.  
  9295.  
  9296.  
  9297.  
  9298.  Enter radius (or 0 to quit).
  9299.  
  9300.  
  9301.  If radius = 0
  9302.  
  9303.  
  9304.  INPUT # Statement
  9305.  ────────────────────────────────────────────────────────────────────────────
  9306.  
  9307.  
  9308.  Action
  9309.  
  9310.  Reads data items from a sequential device or file and assigns them to
  9311.  variables.
  9312.  
  9313.  
  9314.  Syntax
  9315.  
  9316.  
  9317.  
  9318.   INPUT # filenumber%,  variablelist
  9319.  
  9320.  
  9321.  Remarks
  9322.  
  9323.  The argument  filenumber% is the number used in the  OPEN statement to open
  9324.  the file. The argument  variablelist contains the names of the variables
  9325.  that are assigned values read from the file.
  9326.  
  9327.  The data items in the file should appear just as they would if you were
  9328.  entering data in response to an  INPUT statement. Separate numbers with a
  9329.  space, carriage return, line feed, or comma. Separate strings with a
  9330.  carriage return or line feed (leading spaces are ignored). The end-of-file
  9331.  character will end either a numeric or string entry.
  9332.  
  9333.  
  9334.  See Also
  9335.  
  9336.   INPUT$ Function,  INPUT Statement
  9337.  
  9338.  
  9339.  Example
  9340.  
  9341.  This example reads a series of test scores from a sequential file. It then
  9342.  calculates and displays the average score.
  9343.  
  9344.  DEFINT A-Z
  9345.  
  9346.  
  9347.  DIM Total AS LONG
  9348.  
  9349.  
  9350.  ' Create the required input file.
  9351.  
  9352.  
  9353.  OPEN "class.dat" FOR OUTPUT AS #1
  9354.  
  9355.  
  9356.  PRINT #1, 98, 84, 63, 89, 100
  9357.  
  9358.  
  9359.  CLOSE #1
  9360.  
  9361.  
  9362.  
  9363.  
  9364.  
  9365.  ' Open the file just created.
  9366.  
  9367.  
  9368.  OPEN "class.dat" FOR INPUT AS #1
  9369.  
  9370.  
  9371.  DO WHILE NOT EOF(1)'Do until end-of-file is reached.
  9372.  
  9373.  
  9374.      Count = Count + 1
  9375.  
  9376.  
  9377.      INPUT #1, Score'Get a score from file #1.
  9378.  
  9379.  
  9380.      Total = Total + Score
  9381.  
  9382.  
  9383.      PRINT Count; Score
  9384.  
  9385.  
  9386.  LOOP
  9387.  
  9388.  
  9389.  PRINT "Total students:"; Count; " Average score:"; Total / Count
  9390.  
  9391.  
  9392.  
  9393.  
  9394.  Output
  9395.  
  9396.  1  98
  9397.  
  9398.  
  9399.  2  84
  9400.  
  9401.  
  9402.  3  63
  9403.  
  9404.  
  9405.  4  89
  9406.  
  9407.  
  9408.  5  100
  9409.  
  9410.  
  9411.  Total students: 5  Average score: 86.8
  9412.  
  9413.  
  9414.  INSERT Statement
  9415.  ────────────────────────────────────────────────────────────────────────────
  9416.  
  9417.  
  9418.  Action
  9419.  
  9420.  Adds a new record to an ISAM table.
  9421.  
  9422.  
  9423.  Syntax
  9424.  
  9425.  
  9426.  
  9427.   INSERT #  filenumber%,  recordvariable
  9428.  
  9429.  Remarks
  9430.  
  9431.  
  9432.  The  INSERT statement uses the following arguments:
  9433.  
  9434. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  9435.  Argument                                Description
  9436.  ────────────────────────────────────────────────────────────────────────────
  9437.   filenumber%                            The number used in the  OPEN
  9438.                                          statement to open the table.
  9439.  
  9440.   recordvariable                         The record you wish to insert. It
  9441.                                          is a variable of the user-defined
  9442.                                          type corresponding to the table.
  9443.  
  9444.  
  9445.  
  9446.  
  9447.  
  9448.   INSERT places the contents of  recordvariable in the table, and updates the
  9449.  table's indexes to include the new record. Insert has no effect on the
  9450.  current position.
  9451.  
  9452.  BASIC removes trailing spaces from strings used in an insert.
  9453.  
  9454.  
  9455.  See Also
  9456.  
  9457.   DELETE,  OPEN (File I/O),  RETRIEVE
  9458.  
  9459.  
  9460.  Example
  9461.  
  9462.  See the programming example for the  SEEKGT,  SEEKGE, and  SEEKEQ
  9463.  statements, which uses the  INSERT statement.
  9464.  
  9465.  
  9466.  INSTR Function
  9467.  ────────────────────────────────────────────────────────────────────────────
  9468.  
  9469.  
  9470.  Action
  9471.  
  9472.  Returns the character position of the first occurrence of a string in
  9473.  another string.
  9474.  
  9475.  
  9476.  Syntax
  9477.  
  9478.  
  9479.  
  9480.   INSTR( start%, stringexpression1$,  stringexpression2$)
  9481.  
  9482.  Remarks
  9483.  
  9484.  
  9485.  The  INSTR function uses the following arguments:
  9486.  
  9487. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  9488.  Argument                                Description
  9489.  ────────────────────────────────────────────────────────────────────────────
  9490.   start%                                 An optional offset that sets the
  9491.                                          position for starting the search;
  9492.                                          start% must be between 1 and
  9493.                                          32,767, inclusive. If  start% is
  9494.  Argument                                Description
  9495.  ────────────────────────────────────────────────────────────────────────────
  9496.                                         32,767, inclusive. If  start% is
  9497.                                          not given, the  INSTR function
  9498.                                          begins the search at the first
  9499.                                          character of  stringexpression1$.
  9500.  
  9501.   stringexpression1$                     The string being searched.
  9502.  
  9503.   stringexpression2$                     The string to look for.
  9504.  
  9505.  
  9506.  
  9507.  
  9508.  
  9509.  The arguments  stringexpression1$ and  stringexpression2$ can be string
  9510.  variables, string expressions, or string literals. The value returned by
  9511.  INSTR depends on these conditions:
  9512.  
  9513. ╓┌─────────────────────────────────────┌─────────────────────────────────────╖
  9514.  Condition                             Value returned
  9515.  Condition                             Value returned
  9516.  ────────────────────────────────────────────────────────────────────────────
  9517.   stringexpression2$ found in          The position at which the match is
  9518.  stringexpression1$                    found
  9519.  
  9520.   start% greater than length of        0
  9521.  stringexpression1$
  9522.  
  9523.   stringexpression1$ is a null string  0
  9524.  
  9525.   stringexpression2$ cannot be found   0
  9526.  
  9527.   stringexpression2$ is a null string   start% (if given); otherwise, 1
  9528.  
  9529.  
  9530.  
  9531.  
  9532.  
  9533.  Use the  LEN function to find the length of  stringexpression1$.
  9534.  
  9535.  
  9536.  See Also
  9537.  
  9538.   LEN
  9539.  
  9540.  
  9541.  Example
  9542.  
  9543.  
  9544.  The following example uses  INSTR and  UCASE$ to determine a person's gender
  9545.  from a courtesy title (Mr., Mrs., or Ms.):
  9546.  
  9547.  CLS    ' Clear screen.
  9548.  
  9549.  
  9550.  DO
  9551.  
  9552.  
  9553.     INPUT "Enter name with courtesy title (Mr., Mrs., or Ms.): ", Nm$
  9554.  
  9555.  
  9556.  LOOP UNTIL LEN(Nm$) >= 3
  9557.  
  9558.  
  9559.  
  9560.  
  9561.  
  9562.  Nm$ = UCASE$(Nm$) ' Convert lowercase letters to uppercase.
  9563.  
  9564.  
  9565.  ' Look for MS, MRS, or MR to set Sex$.
  9566.  
  9567.  
  9568.  IF INSTR(Nm$, "MS") > 0 OR INSTR(Nm$, "MRS") > 0 THEN
  9569.  
  9570.  
  9571.      Sex$ = "F"
  9572.  
  9573.  
  9574.  ELSEIF INSTR(Nm$, "MR") > 0 THEN
  9575.  
  9576.  
  9577.      Sex$ = "M"
  9578.  
  9579.  
  9580.  ELSE
  9581.  
  9582.  
  9583.      ' Can't determine gender, query user.
  9584.  
  9585.  
  9586.      DO
  9587.  
  9588.  
  9589.          INPUT "Enter sex (M/F): ", Sex$
  9590.  
  9591.  
  9592.          Sex$ = UCASE$(Sex$)
  9593.  
  9594.  
  9595.      LOOP WHILE Sex$ <> "M" AND Sex$ <> "F"
  9596.  
  9597.  
  9598.  END IF
  9599.  
  9600.  
  9601.  PRINT "Sex is "; Sex$
  9602.  
  9603.  
  9604.  
  9605.  
  9606.  Output
  9607.  
  9608.  Enter name: Ms. Elspeth Brandtkeep
  9609.  
  9610.  
  9611.  Sex is F
  9612.  
  9613.  
  9614.  
  9615.  
  9616.  
  9617.  Enter name: Dr. Richard Science
  9618.  
  9619.  
  9620.  Enter sex (M/F): M
  9621.  
  9622.  
  9623.  Sex is M
  9624.  
  9625.  
  9626.  INT Function
  9627.  ────────────────────────────────────────────────────────────────────────────
  9628.  
  9629.  
  9630.  Action
  9631.  
  9632.  Returns the largest integer less than or equal to a numeric expression.
  9633.  
  9634.  
  9635.  Syntax
  9636.  
  9637.  
  9638.  
  9639.   INT( numeric-expression)
  9640.  
  9641.  
  9642.  Remarks
  9643.  
  9644.  The  INT function removes the fractional part of its argument.
  9645.  
  9646.  
  9647.  See Also
  9648.  
  9649.   CINT,  FIX
  9650.  
  9651.  
  9652.  Example
  9653.  
  9654.  The following example compares output from  INT,  CINT, and  FIX, the three
  9655.  functions that convert numeric data to integers:
  9656.  
  9657.  CLS                ' Clear screen.
  9658.  
  9659.  
  9660.  PRINT "  N","INT(N)","CINT(N)","FIX(N)" : PRINT
  9661.  
  9662.  
  9663.  FOR I% = 1 TO 6
  9664.  
  9665.  
  9666.      READ N
  9667.  
  9668.  
  9669.      PRINT N, INT(N), CINT(N), FIX(N)
  9670.  
  9671.  
  9672.  NEXT
  9673.  
  9674.  
  9675.  DATA  99.3, 99.5, 99.7, -99.3, -99.5, -99.7
  9676.  
  9677.  
  9678.  
  9679.  
  9680.  Output
  9681.  
  9682.  N           INT(N)        CINT(N)       FIX(N)
  9683.  
  9684.  
  9685.  
  9686.  
  9687.  
  9688.   99.3          99            99            99
  9689.  
  9690.  
  9691.   99.5          99            100           99
  9692.  
  9693.  
  9694.   99.7          99            100           99
  9695.  
  9696.  
  9697.  -99.3         -100          -99           -99
  9698.  
  9699.  
  9700.  -99.5         -100          -100          -99
  9701.  
  9702.  
  9703.  -99.7         -100          -100          -99
  9704.  
  9705.  
  9706.  
  9707.  
  9708.  
  9709.  Interrupt, InterruptX Routines
  9710.  ────────────────────────────────────────────────────────────────────────────
  9711.  
  9712.  
  9713.  Action
  9714.  
  9715.  Allow BASIC programs to perform DOS system calls.
  9716.  
  9717.  
  9718.  Syntax
  9719.  
  9720.  
  9721.  
  9722.   CALL  Interrupt ( interruptnum%,  inregs,  outregs)
  9723.  
  9724.  
  9725.   CALL  InterruptX ( interruptnum%,  inregs,  outregs)
  9726.  
  9727.  Remarks
  9728.  
  9729.  The  Interrupt routines use the following arguments:
  9730.  
  9731. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  9732.  Argument                                Description
  9733.  ────────────────────────────────────────────────────────────────────────────
  9734.   interruptnum%                          A DOS interrupt number that is an
  9735.                                          integer between 0 and 255.
  9736.  
  9737.   inregs                                 The register values before the
  9738.                                          interrupt is performed;  inregs is
  9739.                                          declared as type RegType or
  9740.                                          RegTypeX. The user-defined types
  9741.                                          RegType and RegTypeX are described
  9742.                                          below.
  9743.  
  9744.   outregs                                The register values after the
  9745.                                          interrupt is performed;  outregs
  9746.  Argument                                Description
  9747.  ────────────────────────────────────────────────────────────────────────────
  9748.                                         interrupt is performed;  outregs
  9749.                                          is declared as type RegType or
  9750.                                          RegTypeX. The user-defined types
  9751.                                          RegType and RegTypeX are described
  9752.                                          below.
  9753.  
  9754.  
  9755.  
  9756.  The following statement defines RegTypeX:
  9757.  
  9758.  TYPE RegTypeX
  9759.  
  9760.  
  9761.  AX AS INTEGER
  9762.  
  9763.  
  9764.  BX AS INTEGER
  9765.  
  9766.  
  9767.  CX AS INTEGER
  9768.  
  9769.  
  9770.  DX AS INTEGER
  9771.  
  9772.  
  9773.  BP AS INTEGER
  9774.  
  9775.  
  9776.  SI AS INTEGER
  9777.  
  9778.  
  9779.  DI AS INTEGER
  9780.  
  9781.  
  9782.  FLAGS AS INTEGER
  9783.  
  9784.  
  9785.  DS AS INTEGER
  9786.  
  9787.  
  9788.  ES AS INTEGER
  9789.  
  9790.  
  9791.  END TYPE
  9792.  
  9793.  The following statement defines RegType (the DS and ES registers are not
  9794.  included):
  9795.  
  9796.  
  9797.  TYPE RegType
  9798.  
  9799.  
  9800.  AX AS INTEGER
  9801.  
  9802.  
  9803.  BX AS INTEGER
  9804.  
  9805.  
  9806.  CX AS INTEGER
  9807.  
  9808.  
  9809.  DX AS INTEGER
  9810.  
  9811.  
  9812.  BP AS INTEGER
  9813.  
  9814.  
  9815.  SI AS INTEGER
  9816.  
  9817.  
  9818.  DI AS INTEGER
  9819.  
  9820.  
  9821.  FLAGS AS INTEGER
  9822.  
  9823.  
  9824.  END TYPE
  9825.  
  9826.  Each element of the type corresponds to a CPU element.
  9827.  
  9828.  
  9829.   InterruptX uses the values in the DS and ES registers. To use the current
  9830.  values of these registers, set the record elements to -1.
  9831.  
  9832.  The  Interrupt and  InterruptX routines replace the INT86 and INT86X
  9833.  routines used in earlier versions of BASIC. They provide a more convenient
  9834.  way for BASIC programs to use DOS interrupts and services.
  9835.  
  9836.  To use  Interrupt or  InterruptX in the QBX environment, use the QBX.QLB
  9837.  Quick library. To use  Interrupt or  InterruptX outside of the QBX
  9838.  environment, link your program with the QBX.LIB file.
  9839.  
  9840.  The QBX.BI header file contains the necessary declarations for  Interrupt
  9841.  and  InterruptX .
  9842.  
  9843.  
  9844.  Note
  9845.  
  9846.  The  Interrupt and  InterruptX routines are not available in OS/2 protected
  9847.  mode. For OS/2 protected mode, replace  Interrupt with the equivalent OS/2
  9848.  function invocations. For more information about doing OS/2 calls from
  9849.  BASIC, see Chapter 14, "OS/2 Programming" in the  Programmer's Guide.
  9850.  
  9851.  
  9852.  Example
  9853.  
  9854.  The following example uses  Interrupt to determine the current drive and the
  9855.  amount of free space remaining on the drive.
  9856.  
  9857.  To use  Interrupt, you must load the Quick library QBX.QLB using the /L
  9858.  option when you begin QBX. You also must include the QBX.BI header file as
  9859.  shown below:
  9860.  
  9861.  ' $INCLUDE: 'QBX.BI'
  9862.  
  9863.  
  9864.  DIM regs AS RegType' Define registers.
  9865.  
  9866.  
  9867.  
  9868.  
  9869.  
  9870.  ' Get current drive info.
  9871.  
  9872.  
  9873.  regs.ax = &H1900
  9874.  
  9875.  
  9876.  CALL Interrupt(&H21, regs, regs)
  9877.  
  9878.  
  9879.  ' Convert drive info to readable form.
  9880.  
  9881.  
  9882.  Drive$ = CHR$((regs.ax AND &HFF) + 65) + ":"
  9883.  
  9884.  
  9885.  
  9886.  
  9887.  
  9888.  ' Get disk's free space.
  9889.  
  9890.  
  9891.  regs.ax = &H3600
  9892.  
  9893.  
  9894.  regs.dx = ASC(UCASE$(Drive$)) - 64
  9895.  
  9896.  
  9897.  CALL Interrupt(&H21, regs, regs)
  9898.  
  9899.  
  9900.  ' Decipher the results.
  9901.  
  9902.  
  9903.  SectorsInCluster = regs.ax
  9904.  
  9905.  
  9906.  BytesInSector = regs.cx
  9907.  
  9908.  
  9909.  IF regs.dx >= 0 THEN
  9910.  
  9911.  
  9912.  ClustersInDrive = regs.dx
  9913.  
  9914.  
  9915.  ELSE
  9916.  
  9917.  
  9918.  ClustersInDrive = regs.dx + 65536
  9919.  
  9920.  
  9921.  END IF
  9922.  
  9923.  
  9924.  IF regs.bx >= 0 THEN
  9925.  
  9926.  
  9927.  ClustersAvailable = regs.bx
  9928.  
  9929.  
  9930.  ELSE
  9931.  
  9932.  
  9933.  ClustersAvailable = regx.bx + 65536
  9934.  
  9935.  
  9936.  END IF
  9937.  
  9938.  
  9939.  Freespace = ClustersAvailable * SectorsInCluster * BytesInSector
  9940.  
  9941.  
  9942.  
  9943.  
  9944.  
  9945.  ' Report results.
  9946.  
  9947.  
  9948.  CLS
  9949.  
  9950.  
  9951.  PRINT "Drive "; Drive$; " has a total of";
  9952.  
  9953.  
  9954.  PRINT USING "###,###,###"; Freespace;
  9955.  
  9956.  
  9957.  PRINT " bytes remaining free."
  9958.  
  9959.  
  9960.  IOCTL$ Function
  9961.  ────────────────────────────────────────────────────────────────────────────
  9962.  
  9963.  
  9964.  Action
  9965.  
  9966.  Returns current status information from a device driver.
  9967.  
  9968.  
  9969.  Syntax
  9970.  
  9971.  
  9972.  
  9973.   IOCTL$(#  filenumber%)
  9974.  
  9975.  Remarks
  9976.  
  9977.  
  9978.  The argument  filenumber% is the BASIC file number used to open the device.
  9979.  
  9980.  The  IOCTL$ function is most frequently used to test whether an  IOCTL
  9981.  statement succeeded or failed, or to obtain current status information.
  9982.  
  9983.  You can use  IOCTL$ to ask a communications device to return the current
  9984.  baud rate, information on the last error, logical line width, and so on. The
  9985.  exact information returned depends on the specific device driver. See the
  9986.  device driver documentation to find out what status information the device
  9987.  driver can send.
  9988.  
  9989.  The  IOCTL$ function works only if all of the following conditions are met:
  9990.  
  9991.    ■         The device driver is installed.
  9992.  
  9993.    ■         The device driver states that it processes  IOCTL strings. See
  9994.              the documentation for the driver.
  9995.  
  9996.    ■         BASIC performed an  OPEN operation on a file on that device, and
  9997.              the file is still open.
  9998.  
  9999.  
  10000.  
  10001.  
  10002.  
  10003.  Most standard DOS device drivers do not process  IOCTL strings, and you must
  10004.  determine whether the specific driver accepts the command. If the driver
  10005.  does not process  IOCTL strings, BASIC generates the error message Illegal
  10006.  function call.
  10007.  
  10008.  
  10009.  Note
  10010.  
  10011.  BASIC devices (LPT n, COM n, SCRN, CONS, PIPE) and DOS block devices (A
  10012.  through Z) do not support  IOCTL.
  10013.  
  10014.  The  IOCTL statement is not available in OS/2 protected mode. However, you
  10015.  can achieve the same effect by directly invoking the DosDevIOCtl OS/2
  10016.  functions.
  10017.  
  10018.  
  10019.  See Also
  10020.  
  10021.   IOCTL Statement
  10022.  
  10023.  
  10024.  Example
  10025.  
  10026.  The following example shows how to communicate with a device driver using a
  10027.  hypothetical device driver named ENGINE. The  IOCTL statement sets the data
  10028.  mode in the driver and the  IOCTL$ function tests the data mode.
  10029.  
  10030.  OPEN "\DEV\ENGINE" FOR OUTPUT AS #1
  10031.  
  10032.  
  10033.  IOCTL #1, "RAW"' Tells the device that the data is raw.
  10034.  
  10035.  
  10036.  
  10037.  
  10038.  
  10039.  ' If the character driver "ENGINE" responds "false" from the raw data
  10040.  
  10041.  
  10042.  ' mode in the IOCTL statement, then the file is closed.
  10043.  
  10044.  
  10045.  IF IOCTL$(1) = "0" THEN CLOSE 1
  10046.  
  10047.  
  10048.  IOCTL Statement
  10049.  ────────────────────────────────────────────────────────────────────────────
  10050.  
  10051.  
  10052.  Action
  10053.  
  10054.  Transmits a control data string to a device driver.
  10055.  
  10056.  
  10057.  Syntax
  10058.  
  10059.  
  10060.  
  10061.   IOCTL #  filenumber%,  string$
  10062.  
  10063.  Remarks
  10064.  
  10065.  
  10066.  The  IOCTL statement uses the following arguments:
  10067.  
  10068. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  10069.  Argument          Description
  10070.  ────────────────────────────────────────────────────────────────────────────
  10071.   filenumber%      The BASIC file number used to open the device.
  10072.   string$          The command sent to the device.
  10073.  
  10074.  
  10075.  
  10076.  
  10077.  Commands are specific to the device driver. See the documentation for the
  10078.  device driver for a description of the valid  IOCTL commands. An  IOCTL
  10079.  control data string can be up to 32,767 bytes long.
  10080.  
  10081.  The  IOCTL statement works only if all of the following conditions are met:
  10082.  
  10083.    ■         The device driver is installed.
  10084.  
  10085.    ■         The device driver states that it processes  IOCTL strings. See
  10086.              the documentation for the driver.  You also can test for  IOCTL
  10087.              support through DOS function &H44 by using interrupt &H21 and
  10088.              the  INTERRUPT routine. For more information about interrupt
  10089.              &H21, function &H44, see see the  Microsoft MS-DOS  Programmer's
  10090.               Reference, or books such as  Advanced MS-DOS or  The Peter
  10091.              Norton Guide to the IBM PC.
  10092.  
  10093.    ■         BASIC performed an  OPEN operation on a file on that device, and
  10094.              the file is still open.
  10095.  
  10096.  
  10097.  
  10098.  
  10099.  
  10100.  Most standard DOS device drivers do not process  IOCTL strings, and you must
  10101.  determine whether the specific driver accepts the command. If the driver
  10102.  does not process  IOCTL strings, BASIC generates the error message Illegal
  10103.  function call.
  10104.  
  10105.  
  10106.  Note
  10107.  
  10108.  BASIC devices (LPT n, COM n, SCRN, CONS, PIPE) and DOS block devices (A
  10109.  through Z) do not support  IOCTL.
  10110.  
  10111.  The  IOCTL statement is not available in OS/2 protected mode. However, you
  10112.  can achieve the same effect by directly invoking the DosDevIOCtl OS/2
  10113.  function.
  10114.  
  10115.  
  10116.  See Also
  10117.  
  10118.   IOCTL$ Function
  10119.  
  10120.  
  10121.  Example
  10122.  
  10123.  See the  IOCTL$ function programming example, which shows how the  IOCTL
  10124.  statement and the  IOCTL$ function are used with a device driver.
  10125.  
  10126.  
  10127.  KEY Statements (Assignment)
  10128.  ────────────────────────────────────────────────────────────────────────────
  10129.  
  10130.  
  10131.  Action
  10132.  
  10133.  Assign soft-key string values to function keys, then display the values and
  10134.  enable or disable the function-key display line.
  10135.  
  10136.  
  10137.  Syntax
  10138.  
  10139.  
  10140.  
  10141.   KEY  n%,  stringexpression$
  10142.  
  10143.  
  10144.   KEY ON
  10145.  
  10146.   KEY OFF
  10147.  KEY LIST
  10148.  
  10149.  
  10150.  Remarks
  10151.  
  10152.  
  10153.  The argument  n% is a number representing the function key. The values for
  10154.  n% are 1 to 10 for the function keys, and 30 and 31 for function keys F11
  10155.  and F12 on 101-key keyboards. The  stringexpression$ is a string of up to 15
  10156.  characters that is returned when the function key is pressed. If the
  10157.  stringexpression$ is longer than 15 characters, the extra characters are
  10158.  ignored.
  10159.  
  10160.  The  KEY statements allows you to designate special "soft-key" functions --
  10161.  strings that are returned when function keys are pressed.
  10162.  
  10163.  Assigning a null string to a soft key disables the function key as a soft
  10164.  key.
  10165.  
  10166.  If the function key number is not in the correct range, BASIC generates the
  10167.  error message Illegal function call, and the previous key string expression
  10168.  is retained.
  10169.  
  10170.  You can display soft keys with the  KEY ON,  KEY OFF, and  KEY LIST
  10171.  statements:
  10172.  
  10173. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  10174.  Statement                               Action
  10175.  ────────────────────────────────────────────────────────────────────────────
  10176.   KEY ON                                 Displays the first six characters
  10177.                                          of the soft-key string values on
  10178.                                          the bottom line of the screen.
  10179.  
  10180.   KEY OFF                                Erases the soft-key display from
  10181.                                          the bottom line, making that line
  10182.                                          available for program use. It does
  10183.                                          not disable the function keys.
  10184.  
  10185.   KEY LIST                               Displays all soft-key values on
  10186.                                          the screen, with all 15 characters
  10187.  Statement                               Action
  10188.  ────────────────────────────────────────────────────────────────────────────
  10189.                                         the screen, with all 15 characters
  10190.                                          of each key displayed.
  10191.  
  10192.  
  10193.  
  10194.  
  10195.  
  10196.  If a soft key is pressed, the effect is the same as if the user typed the
  10197.  string associated with the soft key.  INPUT$,  INPUT, and  INKEY$ all can be
  10198.  used to read the string produced by pressing the soft key.
  10199.  
  10200.  See Also
  10201.  
  10202.   ON  event; Appendix A, "Keyboard Scan Codes and ASCII Character Codes"
  10203.  
  10204.  
  10205.  Examples
  10206.  
  10207.  The following examples show how to assign values to soft keys. First is an
  10208.  example of assigning and disabling a soft key.  KEY LIST displays key values
  10209.  after KEY 4 has been assigned and again after it has been disabled.
  10210.  
  10211.  KEY 4, "MENU" + CHR$(13) ' Assigns to soft key 4 the string
  10212.  
  10213.  KEY LIST' "MENU" followed by a carriage return.
  10214.  
  10215.  KEY 4, ""  ' Disables soft key 4.
  10216.  
  10217.  KEY LIST
  10218.  
  10219.  This is an example of using  KEY statements to set up one-key equivalents of
  10220.  menu selections. For example, pressing the F1 key is the same as entering
  10221.  the string "Add":
  10222.  
  10223.  
  10224.  CLS                       ' Clear screen.
  10225.  
  10226.  DIM KeyText$(3)
  10227.  
  10228.  DATA Add, Delete, Quit
  10229.  
  10230.  ' Assign soft-key strings to F1 to F3.
  10231.  
  10232.  FOR I = 1 TO 3
  10233.  
  10234.     READ KeyText$(I)
  10235.  
  10236.     KEY I, KeyText$(I) + CHR$(13)   ' String followed by Enter.
  10237.  
  10238.  NEXT I
  10239.  
  10240.  
  10241.  
  10242.  ' Print menu.
  10243.  
  10244.  PRINT "                 Main Menu" : PRINT
  10245.  
  10246.  PRINT "           Add to list (F1)"
  10247.  
  10248.  PRINT "           Delete from list (F2)"
  10249.  
  10250.  PRINT "           Quit (F3)" : PRINT
  10251.  
  10252.  
  10253.  
  10254.  ' Get input and respond.
  10255.  
  10256.  DO
  10257.  
  10258.     LOCATE 7,1 : PRINT SPACE$(50);
  10259.  
  10260.     LOCATE 7,1 : INPUT "             Enter your choice:", R$
  10261.  
  10262.     SELECT CASE R$
  10263.  
  10264.        CASE "Add", "Delete"
  10265.  
  10266.           LOCATE 10,1 : PRINT SPACE$(15);
  10267.  
  10268.           LOCATE 10,1 : PRINT R$;
  10269.  
  10270.        CASE "Quit"
  10271.  
  10272.           EXIT DO
  10273.  
  10274.        CASE ELSE
  10275.  
  10276.           LOCATE 10,1 : PRINT "Enter first word or press key."
  10277.  
  10278.     END SELECT
  10279.  
  10280.  LOOP
  10281.  
  10282.  
  10283.  
  10284.  
  10285.  KEY Statements (Event Trapping)
  10286.  ────────────────────────────────────────────────────────────────────────────
  10287.  
  10288.  
  10289.  
  10290.  Action
  10291.  
  10292.  Enable, disable, or suspend trapping of specified keys.
  10293.  
  10294.  
  10295.  Syntax
  10296.  
  10297.  
  10298.  
  10299.   KEY( n%)  ON
  10300.  
  10301.  
  10302.   KEY( n%)  OFF
  10303.  
  10304.  
  10305.   KEY( n%)  STOP
  10306.  
  10307.  
  10308.  Remarks
  10309.  
  10310.  
  10311.  The argument  n% is an integer expression that is the number of a function
  10312.  key, a direction key, or a user-defined key. The values of  n% are as
  10313.  follows:
  10314.  
  10315. ╓┌──────────────────┌────────────────────────────────────────────────────────╖
  10316.   n%                Value
  10317.  ────────────────────────────────────────────────────────────────────────────
  10318.  0                  All keys listed in this table
  10319.  1-10               F1-F10
  10320.  11                 Up Arrow key
  10321.  12                 Left Arrow key
  10322.  13                 Right Arrow key
  10323.  14\~               Down Arrow key
  10324.  15-25              User-defined keys
  10325.  30-31              F11-F12 on 101-key keyboards
  10326.  
  10327.  
  10328.  
  10329.  
  10330.  The  KEY( n%)  ON statement enables trapping of function keys, direction
  10331.  keys, and user-defined keys. If key  n% is pressed after a  KEY( n%)  ON
  10332.  statement, the routine specified in the  ON  KEY statement is executed.
  10333.  
  10334.   KEY( n%  OFF disables trapping of key  n%. No key trapping takes place
  10335.  until another  KEY( n%)  ON statement is executed. Events occurring while
  10336.  trapping is off are ignored.
  10337.  
  10338.   KEY( n%)  STOP suspends trapping of key  n%. No trapping takes place until
  10339.  a  KEY( n%)  ON statement is executed. Events occurring while trapping is
  10340.  suspended are remembered and processed when the next  KEY( n%)  ON statement
  10341.  is executed. However, remembered events are lost if  KEY( n%)  OFF is
  10342.  executed.
  10343.  
  10344.  When a key-event trap occurs (that is, the  GOSUB is performed), an
  10345.  automatic  KEY( n%)  STOP is executed so that recursive traps cannot take
  10346.  place. The  RETURN operation from the trapping routine automatically
  10347.  performs a  KEY( n%)  ON statement unless an explicit  KEY( n%)  OFF was
  10348.  performed inside the subroutine.
  10349.  
  10350.  For more information on event trapping, see Chapter 9, "Event Handling" in
  10351.  the  Programmer's Guide.
  10352.  
  10353.  
  10354.  In addition to providing the preassigned key numbers 1-14 (plus 30 and 31 on
  10355.  the 101-key keyboard), BASIC enables you to create user-defined keys. You do
  10356.  this by assigning the numbers 15-25 to any of the remaining keys on the
  10357.  keyboard. Use the  KEY statement (assignment) to create user-defined keys.
  10358.  
  10359.  You also can set a trap for "shifted" keys. A key is shifted when you press
  10360.  it simultaneously with one or more of the special keys Shift, Ctrl, or Alt
  10361.  after pressing NumLock or Caps Lock. Use the  KEY statement (assignment) to
  10362.  define shifted keys before you trap them. The syntax for  KEY (assignment)
  10363.  is:
  10364.  
  10365.  
  10366.  
  10367.   KEY  n%,  CHR$ ( keyboardflag) +  CHR$ ( scancode)
  10368.  
  10369.  The argument  n% is in the range 15-25 to indicate a user-defined key. The
  10370.  argument  keyboardflag can be any combination of the following values:
  10371.  
  10372.  
  10373. ╓┌─────────────────────┌─────────────────────────────────────────────────────╖
  10374.  Value                 Key
  10375.  ────────────────────────────────────────────────────────────────────────────
  10376.  Value                 Key
  10377.  ────────────────────────────────────────────────────────────────────────────
  10378.  0                     No keyboard flag
  10379.  1, 2, or 3            Either Shift key
  10380.  4                     Ctrl
  10381.  8                     Alt
  10382.  32                    NumLock
  10383.  64                    Caps Lock
  10384.  128                   101-key keyboard extended keys
  10385.  
  10386.  
  10387.  
  10388.  
  10389.  You can add the values together to test for multiple shift states. A
  10390.  keyboardflag value of 12 would test for both Ctrl and Alt being pressed, for
  10391.  example.
  10392.  
  10393.  To define Shift, Ctrl, Alt, NumLock, or Caps Lock as a user-defined key (by
  10394.  itself, not in combination with another key), use a keyboard flag of 0. For
  10395.  example, to define Alt as a user-defined key, use the following statement:
  10396.  
  10397.  KEY CHR$(0) + CHR$(56)
  10398.  
  10399.  To define Alt + Alt as a user-defined key (the second Alt will be trapped
  10400.  when it is pressed only if the first Alt key is already being pressed), use
  10401.  the following statement:
  10402.  
  10403.  KEY CHR$(8) + CHR$(56)
  10404.  
  10405.  Because key trapping assumes the left and right Shift keys are the same, you
  10406.  can use 1, 2, or 3 to indicate a Shift key.
  10407.  
  10408.  The argument  scancode is a number that identifies one of the 83 keys to
  10409.  trap, as shown in the following table:
  10410.  
  10411.  
  10412.  Keyboard Scan Codes
  10413. ╓┌──────────┌─────┌────────────┌─────┌────────────┌──────────────────────────╖
  10414.  Key        Code  Key          Code  Key          Code
  10415.  ────────────────────────────────────────────────────────────────────────────
  10416.  Esc        1     Ctrl         29    Spacebar     57
  10417.  ! or 1     2     A            30    Caps Lock    58
  10418.  Key        Code  Key          Code  Key          Code
  10419.  ────────────────────────────────────────────────────────────────────────────
  10420. ! or 1     2     A            30    Caps Lock    58
  10421.  @ or 2     3     S            31    F1           59
  10422.  # or 3     4     D            32    F2           60
  10423.  $ or 4     5     F            33    F3           61
  10424.  % or 5     6     G            34    F4           62
  10425.  ^ or 6     7     H            35    F5           63
  10426.  & or 7     8     J            36    F6           64
  10427.  * or 8     9     K            37    F7           65
  10428.  ( or 9     10    L            38    F8           66
  10429.  ) or 0     11    : or ;       39    F9           67
  10430.  _ or -     12    " or '       40    F10          68
  10431.  + or =     13    ~ or `       41    NumLock      69
  10432.  Backspace  14    Left Shift   42    Scroll Lock  70
  10433.  Tab        15    | or \       43    Home or 7    71
  10434.  Q          16    Z            44    Up or 8      72
  10435.  W          17    X            45    PgUp or 9    73
  10436.  E          18    C            46    Gray  -      74
  10437.  R          19    V            47    Left or 4    75
  10438.  T          20    B            48    Center or 5  76
  10439.  Key        Code  Key          Code  Key          Code
  10440.  ────────────────────────────────────────────────────────────────────────────
  10441. T          20    B            48    Center or 5  76
  10442.  Y          21    N            49    Right or 6   77
  10443.  U          22    M            50    Gray +       78
  10444.  I          23    < or ,       51    End or 1     79
  10445.  O          24    > or .       52    Down or 2    80
  10446.  P          25    ? or /       53    PgDn or 3    81
  10447.  { or [     26    Right Shift  54    Ins or 0     82
  10448.  } or ]     27    PrtSc or *   55    Del or .     83
  10449.  Enter      28    Alt          56
  10450.  
  10451.  
  10452.  
  10453.  
  10454.  Note
  10455.  
  10456.  
  10457.  The scan codes in the preceding table are equivalent to the first column of
  10458.  the scan code table in Appendix A, "Keyboard Scan Codes and ASCII Character
  10459.  Codes." The codes in the other columns of the table in the appendix should
  10460.  not be used for key trapping.
  10461.  
  10462.  
  10463.  See Also
  10464.  
  10465.  
  10466.   KEY (Assignment),  ON  event
  10467.  
  10468.  
  10469.  Example
  10470.  
  10471.  The following example traps the Down Arrow key and Ctrl+s (Control key and
  10472.  lowercase "s"). To trap the combination of the Ctrl key and uppercase "s",
  10473.  trap Ctrl+Shift and
  10474.  
  10475.  I = 0
  10476.  
  10477.  CLS' Clear screen.
  10478.  
  10479.  PRINT "Press Down Arrow key to end."
  10480.  
  10481.  KEY 15, CHR$(&H4) + CHR$(&H1F)
  10482.  
  10483.  KEY(15) ON ' Trap Ctrl+s.
  10484.  
  10485.  KEY(14) ON ' Trap Down Arrow key.
  10486.  
  10487.  ON KEY(15) GOSUB Keytrap
  10488.  
  10489.  ON KEY(14) GOSUB Endprog
  10490.  
  10491.  Idle: GOTO Idle' Endless loop.
  10492.  
  10493.  
  10494.  
  10495.  Keytrap:   ' Counts the number of times Ctrl+s pressed.
  10496.  
  10497.  I = I + 1
  10498.  
  10499.  RETURN
  10500.  
  10501.  
  10502.  
  10503.  Endprog:
  10504.  
  10505.  PRINT "CTRL+s trapped"; I; "times"
  10506.  
  10507.  END
  10508.  
  10509.  RETURN
  10510.  
  10511.  
  10512.  KILL Statement
  10513.  ────────────────────────────────────────────────────────────────────────────
  10514.  
  10515.  
  10516.  Action
  10517.  
  10518.  Deletes files from a disk.
  10519.  
  10520.  
  10521.  Syntax
  10522.  
  10523.  
  10524.  
  10525.   KILL  filespec$
  10526.  
  10527.  
  10528.  Remarks
  10529.  
  10530.  
  10531.  The  KILL statement is similar to the DOS ERASE or DEL command.
  10532.  
  10533.   KILL is used for all types of disk files: program files, random-access data
  10534.  files, and sequential data files. The  filespec$ is a string expression that
  10535.  can contain a path and question marks (?) or asterisks (*) used as DOS
  10536.  wildcards. A question mark matches any single character in the filename or
  10537.  extension. An asterisk matches one or more characters.
  10538.  
  10539.   KILL deletes files only. To delete directories, use the DOS RMDIR command
  10540.  or BASIC  RMDIR statement. Using  KILL to delete a file that is currently
  10541.  open produces an error message that reads  File already open.
  10542.  
  10543.  
  10544.  Warning
  10545.  
  10546.  Be extremely careful when using wildcards with  KILL. You can delete files
  10547.  unintentionally with the wildcard characters.
  10548.  
  10549.  
  10550.  See Also
  10551.  
  10552.   FILES,  RMDIR
  10553.  
  10554.  
  10555.  Examples
  10556.  
  10557.  The first example uses wildcard characters with  KILL. It will not work
  10558.  properly unless the specified files are found.
  10559.  
  10560.  KILL "DATA1?.DAT" ' Kills any file with a six-character
  10561.  
  10562.  ' base name starting with DATA1 and
  10563.  
  10564.  ' also with the extension .DAT.
  10565.  
  10566.  
  10567.  
  10568.  KILL "DATA1.*"' Kills any file with the base name
  10569.  
  10570.  ' DATA1 and any extension.
  10571.  
  10572.  
  10573.  
  10574.  KILL "\GREG\*.DAT"' Kills any file with the extension
  10575.  
  10576.  ' .DAT in a subdirectory called GREG.
  10577.  
  10578.  
  10579.  
  10580.  The following example deletes the file specified on the command line:
  10581.  
  10582.  
  10583.  DEFINT A-Z
  10584.  
  10585.  CLS    ' Clear screen.
  10586.  
  10587.  ON ERROR GOTO Errorhandle' Set up error handling.
  10588.  
  10589.  FileName$ = COMMAND$ ' Get filename.
  10590.  
  10591.  KILL FileName$
  10592.  
  10593.  PRINT FileName$ " deleted"
  10594.  
  10595.  END
  10596.  
  10597.  
  10598.  
  10599.  Errorhandle:
  10600.  
  10601.      Number = ERR
  10602.  
  10603.      IF Number = 53 THEN
  10604.  
  10605.         PRINT "Couldn't delete " FileName$ ;
  10606.  
  10607.         PRINT "; file does not exist in current directory"
  10608.  
  10609.      ELSE
  10610.  
  10611.         PRINT "Unrecoverable error:";Number
  10612.  
  10613.         ON ERROR GOTO 0 ' ON ERROR GOTO zero aborts program.
  10614.  
  10615.      END IF
  10616.  
  10617.  RESUME NEXT
  10618.  
  10619.  
  10620.  LBOUND Function
  10621.  ────────────────────────────────────────────────────────────────────────────
  10622.  
  10623.  
  10624.  Action
  10625.  
  10626.  Returns the lower bound (smallest available subscript) for the indicated
  10627.  dimension of an array.
  10628.  
  10629.  
  10630.  Syntax
  10631.  
  10632.  
  10633.  
  10634.   LBOUND( array ,  dimension% )
  10635.  
  10636.  
  10637.  Remarks
  10638.  
  10639.  
  10640.  The  LBOUND function is used with the  UBOUND function to determine the size
  10641.  of an array.  LBOUND takes the following arguments:
  10642.  
  10643. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  10644.  Argument                                Description
  10645.  ────────────────────────────────────────────────────────────────────────────
  10646.   array                                  The name of the array variable to
  10647.                                          be tested.
  10648.  
  10649.  Argument                                Description
  10650.  ────────────────────────────────────────────────────────────────────────────
  10651. 
  10652.   dimension%                             An integer ranging from 1 to the
  10653.                                          number of dimensions in  array;
  10654.                                          indicates which dimension's lower
  10655.                                          bound is returned. Use 1 for the
  10656.                                          first dimension, 2 for the second
  10657.                                          dimension, and so on. This
  10658.                                          argument is optional for
  10659.                                          one-dimensional arrays.
  10660.  
  10661.  
  10662.  
  10663.  
  10664.  
  10665.   LBOUND returns the values listed below for an array with the following
  10666.  dimensions:
  10667.  
  10668.  DIM A(1 TO 100, 0 TO 3, -3 TO 4)
  10669.  
  10670.  
  10671.  
  10672. ╓┌───────────────────────────┌───────────────────────────────────────────────╖
  10673.  Invocation                  Value returned
  10674.  ────────────────────────────────────────────────────────────────────────────
  10675.  LBOUND(A,1)                 1
  10676.  LBOUND(A,2)                 0
  10677.  LBOUND(A,3)                 -3
  10678.  
  10679.  
  10680.  
  10681.  
  10682.  The default lower bound for any dimension is either 0 or 1, depending on the
  10683.  setting of the  OPTION BASE statement. If  OPTION BASE is 0, the default
  10684.  lower bound is 0, and if  OPTION BASE is 1, the default lower bound is 1.
  10685.  
  10686.  Arrays dimensioned using the  TO clause in the  DIM statement can have any
  10687.  integer value as a lower bound.
  10688.  
  10689.  You can use the shortened syntax  LBOUND( array) for one-dimensional arrays,
  10690.  because the default value for  dimension% is 1. Use the  UBOUND function to
  10691.  find the upper limit of an array dimension.
  10692.  
  10693.  
  10694.  See Also
  10695.  
  10696.   DIM,  OPTION BASE,  UBOUND
  10697.  
  10698.  
  10699.  Example
  10700.  
  10701.  See the  UBOUND function programming example, which uses the  LBOUND
  10702.  function.
  10703.  
  10704.  
  10705.  LCASE$ Function
  10706.  ────────────────────────────────────────────────────────────────────────────
  10707.  
  10708.  
  10709.  Action
  10710.  
  10711.  Returns a string with all letters in lowercase.
  10712.  
  10713.  
  10714.  Syntax
  10715.  
  10716.  
  10717.  
  10718.   LCASE$ ( stringexpression$)
  10719.  
  10720.  
  10721.  Remarks
  10722.  
  10723.  
  10724.  The  LCASE$ function takes a string variable, string constant, or string
  10725.  expression as its single argument.  LCASE$ works with both variable- and
  10726.  fixed-length strings.
  10727.  
  10728.   LCASE$ and  UCASE$ are helpful in making string comparisons that are not
  10729.  case sensitive.
  10730.  
  10731.  
  10732.  See Also
  10733.  
  10734.   UCASE$
  10735.  
  10736.  
  10737.  Example
  10738.  
  10739.  The following example converts uppercase characters in a string to
  10740.  lowercase:
  10741.  
  10742.  CLS                ' Clear screen.
  10743.  
  10744.  READ Word$
  10745.  
  10746.  PRINT LCASE$(Word$);
  10747.  
  10748.  DATA "THIS IS THE STRING in lower case."
  10749.  
  10750.  
  10751.  
  10752.  Outputthis is the string in lower case.
  10753.  
  10754.  
  10755.  
  10756.  
  10757.  
  10758.  LEFT$ Function
  10759.  ────────────────────────────────────────────────────────────────────────────
  10760.  
  10761.  
  10762.  Action
  10763.  
  10764.  Returns a string consisting of the leftmost  n characters of a string.
  10765.  
  10766.  
  10767.  Syntax
  10768.  
  10769.  
  10770.  
  10771.   LEFT$( stringexpression$,  n%)
  10772.  
  10773.  
  10774.  Remarks
  10775.  
  10776.  
  10777.  The argument  stringexpression$ can be any string variable, string constant,
  10778.  or string expression.
  10779.  
  10780.  The argument  n% is a numeric expression in the range 0-32,767 indicating
  10781.  how many characters are to be returned.
  10782.  
  10783.  If  n% is 0, the null string (length zero) is returned.
  10784.  
  10785.  If  n% is greater than or equal to the number of characters in
  10786.  stringexpression$, the entire string is returned. To find the number of
  10787.  characters in  stringexpression$, use  LEN( stringexpression$) .
  10788.  
  10789.  
  10790.  See Also
  10791.  
  10792.   MID$ Function,  RIGHT$ Function
  10793.  
  10794.  
  10795.  Example
  10796.  
  10797.  The following example prints the leftmost five characters of A$:
  10798.  
  10799.  CLS                ' Clear screen.
  10800.  
  10801.  A$="BASIC LANGUAGE"
  10802.  
  10803.  B$=LEFT$(A$, 5)
  10804.  
  10805.  PRINT B$
  10806.  
  10807.  
  10808.  
  10809.  Output
  10810.  
  10811.  BASIC
  10812.  
  10813.  
  10814.  
  10815.  LEN Function
  10816.  ────────────────────────────────────────────────────────────────────────────
  10817.  
  10818.  
  10819.  Action
  10820.  
  10821.  Returns the number of characters in a string or the number of bytes required
  10822.  by a variable.
  10823.  
  10824.  
  10825.  Syntax 1
  10826.  
  10827.   LEN( stringexpression$)
  10828.  
  10829.  Syntax 2
  10830.  
  10831.   LEN( variable)
  10832.  
  10833.  
  10834.  Remarks
  10835.  
  10836.  
  10837.  In the first form,  LEN returns the number of characters in the argument
  10838.  stringexpression$. The second syntax returns the number of bytes required by
  10839.  a BASIC variable. This syntax is particularly useful for determining the
  10840.  correct record size of a random-access file.
  10841.  
  10842.  When you pass a string length as an argument to a procedure that may change
  10843.  the value of the argument, be sure to pass it by value instead of by
  10844.  reference, which is the BASIC default. Do this by placing parentheses around
  10845.  LEN(N$), e.g.,(LEN(N%)). Alternatively, you can use a temporary variable,
  10846.  e.g. N% = LEN(N$), and pass the temporary variable in the standard way.
  10847.  Failure to use these techniques will corrupt string space if you change the
  10848.  value of the passed argument.
  10849.  
  10850.  
  10851.  Example
  10852.  
  10853.  The following example prints the length of a string and the size in bytes of
  10854.  several types of variables:
  10855.  
  10856.  CLS    ' Clear screen.
  10857.  
  10858.  TYPE EmpRec
  10859.  
  10860.     EmpName AS STRING * 20
  10861.  
  10862.     EmpNum AS INTEGER
  10863.  
  10864.  END TYPE
  10865.  
  10866.  DIM A AS INTEGER, B AS LONG, C AS SINGLE, D AS DOUBLE
  10867.  
  10868.  DIM E AS EmpRec
  10869.  
  10870.  
  10871.  
  10872.  PRINT "A string:" LEN("A string.")
  10873.  
  10874.  PRINT "Integer:" LEN(A)
  10875.  
  10876.  PRINT "Long:" LEN(B)
  10877.  
  10878.  PRINT "Single:" LEN(C)
  10879.  
  10880.  PRINT "Double:" LEN(D)
  10881.  
  10882.  PRINT "EmpRec:" LEN(E)
  10883.  
  10884.  END
  10885.  
  10886.  
  10887.  
  10888.  Output
  10889.  
  10890.  A string: 9
  10891.  
  10892.  
  10893.  Integer: 2
  10894.  
  10895.  Long: 4
  10896.  
  10897.  Single: 4
  10898.  
  10899.  Double: 8
  10900.  
  10901.  EmpRec: 22
  10902.  
  10903.  
  10904.  Let Statement
  10905.  ────────────────────────────────────────────────────────────────────────────
  10906.  
  10907.  
  10908.  Action
  10909.  
  10910.  Assigns the value of an expression to a variable.
  10911.  
  10912.  
  10913.  Syntax
  10914.  
  10915.  
  10916.  
  10917.   LET  variable= expression
  10918.  
  10919.  
  10920.  Remarks
  10921.  
  10922.  
  10923.  Notice that the keyword  LET is optional. The equal sign in the statement is
  10924.  enough to inform BASIC that the statement is an assignment statement.
  10925.  
  10926.  The  LET statement uses the following arguments:
  10927.  
  10928. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  10929.  Argument                                Description
  10930.  ────────────────────────────────────────────────────────────────────────────
  10931.   variable                               A variable.
  10932.  
  10933.   expression                             An expression that provides the
  10934.                                          value to assign to the variable.
  10935.  
  10936.  
  10937.  
  10938.  
  10939.  
  10940.   LET statements can be used with record variables only when both variables
  10941.  are the same user-defined type. Use the  LSET statement to assign record
  10942.  variables of different user-defined types.
  10943.  
  10944.  
  10945.  See Also
  10946.  
  10947.   LSET
  10948.  
  10949.  
  10950.  Examples
  10951.  
  10952.  The first example below shows the use of the optional  LET keyword:
  10953.  
  10954.  LET D = 12
  10955.  
  10956.  LET E = 12 - 2
  10957.  
  10958.  LET F = 12 - 4
  10959.  
  10960.  LET SUM = D + E + F
  10961.  
  10962.  PRINT D E F SUM
  10963.  
  10964.  
  10965.  
  10966.  The following program lines perform the same function, without using the
  10967.  LET keyword:
  10968.  
  10969.  D = 12
  10970.  
  10971.  E = 12 - 2
  10972.  
  10973.  F = 12 - 4
  10974.  
  10975.  SUM = D + E + F
  10976.  
  10977.  PRINT D E F SUM
  10978.  
  10979.  
  10980.  
  10981.  Output
  10982.  
  10983.  12 10 8 30
  10984.  
  10985.  
  10986.  
  10987.  LINE Statement
  10988.  ────────────────────────────────────────────────────────────────────────────
  10989.  
  10990.  
  10991.  Action
  10992.  
  10993.  Draws a line or box on the screen.
  10994.  
  10995.  
  10996.  Syntax
  10997.  
  10998.  
  10999.  
  11000.   LINE  STEP ( x1!, y1!)   -  STEP ( x2!, y2!)  ,  color&  , B F ,  style%
  11001.  
  11002.  
  11003.  Remarks
  11004.  
  11005.  
  11006.  The coordinates ( x1!, y1!) and ( x2!, y2!) specify the end points of the
  11007.  line; note that the order in which these end points appear is unimportant,
  11008.  since a line from (10,20) to (120,130) is the same as a line from (120,130)
  11009.  to (10,20).
  11010.  
  11011.  The  STEP option makes the specified coordinates relative to the most-recent
  11012.  point. For example, if the most-recent point referred to by the program were
  11013.  (10,10), then the following statement would draw a line from (10,10) to the
  11014.  point with an x coordinate equal to 10 + 10 and a y coordinate equal to 10 +
  11015.  5, or (20,15):
  11016.  
  11017.  LINE -STEP (10,5)
  11018.  
  11019.  You may establish a new most-recent point by initializing the screen with
  11020.  the  CLS and  SCREEN statements. Using the  PSET,  PRESET,  CIRCLE, and
  11021.  DRAW statements will also establish a new most-recent point.
  11022.  
  11023.  Variations of the  STEP argument are shown below. For the following
  11024.  examples, assume that the last point plotted was (10,10):
  11025.  
  11026. ╓┌─────────────────────────────────┌─────────────────────────────────────────╖
  11027.  ────────────────────────────────────────────────────────────────────────────
  11028.  LINE -(50,50)                     Draws from (10,10) to (50,50).
  11029.  LINE -STEP(50,50)                 Draws from (10,10) to (60,60).
  11030.  LINE (25,25)-STEP(50,50)          Draws from (25,25) to (75,75).
  11031.  LINE STEP(25,25)-STEP(50,50)      Draws from (35,35) to (85,85).
  11032.  LINE STEP(25,25)-(50,50)          Draws from (35,35) to (50,50).
  11033.  
  11034.  
  11035.  
  11036.  
  11037.  The argument  color% is the number of the color in which the line is drawn.
  11038.  (If the B or BF option is used, the box is drawn in this color.) For
  11039.  information on valid colors, see the  SCREEN statement.
  11040.  
  11041.  The B option draws a box with the points ( x1!, y1!) and ( x2!, y2!)
  11042.  specifying diagonally opposite corners.
  11043.  
  11044.  The BF option draws a filled box. This option is similar to the B option; BF
  11045.  also paints the interior of the box with the selected color.
  11046.  
  11047.  The argument  style% is a 16-bit integer mask used to put pixels on the
  11048.  screen. Using  style% is called "line styling." With line styling,  LINE
  11049.  reads the bits in  style% from left to right. If a bit is 0, then no point
  11050.  is plotted; if the bit is 1, a point is plotted. After plotting a point,
  11051.  LINE selects the next bit position in  style%.
  11052.  
  11053.  Because a zero bit in  style% does not change the point on the screen, you
  11054.  may want to draw a background line before using styling so you can have a
  11055.  known background. Style is used for normal lines and boxes, but has no
  11056.  effect on filled boxes.
  11057.  
  11058.  
  11059.  When coordinates specify a point that is not within the current viewport,
  11060.  the line segment to that point is drawn to the border of the viewport.
  11061.  
  11062.  For more information on the  LINE statement, see Chapter 5, "Graphics" in
  11063.  the  Programmer's Guide.
  11064.  
  11065.  
  11066.  See Also
  11067.  
  11068.   CIRCLE,  PSET,  SCREEN Statement
  11069.  
  11070.  
  11071.  Examples
  11072.  
  11073.  The following example uses  LINE statements to display a series of screens
  11074.  with different line graphics. To run this program, your screen must be 320
  11075.  pixels wide by 200 pixels high and support CGA screen mode.
  11076.  
  11077.  SCREEN 1' Set up the screen mode.
  11078.  
  11079.  
  11080.  
  11081.  LINE -(X2, Y2)' Draw a line (in the foreground color)
  11082.  
  11083.  ' from the most recent point to X2,Y2.
  11084.  
  11085.  DO: LOOP WHILE INKEY$ = ""
  11086.  
  11087.  CLS
  11088.  
  11089.  LINE(0, 0)-(319, 199)' Draw a diagonal line across the screen.
  11090.  
  11091.  DO: LOOP WHILE INKEY$ = ""
  11092.  
  11093.  CLS
  11094.  
  11095.  LINE(0, 100)-(319, 100)' Draw a horizontal line across the screen.
  11096.  
  11097.  DO: LOOP WHILE INKEY$ = ""
  11098.  
  11099.  CLS
  11100.  
  11101.  LINE(10, 10)-(20, 20), 2 ' Draw a line in color 2.
  11102.  
  11103.  DO: LOOP WHILE INKEY$ = ""
  11104.  
  11105.  CLS
  11106.  
  11107.  FOR X = 0 to 319' Draw an alternating pattern
  11108.  
  11109.      LINE(X, 0)-(X, 199), X AND 1' (line on/line off) on mono-
  11110.  
  11111.  NEXT' chrome display.
  11112.  
  11113.  DO: LOOP WHILE INKEY$ = ""
  11114.  
  11115.  CLS
  11116.  
  11117.  LINE (0, 0)-(100, 100),, B' Draw a box in the foreground color
  11118.  
  11119.  ' (note that the color is not included).
  11120.  
  11121.  DO: LOOP WHILE INKEY$ = ""
  11122.  
  11123.  CLS
  11124.  
  11125.  LINE STEP(0,0)-STEP(200,200),2,BF ' Draw a filled box in color
  11126.  
  11127.  ' 2 (coordinates are given as
  11128.  
  11129.  ' offsets with the STEP option).
  11130.  
  11131.  DO: LOOP WHILE INKEY$ = ""
  11132.  
  11133.  CLS
  11134.  
  11135.  LINE(0,0)-(160,100),3,,&HFF00' Draw a dashed line from the
  11136.  
  11137.  ' upper-left corner to the
  11138.  
  11139.  ' center of the screen in color 3.
  11140.  
  11141.  
  11142.  LINE INPUT Statement
  11143.  ────────────────────────────────────────────────────────────────────────────
  11144.  
  11145.  
  11146.  Action
  11147.  
  11148.  Enters an entire line (up to 255 characters) from the keyboard to a string
  11149.  variable, without the use of delimiters.
  11150.  
  11151.  
  11152.  Syntax
  11153.  
  11154.  
  11155.  
  11156.   LINE INPUT ; " promptstring";  stringvariable
  11157.  
  11158.  
  11159.  Remarks
  11160.  
  11161.  
  11162.  The argument  promptstring is a string constant. After  promptstring is
  11163.  displayed on the screen, entry of data items into the data input field is
  11164.  accepted. A question mark is not printed unless it is part of  promptstring.
  11165.  All input from the end of  promptstring to the carriage return is assigned
  11166.  to  stringvariable.
  11167.  
  11168.  A semicolon immediately after the  LINE INPUT keywords keeps the cursor at
  11169.  the next character position after the user presses Enter. Omitting a
  11170.  semicolon causes the cursor to skip to the next line.
  11171.  
  11172.   LINE INPUT uses the same editing characters as  INPUT.
  11173.  
  11174.  
  11175.  See Also
  11176.  
  11177.   INPUT$ Function,  INPUT Statement
  11178.  
  11179.  
  11180.  Example
  11181.  
  11182.  See the  DEF SEG statement programming example, which uses the  LINE INPUT
  11183.  statement.
  11184.  
  11185.  
  11186.  LINE INPUT # Statement
  11187.  ────────────────────────────────────────────────────────────────────────────
  11188.  
  11189.  
  11190.  Action
  11191.  
  11192.  Reads an entire line from a sequential file into a string variable.
  11193.  
  11194.  
  11195.  Syntax
  11196.  
  11197.  
  11198.  
  11199.   LINE INPUT # filenumber%,  stringvariable$
  11200.  
  11201.  
  11202.  Remarks
  11203.  
  11204.  
  11205.  The  LINE INPUT  # statement uses the following arguments:
  11206.  
  11207. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  11208.  Argument                                Description
  11209.  ────────────────────────────────────────────────────────────────────────────
  11210.   filenumber%                            The number used in the  OPEN
  11211.                                          statement to open the file.
  11212.  
  11213.   stringvariable$                        The variable the line is assigned
  11214.                                          to.
  11215.  
  11216.  Argument                                Description
  11217.  ────────────────────────────────────────────────────────────────────────────
  11218. 
  11219.  
  11220.  
  11221.  The  LINE INPUT # statement reads all characters in the sequential file up
  11222.  to a carriage return. It then skips over the carriage-return-and-line-feed
  11223.  sequence.
  11224.  
  11225.   LINE INPUT # is especially useful if a text file is being read one line at
  11226.  a time.
  11227.  
  11228.  
  11229.  See Also
  11230.  
  11231.   INPUT$ Function,  INPUT Statement,  INPUT  # Statement,  LINE INPUT
  11232.  
  11233.  
  11234.  Example
  11235.  
  11236.  The following example creates a data file consisting of customer records
  11237.  that include LAST NAME, FIRST NAME, AGE, and SEX. After the file is
  11238.  complete, the  LINE  INPUT  # statement is used to read the individual
  11239.  records so they can be displayed on the screen.
  11240.  
  11241.  OPEN "LIST" FOR OUTPUT AS #1
  11242.  
  11243.  
  11244.  PRINT "CUSTOMER INFORMATION:"
  11245.  
  11246.  
  11247.  ' Get customer information.
  11248.  
  11249.  
  11250.  DO
  11251.  
  11252.  
  11253.      PRINT
  11254.  
  11255.  
  11256.      INPUT "   LAST NAME:  ", LName$
  11257.  
  11258.  
  11259.      INPUT "   FIRST NAME: ", FrName$
  11260.  
  11261.  
  11262.      INPUT "   AGE:        ", Age$
  11263.  
  11264.  
  11265.      INPUT "   SEX:        ", Sex$
  11266.  
  11267.  
  11268.      Sex$ = UCASE$(Sex$)
  11269.  
  11270.  
  11271.      WRITE #1, LName$, FrName$, Age$, Sex$
  11272.  
  11273.  
  11274.      INPUT "Add another"; R$
  11275.  
  11276.  
  11277.  LOOP WHILE UCASE$(R$) = "Y"
  11278.  
  11279.  
  11280.  CLOSE #1
  11281.  
  11282.  
  11283.  
  11284.  
  11285.  
  11286.  ' Echo the file back.
  11287.  
  11288.  
  11289.  OPEN "LIST" FOR INPUT AS #1
  11290.  
  11291.  
  11292.  CLS
  11293.  
  11294.  
  11295.  PRINT "Records in file:": PRINT
  11296.  
  11297.  
  11298.  DO WHILE NOT EOF(1)
  11299.  
  11300.  
  11301.      LINE INPUT #1, REC$   ' Read records from file.
  11302.  
  11303.  
  11304.      PRINT REC$            ' Print the records on the screen.
  11305.  
  11306.  
  11307.  LOOP
  11308.  
  11309.  
  11310.  ' Remove file from disk.
  11311.  
  11312.  
  11313.  CLOSE #1
  11314.  
  11315.  
  11316.  KILL "LIST"
  11317.  
  11318.  
  11319.  
  11320.  
  11321.  Output
  11322.  
  11323.  
  11324.  
  11325.  CUSTOMER INFORMATION:
  11326.  
  11327.  
  11328.  
  11329.  
  11330.  
  11331.    LAST NAME:  Saintsbury
  11332.  
  11333.  
  11334.    FIRST NAME: Aloysius
  11335.  
  11336.  
  11337.    AGE:        35
  11338.  
  11339.  
  11340.    SEX:        m
  11341.  
  11342.  
  11343.  Add another? y
  11344.  
  11345.  
  11346.  
  11347.  
  11348.  
  11349.    LAST NAME:  Frangio
  11350.  
  11351.  
  11352.    FIRST NAME: Louisa
  11353.  
  11354.  
  11355.    AGE:        27
  11356.  
  11357.  
  11358.    SEX:        f
  11359.  
  11360.  
  11361.  Add another? n
  11362.  
  11363.  
  11364.  
  11365.  
  11366.  
  11367.  Records in file:
  11368.  
  11369.  
  11370.  
  11371.  
  11372.  
  11373.  "Saintsbury","Aloysius","35","M"
  11374.  
  11375.  
  11376.  "Frangio","Louisa","27","F"
  11377.  
  11378.  
  11379.  LOC Function
  11380.  ────────────────────────────────────────────────────────────────────────────
  11381.  
  11382.  
  11383.  Action
  11384.  
  11385.  Returns the current position within an open file.
  11386.  
  11387.  
  11388.  Syntax
  11389.  
  11390.  
  11391.  
  11392.   LOC( filenumber%)
  11393.  
  11394.  
  11395.  Remarks
  11396.  
  11397.  
  11398.  The argument  filenumber% is the number of an open file or device. With
  11399.  random-access files, the  LOC function returns the number of the last record
  11400.  read from, or written to, the file. With sequential files,  LOC returns the
  11401.  current byte position in the file, divided by 128. With binary mode files,
  11402.  LOC returns the position of the last byte read or written.
  11403.  
  11404.  For a communications device,  LOC returns the number of characters in the
  11405.  input queue waiting to be read. The value returned depends on whether the
  11406.  device was opened in ASCII or binary mode. In ASCII mode, the low-level
  11407.  routines stop queuing characters as soon as an end-of-file is received. The
  11408.  end-of-file itself is not queued and cannot be read. If you attempt to read
  11409.  the end-of-file, BASIC generates the error message Input past end of file.
  11410.  In binary mode, the end-of-file character is ignored and the entire file can
  11411.  be read.
  11412.  
  11413.  For a PIPE device,  LOC returns 1 if any data are available in the PIPE
  11414.  queue.
  11415.  
  11416.  
  11417.  Note
  11418.  
  11419.  The  LOC function cannot be used on ISAM tables, or the SCRN, KYBD, or LPT n
  11420.  devices.
  11421.  
  11422.  
  11423.  See Also
  11424.  
  11425.   EOF,  LOF,  OPEN (File I/O)
  11426.  
  11427.  
  11428.  Example
  11429.  
  11430.  The following example stops the program if the current file position is
  11431.  beyond 50. Note that this example is incomplete.
  11432.  
  11433.  IF LOC(1) > 50 THEN STOP
  11434.  
  11435.  
  11436.  LOCATE Statement
  11437.  ────────────────────────────────────────────────────────────────────────────
  11438.  
  11439.  
  11440.  Action
  11441.  
  11442.  Moves the cursor to the specified position on the screen.
  11443.  
  11444.  
  11445.  Syntax
  11446.  
  11447.  
  11448.  
  11449.   LOCATE  row% ,  column% ,  cursor% ,  start% ,  stop%
  11450.  
  11451.  
  11452.  Remarks
  11453.  
  11454.  
  11455.  The  LOCATE statement uses the following arguments:
  11456.  
  11457. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  11458.  Argument                                Description
  11459.  ────────────────────────────────────────────────────────────────────────────
  11460.   row%                                   The number of a row on the screen;
  11461.                                           row% is a numeric expression
  11462.                                          returning an integer. If  row% is
  11463.                                          not specified, the row location of
  11464.                                          the cursor does not change.
  11465.  
  11466.   column%                                The number of a column on the
  11467.                                          screen;  column% is a numeric
  11468.  Argument                                Description
  11469.  ────────────────────────────────────────────────────────────────────────────
  11470.                                         screen;  column% is a numeric
  11471.                                          expression returning an integer.
  11472.                                          If  column% is not specified, the
  11473.                                          column location of the cursor does
  11474.                                          not change.
  11475.  
  11476.   cursor%                                A Boolean value indicating whether
  11477.                                          the cursor is visible or not. A
  11478.                                          value of 0 indicates cursor  off;
  11479.                                          a value of 1 indicates cursor  on.
  11480.  
  11481.   start%,  stop%                         The starting and ending raster
  11482.                                          scan lines of the cursor on the
  11483.                                          screen. The arguments  start% and
  11484.                                          stop% redefine the cursor size and
  11485.                                          must be numeric expressions
  11486.                                          returning an integer between 0 and
  11487.                                          31, inclusive.
  11488.  
  11489.  Argument                                Description
  11490.  ────────────────────────────────────────────────────────────────────────────
  11491. 
  11492.  
  11493.  
  11494.  
  11495.  
  11496.  You can omit any argument from the statement except that if  stop% is
  11497.  specified,  start% also must be specified. When you omit  row% or  column%,
  11498.  LOCATE leaves the cursor at the row or column where it was moved by the most
  11499.  recently executed input or output statement (such as  LOCATE,  PRINT, or
  11500.  INPUT). When you omit other arguments, BASIC assumes the previous value for
  11501.  the argument.
  11502.  
  11503.  Note that the  start% and  stop% lines are the CRT scan lines that specify
  11504.  which pixels on the screen are lit. A wider range between the  start% and
  11505.  stop% lines produces a taller cursor, such as one that occupies an entire
  11506.  character block. In OS/2 real mode and under DOS,  LOCATE assumes there are
  11507.  eight lines (numbered 0 to 7) in the cursor. In OS/2 protected mode there
  11508.  are 16 lines (numbered 0 to 15).
  11509.  
  11510.  When  start% is greater than  stop%,  LOCATE produces a two-part cursor. If
  11511.  the  start% line is given but the  stop% line is omitted,  stop% assumes the
  11512.  same value as  start%. A value of 8 for both  start% and  stop% produces the
  11513.  underline cursor. The maximum cursor size is determined by the character
  11514.  block size of the screen mode in use. Setting  start% greater than  stop%
  11515.  displays a full-height cursor on VGA-equipped systems.
  11516.  
  11517.  For screen mode information, see the entry for the  SCREEN statement.
  11518.  
  11519.  The last line on the screen is reserved for the soft-key display and is not
  11520.  accessible to the cursor unless the soft-key display is off ( KEY OFF) and
  11521.  LOCATE is used with  PRINT to write on the line.
  11522.  
  11523.  
  11524.  See Also
  11525.  
  11526.  
  11527.   CSRLIN,  POS
  11528.  
  11529.  
  11530.  Examples
  11531.  
  11532.  The first example shows the effects on the cursor of different  LOCATE
  11533.  statements:
  11534.  
  11535.  CLS' Clear screen.
  11536.  
  11537.  
  11538.  LOCATE 5,5 ' Moves cursor to row 5, column 5.
  11539.  
  11540.  
  11541.  PRINT "C"
  11542.  
  11543.  
  11544.  DO
  11545.  
  11546.  
  11547.  LOOP WHILE INKEY$ = ""
  11548.  
  11549.  
  11550.  LOCATE 1,1 ' Moves cursor to upper-left corner of the screen.
  11551.  
  11552.  
  11553.  PRINT "C"
  11554.  
  11555.  
  11556.  DO
  11557.  
  11558.  
  11559.  LOOP WHILE INKEY$ = ""
  11560.  
  11561.  
  11562.  LOCATE , ,1' Makes cursor visible; position remains unchanged.
  11563.  
  11564.  
  11565.  PRINT "C"
  11566.  
  11567.  
  11568.  DO
  11569.  
  11570.  
  11571.  LOOP WHILE INKEY$ = ""
  11572.  
  11573.  
  11574.  LOCATE , , ,7 ' Position and cursor visibility remain unchanged;
  11575.  
  11576.  
  11577.  ' sets the cursor to display at the bottom of the
  11578.  
  11579.  
  11580.  ' character box starting and ending on scan line 7.
  11581.  
  11582.  
  11583.  PRINT "C"
  11584.  
  11585.  
  11586.  DO
  11587.  
  11588.  
  11589.  LOOP WHILE INKEY$ = ""
  11590.  
  11591.  
  11592.  LOCATE 5,1,1,0,7  ' Moves the cursor to line 5, column 1;
  11593.  
  11594.  
  11595.  ' turns cursor on; cursor covers entire
  11596.  
  11597.  
  11598.  ' character cell starting at scan line
  11599.  
  11600.  
  11601.  ' 0 and ending on scan line 7.
  11602.  
  11603.  
  11604.  PRINT "C"
  11605.  
  11606.  
  11607.  DO
  11608.  
  11609.  
  11610.  LOOP WHILE INKEY$ = ""
  11611.  
  11612.  
  11613.  END
  11614.  
  11615.  The following example prints a menu on the screen, then waits for input in
  11616.  the allowable range (1-4). If a number outside that range is entered, the
  11617.  program continues to prompt for a selection.
  11618.  
  11619.  
  11620.  Note that this program is incomplete.
  11621.  
  11622.  CONST FALSE = 0, TRUE = NOT FALSE
  11623.  
  11624.  
  11625.  DO
  11626.  
  11627.  
  11628.  CLS
  11629.  
  11630.  
  11631.  PRINT "MAIN MENU": PRINT
  11632.  
  11633.  
  11634.  PRINT "1)  Add Records"
  11635.  
  11636.  
  11637.  PRINT "2)  Display/Update/Delete a Record"
  11638.  
  11639.  
  11640.  PRINT "3)  Print Out List of People Staying at Hotel"
  11641.  
  11642.  
  11643.  PRINT "4)  End Program"
  11644.  
  11645.  
  11646.  ' Change cursor to a block.
  11647.  
  11648.  
  11649.  LOCATE , , 1, 1, 12
  11650.  
  11651.  
  11652.  LOCATE 12, 1
  11653.  
  11654.  
  11655.  PRINT "What is your selection?";
  11656.  
  11657.  
  11658.  DO
  11659.  
  11660.  
  11661.  CH$ = INPUT$(1)
  11662.  
  11663.  
  11664.  LOOP WHILE (CH$ < "1" OR CH$ > "4")
  11665.  
  11666.  
  11667.  PRINT CH$
  11668.  
  11669.  
  11670.  
  11671.  
  11672.  
  11673.  ' Call the appropriate SUB procedure.
  11674.  
  11675.  
  11676.  SELECT CASE VAL(CH$)
  11677.  
  11678.  
  11679.  CASE 1
  11680.  
  11681.  
  11682.  CALL Add
  11683.  
  11684.  
  11685.  CASE 2
  11686.  
  11687.  
  11688.  CALL Search
  11689.  
  11690.  
  11691.  CASE 3
  11692.  
  11693.  
  11694.  CALL Hotel
  11695.  
  11696.  
  11697.  CASE 4
  11698.  
  11699.  
  11700.  CALL Quit
  11701.  
  11702.  
  11703.  END SELECT
  11704.  
  11705.  
  11706.  LOOP WHILE NOT ENDPROG
  11707.  
  11708.  
  11709.    .
  11710.  
  11711.  
  11712.    .
  11713.  
  11714.  
  11715.    .
  11716.  
  11717.  
  11718.  END
  11719.  
  11720.  
  11721.  LOCK...UNLOCK Statement
  11722.  ────────────────────────────────────────────────────────────────────────────
  11723.  
  11724.  
  11725.  Action
  11726.  
  11727.  Controls access by other processes to all or part of an opened file.
  11728.  
  11729.  
  11730.  Syntax
  11731.  
  11732.  
  11733.  
  11734.   LOCK #  filenumber% ,{ record& |  start&  TO  end&}
  11735.  .
  11736.  
  11737.  .
  11738.  
  11739.  .
  11740.  
  11741.  
  11742.  
  11743.   UNLOCK #  filenumber% ,{ record& |  start&  TO  end&}
  11744.  
  11745.  
  11746.  Remarks
  11747.  
  11748.  
  11749.  These statements are used in networked environments where several processes
  11750.  might need access to the same file. The  LOCK and  UNLOCK statements use the
  11751.  following arguments:
  11752.  
  11753. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  11754.  Argument                                Description
  11755.  ────────────────────────────────────────────────────────────────────────────
  11756.   filenumber%                            The number used in the  OPEN
  11757.                                          statement to open the file.
  11758.  
  11759.   record&                                The number of the record or byte
  11760.                                          to be locked. The argument
  11761.                                          record& can be any number from 1
  11762.  Argument                                Description
  11763.  ────────────────────────────────────────────────────────────────────────────
  11764.                                         record& can be any number from 1
  11765.                                          to 2,147,483,647 (equivalent to
  11766.                                          231 -1). A record can be up to
  11767.                                          32,767 bytes in length.
  11768.  
  11769.   start&                                 The number of the first record or
  11770.                                          byte to be locked.
  11771.  
  11772.   end&                                   The number of the last record or
  11773.                                          byte to be locked..
  11774.  
  11775.  
  11776.  
  11777.  For binary-mode files,  record&,  start&, and  end& represent the number of
  11778.  a byte relative to the beginning of the file. The first byte in a file is
  11779.  byte 1.
  11780.  
  11781.  For random-access files,  record&,  start&, and  end& represent the number
  11782.  of a record relative to the beginning of the file. The first record is
  11783.  record 1.
  11784.  
  11785.  If the file has been opened for sequential input or output,  LOCK and
  11786.  UNLOCK affect the entire file, regardless of the range specified by  start&
  11787.  and  end&.
  11788.  
  11789.  The  LOCK and  UNLOCK statements are always used in pairs. The arguments to
  11790.  LOCK and  UNLOCK must match exactly.
  11791.  
  11792.  If you specify just one record, then only that record is locked or unlocked.
  11793.  If you specify a range of records and omit a starting record ( start&), then
  11794.  all records from the first record to the end of the range ( end&) are locked
  11795.  or unlocked.  LOCK with no  record& locks the entire file, while  UNLOCK
  11796.  with no  record& unlocks the entire file.
  11797.  
  11798.   LOCK and  UNLOCK execute only at run time if you are using OS/2 or versions
  11799.  of DOS that support networking (version 3.1 or later). In DOS, you must run
  11800.  the SHARE.EXE program to enable locking operations. Using earlier versions
  11801.  of DOS causes BASIC to generate the error message Feature unavailable if
  11802.  LOCK and  UNLOCK are executed.
  11803.  
  11804.  
  11805.  Warning
  11806.  
  11807.  Be sure to remove all locks with an  UNLOCK statement before closing a file
  11808.  or terminating your program. Failing to remove locks produces unpredictable
  11809.  results.
  11810.  The arguments to  LOCK and  UNLOCK must match exactly.
  11811.  Do not use  LOCK and  UNLOCK on devices or ISAM tables.
  11812.  
  11813.  
  11814.  If you attempt to access a file that is locked, BASIC may generate the
  11815.  following error messages:
  11816.  
  11817.  Bad record number
  11818.  
  11819.  Permission denied
  11820.  
  11821.  
  11822.  Example
  11823.  
  11824.  The following example illustrates the use of the  LOCK and  UNLOCK
  11825.  statements. The program creates a sample data record in a random-access
  11826.  file. Once the sample record is created and closed, the program again opens
  11827.  the file to allow customer information to be updated. As a record is opened,
  11828.  it is locked to prevent use by another terminal that has access to the same
  11829.  file. After the update is complete, the record is unlocked, again allowing
  11830.  modifications by others with access.
  11831.  
  11832.  ' Define the record.
  11833.  
  11834.  
  11835.  TYPE AccountRec
  11836.  
  11837.  
  11838.     Payer AS STRING * 20
  11839.  
  11840.  
  11841.     Address AS STRING * 20
  11842.  
  11843.  
  11844.     Place AS STRING * 20
  11845.  
  11846.  
  11847.     Owe AS SINGLE
  11848.  
  11849.  
  11850.  END TYPE
  11851.  
  11852.  
  11853.  
  11854.  
  11855.  
  11856.  DIM CustRec AS AccountRec
  11857.  
  11858.  
  11859.  
  11860.  
  11861.  
  11862.  ' This section creates a sample record to use.
  11863.  
  11864.  
  11865.  ON ERROR GOTO ErrHandler
  11866.  
  11867.  
  11868.  
  11869.  
  11870.  
  11871.  OPEN "MONITOR" FOR RANDOM SHARED AS #1 LEN = LEN(CustRec)
  11872.  
  11873.  
  11874.  
  11875.  
  11876.  
  11877.  CustRec.Payer = "George Washington"
  11878.  
  11879.  
  11880.  CustRec.Address = "1 Cherry Tree Lane"
  11881.  
  11882.  
  11883.  CustRec.Place = "Mt. Vernon, VA"
  11884.  
  11885.  
  11886.  CustRec.Owe = 12!
  11887.  
  11888.  
  11889.  PUT #1, 1, CustRec          ' Put one record in the file.
  11890.  
  11891.  
  11892.  CLOSE #1
  11893.  
  11894.  
  11895.  
  11896.  
  11897.  
  11898.  ' This section opens the sample record for updating.
  11899.  
  11900.  
  11901.  OPEN "MONITOR" FOR RANDOM SHARED AS #1 LEN = LEN(CustRec)
  11902.  
  11903.  
  11904.  DO
  11905.  
  11906.  
  11907.      Number% = 0             ' Reset to zero.
  11908.  
  11909.  
  11910.      DO UNTIL Number% = 1    ' Force user to input 1.
  11911.  
  11912.  
  11913.          CLS : LOCATE 10, 10
  11914.  
  11915.  
  11916.          INPUT "Customer Number?   #"; Number%
  11917.  
  11918.  
  11919.      LOOP
  11920.  
  11921.  
  11922.      ' Lock the current record so another process
  11923.  
  11924.  
  11925.      ' doesn't change it while you're using it.
  11926.  
  11927.  
  11928.      LOCK #1, Number%
  11929.  
  11930.  
  11931.      GET #1, Number%, CustRec
  11932.  
  11933.  
  11934.      LOCATE 11, 10: PRINT "Customer: "; CustRec.Payer
  11935.  
  11936.  
  11937.      LOCATE 12, 10: PRINT "Address:  "; CustRec.Address
  11938.  
  11939.  
  11940.      LOCATE 13, 10: PRINT "Currently owes: $"; CustRec.Owe
  11941.  
  11942.  
  11943.      LOCATE 15, 10: INPUT "Change (+ or -)", Change!
  11944.  
  11945.  
  11946.      CustRec.Owe = CustRec.Owe + Change!
  11947.  
  11948.  
  11949.      PUT #1, Number%, CustRec
  11950.  
  11951.  
  11952.      ' Unlock the record.
  11953.  
  11954.  
  11955.      UNLOCK #1, Number%
  11956.  
  11957.  
  11958.      LOCATE 17, 10: INPUT "Update another? ", Continue$
  11959.  
  11960.  
  11961.      Update$ = UCASE$(LEFT$(Continue$, 1))
  11962.  
  11963.  
  11964.  LOOP WHILE Update$ = "Y"
  11965.  
  11966.  
  11967.  CLOSE #1
  11968.  
  11969.  
  11970.  KILL "MONITOR"' Remove file from disk.
  11971.  
  11972.  
  11973.  END
  11974.  
  11975.  
  11976.  
  11977.  
  11978.  
  11979.  ErrHandler:
  11980.  
  11981.  
  11982.  IF ERR = 70 THEN        ' Permission-denied error.
  11983.  
  11984.  
  11985.      CLS
  11986.  
  11987.  
  11988.      PRINT "You must run SHARE.EXE before running this example."
  11989.  
  11990.  
  11991.      PRINT "Exit the programming environment, run SHARE.EXE, and"
  11992.  
  11993.  
  11994.      PRINT "reenter the programming environment to run this"
  11995.  
  11996.  
  11997.      PRINT "example. Do not shell to DOS to run SHARE.EXE or you"
  11998.  
  11999.  
  12000.      PRINT "may not be able to run other programs until you reboot."
  12001.  
  12002.  
  12003.  END IF
  12004.  
  12005.  
  12006.  END
  12007.  
  12008.  
  12009.  LOF Function
  12010.  ────────────────────────────────────────────────────────────────────────────
  12011.  
  12012.  
  12013.  Action
  12014.  
  12015.  Returns the size of an open file (in bytes), the number of records in an
  12016.  ISAM table, or, when used with the  OPEN  COM statement, the number of bytes
  12017.  free in the output buffer.
  12018.  
  12019.  
  12020.  Syntax
  12021.  
  12022.  
  12023.  
  12024.   LOF( filenumber%)
  12025.  
  12026.  
  12027.  Remarks
  12028.  
  12029.  
  12030.  The argument  filenumber% is the number used in the  OPEN statement to open
  12031.  the file, device, or ISAM table.
  12032.  
  12033.  
  12034.  Important
  12035.  
  12036.   LOF can be used only on disk files, ISAM tables, or COM devices. It cannot
  12037.  be used with the BASIC devices SCRN, KYBD, CONS, LPT n, or PIPE.
  12038.  
  12039.  
  12040.  See Also
  12041.  
  12042.   BOF,  EOF,  LOC,  OPEN (File I/O)
  12043.  
  12044.  
  12045.  Example
  12046.  
  12047.  See the programming example for the  SEEKGT,  SEEKGE, and  SEEKEQ
  12048.  statements, which uses the  LOF function in the context of ISAM.
  12049.  
  12050.  
  12051.  LOG Function
  12052.  ────────────────────────────────────────────────────────────────────────────
  12053.  
  12054.  
  12055.  Action
  12056.  
  12057.  Returns the natural logarithm of a numeric expression.
  12058.  
  12059.  
  12060.  Syntax
  12061.  
  12062.  
  12063.  
  12064.   LOG( numeric-expression)
  12065.  
  12066.  
  12067.  Remarks
  12068.  
  12069.  
  12070.  The argument  numeric-expression must be greater than zero. The natural
  12071.  logarithm is the logarithm to the base  e. The constant  e is approximately
  12072.  equal to 2.718282.
  12073.  
  12074.   LOG is calculated in single precision if  numeric-expression is an integer
  12075.  or single-precision value. If you use any other numeric type,  LOG is
  12076.  calculated in double precision.
  12077.  
  12078.  You can calculate base-10 logarithms by dividing the natural logarithm of
  12079.  the number by the natural logarithm of 10. The following  FUNCTION procedure
  12080.  calculates base-10 logarithms:
  12081.  
  12082.  FUNCTION Log10(X) STATIC
  12083.  
  12084.     Log10=LOG(X)/LOG(10#)
  12085.  
  12086.  END FUNCTION
  12087.  
  12088.  
  12089.  See Also
  12090.  
  12091.  
  12092.   EXP
  12093.  
  12094.  
  12095.  Example
  12096.  
  12097.  The following example prints the value of  e and then prints the natural
  12098.  logarithms of  e taken to the first, second, and third powers:
  12099.  
  12100.  CLS                    ' Clear screen.
  12101.  
  12102.  
  12103.  PRINT EXP(1),
  12104.  
  12105.  
  12106.  FOR I = 1 TO 3
  12107.  
  12108.  
  12109.      PRINT LOG(EXP(1) ^ I),
  12110.  
  12111.  
  12112.  NEXT
  12113.  
  12114.  
  12115.  PRINT
  12116.  
  12117.  
  12118.  
  12119.  
  12120.  Output
  12121.  
  12122.  
  12123.  
  12124.  2.718282       1       2       3
  12125.  
  12126.  
  12127.  
  12128.  
  12129.  
  12130.  LPOS Function
  12131.  ────────────────────────────────────────────────────────────────────────────
  12132.  
  12133.  
  12134.  Action
  12135.  
  12136.  Returns the number of characters sent to the printer since the last carriage
  12137.  return was sent.
  12138.  
  12139.  
  12140.  Syntax
  12141.  
  12142.  
  12143.  
  12144.   LPOS( n%)
  12145.  
  12146.  
  12147.  Remarks
  12148.  
  12149.  
  12150.  The argument  n% is an integer expression with a value between 0 and 3 that
  12151.  indicates one of the printers. For example, LPT1 would be tested with
  12152.  LPOS(1) or LPOS(0), LPT2 would be tested with LPOS(2), and LPT3 would be
  12153.  tested with LPOS(3).
  12154.  
  12155.  The  LPOS function does not necessarily give the physical position of the
  12156.  print head because it does not expand tab characters. In addition, some
  12157.  printers may buffer characters.
  12158.  
  12159.  
  12160.  Example
  12161.  
  12162.  See the  LPRINT statement programming example, which uses the  LPOS
  12163.  function.
  12164.  
  12165.  
  12166.  LPRINT, LPRINT USING Statements
  12167.  ────────────────────────────────────────────────────────────────────────────
  12168.  
  12169.  
  12170.  Action
  12171.  
  12172.  Print data on the printer LPT1.
  12173.  
  12174.  
  12175.  Syntax
  12176.  
  12177.  
  12178.  
  12179.   LPRINT  expressionlist {;|,}
  12180.  
  12181.  
  12182.   LPRINT  USING  formatstring$;  expressionlist {;|,}
  12183.  
  12184.  
  12185.  Remarks
  12186.  
  12187.  
  12188.  These statements function in the same way as the  PRINT and  PRINT USING
  12189.  statements except that output goes to the printer.
  12190.  
  12191.  The following list describes the parts of the  LPRINT and  LPRINT USING
  12192.  statements:
  12193.  
  12194. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  12195.  Part                                    Description
  12196.  ────────────────────────────────────────────────────────────────────────────
  12197.   expressionlist                         The values that are printed on
  12198.                                          printer LPT1.
  12199.  
  12200.   formatstring$                          Specifies the format, using the
  12201.                                          same formatting characters as the
  12202.                                          PRINT USING statement.
  12203.  Part                                    Description
  12204.  ────────────────────────────────────────────────────────────────────────────
  12205.                                         PRINT USING statement.
  12206.  
  12207.  {;|,}                                   Determines the location on the
  12208.                                          page of the first value printed by
  12209.                                          the next statement to use LPT1
  12210.                                          (such as the next  LPRINT
  12211.                                          statement or a  PRINT # or  WRITE
  12212.                                          # directing data to LPT1). The
  12213.                                          semicolon means to print
  12214.                                          immediately after the last value
  12215.                                          in this  LPRINT statement; the
  12216.                                          comma means to print at the start
  12217.                                          of the next unoccupied print zone.
  12218.  
  12219.  
  12220.  
  12221.  The printer output from an  LPRINT statement will be the same as the screen
  12222.  output from a  PRINT statement, if both statements have the same
  12223.  expressionlist values and output-line width.
  12224.  
  12225.  The printer output from an  LPRINT  USING statement will be the same as the
  12226.  screen output from a  PRINT  USING statement, if both statements have the
  12227.  same values for  formatstring$,  expressionlist, and output-line width.
  12228.  
  12229.  The  LPRINT statement assumes an 80-character-wide printer. This width can
  12230.  be changed with a  WIDTH statement.
  12231.  
  12232.  If you use  LPRINT with no arguments, a blank line is printed.
  12233.  
  12234.  
  12235.  Warning
  12236.  
  12237.  Because the  LPRINT statement uses the LPT1 printer device, you should not
  12238.  use  LPRINT in a program that also contains an OPEN "LPT1" statement. Using
  12239.  these two statements together produces unpredictable results.
  12240.  
  12241.  
  12242.  BASICA
  12243.  
  12244.  An LPRINT CHR$(13) statement actually outputs both CHR$(13) and CHR$(10).
  12245.  This feature was created to provide compatibility with BASICA.
  12246.  
  12247.  
  12248.  See Also
  12249.  
  12250.  
  12251.   PRINT, PRINT USING,  WIDTH
  12252.  
  12253.  
  12254.  Example
  12255.  
  12256.  The following example prompts the user for team names and the names of
  12257.  players on each team. Then it prints the players and their teams on the
  12258.  printer.
  12259.  
  12260.  CLS' Clear screen.
  12261.  
  12262.  
  12263.  LPRINT "Team Members"; TAB(76); "TEAM" : LPRINT
  12264.  
  12265.  
  12266.  INPUT "How many teams"; TEAMS
  12267.  
  12268.  
  12269.  INPUT "How many players per team";PPT
  12270.  
  12271.  
  12272.  PRINT
  12273.  
  12274.  
  12275.  FOR T = 1 TO TEAMS
  12276.  
  12277.  
  12278.  INPUT "Team name: ", TEAM$
  12279.  
  12280.  
  12281.  FOR P = 1 TO PPT
  12282.  
  12283.  
  12284.  INPUT "   Enter player name: ", PLAYER$
  12285.  
  12286.  
  12287.  LPRINT PLAYER$;
  12288.  
  12289.  
  12290.  IF P < PPT THEN
  12291.  
  12292.  
  12293.  IF LPOS(0) > 55 THEN  ' Print a new line if print
  12294.  
  12295.  
  12296.  LPRINT : LPRINT "     ";  ' head is past column 55.
  12297.  
  12298.  
  12299.  ELSE
  12300.  
  12301.  
  12302.  LPRINT ", ";' Otherwise, print a comma.
  12303.  
  12304.  
  12305.  END IF
  12306.  
  12307.  
  12308.  END IF
  12309.  
  12310.  
  12311.  NEXT P
  12312.  
  12313.  
  12314.  LPRINT STRING$(80-LPOS(0)-LEN(TEAM$),"."); TEAM$
  12315.  
  12316.  
  12317.  NEXT T
  12318.  
  12319.  
  12320.  LSET Statement
  12321.  ────────────────────────────────────────────────────────────────────────────
  12322.  
  12323.  
  12324.  Action
  12325.  
  12326.  Moves data from memory to a random-access file buffer (in preparation for a
  12327.  PUT statement), copies one record variable to another, or left-justifies the
  12328.  value of a string in a string variable.
  12329.  
  12330.  
  12331.  Syntax 1
  12332.  
  12333.   LSET  stringvariable$= stringexpression$
  12334.  
  12335.  Syntax 2
  12336.  
  12337.  
  12338.  
  12339.  
  12340.   LSET  recordvariable1= recordvariable2
  12341.  
  12342.  
  12343.  Remarks
  12344.  
  12345.  
  12346.  The  LSET statement uses the following arguments:
  12347.  
  12348. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  12349.  Argument                                Description
  12350.  Argument                                Description
  12351.  ────────────────────────────────────────────────────────────────────────────
  12352.   stringvariable$                        Usually a random-access file field
  12353.                                          defined in a  FIELD statement,
  12354.                                          although it can be any string
  12355.                                          variable.
  12356.  
  12357.   stringexpression$                      The value that is assigned to
  12358.                                          stringvariable$ and is
  12359.                                          left-justified.
  12360.  
  12361.   recordvariable1                        A record variable of any data type.
  12362.  
  12363.   recordvariable2                        A record variable of any data type.
  12364.  
  12365.  
  12366.  
  12367.  
  12368.  
  12369.  If  stringexpression$ requires fewer bytes than were defined for
  12370.  stringvariable$ in the  FIELD statement, the  LSET function left-justifies
  12371.  the string in the field ( RSET right-justifies the string). Spaces are used
  12372.  to pad the extra positions. If the string is too long for the field, both
  12373.  LSET and  RSET truncate characters from the right. Numeric values must be
  12374.  converted to strings before they are justified with the  LSET or  RSET
  12375.  statements.
  12376.  
  12377.  You also can use  LSET or  RSET with a string variable not defined in a
  12378.  FIELD statement to left-justify or right-justify a string in a given field.
  12379.  For example, the following program lines will right-justify the string N$ in
  12380.  a 20-character field:
  12381.  
  12382.  A$=SPACE$(20)
  12383.  
  12384.  RSET A$=N$
  12385.  
  12386.  This can be useful for formatting printed output.
  12387.  
  12388.  
  12389.  You can use  LSET with Syntax 2 to assign one record variable to another.
  12390.  The following example copies the contents of RecTwo to RecOne:
  12391.  
  12392.  
  12393.  TYPE TwoString
  12394.  
  12395.     StrFld AS STRING * 2
  12396.  
  12397.  END TYPE
  12398.  
  12399.  TYPE ThreeString
  12400.  
  12401.     StrFld AS STRING * 3
  12402.  
  12403.  END TYPE
  12404.  
  12405.  DIM RecOne AS TwoString, RecTwo AS ThreeString
  12406.  
  12407.  .
  12408.  
  12409.  .
  12410.  
  12411.  .
  12412.  
  12413.  LSET RecOne = RecTwo
  12414.  
  12415.  Notice that  LSET is used to assign record variables of differing types.
  12416.  Record variables of the same type also can be assigned using  LET. Also,
  12417.  because RecOne is only two bytes long, only two bytes are copied from
  12418.  RecTwo.  LSET copies only the number of bytes in the shorter of the two
  12419.  record variables.
  12420.  
  12421.  
  12422.  
  12423.  See Also
  12424.  
  12425.   LET;  MKI$,  MKL$,  MKS$,  MKD$,  MKC$;  PUT (File I/O);  RSET
  12426.  
  12427.  
  12428.  Example
  12429.  
  12430.  The following example shows the effects of using  LSET and  RSET to assign
  12431.  values to fixed- and variable-length strings:
  12432.  
  12433.  DIM TmpStr2 AS STRING * 25
  12434.  
  12435.  
  12436.  CLS    ' Clear screen.
  12437.  
  12438.  
  12439.  
  12440.  
  12441.  
  12442.  ' Use RSET on variable-length string with a value.
  12443.  
  12444.  
  12445.  TmpStr$ = SPACE$(40)
  12446.  
  12447.  
  12448.  PRINT "Here are two strings that have been right and left "
  12449.  
  12450.  
  12451.  PRINT "justified in a 40-character variable-length string."
  12452.  
  12453.  
  12454.  PRINT
  12455.  
  12456.  
  12457.  
  12458.  
  12459.  
  12460.  RSET TmpStr$ = "Right-|"
  12461.  
  12462.  
  12463.  PRINT TmpStr$
  12464.  
  12465.  
  12466.  LSET TmpStr$ = "|-Left"
  12467.  
  12468.  
  12469.  PRINT TmpStr$
  12470.  
  12471.  
  12472.  PRINT "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
  12473.  
  12474.  
  12475.  PRINT "12345678901234567890123456789012345678901234567890"
  12476.  
  12477.  
  12478.  PRINT "         1         2         3         4         5"
  12479.  
  12480.  
  12481.  
  12482.  
  12483.  
  12484.  ' Use RSET on fixed-length string of length 25.
  12485.  
  12486.  
  12487.  PRINT
  12488.  
  12489.  
  12490.  PRINT
  12491.  
  12492.  
  12493.  PRINT "Here are two strings that have been right and left"
  12494.  
  12495.  
  12496.  PRINT "justified in a 25-character fixed-length string."
  12497.  
  12498.  
  12499.  PRINT
  12500.  
  12501.  
  12502.  RSET TmpStr2 = "Right-|"
  12503.  
  12504.  
  12505.  PRINT TmpStr2
  12506.  
  12507.  
  12508.  LSET TmpStr2$ = "|-Left"
  12509.  
  12510.  
  12511.  PRINT TmpStr2$
  12512.  
  12513.  
  12514.  PRINT "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
  12515.  
  12516.  
  12517.  PRINT "12345678901234567890123456789012345678901234567890"
  12518.  
  12519.  
  12520.  PRINT "         1         2         3         4         5"
  12521.  
  12522.  
  12523.  
  12524.  
  12525.  Output
  12526.  
  12527.  
  12528.  
  12529.  Here are two strings that have been right and left
  12530.  
  12531.  justified in a 40-character variable-length string.
  12532.  
  12533.  
  12534.                                   Right-|
  12535.  
  12536.  
  12537.  |-Left
  12538.  
  12539.  
  12540.  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12541.  
  12542.  
  12543.  12345678901234567890123456789012345678901234567890
  12544.  
  12545.  
  12546.           1         2         3         4         5
  12547.  
  12548.  
  12549.  
  12550.  
  12551.  
  12552.  
  12553.  
  12554.  
  12555.  Here are two strings that have been right and left
  12556.  
  12557.  justified in a 25-character fixed-length string.
  12558.  
  12559.  
  12560.                    Right-|
  12561.  
  12562.  
  12563.  |-Left
  12564.  
  12565.  
  12566.  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12567.  
  12568.  
  12569.  12345678901234567890123456789012345678901234567890
  12570.  
  12571.  
  12572.  1         2         3         4         5
  12573.  
  12574.  
  12575.  LTRIM$ Function
  12576.  ────────────────────────────────────────────────────────────────────────────
  12577.  
  12578.  
  12579.  Action
  12580.  
  12581.  Returns a copy of a string with leading spaces removed.
  12582.  
  12583.  
  12584.  Syntax
  12585.  
  12586.  
  12587.  
  12588.   LTRIM$( stringexpression$)
  12589.  
  12590.  
  12591.  Remarks
  12592.  
  12593.  
  12594.  The  stringexpression$ can be any string expression. The  LTRIM$ function
  12595.  works with both fixed- and variable-length string variables.
  12596.  
  12597.  
  12598.  See Also
  12599.  
  12600.   RTRIM$
  12601.  
  12602.  
  12603.  Example
  12604.  
  12605.  The following example copies a file to a new file, removing all leading and
  12606.  trailing spaces:
  12607.  
  12608.  ' Get the filenames.
  12609.  
  12610.  
  12611.  INPUT "Enter input filename:", InFile$
  12612.  
  12613.  
  12614.  INPUT "Enter output filename:", OutFile$
  12615.  
  12616.  
  12617.  
  12618.  
  12619.  
  12620.  OPEN InFile$ FOR INPUT AS #1
  12621.  
  12622.  
  12623.  OPEN OutFile$ FOR OUTPUT AS #2
  12624.  
  12625.  
  12626.  
  12627.  
  12628.  
  12629.  ' Read, trim, and write each line.
  12630.  
  12631.  
  12632.  DO WHILE NOT EOF(1)
  12633.  
  12634.  
  12635.     LINE INPUT #1, LineIn$
  12636.  
  12637.  
  12638.     ' Remove leading and trailing blanks.
  12639.  
  12640.  
  12641.     LineIn$ = LTRIM$(RTRIM$(LineIn$))
  12642.  
  12643.  
  12644.     PRINT #2, LineIn$
  12645.  
  12646.  
  12647.  LOOP
  12648.  
  12649.  
  12650.  
  12651.  
  12652.  
  12653.  CLOSE #1, #2
  12654.  
  12655.  
  12656.  END
  12657.  
  12658.  
  12659.  MID$ Function
  12660.  ────────────────────────────────────────────────────────────────────────────
  12661.  
  12662.  
  12663.  Action
  12664.  
  12665.  Returns a substring of a string.
  12666.  
  12667.  
  12668.  Syntax
  12669.  
  12670.   MID$( stringexpression$,  start%,  length%)
  12671.  
  12672.  Remarks
  12673.  
  12674.  
  12675.  The  MID$ function uses the following arguments:
  12676.  
  12677. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  12678.  Argument                                Description
  12679.  ────────────────────────────────────────────────────────────────────────────
  12680.   stringexpression$                      The string expression from which
  12681.                                          the substring is extracted. This
  12682.                                          can be any string expression.
  12683.  
  12684.   start%                                 The character position in
  12685.                                          stringexpression$ where the
  12686.  Argument                                Description
  12687.  ────────────────────────────────────────────────────────────────────────────
  12688.                                         stringexpression$ where the
  12689.                                          substring starts.
  12690.  
  12691.   length%                                The number of characters to
  12692.                                          extract.
  12693.  
  12694.  
  12695.  
  12696.  
  12697.  
  12698.  The arguments  start% and  length% must be between 1 and 32,767, inclusive.
  12699.  If  length% is omitted or if there are fewer than  length% characters in the
  12700.  string (including the  start% character), the  MID$ function returns all
  12701.  characters from the position  start% to the end of the string.
  12702.  
  12703.  If  start% is greater than the number of characters in  stringexpression$,
  12704.  MID$ returns a null string.
  12705.  
  12706.  Use the  LEN function to find the number of characters in
  12707.  stringexpression$.
  12708.  
  12709.  
  12710.  See Also
  12711.  
  12712.   LEFT$,  LEN,  MID$ Statement,  RIGHT$
  12713.  
  12714.  
  12715.  Example
  12716.  
  12717.  The following example converts a binary number to a decimal number. The
  12718.  program uses the  MID$ function to extract digits from the binary number
  12719.  (input as a string).
  12720.  
  12721.  INPUT "Binary number = ", Binary$' Input binary number as string.
  12722.  
  12723.  Length = LEN(Binary$)' Get length of string.
  12724.  
  12725.  Decimal = 0
  12726.  
  12727.  FOR K = 1 TO Length
  12728.  
  12729.     Digit$ = MID$(Binary$, K, 1) ' Get digit from string.
  12730.  
  12731.     IF Digit$ = "0" OR Digit$ = "1" THEN' Test for binary digit.
  12732.  
  12733.        Decimal = 2 * Decimal + VAL(Digit$)' Convert digits to numbers.
  12734.  
  12735.     ELSE
  12736.  
  12737.        PRINT "Error--invalid binary digit: "; Digit$
  12738.  
  12739.        EXIT FOR
  12740.  
  12741.     END IF
  12742.  
  12743.  NEXT
  12744.  
  12745.  PRINT "Decimal number =" Decimal
  12746.  
  12747.  
  12748.  MID$ Statement
  12749.  ────────────────────────────────────────────────────────────────────────────
  12750.  
  12751.  
  12752.  Action
  12753.  
  12754.  Replaces a portion of a string variable with another string.
  12755.  
  12756.  
  12757.  Syntax
  12758.  
  12759.  
  12760.  
  12761.   MID$( stringvariable$,  start% ,  length%) =  stringexpression$
  12762.  
  12763.  Remarks
  12764.  
  12765.  
  12766.  The  MID$ statement uses the following arguments:
  12767.  
  12768. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  12769.  Argument                                Description
  12770.  Argument                                Description
  12771.  ────────────────────────────────────────────────────────────────────────────
  12772.   stringvariable$                        The string variable being modified.
  12773.  
  12774.   start%                                 A numeric expression giving the
  12775.                                          position in  stringvariable$ where
  12776.                                          the replacement starts.
  12777.  
  12778.   length%                                A numeric expression that gives
  12779.                                          the length of the string being
  12780.                                          replaced.
  12781.  
  12782.   stringexpression$                      The string expression that
  12783.                                          replaces part of  stringvariable$.
  12784.  
  12785.  
  12786.  
  12787.  
  12788.  
  12789.  The arguments  start% and  length% are integer expressions. The argument
  12790.  stringvariable$ is a string variable, but  stringexpression$ can be a string
  12791.  variable, a string constant, or a string expression.
  12792.  
  12793.  The optional  length% refers to the number of characters from the argument
  12794.  stringexpression$ that are used in the replacement. If  length% is omitted,
  12795.  all of  stringexpression$ is used. However, regardless of whether  length%
  12796.  is omitted or included, the replacement of characters never goes beyond the
  12797.  original length of  stringvariable$.
  12798.  
  12799.  
  12800.  See Also
  12801.  
  12802.   MID$ Function
  12803.  
  12804.  
  12805.  Example
  12806.  
  12807.  This example uses the  MID$ statement to replace string characters:
  12808.  
  12809.  CLS' Clear screen.
  12810.  
  12811.  Test$ = "Paris, France"
  12812.  
  12813.  PRINT Test$
  12814.  
  12815.  MID$(Test$, 8)="Texas "' Starting at position 8, replace
  12816.  
  12817.  ' characters in Test$ with Texas.
  12818.  
  12819.  PRINT Test$
  12820.  
  12821.  
  12822.  
  12823.  Output
  12824.  
  12825.  Paris, France
  12826.  
  12827.  
  12828.  Paris, Texas
  12829.  
  12830.  
  12831.  MKDIR Statement
  12832.  ────────────────────────────────────────────────────────────────────────────
  12833.  
  12834.  
  12835.  Action
  12836.  
  12837.  Creates a new directory.
  12838.  
  12839.  
  12840.  Syntax
  12841.  
  12842.  
  12843.  
  12844.   MKDIR  pathname$
  12845.  
  12846.  Remarks
  12847.  
  12848.  
  12849.  The  pathname$ is a string expression that specifies the name of the
  12850.  directory to be created in DOS. The  pathname$ must be a string of fewer
  12851.  than 64 characters.
  12852.  
  12853.  The  MKDIR statement works like the DOS command MKDIR. However, the syntax
  12854.  in BASIC cannot be shortened to MD, as it can in DOS.
  12855.  
  12856.  You can use  MKDIR to create a DOS directory with a name that contains an
  12857.  embedded space. However, although you can access that directory through DOS,
  12858.  you can remove it only with the BASIC  RMDIR statement.
  12859.  
  12860.  
  12861.  See Also
  12862.  
  12863.   CHDIR,  RMDIR
  12864.  
  12865.  
  12866.  Example
  12867.  
  12868.  See the  CHDIR statement programming example, which uses the  MKDIR
  12869.  statement.
  12870.  
  12871.  
  12872.  MKI$, MKL$, MKS$, MKD$, and MKC$ Functions
  12873.  ────────────────────────────────────────────────────────────────────────────
  12874.  
  12875.  
  12876.  Action
  12877.  
  12878.  Convert numeric values to string values.
  12879.  
  12880.  
  12881.  Syntax
  12882.  
  12883.  
  12884.  
  12885.   MKI$( integer-expression%)
  12886.  
  12887.  
  12888.   MKL$( long-integer-expression&)
  12889.  
  12890.  
  12891.   MKS$( single-precision-expression!)
  12892.  
  12893.  
  12894.   MKD$( double-precision-expression#)
  12895.  
  12896.  
  12897.   MKC$( currency-expression@)
  12898.  
  12899.  Remarks
  12900.  
  12901.  
  12902.   MKI$,  MKL$,  MKS$,  MKD$ and  MKC$ are used with  FIELD and  PUT
  12903.  statements to write numbers to a random-access file. The functions convert
  12904.  numeric expressions to strings that can be stored in the strings defined in
  12905.  the  FIELD statement. These functions are the inverse of  CVI,  CVL,  CVS,
  12906.  CVD, and  CVC.
  12907.  
  12908.  The following table describes these numeric-conversion functions:
  12909.  
  12910. ╓┌───────────┌───────────────────────────────────────────────────────────────╖
  12911.  Function    Description
  12912.  ────────────────────────────────────────────────────────────────────────────
  12913.   MKI$       Converts an integer to a 2-byte string.
  12914.   MKL$       Converts a long-integer value to a 4-byte string.
  12915.   MKS$       Converts a single-precision value to a 4-byte string.
  12916.   MKD$       Converts a double-precision value to an 8-byte string.
  12917.  Function    Description
  12918.  ────────────────────────────────────────────────────────────────────────────
  12919.  MKD$       Converts a double-precision value to an 8-byte string.
  12920.   MKC$       Converts a currency value to an 8-byte string.
  12921.  
  12922.  
  12923.  
  12924.  
  12925.  
  12926.  Note
  12927.  
  12928.  These BASIC record variables provide a more efficient and convenient way of
  12929.  reading and writing random-access files than some older versions of BASIC.
  12930.  
  12931.  
  12932.  See Also
  12933.  
  12934.   CVI,  CVL,  CVS,  CVD,  CVC;  GET (File I/O);  FIELD;  PUT (File I/O)
  12935.  
  12936.  
  12937.  Example
  12938.  
  12939.  See the programming example for the  CVI,  CVL,  CVS,  CVD, and  CVC
  12940.  statements, which uses the  MKS$ function.
  12941.  
  12942.  
  12943.  MKSMBF$, MKDMBF$ Functions
  12944.  ────────────────────────────────────────────────────────────────────────────
  12945.  
  12946.  
  12947.  Action
  12948.  
  12949.  Convert an IEEE-format number to a string containing a
  12950.  Microsoft-Binary-format number.
  12951.  
  12952.  
  12953.  Syntax
  12954.  
  12955.  
  12956.  
  12957.   MKSMBF$( single-precision-expression!)
  12958.  
  12959.  
  12960.   MKDMBF$( double-precision-expression#)
  12961.  
  12962.  Remarks
  12963.  
  12964.  
  12965.  These functions are used to write real numbers to random-access files using
  12966.  Microsoft Binary format. They are particularly useful for maintaining data
  12967.  files created with older versions of BASIC.
  12968.  
  12969.  The  MKSMBF$ and  MKDMBF$ functions convert real numbers in IEEE format to
  12970.  strings so they can be written to the random-access file.
  12971.  
  12972.  To write a real number to a random-access file in Microsoft Binary format,
  12973.  convert the number to a string using  MKSMBF$ (for a single-precision
  12974.  number) or  MKDMBF$ (for a double-precision number). Then store the result
  12975.  in the corresponding field (defined in the  FIELD statement) and write the
  12976.  record to the file using the  PUT statement.
  12977.  
  12978.  Currency numbers are not real numbers, so they cannot be converted to
  12979.  strings that contain Microsoft-Binary-format numbers.
  12980.  
  12981.  
  12982.  See Also
  12983.  
  12984.   CVSMBF,  CVDMBF;  CVI,  CVL,  CVS,  CVD,  CVC;  MKI$,  MKL$,  MKS$,  MKD$,
  12985.  MKC$
  12986.  
  12987.  
  12988.  Example
  12989.  
  12990.  The following example stores real values in a file as
  12991.  Microsoft-Binary-Format numbers:
  12992.  
  12993.  TYPE Buffer
  12994.  
  12995.     NameField AS STRING * 20
  12996.  
  12997.     ScoreField AS STRING * 4
  12998.  
  12999.  END TYPE
  13000.  
  13001.  DIM RecBuffer AS Buffer
  13002.  
  13003.  OPEN "TESTDAT.DAT" FOR RANDOM AS #1 LEN=LEN(RecBuffer)
  13004.  
  13005.  PRINT "Enter a name and a score, separated by a comma."
  13006.  
  13007.  PRINT "Enter 'END, 0' to end input."
  13008.  
  13009.  INPUT NameIn$, Score
  13010.  
  13011.  I=0' Read names and scores from the console until the name is END.
  13012.  
  13013.  DO WHILE UCASE$(NameIn$) <> "END"
  13014.  
  13015.     I=I+1
  13016.  
  13017.     RecBuffer.NameField=NameIn$
  13018.  
  13019.     RecBuffer.ScoreField=MKSMBF$(Score)   ' Convert to a string.
  13020.  
  13021.     PUT #1,I,RecBuffer
  13022.  
  13023.     INPUT NameIn$, Score
  13024.  
  13025.  LOOP
  13026.  
  13027.  PRINT I;" records written."
  13028.  
  13029.  CLOSE #1
  13030.  
  13031.  
  13032.  MOVEFIRST, MOVELAST, MOVENEXT, MOVEPREVIOUS Statements
  13033.  ────────────────────────────────────────────────────────────────────────────
  13034.  
  13035.  
  13036.  Action
  13037.  
  13038.  Make records current according to their relative position in an ISAM table.
  13039.  
  13040.  
  13041.  Syntax
  13042.  
  13043.  
  13044.  
  13045.   MOVEFIRST #  filenumber%
  13046.  
  13047.  
  13048.   MOVELAST #  filenumber%
  13049.  
  13050.  
  13051.   MOVENEXT #  filenumber%
  13052.  
  13053.  
  13054.   MOVEPREVIOUS #  filenumber%
  13055.  
  13056.  Remarks
  13057.  
  13058.  
  13059.  The  filenumber% is the number used in the  OPEN statement to open the
  13060.  table. The  MOVEFIRST,  MOVELAST,  MOVENEXT, and  MOVEPREVIOUS statements
  13061.  allow you to make records current according to their relative position on
  13062.  the current index in an ISAM table:
  13063.  
  13064. ╓┌──────────────────────┌────────────────────────────────────────────────────╖
  13065.  Statement              Effect
  13066.  ────────────────────────────────────────────────────────────────────────────
  13067.   MOVEFIRST             First record becomes current.
  13068.   MOVELAST              Last record becomes current.
  13069.   MOVENEXT              Next record becomes current.
  13070.   MOVEPREVIOUS          Previous record becomes current.
  13071.  
  13072.  
  13073.  The action of these statements is made relative to the record that is
  13074.  current according to the current index.
  13075.  
  13076.  Using  MOVEPREVIOUS when the first indexed record is current moves the
  13077.  current position to the beginning of the table. The beginning of an ISAM
  13078.  table is the position before the first record according to the current
  13079.  index.
  13080.  
  13081.  Using  MOVENEXT when the last indexed record is current moves the current
  13082.  position to the end of the table. The end of an ISAM table is the position
  13083.  following the last record according to the current index.
  13084.  
  13085.  
  13086.  See Also
  13087.  
  13088.   BOF;  EOF;  SEEKGT,  SEEKGE,  SEEKEQ
  13089.  
  13090.  
  13091.  Example
  13092.  
  13093.  See the  CREATEINDEX statement programming example, which uses the
  13094.  MOVEFIRST,  MOVELAST,  MOVENEXT, and  MOVEPREVIOUS statements.
  13095.  
  13096.  
  13097.  NAME Statement
  13098.  ────────────────────────────────────────────────────────────────────────────
  13099.  
  13100.  
  13101.  Action
  13102.  
  13103.  Changes the name of a disk file or directory.
  13104.  
  13105.  
  13106.  Syntax
  13107.  
  13108.  
  13109.  
  13110.   NAME  oldfilespec$  AS  newfilespec$
  13111.  
  13112.  Remarks
  13113.  
  13114.  
  13115.  The  NAME statement is similar to the DOS RENAME command.  NAME can move a
  13116.  file from one directory to another but cannot move a directory.
  13117.  
  13118.  The arguments  oldfilespec$ and  newfilespec$ are string expressions, each
  13119.  of which contains a filename and an optional path. If the path in
  13120.  newfilespec$ is different from the path in  oldfilespec$, the  NAME
  13121.  statement renames the file as indicated.
  13122.  
  13123.  The file  oldfilespec$ must exist and  newfilespec$ must not be in use. Both
  13124.  files must be on the same drive. If you use  NAME with different drive
  13125.  designations in the old and new filenames, BASIC generates the error message
  13126.  Rename across disks.
  13127.  
  13128.  Using  NAME on an open file causes BASIC to generate the run-time error
  13129.  message File already open. You must close an open file before renaming it.
  13130.  
  13131.  
  13132.  Example
  13133.  
  13134.  The following example shows how to use  NAME to rename a README.DOC file:
  13135.  
  13136.  CLS    ' Clear screen.
  13137.  
  13138.  
  13139.  'Change README.DOC to READMINE.DOC
  13140.  
  13141.  
  13142.  NAME "README.DOC" AS "READMINE.DOC"
  13143.  
  13144.  
  13145.  FILES  ' Display the files in your directory to confirm name change.
  13146.  
  13147.  
  13148.  PRINT
  13149.  
  13150.  
  13151.  PRINT "README.DOC is now called READMINE.DOC"
  13152.  
  13153.  
  13154.  PRINT "Press any key to continue"
  13155.  
  13156.  
  13157.  DO
  13158.  
  13159.  
  13160.  LOOP WHILE INKEY$ = ""
  13161.  
  13162.  
  13163.  ' Change name back to README.DOC and confirm by displaying files.
  13164.  
  13165.  
  13166.  NAME "READMINE.DOC" AS "README.DOC"
  13167.  
  13168.  
  13169.  FILES
  13170.  
  13171.  
  13172.  PRINT
  13173.  
  13174.  
  13175.  PRINT "README.DOC is back to its original name"
  13176.  
  13177.  
  13178.  
  13179.  
  13180.  You also can use  NAME to move a file from one directory to another. You can
  13181.  move README.DOC to the directory \MYDIR with the following statement:
  13182.  
  13183.  
  13184.  NAME "README.DOC" AS "\MYDIR\README.DOC"
  13185.  
  13186.  
  13187.  OCT$ Function
  13188.  ────────────────────────────────────────────────────────────────────────────
  13189.  
  13190.  
  13191.  Action
  13192.  
  13193.  Returns a string representing the octal value of the numeric argument.
  13194.  
  13195.  
  13196.  Syntax
  13197.  
  13198.  
  13199.  
  13200.   OCT$( numeric-expression)
  13201.  
  13202.  Remarks
  13203.  
  13204.  
  13205.  The argument  numeric-expression can be of any type. It is rounded to an
  13206.  integer or long integer before the  OCT$ function evaluates it.
  13207.  
  13208.  
  13209.  See Also
  13210.  
  13211.   HEX$
  13212.  
  13213.  
  13214.  Example
  13215.  
  13216.  The following example displays the octal version of several decimal numbers:
  13217.  
  13218.  PRINT "The octal representation of decimal 24 is " OCT$(24)
  13219.  
  13220.  
  13221.  PRINT "The octal representation of decimal 55 is " OCT$(55)
  13222.  
  13223.  
  13224.  PRINT "The octal representation of decimal 101 is " OCT$(101)
  13225.  
  13226.  
  13227.  
  13228.  
  13229.  Output
  13230.  
  13231.  
  13232.  
  13233.  The octal representation of decimal 24 is 30
  13234.  
  13235.  
  13236.  The octal representation of decimal 55 is 67
  13237.  
  13238.  
  13239.  The octal representation of decimal 101 is 145
  13240.  
  13241.  
  13242.  ON ERROR Statement
  13243.  ────────────────────────────────────────────────────────────────────────────
  13244.  
  13245.  
  13246.  Action
  13247.  
  13248.  Enables an error-handling routine and specifies the location of that routine
  13249.  in the program. The  ON  ERROR statement also can be used to disable an
  13250.  error-handling routine.
  13251.  
  13252.  
  13253.  Syntax
  13254.  
  13255.  
  13256.  
  13257.   ON  LOCAL  ERROR { GOTO  line |  RESUME  NEXT |  GOTO  0}
  13258.  
  13259.  Remarks
  13260.  
  13261.  
  13262.  If no  ON  ERROR statement is used in a program, any run-time error will be
  13263.  fatal (BASIC generates an error message and program execution stops).
  13264.  
  13265.  The following list describes the parts of the  ON ERROR statement:
  13266.  
  13267. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  13268.  Part                                    Description
  13269.  ────────────────────────────────────────────────────────────────────────────
  13270.   LOCAL                                  Used to indicate an error-handling
  13271.                                          routine in the same procedure. If
  13272.                                          not used, module-level error
  13273.                                          handlers are indicated.
  13274.  Part                                    Description
  13275.  ────────────────────────────────────────────────────────────────────────────
  13276.                                         handlers are indicated.
  13277.  
  13278.   GOTO  line                             Enables the error-handling routine
  13279.                                          that starts at  line. Thereafter,
  13280.                                          if a run-time error occurs,
  13281.                                          program control branches to  line
  13282.                                          (a label or a line number). The
  13283.                                          specified line is either in the
  13284.                                          module-level code or in the same
  13285.                                          procedure (if the  LOCAL keyword
  13286.                                          is used). If not found in either
  13287.                                          place, BASIC generates a Label not
  13288.                                          defined compile-time error.
  13289.  
  13290.   RESUME NEXT                            Specifies that, when a run-time
  13291.                                          error occurs, control goes to the
  13292.                                          statement after the statement
  13293.                                          where the error occurred; the  ERR
  13294.                                          function then can be used to
  13295.  Part                                    Description
  13296.  ────────────────────────────────────────────────────────────────────────────
  13297.                                         function then can be used to
  13298.                                          obtain the run-time error code.
  13299.  
  13300.   GOTO 0                                 Disables any enabled module-level
  13301.                                          error-handling routine within the
  13302.                                          current module, or disables any
  13303.                                          enabled error handler within the
  13304.                                          current procedure (if used
  13305.                                          together with the  LOCAL keyword).
  13306.  
  13307.  
  13308.  
  13309.  
  13310.  
  13311.  
  13312.  The  LOCAL keyword indicates an error-handling routine that is "local" to
  13313.  the procedure within which the error-handling routine is located. A local
  13314.  error-handling routine:
  13315.  
  13316.    ■   Overrides any enabled module-level error-handling routines.
  13317.  
  13318.    ■   Is enabled only while the procedure within which it is located is
  13319.        executing.
  13320.  
  13321.  Notice that the local error handler remains enabled while any procedures
  13322.  execute that are directly or indirectly called by the procedure within which
  13323.  the error handler is located. One of those procedures may supersede the
  13324.  local error handler.
  13325.  
  13326.  
  13327.  Note
  13328.  
  13329.  The module-level error-handling routines provided by previous versions of
  13330.  BASIC may be all you need; you may never need to use the  LOCAL keyword.
  13331.  
  13332.  Use of the  RESUME  NEXT option causes program execution to resume with the
  13333.  statement immediately following the statement that caused the run-time
  13334.  error. This enables your program to continue execution of a block of program
  13335.  code, despite a run-time error, then check for the cause of the error. This
  13336.  also enables you to build the error-handling code in line with the main
  13337.  module code or procedure, rather than at a remote location in the program.
  13338.  
  13339.  
  13340.  The statement form  ON  ERROR  GOTO  0 disables error handling. It does not
  13341.  specify line 0 as the start of the error-handling code, even if the program
  13342.  or procedure contains a line num-bered 0.
  13343.  
  13344.  
  13345.  Notice that an error-handling routine is not a  SUB or  FUNCTION procedure
  13346.  or a  DEF  FN function. An error-handling routine is a block of code marked
  13347.  by a line label or line number.
  13348.  
  13349.  An error handler is enabled when it is referred to by an  ON  ERROR  GOTO
  13350.  line statement. Once an error handler is enabled, a run-time error causes
  13351.  program control to jump to the enabled error-handling routine and makes the
  13352.  error handler "active." An error handler is active from the time a run-time
  13353.  error has been trapped until a  RESUME statement is executed in the handler.
  13354.  
  13355.  Error-handling routines must rely on the value in  ERR to determine the
  13356.  cause of the error. The error-handling routine should test or save this
  13357.  value before any other error can occur or before calling a procedure that
  13358.  could cause an error. The value in  ERR reflects only the last error to
  13359.  occur.
  13360.  
  13361.  If you use the BASIC command line to compile a program that has been
  13362.  developed in the QBX environment and has error-handling routines, compile
  13363.  with the /E or /X option. The Make EXE File command in the QBX environment
  13364.  uses these options.
  13365.  
  13366.  If an error occurs in a procedure or module that does not have an enabled
  13367.  error-handling routine, BASIC searches for an enabled, inactive error
  13368.  handler to trap the error. BASIC searches back through all the procedures
  13369.  and modules that have called the procedure where the error occurred.
  13370.  
  13371.  Using Module-Level Error Handlers
  13372.  Once enabled by execution of an  ON  ERROR  GOTO  line statement, a
  13373.  module-level error handler stays enabled unless explicitly disabled by
  13374.  execution of an  ON  ERROR  GOTO  0 statement somewhere in the module.
  13375.  
  13376.  
  13377.  In the following cases, BASIC searches back through the module-level code of
  13378.  the calling modules, looking for an enabled, inactive error handler:
  13379.  
  13380.    ■         In a multiple-module program that contains only module-level
  13381.              error handlers, if an enabled and inactive error handler cannot
  13382.              be found in the module where the error occurred.
  13383.  
  13384.    ■         If an error occurs in a module-level error handler itself (BASIC
  13385.              does not automatically treat this as a fatal error).
  13386.  
  13387.    ■         If an  ON ERROR GOTO 0 statement is encountered while the
  13388.              current module's module-level error handler is active.
  13389.  
  13390.  
  13391.  
  13392.  
  13393.  
  13394.  Procedure-Level Error Handlers
  13395.   SUB and  FUNCTION procedures and  DEF  FN functions can contain their own
  13396.  error-handling routines.
  13397.  
  13398.  
  13399.  To enable a local error handler, use the statement  ON LOCAL ERROR GOTO
  13400.  line. The argument  line must be a label or line number in the same
  13401.  procedure as the  ON LOCAL ERROR GOTO statement.
  13402.  
  13403.  The local error handler is automatically disabled when the procedure
  13404.  returns, or by execution of the statement  ON LOCAL ERROR GOTO 0.
  13405.  
  13406.  You will want program flow to avoid the statements that make up the
  13407.  error-handling routine. One way to keep the error-handling code from
  13408.  executing when there is no error is to place an  EXIT  SUB,  EXIT  FUNCTION,
  13409.  or  EXIT  DEF statement immediately ahead of the error-handling routine, as
  13410.  in the following example:
  13411.  
  13412.  SUB InitializeMatrix (var1, var2, var3, var4)
  13413.  
  13414.  
  13415.  .
  13416.  
  13417.  
  13418.  .
  13419.  
  13420.  
  13421.  .
  13422.  
  13423.  
  13424.  ON LOCAL ERROR GOTO ErrorHandler
  13425.  
  13426.  
  13427.  .
  13428.  
  13429.  
  13430.  .
  13431.  
  13432.  
  13433.  .
  13434.  
  13435.  
  13436.  EXIT SUB
  13437.  
  13438.  
  13439.  ErrorHandler:
  13440.  
  13441.  
  13442.  .
  13443.  
  13444.  
  13445.  .
  13446.  
  13447.  
  13448.  .
  13449.  
  13450.  
  13451.  RESUME NEXT
  13452.  
  13453.  
  13454.  END SUB
  13455.  
  13456.  The example shows the error-handling code located after the  EXIT  SUB
  13457.  statement and before the  END  SUB statement. This partitions the
  13458.  error-handling code from the normal execution flow of the procedure.
  13459.  However, error-handling code can be placed anywhere in a procedure.
  13460.  
  13461.  
  13462.  In the QBX environment, or if the command-line compiler is used with the /O
  13463.  option:
  13464.  
  13465.    ■         If a local error handler is active and an  END  SUB,  END
  13466.              FUNCTION, or  END  DEF statement is encountered, BASIC generates
  13467.              the run-time error message  No RESUME.
  13468.  
  13469.    ■         If an  EXIT  SUB,  EXIT  FUNCTION, or  EXIT  DEF statement is
  13470.              encountered, BASIC does not generate a run-time error; in other
  13471.              words, it is assumed that this does not represent a logic error
  13472.              in the program.
  13473.  
  13474.  In a multiple-module program that contains only procedure-level (local)
  13475.  error handlers, if an enabled and inactive error handler cannot be found in
  13476.  the procedure where the error occurred, BASIC searches back through all the
  13477.  calling procedures as well as the module-level code of all the calling
  13478.  modules, looking for an enabled, inactive error handler.
  13479.  
  13480.  Using Both Module-Level and Procedure-Level Error Handlers
  13481.  For simplicity and clarity, avoid using both local- and module-level error
  13482.  handlers in the same program, except for using an error handler in the main
  13483.  module module-level code as the last line of defense against a fatal error.
  13484.  If you need to, however, you can have both a module-level error handler and
  13485.  a local error handler enabled at the same time. (In fact, you can enable
  13486.  both local- and module-level error handling from within a procedure.)
  13487.  
  13488.  
  13489.  While searching for an enabled, inactive error handler, BASIC may encounter
  13490.  an active event handler. Unless an enabled error-handling routine is
  13491.  provided in the same module-level code as the event handler, BASIC generates
  13492.  a fatal error. Therefore, to produce completely bullet-proof BASIC code in
  13493.  programs that trap events, make sure an error handler in the same
  13494.  module-level code as the event handler is enabled at the time the event
  13495.  occurs. Because event handlers can be located only at the module level, this
  13496.  is another special case where you might mix module-level and procedure-level
  13497.  error handlers.
  13498.  
  13499.  Notice that when an error-handling routine is finished and program execution
  13500.  resumes through execution of a  RESUME 0 or  RESUME  NEXT statement, the
  13501.  resume location is based on the location of the error-handling routine, and
  13502.  not necessarily on the location where the error occurred. For more
  13503.  information, see the entry for  RESUME.
  13504.  
  13505.  
  13506.  See Also
  13507.  
  13508.   ERL,  ERR;  ERROR;  RESUME
  13509.  
  13510.  
  13511.  Example
  13512.  
  13513.  The following program prompts the user for a disk drive designation. Once
  13514.  the user has input the drive designation, the program attempts to write a
  13515.  large file to the disk. A number of errors can occur.
  13516.  
  13517.  DECLARE SUB ErrorMessage (Message$)
  13518.  
  13519.  DECLARE SUB WriteBigFile (Filenum%)
  13520.  
  13521.  
  13522.  
  13523.  ON ERROR GOTO ErrHandler
  13524.  
  13525.  CLS
  13526.  
  13527.  PRINT "This program will attempt to write a large file to a disk drive that"
  13528.  
  13529.  PRINT "you have selected. The file will be erased when the program ends."
  13530.  
  13531.  PRINT
  13532.  
  13533.  DO
  13534.  
  13535.  INPUT "Enter the letter of the drive where you want this file written"; DR$
  13536.  
  13537.  DR$ = UCASE$(DR$)
  13538.  
  13539.  LOOP UNTIL LEN(DR$) >= 1 AND LEN(DR$) <= 2 AND DR$ >= "A" AND DR$ <= "Z"
  13540.  
  13541.  IF LEN(DR$) > 1 THEN
  13542.  
  13543.  IF RIGHT$(DR$, 1) <> ":" THEN
  13544.  
  13545.  DR$ = LEFT$(DR$, 1) + ":"
  13546.  
  13547.  END IF
  13548.  
  13549.  ELSE
  13550.  
  13551.  DR$ = DR$ + ":"
  13552.  
  13553.  END IF
  13554.  
  13555.  
  13556.  
  13557.  ' Put together a complete file specification.
  13558.  
  13559.  
  13560.  FileSpec$ = DR$ + "BIGFILE.XXX"
  13561.  
  13562.  ' Get the next available file number.
  13563.  
  13564.  Filenum% = FREEFILE
  13565.  
  13566.  ' Try an open the file
  13567.  
  13568.  OPEN FileSpec$ FOR OUTPUT AS Filenum%
  13569.  
  13570.  WriteBigFile Filenum%
  13571.  
  13572.  CLOSE Filenum%
  13573.  
  13574.  CLS
  13575.  
  13576.  PRINT "Everything was OK. No errors occurred."
  13577.  
  13578.  PRINT "Deleting the file that was created."
  13579.  
  13580.  KILL FileSpec$
  13581.  
  13582.  ' Same as END, returns to operating system.
  13583.  
  13584.  SYSTEM
  13585.  
  13586.  
  13587.  
  13588.  ErrHandler:
  13589.  
  13590.  SELECT CASE ERR
  13591.  
  13592.  CASE 52'Bad file name or number.
  13593.  
  13594.  END
  13595.  
  13596.  CASE 53' File not found.
  13597.  
  13598.  RESUME NEXT
  13599.  
  13600.  CASE 57' Device I/O error.
  13601.  
  13602.  ErrorMessage "You should probably format the disk."
  13603.  
  13604.  END
  13605.  
  13606.  CASE 64' Bad file name.
  13607.  
  13608.  ErrorMessage "The drive name you specified was not correct."
  13609.  
  13610.  END
  13611.  
  13612.  CASE 68' Device unavailable
  13613.  
  13614.  ErrorMessage "The drive you named is unavailable."
  13615.  
  13616.  END
  13617.  
  13618.  CASE 71' Drive not ready
  13619.  
  13620.  ErrorMessage "The drive was not ready. Check the drive!"
  13621.  
  13622.  END
  13623.  
  13624.  CASE ELSE
  13625.  
  13626.  ErrorMessage "An unexpected FATAL error has occurred."
  13627.  
  13628.  STOP
  13629.  
  13630.  END SELECT
  13631.  
  13632.  
  13633.  
  13634.  SUB ErrorMessage (Message$)
  13635.  
  13636.  
  13637.  ON LOCAL ERROR GOTO MessageError
  13638.  
  13639.  CLS
  13640.  
  13641.  PRINT Message$
  13642.  
  13643.  PRINT "Cannot continue."
  13644.  
  13645.  PRINT
  13646.  
  13647.  PRINT "Press any key to exit."
  13648.  
  13649.  DO
  13650.  
  13651.  LOOP WHILE INKEY$ = ""
  13652.  
  13653.  EXIT SUB
  13654.  
  13655.  MessageError:
  13656.  
  13657.  RESUME NEXT
  13658.  
  13659.  END SUB
  13660.  
  13661.  
  13662.  
  13663.  SUB WriteBigFile (Filenum%)
  13664.  
  13665.  ON LOCAL ERROR GOTO LocalHandler
  13666.  
  13667.  TEXT$ = STRING$(1024, "A")
  13668.  
  13669.  FOR I% = 1 TO 400
  13670.  
  13671.  PRINT #Filenum%, TEXT$
  13672.  
  13673.  NEXT I%
  13674.  
  13675.  EXIT SUB
  13676.  
  13677.  LocalHandler:
  13678.  
  13679.  SELECT CASE ERR
  13680.  
  13681.  CASE 61 ' Disk full
  13682.  
  13683.  ErrorMessage ("There is no room remaining on the disk.")
  13684.  
  13685.  KILL "BIGFILE.XXX"
  13686.  
  13687.  END
  13688.  
  13689.  CASE ELSE
  13690.  
  13691.  ERROR ERR
  13692.  
  13693.  END SELECT
  13694.  
  13695.  END SUB
  13696.  
  13697.  
  13698.  ON event Statements
  13699.  ────────────────────────────────────────────────────────────────────────────
  13700.  
  13701.  
  13702.  Action
  13703.  
  13704.  Indicate the first line of an event-trapping routine.
  13705.  
  13706.  
  13707.  Syntax
  13708.  
  13709.  
  13710.  
  13711.   ON  event  GOSUB { linenumber |  linelabel}
  13712.  
  13713.  Remarks
  13714.  
  13715.  
  13716.  The  ON  event statements let you specify a routine that is executed
  13717.  whenever a specified type of event occurs on a specified device. The  ON
  13718.  event statements use the following arguments:
  13719.  
  13720. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  13721.  Argument                                Description
  13722.  ────────────────────────────────────────────────────────────────────────────
  13723.   event                                  Specifies the event that causes a
  13724.                                          branch to the event-trapping
  13725.                                          routine. See below for more
  13726.                                          information about specific types
  13727.                                          of events.
  13728.  
  13729.   linenumber or  linelabel               The number or label of the first
  13730.                                          line in the event-trapping routine.
  13731.                                          This line must be in the
  13732.                                          module-level code.
  13733.  
  13734.                                          A  linenumber value of 0 disables
  13735.                                          event trapping and does not
  13736.  Argument                                Description
  13737.  ────────────────────────────────────────────────────────────────────────────
  13738.                                         event trapping and does not
  13739.                                          specify line 0 as the start of the
  13740.                                          routine.
  13741.  
  13742.  
  13743.  
  13744.  The following list describes the events that can be trapped:
  13745. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  13746.  Event                                   Description
  13747.  ────────────────────────────────────────────────────────────────────────────
  13748.   COM( n%)                               Branches to the routine when
  13749.                                          characters are received at a
  13750.                                          communications port. The integer
  13751.                                          expression  n% indicates one of
  13752.                                          the serial ports, either 1 or 2.
  13753.                                          For more information, see "Using
  13754.                                          ON COM" later in this entry.
  13755.  
  13756.   KEY( n%)                               Branches to the routine when a
  13757.  Event                                   Description
  13758.  ────────────────────────────────────────────────────────────────────────────
  13759.  KEY( n%)                               Branches to the routine when a
  13760.                                          specified key is pressed. The
  13761.                                          integer expression  n% is the
  13762.                                          number of a function key,
  13763.                                          direction key, or user-defined key.
  13764.                                          For more information, see "Using
  13765.                                          ON KEY" later in this entry.
  13766.  
  13767.   PEN                                    Branches to the routine when a
  13768.                                          lightpen is activated. For more
  13769.                                          information, see "Using ON PEN"
  13770.                                          later in this entry.
  13771.  
  13772.   PLAY( queuelimit%)                     Branches when there are fewer than
  13773.                                           queuelimit% notes in the
  13774.                                          background-music queue. A  PLAY
  13775.                                          event-trapping routine can be used
  13776.                                          with a  PLAY statement to play
  13777.                                          music in the background while a
  13778.  Event                                   Description
  13779.  ────────────────────────────────────────────────────────────────────────────
  13780.                                         music in the background while a
  13781.                                          program is running. For more
  13782.                                          information, see "Using ON PLAY"
  13783.                                          later in this entry.
  13784.  
  13785.   SIGNAL( n%)                            Branches to the routine when an
  13786.                                          OS/2 protected-mode signal is
  13787.                                          received. For more information,
  13788.                                          see "Using ON SIGNAL" later in
  13789.                                          this entry.
  13790.  
  13791.   STRIG( n%)                             Branches to the event-trapping
  13792.                                          routine when a joystick trigger is
  13793.                                          pressed. The integer expression
  13794.                                          n% is the joystick trigger number.
  13795.                                          For more information, see "Using
  13796.                                          ON STRIG" later in this entry.
  13797.  
  13798.   TIMER( n&)                             Branches to the routine when  n
  13799.  Event                                   Description
  13800.  ────────────────────────────────────────────────────────────────────────────
  13801.  TIMER( n&)                             Branches to the routine when  n
  13802.                                          seconds have passed. The numeric
  13803.                                          expression  n& is in the range 1
  13804.                                          to 86,400 (1 second to 24 hours).
  13805.  
  13806.   UEVENT                                 Branches to the event-trapping
  13807.                                          routine for a user-defined event.
  13808.                                          This event usually is a hardware
  13809.                                          interrupt (although it can be a
  13810.                                          software interrupt). For more
  13811.                                          information, see "Using ON UEVENT"
  13812.                                          later in this entry.
  13813.  
  13814.  
  13815.  
  13816.  The  ON  event statement specifies only the start of an event-trapping
  13817.  routine. Another set of statements determines whether or not the routine is
  13818.  called. This set of statements turns event trapping on or off and determines
  13819.  how events are handled when trapping is off. The following list describes
  13820.  these statements in a general way. See the entries for particular statements
  13821.  for more specific information.
  13822. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  13823.  Event                                   Description
  13824.  ────────────────────────────────────────────────────────────────────────────
  13825.   event  ON                              Enables event trapping. Event
  13826.                                          trapping occurs only after an
  13827.                                          event  ON statement is executed.
  13828.  
  13829.   event  OFF                             Disables event trapping. No
  13830.                                          trapping takes place until the
  13831.                                          execution of another  event  ON
  13832.                                          statement. Events occurring while
  13833.                                          trapping is off are ignored.
  13834.  
  13835.   event  STOP                            Suspends event trapping so no
  13836.                                          trapping takes place until an
  13837.                                          event  ON statement is executed.
  13838.                                          Events occurring while trapping is
  13839.                                          inhibited are remembered and
  13840.                                          processed when an  event  ON
  13841.  Event                                   Description
  13842.  ────────────────────────────────────────────────────────────────────────────
  13843.                                         processed when an  event  ON
  13844.                                          statement is executed.
  13845.  
  13846.  
  13847.  
  13848.  
  13849.  When an event trap occurs and the routine is called, BASIC performs an
  13850.  automatic  event  STOP that prevents recursive traps. The  RETURN statement
  13851.  from the trapping routine automatically performs an  event  ON statement
  13852.  unless an explicit  event  OFF is performed inside the routine.
  13853.  
  13854.  If your program contains event-handling statements and you are compiling
  13855.  from the BC command line, use the BC /W or /V option. (The /W option checks
  13856.  for events at every label or line number; the /V option checks at every
  13857.  statement.) If you do not use these options and your program contains event
  13858.  traps, BASIC generates the error message ON events without /V or /W on
  13859.  command line.
  13860.  
  13861.  
  13862.  Note
  13863.  
  13864.  Because of the implicit  event  STOP and  event  ON statements, events that
  13865.  occur during execution of the trapping routine are remembered and processed
  13866.  when the routine ends.
  13867.  
  13868.  The  RETURN  linenumber or  RETURN  linelabel forms of  RETURN can be used
  13869.  to return to a specific line from the trapping routine. Use this type of
  13870.  return with care, however, because any  GOSUB,  WHILE, or  FOR statements
  13871.  active at the time of the trap remain active. BASIC may generate error
  13872.  messages such as NEXT without FOR. In addition, if an event occurs in a
  13873.  procedure, a  RETURN  linenumber or  RETURN  linelabel statement cannot get
  13874.  back into the procedure because the line number or label must be in the
  13875.  module-level code.
  13876.  
  13877.  
  13878.  The next sections contain additional information about the  ON COM,  ON KEY,
  13879.   ON PEN,  ON PLAY,  ON SIGNAL,  ON STRIG, and  ON UEVENT statements.
  13880.  
  13881.  
  13882.  Using On Com
  13883.  You can use  ON COM( n%)  to specify a routine to branch to when characters
  13884.  are received at communications port  n%, which can be either 1 or 2.
  13885.  
  13886.  
  13887.  If your program receives data using an asynchronous communications adapter,
  13888.  the BASIC command-line option /C can be used to set the size of the data
  13889.  buffer.
  13890.  
  13891.  For an example of the  ON COM statement, see the  COM statements programming
  13892.  example.
  13893.  
  13894.  Using On Key
  13895.  You can use  ON KEY( n%) to specify a routine to branch to when key  n% is
  13896.  pressed. The argument  n% is the number of a function key, direction key, or
  13897.  user-defined key.
  13898.  
  13899.  
  13900.  Keys are processed in the following order:
  13901.  
  13902.    ■         The line printer's echo-toggle key is processed first. Defining
  13903.              this key as a user-defined key trap does not prevent characters
  13904.              from being echoed to the line printer when pressed.
  13905.  
  13906.    ■         Function keys and the direction keys are examined next. Defining
  13907.              a function key or direction key as a user-defined key trap has
  13908.              no effect because these keys are predefined.
  13909.  
  13910.    ■         Finally, the user-defined keys are examined.
  13911.  
  13912.  The  ON KEY statement can trap any key, including break or system reset.
  13913.  This makes it possible to prevent accidentally breaking out of a program or
  13914.  rebooting the machine.
  13915.  
  13916.  Note
  13917.  
  13918.  After a key is trapped, the information on which key was trapped is no
  13919.  longer available. This means that you cannot subsequently use the  INPUT
  13920.  statement or  INKEY$ function to find out which key caused the trap. Because
  13921.  you do not know which key press caused the trap, you must set up a different
  13922.  event-handling routine for each key you want to trap.
  13923.  
  13924.  For an example of the  ON KEY statement, see the  KEY statements programming
  13925.  example.
  13926.  
  13927.  Using On PEN
  13928.  You can use  ON PEN to specify a routine to branch to when the lightpen is
  13929.  activated.
  13930.  
  13931.  
  13932.   ON PEN is not available for OS/2 protected mode.
  13933.  
  13934.  For an example of the  ON PEN statement, see the  PEN statements programming
  13935.  example.
  13936.  
  13937.  Using On PLAY
  13938.  You can use  ON PLAY( queuelimit%) to specify a routine to branch to when
  13939.  there are fewer than  queuelimit% notes in the background-music queue. The
  13940.  argument  queuelimit% is an integer expression between 1 and 32, inclusive.
  13941.  
  13942.  
  13943.  The following three rules apply to the use of  ON PLAY:
  13944.  
  13945.    ■         A play-event trap occurs only when music is playing in the
  13946.              background. Play-event traps do not occur when music is running
  13947.              in the foreground.
  13948.  
  13949.    ■         A play-event trap does not occur if the background music queue
  13950.              has already gone from having  queuelimit% to  queuelimit%-1
  13951.              notes when a  PLAY ON is executed.
  13952.  
  13953.    ■         If  queuelimit% is a large number, event traps may occur often
  13954.              enough to slow down the program.
  13955.  
  13956.  
  13957.  
  13958.  
  13959.  
  13960.   ON PLAY is not available for OS/2 protected mode.
  13961.  
  13962.  For an example of the  ON PLAY statement, see the  PLAY function programming
  13963.  example.
  13964.  
  13965.  Using On SIGNAL
  13966.  You can use  ON SIGNAL to specify a routine to branch to when an OS/2
  13967.  protected-mode signal is trapped.
  13968.  
  13969.  
  13970.  The following table lists the numbers of the protected-mode signals:
  13971.  
  13972. ╓┌─────────────────────┌─────────────────────────────────────────────────────╖
  13973.  Number                Signal
  13974.  ────────────────────────────────────────────────────────────────────────────
  13975.  1                     Ctrl+C
  13976.  2                     Pipe connection broken
  13977.  3                     Program terminated
  13978.  4                     Ctrl+Break
  13979.  5                     Process flag A
  13980.  6                     Process flag B
  13981.  7                     Process flag C
  13982.  
  13983.  
  13984.  Process flag A, process flag B, and process flag C are used for
  13985.  communicating between processes. Although BASIC has no built-in mechanism
  13986.  for activating a process flag, you can activate the signal handler in a
  13987.  separate process by invoking the OS/2 function DOSFLAGPROCESS.
  13988.  
  13989.  The  ON SIGNAL statement is available only for OS/2 protected mode.
  13990.  
  13991.  For an example of the  ON SIGNAL statement, see the  SIGNAL statements
  13992.  programming example.
  13993.  
  13994.  Using On STRIG
  13995.  You can use  ON STRIG( n%) to specify a routine to branch to when the button
  13996.  on the joystick is pressed. The argument  n% is the trigger number as
  13997.  defined in the following table:
  13998. ╓┌───┌───────┌───────────────────────────────────────────────────────────────╖
  13999.  n%  Button  Joystick
  14000.  ────────────────────────────────────────────────────────────────────────────
  14001.  0   Lower   First
  14002.  2   Lower   Second
  14003.  4   Upper   First
  14004.  6   Upper   Second
  14005.  
  14006.  
  14007.   ON STRIG is not available for OS/2 protected mode.
  14008.  
  14009.  For an example of the  ON STRIG statement, see the  STRIG statements
  14010.  programming example.
  14011.  
  14012.  Using On UEVENT
  14013.  You can use  ON UEVENT to specify a routine to branch to when a user-defined
  14014.  event occurs. The event usually is a hardware interrupt (although it also
  14015.  can be a software interrupt).
  14016.  
  14017.  
  14018.  When using DOS, at least two (and sometimes three) pieces of code are
  14019.  needed. The first is the interrupt-service routine. The second is an
  14020.  initialization routine to insert the address of the service routine into the
  14021.  interrupt-vector table. The third is the routine your BASIC program calls to
  14022.  retrieve the data (if any) collected by the interrupt-service routine. For
  14023.  more information, see "Event Handling" in the  Programmer's Guide.
  14024.  
  14025.  If the initialization routine "steals" an interrupt used by another service
  14026.  routine, the original address must be restored before your program
  14027.  terminates.
  14028.  
  14029.  These routines usually are written in assembly language. However, any
  14030.  language whose compiler can generate interrupt-service routines and whose
  14031.  object code can be linked with BASIC can be used.
  14032.  
  14033.  There are four steps in creating a user-defined event:
  14034.  
  14035.    ■         Write an event-handling routine and add it to your BASIC
  14036.              program.
  14037.  
  14038.    ■         Execute the  ON UEVENT statement to specify the user-event
  14039.              handling routine.
  14040.  
  14041.    ■         Execute the  UEVENT ON statement to enable user-event trapping.
  14042.  
  14043.    ■         Call the interrupt-initialization routine to insert the address
  14044.              of the interrupt-service routine into the interrupt-vector
  14045.              table.
  14046.  
  14047.  You're now ready for the interrupt when it occurs. The interrupt transfers
  14048.  execution to the interrupt-service routine. The service routine collects and
  14049.  stores the data the user wants. It then calls SetUEvent (see the entry for
  14050.  SetUEvent for details).
  14051.  
  14052.  SetUEvent sets a flag checked by BASIC before going to the next BASIC
  14053.  statement (or label if executing compiled code using /W instead of /V). When
  14054.  the flag is set, control transfers to the event-handling routine designated
  14055.  in  ON EVENT.
  14056.  
  14057.  
  14058.  For an example of the  ON UEVENT statement, see the  UEVENT statements
  14059.  programming example.
  14060.  
  14061.  
  14062.  See Also
  14063.  
  14064.   COM,  EVENT,  KEY (Event Trapping),  PEN,  PLAY (Event Trapping),  RETURN,
  14065.  SIGNAL,  STRIG,  TIMER,  UEVENT
  14066.  
  14067.  
  14068.  ON...GOSUB, ON...GOTO Statements
  14069.  ────────────────────────────────────────────────────────────────────────────
  14070.  
  14071.  
  14072.  Action
  14073.  
  14074.  Branches to one of several specified lines, depending on the value of an
  14075.  expression.
  14076.  
  14077.  
  14078.  Syntax 1
  14079.  
  14080.   ON  expression  GOSUB  line-label-list
  14081.  
  14082.  Syntax 2
  14083.  
  14084.   ON  expression  GOTO  line-label-list
  14085.  
  14086.  Remarks
  14087.  
  14088.  
  14089.  The argument  expression can be any numeric expression between 0 and 255,
  14090.  inclusive ( expression is rounded to an integer before the  ON... GOSUB or
  14091.  ON... GOTO statement is evaluated). The argument  line-label-list consists
  14092.  of a list of line numbers or line labels, separated by commas. The value of
  14093.  expression determines which line the program branches to. For example, if
  14094.  the value is 3, the third line specified in the list is the destination of
  14095.  the branch.
  14096.  
  14097.  The value of  expression should be greater than or equal to 1 and less than
  14098.  or equal to the number of items in the list. If the value falls outside this
  14099.  range, one of the following results occurs:
  14100. ╓┌─────────────────────────────────────┌─────────────────────────────────────╖
  14101.  Value                                 Result
  14102.  ────────────────────────────────────────────────────────────────────────────
  14103.  Number equal to 0 or greater than     Control drops to the next BASIC
  14104.  number of items in list               statement.
  14105.  
  14106.  Negative number or a number greater   BASIC generates the error
  14107.  than 255                              messageIllegal function call.
  14108.  
  14109.  
  14110.  
  14111.  You may mix line numbers and labels in the same list.
  14112.  
  14113.  
  14114.  Note
  14115.  
  14116.  You can mix line numbers and labels in the same list. The  ON ... GOTO
  14117.  statement accepts a maximum of 60 line labels or line numbers. The  SELECT
  14118.  CASE statement provides a more powerful, convenient, and flexible way to
  14119.  perform multiple branching.
  14120.  
  14121.  
  14122.  See Also
  14123.  
  14124.   GOSUB,  RETURN,  SELECT CASE
  14125.  
  14126.  
  14127.  Example
  14128.  
  14129.  
  14130.  The following example causes program control to branch to one of three
  14131.  subroutines, depending on the value of Chval:
  14132.  
  14133.  CLS    ' Clear screen.
  14134.  
  14135.  
  14136.  Attend = 20
  14137.  
  14138.  
  14139.  Fees = 5 * Attend
  14140.  
  14141.  
  14142.  PRINT "1  Display attendance at workshops"
  14143.  
  14144.  
  14145.  PRINT "2  Calculate total registration fees paid"
  14146.  
  14147.  
  14148.  PRINT "3  End program"
  14149.  
  14150.  
  14151.  PRINT : PRINT "What is your choice?"
  14152.  
  14153.  
  14154.  Choice:
  14155.  
  14156.  
  14157.      DO
  14158.  
  14159.  
  14160.         ch$ = INKEY$
  14161.  
  14162.  
  14163.      LOOP WHILE ch$ = ""
  14164.  
  14165.  
  14166.      Chval = VAL(ch$)
  14167.  
  14168.  
  14169.      IF Chval > 0 AND Chval < 4 THEN
  14170.  
  14171.  
  14172.          ON Chval GOSUB Shop, Fees, Progend
  14173.  
  14174.  
  14175.      END IF
  14176.  
  14177.  
  14178.  END
  14179.  
  14180.  
  14181.  Shop:
  14182.  
  14183.  
  14184.      PRINT "ATTENDANCE IS", Attend
  14185.  
  14186.  
  14187.      RETURN Choice
  14188.  
  14189.  
  14190.  Fees:
  14191.  
  14192.  
  14193.      PRINT "REGISTRATION FEES ARE $"; Fees
  14194.  
  14195.  
  14196.      RETURN Choice
  14197.  
  14198.  
  14199.  Progend:
  14200.  
  14201.  
  14202.  END
  14203.  
  14204.  
  14205.  OPEN Statement (File I/O)
  14206.  ────────────────────────────────────────────────────────────────────────────
  14207.  
  14208.  
  14209.  Action
  14210.  
  14211.  Enables I/O to a file, device, or ISAM table.
  14212.  
  14213.  
  14214.  Syntax 1
  14215.  
  14216.   OPEN  file$   FOR  mode  ACCESS  access  lock  AS #  filenumber%   LEN=
  14217.  reclen%  OPEN  database$  FOR  ISAM  tabletype  tablename$  AS #
  14218.  filenumber%
  14219.  
  14220.  Syntax 2
  14221.  
  14222.   OPEN  mode$, #  filenumber%,  file$,  reclen%
  14223.  
  14224.  Remarks
  14225.  
  14226.  
  14227.  You must open a file before any I/O operation can be performed on it.  OPEN
  14228.  allocates a buffer for I/O to the file or device and determines the mode of
  14229.  access used with the buffer.
  14230.  
  14231.  The  OPEN statement uses the following arguments:
  14232.  
  14233. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  14234.  Argument                                Description
  14235.  ────────────────────────────────────────────────────────────────────────────
  14236.   file$                                  A filename or path.
  14237.  
  14238.   mode                                   A keyword that specifies one of
  14239.                                          the following file modes: Random,
  14240.  Argument                                Description
  14241.  ────────────────────────────────────────────────────────────────────────────
  14242.                                         the following file modes: Random,
  14243.                                          Binary, Input, Output
  14244.  
  14245.  
  14246.   access                                 A keyword that specifies the
  14247.                                          operation performed on the open
  14248.                                          file:
  14249.  
  14250.  
  14251.   lock                                   A keyword that specifies the lock
  14252.                                          type:
  14253.  
  14254.  
  14255.   filenumber%                            An integer expression with a value
  14256.                                          between 1 and 255, inclusive. When
  14257.                                          an  OPEN statement is executed,
  14258.                                          the file number is associated with
  14259.                                          the file as long as it is open.
  14260.                                          Other I/O statements may use the
  14261.  Argument                                Description
  14262.  ────────────────────────────────────────────────────────────────────────────
  14263.                                         Other I/O statements may use the
  14264.                                          number to refer to the file.
  14265.  
  14266.   reclen%                                For random-access files, the
  14267.                                          record length; for sequential
  14268.                                          files, the number of characters
  14269.                                          buffered. The  reclen% is an
  14270.                                          integer expression less than or
  14271.                                          equal to 32,767 bytes.
  14272.  
  14273.   database$                              A database filename or path.
  14274.  
  14275.   tabletype                              The name of a type of table
  14276.                                          defined using the  TYPE statement.
  14277.  
  14278.   tablename$                             The name of the ISAM table being
  14279.                                          opened. It follows the ISAM naming
  14280.                                          conventions (listed later in this
  14281.                                          entry).
  14282.  Argument                                Description
  14283.  ────────────────────────────────────────────────────────────────────────────
  14284.                                         entry).
  14285.  
  14286.  
  14287.  
  14288.  Syntax 1
  14289.  The arguments  file$ and  database$ specify an optional device, followed by
  14290.  a filename or path conforming to the DOS file-naming conventions. The
  14291.  argument  database$ must be the name of an ISAM file.
  14292.  
  14293.  
  14294.  For sequential files, if  file$ does not exist, it is created when opening a
  14295.  file for anything but input [mdash] that is,  OUTPUT,  RANDOM,  BINARY, and
  14296.  APPEND. For ISAM, a nonexistent  database$ or  tablename$ is created only
  14297.  when using the PROISAMD library; with the PROISAM library, BASIC generates
  14298.  the error message File Not Found if  database$ or  tablename$ does not
  14299.  exist.
  14300.  
  14301.  
  14302.  The argument  mode is a keyword that specifies one of the following file
  14303.  modes:
  14304.  
  14305. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  14306.  Keyword                                 Description
  14307.  ────────────────────────────────────────────────────────────────────────────
  14308.  Random                                  Specifies random-access file mode,
  14309.                                          the default mode. In random mode,
  14310.                                          if no  ACCESS clause is present,
  14311.                                          three attempts are made to open
  14312.                                          the file when the  OPEN statement
  14313.                                          is executed. Access is attempted
  14314.                                          in the following order:
  14315.  
  14316.                                          1. Read and write
  14317.  
  14318.                                          2. Write only
  14319.  
  14320.                                          3. Read only
  14321.  
  14322.  Binary                                  Specifies binary file mode. In
  14323.                                          binary mode, you can read or write
  14324.  Keyword                                 Description
  14325.  ────────────────────────────────────────────────────────────────────────────
  14326.                                         binary mode, you can read or write
  14327.                                          information to any byte position
  14328.                                          in the file using  GET and  PUT.
  14329.  
  14330.                                          In binary mode, if no  ACCESS
  14331.                                          clause is present, three attempts
  14332.                                          are made to open the file,
  14333.                                          following the same order as for
  14334.                                          random files.
  14335.  
  14336.  Input                                   Sequential input mode.
  14337.  
  14338.  Output                                  Sequential output mode.
  14339.  
  14340.  Append                                  Sequential output mode. Sets the
  14341.                                          file pointer to the end-of-file
  14342.                                          and the record number to the last
  14343.                                          record of the file. A  PRINT # or
  14344.                                          WRITE # statement then extends
  14345.  Keyword                                 Description
  14346.  ────────────────────────────────────────────────────────────────────────────
  14347.                                         WRITE # statement then extends
  14348.                                          (appends to) the file.
  14349.  
  14350.  
  14351.  
  14352.  
  14353.  
  14354.  If the  mode argument is omitted, the default random-access mode is assumed.
  14355.  
  14356.  The argument  access is a keyword that specifies the operation performed on
  14357.  the opened file. If the file is already opened by another process and the
  14358.  specified type of access is not allowed, the  OPEN operation fails and BASIC
  14359.  generates the error Permission denied. The  ACCESS clause works in an  OPEN
  14360.  statement only if you are using a version of DOS that supports networking
  14361.  (DOS version 3.0 or later). In addition, you must run the SHARE.EXE program
  14362.  (or the network startup program must run it) to perform any locking
  14363.  operation. If  ACCESS is used with  OPEN, earlier versions of DOS return the
  14364.  error message Feature unavailable.
  14365.  
  14366.  The argument  access can be one of the following:
  14367.  
  14368. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  14369.  Access type                             Description
  14370.  ────────────────────────────────────────────────────────────────────────────
  14371.   Read                                   Opens the file for reading only.
  14372.  
  14373.   Write                                  Opens the file for writing only.
  14374.  
  14375.   Read  Write                            Opens the file for both reading
  14376.                                          and writing. This mode is valid
  14377.                                          only for random and binary files,
  14378.                                          and files opened for append.
  14379.  
  14380.  
  14381.  
  14382.  
  14383.  
  14384.  The  lock clause works in a multiprocessing environment to restrict access
  14385.  by other processes to an open file. The argument can be one of the following
  14386.  keywords specifying the lock type:
  14387.  
  14388.  
  14389. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  14390.  Lock type                               Description
  14391.  ────────────────────────────────────────────────────────────────────────────
  14392.   Shared                                 Any process on any machine may
  14393.                                          read from or write to this file.
  14394.                                          Do not confuse the shared lock
  14395.                                          type with the  SHARED statement or
  14396.                                          the shared attribute that appears
  14397.                                          in other statements.
  14398.  
  14399.   Lock  Read                             No other process is granted read
  14400.                                          access to this file. This access
  14401.                                          is granted only if no other
  14402.                                          process has a previous read access
  14403.                                          to the file.
  14404.  
  14405.   Lock  Write                            No other process is granted write
  14406.                                          access to this file. This lock is
  14407.                                          granted only if no other process
  14408.  Lock type                               Description
  14409.  ────────────────────────────────────────────────────────────────────────────
  14410.                                         granted only if no other process
  14411.                                          has a previous write access to the
  14412.                                          file.
  14413.  
  14414.   Lock  Read  Write                      No other process is granted either
  14415.                                          read or write access to this file.
  14416.                                          This access is granted only if
  14417.                                          read or write access has not
  14418.                                          already been granted to another
  14419.                                          process, or if a lock read or lock
  14420.                                          write is not already in place.
  14421.  
  14422.  
  14423.  
  14424.  
  14425.  
  14426.  If you do not specify a lock type, the file may be opened for reading and
  14427.  writing any number of times by this statement, but other operations are
  14428.  denied access to the file while it is opened.
  14429.  
  14430.  When  OPEN is restricted by a previous process, BASIC generates error 70,
  14431.  Permission denied.
  14432.  
  14433.  The argument  reclen% is an integer expression less than or equal to 32,767
  14434.  bytes. It specifies different settings for random-access or sequential
  14435.  files:
  14436.  
  14437. ╓┌─────────────────────────────────────┌─────────────────────────────────────╖
  14438.  For random-access:                    For sequential files:
  14439.  ────────────────────────────────────────────────────────────────────────────
  14440.  The argument  reclen% sets the        The argument  reclen% specifies the
  14441.  record length (the number of          number of characters to be loaded
  14442.  characters in a record).              into the buffer before the buffer is
  14443.                                        written to, or read from, the disk.
  14444.  
  14445.  The default is 128 bytes.             A larger buffer means more room
  14446.                                        taken from BASIC, but faster file
  14447.                                        I/O. A smaller buffer means more
  14448.                                        room in memory for BASIC, but slower
  14449.                                        I/O.
  14450.  For random-access:                    For sequential files:
  14451.  ────────────────────────────────────────────────────────────────────────────
  14452.                                       I/O.
  14453.  
  14454.                                        The default is 512 bytes.
  14455.  
  14456.  
  14457.  
  14458.  
  14459.  
  14460.  The  LEN clause and  reclen% are ignored if  mode is binary. For sequential
  14461.  files,  reclen% need not correspond to an individual record size, because a
  14462.  sequential file may have records of different sizes.
  14463.  
  14464.   ISAM is a keyword that specifies you are opening an ISAM table.
  14465.  
  14466.  
  14467.  The argument  tabletype is the name of a user-defined type that defines a
  14468.  subset of the table definition. (See the entry for the  TYPE statement.) The
  14469.  argument  tablename$ is the name of the ISAM table being opened. It follows
  14470.  the ISAM naming conventions:
  14471.  
  14472.    ■         It has no more than 30 characters.
  14473.  
  14474.    ■         It uses only alphanumeric characters (A-Z, a-z, 0-9).
  14475.  
  14476.    ■         It begins with an alphabetic character.
  14477.  
  14478.    ■         It includes no BASIC special characters.
  14479.  
  14480.  Syntax 2
  14481.  In the second (alternative) form of the  OPEN syntax,  mode$ is a string
  14482.  expression that begins with one of the following characters and specifies
  14483.  the file mode:
  14484.  
  14485.  
  14486. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  14487.  Mode                                    Description
  14488.  ────────────────────────────────────────────────────────────────────────────
  14489.   O                                      Sequential output mode.
  14490.  
  14491.   I                                      Sequential input mode.
  14492.  Mode                                    Description
  14493.  ────────────────────────────────────────────────────────────────────────────
  14494.  I                                      Sequential input mode.
  14495.  
  14496.   R                                      Random-access file I/O mode.
  14497.  
  14498.   B                                      Binary file mode.
  14499.  
  14500.   A                                      Sequential output mode. Sets the
  14501.                                          file pointer to the end of the
  14502.                                          file and the record number to the
  14503.                                          last record of the file. A  PRINT
  14504.                                          # or  WRITE # statement extends
  14505.                                          (appends to) the file.
  14506.  
  14507.  
  14508.  
  14509.  
  14510.  
  14511.  
  14512.  Note
  14513.  
  14514.  This alternative syntax does not support any of the access and file-sharing
  14515.  options found in the primary syntax. It is supported for compatibility with
  14516.  programs written in earlier versions of BASIC.
  14517.  
  14518.  The following devices are supported by BASIC and can be named and opened
  14519.  with the argument  file$:
  14520.  
  14521.  KYBD, SCRN, COM n, LPT n, CONS, PIPE.
  14522.  
  14523.  The BASIC file I/O system allows you to take advantage of user-installed
  14524.  devices. (See your DOS manual for information on character devices.)
  14525.  
  14526.  Character devices are opened and used in the same manner as disk files.
  14527.  However, characters are not buffered by BASIC as they are for disk files.
  14528.  The record length for device files is set to 1.
  14529.  
  14530.  
  14531.  BASIC sends only a carriage return at the end of a line. If the device
  14532.  requires a line feed, the driver must provide it. When writing to device
  14533.  drivers, keep in mind that other BASIC users will want to read and write
  14534.  control information. Writing and reading of device-control data is handled
  14535.  by the  IOCTL statement and  IOCTL$ function.
  14536.  
  14537.  
  14538.  None of the BASIC devices directly supports binary mode. However,
  14539.  line-printer devices can be opened in binary mode by adding the  BIN
  14540.  keyword:
  14541.  
  14542.  OPEN "LPT1:BIN" FOR OUTPUT AS #1
  14543.  
  14544.  Opening a printer in binary mode eliminates printing a carriage return at
  14545.  the end of a line.
  14546.  
  14547.  
  14548.  When you open an ISAM table, the next record is the first record in the
  14549.  table and the current index is the null index.
  14550.  
  14551.  Any ISAM operation that closes a table causes transactions to be committed.
  14552.  For example, if a type mismatch occurs while you are opening an ISAM table,
  14553.  the table is closed and a pending transaction is committed.
  14554.  
  14555.  You may wish to code your programs so they first open all tables, then
  14556.  perform all transactions, then close tables. Make sure any operation that
  14557.  can close a table occurs outside a transaction.
  14558.  
  14559.  
  14560.  Note
  14561.  
  14562.  In input, random-access, and binary modes you can open a file under a
  14563.  different file number without first closing the file. In output or append
  14564.  mode you must close a file before opening it with a different file number.
  14565.  
  14566.  
  14567.  See Also
  14568.  
  14569.   CLOSE,  FREEFILE,  TYPE
  14570.  
  14571.  
  14572.  Example
  14573.  
  14574.  See the  FREEFILE function programming example, which uses the  OPEN
  14575.  statement.
  14576.  
  14577.  
  14578.  OPEN COM Statement
  14579.  ────────────────────────────────────────────────────────────────────────────
  14580.  
  14581.  
  14582.  Action
  14583.  
  14584.  Opens and initializes a communications channel for I/O.
  14585.  
  14586.  
  14587.  Syntax
  14588.  
  14589.  
  14590.  
  14591.   OPEN " COM n:  optlist1  optlist2"  FOR  mode  AS  #  filenum%  LEN=
  14592.  reclen%
  14593.  
  14594.  Remarks
  14595.  
  14596.  
  14597.  The  OPEN COM statement must be executed before a device can be used for
  14598.  communication using an RS232 interface.  COM n is the name of the device to
  14599.  be opened. If there are any syntax errors in the  OPEN COM statement, BASIC
  14600.  generates the error message Bad file name.
  14601.  
  14602.  The  OPEN COM statement uses the following arguments:
  14603.  
  14604. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  14605.  Argument                                Description
  14606.  ────────────────────────────────────────────────────────────────────────────
  14607.   n                                      The communications port to open,
  14608.                                          such as 1 for COM1 and 2 for COM2.
  14609.  
  14610.   optlist1                               The most-often-used communications
  14611.                                          parameters. The defaults are 300
  14612.                                          baud, even parity, 7 data bits,
  14613.                                          and 1 stop bit. The syntax of
  14614.                                          optlist1 and options are described
  14615.                                          later in this entry.
  14616.  
  14617.   optlist2                               Up to 10 other optional,
  14618.  Argument                                Description
  14619.  ────────────────────────────────────────────────────────────────────────────
  14620.  optlist2                               Up to 10 other optional,
  14621.                                          less-often-used data
  14622.                                          communications parameters. The
  14623.                                          parameters for  optlist2 are
  14624.                                          described later in this entry.
  14625.  
  14626.   mode                                   One of the keywords  OUTPUT,
  14627.                                          INPUT, or  RANDOM (the default).
  14628.  
  14629.   filenum%                               Any unused file number between 1
  14630.                                          and 255, inclusive.
  14631.  
  14632.   reclen%                                The size of a random-access-mode
  14633.                                          buffer (128 bytes is the default).
  14634.  
  14635.  
  14636.  
  14637.  
  14638.  
  14639.  The argument  optlist1 specifies the communication-line parameters and has
  14640.  this syntax:
  14641.  
  14642.  
  14643.   speed , parity , data , stop
  14644.  
  14645.  The following table lists the valid values for  optlist1 options:
  14646. ╓┌───────┌─────────────────────┌─────────────────────┌───────────────────────╖
  14647.  Option  Description           Range                 Default
  14648.  ────────────────────────────────────────────────────────────────────────────
  14649.  speed   Baud rate (bits per   75, 110, 150, 300,    300
  14650.          second) of the        600, 1200, 1800,
  14651.          device to be opened)   2400, 9600
  14652.  
  14653.  parity  Method of parity      N, E, O, S, M         E
  14654.          checking (none, even,
  14655.          odd, space, mark)
  14656.  
  14657.  data    Number of data bits   5, 6, 7, or 8         7
  14658.          per byte
  14659.  
  14660.  Option  Description           Range                 Default
  14661.  ────────────────────────────────────────────────────────────────────────────
  14662. 
  14663.  stop    Number of stop bits   1, 1.5, or 2          1 *
  14664.  
  14665.                                                      * The default value is
  14666.                                                      1 for baud rates
  14667.                                                      greater than 110. For
  14668.                                                      baud rates less than
  14669.                                                      or equal to 110, the
  14670.                                                      default value is 1.5
  14671.                                                      when data is 5;
  14672.                                                      otherwise, the value
  14673.                                                      is 2.
  14674.  
  14675.  
  14676.  
  14677.  
  14678.  Options in this list must be entered in the order shown. Use comma
  14679.  placeholders for defaults. For example:
  14680.  
  14681.  OPEN "COM1: ,N,8," FOR INPUT AS #1
  14682.  
  14683.  
  14684.  
  14685.  
  14686.  Only the baud rates shown are supported. Any other value for  speed is
  14687.  invalid.
  14688.  
  14689.  
  14690.  If any options from  optlist2 are chosen, comma placeholders still must be
  14691.  used even if all of the  optlist1 options are defaults. For example:
  14692.  
  14693.  OPEN "COM1: ,,,,CD1500" FOR INPUT AS #1
  14694.  
  14695.  
  14696.  
  14697.  
  14698.  If you set  data to 8 bits per byte, you must specify no parity ( N).
  14699.  
  14700.  
  14701.  
  14702.  Note
  14703.  
  14704.  Because BASIC uses complete bytes (8 bits) for numbers, you must specify 8
  14705.  data bits when transmitting or receiving numeric data.
  14706.  
  14707.  The  optlist2 options can be specified in any order, and must be separated
  14708.  by commas. There are three types of options: data mode, buffer size, and
  14709.  handshaking.
  14710.  
  14711.  The data-mode options ( ASC,  BIN, and  LF) are described in the following
  14712.  table:
  14713.  
  14714.  
  14715. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  14716.  Option                                  Description
  14717.  ────────────────────────────────────────────────────────────────────────────
  14718.  ASC                                     Opens the device in ASCII mode. In
  14719.                                          ASCII mode, tabs are expanded to
  14720.                                          blanks, carriage returns are
  14721.                                          forced at end-of-line, and Ctrl+Z
  14722.                                          means end-of-file. When the
  14723.  Option                                  Description
  14724.  ────────────────────────────────────────────────────────────────────────────
  14725.                                         means end-of-file. When the
  14726.                                          channel is closed, Ctrl+Z is sent
  14727.                                          over the RS-232 line.
  14728.  
  14729.  BIN                                     Opens the device in binary mode.
  14730.                                          This option supersedes the LF
  14731.                                          option. BIN is elected by default
  14732.                                          unless ASC is specified.
  14733.  
  14734.                                          In binary mode, tabs are not
  14735.                                          expanded to spaces, a carriage
  14736.                                          return is not forced at the end of
  14737.                                          a line, and Ctrl+Z is not treated
  14738.                                          as end-of-file. When the channel
  14739.                                          is closed, Ctrl+Z will not be sent
  14740.                                          over the RS232 line.
  14741.  
  14742.  LF                                      Allows communication files to be
  14743.                                          printed on a serial line printer.
  14744.  Option                                  Description
  14745.  ────────────────────────────────────────────────────────────────────────────
  14746.                                         printed on a serial line printer.
  14747.                                          Effective only with the ASC option.
  14748.                                          When LF is specified, a line-feed
  14749.                                          character (0AH) is automatically
  14750.                                          sent after each carriage-return
  14751.                                          character (0DH). This includes the
  14752.                                          carriage return sent as a result
  14753.                                          of the width setting. Note that
  14754.                                          INPUT and  LINE INPUT, when used
  14755.                                          to read from a communications file
  14756.                                          that was opened with the LF option,
  14757.                                          stop when they see a carriage
  14758.                                          return, ignoring the line feed.
  14759.  
  14760.  
  14761.  
  14762.  The buffer-size options for sequential modes (RB and TB) are described in
  14763.  the following table:
  14764.  
  14765. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  14766.  Option                                  Description
  14767.  ────────────────────────────────────────────────────────────────────────────
  14768.  RB n                                    Sets the size of the receive
  14769.                                          buffer to  n bytes. The initial
  14770.                                          buffer size, if  n or the RB
  14771.                                          option is omitted, is 512 bytes,
  14772.                                          unless overridden by the /C option
  14773.                                          on the QBX or BC command line. The
  14774.                                          default value, if  n or the RB
  14775.                                          option is omitted, is the current
  14776.                                          receive-buffer size. The maximum
  14777.                                          size is 32,767 bytes.
  14778.  
  14779.  TB n                                    Sets the size of the receive
  14780.                                          buffer to  n bytes. The initial
  14781.                                          buffer size, if  n or the TB
  14782.                                          option is omitted, is 512 bytes.
  14783.                                          The default value, if  n or the TB
  14784.                                          option is omitted, is the current
  14785.                                          receive-buffer size.
  14786.  Option                                  Description
  14787.  ────────────────────────────────────────────────────────────────────────────
  14788.                                         receive-buffer size.
  14789.  
  14790.  
  14791.  
  14792.  
  14793.  Handshake and timing options (RS, CD, CS, DS, and OP) are described in the
  14794.  table below:
  14795.  
  14796.  
  14797. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  14798.  Option                                  Description
  14799.  ────────────────────────────────────────────────────────────────────────────
  14800.  RS                                      Suppresses detection of Request To
  14801.                                          Send (RTS).
  14802.  
  14803.  CD m                                    Specifies the timeout period on
  14804.                                          the Data Carrier Detect line (DCD).
  14805.                                          If no signal appears on the DCD
  14806.                                          line (the DCD line remains low)
  14807.  Option                                  Description
  14808.  ────────────────────────────────────────────────────────────────────────────
  14809.                                         line (the DCD line remains low)
  14810.                                          for more than  m milliseconds, a
  14811.                                          device timeout occurs. If a CD
  14812.                                          timeout occurs,  ERDEV contains
  14813.                                          130 (82H).
  14814.  
  14815.                                          The range for  m, if specified, is
  14816.                                          0 - 65,535 milliseconds, inclusive.
  14817.                                          The default value is 0, if the CD
  14818.                                          option is not used, or if  m is
  14819.                                          omitted. When  m is 0, either by
  14820.                                          default or assignment, it means
  14821.                                          that the state of the DCD line is
  14822.                                          to be ignored.
  14823.  
  14824.  CS m                                    Specifies the timeout period on
  14825.                                          the Clear To Send line (CTS). If
  14826.                                          no signal appears on the CTS line
  14827.                                          (the CTS line remains low) for
  14828.  Option                                  Description
  14829.  ────────────────────────────────────────────────────────────────────────────
  14830.                                         (the CTS line remains low) for
  14831.                                          more than  m milliseconds, a
  14832.                                          device timeout occurs. If a CS
  14833.                                          timeout occurs,  ERDEV contains
  14834.                                          128 (80H).
  14835.  
  14836.                                          The range for  m, if specified, is
  14837.                                          0 - 65,535 milliseconds, inclusive.
  14838.                                          The default value is 1,000
  14839.                                          milliseconds, if the CS option is
  14840.                                          not used, or if  m is omitted.
  14841.                                          When  m is 0, either by default or
  14842.                                          assignment, it means the state of
  14843.                                          the CTS line is to be ignored.
  14844.  
  14845.  DS m                                    Specifies the timeout period on
  14846.                                          the Data Set Ready line (DSR). If
  14847.                                          no signal appears on the DSR line
  14848.                                          (the DSR line remains low) for
  14849.  Option                                  Description
  14850.  ────────────────────────────────────────────────────────────────────────────
  14851.                                         (the DSR line remains low) for
  14852.                                          more than  m milliseconds, a
  14853.                                          device timeout occurs. If a DS
  14854.                                          timeout occurs,  ERDEV contains
  14855.                                          129 (81H).
  14856.  
  14857.                                          The range for  m, if specified, is
  14858.                                          0 - 65,535 milliseconds, inclusive.
  14859.                                          (See Note below.) The default
  14860.                                          value is 1,000 milliseconds, if
  14861.                                          the  DS option is not used, or if
  14862.                                          m is omitted. When  m is 0, either
  14863.                                          by default or assignment, it means
  14864.                                          that the state of the DSR line is
  14865.                                          to be ignored.
  14866.  
  14867.  OP m                                    Specifies how long the  OPEN
  14868.                                          statement waits for all
  14869.                                          communications lines to become
  14870.  Option                                  Description
  14871.  ────────────────────────────────────────────────────────────────────────────
  14872.                                         communications lines to become
  14873.                                          active. The range for  m is 0 -
  14874.                                          65,535 milliseconds, inclusive.
  14875.                                          The default value for  m, if the
  14876.                                          OP option is not used, is 10 times
  14877.                                          the CD or DS timeout value,
  14878.                                          whichever is greater. If OP is
  14879.                                          specified, but with  m omitted,
  14880.                                          OPEN  COM waits for 10 seconds.
  14881.                                          Use a relatively large value for
  14882.                                          the OP option compared to the CS,
  14883.                                          DS, or CD options.
  14884.  
  14885.  
  14886.  
  14887.  
  14888.  
  14889.  
  14890.  Note
  14891.  
  14892.  Under OS/2, specifying DS0 to ignore the state of the Data Set Ready (DSR)
  14893.  line does not work properly. In this case, you will have to either not
  14894.  ignore the DSR line or you will have to jumper the DSR line to an active
  14895.  high signal line. Refer to serial port information that specifically
  14896.  pertains to your hardware, and perform any modifications at your own risk.
  14897.  
  14898.  The argument  filenum% is the number used to open the file.
  14899.  
  14900.  The argument  reclen% is effective only in random-access mode and specifies
  14901.  the length of the random-access buffer (default is 128 bytes). You can use
  14902.  any of the random-access I/O statements, such as  GET and  PUT, to treat the
  14903.  device as if it were a random-access file.
  14904.  
  14905.  The argument  mode is one of the following string expressions:
  14906.  
  14907.  
  14908. ╓┌──────────────────┌────────────────────────────────────────────────────────╖
  14909.  Mode               Description
  14910.  ────────────────────────────────────────────────────────────────────────────
  14911.   OUTPUT            Specifies sequential output mode.
  14912.  Mode               Description
  14913.  ────────────────────────────────────────────────────────────────────────────
  14914.   OUTPUT            Specifies sequential output mode.
  14915.   INPUT             Specifies sequential input mode.
  14916.   RANDOM            Specifies random-access mode.
  14917.  
  14918.  
  14919.  
  14920.  
  14921.  If  mode is omitted, it is assumed to be random-access input/output.
  14922.  
  14923.  The  OPEN COM statement performs the following steps in opening a
  14924.  communications device:
  14925.  
  14926.    ■         The communications buffers are allocated and interrupts are
  14927.              enabled.
  14928.  
  14929.    ■         The Data Terminal Ready line (DTR) is set high.
  14930.  
  14931.    ■         If either of the OP or DS options is nonzero, the statement
  14932.              waits for the timeout period for the Data Set Ready line (DSR)
  14933.              to go high. If a timeout occurs, the process goes to step 6.
  14934.  
  14935.    ■         If the RS option is not specified, the Request To Send line
  14936.              (RTS) is set high.
  14937.  
  14938.    ■         If either of the OP or CD options is nonzero, the statement
  14939.              waits for the timeout period for the Data Carrier Detect line
  14940.              (DCD) to go high. If a timeout occurs, the process goes to step
  14941.              6. Otherwise, the RS232 device has been successfully opened.
  14942.  
  14943.    ■         If there is a timeout, the open fails. The process deallocates
  14944.              the buffers, disables interrupts, clears all of the control
  14945.              lines, and generates the message Device timeout. In addition,
  14946.              for DOS, the process sets the value of  ERDEV$ to COM and sets
  14947.              ERDEV to a value that indicates the signal line that timed out,
  14948.              according to the following table:
  14949.  
  14950. ╓┌────────────────────┌──────────────────────────────────────────────────────╖
  14951.  ERDEV value          Signal line
  14952.  ────────────────────────────────────────────────────────────────────────────
  14953.  128 (80H)            Clear to Send (CTS) timeout
  14954.  ERDEV value          Signal line
  14955.  ────────────────────────────────────────────────────────────────────────────
  14956.  128 (80H)            Clear to Send (CTS) timeout
  14957.  129 (81H)            Data Set Ready (DSR) timeout
  14958.  130 (82H)            Data Carrier Detect (DCD) timeout
  14959.  
  14960.  
  14961.  
  14962.  
  14963.  
  14964.  Note
  14965.  
  14966.  If there is not an  OPEN COM statement in your program, you can reduce the
  14967.  size of the .EXE file by linking your program with the stub file NOCOM.OBJ.
  14968.  
  14969.  
  14970.  Example
  14971.  
  14972.  See the  COM statements programming example, which uses the  OPEN COM
  14973.  statement.
  14974.  
  14975.  
  14976.  OPTION BASE Statement
  14977.  ────────────────────────────────────────────────────────────────────────────
  14978.  
  14979.  
  14980.  Action
  14981.  
  14982.  Declares the default lower bound for array subscripts.
  14983.  
  14984.  
  14985.  Syntax
  14986.  
  14987.  
  14988.  
  14989.   OPTION  BASE  n%
  14990.  
  14991.  Remarks
  14992.  
  14993.  
  14994.  The  OPTION  BASE statement is never required.
  14995.  
  14996.  The value of  n% must be either 0 or 1. The default base is 0. If the
  14997.  following statement is executed, the default lowest value of an array
  14998.  subscript is 1.
  14999.  
  15000.  OPTION BASE 1
  15001.  
  15002.  
  15003.  Note
  15004.  
  15005.  
  15006.  The  TO clause in the  DIM statement provides an easier, more flexible way
  15007.  to control the range of an array's subscripts. If the lower bound of an
  15008.  array subscript is not explicitly set, then  OPTION  BASE can be used to
  15009.  change the default lower bound to 1.
  15010.  
  15011.  The  OPTION  BASE statement can be used only once in a module (source file)
  15012.  and can appear only in the module-level code. An  OPTION  BASE statement
  15013.  must be used before you can declare the dimensions for any arrays.
  15014.  
  15015.  Chained programs can have an  OPTION  BASE statement if no arrays are passed
  15016.  between them in a  COMMON block, or if the specified base is identical in
  15017.  the chained programs. The chained-to program inherits the  OPTION  BASE
  15018.  value of the chaining program if  OPTION  BASE is omitted in the latter.
  15019.  
  15020.  
  15021.  See Also
  15022.  
  15023.   DIM,  LBOUND,  UBOUND
  15024.  
  15025.  
  15026.  Example
  15027.  
  15028.  The following example shows the use of  OPTION  BASE to override the default
  15029.  base array subscript value of 0. Subscripts in array A range from 1 to 20
  15030.  rather than 0 to 19.
  15031.  
  15032.  OPTION BASE 1
  15033.  
  15034.  
  15035.  DIM A(20)
  15036.  
  15037.  
  15038.  PRINT "The base subscript in array A is"; LBOUND(A)
  15039.  
  15040.  
  15041.  PRINT "The upper bound subscript in array A is"; UBOUND(A)
  15042.  
  15043.  
  15044.  
  15045.  
  15046.  Output
  15047.  
  15048.  
  15049.  
  15050.  The base subscript in array A is 1
  15051.  
  15052.  
  15053.  The upper bound subscript in array A is 20
  15054.  
  15055.  
  15056.  OUT Statement
  15057.  ────────────────────────────────────────────────────────────────────────────
  15058.  
  15059.  
  15060.  Action
  15061.  
  15062.  Sends a byte to a hardware I/O port.
  15063.  
  15064.  
  15065.  Syntax
  15066.  
  15067.  
  15068.  
  15069.   OUT  port,  data%
  15070.  
  15071.  Remarks
  15072.  
  15073.  
  15074.  The  OUT statement complements the  INP function, which returns the byte
  15075.  read from a hardware I/O port. The  OUT statement uses the following
  15076.  arguments:
  15077.  
  15078. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  15079.  Argument                                Description
  15080.  Argument                                Description
  15081.  ────────────────────────────────────────────────────────────────────────────
  15082.   port                                   A numeric expression with an
  15083.                                          integer value between 0 and 65,535,
  15084.                                          inclusive, that identifies the
  15085.                                          destination hardware I/O port.
  15086.  
  15087.   data%                                  A numeric expression with an
  15088.                                          integer value between 0 and 255,
  15089.                                          inclusive, that is the data to be
  15090.                                          sent to the port.
  15091.  
  15092.  
  15093.  
  15094.  The  OUT statement and the  INP function give a BASIC program direct control
  15095.  over the hardware in a system through the I/O ports.  OUT and  INP must be
  15096.  used carefully because they  directly manipulate the system hardware.
  15097.  
  15098.  
  15099.  Note
  15100.  
  15101.  The  OUT statement is not available in OS/2 protected mode.
  15102.  
  15103.  
  15104.  See Also
  15105.  
  15106.   INP,  WAIT
  15107.  
  15108.  Example
  15109.  
  15110.  
  15111.  The following example uses the  OUT and  INP statements to control the timer
  15112.  and speaker to produce a note:
  15113.  
  15114.  ' Play a scale using speaker and timer.
  15115.  
  15116.  
  15117.  CONST WHOLE = 5000!, QRTR = WHOLE / 4!
  15118.  
  15119.  
  15120.  CONST C = 523!, D = 587.33, E = 659.26, F = 698.46, G = 783.99
  15121.  
  15122.  
  15123.  CONST A = 880!, B = 987.77, C1 = 1046.5
  15124.  
  15125.  
  15126.  CALL Sounds(C, QRTR): CALL Sounds(D, QRTR)
  15127.  
  15128.  
  15129.  CALL Sounds(E, QRTR): CALL Sounds(F, QRTR)
  15130.  
  15131.  
  15132.  CALL Sounds(G, QRTR): CALL Sounds(A, QRTR)
  15133.  
  15134.  
  15135.  CALL Sounds(B, QRTR): CALL Sounds(C1, WHOLE)
  15136.  
  15137.  
  15138.  
  15139.  
  15140.  
  15141.  SUB Sounds (Freq!, Length!) STATIC
  15142.  
  15143.  
  15144.  ' Ports 66, 67, and 97 control timer and speaker.
  15145.  
  15146.  
  15147.      ' Divide clock frequency by sound frequency
  15148.  
  15149.  
  15150.      ' to get number of "clicks" clock must produce.
  15151.  
  15152.  
  15153.      Clicks% = CINT(1193280! / Freq!)
  15154.  
  15155.  
  15156.      LoByte% = Clicks% AND &HFF
  15157.  
  15158.  
  15159.      HiByte% = Clicks% \ 256
  15160.  
  15161.  
  15162.      OUT 67, 182' Tell timer that data is coming.
  15163.  
  15164.  
  15165.      OUT 66, LoByte%' Send count to timer.
  15166.  
  15167.  
  15168.      OUT 66, HiByte%
  15169.  
  15170.  
  15171.      SpkrOn% = INP(97) OR &H3' Turn speaker on by setting
  15172.  
  15173.  
  15174.      OUT 97, SpkrOn%' bits 0 and 1 of PPI chip.
  15175.  
  15176.  
  15177.      FOR I! = 1 TO Length!: NEXT I!' Leave speaker on.
  15178.  
  15179.  
  15180.      SpkrOff% = INP(97) AND &HFC ' Turn speaker off.
  15181.  
  15182.  
  15183.      OUT 97, SpkrOff%
  15184.  
  15185.  
  15186.  END SUB
  15187.  
  15188.  PAINT Statement
  15189.  ────────────────────────────────────────────────────────────────────────────
  15190.  
  15191.  
  15192.  Action
  15193.  
  15194.  Fills a graphics area with the color or pattern specified.
  15195.  
  15196.  
  15197.  Syntax
  15198.  
  15199.   PAINT  STEP ( x!, y!) , paint , bordercolor& ,  background$
  15200.  
  15201.  Remarks
  15202.  
  15203.  
  15204.  The following list describes the parts of the  PAINT statement:
  15205.  
  15206. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  15207.  Part                                    Description
  15208.  ────────────────────────────────────────────────────────────────────────────
  15209.   STEP                                   Keyword indicating that
  15210.                                          coordinates are relative to the
  15211.                                          most recently plotted point. For
  15212.                                          example, if the last point plotted
  15213.                                          were (10,10), then the coordinates
  15214.                                          referred to by STEP (4,5)  would
  15215.                                          be (4+10, 5+10) or (14,15).
  15216.  
  15217.  ( x!, y!)                               The coordinates where painting
  15218.                                          begins. The point must be inside
  15219.                                          or outside of a figure, not on the
  15220.                                          border itself. If this point is
  15221.                                          inside, the figure's interior is
  15222.                                          painted; if the point is on the
  15223.                                          outside, the background is painted.
  15224.  
  15225.   paint                                  A numeric or string expression. If
  15226.                                           paint is a numeric expression,
  15227.  Part                                    Description
  15228.  ────────────────────────────────────────────────────────────────────────────
  15229.                                          paint is a numeric expression,
  15230.                                          then the number must be a valid
  15231.                                          color attribute. The corresponding
  15232.                                          color is used to paint the area.
  15233.                                          If you do not specify  paint, the
  15234.                                          foreground color attribute is used.
  15235.                                          (See the  COLOR,  PALETTE, and
  15236.                                          SCREEN statements for discussions
  15237.                                          of valid colors, numbers, and
  15238.                                          attributes.)
  15239.  
  15240.                                          If the argument  paint is a string
  15241.                                          expression,  PAINT "tiles," a
  15242.                                          process that paints a pattern
  15243.                                          rather than a solid color. Tiling
  15244.                                          is similar to "line styling,"
  15245.                                          which creates dashed lines rather
  15246.                                          than solid lines.
  15247.  
  15248.  Part                                    Description
  15249.  ────────────────────────────────────────────────────────────────────────────
  15250. 
  15251.   bordercolor&                           A numeric expression that
  15252.                                          identifies the color attribute to
  15253.                                          use to paint the border of the
  15254.                                          figure. When the border color is
  15255.                                          encountered, painting of the
  15256.                                          current line stops. If the border
  15257.                                          color is not specified, the  paint
  15258.                                          argument is used.
  15259.  
  15260.   background$                            A string value that gives the
  15261.                                          "background tile slice" to skip
  15262.                                          when checking for termination of
  15263.                                          the boundary. Painting is
  15264.                                          terminated when adjacent points
  15265.                                          display the paint color.
  15266.                                          Specifying a background tile slice
  15267.                                          allows you to paint over an
  15268.                                          already painted area. When you
  15269.  Part                                    Description
  15270.  ────────────────────────────────────────────────────────────────────────────
  15271.                                         already painted area. When you
  15272.                                          omit  background$ the default is
  15273.                                          CHR$ (0).
  15274.  
  15275.  
  15276.  
  15277.  
  15278.  
  15279.  Painting is complete when a line is painted without changing the color of
  15280.  any pixel; in other words, when the entire line is equal to the paint color.
  15281.  The  PAINT statement permits coordinates outside the screen or viewport.
  15282.  
  15283.  "Tiling" is the design of a  PAINT pattern represented in string form. The
  15284.  tile string is eight bits wide and up to 64 bytes long. Each byte masks
  15285.  eight bits along the x axis when plotting points. The syntax for
  15286.  constructing the tile mask is
  15287.  
  15288.  A$ =  CHR$( arg1)+ CHR$( arg2)+...+ CHR$( argn)  PAINT ( x, y), A$
  15289.  
  15290.  The arguments to  CHR$ are numbers between 0 and 255, represented in binary
  15291.  form across the x axis of the tile. There can be up to 64 of these  CHR$
  15292.  elements; each generates an image not of the assigned character, but of the
  15293.  bit arrangement of the code for that character. For example, the decimal
  15294.  number 85 is binary 01010101; the graphic image line on a black-and-white
  15295.  screen generated by CHR$(85) is an eight-pixel line, with even-numbered
  15296.  points white and odd-numbered points black. That is, each bit equal to 1
  15297.  turns the associated pixel on and each bit equal to 0 turns the associated
  15298.  bit off in a black-and-white system. The ASCII character CHR$(85), which is
  15299.  U, is not displayed in this case.
  15300.  
  15301.  
  15302.  When supplied,  background$ defines the "background tile slice" to skip when
  15303.  checking for boundary termination. You cannot specify more than two
  15304.  consecutive bytes that match the tile string in the background tile slice.
  15305.  If you specify more than two consecutive bytes, BASIC generates an error
  15306.  message Illegal function call.
  15307.  
  15308.  Tiling also can be done to produce various patterns of different colors. See
  15309.  Chapter 5, "Graphics" in the  Programmer's Guide for a complete description
  15310.  of how to do tiling.
  15311.  
  15312.  
  15313.  See Also
  15314.  
  15315.   CHR$,  CIRCLE,  DRAW,  LINE,  SCREEN Statement
  15316.  
  15317.  
  15318.  Example
  15319.  
  15320.  The following example uses  PAINT to create a magenta fish with a cyan tail:
  15321.  
  15322.  CONST PI = 3.1415926536
  15323.  CLS' Clear screen.
  15324.  SCREEN 1
  15325.  
  15326.  CIRCLE (190, 100), 100, 1, , , .3' Outline fish body in cyan.
  15327.  CIRCLE (265, 92), 5, 1, , , .7' Outline fish eye in cyan.
  15328.  PAINT (190, 100), 2, 1' Fill in fish body with magenta.
  15329.  
  15330.  LINE (40, 120)-STEP (0, -40), 2 ' Outline tail in magenta.
  15331.  LINE -STEP (60, 20), 2
  15332.  LINE -STEP (-60, 20), 2
  15333.  PAINT (50, 100), 1, 2' Paint tail cyan.
  15334.  
  15335.  CIRCLE (250,100),30,0,PI*3/4,PI* 5/4,1.5' Draw gills in black.
  15336.  FOR Y = 90 TO 110 STEP 4
  15337.     LINE (40, Y)-(52, Y), 0' Draw comb in tail.
  15338.  NEXT
  15339.  
  15340.  PALETTE, PALETTE USING Statements
  15341.  ────────────────────────────────────────────────────────────────────────────
  15342.  
  15343.  
  15344.  Action
  15345.  
  15346.  Change one or more colors in the palette.
  15347.  
  15348.  
  15349.  Syntax
  15350.  
  15351.  
  15352.   PALETTE  attribute%,  color&
  15353.  
  15354.   PALETTE USING  array-name ( array-index)
  15355.  
  15356.  Remarks
  15357.  
  15358.  
  15359.  The  PALETTE and  PALETTE USING statements use the following arguments:
  15360.  
  15361. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  15362.  Argument                                Description
  15363.  ────────────────────────────────────────────────────────────────────────────
  15364.   attribute%                             The palette attribute to be
  15365.                                          changed.
  15366.  
  15367.   color&                                 The display color number to be
  15368.                                          assigned to the attribute. The
  15369.                                          color& value must be a
  15370.                                          long-integer expression for the
  15371.                                          IBM Video Graphics Array adapter
  15372.                                          (VGA) and IBM Multicolor Graphics
  15373.                                          Array adapter (MCGA) in screen
  15374.  Argument                                Description
  15375.  ────────────────────────────────────────────────────────────────────────────
  15376.                                         Array adapter (MCGA) in screen
  15377.                                          modes 11 to 13. Integer or
  15378.                                          long-integer expressions can be
  15379.                                          used with the IBM Enhanced
  15380.                                          Graphics Adapter (EGA).
  15381.  
  15382.   array-name                             An array that contains more than
  15383.                                          one display color. It must be a
  15384.                                          long-integer array for VGA and
  15385.                                          MCGA adapters in screen modes 11
  15386.                                          to 13. Otherwise, it can be either
  15387.                                          an integer or long-integer array.
  15388.  
  15389.   array-index                            The index of the first array
  15390.                                          element to use in setting the
  15391.                                          palette.
  15392.  
  15393.                                          The arguments  array-name and
  15394.                                          array-index are used to change
  15395.  Argument                                Description
  15396.  ────────────────────────────────────────────────────────────────────────────
  15397.                                         array-index are used to change
  15398.                                          more than one palette assignment
  15399.                                          with a single  PALETTE  USING
  15400.                                          statement.
  15401.  
  15402.  
  15403.  
  15404.  
  15405.  
  15406.  The  PALETTE statement works  only on systems equipped with the EGA, VGA, or
  15407.  MCGA adapters. The  PALETTE statement is not supported in screen modes 3 or
  15408.  4.
  15409.  
  15410.  The  PALETTE statement provides a way of mapping display colors (the actual
  15411.  binary values used by the adapter) to color attributes (a smaller set of
  15412.  values).
  15413.  
  15414.  When a program enters a screen mode, the attributes are set to a series of
  15415.  default color values. (See the  SCREEN statement for a list of the default
  15416.  colors.) In the EGA, VGA, and MCGA adapters, the default values have been
  15417.  selected so the display shows the same colors, even though the EGA uses
  15418.  different color values.
  15419.  
  15420.  With the  PALETTE statement you can assign different colors to the
  15421.  attributes. Changing the display color assigned to an attribute immediately
  15422.  changes those colors currently displayed on the screen associated with that
  15423.  attribute.
  15424.  
  15425.  For example, assume that the current palette contains colors 0, 1, 2, and 3
  15426.  in the four attributes numbered 0, 1, 2, and 3. The following  DRAW
  15427.  statement selects attribute 3, and draws a line of 100 pixels using the
  15428.  display color associated with attribute 3, in this case also 3:
  15429.  
  15430.  DRAW "C3L100"
  15431.  
  15432.  If the following statement is executed, the color associated with attribute
  15433.  3 is changed to color 2:
  15434.  
  15435.  PALETTE 3,2
  15436.  
  15437.  All text or graphics currently on the screen displayed using attribute 3,
  15438.  including the line that is 100 pixels long, are instantaneously changed to
  15439.  color 2. Text or graphics subsequently dis-played with attribute 3 also are
  15440.  displayed in color 2. The new palette of colors contains 0, 1, 2, and 2. A
  15441.  PALETTE statement with no arguments sets the palette back to the default
  15442.  color values.
  15443.  
  15444.  With  PALETTE  USING, all entries in the palette can be modified in one
  15445.  statement. Each attribute in the palette is assigned a corresponding color
  15446.  from the array.
  15447.  
  15448.  The dimensions for the array must be large enough to set all the palette
  15449.  entries after  array-index. For example, if you are assigning colors to a
  15450.  palette with 16 attributes and the  array-index argument is 5 (the first
  15451.  array element to use in resetting the palette), then the dimensions for the
  15452.  array must be declared to hold at least 20 elements (because the number of
  15453.  elements from 5 to 20, inclusive, is 16):
  15454.  
  15455.  DIM PAL%(20)
  15456.  .
  15457.   .
  15458.   .
  15459.  PALETTE USING PAL%(5)
  15460.  Note that a  color& argument of -1 in the array leaves the attribute
  15461.  unchanged in the palette. All other negative numbers are invalid values for
  15462.  color.
  15463.  
  15464.  Attribute 0 is always the screen background color. Under a common initial
  15465.  palette setting, points colored with the attribute 0 appear black on the
  15466.  display screen. Using the  PALETTE statement, you could, for example, change
  15467.  the mapping of attribute 0 from black to white. You can also use the  COLOR
  15468.  statement to change the screen background color in modes 1 and 7 through 10.
  15469.  
  15470.  The 64 EGA colors are derived from four levels each of red, green, and blue.
  15471.  For example, black is composed of red, green, and blue levels of (0,0,0),
  15472.  bright white is (3,3,3), dark gray is (1,1,1), and so on. The best way to
  15473.  see the Microsoft BASIC color code (0-63) associated with each combination
  15474.  of red, green, and blue levels is to run the following program:
  15475.  
  15476.  
  15477.  ' Display the EGA color codes 1 through 63
  15478.  ' using color code 0 (black) as background.
  15479.  DEFINT A-Z
  15480.  SCREEN 9                      ' Establish EGA screen mode.
  15481.  ' Display a set of nine color bars.
  15482.  FOR ColorCode% = 1 TO 9
  15483.  LINE (((ColorCode% * 64) - 24), 40)-STEP(60, 140), ColorCode%, BF
  15484.  NEXT ColorCode%
  15485.  ' Display seven sets of nine color bars.
  15486.  ' A new set is displayed each time user presses a key.
  15487.  FOR Set% = 0 TO 6
  15488.  FOR ColorBar% = 1 TO 9
  15489.  DisplayCode% = (Set% * 9) + ColorBar%
  15490.  LOCATE 15, (ColorBar% * 8)
  15491.  PRINT DisplayCode%
  15492.  PALETTE ColorBar%, DisplayCode%
  15493.  NEXT ColorBar%
  15494.  SLEEP
  15495.  NEXT Set%
  15496.  END
  15497.  The following table lists attribute and color ranges for various adapter
  15498.  types and screen modes. See the  SCREEN statement for the list of colors
  15499.  available for various screen modes, monitor, and graphics-adapter
  15500.  combinations.
  15501. ╓┌───────────┌───────────┌───────────┌───────────┌───────────┌───────────────╖
  15502.  Screen      Monitor     Adapter     Attribute   Color       PALETTE
  15503.  mode        attached                range       range       supported
  15504.  ────────────────────────────────────────────────────────────────────────────
  15505.  0           Monochrome  MDPA        0 - 15                  No
  15506.  
  15507.              Monochrome  EGA         0 - 15      0 - 2       Yes
  15508.  
  15509.              Color       CGA         0 - 15                  No
  15510.  
  15511.              Color/Enha  EGA         0 - 15      0 - 15 / 0  Yes
  15512.              nced1                               - 63
  15513.  
  15514.              Analog      VGA         0 - 15      0 - 63      Yes
  15515.  
  15516.              Color/Anal  MCGA        0 - 15      0 - 63      No
  15517.              og
  15518.  
  15519.  1           Color       CGA         0 - 3       0 - 152     No
  15520.  
  15521.  Screen      Monitor     Adapter     Attribute   Color       PALETTE
  15522.  mode        attached                range       range       supported
  15523.  ────────────────────────────────────────────────────────────────────────────
  15524. 
  15525.              Color/Enha  EGA         0 - 3       0 - 15      Yes
  15526.              nced1
  15527.  
  15528.              Analog      VGA         0 - 3       0 - 15      Yes
  15529.  
  15530.              Color/Anal  MCGA        0 - 1       0 - 15      No
  15531.              og
  15532.  
  15533.  2           Color       CGA         0 - 1                   No
  15534.  
  15535.              Color/Enha  EGA         0 - 1       0 - 15      Yes
  15536.              nced1
  15537.  
  15538.              Analog      VGA         0 - 1       0 - 15      Yes
  15539.  
  15540.              Color/Anal  MCGA        0 - 1       0 - 15      No
  15541.              og
  15542.  Screen      Monitor     Adapter     Attribute   Color       PALETTE
  15543.  mode        attached                range       range       supported
  15544.  ────────────────────────────────────────────────────────────────────────────
  15545.             og
  15546.  
  15547.  3           Monochrome  HGC         0 - 1                   No
  15548.  
  15549.  4           Color/Enha  OCGA/       0 - 1       0 - 153     No
  15550.              nced        OEGA/ OVGA
  15551.  
  15552.  7           Color/Enha  EGA         0 - 15      0 - 15      Yes
  15553.              nced1
  15554.  
  15555.                          VGA         0 - 15      0 - 15      Yes
  15556.  
  15557.  8           Color/Enha  EGA         0 - 15      0 - 15      Yes
  15558.              nced1
  15559.  
  15560.                          VGA         0 - 15      0 - 15      Yes
  15561.  
  15562.  9           Enhanced1   EGA4        0 - 3       0 - 63      Yes
  15563.  Screen      Monitor     Adapter     Attribute   Color       PALETTE
  15564.  mode        attached                range       range       supported
  15565.  ────────────────────────────────────────────────────────────────────────────
  15566. 9           Enhanced1   EGA4        0 - 3       0 - 63      Yes
  15567.  
  15568.              Enhanced1   EGA5        0 - 15      0 - 63      Yes
  15569.  
  15570.              Analog      VGA         0 - 16      0 - 63      Yes
  15571.  
  15572.  10          Monochrome  EGA         0 - 3       0 - 8       Yes
  15573.  
  15574.              Analog      VGA         0 - 3       0 - 8       Yes
  15575.  
  15576.  11          Analog      VGA         0 - 1       0 -         Yes
  15577.                                                  262,1436
  15578.  
  15579.              Analog      MCGA        0 - 1       0 -         Yes
  15580.                                                  262,1436
  15581.  
  15582.  12          Analog      VGA         0 - 15      0 -         Yes
  15583.                                                  262,1436
  15584.  Screen      Monitor     Adapter     Attribute   Color       PALETTE
  15585.  mode        attached                range       range       supported
  15586.  ────────────────────────────────────────────────────────────────────────────
  15587.                                                 262,1436
  15588.  
  15589.  13          Analog      VGA         0 - 255     0 -         Yes
  15590.                                                  262,1436
  15591.  
  15592.              Analog      MCGA        0 - 255     0 -         Yes
  15593.                                                  262,1436
  15594.  
  15595.  
  15596.  
  15597.    1  IBM Enhanced Color Display.
  15598.    2  Color range available for attribute 0 only.
  15599.    3  Color range available for attribute 1 only.
  15600.    4  With 64K of EGA memory.
  15601.    5  With more than 64K of EGA memory.
  15602.    6  Range of display colors is actually from 0 to 4,144,959, but only
  15603.       262,144 of these can be displayed.
  15604.  
  15605.  
  15606.  To calculate a VGA color value, select the intensities of red, green, and
  15607.  blue. The intensity of a color is a number from 0 (low intensity) to 63
  15608.  (high intensity). Then use the following formula to calculate the actual
  15609.  color number:
  15610.  
  15611.  color number = 65,536 * blue + 256 * green + red
  15612.  
  15613.  This formula yields integer values from 0 to 4,144,959, but because there
  15614.  are gaps in the range of color numbers, you should use the formula rather
  15615.  than just select a number.
  15616.  
  15617.  When used with the IBM Analog Monochrome Monitor, the VGA color values are
  15618.  converted to a gray-scale value by taking a weighted sum of the red, blue,
  15619.  and green intensities:
  15620.  
  15621.  gray value = 11% blue + 59% green + 30% red
  15622.  
  15623.  For example, if the blue, green, and red intensities are 45, 20, and 20, the
  15624.  gray intensity value calculation would be gray value = (.11 * 45) + (.59 *
  15625.  20) + (.30 * 20) = 22. The fractional part of the result is dropped.
  15626.  
  15627.  
  15628.  See Also
  15629.  
  15630.   COLOR,  SCREEN Statement
  15631.  
  15632.  
  15633.  Example
  15634.  
  15635.  The following example illustrates the use of the  PALETTE and  PALETTE USING
  15636.  statements:
  15637.  
  15638.  DEFINT A-Z
  15639.  DIM SHARED PaletteArray(15)
  15640.  CONST ASPECT = 1 / 3
  15641.  SCREEN 8' 640 x 200, 16 color resolution.
  15642.  ' Initialize PaletteArray.
  15643.  FOR I = 0 TO 15
  15644.      PaletteArray(I) = I
  15645.  NEXT I
  15646.  ' Draw and paint concentric ellipses.
  15647.  FOR ColorVal = 15 TO 1 STEP -1
  15648.      Radius = 20 * ColorVal
  15649.      CIRCLE (320, 100), Radius, ColorVal, , , ASPECT
  15650.      PAINT (320, 100), ColorVal
  15651.  NEXT
  15652.  ' Shift the palette until a key is pressed.
  15653.  DO
  15654.      FOR I = 1 TO 15
  15655.          PaletteArray(I) = (PaletteArray(I) MOD 15) + 1
  15656.      NEXT I
  15657.      PALETTE USING PaletteArray(0)
  15658.      ' Map the black background to a random color.
  15659.      PALETTE 0, PaletteArray(INT(RND * 15))
  15660.  LOOP WHILE INKEY$ = ""
  15661.  
  15662.  PCOPY Statement
  15663.  ────────────────────────────────────────────────────────────────────────────
  15664.  
  15665.  
  15666.  Action
  15667.  
  15668.  Copies one video memory page to another.
  15669.  
  15670.  
  15671.  Syntax
  15672.  
  15673.  
  15674.   PCOPY  sourcepage%,  destinationpage%
  15675.  
  15676.  Remarks
  15677.  
  15678.  
  15679.  The  PCOPY statement uses the following arguments:
  15680.  
  15681. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  15682.  Argument                                Description
  15683.  ────────────────────────────────────────────────────────────────────────────
  15684.   sourcepage%                            A numeric expression with an
  15685.                                          integer value between 0 and  n
  15686.                                          that identifies a video memory
  15687.                                          page to be copied.
  15688.  
  15689.  Argument                                Description
  15690.  ────────────────────────────────────────────────────────────────────────────
  15691. 
  15692.   destinationpage%                       A numeric expression with an
  15693.                                          integer value between 0 and  n
  15694.                                          that identifies the video memory
  15695.                                          page to be copied to.
  15696.  
  15697.  
  15698.  
  15699.  The value of  n is determined by the current size of video memory and the
  15700.  current screen mode. The number of video memory pages available depends on
  15701.  the current screen mode, the graphics adapter, and how much screen memory is
  15702.  available with the adapter.
  15703.  
  15704.  
  15705.  Note
  15706.  
  15707.  Multiple video pages are not available in OS/2 protected mode, so the  PCOPY
  15708.  statement has no effect.
  15709.  
  15710.  See the  SCREEN statement for more information about the number of pages
  15711.  available in different modes
  15712.  
  15713.  
  15714.  See Also
  15715.  
  15716.   CLEAR,  SCREEN Statement
  15717.  
  15718.  
  15719.  Example
  15720.  
  15721.  See the  SCREEN statement programming example, which uses the  PCOPY
  15722.  statement.
  15723.  
  15724.  PEEK Function
  15725.  ────────────────────────────────────────────────────────────────────────────
  15726.  
  15727.  
  15728.  Action
  15729.  
  15730.  Returns byte value stored at a specified memory location. Complements the
  15731.  POKE statement.
  15732.  
  15733.  
  15734.  Syntax
  15735.  
  15736.  
  15737.   PEEK( address)
  15738.  
  15739.  Remarks
  15740.  
  15741.  
  15742.  The returned value is an integer between 0 and 255, inclusive. The argument
  15743.  address is a value between 0 and 65,535, inclusive.  The argument  address
  15744.  is treated as the offset from the current default segment (as set by the
  15745.  DEF SEG statement).
  15746.  
  15747.  If  address is a single- or double-precision floating-point value, or a long
  15748.  integer, it is converted to a 2-byte integer.
  15749.  
  15750.  When using  PEEK to return a byte from a far-string array, use the  SSEG and
  15751.   SADD functions to obtain the current segment and offset. For example:
  15752.  
  15753.  DEF SEG = SSEG(a$) ' Set current segment address to address of a$.
  15754.  
  15755.  StringOffset = SADD(a$) ' Determine string's location within segment.
  15756.  
  15757.  PEEK(StringOffset)' Return the byte stored at this location.
  15758.  
  15759.  Direct string manipulation with  PEEK should be used cautiously, because
  15760.  BASIC moves string locations during run time.
  15761.  
  15762.  
  15763.  PEEK and Expanded Memory Arrays
  15764.  
  15765.  Do not use  PEEK to return a byte from an expanded memory array. If you
  15766.  start QBX with the /Ea switch, any of these arrays may be stored in expanded
  15767.  memory:
  15768.  
  15769.    ■   Numeric arrays less than 16K in size.
  15770.  
  15771.    ■   Fixed-length string arrays less than16K in size.
  15772.  
  15773.    ■   User-defined-type arrays less than 16K in size.
  15774.  
  15775.  
  15776.  
  15777.  
  15778.  If you want to use  PEEK to return a byte from an array, first start QBX
  15779.  without the /Ea switch. (Without the /Ea switch, no arrays are stored in
  15780.  expanded memory.)
  15781.  
  15782.  For more information on using expanded memory, see "Memory Management for
  15783.  QBX" in  Getting Started.
  15784.  
  15785.  
  15786.  Note
  15787.  
  15788.  When programming with OS/2 protected mode, note that any address referred to
  15789.  by  PEEK must be readable. If  PEEK refers to an address for which your
  15790.  process does not have read permission, the operating system may generate a
  15791.  protection exception, or BASIC may generate the error message Permission
  15792.  denied.
  15793.  
  15794.  
  15795.  See Also
  15796.  
  15797.   DEF SEG;  POKE;  SADD;  SSEG;  SSEGADD;  VARPTR,  VARSEG;  VARPTR$
  15798.  
  15799.  
  15800.  Example
  15801.  
  15802.  See the  DEF SEG statement programming example, which uses the  PEEK
  15803.  statement.
  15804.  
  15805.  
  15806.  PEN Function
  15807.  ────────────────────────────────────────────────────────────────────────────
  15808.  
  15809.  
  15810.  Action
  15811.  
  15812.  Returns lightpen status.
  15813.  
  15814.  
  15815.  Syntax
  15816.  
  15817.  
  15818.   PEN( n%)
  15819.  
  15820.  Remarks
  15821.  
  15822.  
  15823.  The argument  n% is an integer value between 0 and 9, inclusive, that
  15824.  specifies what information is to be returned about the status of the
  15825.  lightpen.
  15826.  
  15827.  
  15828.  Note
  15829.  
  15830.  The  PEN function does not work when the mouse driver is enabled because the
  15831.  mouse driver uses the  PEN function's BIOS calls. Use mouse function 14 to
  15832.  disable the driver's lightpen emulation. Mouse function 13 turns emulation
  15833.  back on. See your mouse manual for more information.
  15834.  
  15835.  The following list describes the values for  n% and the corresponding values
  15836.  returned by  PEN:
  15837.  
  15838. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  15839.  Argument                                Value returned
  15840.  ────────────────────────────────────────────────────────────────────────────
  15841.  0                                       Whether the pen was down since the
  15842.                                          last function call  (-1 if yes, 0
  15843.                                          if no).
  15844.  
  15845.  1                                       The x coordinate of the last pen
  15846.                                          press.
  15847.  
  15848.  2                                       The y coordinate of the last pen
  15849.                                          press.
  15850.  
  15851.  3                                       The current pen switch status (-1
  15852.                                          if down, 0 if up).
  15853.  
  15854.  4                                       The x coordinate where the pen
  15855.                                          last left the screen.
  15856.  
  15857.  Argument                                Value returned
  15858.  ────────────────────────────────────────────────────────────────────────────
  15859. 
  15860.  5                                       The y coordinate where the pen
  15861.                                          last left the screen.
  15862.  
  15863.  6                                       The character row of the last pen
  15864.                                          press.
  15865.  
  15866.  7                                       The character column of the last
  15867.                                          pen press.
  15868.  
  15869.  8                                       The character row where the pen
  15870.                                          last left the screen.
  15871.  
  15872.  9                                       The character column where the pen
  15873.                                          last left the screen.-
  15874.  
  15875.  
  15876.  
  15877.  The light-pen coordinate system is identical to the current graphics screen
  15878.  mode, without viewport or window considerations.
  15879.  
  15880.  
  15881.  Note
  15882.  
  15883.  The  PEN function is not available in OS/2 protected mode.
  15884.  
  15885.  
  15886.  See Also
  15887.  
  15888.   PEN Statements
  15889.  
  15890.  
  15891.  Example
  15892.  
  15893.  See the  ON PEN statement programming example, which uses the  PEN function.
  15894.  
  15895.  
  15896.  PEN Statements
  15897.  ────────────────────────────────────────────────────────────────────────────
  15898.  
  15899.  
  15900.  Action
  15901.  
  15902.  Enable, disable, or suspend lightpen-event trapping.
  15903.  
  15904.  
  15905.  Syntax
  15906.  
  15907.  
  15908.   PEN ON
  15909.  
  15910.   PEN OFF
  15911.  
  15912.   PEN STOP
  15913.  
  15914.  Remarks
  15915.  
  15916.  
  15917.  The  PEN ON statement enables lightpen-event trapping. A lightpen event
  15918.  occurs whenever the lightpen is activated by pressing the tip to the screen
  15919.  or pressing the touch ring. If a lightpen event occurs after a  PEN  ON
  15920.  statement, the routine specified in the  ON  PEN statement is executed.
  15921.  
  15922.  The  PEN OFF statement disables lightpen-event trapping. No trapping takes
  15923.  place until a  PEN  ON statement is executed. Events occurring while
  15924.  trapping is off are ignored.
  15925.  
  15926.  The  PEN  STOP statement suspends lightpen-event trapping. No trapping takes
  15927.  place until a  PEN  ON statement is executed. Events occurring while
  15928.  trapping is suspended are remembered and processed when the next  PEN  ON
  15929.  statement is executed. However, remembered events are lost if  PEN  OFF is
  15930.  executed.
  15931.  
  15932.  When a lightpen-event trap occurs (that is, the  GOSUB is performed), an
  15933.  automatic  PEN STOP is executed so that recursive traps cannot take place.
  15934.  The  RETURN statement from the trapping routine automatically performs a
  15935.  PEN ON statement unless an explicit  PEN OFF was performed inside the
  15936.  routine.
  15937.  
  15938.  A  PEN ON statement must be executed before you use the  PEN function. If a
  15939.  Pen function is executed when the lightpen is off, BASIC generates the error
  15940.  message Illegal function call.
  15941.  
  15942.  
  15943.  Note
  15944.  
  15945.  The lightpen requires an IBM Color Graphics Adapter.
  15946.  
  15947.  The  PEN statements are not available for OS/2 protected mode.
  15948.  
  15949.  For more information, see Chapter 9, "Event Handling" in the  Programmer's
  15950.  Guide.
  15951.  
  15952.  
  15953.  See Also
  15954.  
  15955.   ON  event
  15956.  
  15957.  
  15958.  Example
  15959.  
  15960.  
  15961.  The following example uses the  PEN statements and the  PEN function to
  15962.  enable and display current lightpen status (up or down) and position (x and
  15963.  y coordinates). The  ON PEN statement passes control to the PenReport
  15964.  routine when a lightpen event occurs.
  15965.  
  15966.  ' Note: Do not run this program with your mouse driver enabled.
  15967.  CLS                ' Clear screen.
  15968.  COLOR 0, 7         ' Set black on white.
  15969.  CLS                ' Clear screen.
  15970.  PEN ON             ' Enable lightpen
  15971.  ON PEN GOSUB PenReport
  15972.  DO
  15973.      LOCATE 23, 12
  15974.      PRINT "Press the lightpen against the screen to see a report."
  15975.      LOCATE 24, 17
  15976.      PRINT "  Press the Spacebar to exit the program.     ";
  15977.  LOOP UNTIL INKEY$ = " "
  15978.  PEN OFF            ' Disable lightpen.
  15979.  COLOR 7, 0         ' Set back to black on white.
  15980.  CLS                ' Clean up the screen.
  15981.  END
  15982.  
  15983.  PenReport:
  15984.      DO
  15985.          P = PEN(3)
  15986.          ' Report lightpen status and get X and Y position.
  15987.          LOCATE 10, 27
  15988.          PRINT "A Pen event has occurred."
  15989.          LOCATE 24, 17
  15990.          PRINT "Press ANY key to exit the lightpen report.";
  15991.          LOCATE 12, 30
  15992.          PRINT "lightpen is ";
  15993.          IF P THEN
  15994.              PRINT "Down"
  15995.              X = PEN(4): Y = PEN(5)
  15996.          ELSE
  15997.              PRINT "Up  "
  15998.              X = 0: Y = 0
  15999.          END IF
  16000.          ' Report the X and Y position.
  16001.          LOCATE 14, 22
  16002.          PRINT "X Position ="; X; "   "
  16003.          LOCATE 14, 40
  16004.          PRINT "Y Position ="; Y; "   "
  16005.      LOOP WHILE INKEY$ = ""
  16006.      RETURN
  16007.  
  16008.  PLAY Function
  16009.  ────────────────────────────────────────────────────────────────────────────
  16010.  
  16011.  
  16012.  Action
  16013.  
  16014.  Returns the number of notes currently in the background-music queue.
  16015.  
  16016.  
  16017.  Syntax
  16018.  
  16019.  
  16020.   PLAY ( n)
  16021.  
  16022.  Remarks
  16023.  
  16024.  
  16025.  The argument  n is a dummy argument and can be any numeric value.
  16026.  
  16027.   PLAY( n) will return 0 when music is running in the foreground.
  16028.  
  16029.  The  PLAY function is not available for OS/2 protected mode.
  16030.  
  16031.  
  16032.  See Also
  16033.  
  16034.   ON  event,  PLAY Statements (Event Trapping),  PLAY Statement (Music)
  16035.  
  16036.  
  16037.  Example
  16038.  
  16039.  The following example plays continuous music by calling an event-handling
  16040.  routine when the background music buffer goes from three to two notes:
  16041.  
  16042.  CLS
  16043.  ' Call routine Replay when the music buffer goes
  16044.   ' from 3 to 2 notes.
  16045.  ON PLAY(3) GOSUB Replay
  16046.  ' Turn on event trapping for PLAY.
  16047.  PLAY ON
  16048.  ' Define a string containing the melody.
  16049.  FElise$ = "o3 L8 E D+ E D+ E o2 B o3 D C L2 o2 A"
  16050.  PLAY "MB X" + VARPTR$(FElise$)
  16051.  ' Suspend event trapping until next PLAY ON but remember
  16052.   ' events that occur while event trapping is disabled.
  16053.  PLAY STOP
  16054.  ' Introduce a variable-length delay.
  16055.  LOCATE 23, 1: PRINT "Press any key to continue."
  16056.  DO
  16057.  LOOP WHILE INKEY$ = ""
  16058.  
  16059.  ' Re-enable play-event trapping, remembering that a play event
  16060.  
  16061.   ' has occurred.
  16062.  PLAY ON
  16063.  LOCATE 23, 1: PRINT "Press any key to stop.    "
  16064.  ' Loop until a key is pressed.
  16065.  DO
  16066.      GOSUB BackGround
  16067.  LOOP WHILE INKEY$ = ""
  16068.  ' Disable play-event processing.
  16069.  PLAY OFF
  16070.  ' Count down to 0 notes in the queue.
  16071.  DO
  16072.      GOSUB BackGround
  16073.  LOOP UNTIL NoteCount = 0
  16074.  END
  16075.  
  16076.  ' Play event-handling routine.
  16077.  Replay:
  16078.      ' Increment and print a counter each time.
  16079.      Count% = Count% + 1
  16080.      LOCATE 3, 1: PRINT "Replay routine called"; Count%; "time(s)";
  16081.      ' Play it again to fill the buffer.
  16082.      PLAY "MB X" + VARPTR$(FElise$)
  16083.  RETURN
  16084.  
  16085.  ' Background music queue reporting routine.
  16086.  BackGround:
  16087.      ' Get a note count.
  16088.      NoteCount = PLAY(0)
  16089.      LOCATE 1, 1
  16090.      PRINT "Background queue notes remaining --> "; NoteCount
  16091.      ' Loop until Notecount changes or equals 0.
  16092.      DO
  16093.      LOOP UNTIL NoteCount <> PLAY(0) OR NoteCount = 0
  16094.  RETURN
  16095.  
  16096.  PLAY Statements (Event Trapping)
  16097.  ────────────────────────────────────────────────────────────────────────────
  16098.  
  16099.  
  16100.  Action
  16101.  
  16102.  Enable, disable, and suspend play-event trapping.
  16103.  
  16104.  
  16105.  Syntax
  16106.  
  16107.  
  16108.   PLAY ON
  16109.   PLAY OFF
  16110.   PLAY STOP
  16111.  
  16112.  Remarks
  16113.  
  16114.  
  16115.  The  PLAY  ON statement enables play-event trapping. (A play event occurs
  16116.  when the number of notes in the background music queue drops below the limit
  16117.  you set with the  ON  PLAY statement.) If a play event occurs after a  PLAY
  16118.  ON statement, the routine specified in the  ON  PLAY statement is executed.
  16119.  
  16120.  The  PLAY  OFF statement disables play-event trapping. No trapping takes
  16121.  place until a  PLAY  ON statement is executed. Events occurring while
  16122.  trapping is off are ignored.
  16123.  
  16124.   PLAY  STOP suspends play-event trapping. No trapping takes place until a
  16125.  PLAY  ON statement is executed. Events occurring while trapping is suspended
  16126.  are remembered and processed when the next  PLAY  ON statement is executed.
  16127.  However, remembered events are lost if  PLAY  OFF is executed.
  16128.  
  16129.  When a play-event trap occurs (that is, the  GOSUB is performed), an
  16130.  automatic  PLAY STOP is executed so that recursive traps cannot take place.
  16131.  The  RETURN operation from the trapping routine automatically executes a
  16132.  PLAY ON statement unless an explicit  PLAY OFF was performed inside the
  16133.  routine.
  16134.  
  16135.  For more information, see Chapter 9, "Event Handling" in the  Programmer's
  16136.  Guide.
  16137.  
  16138.  
  16139.  Note
  16140.  
  16141.  The  PLAY statements (event trapping) are not available for OS/2 protected
  16142.  mode.
  16143.  
  16144.  
  16145.  See Also
  16146.  
  16147.   ON  event,  PLAY Function,  PLAY Statements (Music)
  16148.  
  16149.  
  16150.  Example
  16151.  
  16152.  See the  PLAY function programming example, which uses the  PLAY ON
  16153.  statement.
  16154.  
  16155.  
  16156.  PLAY Statement (Music)
  16157.  ────────────────────────────────────────────────────────────────────────────
  16158.  
  16159.  
  16160.  Action
  16161.  
  16162.  Plays music as specified by a string.
  16163.  
  16164.  
  16165.  Syntax
  16166.  
  16167.  
  16168.   PLAY  commandstring$
  16169.  
  16170.  Remarks
  16171.  
  16172.  
  16173.  The  commandstring$ argument is a string expression that contains one or
  16174.  more music commands listed later in this entry.
  16175.  
  16176.  The  PLAY statement uses a concept similar to  DRAW in that it embeds a
  16177.  music macro language (described below) in one statement. A set of commands,
  16178.  used as part of the  PLAY statement, specifies a particular action.
  16179.  
  16180.  The  VARPTR$( variablename) form for variables must be used with  DRAW and
  16181.  PLAY (music) statements in BASIC to execute substrings that contain
  16182.  variables. BASICA supports both the  VARPTR$ syntax and the syntax
  16183.  containing just the variable name. For example, consider these BASICA
  16184.  statements:
  16185.  
  16186.  PLAY "XA$"
  16187.  PLAY "O = I"
  16188.  
  16189.  For BASIC programs, those statements should be written like this:
  16190.  
  16191.  PLAY "X" + VARPTR$(A$)
  16192.  PLAY "O=" + VARPTR$(I)
  16193.  
  16194.  The  commandstring$ music commands are described as follows:
  16195.  
  16196. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  16197.  Command                                 Action
  16198.  ────────────────────────────────────────────────────────────────────────────
  16199.  Octave command
  16200.  
  16201.  o n                                     Sets the current octave. There are
  16202.                                          seven octaves, numbered 0-6.
  16203.  
  16204.  >                                       Increases octave by 1. Octave
  16205.                                          cannot go beyond 6.
  16206.  
  16207.  <                                       Decreases octave by 1. Octave
  16208.                                          cannot drop below 0.
  16209.  
  16210.  
  16211.  
  16212.  Tone command
  16213.  
  16214.  Command                                 Action
  16215.  ────────────────────────────────────────────────────────────────────────────
  16216. 
  16217.  A - G                                   Plays a note in the range A - G.
  16218.                                          The number sign (#) or the plus
  16219.                                          sign (+) after a note specifies
  16220.                                          sharp; a minus sign (-) specifies
  16221.                                          flat.
  16222.  
  16223.  N n                                     Plays note  n. The range for n is
  16224.                                          0 - 84 (in the seven possible
  16225.                                          octaves, there are 84 notes); an
  16226.                                          n value of 0 means a rest.
  16227.  
  16228.  
  16229.  
  16230.  Duration command
  16231.  
  16232.  L  n                                    Sets the length of each note. L4
  16233.                                          is a quarter note, L1 is a whole
  16234.                                          note, etc. The range for  n is 1 -
  16235.  Command                                 Action
  16236.  ────────────────────────────────────────────────────────────────────────────
  16237.                                         note, etc. The range for  n is 1 -
  16238.                                          64. The length can also follow the
  16239.                                          note when a change of length only
  16240.                                          is desired for a particular note.
  16241.                                          For example, A16 can be equivalent
  16242.                                          to L16A.
  16243.  
  16244.  MN                                      Sets "music normal" so that each
  16245.                                          note will play 7/8 of the time
  16246.                                          determined by the length (L).
  16247.  
  16248.  ML                                      Sets "music legato" so that each
  16249.                                          note will play the full period set
  16250.                                          by length (L).
  16251.  
  16252.  MS                                      Sets "music staccato" so that each
  16253.                                          note will play 3/4 of the time
  16254.                                          determined by the length (L).
  16255.  
  16256.  Command                                 Action
  16257.  ────────────────────────────────────────────────────────────────────────────
  16258. 
  16259.  
  16260.  
  16261.  Tempo command
  16262.  
  16263.  P  n                                    Specifies a pause, ranging from 1
  16264.                                          to 64. This option corresponds to
  16265.                                          the length of each note, set with
  16266.                                          L  n.
  16267.  
  16268.  T  n                                    Sets the "tempo," or the number of
  16269.                                          L4  quarter notes in one minute.
  16270.                                          The range for  n is 32-255. The
  16271.                                          default for  n is 120.
  16272.  
  16273.                                          Because of the slow
  16274.                                          clock-interrupt rate, some notes
  16275.                                          will not play at higher tempos
  16276.                                          (L64 at T255, for example).
  16277.  Command                                 Action
  16278.  ────────────────────────────────────────────────────────────────────────────
  16279.                                         (L64 at T255, for example).
  16280.  
  16281.  
  16282.  
  16283.  Mode command
  16284.  
  16285.  MF                                      Sets music ( PLAY statement) and
  16286.                                          SOUND to run in the foreground.
  16287.                                          That is, each subsequent note or
  16288.                                          sound will not start until the
  16289.                                          previous note or sound has
  16290.                                          finished. This is the default
  16291.                                          setting.
  16292.  
  16293.  MB                                      Music ( PLAY statement) and  SOUND
  16294.                                          are set to run in the background.
  16295.                                          That is, each note or sound is
  16296.                                          placed in a buffer, allowing the
  16297.                                          BASIC program to continue
  16298.  Command                                 Action
  16299.  ────────────────────────────────────────────────────────────────────────────
  16300.                                         BASIC program to continue
  16301.                                          executing while the note or sound
  16302.                                          plays in the background. The
  16303.                                          maximum number of notes that can
  16304.                                          be played in the background at one
  16305.                                          time is 32.
  16306.  
  16307.  
  16308.  
  16309.  Suffix
  16310.  
  16311.   # or +                                 Follows a specified note and turns
  16312.                                          it into a sharp.
  16313.  
  16314.   -                                      Follows a specified note and turns
  16315.                                          it into a flat..
  16316.  
  16317.   .                                      A period after a note causes the
  16318.                                          note to play one-and-a-half times
  16319.  Command                                 Action
  16320.  ────────────────────────────────────────────────────────────────────────────
  16321.                                         note to play one-and-a-half times
  16322.                                          the length determined by L*T
  16323.                                          (length times tempo). The period
  16324.                                          has the same meaning as in a
  16325.                                          musical score. Multiple periods
  16326.                                          can appear after a note. Each
  16327.                                          period adds a length equal to
  16328.                                          one-half the length of the
  16329.                                          previous period. For example, the
  16330.                                          command A . plays 1 + 1/2, or 3/2
  16331.                                          times the length; A.. plays 1 +
  16332.                                          1/2 + 1/4, or 7/4 times the length.
  16333.                                          Periods can appear after a pause
  16334.                                          (P). In this case, the pause
  16335.                                          length is scaled in the same way
  16336.                                          notes are scaled.
  16337.  
  16338.  
  16339.  
  16340.  Command                                 Action
  16341.  ────────────────────────────────────────────────────────────────────────────
  16342. 
  16343.  Substring command
  16344.  
  16345.  "X" + VARPTR$(string)                   Executes a substring. This
  16346.                                          powerful command enables you to
  16347.                                          execute a second substring from a
  16348.                                          string. You can have one string
  16349.                                          expression execute another, which
  16350.                                          executes a third, and so on.
  16351.  
  16352.  
  16353.  
  16354.  
  16355.  Note
  16356.  
  16357.  The  PLAY statement is not available in OS/2 protected mode.
  16358.  
  16359.  
  16360.  See Also
  16361.  
  16362.   BEEP,  ON  event,  PLAY Function,  PLAY Statements (Event Trapping),  SOUND
  16363.  
  16364.  
  16365.  Example
  16366.  
  16367.  See the  PLAY function programming example, which uses the  PLAY statement.
  16368.  
  16369.  
  16370.  
  16371.  PMAP Function
  16372.  ────────────────────────────────────────────────────────────────────────────
  16373.  
  16374.  
  16375.  Action
  16376.  
  16377.  Returns the window coordinate equivalent to a specified viewport coordinate,
  16378.  or the viewport coordinate equivalent to a specified window coordinate.
  16379.  
  16380.  
  16381.  Syntax
  16382.  
  16383.  
  16384.   PMAP ( expression#,  n%)
  16385.  
  16386.  Remarks
  16387.  The argument   expression# specifies the known coordinate, either an x
  16388.  coordinate or y coordinate, in the window or in the viewport. The argument
  16389.  n% specifies the mapping function and can have one of the four following
  16390.  values:
  16391. ╓┌──────────────────────┌──────────┌─────────────────────────────────────────╖
  16392.  If expression is       n must be  Returns:
  16393.  ────────────────────────────────────────────────────────────────────────────
  16394.  Window x coordinate    0          Viewport x coordinate
  16395.  Window y coordinate    1          Viewport y coordinate
  16396.  Viewport x coordinate  2          Window x coordinate
  16397.  Viewport y coordinate  3          Window y coordinate
  16398.  
  16399.  
  16400.  The four  PMAP functions allow you to find equivalent point locations
  16401.  between the window coordinates created with the  WINDOW statement and the
  16402.  absolute screen coordinates or viewport coordinates as defined by the  VIEW
  16403.  statement.
  16404.  
  16405.  If no  VIEW statement has been executed, or the most recently executed  VIEW
  16406.  statement has no arguments, the viewport coordinates are equivalent to the
  16407.  absolute screen coordinates established by the most recently executed
  16408.  SCREEN statement.
  16409.  
  16410.  
  16411.  See Also
  16412.  
  16413.   POINT,  VIEW,  WINDOW
  16414.  
  16415.  
  16416.  Example
  16417.  
  16418.  See the  WINDOW statement programming example, which uses the  PMAP
  16419.  function.
  16420.  
  16421.  POINT Function
  16422.  ────────────────────────────────────────────────────────────────────────────
  16423.  
  16424.  
  16425.  Action
  16426.  
  16427.  Returns the current horizontal or vertical position of the graphics cursor,
  16428.  or the color of a specified pixel.
  16429.  
  16430.  
  16431.  Syntax 1
  16432.  
  16433.   POINT ( x%,y%)
  16434.  
  16435.  Syntax 2
  16436.  
  16437.   POINT ( number%)
  16438.  
  16439.  Remarks
  16440.  
  16441.  
  16442.  The coordinates  x% and  y% refer to the viewport coordinates of the pixel
  16443.  being evaluated by the  POINT function;  POINT returns the color number of
  16444.  the indicated pixel. If the specified pixel is out of range,  POINT returns
  16445.  the value -1.
  16446.  
  16447.   POINT with the argument  number% allows the user to retrieve the current
  16448.  graphics-cursor coordinates, as described in the following table:
  16449.  
  16450. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  16451.  Argument                                Value returned
  16452.  ────────────────────────────────────────────────────────────────────────────
  16453.  0                                       The current viewport x coordinate.
  16454.  
  16455.  1                                       The current viewport y coordinate.
  16456.  
  16457.  2                                       The current window x coordinate.
  16458.                                          This returns the same value as the
  16459.                                          POINT(0) function if the  WINDOW
  16460.                                          statement has not been used.
  16461.  
  16462.  3                                       The current window y coordinate.
  16463.                                          This returns the same value as the
  16464.                                          POINT(1) function if the  WINDOW
  16465.                                          statement has not been used.
  16466.  Argument                                Value returned
  16467.  ────────────────────────────────────────────────────────────────────────────
  16468.                                         statement has not been used.
  16469.  
  16470.  
  16471.  
  16472.  
  16473.  
  16474.  
  16475.  See Also
  16476.  
  16477.  Pmap, Screen Statement, VIEW, Window
  16478.  
  16479.  
  16480.  Example
  16481.  
  16482.  
  16483.  The following example redraws an ellipse drawn with the  CIRCLE statement,
  16484.  using  POINT to find the border of the ellipse by testing for a change in
  16485.  color:
  16486.  
  16487.  DEFINT X-Y
  16488.  
  16489.  INPUT "Enter angle of tilt in degrees (0 to 90): ",Ang
  16490.  
  16491.  SCREEN 1' Medium resolution screen.
  16492.  
  16493.  Ang = (3.1415926# / 180) * Ang' Convert degrees to radians.
  16494.  
  16495.  Cs = COS(Ang) : Sn = SIN(Ang)
  16496.  
  16497.  CIRCLE (45, 70), 50, 2, , , 2' Draw ellipse.
  16498.  
  16499.  PAINT (45, 70), 2 ' Paint interior of ellipse.
  16500.  
  16501.  FOR Y = 20 TO 120
  16502.  
  16503.     FOR X = 20 TO 70
  16504.  
  16505.     ' Check each point in rectangle enclosing ellipse.
  16506.  
  16507.     IF POINT(X, Y) <> 0 THEN
  16508.  
  16509.         ' If the point is in the ellipse, plot a corresponding
  16510.  
  16511.         '  point in the "tilted" ellipse.
  16512.  
  16513.         Xnew = (X * Cs - Y * Sn) + 200 : Ynew = (X * Sn + Y * Cs)
  16514.  
  16515.         PSET(Xnew, Ynew), 2
  16516.  
  16517.     END IF
  16518.  
  16519.     NEXT
  16520.  
  16521.  NEXT
  16522.  
  16523.  END
  16524.  
  16525.  POKE Statement
  16526.  ────────────────────────────────────────────────────────────────────────────
  16527.  
  16528.  
  16529.  Action
  16530.  
  16531.  Writes a byte value into a specified memory location.
  16532.  
  16533.  
  16534.  Syntax
  16535.  
  16536.  
  16537.   POKE  address,  byte%
  16538.  
  16539.  Remarks
  16540.  
  16541.  
  16542.  The  POKE statement uses the following arguments:
  16543.  
  16544. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  16545.  Argument                                Description
  16546.  ────────────────────────────────────────────────────────────────────────────
  16547.   address                                An offset into the memory segment
  16548.                                          specified by the current default
  16549.                                          segment (as set by the  DEF SEG
  16550.  Argument                                Description
  16551.  ────────────────────────────────────────────────────────────────────────────
  16552.                                         segment (as set by the  DEF SEG
  16553.                                          statement). The value of  address
  16554.                                          is between 0 and 65,535, inclusive.
  16555.  
  16556.   byte%                                  The data byte to be written into
  16557.                                          the memory location. The argument
  16558.                                          byte% is an integer value between
  16559.                                          0 and 255, inclusive. Any value
  16560.                                          for  byte% that must be
  16561.                                          represented in more than one byte
  16562.                                          (for instance, a long integer or
  16563.                                          any real number) is accepted;
  16564.                                          however, only the low order byte
  16565.                                          is used. The value of any high
  16566.                                          order bytes is ignored.
  16567.  
  16568.  
  16569.  
  16570.  
  16571.  
  16572.  If  address is a single- or double-precision floating-point value, or a long
  16573.  integer, it is converted to a 2-byte integer.
  16574.  
  16575.  The  POKE statement complements the  PEEK function.
  16576.  
  16577.  Before using  POKE to directly manipulate data stored in far memory, use the
  16578.   DEF SEG statement to set the current segment address. For example:
  16579.  
  16580.  DEF SEG = SSEG(a$)' Set current segment address to address of a$.
  16581.  
  16582.  Offset1 = SADD(a$)' Determine string's location within the segment.
  16583.  
  16584.  ' Write the byte stored in:
  16585.  
  16586.  POKE Offset1, PEEK(Offset2)
  16587.  
  16588.  
  16589.  Note
  16590.  
  16591.  
  16592.  
  16593.  BASIC moves string locations during run time. Therefore, the  DEF SEG
  16594.  statement must be executed immediately before using the  POKE statement.
  16595.  
  16596.  
  16597.  POKE and Expanded Memory Arrays
  16598.  
  16599.  Do not use  POKE to manipulate expanded memory arrays. If you start QBX with
  16600.  the /Ea switch, any of these arrays may be stored in expanded memory:
  16601.  
  16602.    ■   Numeric arrays less than 16K in size.
  16603.  
  16604.    ■   Fixed-length string arrays less than 16K in size.
  16605.  
  16606.    ■   User-defined-type arrays less than 16K in size.
  16607.  
  16608.  
  16609.  
  16610.  
  16611.  
  16612.  If you want to use  POKE to manipulate an array, first start QBX without the
  16613.  /Ea switch. (Without the /Ea switch, no arrays are stored in expanded
  16614.  memory.)
  16615.  
  16616.  
  16617.  For more information on using expanded memory, see "Memory Management for
  16618.  QBX" in  Getting Started.
  16619.  
  16620.  Any address referred to by  POKE in OS/2 protected mode must be open for
  16621.  writing. If  POKE refers to a memory address for which your process does not
  16622.  have write permission, the operating system may generate a protection
  16623.  exception, or BASIC may generate the error message Permission denied.
  16624.  
  16625.  
  16626.  Warning
  16627.  
  16628.  Use  POKE carefully. If used incorrectly, it can cause BASIC or the
  16629.  operating system to fail.
  16630.  
  16631.  
  16632.  See Also
  16633.  
  16634.   DEF SEG;  PEEK;  VARPTR,  VARSEG;  VARPTR$
  16635.  
  16636.  
  16637.  Example
  16638.  
  16639.  See the  DEF SEG statement programming example, which uses the  POKE
  16640.  statement.
  16641.  
  16642.  
  16643.  POS Function
  16644.  ────────────────────────────────────────────────────────────────────────────
  16645.  
  16646.  
  16647.  Action
  16648.  
  16649.  Returns the current horizontal position (column) of the text cursor.
  16650.  
  16651.  
  16652.  Syntax
  16653.  
  16654.  
  16655.   POS( numeric-expression)
  16656.  
  16657.  Remarks
  16658.  
  16659.  
  16660.  If the screen cursor is in the leftmost column, this function returns a
  16661.  value of 1. To return the current vertical-line position of the cursor, use
  16662.  the  CSRLIN function. The argument  numeric-expression can be any numeric
  16663.  expression; while it passes no information, it is required to maintain
  16664.  consistent BASIC function syntax.
  16665.  
  16666.  
  16667.  See Also
  16668.  
  16669.   CSRLIN,  LPOS
  16670.  
  16671.  
  16672.  Example
  16673.  
  16674.  The following example uses  POS to start a new line after every 40
  16675.  characters:
  16676.  
  16677.  CLS                       ' Clear screen.
  16678.  
  16679.  PRINT "This program starts a new line after every 40"
  16680.  
  16681.  PRINT "characters you type. Press Ctrl+C to end."
  16682.  
  16683.  PRINT
  16684.  
  16685.  DO
  16686.  
  16687.     DO WHILE POS(0) < 41   ' Stay on same line until 40 characters
  16688.  
  16689.        DO                  ' printed.
  16690.  
  16691.           Char$ = INKEY$
  16692.  
  16693.        LOOP WHILE Char$ = ""
  16694.  
  16695.        ' If input is key combination CTRL-C then end; otherwise,
  16696.  
  16697.        ' print the character.
  16698.  
  16699.        IF ASC(Char$) = 3 THEN END ELSE PRINT Char$;
  16700.  
  16701.     LOOP
  16702.  
  16703.     PRINT                  ' Print a new line.
  16704.  
  16705.  LOOP
  16706.  
  16707.  PRESET Statement
  16708.  ────────────────────────────────────────────────────────────────────────────
  16709.  
  16710.  
  16711.  Action
  16712.  
  16713.  Draws a specified point on the screen.
  16714.  
  16715.  
  16716.  Syntax
  16717.  
  16718.  
  16719.   PRESET  STEP( x%,  y%) ,  color&
  16720.  
  16721.  Remarks
  16722.  
  16723.  
  16724.  The following list describes the parts of the  PRESET statement:
  16725.  
  16726. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  16727.  Part                                    Description
  16728.  ────────────────────────────────────────────────────────────────────────────
  16729.   STEP                                   Indicates that  x% and  yc% are
  16730.                                          relative, not absolute. The
  16731.                                          coordinates are treated as
  16732.                                          distances from the most recent
  16733.                                          graphics cursor location, not
  16734.                                          distances from the (0,0) screen
  16735.                                          coordinate.
  16736.  
  16737.                                          For example, if the most recent
  16738.                                          graphics cursor location  were
  16739.  Part                                    Description
  16740.  ────────────────────────────────────────────────────────────────────────────
  16741.                                         graphics cursor location  were
  16742.                                          (10,10), PRESET STEP (10,5) would
  16743.                                          draw a point  at (20,15).
  16744.  
  16745.   x%                                     The x coordinate of the pixel that
  16746.                                          is to be set.
  16747.  
  16748.   y%                                     The y coordinate of the pixel that
  16749.                                          is to be set.
  16750.  
  16751.   color&                                 The color attribute for the
  16752.                                          specified pixel.
  16753.  
  16754.  
  16755.  
  16756.  The valid range of screen coordinate values and color values depends on the
  16757.  screen mode established by the most recently executed  SCREEN statement. If
  16758.  a coordinate is outside the current viewport, no action is taken, nor is an
  16759.  error message generated.
  16760.  
  16761.  If you use  PRESET without  color&, the background color is selected. In
  16762.  contrast, if you use  PSET without  color&, the foreground color is
  16763.  selected. Otherwise, the two statements work exactly the same.
  16764.  
  16765.  
  16766.  See Also
  16767.  
  16768.   PSET
  16769.  
  16770.  
  16771.  Example
  16772.  
  16773.  The following example uses  PSET and  PRESET to draw a line 20 pixels long,
  16774.  then move the line across the screen from left to right:
  16775.  
  16776.  SCREEN 1 : COLOR 1,1 : CLS
  16777.  
  16778.  FOR I = 0 TO 299 STEP 3
  16779.  
  16780.  FOR J = I TO 20 + I
  16781.  
  16782.  PSET (J, 50), 2' Draw the line in new location.
  16783.  
  16784.  NEXT
  16785.  
  16786.  FOR J = I TO 20 + I
  16787.  
  16788.  PRESET (J, 50) ' Erase the line.
  16789.  
  16790.  NEXT
  16791.  
  16792.  NEXT
  16793.  
  16794.  PRINT Statement
  16795.  ────────────────────────────────────────────────────────────────────────────
  16796.  
  16797.  
  16798.  Action
  16799.  
  16800.  Outputs data to the screen.
  16801.  
  16802.  
  16803.  Syntax
  16804.  
  16805.  
  16806.   PRINT  expressionlist {;|,}
  16807.  
  16808.  Remarks
  16809.  
  16810.  
  16811.  If  expressionlist is omitted, a blank line is displayed. If  expressionlist
  16812.  is included, the values of its expressions are printed on the screen.
  16813.  
  16814.  The  PRINT statement uses the following arguments:
  16815.  
  16816. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  16817.  Argument                                Description
  16818.  ────────────────────────────────────────────────────────────────────────────
  16819.   expressionlist                         The values that are displayed on
  16820.                                          the screen. The argument
  16821.                                          expressionlist can contain numeric
  16822.                                          or string expressions. String
  16823.  Argument                                Description
  16824.  ────────────────────────────────────────────────────────────────────────────
  16825.                                         or string expressions. String
  16826.                                          literals must be enclosed in
  16827.                                          quotation marks.
  16828.  
  16829.  {;|,}                                   Determines the screen location of
  16830.                                          the text cursor for the next
  16831.                                          screen input or output statement:
  16832.                                          a semicolon means the text cursor
  16833.                                          is placed immediately after the
  16834.                                          last character displayed; a comma
  16835.                                          means the text cursor is placed at
  16836.                                          the start of the next print zone.
  16837.  
  16838.  
  16839.  
  16840.  
  16841.  
  16842.  The  PRINT statement supports only elementary BASIC data types (integers,
  16843.  long integers, single-precision real numbers, double-precision real numbers,
  16844.  currency, and strings). To print information from a record, use individual
  16845.  record-element names in the  PRINT statement, as in the following code
  16846.  fragment:
  16847.  
  16848.  TYPE MyType
  16849.  
  16850.  Word AS STRING * 20
  16851.  
  16852.  Count AS LONG
  16853.  
  16854.  END TYPE
  16855.  
  16856.  DIM Myrec AS MyType
  16857.  
  16858.  
  16859.  
  16860.  PRINT Myrec.Word
  16861.  
  16862.  
  16863.  
  16864.  Item-Format Rules
  16865.  
  16866.  A printed number always is followed by a space. If the number is positive,
  16867.  it also is preceded by a space; if the number is negative, it is preceded by
  16868.  a minus sign (-). If a single-precision number can be expressed as seven or
  16869.  fewer digits with no loss of accuracy, then it is printed in fixed-point
  16870.  format; otherwise, floating-point format is used. For example, the number
  16871.  1.1E-6 is output displayed as .0000011, but the number 1.1E-7 is output as
  16872.  1.1E-7.
  16873.  
  16874.  If a double-precision number can be expressed with 15 or fewer digits and no
  16875.  loss of accuracy, it is printed in fixed-point format; otherwise,
  16876.  floating-point format is used. For example, the number 1.1D-14 is displayed
  16877.  as .000000000000011, but the number 1.1D-15 is output as 1.1D-15.
  16878.  
  16879.  
  16880.  Print-Line Format Rules
  16881.  
  16882.  The print line is divided into print zones of 14 spaces each. The position
  16883.  of each printed item is determined by the punctuation used to separate the
  16884.  items in  expressionlist: a comma makes the next value print at the start of
  16885.  the next zone; a semicolon makes the next value print immediately after the
  16886.  last value. Using one or more spaces or tabs between expressions has the
  16887.  same effect as using a semicolon.
  16888.  
  16889.  If a comma or a semicolon terminates the list of expressions, the next
  16890.  PRINT statement to execute prints on the same line, after spacing
  16891.  accordingly. If the expression list ends without a comma or a semicolon, a
  16892.  carriage-return-and-line-feed sequence is printed at the end of the line. If
  16893.  the printed line is wider than the screen width, BASIC goes to the next
  16894.  physical line and continues printing.
  16895.  
  16896.  
  16897.  See Also
  16898.  
  16899.   PRINT #,  PRINT  USING,  WIDTH
  16900.  
  16901.  
  16902.  Examples
  16903.  
  16904.  The following examples show the use of commas and semicolons with  PRINT.
  16905.  
  16906.  First is an example of using commas in a  PRINT statement to print each
  16907.  value at the beginning of the next print zone:
  16908.  
  16909.  CLS                ' Clear screen.
  16910.  X = 5
  16911.  PRINT X + 5, X - 5, X * (-5), X ^ 5
  16912.  END
  16913.  
  16914.  
  16915.  Output
  16916.  
  16917.  
  16918.  
  16919.  
  16920.  
  16921.  10            0            -25            3125
  16922.  
  16923.  
  16924.  In the second example, the semicolon at the end of the first  PRINT
  16925.  statement makes the first two  PRINT statements display output on the same
  16926.  line. The last  PRINT statement prints a blank line before the next prompt.
  16927.  
  16928.  
  16929.  CLS                ' Clear screen.
  16930.  
  16931.  DO
  16932.  
  16933.     INPUT "Input X (type 0 to quit): ", X
  16934.  
  16935.     IF X = 0 THEN
  16936.  
  16937.        EXIT DO
  16938.  
  16939.     ELSE
  16940.  
  16941.        PRINT X; "squared is"; X ^ 2; "and";
  16942.  
  16943.        PRINT X; "cubed is"; X^3
  16944.  
  16945.        PRINT
  16946.  
  16947.     END IF
  16948.  
  16949.  LOOP
  16950.  
  16951.  
  16952.  
  16953.  Output
  16954.  
  16955.  
  16956.  
  16957.  
  16958.  
  16959.  Input X (type 0 to quit): 9
  16960.   9 squared is 81 and 9 cubed is 729
  16961.  
  16962.  Input X (type 0 to quit): 21
  16963.   21 squared is 441 and 21 cubed is 9261
  16964.  
  16965.  Input X (type 0 to quit): 0
  16966.  
  16967.  
  16968.  In the third example, the semicolons in the  PRINT statement print each
  16969.  value immediately after the preceding value. Note that a space always
  16970.  follows a number and precedes a positive number.
  16971.  
  16972.  CLS                ' Clear screen.
  16973.  FOR X = 1 TO 5
  16974.    J = J + 5
  16975.    K = K + 10
  16976.    PRINT J; K;
  16977.  NEXT X
  16978.  
  16979.  
  16980.  Output
  16981.  
  16982.  
  16983.  
  16984.  
  16985.  
  16986.  5  10  10  20  15  30  20  40  25  50
  16987.  
  16988.  PRINT # Statement
  16989.  ────────────────────────────────────────────────────────────────────────────
  16990.  
  16991.  
  16992.  Action
  16993.  
  16994.  Writes data to a sequential device or file.
  16995.  
  16996.  
  16997.  Syntax
  16998.  
  16999.  
  17000.   PRINT #  filenumber%,  USING  formatstring$;  expressionlist{,|;}
  17001.  
  17002.  Remarks
  17003.  
  17004.  
  17005.  The  PRINT # statement uses the following arguments:
  17006.  
  17007. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  17008.  Argument                                Description
  17009.  ────────────────────────────────────────────────────────────────────────────
  17010.   filenumber%                            The number of an open sequential
  17011.                                          file.
  17012.  Argument                                Description
  17013.  ────────────────────────────────────────────────────────────────────────────
  17014.                                         file.
  17015.  
  17016.   formatstring$                          Specifies the exact format in
  17017.                                          which values are written to the
  17018.                                          file; described under  PRINT
  17019.                                          USING.
  17020.  
  17021.   expressionlist                         Numeric or string expressions to
  17022.                                          be written to the file.
  17023.  
  17024.  
  17025.  
  17026.  Spaces, commas, and semicolons in  expressionlist have the same meaning as
  17027.  they have in a  PRINT statement.
  17028.  
  17029.  If you omit  expressionlist, the  PRINT # statement prints a blank line in
  17030.  the file.
  17031.  
  17032.   PRINT # works like  PRINT and writes an image of the data to the file, just
  17033.  as the data would be displayed on the terminal screen. For this reason, be
  17034.  careful to delimit the data so it is output correctly. If you use commas as
  17035.  delimiters, the blanks between print fields are also written to the file.
  17036.  For more information, see "File and Device I/O" in the  Programmer's Guide.
  17037.  
  17038.  
  17039.  See Also
  17040.  
  17041.   OPEN (File I/O),  PRINT,  PRINT  USING,  WRITE #
  17042.  
  17043.  
  17044.  Example
  17045.  
  17046.  The following example shows the effects of using data delimiters with  PRINT
  17047.   #:
  17048.  
  17049.  CONST A$ = "CAMERA, AUTOFOCUS", B$ = "September 20, 1989", C$ = "42"
  17050.  
  17051.  Q$ = CHR$(34)
  17052.  
  17053.  OPEN "INVENT.DAT" FOR OUTPUT AS #1' Open INVENT.DAT for writing.
  17054.  
  17055.  PRINT #1, A$; B$; C$ ' Write without delimiters.
  17056.  
  17057.  PRINT #1, Q$; A$; Q$; Q$; B$; Q$; Q$; C$; Q$' With delimiters.
  17058.  
  17059.  CLOSE #1
  17060.  
  17061.  OPEN "INVENT.DAT" FOR INPUT AS #1' Open INVENT.DAT for reading.
  17062.  
  17063.  FOR I% = 1 TO 2' Read first two records and print.
  17064.  
  17065.     INPUT #1, First$, Second$, Third$
  17066.  
  17067.     PRINT First$; TAB(30); Second$; TAB(60); Third$
  17068.  
  17069.  NEXT
  17070.  
  17071.  CLOSE #1
  17072.  
  17073.  
  17074.  
  17075.  Output
  17076.  
  17077.  
  17078.  
  17079.  
  17080.  
  17081.  CAMERA                  AUTOFOCUSSeptember 20           198942
  17082.  CAMERA, AUTOFOCUS       September 20, 1989              42
  17083.  
  17084.  PRINT USING Statement
  17085.  ────────────────────────────────────────────────────────────────────────────
  17086.  
  17087.  
  17088.  Action
  17089.  
  17090.  Prints strings or numbers using a specified format.
  17091.  
  17092.  
  17093.  Syntax
  17094.  
  17095.  
  17096.   PRINT USING  formatstring$;  expressionlist {;|,}
  17097.  
  17098.  Remarks
  17099.  
  17100.  
  17101.  The  PRINT  USING statement uses the following arguments:
  17102.  
  17103. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  17104.  Argument                                Description
  17105.  ────────────────────────────────────────────────────────────────────────────
  17106.   formatstring$                          A string literal (or variable)
  17107.                                          that contains literal characters
  17108.                                          to print (such as labels) and
  17109.                                          special formatting characters. The
  17110.                                          latter determine the field and
  17111.                                          format of printed strings or
  17112.                                          numbers.
  17113.  
  17114.   expressionlist                         The values displayed on the screen.
  17115.                                          Commas, semicolons, spaces, or
  17116.                                          tabs can be used in
  17117.  Argument                                Description
  17118.  ────────────────────────────────────────────────────────────────────────────
  17119.                                         tabs can be used in
  17120.                                          expressionlist to separate items.
  17121.                                          In contrast with the  PRINT
  17122.                                          statement, delimiters in the
  17123.                                          expressionlist argument used with
  17124.                                          PRINT  USING have no effect on
  17125.                                          item placement.
  17126.  
  17127.  {;|,}                                   Determines the screen location of
  17128.                                          the text cursor for the next
  17129.                                          screen input or output statement:
  17130.                                          a semicolon means the text cursor
  17131.                                          is placed immediately after the
  17132.                                          last character displayed; a comma
  17133.                                          means the text cursor is placed at
  17134.                                          the start of the next print zone.
  17135.  
  17136.  
  17137.  
  17138.  When  PRINT USING is used to print strings, you can use one of three
  17139.  formatting characters to format the string field, as described in the
  17140.  following list:
  17141.  
  17142. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  17143.  Character                               Rules
  17144.  ────────────────────────────────────────────────────────────────────────────
  17145.  !                                       Only the first character in the
  17146.                                          given string is to be printed.
  17147.  
  17148.  \ \                                     Prints 2 +  n characters from the
  17149.                                          string, where  n is the number of
  17150.                                          spaces between the two backslashes.
  17151.                                          For example, if the backslashes
  17152.                                          are typed with no spaces, two
  17153.                                          characters are printed; with one
  17154.                                          space, three characters are
  17155.                                          printed, and so on. If the field
  17156.                                          is longer than the string, the
  17157.                                          string is left-justified in the
  17158.                                          field and padded with spaces on
  17159.  Character                               Rules
  17160.  ────────────────────────────────────────────────────────────────────────────
  17161.                                         field and padded with spaces on
  17162.                                          the right.
  17163.  
  17164.  &                                       The string is output without
  17165.                                          modification.
  17166.  
  17167.  
  17168.  
  17169.  
  17170.  
  17171.  When  PRINT USING is used to print numbers, the following special characters
  17172.  can be used to format the numeric field:
  17173.  
  17174.  
  17175. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  17176.  Character                               Rules
  17177.  ────────────────────────────────────────────────────────────────────────────
  17178.  #                                       Represents each digit position.
  17179.                                          Digit positions are always filled.
  17180.  Character                               Rules
  17181.  ────────────────────────────────────────────────────────────────────────────
  17182.                                         Digit positions are always filled.
  17183.                                          If the number to be printed has
  17184.                                          fewer digits than positions
  17185.                                          specified, the number is
  17186.                                          right-justified (preceded by
  17187.                                          spaces) in the field.
  17188.  
  17189.  .                                       Prints a decimal point. A decimal
  17190.                                          point can be inserted at any
  17191.                                          position in the field. If the
  17192.                                          format string specifies that a
  17193.                                          digit is to precede the decimal
  17194.                                          point, the digit is always printed
  17195.                                          (as 0, if necessary). Numbers are
  17196.                                          rounded as necessary.
  17197.  
  17198.  +                                       Prints the sign of the number (+
  17199.                                          or -) before the number (if it
  17200.                                          appears at the beginning of the
  17201.  Character                               Rules
  17202.  ────────────────────────────────────────────────────────────────────────────
  17203.                                         appears at the beginning of the
  17204.                                          format string) or after (if it
  17205.                                          appears at the end).
  17206.  
  17207.  -                                       Prints a negative number with a
  17208.                                          trailing minus sign if it appears
  17209.                                          at the end of the format string.
  17210.  
  17211.  **                                      Fills leading spaces in the
  17212.                                          numeric field with asterisks. Also
  17213.                                          specifies positions for two more
  17214.                                          digits.
  17215.  
  17216.  $$                                      Prints a dollar sign to the
  17217.                                          immediate left of the formatted
  17218.                                          number. Specifies two more digit
  17219.                                          positions, one of which is the
  17220.                                          dollar sign.
  17221.  
  17222.  Character                               Rules
  17223.  ────────────────────────────────────────────────────────────────────────────
  17224. 
  17225.  **$                                     Combines effects of
  17226.                                          double-asterisk and
  17227.                                          double-dollar-sign symbols.
  17228.                                          Leading spaces are filled with
  17229.                                          asterisks and a dollar sign is
  17230.                                          printed before the number.
  17231.                                          Specifies three more digit
  17232.                                          positions, one of which is the
  17233.                                          dollar sign. When negative numbers
  17234.                                          are printed, the minus sign
  17235.                                          appears to the immediate left of
  17236.                                          the dollar sign.
  17237.  
  17238.  ,                                       If the comma appears to the left
  17239.                                          of the decimal point in a format
  17240.                                          string, it makes a comma print to
  17241.                                          the left of every third digit left
  17242.                                          of the decimal point. If the comma
  17243.  Character                               Rules
  17244.  ────────────────────────────────────────────────────────────────────────────
  17245.                                         of the decimal point. If the comma
  17246.                                          appears at the end of the format
  17247.                                          string, it is printed as part of
  17248.                                          the string. Specifies another
  17249.                                          digit position. Has no effect if
  17250.                                          used with exponential (^^^^ or
  17251.                                          ^^^^^) format.
  17252.  
  17253.  ^^^^                                    Specifies exponential format. Five
  17254.                                          carets (^^^^^) allows D+ xxx to be
  17255.                                          printed for larger numbers. Any
  17256.                                          decimal point position can be
  17257.                                          specified. The significant digits
  17258.                                          are left-justified and the
  17259.                                          exponent is adjusted. Unless a
  17260.                                          leading +, trailing +, or - is
  17261.                                          specified, one digit position is
  17262.                                          used to the left of the decimal
  17263.                                          point to print a space or a minus
  17264.  Character                               Rules
  17265.  ────────────────────────────────────────────────────────────────────────────
  17266.                                         point to print a space or a minus
  17267.                                          sign.
  17268.  
  17269.   _                                      An underscore in the format string
  17270.                                          prints the next character as a
  17271.                                          literal character. A literal
  17272.                                          underscore is printed as the
  17273.                                          result of two underscores ( _ _ )
  17274.                                          in the format string.
  17275.  
  17276.  
  17277.  
  17278.  
  17279.  
  17280.  If the number to be printed is larger than the specified numeric field, a
  17281.  percent sign (%) is printed in front of the number. If rounding causes the
  17282.  number to exceed the field, a percent sign is printed in front of the
  17283.  rounded number. If the number of digits specified exceeds 24, BASIC
  17284.  generates the error message Illegal function call.
  17285.  
  17286.  
  17287.  
  17288.  Examples
  17289.  
  17290.  The following examples show the use of string- and numeric-formatting
  17291.  characters with  PRINT  USING.
  17292.  
  17293.  This is an example of using string-formatting characters:
  17294.  
  17295.  CLS    ' Clear screen.
  17296.  
  17297.  A$ = "LOOK" : B$ = "OUT"
  17298.  
  17299.  PRINT USING "!"; A$; B$' First characters of A$ and B$.
  17300.  
  17301.  PRINT USING "\  \"; A$; B$' Two spaces between backslashes,
  17302.  
  17303.  ' prints four characters from A$;
  17304.  
  17305.  PRINT USING "\   \"; A$; B$; "!!"  ' three spaces prints A$ and
  17306.  
  17307.  ' a blank.
  17308.  
  17309.  PRINT USING "!"; A$;' First character from A$ and
  17310.  
  17311.  PRINT USING "&"; B$' all of B$ on one line.
  17312.  
  17313.  
  17314.  
  17315.  Output
  17316.  
  17317.  
  17318.  
  17319.  
  17320.  
  17321.  LO
  17322.  LOOKOUT
  17323.  LOOK OUT  !!
  17324.  LOUT
  17325.  
  17326.  
  17327.  This example shows the effects of different combinations of numeric
  17328.  formatting characters:
  17329.  
  17330.  
  17331.  ' Format and print numeric data.
  17332.  
  17333.  CLS    ' Clear screen.
  17334.  
  17335.  PRINT USING "##.##"; .78
  17336.  
  17337.  PRINT USING "###.##"; 987.654
  17338.  
  17339.  PRINT USING "##.##   "; 10.2, 5.3, 66.789, .234
  17340.  
  17341.  PRINT USING "+##.##   "; -68.95, 2.4, 55.6, -.9
  17342.  
  17343.  PRINT USING "##.##-   "; -68.95, 22.449, -7.01
  17344.  
  17345.  PRINT USING "**#.#   "; 12.39, -0.9, 765.1
  17346.  
  17347.  PRINT USING "$$###.##"; 456.78
  17348.  
  17349.  PRINT USING "**$##.##"; 2.34
  17350.  
  17351.  PRINT USING "####,.##"; 1234.5
  17352.  
  17353.  PRINT USING "##.##^^^^"; 234.56
  17354.  
  17355.  PRINT USING ".####^^^^-"; -888888
  17356.  
  17357.  PRINT USING "+.##^^^^^"; 123
  17358.  
  17359.  PRINT USING "_!##.##_!"; 12.34
  17360.  
  17361.  PRINT USING "##.##"; 111.22
  17362.  
  17363.  PRINT USING ".##"; .999
  17364.  
  17365.  
  17366.  
  17367.  Output
  17368.  
  17369.  
  17370.  
  17371.  
  17372.  
  17373.  0.78
  17374.  987.65
  17375.  10.20    5.30   66.79    0.23
  17376.  -68.95    +2.40   +55.60    -0.90
  17377.  68.95-   22.45     7.01-
  17378.  *12.4   *-0.9   765.1
  17379.   $456.78
  17380.  ***$2.34
  17381.  1,234.50
  17382.   2.35E+02
  17383.  .8889E+06-
  17384.  +.12E+003
  17385.  !12.34!
  17386.  %111.22
  17387.  %1.00
  17388.  
  17389.  PSET Statement
  17390.  ────────────────────────────────────────────────────────────────────────────
  17391.  
  17392.  
  17393.  Action
  17394.  
  17395.  Draws a specified point on the screen.
  17396.  
  17397.  
  17398.  Syntax
  17399.  
  17400.  
  17401.   PSET  STEP( x%,  y%) ,  color&
  17402.  
  17403.  Remarks
  17404.  
  17405.  
  17406.  The following list describes the parts of the  PSET statement:
  17407. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  17408.  Part                                    Description
  17409.  ────────────────────────────────────────────────────────────────────────────
  17410.   STEP                                   Indicates that  x% and  y% are
  17411.  Part                                    Description
  17412.  ────────────────────────────────────────────────────────────────────────────
  17413.   STEP                                   Indicates that  x% and  y% are
  17414.                                          relative, not absolute.
  17415.                                          Coordinates are treated as
  17416.                                          distances from the most recent
  17417.                                          graphics cursor location, not
  17418.                                          distances from the (0,0) screen
  17419.                                          coordinate.
  17420.  
  17421.                                          For example, if the most recent
  17422.                                          graphics cursor location were
  17423.                                          (10,10), PSET STEP (10,5) would
  17424.                                          refer to the point at (20,15).
  17425.  
  17426.   x%                                     The x coordinate of the pixel that
  17427.                                          is to be set.
  17428.  
  17429.   y%                                     The y coordinate of the pixel that
  17430.                                          is to be set.
  17431.  
  17432.  Part                                    Description
  17433.  ────────────────────────────────────────────────────────────────────────────
  17434. 
  17435.   color&                                 The color attribute for the
  17436.                                          specified pixel.
  17437.  
  17438.  
  17439.  
  17440.  The valid range of screen coordinate values and color values depends on the
  17441.  screen mode established by the most recently executed  SCREEN statement. If
  17442.  a coordinate is outside the current viewport, no action is taken, nor is an
  17443.  error message generated.
  17444.  
  17445.  If you use  PSET without specifying  color&, the foreground color is
  17446.  selected. In contrast, if you use  PRESET without specifying  color&, the
  17447.  background color is selected. Otherwise, the two statements work exactly the
  17448.  same.
  17449.  
  17450.  
  17451.  See Also
  17452.  
  17453.   PRESET
  17454.  
  17455.  
  17456.  Example
  17457.  
  17458.  The following example draws a line from (0,0) to (100,100), then erases the
  17459.  line by writing over it with the background color:
  17460.  
  17461.  SCREEN 2
  17462.  
  17463.  FOR I = 0 TO 100
  17464.  
  17465.     PSET (I, I)
  17466.  
  17467.  NEXT I
  17468.  
  17469.  LOCATE 16, 2: INPUT "Press the Return key to erase the line ", Gar$
  17470.  
  17471.  ' Now erase the line.
  17472.  
  17473.  PSET (I - 1, I - 1), 0
  17474.  
  17475.  FOR I = 0 TO 100
  17476.  
  17477.     PSET STEP(-1, -1), 0
  17478.  
  17479.  NEXT I
  17480.  
  17481.  LOCATE 16, 2: PRINT "                                       "
  17482.  
  17483.  PUT Statement (File I/O)
  17484.  ────────────────────────────────────────────────────────────────────────────
  17485.  
  17486.  
  17487.  Action
  17488.  
  17489.  Writes from a variable or a random-access buffer to a file.
  17490.  
  17491.  
  17492.  Syntax
  17493.  
  17494.  
  17495.   PUT #  filenumber%,  recordnumber%,  variable
  17496.  
  17497.  Remarks
  17498.  
  17499.  
  17500.  Do not use  PUT on ISAM files.
  17501.  
  17502.  The  PUT statement uses the following arguments:
  17503.  
  17504. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  17505.  Argument                                Description
  17506.  ────────────────────────────────────────────────────────────────────────────
  17507.   filenumber%                            The number used in the  OPEN
  17508.                                          statement to open the file.
  17509.  
  17510.   recordnumber%                          For random-access files, the
  17511.                                          number of the record to be written.
  17512.                                          For binary-mode files, the byte
  17513.                                          position where writing is done.
  17514.                                          The first record or byte position
  17515.                                          in a file is 1. If you omit
  17516.  Argument                                Description
  17517.  ────────────────────────────────────────────────────────────────────────────
  17518.                                         in a file is 1. If you omit
  17519.                                          recordnumber%, the next record or
  17520.                                          byte (the one after the last  GET
  17521.                                          or  PUT statement, or the one
  17522.                                          pointed to by the last  SEEK) is
  17523.                                          written to. The largest possible
  17524.                                          record number is 231 -1 or
  17525.                                          2,147,483,647.
  17526.  
  17527.   variable                               A variable that contains output to
  17528.                                          be written to the file. The  PUT
  17529.                                          statement writes as many bytes to
  17530.                                          the file as there are bytes in the
  17531.                                          variable.
  17532.  
  17533.                                          If you specify a variable, you do
  17534.                                          not need to use  MKI$,  MKL$,
  17535.                                          MKS$,  MKD$, or  MKC$ to convert
  17536.                                          numeric fields before writing. You
  17537.  Argument                                Description
  17538.  ────────────────────────────────────────────────────────────────────────────
  17539.                                         numeric fields before writing. You
  17540.                                          cannot use a  FIELD statement with
  17541.                                          the file if you use the variable
  17542.                                          argument.
  17543.  
  17544.                                          For random-access files, you can
  17545.                                          use any variable as long as the
  17546.                                          length of the variable is less
  17547.                                          than or equal to the length of the
  17548.                                          record. Usually, a record variable
  17549.                                          defined to match the fields in a
  17550.                                          data record is used. A record
  17551.                                          cannot be longer than 32,767 bytes.
  17552.  
  17553.                                          For binary-mode files, you can use
  17554.                                          any variable.
  17555.  
  17556.                                          When you use a variable-length
  17557.                                          string variable, the statement
  17558.  Argument                                Description
  17559.  ────────────────────────────────────────────────────────────────────────────
  17560.                                         string variable, the statement
  17561.                                          writes as many bytes as there are
  17562.                                          characters in the string's value.
  17563.                                          For example, the following two
  17564.                                          statements write 15 bytes to file
  17565.                                          number 1:
  17566.  
  17567.                                          VarString$=STRING$(15, "X")
  17568.  
  17569.                                          PUT #1,,VarString$
  17570.  
  17571.                                          See the examples for more
  17572.                                          information about using variables
  17573.                                          rather than  FIELD statements for
  17574.                                          random-access files.
  17575.  
  17576.  
  17577.  
  17578.  
  17579.  
  17580.  You can omit  recordnumber%,  variable, or both. If you omit  recordnumber%
  17581.  but include a variable, you must still include the commas:
  17582.  
  17583.  
  17584.  PUT #4,,FileBuffer
  17585.  
  17586.  If you omit both arguments, do not include the commas:
  17587.  
  17588.  
  17589.  PUT #4
  17590.  
  17591.   GET and  PUT statements allow fixed-length input and output for BASIC
  17592.  communication files. Be careful using  GET and  PUT for communication
  17593.  because  PUT writes a fixed number of characters and may wait indefinitely
  17594.  if there is a communication failure.
  17595.  
  17596.  
  17597.  
  17598.  
  17599.  Note
  17600.  
  17601.  
  17602.  When using a file buffer defined by a  FIELD statement,  LSET,  RSET,  PRINT
  17603.  # ,  PRINT #  USING, and  WRITE # can be used to put characters in the
  17604.  random-file buffer before executing a  PUT statement. In the case of  WRITE
  17605.  #, BASIC pads the buffer with spaces up to the carriage return. If you
  17606.  attempt to read or write past the end of the buffer, BASIC generates the
  17607.  error message FIELD overflow.
  17608.  
  17609.  
  17610.  
  17611.  See Also
  17612.  
  17613.  
  17614.   CVI,  CVL,  CVS,  CVD,  CVC;  GET (File I/O);  LSET;  MKI$,  MKL$,  MKS$,
  17615.  MKD$,  MKC$;  OPEN (File I/O)
  17616.  
  17617.  
  17618.  
  17619.  Example
  17620.  
  17621.  
  17622.  The following example reads names and test scores from the console and
  17623.  stores them in a random-access file:
  17624.  
  17625.  ' Define record fields.
  17626.  
  17627.  TYPE TestRecord
  17628.  
  17629.     NameField  AS STRING * 20
  17630.  
  17631.     ScoreField AS SINGLE
  17632.  
  17633.  END TYPE
  17634.  
  17635.  DIM FileBuffer AS TestRecord
  17636.  
  17637.  DIM I AS LONG
  17638.  
  17639.  ' Open the test data file.
  17640.  
  17641.  OPEN "TESTDAT.DAT" FOR RANDOM AS #1 LEN = LEN(FileBuffer)
  17642.  
  17643.  ' Read pairs of names and scores from the console.
  17644.  
  17645.  CLS    ' Clear screen.
  17646.  
  17647.  I = 0
  17648.  
  17649.  DO
  17650.  
  17651.      I = I + 1
  17652.  
  17653.      INPUT "Name ? ", FileBuffer.NameField
  17654.  
  17655.      INPUT "Score? ", FileBuffer.ScoreField
  17656.  
  17657.      INPUT "-->More (y/n)? ", Resp$
  17658.  
  17659.      PUT #1, I, FileBuffer
  17660.  
  17661.  LOOP UNTIL UCASE$(MID$(Resp$, 1, 1)) = "N"
  17662.  
  17663.  PRINT I; " records written."
  17664.  
  17665.  CLOSE #1
  17666.  
  17667.  KILL "TESTDAT.DAT"' Remove file from disk.
  17668.  
  17669.  PUT Statement (Graphics)
  17670.  ────────────────────────────────────────────────────────────────────────────
  17671.  
  17672.  
  17673.  Action
  17674.  
  17675.  Places a graphic image obtained by a  GET statement onto the screen.
  17676.  
  17677.  
  17678.  Syntax
  17679.  
  17680.  
  17681.   PUT  STEP ( x!,  y!),  arrayname# ( indexes%) ,  actionverb
  17682.  
  17683.  Remarks
  17684.  
  17685.  
  17686.  The list below describes the parts of the  PUT statement:
  17687.  
  17688. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  17689.  Part                                    Description
  17690.  ────────────────────────────────────────────────────────────────────────────
  17691.   STEP                                   Keyword indicating that the given
  17692.                                          x and y coordinates are relative
  17693.                                          to the most recently plotted point.
  17694.                                          The coordinates are treated as
  17695.                                          distances from the most-recent
  17696.                                          cursor location, not distances
  17697.                                          from the (0,0) screen coordinate.
  17698.                                          For example, if the most recent
  17699.                                          cursor location were (10,10) then
  17700.                                          the following statement would put
  17701.                                          the object stored in Ball at
  17702.                                          (20,15):
  17703.  
  17704.                                          PUT STEP (10,5),Ball
  17705.  Part                                    Description
  17706.  ────────────────────────────────────────────────────────────────────────────
  17707.                                         PUT STEP (10,5),Ball
  17708.  
  17709.  ( x!, y!)                               Coordinates that specify the
  17710.                                          top-left corner of the rectangle
  17711.                                          enclosing the image to be placed
  17712.                                          in the current output window. The
  17713.                                          entire rectangle to be put on the
  17714.                                          screen must be within the bounds
  17715.                                          of the current viewport.
  17716.  
  17717.                                          Note that if a  WINDOW statement
  17718.                                          without the argument  SCREEN
  17719.                                          appears in a program before  PUT,
  17720.                                          the coordinates refer to the
  17721.                                          lower-left corner of the rectangle.
  17722.  
  17723.   arrayname#                             The name of the array that holds
  17724.                                          the image. See the  GET statement
  17725.                                          for information about the number
  17726.  Part                                    Description
  17727.  ────────────────────────────────────────────────────────────────────────────
  17728.                                         for information about the number
  17729.                                          of elements that are required in
  17730.                                          the array, which can be
  17731.                                          multidimensional.
  17732.  
  17733.   indexes%                               Specifies that the image is
  17734.                                          retrieved starting from the
  17735.                                          designated array element, rather
  17736.                                          than at the first array element.
  17737.  
  17738.   actionverb                             Determines interaction between
  17739.                                          stored image and the one already
  17740.                                          on the screen. This allows display
  17741.                                          of the image with special effects.
  17742.  
  17743.  
  17744.  
  17745.  The different values for  actionverb are described in the following list.
  17746.  The default  actionverb value is  XOR.
  17747.  
  17748. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  17749.  Verb                                    Description
  17750.  ────────────────────────────────────────────────────────────────────────────
  17751.   XOR                                    Causes the points on the screen to
  17752.                                          be inverted where a point exists
  17753.                                          in the array image. When an image
  17754.                                          is placed on the screen against a
  17755.                                          complex background twice, the
  17756.                                          background is restored. This
  17757.                                          behavior is exactly like that of
  17758.                                          the cursor. You can move an object
  17759.                                          around the screen without erasing
  17760.                                          the background, thus creating
  17761.                                          animation effects.
  17762.  
  17763.   PSET                                   Transfers the data point-by-point
  17764.                                          onto the screen. Each point has
  17765.                                          the exact color attribute it had
  17766.                                          when it was taken from the screen
  17767.                                          with  GET. The  PSET argument
  17768.  Verb                                    Description
  17769.  ────────────────────────────────────────────────────────────────────────────
  17770.                                         with  GET. The  PSET argument
  17771.                                          draws the image as stored, wiping
  17772.                                          out any existing image.
  17773.  
  17774.   PRESET                                 The same as  PSET except that a
  17775.                                          negative image (for example, black
  17776.                                          on white) is produced.
  17777.  
  17778.   AND                                    Used when the image is to be
  17779.                                          transferred over an existing image
  17780.                                          on the screen. The resulting
  17781.                                          merged image is the result of a
  17782.                                          logical-  AND operation on the
  17783.                                          stored image and the screen.
  17784.                                          Points that had the same color in
  17785.                                          both the existing image and the
  17786.                                          stored image remain the same color.
  17787.                                          Points that do not have the same
  17788.                                          color in both the existing image
  17789.  Verb                                    Description
  17790.  ────────────────────────────────────────────────────────────────────────────
  17791.                                         color in both the existing image
  17792.                                          and the stored image do not.
  17793.  
  17794.   OR                                     Used to superimpose the image onto
  17795.                                          an existing image. The resulting
  17796.                                          image is the product of a logical-
  17797.                                          OR operation on the stored image
  17798.                                          and the screen image. The stored
  17799.                                          image does not erase the previous
  17800.                                          screen contents.
  17801.  
  17802.  
  17803.  
  17804.  
  17805.  
  17806.  
  17807.  
  17808.  See Also
  17809.  
  17810.   GET (Graphics)
  17811.  
  17812.  
  17813.  Example
  17814.  
  17815.  The following example creates a moving white ball that ricochets off the
  17816.  sides of the screen until you press a key:
  17817.  
  17818.  DEFINT A-Z
  17819.  
  17820.  DIM Ball(84)' Set the dimensions for an integer array large
  17821.  
  17822.   ' enough to hold ball.
  17823.  
  17824.  SCREEN 2' 640 pixels by 200 pixels screen resolution.
  17825.  
  17826.  
  17827.  
  17828.  INPUT "Press any key to end; press <ENTER> to start", Test$
  17829.  
  17830.  CLS
  17831.  
  17832.  CIRCLE (16, 16), 14' Draw and paint ball.
  17833.  
  17834.  PAINT (16, 16), 1
  17835.  
  17836.  GET (0, 0)-(32, 32), Ball
  17837.  
  17838.  X = 0 : Y = 0
  17839.  
  17840.  Xdelta = 2 : Ydelta = 1
  17841.  
  17842.  
  17843.  
  17844.  DO
  17845.  
  17846.     ' Continue moving in same direction as long as ball is within
  17847.  
  17848.     ' the boundaries of the screen - (0,0) to (640,200).
  17849.  
  17850.     X = X + Xdelta : Y = Y + Ydelta
  17851.  
  17852.     IF INKEY$ <> "" THEN END  ' Test for key press.
  17853.  
  17854.     ' Change X direction if ball hits left or right edge.
  17855.  
  17856.     IF (X < 1 OR X > 600) THEN
  17857.  
  17858.        Xdelta = -Xdelta
  17859.  
  17860.        BEEP
  17861.  
  17862.     END IF
  17863.  
  17864.     ' Change Y direction if ball hits top or bottom edge.
  17865.  
  17866.     IF (Y < 1 OR Y > 160) THEN
  17867.  
  17868.        Ydelta = -Ydelta
  17869.  
  17870.        BEEP
  17871.  
  17872.     END IF
  17873.  
  17874.     ' Put new image on screen, simultaneously erasing old image.
  17875.  
  17876.     PUT (X, Y), Ball, PSET
  17877.  
  17878.  LOOP
  17879.  
  17880.  END
  17881.  
  17882.  RANDOMIZE Statement
  17883.  ────────────────────────────────────────────────────────────────────────────
  17884.  
  17885.  
  17886.  Action
  17887.  
  17888.  Initializes (reseeds) the random-number generator.
  17889.  
  17890.  
  17891.  Syntax
  17892.  
  17893.  
  17894.   RANDOMIZE  expression%
  17895.  
  17896.  Remarks
  17897.  
  17898.  
  17899.  If you omit  expression%, BASIC pauses and asks for a value by printing the
  17900.  following messages before executing the  RANDOMIZE statement:
  17901.  
  17902.  Random Number Seed (-32768 to 32767)?
  17903.  
  17904.  When you use the argument  expression%, BASIC uses this value to initialize
  17905.  the random-number generator.
  17906.  
  17907.  
  17908.  
  17909.  If the random-number generator is not reseeded, the  RND function returns
  17910.  the same sequence of random numbers each time the program is run. To change
  17911.  the sequence of random numbers every time the program is run, place a
  17912.  RANDOMIZE statement at the beginning of the program and change the argument
  17913.  with each run.
  17914.  
  17915.  
  17916.  A convenient way to initialize the random-number generator is to use the
  17917.  TIMER function. Using  TIMER ensures a new series of random numbers each
  17918.  time you use the program. See the example below.
  17919.  
  17920.  
  17921.  
  17922.  See Also
  17923.  
  17924.  
  17925.   RND,  TIMER
  17926.  
  17927.  
  17928.  
  17929.  Example
  17930.  
  17931.  
  17932.  The following example uses  RANDOMIZE to seed and reseed the random number
  17933.  generator. It uses the  RND function to simulate rolling a pair of dice.
  17934.  
  17935.  ' Use the timer as the seed for the number generator.
  17936.  
  17937.  RANDOMIZE TIMER
  17938.  
  17939.  DO
  17940.  
  17941.     ' Simulate rolling two dice using RND.
  17942.  
  17943.     D1 = INT(RND * 6) + 1
  17944.  
  17945.     D2 = INT(RND * 6) + 1
  17946.  
  17947.     ' Report the roll.
  17948.  
  17949.     CLS    ' Clear screen.
  17950.  
  17951.     PRINT "You rolled a"; D1; "and a"; D2; "for a total of"; D1 + D2
  17952.  
  17953.     INPUT "Roll again (Y/N)"; Resp$
  17954.  
  17955.     PRINT
  17956.  
  17957.  LOOP UNTIL UCASE$(MID$(Resp$, 1, 1)) = "N"
  17958.  
  17959.  END
  17960.  
  17961.  
  17962.  
  17963.  Output
  17964.  
  17965.  
  17966.  
  17967.  
  17968.  
  17969.  You rolled a 3 and a 5 for a total of 8
  17970.  Roll again (Y/N)? n
  17971.  
  17972.  READ Statement
  17973.  ────────────────────────────────────────────────────────────────────────────
  17974.  
  17975.  
  17976.  Action
  17977.  
  17978.  Reads values from a  DATA statement and assigns the values to variables.
  17979.  
  17980.  
  17981.  Syntax
  17982.  
  17983.  
  17984.   READ  variablelist
  17985.  
  17986.  Remarks
  17987.  
  17988.  
  17989.  The argument  variablelist is a series of BASIC variables that receive the
  17990.  data from a  DATA statement. The variables are separated by commas and can
  17991.  be string or numeric. Only individual elements of a record variable can
  17992.  appear in a  READ statement.
  17993.  
  17994.  The following table describes what happens when you try to read data of one
  17995.  data type into a variable with a different data type:
  17996.  
  17997. ╓┌────────────────────────┌────────────────────────┌─────────────────────────╖
  17998.  If you try to read       Into this:               The result is:
  17999.  If you try to read       Into this:               The result is:
  18000.  this:
  18001.  ────────────────────────────────────────────────────────────────────────────
  18002.  String value             Numeric variable         A run-time error.
  18003.  
  18004.  Numeric value            String variable          The value is stored as a
  18005.                                                    string of numerals (no
  18006.                                                    error is produced).
  18007.  
  18008.  Any numeric value        Integer variables        The value is rounded
  18009.                                                    before it is assigned to
  18010.                                                    the variable.
  18011.  
  18012.  Numeric value            A variable not large     A run-time error.
  18013.                           enough to handle the
  18014.                           numeric variable.
  18015.  
  18016.  String value             Fixed-length string      Truncated if the string
  18017.                           variables                is too long;
  18018.                                                    left-justified and
  18019.                                                    padded with blanks if
  18020.  If you try to read       Into this:               The result is:
  18021.  this:
  18022.                                                   padded with blanks if
  18023.                                                    the string is shorter
  18024.                                                    than the variable.
  18025.  
  18026.  
  18027.  
  18028.  
  18029.  
  18030.  Each variable in a  READ statement receives its value from some  DATA
  18031.  statement. Which value the variable receives depends on how many values have
  18032.  previously been read. The values of all  DATA statements in a module can be
  18033.  considered as a single list of values. Each value in this list is assigned
  18034.  in turn to the variables specified in  READ statements. It doesn't matter
  18035.  how many values are specified in a given  DATA statement or how many
  18036.  variables are specified in a  READ statement. If you attempt to read more
  18037.  values than are specified in all of the statements combined, BASIC generates
  18038.  the error message Out of data.
  18039.  
  18040.  Use the  RESTORE statement to reread  DATA statements.
  18041.  
  18042.  
  18043.  See Also
  18044.  
  18045.   DATA,  RESTORE
  18046.  
  18047.  
  18048.  Example
  18049.  
  18050.  
  18051.  The following example shows how you can use a  READ statement to assign
  18052.  values to the user-defined type Employee.
  18053.  
  18054.  TYPE Employee
  18055.  
  18056.     EmpName AS STRING * 35
  18057.  
  18058.     SocSec AS STRING * 11
  18059.  
  18060.     JobClass AS INTEGER
  18061.  
  18062.  END TYPE
  18063.  
  18064.  
  18065.  
  18066.  CLS                ' Clear screen.
  18067.  
  18068.  DIM ThisEmp AS Employee
  18069.  
  18070.  DATA "Julia Magruder","300-32-3403",3
  18071.  
  18072.  DATA "Amelie Reeves Troubetzkoy","777-29-3206",7
  18073.  
  18074.  
  18075.  
  18076.  ' Read first data input line and verify by printing data.
  18077.  
  18078.  READ ThisEmp.EmpName, ThisEmp.SocSec, ThisEmp.JobClass
  18079.  
  18080.  PRINT "Employee is "; ThisEmp.EmpName
  18081.  
  18082.  PRINT "Employee's social security number is "; ThisEmp.SocSec
  18083.  
  18084.  PRINT "Employee's job class is"; ThisEmp.JobClass
  18085.  
  18086.  PRINT' Print blank line
  18087.  
  18088.  
  18089.  
  18090.  ' Read second data input line and verify.
  18091.  
  18092.  READ ThisEmp.EmpName, ThisEmp.SocSec, ThisEmp.JobClass
  18093.  
  18094.  PRINT "Employee is "; ThisEmp.EmpName
  18095.  
  18096.  PRINT "Employee's social security number is "; ThisEmp.SocSec
  18097.  
  18098.  PRINT "Employee's job class is"; ThisEmp.JobClass
  18099.  
  18100.  
  18101.  
  18102.  Output
  18103.  
  18104.  
  18105.  
  18106.  
  18107.  
  18108.  Employee is Julia Magruder
  18109.  Employee's social security number is 300-32-3403
  18110.  Employee's job class is 3
  18111.  
  18112.  Employee is Amelie Reeves Troubetzkoy
  18113.  Employee's social security number is 777-29-3206
  18114.  Employee's job class is 7
  18115.  
  18116.  REDIM Statement
  18117.  ────────────────────────────────────────────────────────────────────────────
  18118.  
  18119.  
  18120.  Action
  18121.  
  18122.  Changes the space allocated to an array that has been declared dynamic.
  18123.  
  18124.  
  18125.  Syntax
  18126.  
  18127.  
  18128.   REDIM  SHARED  variable( subscripts)  AS  type ,  variable( subscripts)  AS
  18129.   type...
  18130.  
  18131.  Remarks
  18132.  
  18133.  
  18134.  The  REDIM statement uses the following arguments:
  18135.  
  18136. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  18137.  Arguments                               Description
  18138.  ────────────────────────────────────────────────────────────────────────────
  18139.   SHARED                                 The optional  SHARED attribute
  18140.                                          allows a module to share variables
  18141.                                          with all the procedures in the
  18142.                                          module; this differs from the
  18143.                                          SHARED statement, which affects
  18144.                                          only the variables within a single
  18145.                                          module.  SHARED can be used in
  18146.  Arguments                               Description
  18147.  ────────────────────────────────────────────────────────────────────────────
  18148.                                         module.  SHARED can be used in
  18149.                                          REDIM statements only in the
  18150.                                          module-level code.
  18151.  
  18152.   variable                               A BASIC variable name.
  18153.  
  18154.   subscripts                             The dimensions of the array.
  18155.                                          Multiple dimensions can be
  18156.                                          declared. The subscript syntax is
  18157.                                          described below.
  18158.  
  18159.   AS  type                               Declares the type of the variable.
  18160.                                          The type can be  INTEGER,  LONG,
  18161.                                          SINGLE,  DOUBLE,  STRING (for
  18162.                                          variable-length strings),  STRING
  18163.                                          *  length (for fixed-length
  18164.                                          strings),  CURRENCY, or a
  18165.                                          user-defined type.
  18166.  
  18167.  Arguments                               Description
  18168.  ────────────────────────────────────────────────────────────────────────────
  18169. 
  18170.  
  18171.  
  18172.  
  18173.  
  18174.  Subscripts in  REDIM have the following form:
  18175.  
  18176.   lower  TO  upper ,  lower  TO  upper...
  18177.  
  18178.  The  TO keyword provides a way to indicate both the lower and the upper
  18179.  bounds of an array's subscripts. The arguments  lower and  upper are numeric
  18180.  expressions that specify the lowest and highest value for the subscript. For
  18181.  more information about using the  TO keyword, see the  DIM statement. For
  18182.  more information about static and dynamic arrays, see Appendix B, "Data
  18183.  Types, Constants, Variables, and Arrays" in the  Programmer's Guide.
  18184.  
  18185.  When a  REDIM statement is compiled, all arrays declared in the statement
  18186.  are treated as dynamic. At run time, when a  REDIM statement is executed,
  18187.  the array is deallocated (if it is already allocated) and then reallocated
  18188.  with the new dimensions. Old array-element values are lost because all
  18189.  numeric elements are reset to 0, and all string elements are reset to null
  18190.  strings.
  18191.  
  18192.  Although you can change the  size of an array's dimensions with the  REDIM
  18193.  statement, you can not change the number of dimensions. For example, the
  18194.  following statements are legal:
  18195.  
  18196.  
  18197.  ' $DYNAMIC
  18198.  
  18199.  DIM A(50,50)
  18200.  
  18201.  ERASE A
  18202.  
  18203.  REDIM A(20,15) ' Array A still has two dimensions.
  18204.  
  18205.  
  18206.  
  18207.  However, the following statements are  not legal, and if you use them, BASIC
  18208.  generates the error message Wrong number of dimensions:
  18209.  
  18210.  
  18211.  ' $DYNAMIC
  18212.  
  18213.  DIM A(50,50)
  18214.  
  18215.  ERASE A
  18216.  
  18217.  REDIM A(5,5,5) ' Changed number of dimensions from two to three.
  18218.  
  18219.  
  18220.  Note
  18221.  
  18222.  
  18223.  
  18224.  BASIC now supports the  CURRENCY data type (type suffix  @). This is used in
  18225.  the  AS  type clause of  REDIM. BASIC now supports static arrays in
  18226.  user-defined types.
  18227.  
  18228.  
  18229.  
  18230.  See Also
  18231.  
  18232.  
  18233.   DIM,  ERASE
  18234.  
  18235.  
  18236.  
  18237.  Example
  18238.  
  18239.  
  18240.  The following example shows how to use  REDIM to allocate an array of
  18241.  records and then how to free the memory that the records use.
  18242.  
  18243.  TYPE KeyElement
  18244.  
  18245.     Word AS STRING * 20
  18246.  
  18247.     Count AS INTEGER
  18248.  
  18249.  END TYPE
  18250.  
  18251.  
  18252.  
  18253.  ' Make arrays dynamic.
  18254.  
  18255.  ' $DYNAMIC
  18256.  
  18257.  CLS                          ' Clear screen.
  18258.  
  18259.  ' Allocate an array of records when you need it.
  18260.  
  18261.  REDIM Keywords(100) AS KeyElement
  18262.  
  18263.  Keywords(99).Word = "ERASE"
  18264.  
  18265.  Keywords(99).Count = 2
  18266.  
  18267.  PRINT "Keyword 99 is "; Keywords(99).Word
  18268.  
  18269.  PRINT "Count is"; Keywords(99).Count
  18270.  
  18271.  ' Free the space taken by Keywords when you're finished.
  18272.  
  18273.  ERASE Keywords
  18274.  
  18275.  END
  18276.  
  18277.  
  18278.  
  18279.  Output
  18280.  
  18281.  
  18282.  
  18283.  
  18284.  
  18285.  Keyword 99 is ERASE
  18286.  Count is 2
  18287.  
  18288.  REM Statement
  18289.  ────────────────────────────────────────────────────────────────────────────
  18290.  
  18291.  
  18292.  Action
  18293.  
  18294.  Allows explanatory remarks to be inserted in a program.
  18295.  
  18296.  
  18297.  Syntax 1
  18298.  
  18299.   REM  remark
  18300.  
  18301.  Syntax 2
  18302.  
  18303.  '  remark
  18304.  
  18305.  
  18306.  
  18307.  Remarks
  18308.  
  18309.   REM statements are not compiled, but they appear exactly as entered when
  18310.  the program is listed. You can branch from a  GOTO or  GOSUB statement to a
  18311.  REM statement. Execution continues with the first executable statement after
  18312.  the  REM statement.
  18313.  
  18314.  A single quotation mark can be used instead of the  REM keyword. If the  REM
  18315.  keyword follows other statements on a line, it must be separated from the
  18316.  statements by a colon.
  18317.  
  18318.   REM statements also are used to introduce metacommands. For more
  18319.  information, see Chapter 2, "SUB and FUNCTION Procedures" in the
  18320.  Programmer's Guide.
  18321.  
  18322.  
  18323.  Note
  18324.  
  18325.  Do not use the single quotation form of the  REM statement in a  DATA
  18326.  statement because it will be considered valid data.
  18327.  
  18328.  
  18329.  Examples
  18330.  
  18331.  The following example shows two equivalent remark statements. Note that you
  18332.  must precede a REM statement at the end of a line with a colon.
  18333.  
  18334.  This is not a complete program.
  18335.  
  18336.  DIM Array(23)
  18337.  FOR I = 1 TO 23 : Array(I) = 1 : NEXT I : REM Initialize the array.
  18338.  FOR I = 1 TO 23 : Array(I) = 1 : NEXT I   ' Initialize the array.
  18339.  
  18340.  RESET Statement
  18341.  ────────────────────────────────────────────────────────────────────────────
  18342.  
  18343.  
  18344.  Action
  18345.  
  18346.  Closes all disk files.
  18347.  
  18348.  
  18349.  Syntax
  18350.  
  18351.  
  18352.   RESET
  18353.  
  18354.  Remarks
  18355.  
  18356.  
  18357.  The  RESET statement closes all open disk files and writes data still in the
  18358.  file buffers to disk.
  18359.  
  18360.  
  18361.  See Also
  18362.  
  18363.   CLOSE,  END,  SYSTEM
  18364.  
  18365.  
  18366.  Example
  18367.  
  18368.  The following example opens several files for sequential output, then
  18369.  performs a  RESET. The program attempts to write to the previously opened
  18370.  files. The error that occurs is trapped and a message is printed indicating
  18371.  that all files have been closed using the  RESET statement.
  18372.  
  18373.  DEFINT A-Z
  18374.  
  18375.  ON ERROR GOTO ErrHandler    ' Set up the error-handling routine.
  18376.  
  18377.  
  18378.  
  18379.  CLS
  18380.  
  18381.  FOR I = 1 TO 3
  18382.  
  18383.      OPEN "Test" + RIGHT$(STR$(I), 1) + ".dat" FOR OUTPUT AS FREEFILE
  18384.  
  18385.      PRINT "File #"; I; "has been opened for output."
  18386.  
  18387.  NEXT I
  18388.  
  18389.  PRINT : PRINT "Press any key to reset all open files."
  18390.  
  18391.  PRINT
  18392.  
  18393.  Z$ = INPUT$(1)
  18394.  
  18395.  RESET
  18396.  
  18397.  FOR I = 1 TO 3
  18398.  
  18399.      PRINT "Trying to write to file #"; I
  18400.  
  18401.      PRINT #I, "Test data"
  18402.  
  18403.  NEXT I
  18404.  
  18405.  END
  18406.  
  18407.  
  18408.  
  18409.  ErrHandler:
  18410.  
  18411.  ' Error 52 is "Bad file name or number"
  18412.  
  18413.  IF ERR = 52 THEN PRINT "  File #"; I; "not open. RESET closed it."
  18414.  
  18415.  RESUME NEXT
  18416.  
  18417.  RESTORE Statement
  18418.  ────────────────────────────────────────────────────────────────────────────
  18419.  
  18420.  
  18421.  Action
  18422.  
  18423.  Allows  DATA statements to be reread from a specified line.
  18424.  
  18425.  
  18426.  Syntax
  18427.  
  18428.  
  18429.   RESTORE { linelabel |  linenumber}
  18430.  
  18431.  Remarks
  18432.  
  18433.  
  18434.  After executing a  RESTORE statement without a specified  linelabel or
  18435.  linenumber, the next  READ statement gets the first item in the first  DATA
  18436.  statement in the program.
  18437.  
  18438.  If  linelabel or  linenumber is specified, the next  READ statement gets the
  18439.  first item in the specified  DATA statement. If a line is specified, the
  18440.  line label or line number must be in the module-level code. (Note that in
  18441.  the QBX environment,  DATA statements are automatically moved to the
  18442.  module-level code.)
  18443.  
  18444.  
  18445.  See Also
  18446.  
  18447.   DATA,  READ
  18448.  
  18449.  
  18450.  Example
  18451.  
  18452.  See the  SEEK (file I/O) statement programming example, which uses the
  18453.  RESTORE statement.
  18454.  
  18455.  
  18456.  RESUME Statement
  18457.  ────────────────────────────────────────────────────────────────────────────
  18458.  
  18459.  
  18460.  Action
  18461.  
  18462.  Resumes program execution after an error-handling routine is finished.
  18463.  
  18464.  
  18465.  Syntax
  18466.  
  18467.  
  18468.   RESUME { 0 |  NEXT |   line}
  18469.  
  18470.  Remarks
  18471.  
  18472.  
  18473.  The different forms of the  RESUME statement redirect program flow as
  18474.  described in the following list:
  18475.  
  18476. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  18477.  Part                                    Description
  18478.  ────────────────────────────────────────────────────────────────────────────
  18479.   RESUME 0                               Program execution resumes with the
  18480.                                          statement that caused the error,
  18481.                                          or at the most recent call out of
  18482.  Part                                    Description
  18483.  ────────────────────────────────────────────────────────────────────────────
  18484.                                         or at the most recent call out of
  18485.                                          the error-handling procedure or
  18486.                                          module.
  18487.  
  18488.   RESUME  NEXT                           Execution resumes with the
  18489.                                          statement immediately following
  18490.                                          the one that caused the error, or
  18491.                                          with the statement immediately
  18492.                                          following the most recent call out
  18493.                                          of the error-handling procedure or
  18494.                                          module.
  18495.  
  18496.   line                                   Execution resumes at  line, a
  18497.                                          label or a line number. The
  18498.                                          argument  line must be in the same
  18499.                                          procedure (for local
  18500.                                          error-handlers) or within the same
  18501.                                          module (for module-level
  18502.                                          error-handlers).
  18503.  Part                                    Description
  18504.  ────────────────────────────────────────────────────────────────────────────
  18505.                                         error-handlers).
  18506.  
  18507.  
  18508.  
  18509.  
  18510.  
  18511.  The location where execution resumes is based on the location of the error
  18512.  handler in which the error is trapped, not necessarily on the location where
  18513.  the error occurred.
  18514.  
  18515.  The following table summarizes the resumption rules for the  RESUME  0
  18516.  statement:
  18517.  
  18518. ╓┌──────────────────────┌─────────────────────────┌──────────────────────────╖
  18519.  Error handler          Location of error         Where program resumes
  18520.  ────────────────────────────────────────────────────────────────────────────
  18521.  Local                  Same procedure            Statement that caused
  18522.                                                   error
  18523.  
  18524.  Error handler          Location of error         Where program resumes
  18525.  ────────────────────────────────────────────────────────────────────────────
  18526. 
  18527.  Module level           Same module               Statement that caused
  18528.                                                   error
  18529.  
  18530.  Local or module level  Another procedure, same   Statement that last
  18531.                         or another module         called out of the
  18532.                                                   procedure or module that
  18533.                                                   contains the error
  18534.                                                   handler
  18535.  
  18536.  
  18537.  
  18538.  
  18539.  
  18540.  
  18541.  Note
  18542.  
  18543.  If BASIC had to search for the error handler (the error handler that
  18544.  contains the  RESUME statement is in a procedure or module other than the
  18545.  one in which the the error occurred), then the last statement executed in
  18546.  that procedure (or module) is the last call out of that procedure or module.
  18547.  
  18548.  As a rule, avoid using a  line argument with a  RESUME statement in a
  18549.  module-level error handler, unless you expect errors to occur only at the
  18550.  module level.
  18551.  
  18552.  
  18553.  If you use a  RESUME statement outside an error-handling routine, BASIC
  18554.  generates the error message RESUME without error.
  18555.  
  18556.  When an error handling routine is active and the end of the program text is
  18557.  encountered before executing a  RESUME statement, BASIC generates the error
  18558.  message No RESUME. This also is true if an  END statement (or an  END  SUB,
  18559.  END  FUNCTION, or  END  DEF statement for a local error handler) is executed
  18560.  before a  RESUME.
  18561.  
  18562.  
  18563.  Note
  18564.  
  18565.  Programs containing error-handling routines must be compiled with either the
  18566.  /E (On error) or /X (Resume next) options when you are compiling from the
  18567.  BASIC command line.
  18568.  
  18569.  
  18570.  See Also
  18571.  
  18572.   ON  ERROR
  18573.  
  18574.  
  18575.  Example
  18576.  
  18577.  See the  ON ERROR statement programming example, which uses the  RESUME
  18578.  statement.
  18579.  
  18580.  
  18581.  RETRIEVE Statement
  18582.  ────────────────────────────────────────────────────────────────────────────
  18583.  
  18584.  
  18585.  Action
  18586.  
  18587.  Fetches the current record in an ISAM table and places its data into a
  18588.  record variable.
  18589.  
  18590.  
  18591.  Syntax
  18592.  
  18593.  
  18594.   RETRIEVE #  filenumber%,  recordvariable
  18595.  
  18596.  Remarks
  18597.  
  18598.  
  18599.   RETRIEVE places the current record's data into  recordvariable. You can
  18600.  change the data in  recordvariable, then update the current record with the
  18601.  changes you've made. Use the  UPDATE statement to update the current record.
  18602.  
  18603.  
  18604.  The  RETRIEVE statement uses the following arguments:
  18605.  
  18606. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  18607.  Argument                                Description
  18608.  Argument                                Description
  18609.  ────────────────────────────────────────────────────────────────────────────
  18610.   filenumber%                            The number used in the  OPEN
  18611.                                          statement to open the table.
  18612.  
  18613.   recordvariable                         The name of the variable that will
  18614.                                          hold the current record's data. It
  18615.                                          is a variable of the user-defined
  18616.                                          type  tabletype that was specified
  18617.                                          in the  OPEN statement.
  18618.  
  18619.  
  18620.  
  18621.  
  18622.  
  18623.   RETRIEVE has no effect on the current position.
  18624.  
  18625.  If the values passed to  recordvariable do not match the record strucure in
  18626.  the user-defined type, BASIC generates the error message Type Mismatch.The
  18627.  record structure includes the names and types of columns or fields.
  18628.  
  18629.  
  18630.  See Also
  18631.  
  18632.   INSERT,  UPDATE
  18633.  
  18634.  
  18635.  Example
  18636.  
  18637.  See the programming example for the  SEEKGT,  SEEKGE, and  SEEKEQ
  18638.  statements, which uses the  RETRIEVE statement.
  18639.  
  18640.  
  18641.  RETURN Statement
  18642.  ────────────────────────────────────────────────────────────────────────────
  18643.  
  18644.  
  18645.  Action
  18646.  
  18647.  Returns control from a routine.
  18648.  
  18649.  
  18650.  Syntax
  18651.  
  18652.  
  18653.   RETURN { linelabel |  linenumber}
  18654.  
  18655.  Remarks
  18656.  
  18657.  
  18658.  Without a line label or number,  RETURN continues execution where an event
  18659.  occurred (for event handling) or at the statement following the  GOSUB
  18660.  statement (for subroutine calls).  GOSUB and  RETURN without a line number
  18661.  can be used anywhere in a program, but the  GOSUB and corresponding  RETURN
  18662.  must be at the same level.
  18663.  
  18664.  The  linelabel or  linenumber in the  RETURN statement causes an
  18665.  unconditional return from a  GOSUB subroutine to the specified line.  RETURN
  18666.  with a line label or line number can return control to a statement in the
  18667.  module-level code only, not in procedure-level code.
  18668.  
  18669.  A  RETURN statement cannot be used to return control to a calling program
  18670.  from a  SUB procedure. Use  EXIT SUB for this purpose.
  18671.  
  18672.  
  18673.  Note
  18674.  
  18675.  BASIC's  SUB procedures provide a better-structured alternative to  GOSUB
  18676.  subroutines.
  18677.  
  18678.  
  18679.  See Also
  18680.  
  18681.   EXIT,  GOSUB,  ON  event
  18682.  
  18683.  
  18684.  Example
  18685.  
  18686.  See the  GOSUB statement programming example, which uses the  RETURN
  18687.  statement.
  18688.  
  18689.  
  18690.  RIGHT$ Function
  18691.  ────────────────────────────────────────────────────────────────────────────
  18692.  
  18693.  
  18694.  Action
  18695.  
  18696.  Returns a string consisting of the rightmost  n% characters of a string.
  18697.  
  18698.  
  18699.  Syntax
  18700.  
  18701.  
  18702.   RIGHT$( stringexpression$,  n%)
  18703.  
  18704.  Remarks
  18705.  
  18706.  
  18707.  The argument  stringexpression$ can be any string variable, string constant,
  18708.  or string expression.
  18709.  
  18710.  The argument  n% is a numeric expression between 0 and 32,767, inclusive,
  18711.  indicating how many characters are to be returned.
  18712.  
  18713.  If  n% is 0, the null string (length 0) is returned.
  18714.  
  18715.  If  n% is greater than or equal to the number of characters in
  18716.  stringexpression$, the entire string is returned. To find the number of
  18717.  characters in  stringexpression$, use  LEN( stringexpression$) .
  18718.  
  18719.  
  18720.  See Also
  18721.  
  18722.   LEFT$,  MID$ Function
  18723.  
  18724.  
  18725.  Example
  18726.  
  18727.  The following example converts names entered in the form "Firstname
  18728.  [Middlename] Lastname" to the form "Lastname, Firstname [Middlename]."
  18729.  
  18730.  CLS' Clear screen.
  18731.  
  18732.  LINE INPUT "Name: "; Nm$
  18733.  
  18734.  I = 1 : Sppos = 0
  18735.  
  18736.  DO WHILE I > 0
  18737.  
  18738.      I = INSTR(Sppos + 1, Nm$, " ")' Get position of next space.
  18739.  
  18740.      IF I > 0 THEN Sppos = I
  18741.  
  18742.  LOOP
  18743.  
  18744.  
  18745.  
  18746.  ' Sppos now points to the position of the last space.
  18747.  
  18748.  IF Sppos = 0 THEN
  18749.  
  18750.      PRINT Nm$ ' Only a last name was input.
  18751.  
  18752.  ELSE
  18753.  
  18754.      ' Everything after last space.
  18755.  
  18756.      Lastname$ = RIGHT$(Nm$, LEN(Nm$) - Sppos)
  18757.  
  18758.      ' Everything before last space.
  18759.  
  18760.      Firstname$ = LEFT$(Nm$, Sppos - 1)
  18761.  
  18762.      PRINT Lastname$ ", " Firstname$
  18763.  
  18764.  END IF
  18765.  
  18766.  END
  18767.  
  18768.  RMDIR Statement
  18769.  ────────────────────────────────────────────────────────────────────────────
  18770.  
  18771.  
  18772.  Action
  18773.  
  18774.  Removes an existing directory.
  18775.  
  18776.  
  18777.  Syntax
  18778.  
  18779.  
  18780.   RMDIR  pathname$
  18781.  
  18782.  Remarks
  18783.  
  18784.  
  18785.  The  pathname$ is the name of the directory that is to be deleted. The
  18786.  pathname$ must be a string of fewer than 64 characters. The directory to be
  18787.  removed must be empty except for the working directory ( '.' ) and the
  18788.  parent directory ( '..' ); otherwise, BASIC generates one of two error
  18789.  messages, either Path not found or Path/File access error.
  18790.  
  18791.   RMDIR works like the DOS command of the same name. However, the syntax in
  18792.  BASIC cannot be shortened to RD, as it can in DOS.
  18793.  
  18794.  
  18795.  See Also
  18796.  
  18797.   CHDIR,  MKDIR
  18798.  
  18799.  
  18800.  Example
  18801.  
  18802.  The following example shows how to use  RMDIR to remove a subdirectory.
  18803.  
  18804.  CHDIR "C:\SALES\TEMP"' Move to \TEMP subdirectory in \SALES.
  18805.  
  18806.  KILL "*.*" ' Remove all files in \TEMP.
  18807.  
  18808.  CHDIR ".." ' Move back up to \SALES.
  18809.  
  18810.  RMDIR "TEMP"' Remove \TEMP subdirectory.
  18811.  
  18812.  RND Function
  18813.  ────────────────────────────────────────────────────────────────────────────
  18814.  
  18815.  
  18816.  Action
  18817.  
  18818.  Returns a single-precision random number between 0 and 1.
  18819.  
  18820.  
  18821.  Syntax
  18822.  
  18823.  
  18824.   RND ( n#)
  18825.  
  18826.  Remarks
  18827.  
  18828.  
  18829.  The value of  n# determines how  RND generates the next random number:
  18830.  
  18831. ╓┌──────────────────────┌────────────────────────────────────────────────────╖
  18832.  Value                  Number returned
  18833.  ────────────────────────────────────────────────────────────────────────────
  18834.   n# < 0                Always returns the same number for any given  n#.
  18835.   n# > 0 or  n omitted  Returns the next random number in the sequence.
  18836.   n# = 0                Returns the last number generated.
  18837.  
  18838.  
  18839.  
  18840.  
  18841.  Even if  n# > 0, the same sequence of random numbers is generated each time
  18842.  the program is run unless you initialize the random-number generator each
  18843.  time. (See the  RANDOMIZE statement entry for more information about
  18844.  initializing the random-number generator.)
  18845.  
  18846.  To produce random  integers in a given range, use this formula:
  18847.  
  18848.   INT (( upperbound -  lowerbound + 1) *  RND +  lowerbound)
  18849.  
  18850.  In this formula,  upperbound is the highest number in the range, and
  18851.  lowerbound is the lowest number in the range.
  18852.  
  18853.  
  18854.  Example
  18855.  
  18856.  See the  RANDOMIZE statement programming example, which uses the  RND
  18857.  function.
  18858.  
  18859.  
  18860.  ROLLBACK, ROLLBACK ALL Statements
  18861.  ────────────────────────────────────────────────────────────────────────────
  18862.  
  18863.  
  18864.  Action
  18865.  
  18866.  Rescind all or part of the operations of a transaction (a series of ISAM
  18867.  database operations).
  18868.  
  18869.  
  18870.  Syntax
  18871.  
  18872.  
  18873.   ROLLBACK  savepoint%
  18874.  
  18875.   ROLLBACK  ALL
  18876.  
  18877.  Remarks
  18878.  
  18879.  
  18880.  The  savepoint% is an integer that identifies a savepoint within a
  18881.  transaction -- a series of ISAM database operations that is either committed
  18882.  as a whole or rescinded. Use the savepoint function to designate a
  18883.  savepoint, which marks the beginning of a subset of operations that can be
  18884.  rescinded.
  18885.  
  18886.  If you specify a  savepoint% argument,  ROLLBACK returns the data affected
  18887.  by a transaction to its state at that savepoint.
  18888.  
  18889.  If you do not specify a  savepoint% argument,  ROLLBACK returns the data
  18890.  affected by the transaction to its state at the previous savepoint, or at
  18891.  the beginning of the transaction if there are no intermediate savepoints.
  18892.  
  18893.   ROLLBACK  ALL rescinds all operations in a transaction and returns the data
  18894.  to its initial state at the beginning of the transaction. Use  BEGINTRANS to
  18895.  indicate the beginning of a transaction. Use  COMMITTRANS to commit all
  18896.  operations since the most recent  BEGINTRANS statement.
  18897.  
  18898.  
  18899.  See Also
  18900.  
  18901.   BEGINTRANS,  COMMITTRANS,  SAVEPOINT
  18902.  
  18903.  
  18904.  Example
  18905.  
  18906.  See the  BEGINTRANS statement programming example, which uses the  ROLLBACK
  18907.  statement.
  18908.  
  18909.  
  18910.  RSET Statement
  18911.  ────────────────────────────────────────────────────────────────────────────
  18912.  
  18913.  
  18914.  Action
  18915.  
  18916.  Moves data from memory to a random-access file buffer (in preparation for a
  18917.  PUT statement), or right-justifies the value of a string in a string
  18918.  variable.
  18919.  
  18920.  
  18921.  Syntax
  18922.  
  18923.  
  18924.   RSET  stringvariable$ =  stringexpression$
  18925.  
  18926.  Remarks
  18927.  
  18928.  
  18929.  The  RSET statement uses the following arguments:
  18930.  
  18931. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  18932.  Argument                                Description
  18933.  ────────────────────────────────────────────────────────────────────────────
  18934.   stringvariable$                        Usually a random-access file field
  18935.                                          defined in a  FIELD statement,
  18936.                                          although it can be any string
  18937.                                          variable.
  18938.  
  18939.   stringexpression$                      The value that is assigned to
  18940.                                          stringvariable$ and is
  18941.                                          right-justified.
  18942.  
  18943.  
  18944.  
  18945.  
  18946.  
  18947.  If  stringexpression$ requires fewer bytes than were defined for
  18948.  stringvariable$ in the  FIELD statement, the  RSET statement right-justifies
  18949.  the string in the field ( LSET left-justifies the string). Spaces are used
  18950.  to pad the extra positions. If the string is too long for the field, both
  18951.  LSET and  RSET truncate characters from the right. Numeric values must be
  18952.  converted to strings before they are justified with the  RSET or  LSET
  18953.  statements.
  18954.  
  18955.  The  RSET statement can be used with string variables unrelated to  FIELD
  18956.  statements. When used with a fixed-length string variable, the value is
  18957.  right-justified and left-padded with blanks.
  18958.  
  18959.  When  RSET is used with a variable-length string, the string is treated as a
  18960.  fixed field. The length of the field is the length of the value the variable
  18961.  had before the  RSET statement.
  18962.  
  18963.  
  18964.  See Also
  18965.  
  18966.   FIELD;  LSET;  MKI$,  MKL$,  MKS$,  MKD$,  MKC$;  PUT (File I/O)
  18967.  
  18968.  
  18969.  Example
  18970.  
  18971.  See the  LSET statement programming example, which uses the  RSET statement.
  18972.  
  18973.  
  18974.  RTRIM$ Function
  18975.  ────────────────────────────────────────────────────────────────────────────
  18976.  
  18977.  
  18978.  Action
  18979.  
  18980.  Returns a string with trailing (rightmost) spaces removed.
  18981.  
  18982.  
  18983.  Syntax
  18984.  
  18985.  
  18986.   RTRIM$( stringexpression$)
  18987.  
  18988.  Remarks
  18989.  
  18990.  
  18991.  The  stringexpression$ can be any string expression. The  RTRIM$ function
  18992.  works with both fixed- and variable-length string variables.
  18993.  
  18994.  
  18995.  See Also
  18996.  
  18997.   LTRIM$
  18998.  
  18999.  
  19000.  Example
  19001.  
  19002.  The following example shows the effects of  RTRIM$ on fixed- and
  19003.  variable-length strings:
  19004.  
  19005.  DIM FixStr AS STRING * 10
  19006.  
  19007.  CLS    ' Clear screen.
  19008.  
  19009.  PRINT "         1         2"
  19010.  
  19011.  PRINT "12345678901234567890"
  19012.  
  19013.  FixStr = "Twine"
  19014.  
  19015.  PRINT FixStr + "*"
  19016.  
  19017.  PRINT RTRIM$(FixStr) + "*"
  19018.  
  19019.  VarStr$ = "Braided" + SPACE$(10)
  19020.  
  19021.  PRINT VarStr$ + "*"
  19022.  
  19023.  PRINT RTRIM$(VarStr$) + "*"
  19024.  
  19025.  
  19026.  
  19027.  Output
  19028.  
  19029.  
  19030.  
  19031.  
  19032.  
  19033.           1         2
  19034.  12345678901234567890
  19035.  Twine     *
  19036.  Twine*
  19037.  Braided          *
  19038.  Braided*
  19039.  
  19040.  RUN Statement
  19041.  ────────────────────────────────────────────────────────────────────────────
  19042.  
  19043.  
  19044.  Action
  19045.  
  19046.  Restarts the program currently in memory, or executes a specified program.
  19047.  
  19048.  
  19049.  Syntax
  19050.  
  19051.  
  19052.   RUN { linenumber |  filespec$}
  19053.  
  19054.  Remarks
  19055.  
  19056.  
  19057.  The  RUN statement uses the following arguments:
  19058.  
  19059. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  19060.  Argument                                Description
  19061.  ────────────────────────────────────────────────────────────────────────────
  19062.   linenumber                             The numeric label of the line
  19063.                                          where execution begins. If no
  19064.                                          argument is given, execution
  19065.                                          begins at the first executable
  19066.                                          line of code.
  19067.  
  19068.   filespec$                              A string expression that names the
  19069.                                          program file to load and run. The
  19070.  Argument                                Description
  19071.  ────────────────────────────────────────────────────────────────────────────
  19072.                                         program file to load and run. The
  19073.                                          current program is cleared from
  19074.                                          memory before the specified
  19075.                                          program is loaded.
  19076.  
  19077.  
  19078.  
  19079.  The line where execution begins must be in the module-level code. Therefore,
  19080.  a  RUN statement in a  SUB or  FUNCTION procedure must point to labels at
  19081.  module level. If no line label is given, execution always starts with the
  19082.  first executable line of the main module.
  19083.  
  19084.  Program lines can have line numbers or alphanumeric labels, such as
  19085.  OpenWindow:. If an alphanumeric label is the target of a  RUN statement, the
  19086.  compiler generates the error message String expression required.
  19087.  
  19088.  You do not need to specify the filename extension in  filespec$. The .BAS
  19089.  extension is assumed in the QBX environment, whereas the .EXE extension is
  19090.  assumed for compiled, stand-alone programs. If the program you wish to run
  19091.  has a different extension, you must give the extension. If the program name
  19092.  has no extension, the filename given must end with a period. For example,
  19093.  the following statement would execute CATCHALL.EXE from a BC-compiled
  19094.  program, and CATCHALL.BAS from within the QBX environment:
  19095.  
  19096.  RUN "CATCHALL"
  19097.  
  19098.  Programs running within the QBX environment must call only BASIC program
  19099.  files. The file is loaded and run as if it were a BASIC program; if it is
  19100.  not in the BASIC program format, execution halts. The error message that
  19101.  results varies, depending on the file's contents. Likewise, programs
  19102.  compiled with the compiler must not invoke BASIC source files, as these run
  19103.  only in the QBX environment.
  19104.  
  19105.  An executable file need not have been written in BASIC. Any executable file
  19106.  can be run.
  19107.  
  19108.  When running a program in the QBX environment, if an executable file
  19109.  matching the filename in the command line cannot be found, BASIC generates
  19110.  the error message File not found and control returns to BASIC. When running
  19111.  a program compiled by BC, BASIC generates the error message File not found
  19112.  in module module-name at address segment:offset and control returns to the
  19113.  operating system.
  19114.  
  19115.  
  19116.  
  19117.  When the invoked program completes execution, control does not return to the
  19118.  invoking program. If the invoking program ran outside QBX, control returns
  19119.  to the operating system. If the invoking program ran under QBX, control
  19120.  returns to BASIC.
  19121.  
  19122.  
  19123.   RUN closes all files and clears program memory before loading the
  19124.  designated program. The compiler does not support the R option from BASICA.
  19125.  (The R option keeps all open data files open.) If you want to run a
  19126.  different program, but leave open files open, use the  CHAIN statement.
  19127.  
  19128.  
  19129.  
  19130.  See Also
  19131.  
  19132.  
  19133.   CHAIN
  19134.  
  19135.  
  19136.  
  19137.  Example
  19138.  
  19139.  
  19140.  This example shows how  RUN  linenumber resets all numeric variables to 0.
  19141.  As the line number following  RUN increases in lines 60, 70, 80, and 90, the
  19142.  variables in the earlier statements lose their assigned values.
  19143.  
  19144.  10 A = 9
  19145.  
  19146.  20 B = 7
  19147.  
  19148.  30 C = 5
  19149.  
  19150.  40 D = 4
  19151.  
  19152.  50 PRINT A, B, C, D
  19153.  
  19154.  60 IF A = 0 THEN 70 ELSE RUN 20
  19155.  
  19156.  70 IF B = 0 THEN 80 ELSE RUN 30
  19157.  
  19158.  80 IF C = 0 THEN 90 ELSE RUN 40
  19159.  
  19160.  90 IF D = 0 THEN END ELSE RUN 50
  19161.  
  19162.  
  19163.  
  19164.  Output
  19165.  
  19166.  
  19167.  
  19168.  
  19169.  
  19170.  9     7     5     4
  19171.  0     7     5     4
  19172.  0     0     5     4
  19173.  0     0     0     4
  19174.  0     0     0     0
  19175.  
  19176.  SADD Function
  19177.  ────────────────────────────────────────────────────────────────────────────
  19178.  
  19179.  
  19180.  Action
  19181.  
  19182.  Returns the address of a specified string variable.
  19183.  
  19184.  
  19185.  Syntax
  19186.  
  19187.   SADD( stringvariable$)
  19188.  
  19189.  Remarks
  19190.  
  19191.  
  19192.  The  SADD function returns the address of a string as an offset (near
  19193.  pointer) from the current data segment. The offset is a two-byte integer.
  19194.  SADD is most often used in mixed-language programming to obtain far
  19195.  addresses before passing far strings to procedures written in other
  19196.  languages.
  19197.  
  19198.  The argument  stringvariable$ is the string whose offset you want to
  19199.  determine. It can be a simple string variable or a single element of a
  19200.  string array. You cannot use fixed-length string arguments.
  19201.  
  19202.   SADD can be used with both near and far strings. To obtain the segment
  19203.  address of a far string, use the  SSEG function. In previous versions of
  19204.  BASIC,  SADD was used only for near strings.
  19205.  
  19206.  
  19207.  Note
  19208.  
  19209.  Do not add characters to the beginning or end of a string passed using  SADD
  19210.  and  LEN. Adding characters can cause BASIC to generate a run-time error.
  19211.  Use this function with caution, because strings can move in the BASIC string
  19212.  space (storage area) at any time.
  19213.  
  19214.  
  19215.  See Also
  19216.  
  19217.   BLOAD;  BSAVE;  DEF SEG;  FRE;  PEEK;  POKE;  SSEG;  SSEGADD;  VARPTR,
  19218.  VARSEG;  VARPTR$
  19219.  
  19220.  
  19221.  Example
  19222.  
  19223.  The following example illustrates the use of the  SADD and  SSEG functions.
  19224.  SADD returns the offset address of a variable-length string.  SSEG returns
  19225.  the segment of a variable-length string. Typically these functions are used
  19226.  in mixed-language programs or with  PEEK,  POKE,  BLOAD, or  BSAVE.
  19227.  
  19228.  In this example, a string is created and then its offset and segment are
  19229.  calculated with  SADD and  SSEG. The information is then passed to a BASIC
  19230.  SUB procedure that mimics the performance of a non-BASIC print routine.
  19231.  
  19232.  DEFINT A-Z
  19233.  
  19234.  ' Create the string.
  19235.  
  19236.  Text$ = ".... a few well-chosen words"
  19237.  
  19238.  
  19239.  
  19240.  ' Calculate the offset, segment, and length of the string.
  19241.  
  19242.  Offset = SADD(Text$)
  19243.  
  19244.  Segment = SSEG(Text$)
  19245.  
  19246.  Length = LEN(Text$)
  19247.  
  19248.  
  19249.  
  19250.  ' Pass these arguments to the print routine.
  19251.  
  19252.  
  19253.  CALL printit(Segment, Offset, Length)
  19254.  
  19255.  
  19256.  
  19257.  SUB printit (Segment, Offset, Length)
  19258.  
  19259.      CLS
  19260.  
  19261.      ' Set the segment for the PEEK function.
  19262.  
  19263.      DEF SEG = Segment
  19264.  
  19265.      FOR i = 0 TO Length - 1
  19266.  
  19267.          ' Get each character from memory, convert to ASCII, and display.
  19268.  
  19269.          PRINT CHR$(PEEK(i + Offset));
  19270.  
  19271.      NEXT i
  19272.  
  19273.  END SUB
  19274.  
  19275.  
  19276.  SAVEPOINT Function
  19277.  ────────────────────────────────────────────────────────────────────────────
  19278.  
  19279.  
  19280.  Action
  19281.  
  19282.  Marks the beginning of a subset of ISAM database operations in a
  19283.  transaction.
  19284.  
  19285.  
  19286.  Syntax
  19287.  
  19288.  
  19289.  
  19290.   SAVEPOINT
  19291.  
  19292.  Remarks
  19293.  
  19294.  
  19295.  The  SAVEPOINT function marks the beginning of a subset of operations within
  19296.  a transaction that can be rescinded using a  ROLLBACK statement. The
  19297.  function returns an integer that refers to the savepoint.
  19298.  
  19299.  Transactions are a way to group a series of ISAM operations so that you can
  19300.  commit them as a whole, rescind them all, or rescind operations since a
  19301.  designated savepoint. Use  BEGINTRANS to indicate the beginning of a
  19302.  transaction and  COMMITTRANS to commit all operations since the beginning of
  19303.  a transaction.
  19304.  
  19305.  Use  ROLLBACK with the argument  savepoint% to return the data affected by a
  19306.  transaction to its state at that savepoint. Use  ROLLBACK with no argument
  19307.  to return the data affected by the transaction to its state at the most
  19308.  recent savepoint, or at the beginning of the transaction if there are no
  19309.  intermediate savepoints.
  19310.  
  19311.   ROLLBACK ALL rescinds all ISAM operations in a transaction and returns the
  19312.  data to its initial state at the beginning of the transaction.
  19313.  
  19314.  If there is no transaction pending when you use  SAVEPOINT, BASIC generates
  19315.  the error message Illegal function call.
  19316.  
  19317.  
  19318.  See Also
  19319.  
  19320.   BEGINTRANS,  COMMITTRANS,  ROLLBACK
  19321.  
  19322.  
  19323.  Example
  19324.  
  19325.  See the  BEGINTRANS statement programming example, which uses the  SAVEPOINT
  19326.  function.
  19327.  
  19328.  
  19329.  SCREEN Function
  19330.  ────────────────────────────────────────────────────────────────────────────
  19331.  
  19332.  
  19333.  Action
  19334.  
  19335.  Reads a specified character's ASCII value or its color from a specified
  19336.  screen location.
  19337.  
  19338.  
  19339.  Syntax
  19340.  
  19341.  
  19342.  
  19343.   SCREEN( line%,  column% ,  colorflag%)
  19344.  
  19345.  Remarks
  19346.  
  19347.  
  19348.  The  SCREEN function uses the following arguments:
  19349.  
  19350. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  19351.  Argument                                Description
  19352.  ────────────────────────────────────────────────────────────────────────────
  19353.   line%                                  The line number of the character
  19354.                                          location on the screen. The
  19355.                                          argument  line% is an integer
  19356.                                          expression whose valid range
  19357.                                          depends on the number of lines on
  19358.                                          screen.
  19359.  
  19360.   column%                                The column number of the character
  19361.                                          location on the screen. The
  19362.                                          argument  column% is an integer
  19363.                                          expression with a value between 1
  19364.  Argument                                Description
  19365.  ────────────────────────────────────────────────────────────────────────────
  19366.                                         expression with a value between 1
  19367.                                          and 80, inclusive.
  19368.  
  19369.   colorflag%                             A numeric expression that
  19370.                                          determines which information is
  19371.                                          returned. When  colorflag% is
  19372.                                          nonzero,  SCREEN returns the
  19373.                                          number of the color attribute at
  19374.                                          the screen location. If
  19375.                                          colorflag% is 0 or is absent, the
  19376.                                          SCREEN function returns the ASCII
  19377.                                          character code.
  19378.  
  19379.  
  19380.  
  19381.  
  19382.  
  19383.  
  19384.  Note
  19385.  
  19386.  In graphics screen modes, if the pattern on the screen at the given
  19387.  character location does not exactly match any pattern in the current ASCII
  19388.  character set, the  SCREEN function will return the ASCII code for a space.
  19389.  If  colorflag% is nonzero, the  SCREEN function will return 0.
  19390.  
  19391.  
  19392.  See Also
  19393.  
  19394.  Appendix A, "Keyboard Scan Codes and ASCII Character Codes,"  COLOR,
  19395.  PALETTE,  SCREEN Statement
  19396.  
  19397.  
  19398.  Examples
  19399.  
  19400.  If the character at (10,10) is A, then the following statement would return
  19401.  65, the ASCII code for A, to the variable X:
  19402.  
  19403.  X = SCREEN(10,10)
  19404.  
  19405.  The following statement returns the color attribute of the character in the
  19406.  upper-left corner of the screen:
  19407.  
  19408.  X = SCREEN(1, 1, 1)
  19409.  
  19410.  
  19411.  SCREEN Statement
  19412.  ────────────────────────────────────────────────────────────────────────────
  19413.  
  19414.  
  19415.  Action
  19416.  
  19417.  Sets the specifications for the graphics adapter and monitor.
  19418.  
  19419.  
  19420.  Syntax
  19421.  
  19422.  
  19423.  
  19424.   SCREEN  mode% ,  colorswitch% ,  activepage% ,  visiblepage%
  19425.  
  19426.  Remarks
  19427.  
  19428.  
  19429.  The  SCREEN statement sets a screen mode for a particular combination of
  19430.  display and adapter. Later sections in this entry describe the available
  19431.  modes for specific adapters. The  SCREEN statement uses the following
  19432.  arguments:
  19433.  
  19434. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  19435.  Argument                                Description
  19436.  ────────────────────────────────────────────────────────────────────────────
  19437.   mode%                                  An integer constant or expression
  19438.                                          that selects a screen mode for a
  19439.                                          particular combination of display
  19440.                                          and adapter (see "Summary of
  19441.                                          Screen Modes" later in this entry
  19442.                                          for information on what the
  19443.                                          acronyms represent). There also
  19444.                                          are more details on  mode% later
  19445.                                          in this entry.
  19446.  
  19447.   colorswitch%                           Integer expression that switches
  19448.  Argument                                Description
  19449.  ────────────────────────────────────────────────────────────────────────────
  19450.  colorswitch%                           Integer expression that switches
  19451.                                          composite monitor display between
  19452.                                          color and monocolor (modes 0 and 1
  19453.                                          only). See below for more details
  19454.                                          on  colorswitch%.
  19455.  
  19456.   activepage%                            Integer expression that identifies
  19457.                                          the screen page that text or
  19458.                                          graphics output is written to.
  19459.  
  19460.   visiblepage%                           Integer expression that identifies
  19461.                                          the screen page that is displayed.
  19462.  
  19463.  
  19464.  
  19465.  The  colorswitch% is effective only for screen modes 0 and 1 and for
  19466.  composite monitors. In screen mode 0, use a  colorswitch% value of 0 to
  19467.  disable color, and a non-zero value to enable color. In screen mode 1, use a
  19468.  non-zero value to disable color and 0 to enable color.
  19469.  
  19470.  See "Adapters, Screen Modes, and Displays" later in this entry for the valid
  19471.  ranges for  activepage% and  visiblepage% for each graphics adapter. The
  19472.  "Attributes and Colors" section lists the default color attributes for
  19473.  different screen modes. If  mode% is an expression, rather than a constant,
  19474.  and if you know your program will not use certain screen modes, you can
  19475.  achieve a smaller .EXE file by linking one or more stub files:
  19476.  
  19477. ╓┌─────────────────────────────────────┌─────────────────────────────────────╖
  19478.  If not using screen modes:            Link to file:
  19479.  ────────────────────────────────────────────────────────────────────────────
  19480.  1 or 2                                NOCGA.OBJ
  19481.  3                                     NOHERC.OBJ
  19482.  4                                     NOOGA.OBJ
  19483.  7, 8, 9, or 10                        NOEGA.OBJ
  19484.  11, 12, or 13                         NOVGA.OBJ
  19485.  
  19486.  
  19487.  
  19488.  If you do not need graphics in your custom run-time module (because the
  19489.  programs use screen mode 0 only), you can save 15K by creating the run-time
  19490.  module with NOGRAPH.OBJ.
  19491.  
  19492.  
  19493.  Summary of Screen Modes
  19494.  The following lists summarize each of the screen modes. The color adapters
  19495.  referred to are the IBM Monochrome Display and Printer Adapter (MDPA), the
  19496.  IBM Color Graphics Adapter (CGA), the IBM Enhanced Graphics Adapter (EGA),
  19497.  the IBM Video Graphics Array (VGA), the IBM Multicolor Graphics Array
  19498.  (MCGA), and the Olivetti Color Adapter. The Hercules Graphics Card, Graphics
  19499.  Card Plus and InColor adapters are supported, but only with monochrome
  19500.  monitors.
  19501.  
  19502.  
  19503.  
  19504.  Note
  19505.  
  19506.  Many screen modes support more than one combination of rows and columns. See
  19507.  the  WIDTH statement for more information about changing the number of rows
  19508.  and columns on the display.
  19509.  
  19510.  SCREEN 0
  19511.  
  19512.    ■         MDPA, CGA, EGA, MCGA, Hercules, Olivetti, or VGA Adapter Boards
  19513.  
  19514.    ■         Text mode only
  19515.  
  19516.    ■         40 x 25, 40 x 43, 40 x 50, 80 x 25, 80 x 43, or 80 x 50 text
  19517.              format with 8 x 8 character box size (8 x 14, 9 x 14, or 9 x 16
  19518.              with EGA or VGA)
  19519.  
  19520.    ■         16 colors assigned to two color attributes
  19521.  
  19522.    ■         16 colors assigned to any of 16 color attributes with CGA or EGA
  19523.  
  19524.    ■         64 colors assigned to any of 16 color attributes with EGA or VGA
  19525.  
  19526.  SCREEN 1
  19527.  
  19528.    ■         CGA, EGA, VGA, or MCGA Adapter Boards
  19529.  
  19530.    ■         320 x 200 graphics
  19531.  
  19532.    ■         40 x 25 text format, 8 x 8 character box
  19533.  
  19534.    ■         16 background colors and one of two sets of three foreground
  19535.              colors assigned using  COLOR statement with CGA
  19536.  
  19537.    ■         16 colors assigned to four color attributes with EGA, VGA or
  19538.              MCGA
  19539.  
  19540.  SCREEN 2
  19541.  
  19542.    ■         CGA, EGA, VGA, or MCGA Adapter Boards
  19543.  
  19544.    ■         640 x 200 graphics
  19545.  
  19546.    ■         80 x 25 text format with character box size of 8 x 8
  19547.  
  19548.    ■         2 colors (black and white) with CGA
  19549.  
  19550.    ■         16 colors assigned to two color attributes with EGA or VGA
  19551.  
  19552.  
  19553.  SCREEN 3
  19554.  
  19555.    ■         Hercules, Olivetti, or AT&T Adapter Boards
  19556.  
  19557.    ■         Hercules adapter required, monochrome monitor only
  19558.  
  19559.    ■         720 x 348 graphics
  19560.  
  19561.    ■         80 x 25 text format, 9 x 14 character box
  19562.  
  19563.    ■         Two screen pages (one only if a second display adapter is
  19564.              installed)
  19565.  
  19566.    ■          PALETTE statement not supported
  19567.  
  19568.  SCREEN 4
  19569.  
  19570.    ■         Hercules, Olivetti, or AT&T Adapter Boards
  19571.  
  19572.    ■         640 x 400 graphics
  19573.  
  19574.    ■         80 x 25 text format, 8 x 16 character box
  19575.  
  19576.    ■         One of 16 colors assigned as the foreground color (selected by
  19577.              the  COLOR statement); background fixed at black
  19578.  
  19579.    ■         Supports Olivetti Personal Computers models M24, M240, M28,
  19580.              M280, M380, M380/C, and M380/T, and AT&T Personal Computers 6300
  19581.              series
  19582.  
  19583.  Warning
  19584.  
  19585.  Olivetti personal computers running 3XBOX under OS/2 should avoid screen
  19586.  mode 4.
  19587.  
  19588.  
  19589.  SCREEN 7
  19590.  
  19591.    ■         EGA or VGA Adapters
  19592.  
  19593.    ■         320 x 200 graphics
  19594.  
  19595.    ■         40 x 25 text format, character box size 8 x 8
  19596.  
  19597.    ■         32K page size, pages 0-1 (64K adapter memory), 0-3 (128K), or
  19598.              0-7 (256K)
  19599.  
  19600.    ■         Assignment of 16 colors to any of 16 color attributes
  19601.  
  19602.  SCREEN 8
  19603.  
  19604.    ■         EGA or VGA Adapters
  19605.  
  19606.    ■         640 x 200 graphics
  19607.  
  19608.    ■         80 x 25 text format, 8 x 8 character box
  19609.  
  19610.    ■         64K page size, pages 0 (64K adapter memory), 0-1 (128K), or 0-3
  19611.              (256K)
  19612.  
  19613.    ■         Assignment of 16 colors to any of 16 color attributes
  19614.  
  19615.  SCREEN 9
  19616.  
  19617.    ■         EGA or VGA Adapters
  19618.  
  19619.    ■         640 x 350 graphics
  19620.  
  19621.    ■         80 x 25 or 80 x 43 text format, 8 x 14 or 8 x 8 character box
  19622.              size
  19623.  
  19624.    ■         64K page size, page 0 (64K adapter memory); 128K page size,
  19625.              pages 0 (128K adapter memory) or 0 - 1 (256K)
  19626.  
  19627.    ■         16 colors assigned to four color attributes (64K adapter
  19628.              memory), or 64 colors assigned to 16 color attributes (more than
  19629.              64K adapter memory)
  19630.  
  19631.  SCREEN 10
  19632.  
  19633.    ■         EGA or VGA adapters, monochrome monitor only
  19634.  
  19635.    ■         640 x 350 graphics, monochrome monitor only
  19636.  
  19637.    ■         80 x 25 or 80 x 43 text format, 8 x 14 or 8 x 8 character box
  19638.              size
  19639.  
  19640.    ■         128K page size, pages 0 (128K adapter memory) or 0 - 1 (256K)
  19641.  
  19642.    ■         Up to nine shades of gray assigned to four color attributes
  19643.  
  19644.  SCREEN 11
  19645.  
  19646.    ■         VGA or MCGA adapters
  19647.  
  19648.    ■         640 x 480 graphics
  19649.  
  19650.    ■         80 x 30 or 80 x 60 text format, character box size of 8 x 16 or
  19651.              8 x 8
  19652.  
  19653.    ■         Assignment of up to 256K colors to two color attributes
  19654.  
  19655.  SCREEN 12
  19656.  
  19657.    ■         VGA adapter
  19658.  
  19659.    ■         640 x 480 graphics
  19660.  
  19661.    ■         80 x 30 or 80 x 60 text format, character box size of 8 x 16 or
  19662.              8 x 8
  19663.  
  19664.    ■         Assignment of up to 256K colors to 16 color attributes
  19665.  
  19666.  SCREEN 13
  19667.  
  19668.    ■         VGA or MCGA adapters
  19669.  
  19670.    ■         320 x 200 graphics
  19671.  
  19672.    ■         40 x 25 text format, character box size of 8 x 8
  19673.  
  19674.    ■         Assignment of up to 256K colors to up to 256 color attributes
  19675.  
  19676.  Screen Modes, Adapters, and Displays
  19677.  This section describes the screen modes available for each adapter. If the
  19678.  display device also is a factor in choosing a screen mode, it is listed. The
  19679.  IBM Monochrome Display and Printer Adapter (MDPA) must be used with a
  19680.  monochrome display. Only SCREEN 0, text mode, can be used with the MDPA.
  19681.  
  19682.  
  19683.  Table 1.10 describes the screen mode available with the MDPA.
  19684.  
  19685.  Table 1.11 summarizes the screen modes available with Hercules Adapters.
  19686.  
  19687.  The IBM Color Graphics Adapter (CGA) and Color Display typically are paired.
  19688.  This combination permits running text-mode programs, and both
  19689.  medium-resolution and high-resolution graphics programs.
  19690.  
  19691.  Table 1.12 summarizes the screen modes available with the CGA.
  19692.  
  19693.  The IBM Enhanced Graphics Adapter (EGA) can be used with either the IBM
  19694.  Color Display or the Enhanced Color Display. In modes 0, 1, 2, 7, and 8,
  19695.  these pairings produce similar results, except for the following
  19696.  differences:
  19697.  
  19698.    ■         Border color can't be set on an Enhanced Color Display when it
  19699.              is in 640 x 350 text mode.
  19700.  
  19701.    ■         The text quality is better on the Enhanced Color Display (an 8 x
  19702.              14 character box for Enhanced Color Display versus an 8 x 8
  19703.              character box for Color Display).
  19704.  
  19705.  
  19706.  Screen mode 9 takes full advantage of the capabilities of the Enhanced Color
  19707.  Display. Mode 9 provides for the highest resolution possible for the
  19708.  EGA/Enhanced Color Display configuration. Programs written for this mode
  19709.  will not work for any other hardware configuration except the VGA.
  19710.  
  19711.  
  19712.  Table 1.13 summarizes the screen modes that can be used with an EGA.
  19713.  
  19714.  Only the EGA and VGA can be paired with the IBM Monochrome display to run
  19715.  programs in screen mode 10. This mode can be used to display monochrome
  19716.  graphics at a very high resolution with the optional effects of blinking and
  19717.  high intensity.
  19718.  
  19719.  The following two tables summarize the color attributes, display colors, and
  19720.  effects for screen mode 10 used with a monochrome display.
  19721.  
  19722.  Tables 1.14 and 1.15 summarize EGA and VGA adapters used with monochrome
  19723.  display (SCREEN 10).
  19724.  
  19725.  The IBM Video Graphics Array (VGA) adapter offers significantly enhanced
  19726.  text and graphics in all modes. Table 1.16 summarizes the modes available
  19727.  with the VGA.
  19728.  
  19729.  The IBM Multicolor Graphics Array (MCGA) combines the modes of the CGA with
  19730.  the very high resolution and 256K color modes of the VGA to provide enhanced
  19731.  text and graphics in all modes. Table 1.17 summarizes the modes supported by
  19732.  the MCGA.
  19733.  
  19734.  The MCGA uses the same display color values as the VGA. For a description of
  19735.  how the MCGA calculates display color values, see the  PALETTE statement.
  19736.  
  19737.  
  19738.  Attributes and Colors
  19739.  For various screen modes and display hardware configurations, different
  19740.  color-attribute and display-color settings exist. (See the  PALETTE
  19741.  statement for a discussion of color attributes and display colors.) The
  19742.  majority of these color-attribute and display-color configurations are
  19743.  summarized in Tables 1.18-1.20.
  19744.  
  19745.  Note
  19746.  
  19747.  In OS/2 protected mode, BASIC supports only screen modes 0 - 2 and does not
  19748.  support the  activepage% and  visiblepage% arguments.
  19749.  
  19750.  
  19751.  See Also
  19752.  
  19753.   COLOR,  PALETTE,  SCREEN Function,  WIDTH
  19754.  
  19755.  
  19756.  Example
  19757.  
  19758.  The following example sets up a multipage EGA or VGA mode 7 (320x200)
  19759.  display using the  SCREEN statement. A help screen is displayed for several
  19760.  seconds then copied (using the  PCOPY statement) to page 2 for later use. A
  19761.  cube is displayed and rotated on the screen. By pressing Shift+F1, the user
  19762.  can again see the help screen, after which the cube display is resumed.
  19763.  
  19764.  DEFINT A-Z
  19765.  
  19766.  ' Define a macro string to draw a cube and paint its sides.
  19767.  
  19768.  One$ = "BR30 BU25 C1 R54 U45 L54 D45 BE20 P1, 1G20 C2 G20"
  19769.  
  19770.  Two$ = "R54 E20 L54 BD5 P2, 2 U5 C4 G20 U45 E20 D45 BL5 P4, 4"
  19771.  
  19772.  Plot$ = One$ + Two$
  19773.  
  19774.  ' Initialize values for active page, visual page, and help page.
  19775.  
  19776.  APage% = 0 : VPage% = 1 : HPage% = 2
  19777.  
  19778.  Angle% = 0
  19779.  
  19780.  ' Create a HELP screen on the visual page.
  19781.  
  19782.  SCREEN 7, 0, VPage%, VPage%
  19783.  
  19784.  LOCATE 1, 18
  19785.  
  19786.  PRINT "HELP"
  19787.  
  19788.  LOCATE 5, 1
  19789.  
  19790.  PRINT "Press 'Alt+F1' keys to see this HELP"
  19791.  
  19792.  PRINT "screen while the cube is rotating"
  19793.  
  19794.  PRINT "around the center of the screen."
  19795.  
  19796.  PRINT
  19797.  
  19798.  PRINT "After a brief delay, the cube will"
  19799.  
  19800.  PRINT "resume at the next point in its rotation."
  19801.  
  19802.  PRINT
  19803.  
  19804.  PRINT "Press any other key to exit the program."
  19805.  
  19806.  ' Put a copy of the help screen in page 2.
  19807.  
  19808.  
  19809.  PCOPY VPage%, HPage%
  19810.  
  19811.  SLEEP 5
  19812.  
  19813.  DO
  19814.  
  19815.      SCREEN 7, 0, APage%, VPage%
  19816.  
  19817.      ' Clear the active page.
  19818.  
  19819.      CLS 1
  19820.  
  19821.      ' Rotate the cube Angle% degrees.
  19822.  
  19823.      DRAW "TA" + STR$(Angle%) + Plot$
  19824.  
  19825.      ' Angle% is some multiple of 15 degrees.
  19826.  
  19827.      Angle% = (Angle% + 15) MOD 360
  19828.  
  19829.  ' Drawing is complete. Make the cube visible in its     '  new position by
  19830.  swapping the active and visual pages.
  19831.  
  19832.  
  19833.  SWAP APage%, VPage%
  19834.  
  19835.      ' Check the keyboard input.
  19836.  
  19837.      Kbd$ = INKEY$
  19838.  
  19839.      SELECT CASE Kbd$
  19840.  
  19841.          ' If Shift+F1 is pressed, show the HELP page.
  19842.  
  19843.          CASE CHR$(0) + CHR$(104)
  19844.  
  19845.              PCOPY HPage%, APage%
  19846.  
  19847.              SLEEP 3
  19848.  
  19849.          ' Do nothing if no key is pressed.
  19850.  
  19851.          CASE ""
  19852.  
  19853.          CASE ELSE
  19854.  
  19855.              EXIT DO
  19856.  
  19857.      END SELECT
  19858.  
  19859.  LOOP
  19860.  
  19861.  END
  19862.  
  19863.  
  19864.  SEEK Function
  19865.  ────────────────────────────────────────────────────────────────────────────
  19866.  
  19867.  
  19868.  Action
  19869.  
  19870.  Returns the current file position.
  19871.  
  19872.  
  19873.  Syntax
  19874.  
  19875.  
  19876.  
  19877.  
  19878.  
  19879.   SEEK(  filenumber%)
  19880.  
  19881.  Remarks
  19882.  
  19883.  
  19884.  The argument  filenumber% is the number used in the  OPEN statement to open
  19885.  the file.  SEEK returns a value between 1 and 2,147,483,647, inclusive
  19886.  (equivalent to 231 -1).
  19887.  
  19888.   SEEK returns the number of the next record read or written when used on
  19889.  random-access files. For files opened in binary, output, append, or input
  19890.  mode,  SEEK returns the byte position in the file where the next operation
  19891.  is to take place. The first byte in a file is 1.
  19892.  
  19893.   SEEK returns zero when used on an ISAM table or on BASIC devices (SCRN,
  19894.  CONS, KYBD, COM n, LPT n, PIPE) that do not support  SEEK.
  19895.  
  19896.  
  19897.  See Also
  19898.  
  19899.   GET (File I/O);  OPEN;  PUT (File I/O);  SEEK Statement;  SEEKGT,  SEEKGE,
  19900.  SEEKEQ Statements
  19901.  
  19902.  
  19903.  Example
  19904.  
  19905.  See the  SEEK statement programming example, which uses the  SEEK function.
  19906.  
  19907.  
  19908.  SEEK Statement
  19909.  ────────────────────────────────────────────────────────────────────────────
  19910.  
  19911.  
  19912.  Action
  19913.  
  19914.  Sets the position in a file for the next read or write.
  19915.  
  19916.  
  19917.  Syntax
  19918.  
  19919.  
  19920.  
  19921.   SEEK #  filenumber%,  position&
  19922.  
  19923.  Remarks
  19924.  
  19925.  
  19926.  The  SEEK statement uses the following arguments:
  19927.  
  19928. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  19929.  Argument                                Description
  19930.  ────────────────────────────────────────────────────────────────────────────
  19931.  Argument                                Description
  19932.  ────────────────────────────────────────────────────────────────────────────
  19933.   filenumber%                            The number used in the  OPEN
  19934.                                          statement to open the file.
  19935.  
  19936.   position&                              A numeric expression that
  19937.                                          indicates where the next read or
  19938.                                          write occurs. The  position& value
  19939.                                          must be between 1 and
  19940.                                          2,147,483,647 (equivalent to 231
  19941.                                          -1), inclusive.
  19942.  
  19943.  
  19944.  
  19945.  
  19946.  
  19947.  For files opened in random-access mode,  position& is the number of a record
  19948.  in the file.
  19949.  
  19950.  For files opened in binary, input, output, or append mode,  position& is the
  19951.  byte position relative to the beginning of the file. The first byte in a
  19952.  file is at position 1; the second byte is at position 2, and so on. After a
  19953.  SEEK operation, the next file I/O operation starts at the specified byte
  19954.  position.
  19955.  
  19956.  
  19957.  Note
  19958.  
  19959.  Record numbers on a  GET or  PUT override the file positioning done by
  19960.  SEEK.
  19961.  
  19962.  Performing a file write after doing a  SEEK operation beyond the end of a
  19963.  file extends the file. If you attempt a  SEEK operation to a negative or
  19964.  zero position, BASIC generates the error message Bad record number.
  19965.  
  19966.  BASIC leaves the file position unchanged when you use  SEEK on an ISAM table
  19967.  or on BASIC devices (SCRN, CONS, KYBD, COM n, LPT n, PIPE) that do not
  19968.  support  SEEK.
  19969.  
  19970.  
  19971.  See Also
  19972.  
  19973.   GET (File I/O);  OPEN;  PUT (File I/O);  SEEK Function;  SEEKGT,  SEEKGE,
  19974.  SEEKEQ Statements
  19975.  
  19976.  
  19977.  
  19978.  Example
  19979.  
  19980.  The following example uses a combination of the  SEEK function and  SEEK
  19981.  statement to move the file position exactly one record back and rewrite the
  19982.  record if a variable is true (nonzero):
  19983.  
  19984.  CONST FALSE = 0, TRUE = NOT FALSE
  19985.  
  19986.  
  19987.  ' Define record fields and a user-type variable.
  19988.  
  19989.  
  19990.  TYPE TestRecord
  19991.  
  19992.  
  19993.     NameField  AS STRING * 20
  19994.  
  19995.  
  19996.     ScoreField AS SINGLE
  19997.  
  19998.  
  19999.  END TYPE
  20000.  
  20001.  
  20002.  DIM RecordVar AS TestRecord
  20003.  
  20004.  
  20005.  DIM I AS LONG
  20006.  
  20007.  
  20008.  ' This part of the program creates the random-access file used by the
  20009.  
  20010.  
  20011.  ' second part of the program, which demonstrates the SEEK statement.
  20012.  
  20013.  
  20014.  OPEN "TESTDAT2.DAT" FOR RANDOM AS #1 LEN = LEN(RecordVar)
  20015.  
  20016.  
  20017.  RESTORE
  20018.  
  20019.  
  20020.  READ NameField$, ScoreField
  20021.  
  20022.  
  20023.  I = 0
  20024.  
  20025.  
  20026.  DO WHILE NameField$ <> "END"
  20027.  
  20028.  
  20029.     I = I + 1
  20030.  
  20031.  
  20032.     RecordVar.NameField = NameField$
  20033.  
  20034.  
  20035.     RecordVar.ScoreField = ScoreField
  20036.  
  20037.  
  20038.     PUT #1, I, RecordVar
  20039.  
  20040.  
  20041.     READ NameField$, ScoreField
  20042.  
  20043.  
  20044.  LOOP
  20045.  
  20046.  
  20047.  CLOSE #1
  20048.  
  20049.  
  20050.    DATA "John Simmons", 100
  20051.  
  20052.  
  20053.    DATA "Allie Simpson", 95
  20054.  
  20055.  
  20056.    DATA "Tom Tucker", 72
  20057.  
  20058.  
  20059.    DATA "Walt Wagner", 90
  20060.  
  20061.  
  20062.    DATA "Mel Zucker", 92
  20063.  
  20064.  
  20065.    DATA "END", 0
  20066.  
  20067.  
  20068.  
  20069.  
  20070.  
  20071.  ' Open the test data file.
  20072.  
  20073.  
  20074.  DIM FileBuffer AS TestRecord
  20075.  
  20076.  
  20077.  OPEN "TESTDAT2.DAT" FOR RANDOM AS #1 LEN = LEN(FileBuffer)
  20078.  
  20079.  
  20080.  ' Calculate number of records in the file.
  20081.  
  20082.  
  20083.  Max = LOF(1) \ LEN(FileBuffer)
  20084.  
  20085.  
  20086.  ' Read and print contents of each record.
  20087.  
  20088.  
  20089.  FOR I = 1 TO Max
  20090.  
  20091.  
  20092.     GET #1, I, FileBuffer
  20093.  
  20094.  
  20095.     IF FileBuffer.NameField = "Tom Tucker" THEN
  20096.  
  20097.  
  20098.        ReWriteFlag = TRUE
  20099.  
  20100.  
  20101.        EXIT FOR
  20102.  
  20103.  
  20104.     END IF
  20105.  
  20106.  
  20107.  NEXT I
  20108.  
  20109.  
  20110.  IF ReWriteFlag = TRUE THEN
  20111.  
  20112.  
  20113.     ' Back up file by the length of the record variable that
  20114.  
  20115.  
  20116.     ' is used to write to the file.
  20117.  
  20118.  
  20119.     FileBuffer.ScoreField = 100
  20120.  
  20121.  
  20122.     SEEK #1, SEEK(1) - LEN(RecordVar)
  20123.  
  20124.  
  20125.     PUT #1, , RecordVar
  20126.  
  20127.  
  20128.  END IF
  20129.  
  20130.  
  20131.  CLOSE #1
  20132.  
  20133.  
  20134.  KILL "TESTDAT2.DAT"
  20135.  
  20136.  
  20137.  END
  20138.  
  20139.  
  20140.  SEEKGT, SEEKGE, SEEKEQ Statements
  20141.  ────────────────────────────────────────────────────────────────────────────
  20142.  
  20143.  
  20144.  
  20145.  Action
  20146.  
  20147.  Causes the first matching record in an ISAM table to become the current
  20148.  record.
  20149.  
  20150.  
  20151.  Syntax
  20152.  
  20153.  
  20154.  
  20155.   SEEKGT #  filenumber% ,  keyvalue,  keyvalue
  20156.  
  20157.  
  20158.   SEEKGE #  filenumber% ,  keyvalue,  keyvalue
  20159.  
  20160.  
  20161.   SEEKEQ #  filenumber% ,  keyvalue,  keyvalue
  20162.  
  20163.  Remarks
  20164.  
  20165.  
  20166.  The  SEEKGT,  SEEKGE, and  SEEKEQ statements cause the first matching record
  20167.  in the table, according to the current index, to become the current record.
  20168.  The following table shows which value of the current index column causes the
  20169.  record to become current for each statement.
  20170.  
  20171. ╓┌──────────────────┌────────────────────────────────────────────────────────╖
  20172.  Statement          Current-index column value
  20173.  ────────────────────────────────────────────────────────────────────────────
  20174.   SEEKGT            Greater than  keyvalue
  20175.   SEEKGE            Greater than, or equal to,  keyvalue
  20176.   SEEKEQ            Equal to  keyvalue
  20177.  
  20178.  
  20179.  
  20180.  
  20181.  The argument  filenumber% is the number used in the  OPEN statement to open
  20182.  the table. The argument  keyvalue is an expression fewer than 256 characters
  20183.  long that is evaluated based on the operand condition in the  SEEK operand
  20184.  keyword. If more than one  keyvalue argument is specified, BASIC assumes the
  20185.  current index is based on the combination of their values.
  20186.  
  20187.  If no match is found, the current index position is at the end of the table
  20188.  and there is no current record.
  20189.  
  20190.  If the number of  keyvalues is greater than the number of values that makes
  20191.  up the current index, BASIC generates the error message Syntax Error.
  20192.  
  20193.  No error is generated if the number of  keyvalues is less than the number of
  20194.  values that makes up the current index. The seek either fails or is based on
  20195.  the  keyvalues supplied:
  20196.  
  20197.    ■          SEEKEQ with too few  keyvalues always fails.
  20198.  
  20199.    ■          SEEKGE with too few  keyvalues is equivalent to a  SEEKGE with
  20200.              the same arguments.
  20201.  
  20202.    ■          SEEKGT with too few  keyvalues seeks for the first record that
  20203.              matches the  keyvalues supplied.
  20204.  
  20205.  
  20206.  BASIC removes trailing spaces from strings used in a seek.
  20207.  
  20208.  
  20209.  Note
  20210.  
  20211.  The  keyvalue expression must be explicitly typed if it is a DOUBLE or
  20212.  CURRENCY value.
  20213.  
  20214.  
  20215.  See Also
  20216.  
  20217.   MOVEFIRST,  MOVELAST,  MOVENEXT,  MOVEPREVIOUS Statements;  OPEN
  20218.  
  20219.  
  20220.  Example
  20221.  
  20222.  
  20223.  The following example uses the  CREATETABLE statement to create a new table
  20224.  in an ISAM file and uses the  SEEKGE,  RETRIEVE,  UPDATE, and  INSERT
  20225.  statements to insert records into the file. It uses the  LOF function to
  20226.  display the number of records in the new table and then deletes the table
  20227.  with  DELETETABLE.
  20228.  
  20229.  The program uses a file called BOOKS.MDB, the sample ISAM file that SETUP
  20230.  copies to your disk.
  20231.  
  20232.  
  20233.  DEFINT A-Z
  20234.  
  20235.  
  20236.  TYPE BookRec
  20237.  
  20238.  
  20239.      IDNum AS DOUBLE             ' Unique ID number for each book.
  20240.  
  20241.  
  20242.      Title AS STRING * 50        ' Book's title.
  20243.  
  20244.  
  20245.      Publisher AS STRING * 50    ' Book's publisher.
  20246.  
  20247.  
  20248.      Author AS STRING * 36       ' Book's author.
  20249.  
  20250.  
  20251.      Price AS CURRENCY           ' Book's price.
  20252.  
  20253.  
  20254.  END TYPE
  20255.  
  20256.  
  20257.  
  20258.  
  20259.  
  20260.  CONST Database = "BOOKS.MDB"    ' Name of the disk file.
  20261.  
  20262.  
  20263.  DIM Library AS BookRec          ' Variable for current record.
  20264.  
  20265.  
  20266.  DIM MinPrice AS CURRENCY        ' SEEK criteria.
  20267.  
  20268.  
  20269.  
  20270.  
  20271.  
  20272.  CLS
  20273.  
  20274.  
  20275.  DO
  20276.  
  20277.  
  20278.  INPUT "Display books that cost as much or more than "; MinPrice
  20279.  
  20280.  
  20281.      IF MinPrice < 0 THEN PRINT "Positive values only, please."
  20282.  
  20283.  
  20284.  LOOP UNTIL MinPrice > 0
  20285.  
  20286.  
  20287.  
  20288.  
  20289.  
  20290.  ' Open existing table.
  20291.  
  20292.  
  20293.  LibraryFile = FREEFILE
  20294.  
  20295.  
  20296.  OPEN Database FOR ISAM BookRec "BooksStock" AS LibraryFile
  20297.  
  20298.  
  20299.  CREATEINDEX LibraryFile, "Library", 0, "Price"
  20300.  
  20301.  
  20302.  SETINDEX LibraryFile, "Library"
  20303.  
  20304.  
  20305.  
  20306.  
  20307.  
  20308.  ' Create and open a new table.
  20309.  
  20310.  
  20311.  NewFile = FREEFILE
  20312.  
  20313.  
  20314.  OPEN Database FOR ISAM BookRec "PricyBooks" AS NewFile
  20315.  
  20316.  
  20317.  
  20318.  
  20319.  
  20320.  ' Fill new table with records for all books with price >= MinPrice.
  20321.  
  20322.  
  20323.  SEEKGE LibraryFile, MinPrice
  20324.  
  20325.  
  20326.  DO
  20327.  
  20328.  
  20329.      RETRIEVE LibraryFile, Library
  20330.  
  20331.  
  20332.      INSERT NewFile, Library
  20333.  
  20334.  
  20335.      MOVENEXT LibraryFile
  20336.  
  20337.  
  20338.  LOOP UNTIL EOF(LibraryFile)
  20339.  
  20340.  
  20341.  ' First time through loop get price increase;
  20342.  
  20343.  
  20344.  ' second time display new price.
  20345.  
  20346.  
  20347.  FOR count = 1 TO 2
  20348.  
  20349.  
  20350.      CLS
  20351.  
  20352.  
  20353.      PRINT SPC(18); LOF(NewFile); "books cost at least ";
  20354.  
  20355.  
  20356.      PRINT USING ("$###.##"); MinPrice
  20357.  
  20358.  
  20359.      PRINT " ID Number"; SPC(3); "Title"; SPC(20); "Author";
  20360.  
  20361.  
  20362.      PRINT SPC(11); "Publisher"; SPC(10); "Price"
  20363.  
  20364.  
  20365.      VIEW PRINT 3 TO 20
  20366.  
  20367.  
  20368.      MOVEFIRST NewFile
  20369.  
  20370.  
  20371.      DO
  20372.  
  20373.  
  20374.          RETRIEVE NewFile, Library
  20375.  
  20376.  
  20377.          PRINT Library.IDNum; " "; LEFT$(Library.Title, 20);
  20378.  
  20379.  
  20380.          IF LEN(RTRIM$(Library.Title)) > 20 THEN
  20381.  
  20382.  
  20383.              PRINT "...  ";
  20384.  
  20385.  
  20386.          ELSE
  20387.  
  20388.  
  20389.              PRINT "     ";
  20390.  
  20391.  
  20392.          END IF
  20393.  
  20394.  
  20395.          PRINT LEFT$(Library.Author, 15); "  ";
  20396.  
  20397.  
  20398.          PRINT LEFT$(Library.Publisher, 16); "  ";
  20399.  
  20400.  
  20401.          PRINT USING ("$###.##"); Library.Price
  20402.  
  20403.  
  20404.          MOVENEXT NewFile
  20405.  
  20406.  
  20407.      LOOP UNTIL EOF(NewFile)
  20408.  
  20409.  
  20410.      IF count = 1 THEN
  20411.  
  20412.  
  20413.          VIEW PRINT 20 TO 24: LOCATE 20, 1
  20414.  
  20415.  
  20416.          DO
  20417.  
  20418.  
  20419.              INPUT "Increase cost by how much (0-100%)"; increase
  20420.  
  20421.  
  20422.              IF increase < 0 OR increase > 100 THEN PRINT "Illegal value"
  20423.  
  20424.  
  20425.          LOOP UNTIL increase >= 0 AND increase <= 100
  20426.  
  20427.  
  20428.          ' Update records in PricyBooks.
  20429.  
  20430.  
  20431.          MOVEFIRST NewFile
  20432.  
  20433.  
  20434.          DO
  20435.  
  20436.  
  20437.              RETRIEVE NewFile, Library
  20438.  
  20439.  
  20440.              Library.Price = (Library.Price * (100 + increase)) / 100
  20441.  
  20442.  
  20443.              ' Overwrite record with increased price.
  20444.  
  20445.  
  20446.              UPDATE NewFile, Library
  20447.  
  20448.  
  20449.              CHECKPOINT' Force ISAM to flush the buffer to disk.
  20450.  
  20451.  
  20452.              MOVENEXT NewFile
  20453.  
  20454.  
  20455.          LOOP UNTIL EOF(NewFile)
  20456.  
  20457.  
  20458.      END IF
  20459.  
  20460.  
  20461.      VIEW PRINT 1 TO 19
  20462.  
  20463.  
  20464.  NEXT count
  20465.  
  20466.  
  20467.  ' Destroy index and temporary table, close files.
  20468.  
  20469.  
  20470.  DELETEINDEX LibraryFile, "Library"
  20471.  
  20472.  
  20473.  CLOSE
  20474.  
  20475.  
  20476.  DELETETABLE Database, "PricyBooks"
  20477.  
  20478.  
  20479.  SELECT CASE Statement
  20480.  ────────────────────────────────────────────────────────────────────────────
  20481.  
  20482.  
  20483.  Action
  20484.  
  20485.  Executes one of several statement blocks depending on the value of an
  20486.  expression.
  20487.  
  20488.  
  20489.  Syntax
  20490.  
  20491.  
  20492.  
  20493.   SELECT CASE  testexpression
  20494.  
  20495.  
  20496.   CASE  expressionlist1
  20497.  
  20498.  
  20499.   statementblock-1
  20500.  
  20501.  
  20502.   CASE  expressionlist2
  20503.  
  20504.  
  20505.   statementblock-2
  20506.  
  20507.  
  20508.   CASE  ELSE
  20509.  
  20510.  
  20511.   statementblock-n
  20512.  
  20513.  
  20514.   END  SELECT
  20515.  
  20516.  Remarks
  20517.  
  20518.  The following list describes the parts of the  SELECT CASE statement:
  20519.  
  20520. ╓┌─────────────────────────────────────┌─────────────────────────────────────╖
  20521.  ────────────────────────────────────────────────────────────────────────────
  20522.   testexpression                       Any numeric or string expression.
  20523.  
  20524.   statementblock-1, statementblock-2,  The elements statementblock-1 to
  20525.  statementblock-n                      statementblock-n consist of any
  20526.                                        number of statements on one or more
  20527.                                        lines.
  20528.  
  20529.   expressionlist1, expressionlist2     These elements can have any of the
  20530.                                        three following forms:
  20531.  
  20532.  
  20533.                                         expression ,  expression...
  20534.  
  20535.                                         expression TO  expression
  20536.  
  20537.                                        IS relational-operator expression
  20538.  
  20539.  
  20540.  
  20541.  
  20542.  
  20543.  The following list describes the parts of  expressionlist :
  20544.  
  20545. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  20546.  ────────────────────────────────────────────────────────────────────────────
  20547.   expression                             Any numeric or string expression.
  20548.                                          The type of the expression must be
  20549.                                          compatible with the type of
  20550.                                          testexpression. (The type of the
  20551.                                          expression will be coerced to the
  20552.                                          same type as  testexpression. For
  20553.                                          example, if  testexpression is an
  20554.                                          integer,  expressionlist can
  20555.                                          contain a double-precision data
  20556.                                          type.)
  20557.  
  20558.   relational-operator                    Any of the following operators:
  20559.  
  20560.                                          <   Less than
  20561.  ────────────────────────────────────────────────────────────────────────────
  20562.                                         <   Less than
  20563.  
  20564.                                          <=  Less than or equal to
  20565.  
  20566.                                          >   Greater than
  20567.  
  20568.                                          >=  Greater than or equal to
  20569.  
  20570.                                          < > Not equal
  20571.  
  20572.                                          =   Equal
  20573.  
  20574.  
  20575.  
  20576.  
  20577.  
  20578.  
  20579.  If  testexpression matches the expression list associated with a  CASE
  20580.  clause, then the statement block following that  CASE clause is executed up
  20581.  to the next  CASE clause or, for the last one, up to  END SELECT. Control
  20582.  then passes to the statement following  END SELECT.
  20583.  
  20584.  
  20585.  If you use the  TO keyword to indicate a range of values, the smaller value
  20586.  must appear first. For example, the statements associated with the line CASE
  20587.  -1 TO -5 are not executed if  testexpression is -4. The line should be
  20588.  written as CASE -5 TO -1.
  20589.  
  20590.  You can use a relational operator only if the  IS keyword appears. If  CASE
  20591.  ELSE is used, its associated statements are executed only if  testexpression
  20592.  does not match any of the other  CASE selections. It is a good idea to have
  20593.  a  CASE ELSE statement in your  SELECT CASE block to handle unforeseen
  20594.  testexpression values.
  20595.  
  20596.  When there is no  CASE ELSE statement and no expression listed in the  CASE
  20597.  clauses matches  testexpression, program execution continues normally.
  20598.  
  20599.  You can use multiple expressions or ranges in each  CASE clause. For
  20600.  example, the following line is valid:
  20601.  
  20602.  CASE 1 TO 4, 7 TO 9, 11, 13, IS > MaxNumber%
  20603.  
  20604.  You also can specify ranges and multiple expressions for strings:
  20605.  
  20606.  
  20607.  CASE "everything", "nuts" TO "soup", TestItem$
  20608.  
  20609.   CASE matches strings that are exactly equal to everything, the current
  20610.  value of TestItem$, or that fall between nuts and soup in alphabetical
  20611.  order.
  20612.  
  20613.  
  20614.  Strings are evaluated according to the ASCII values of their characters.
  20615.  Lowercase letters have larger ASCII values than uppercase letters, so this
  20616.  statement is true:
  20617.  
  20618.  nuts  >  Nuts  >  NUTS
  20619.  
  20620.  If an expression appears in more than one  CASE clause, only the statements
  20621.  associated with the first appearance of the expression are executed.
  20622.  
  20623.   SELECT CASE statements can be nested. Each  SELECT CASE statement must have
  20624.  a matching  END SELECT statement.
  20625.  
  20626.  
  20627.  Examples
  20628.  
  20629.  
  20630.  In the first example,  SELECT  CASE is used to take different actions based
  20631.  on the input value:
  20632.  
  20633.  INPUT "Enter acceptable level of risk (1-10): ", Total
  20634.  
  20635.  
  20636.  SELECT CASE Total
  20637.  
  20638.  
  20639.  CASE IS >= 10
  20640.  
  20641.  
  20642.  PRINT "Maximum risk and potential return."
  20643.  
  20644.  
  20645.  PRINT "Choose stock investment plan."
  20646.  
  20647.  
  20648.  CASE 6 TO 9
  20649.  
  20650.  
  20651.  PRINT "High risk and potential return."
  20652.  
  20653.  
  20654.  PRINT "Choose corporate bonds."
  20655.  
  20656.  
  20657.  CASE 2 TO 5
  20658.  
  20659.  
  20660.  PRINT "Moderate risk and return."
  20661.  
  20662.  
  20663.  PRINT "Choose mutual fund."
  20664.  
  20665.  
  20666.  CASE 1
  20667.  
  20668.  
  20669.  PRINT "No risk, low return."
  20670.  
  20671.  
  20672.  PRINT "Choose IRA."
  20673.  
  20674.  
  20675.  CASE ELSE
  20676.  
  20677.  
  20678.  PRINT "Response out of range."
  20679.  
  20680.  
  20681.  END SELECT
  20682.  
  20683.  
  20684.  
  20685.  
  20686.  Output
  20687.  
  20688.  
  20689.  
  20690.  Enter acceptable level of risk (1-10): 10
  20691.  
  20692.  
  20693.  Maximum risk and potential return.
  20694.  
  20695.  
  20696.  Choose stock investment plan.
  20697.  
  20698.  
  20699.  
  20700.  
  20701.  
  20702.  Enter acceptable level of risk (1-10): 0
  20703.  
  20704.  
  20705.  Response out of range.
  20706.  
  20707.  
  20708.  
  20709.  
  20710.  In the following program, the  SELECT  CASE statement is used to take
  20711.  different actions based on the ASCII value of a character.
  20712.  
  20713.  
  20714.  ' Function and control key constants.
  20715.  
  20716.  
  20717.  CONST ESC = 27, DOWN = 80, UP = 72, LEFT = 75, RIGHT = 77
  20718.  
  20719.  
  20720.  CONST HOME = 71, ENDKEY = 79, PGDN = 81, PGUP = 73
  20721.  
  20722.  
  20723.  CLS
  20724.  
  20725.  
  20726.  PRINT "Press Escape key to end."
  20727.  
  20728.  
  20729.  DO
  20730.  
  20731.  
  20732.  ' Get a function or ASCII key.
  20733.  
  20734.  
  20735.  DO
  20736.  
  20737.  
  20738.  Choice$ = INKEY$
  20739.  
  20740.  
  20741.  LOOP WHILE Choice$ = ""
  20742.  
  20743.  
  20744.  IF LEN(Choice$) = 1 THEN' Handle ASCII keys.
  20745.  
  20746.  
  20747.  SELECT CASE ASC(Choice$)
  20748.  
  20749.  
  20750.  CASE ESC
  20751.  
  20752.  
  20753.  PRINT "Escape key"
  20754.  
  20755.  
  20756.  END
  20757.  
  20758.  
  20759.  CASE IS < 32, 127
  20760.  
  20761.  
  20762.  PRINT "Control code"
  20763.  
  20764.  
  20765.  CASE 48 TO 57
  20766.  
  20767.  
  20768.  PRINT "Digit: "; Choice$
  20769.  
  20770.  
  20771.  CASE 65 TO 90
  20772.  
  20773.  
  20774.  PRINT "Uppercase letter: "; Choice$
  20775.  
  20776.  
  20777.  CASE 97 TO 122
  20778.  
  20779.  
  20780.  PRINT "Lowercase letter: "; Choice$
  20781.  
  20782.  
  20783.  CASE ELSE
  20784.  
  20785.  
  20786.  PRINT "Punctuation: "; Choice$
  20787.  
  20788.  
  20789.  END SELECT
  20790.  
  20791.  
  20792.  ELSE' Convert 2-byte extended code to 1-byte ASCII code.
  20793.  
  20794.  
  20795.  Choice$ = RIGHT$(Choice$, 1)
  20796.  
  20797.  
  20798.  SELECT CASE Choice$
  20799.  
  20800.  
  20801.  CASE CHR$(DOWN)
  20802.  
  20803.  
  20804.  PRINT "DOWN direction key"
  20805.  
  20806.  
  20807.  CASE CHR$(UP)
  20808.  
  20809.  
  20810.  PRINT "UP direction key"
  20811.  
  20812.  
  20813.  CASE CHR$(PGDN)
  20814.  
  20815.  
  20816.  PRINT "PGDN key"
  20817.  
  20818.  
  20819.  CASE CHR$(PGUP)
  20820.  
  20821.  
  20822.  PRINT "PGUP key"
  20823.  
  20824.  
  20825.  CASE CHR$(HOME)
  20826.  
  20827.  
  20828.  PRINT "HOME key"
  20829.  
  20830.  
  20831.  CASE CHR$(ENDKEY)
  20832.  
  20833.  
  20834.  PRINT "END key"
  20835.  
  20836.  
  20837.  CASE CHR$(RIGHT)
  20838.  
  20839.  
  20840.  PRINT "RIGHT direction key"
  20841.  
  20842.  
  20843.  CASE CHR$(LEFT)
  20844.  
  20845.  
  20846.  PRINT "LEFT direction key"
  20847.  
  20848.  
  20849.  CASE ELSE
  20850.  
  20851.  
  20852.  BEEP
  20853.  
  20854.  
  20855.  END SELECT
  20856.  
  20857.  
  20858.  END IF
  20859.  
  20860.  
  20861.  LOOP
  20862.  
  20863.  
  20864.  SETINDEX Statement
  20865.  ────────────────────────────────────────────────────────────────────────────
  20866.  
  20867.  
  20868.  Action
  20869.  
  20870.  Makes the specified ISAM table index the current index.
  20871.  
  20872.  
  20873.  Syntax
  20874.  
  20875.  
  20876.  
  20877.   SETINDEX #  filenumber% ,  indexname$
  20878.  
  20879.  Remarks
  20880.  
  20881.  
  20882.  The  SETINDEX statement uses the following arguments:
  20883.  
  20884. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  20885.  Argument                                Description
  20886.  ────────────────────────────────────────────────────────────────────────────
  20887.   filenumber%                            The number used in the  OPEN
  20888.                                          statement to open the table.
  20889.  
  20890.   indexname$                             The name used in the  CREATEINDEX
  20891.                                          statement to create the index. If
  20892.                                          no  indexname$ argument or set of
  20893.                                          double quotation marks ("") is
  20894.                                          specified, the null index  becomes
  20895.                                          the current index. The NULL index
  20896.                                          represents the order in which
  20897.  Argument                                Description
  20898.  ────────────────────────────────────────────────────────────────────────────
  20899.                                         represents the order in which
  20900.                                          records were added to the file.
  20901.  
  20902.  
  20903.  
  20904.  
  20905.  
  20906.  After  SETINDEX makes an index current, the current record is the first
  20907.  record according to that index.
  20908.  
  20909.  
  20910.  See Also
  20911.  
  20912.   CREATEINDEX,  DELETEINDEX,  GETINDEX$
  20913.  
  20914.  
  20915.  Example
  20916.  
  20917.  See the  CREATEINDEX statement programming example, which uses the  SETINDEX
  20918.  statement.
  20919.  
  20920.  
  20921.  SETMEM Function
  20922.  ────────────────────────────────────────────────────────────────────────────
  20923.  
  20924.  
  20925.  Action
  20926.  
  20927.  Changes the amount of memory used by the far heap -- the area where far
  20928.  objects are stored -- and returns information about the far heap.
  20929.  
  20930.  
  20931.  Syntax
  20932.  
  20933.  
  20934.  
  20935.   SETMEM( numeric- expression&)
  20936.  
  20937.  Remarks
  20938.  
  20939.  
  20940.  The   SETMEM function increases or decreases the far heap by the number of
  20941.  bytes indicated by  numeric- expression&. If  numeric-expression& is
  20942.  negative,  SETMEM decreases the far heap by the indicated number of bytes.
  20943.  If  numeric-expression& is positive,  SETMEM attempts to increase the far
  20944.  heap by the number of bytes. If  SETMEM cannot change the far heap by the
  20945.  requested number of bytes, it reallocates as many bytes as possible.
  20946.  
  20947.   SETMEM can be used in mixed-language programming to decrease the far heap
  20948.  so procedures in other languages can dynamically allocate far memory.
  20949.  
  20950.  The information that the  SETMEM function returns about the far heap depends
  20951.  on the value of  numeric-expression&, as follows:
  20952.  
  20953. ╓┌─────────────────────────┌─────────────────────────────────────────────────╖
  20954.  ────────────────────────────────────────────────────────────────────────────
  20955.  Positive or negative      Total number of bytes in the far heap.
  20956.  0                         Current size of far heap.
  20957.  
  20958.  
  20959.  
  20960.  
  20961.  
  20962.  Note
  20963.  
  20964.  A first call to  SETMEM trying to increase the far heap has no effect
  20965.  because BASIC allocates as much memory as possible to the far heap when a
  20966.  program starts.
  20967.  
  20968.  When programming with OS/2 protected mode, the  SETMEM function performs no
  20969.  other function than to return a dummy value. This value is the previous
  20970.  SETMEM value adjusted by the  SETMEM argument. The initial value for  SETMEM
  20971.  is 655,360.
  20972.  
  20973.  
  20974.  Example
  20975.  
  20976.  
  20977.  In the following example,  SETMEM is used to free memory for a C routine
  20978.  that uses the C function malloc to get dynamic memory. The C routine must be
  20979.  separately compiled and then put in a Quick library or linked to the BASIC
  20980.  program.
  20981.  
  20982.  DECLARE SUB CFunc CDECL (BYVAL X AS INTEGER)
  20983.  
  20984.  
  20985.  
  20986.  
  20987.  
  20988.  ' Decrease the size of the far heap so CFunc can use
  20989.  
  20990.  
  20991.  ' malloc to get dynamic memory.
  20992.  
  20993.  
  20994.  BeforeCall = SETMEM(-2048)
  20995.  
  20996.  
  20997.  
  20998.  
  20999.  
  21000.  CFunc(1024%)' Call the C routine.
  21001.  
  21002.  
  21003.  
  21004.  
  21005.  
  21006.  ' Return the memory to the far heap; use a larger value so
  21007.  
  21008.  
  21009.  ' all space goes back into the heap.
  21010.  
  21011.  
  21012.  AfterCall = SETMEM(3500)
  21013.  
  21014.  
  21015.  IF AfterCall <= BeforeCall THEN PRINT "Memory not reallocated."
  21016.  
  21017.  
  21018.  END
  21019.  
  21020.  
  21021.  
  21022.  
  21023.  This routine is compiled using the large memory model, so calls to the C
  21024.  function malloc use the far space freed by the BASIC program.
  21025.  
  21026.  
  21027.  void far cfunc(bytes)
  21028.  
  21029.  
  21030.  int bytes;
  21031.  
  21032.  
  21033.  {
  21034.  
  21035.  
  21036.     char *malloc();
  21037.  
  21038.  
  21039.     char *workspace;
  21040.  
  21041.  
  21042.  
  21043.  
  21044.  
  21045.     /* Allocate working memory using amount BASIC freed. */
  21046.  
  21047.  
  21048.     workspace=malloc((unsigned) bytes);
  21049.  
  21050.  
  21051.  
  21052.  
  21053.  
  21054.     /* Working space would be used here. */
  21055.  
  21056.  
  21057.  
  21058.  
  21059.  
  21060.     /* Free memory before returning to BASIC. */
  21061.  
  21062.  
  21063.     free(workspace);
  21064.  
  21065.  
  21066.  }
  21067.  
  21068.  
  21069.  SetUEvent Routine
  21070.  ────────────────────────────────────────────────────────────────────────────
  21071.  
  21072.  
  21073.  Action
  21074.  
  21075.  Sets the BASIC entry point that causes a user-defined event.
  21076.  
  21077.  
  21078.  Syntax
  21079.  
  21080.  
  21081.  
  21082.   SetUEvent
  21083.  
  21084.  Remarks
  21085.  
  21086.  
  21087.   SetUEvent is used in user-event trapping.
  21088.  
  21089.   SetUEvent signals an event for the  ON  UEVENT event-handling routine.
  21090.  
  21091.  The  SetUEvent routine is a part of BASIC, and is automatically included in
  21092.  compiled applications or when running QBX with the /L command-line option.
  21093.  Your interrupt-service routine must call  SetUEvent; it is the only way to
  21094.  alert your program that the event has occurred. You can call  SetUEvent from
  21095.  any non-BASIC language.
  21096.  
  21097.  To use the  SetUEvent routine in the QBX environment, use any Quick library.
  21098.  Outside of the QBX environment, you do not have to link to another library.
  21099.  
  21100.  
  21101.  See Also
  21102.  
  21103.   ON  event,  UEVENT
  21104.  
  21105.  
  21106.  Example
  21107.  
  21108.  See the  UEVENT  statements programming example, which uses the  SetUEvent
  21109.  routine.
  21110.  
  21111.  
  21112.  SGN Function
  21113.  ────────────────────────────────────────────────────────────────────────────
  21114.  
  21115.  
  21116.  Action
  21117.  
  21118.  Indicates the sign of a numeric expression.
  21119.  
  21120.  
  21121.  Syntax
  21122.  
  21123.  
  21124.  
  21125.   SGN( numeric-expression)
  21126.  
  21127.  Remarks
  21128.  
  21129.  
  21130.  The  SGN function returns a value depending on the sign of its argument:
  21131.  
  21132.    ■   If  numeric-expression > 0, then  SGN( numeric-expression) returns 1.
  21133.  
  21134.    ■   If  numeric-expression = 0, then  SGN( numeric-expression) returns 0.
  21135.  
  21136.    ■   If  numeric-expression < 0, then  SGN( numeric-expression) returns -1.
  21137.  
  21138.  
  21139.  Example
  21140.  
  21141.  The following example calculates and prints the solution for the input
  21142.  quadratic (or second-degree) equation. The program uses the sign of a test
  21143.  expression to determine how to calculate the solution.
  21144.  
  21145.  CONST NoRealSoln=-1, OneSoln=0, TwoSolns=1
  21146.  
  21147.  
  21148.  ' Input coefficients of quadratic equation:
  21149.  
  21150.  
  21151.  ' ax^2 + bx + c = 0.
  21152.  
  21153.  
  21154.  INPUT;"a = ",   A
  21155.  
  21156.  
  21157.  INPUT;",  b = ",B
  21158.  
  21159.  
  21160.  INPUT ",  c = ",C
  21161.  
  21162.  
  21163.  Test = B^2 - 4 * A * C
  21164.  
  21165.  
  21166.  SELECT CASE SGN(Test)
  21167.  
  21168.  
  21169.     CASE  NoRealSoln
  21170.  
  21171.  
  21172.        PRINT "This equation has no real-number solutions."
  21173.  
  21174.  
  21175.     CASE  OneSoln
  21176.  
  21177.  
  21178.        PRINT "This equation has one solution: ";
  21179.  
  21180.  
  21181.        PRINT -B/(2 * A)
  21182.  
  21183.  
  21184.     CASE  TwoSolns
  21185.  
  21186.  
  21187.        PRINT "This equation has two solutions: ";
  21188.  
  21189.  
  21190.        PRINT (-B + SQR(Test))/(2 * A) " and ";
  21191.  
  21192.  
  21193.        PRINT (-B - SQR(Test))/(2 * A)
  21194.  
  21195.  
  21196.  END SELECT
  21197.  
  21198.  
  21199.  
  21200.  
  21201.  Output
  21202.  
  21203.  
  21204.  
  21205.  a = 3,  b = -4,  c = 1
  21206.  
  21207.  
  21208.  This equation has two solutions:  1  and  .3333333
  21209.  
  21210.  
  21211.  SHARED Statement
  21212.  ────────────────────────────────────────────────────────────────────────────
  21213.  
  21214.  
  21215.  Action
  21216.  
  21217.  Gives a  SUB or  FUNCTION procedure access to variables declared at the
  21218.  module level without passing them as parameters.
  21219.  
  21220.  
  21221.  Syntax
  21222.  
  21223.  
  21224.  
  21225.   SHARED  variable( )  AS  type ,  variable( )  AS  type...
  21226.  
  21227.  Remarks
  21228.  
  21229.  
  21230.  The argument  variable is the module-level variable the procedure will use.
  21231.  It is either an array name followed by ( ), or a variable name. The  AS
  21232.  type clause can be used to indicate the variable's type, which can be
  21233.  INTEGER,  LONG,  SINGLE,  DOUBLE,  STRING, fixed-length string ( STRING *
  21234.  length),  CURRENCY, or a user-defined type.
  21235.  
  21236.  By using either the  SHARED statement in a  SUB or  FUNCTION procedure, or
  21237.  the  SHARED attribute with  COMMON or  DIM in the module-level code, you can
  21238.  use variables in a procedure without passing them as parameters. The  SHARED
  21239.  attribute used with  COMMON or  DIM shares variables among all procedures in
  21240.  a module, while the  SHARED statement shares variables between a single
  21241.  procedure and the module-level code.
  21242.  
  21243.  
  21244.  Note
  21245.  
  21246.  The  SHARED statement shares variables only within a single compiled module.
  21247.  It does not share variables with programs in the Quick library or with
  21248.  procedures compiled separately and linked to the program. The  SHARED
  21249.  statement shares variables only between the module-level code and a  SUB or
  21250.  FUNCTION procedure in the same module.
  21251.  
  21252.  The  SHARED statement can appear only in a  SUB or  FUNCTION procedure. For
  21253.  more information, see Chapter 2, "SUB and FUNCTION Procedures" in the
  21254.  Programmer's Guide.
  21255.  
  21256.  
  21257.  See Also
  21258.  
  21259.   COMMON,  DIM,  SUB
  21260.  
  21261.  
  21262.  Example
  21263.  
  21264.  
  21265.  The following example calls a  SUB procedure named Convert that converts the
  21266.  input decimal number to its string representation in the given new base. The
  21267.  string N$ is shared by the procedure and the main program.
  21268.  
  21269.  DEFINT A-Z
  21270.  
  21271.  
  21272.  DO
  21273.  
  21274.  
  21275.     INPUT "Decimal number (input number <= 0 to quit): ",Decimal
  21276.  
  21277.  
  21278.     IF Decimal <= 0 THEN EXIT DO
  21279.  
  21280.  
  21281.     INPUT "New base: ",Newbase
  21282.  
  21283.  
  21284.     N$ = ""
  21285.  
  21286.  
  21287.     PRINT Decimal "base 10 equals ";
  21288.  
  21289.  
  21290.     DO WHILE Decimal > 0
  21291.  
  21292.  
  21293.        CALL Convert (Decimal,Newbase)
  21294.  
  21295.  
  21296.        Decimal = Decimal\Newbase
  21297.  
  21298.  
  21299.     LOOP
  21300.  
  21301.  
  21302.     PRINT N$ " base" Newbase
  21303.  
  21304.  
  21305.     PRINT
  21306.  
  21307.  
  21308.  LOOP
  21309.  
  21310.  
  21311.  
  21312.  
  21313.  
  21314.  SUB Convert (D,Nb) STATIC
  21315.  
  21316.  
  21317.  SHARED N$
  21318.  
  21319.  
  21320.     ' Take the remainder to find the value of the current
  21321.  
  21322.  
  21323.     ' digit.
  21324.  
  21325.  
  21326.     R = D MOD Nb
  21327.  
  21328.  
  21329.     ' If the digit is less than ten, return a digit (0-9).
  21330.  
  21331.  
  21332.     ' Otherwise, return a letter (A-Z).
  21333.  
  21334.  
  21335.     IF R < 10 THEN Digit$ = CHR$(R+48) ELSE Digit$ = CHR$(R+55)
  21336.  
  21337.  
  21338.     N$ = RIGHT$(Digit$,1) + N$
  21339.  
  21340.  
  21341.  END SUB
  21342.  
  21343.  
  21344.  SHELL Function
  21345.  ────────────────────────────────────────────────────────────────────────────
  21346.  
  21347.  
  21348.  Action
  21349.  
  21350.  Returns an integer value that is the OS/2 process ID for the shelled
  21351.  process.
  21352.  
  21353.  
  21354.  Syntax
  21355.  
  21356.  
  21357.  
  21358.   SHELL( commandstring$)
  21359.  
  21360.  Remarks
  21361.  
  21362.  
  21363.  The argument  commandstring$ is the name of the OS/2 process to be executed,
  21364.  along with any command-line arguments that the executed process requires.
  21365.  The command string is required.
  21366.  
  21367.  The  SHELL function is used only under OS/2 protected mode.
  21368.  
  21369.  Like the  SHELL statement, the OS/2 protected-mode  SHELL function permits a
  21370.  BASIC program to execute another process. In addition, the  SHELL function
  21371.  allows the BASIC program to continue execution without waiting for the child
  21372.  process to terminate, and returns the process ID of the child process. The
  21373.  process ID is used by some of the OS/2 API functions (which can be called
  21374.  from BASIC).
  21375.  
  21376.  
  21377.  See Also
  21378.  
  21379.   SHELL Statement
  21380.  
  21381.  
  21382.  Example
  21383.  
  21384.  The following example uses the  SHELL function to execute three OS/2
  21385.  commands:
  21386.  
  21387.  ON ERROR GOTO ErrHandler
  21388.  
  21389.  
  21390.  Ext$ = CHR$(34) + " EXE" + CHR$(34)
  21391.  
  21392.  
  21393.  ' The child process does: DIR | FIND " EXE" | SORT
  21394.  
  21395.  
  21396.  Child$ = "dir | find " + Ext$ + "| sort"
  21397.  
  21398.  
  21399.  ProcessID = SHELL(Child$)
  21400.  
  21401.  
  21402.  PRINT "Process ID is:" ProcessID
  21403.  
  21404.  
  21405.  END
  21406.  
  21407.  
  21408.  
  21409.  
  21410.  
  21411.  ErrHandler:
  21412.  
  21413.  
  21414.      SELECT CASE ERR
  21415.  
  21416.  
  21417.          CASE 73
  21418.  
  21419.  
  21420.              PRINT : PRINT "You cannot use the SHELL function in DOS."
  21421.  
  21422.  
  21423.          CASE ELSE
  21424.  
  21425.  
  21426.      END SELECT
  21427.  
  21428.  
  21429.      END
  21430.  
  21431.  
  21432.  SHELL Statement
  21433.  ────────────────────────────────────────────────────────────────────────────
  21434.  
  21435.  
  21436.  Action
  21437.  
  21438.  Suspends execution of the BASIC program, runs a .COM, .EXE, .BAT, or .CMD
  21439.  program, or a DOS or OS/2 command, and resumes execution of the BASIC
  21440.  program at the statement following the  SHELL statement.
  21441.  
  21442.  
  21443.  Syntax
  21444.  
  21445.  
  21446.  
  21447.   SHELL  commandstring
  21448.  
  21449.  Remarks
  21450.  
  21451.  
  21452.  The argument  commandstring must be a valid string expression that contains
  21453.  the name of a program to run, and any program arguments.
  21454.  
  21455.  Any .COM file, .EXE file, .BAT program, .CMD program, DOS command, or OS/2
  21456.  command that runs under the  SHELL statement is called a "child process."
  21457.  Child processes are executed by the  SHELL statement, which loads and runs a
  21458.  copy of COMMAND.COM (for DOS) or CMD.EXE (for OS/2) with the /C option.
  21459.  
  21460.  The /C option allows any parameters in  commandstring to be passed to the
  21461.  child process. It also allows redirection of standard input and output, and
  21462.  execution of built-in commands such as DIR and PATH.
  21463.  
  21464.  The program name in  commandstring can have any extension you wish. If no
  21465.  extension is supplied, COMMAND.COM (for DOS) or CMD.EXE (for OS/2) looks for
  21466.  a .COM file, then an .EXE file, and finally, a .BAT file (for DOS) or a .CMD
  21467.  file (for OS/2). If COMMAND.COM or CMD.EXE is not found, BASIC generates the
  21468.  error message File not found. BASIC does not generate an error if
  21469.  COMMAND.COM or CMD.EXE cannot find the file specified in  commandstring, but
  21470.  the operating system generates an error message.
  21471.  
  21472.  
  21473.  COMMAND.COM or CMD.EXE treat as program parameters any text separated from
  21474.  the program name by at least one blank. BASIC remains in memory while the
  21475.  child process is running. When the child process finishes, BASIC continues.
  21476.  
  21477.  If you omit the argument  commandstring,  SHELL gives you a new shell
  21478.  (COMMAND.COM for DOS or CMD.EXE for OS/2). You then can enter
  21479.  operating-system commands at the prompt. Use the  EXIT command to return to
  21480.  BASIC.
  21481.  
  21482.  
  21483.  Note
  21484.  
  21485.  If you are using OS/2, make sure that the SET COMSPEC configuration command
  21486.  in your CONFIG.SYS file specifies the path for the CMD.EXE file. If the path
  21487.  for CMD.EXE is not set, BASIC generates an error message when  SHELL
  21488.  searches for the CMD.EXE file.
  21489.  
  21490.  
  21491.  See Also
  21492.  
  21493.   SHELL Function
  21494.  
  21495.  
  21496.  Examples
  21497.  
  21498.  
  21499.  The following example shows how a single  SHELL statement starts up a new
  21500.  COMMAND.COM:
  21501.  
  21502.  ' Get a new COMMAND.COM
  21503.  
  21504.  
  21505.  ' Type EXIT at the operating system prompt to return to this program.
  21506.  
  21507.  
  21508.  SHELL
  21509.  
  21510.  
  21511.  
  21512.  
  21513.  If the name of a any executable file or command is provided as an argument
  21514.  to the  SHELL statement, that command will be executed as if it had been
  21515.  invoked from the operating-system prompt. When the program is finished,
  21516.  control returns to BASIC. The following use of the  SHELL statement
  21517.  illustrates how to display a directory listing to check the creation time of
  21518.  a file:
  21519.  
  21520.  
  21521.  SHELL "DIR | MORE"
  21522.  
  21523.  
  21524.  SIGNAL Statements
  21525.  ────────────────────────────────────────────────────────────────────────────
  21526.  
  21527.  
  21528.  Action
  21529.  
  21530.  Enable, disable, or suspend event trapping for an OS/2 protected-mode
  21531.  signal.
  21532.  
  21533.  
  21534.  Syntax
  21535.  
  21536.  
  21537.  
  21538.   SIGNAL( n%)  ON
  21539.  
  21540.  
  21541.   SIGNAL( n%)  OFF
  21542.  
  21543.  
  21544.   SIGNAL( n%)  STOP
  21545.  
  21546.  Remarks
  21547.  
  21548.  
  21549.  The argument  n% identifies an OS/2 protected-mode signal. The following
  21550.  table lists the numbers of the protected-mode signals:
  21551.  
  21552. ╓┌─────────────────────┌─────────────────────────────────────────────────────╖
  21553.  Number                Signal
  21554.  ────────────────────────────────────────────────────────────────────────────
  21555.  1                     Ctrl+C
  21556.  2                     Pipe connection broken
  21557.  3                     Program terminated
  21558.  4                     Ctrl+Break
  21559.  5                     Process flag A
  21560.  6                     Process flag B
  21561.  7                     Process flag C
  21562.  
  21563.  
  21564.  
  21565.  
  21566.  
  21567.  
  21568.   SIGNAL( n%)  OFF disables trapping of OS/2 signal  n%. No trapping takes
  21569.  place until another  SIGNAL( n%)  ON statement is executed. Events occurring
  21570.  while trapping is off are ignored.
  21571.  
  21572.   SIGNAL( n%)  STOP suspends trapping of OS/2 signal  n%. No trapping takes
  21573.  place until a  SIGNAL( n%)  ON statement is executed. Events occurring while
  21574.  trapping is suspended are remembered and processed when the next  SIGNAL(
  21575.  n%)  ON statement is executed. However, remembered events are lost if
  21576.  SIGNAL( n%)  OFF is executed.
  21577.  
  21578.  When a signal-event trap occurs (that is, the  GOSUB is performed), an
  21579.  automatic  SIGNAL STOP is executed so that recursive traps cannot take
  21580.  place. The  RETURN operation from the trapping routine automatically
  21581.  performs a  SIGNAL ON statement unless an explicit  SIGNAL OFF was performed
  21582.  inside the routine. For more information, see Chapter 9, "Event Handling" in
  21583.  the  Programmer's Guide.
  21584.  
  21585.  
  21586.  Note
  21587.  
  21588.  The  SIGNAL statement is available only for OS/2 protected mode.
  21589.  
  21590.  
  21591.  See Also
  21592.  
  21593.   ON  event
  21594.  
  21595.  
  21596.  Example
  21597.  
  21598.  
  21599.  The following example uses  ON SIGNAL to trap an event in the OS/2 operating
  21600.  system:
  21601.  
  21602.  PRINT "This program traps Ctrl+Break. Press Q to quit."
  21603.  
  21604.  
  21605.  EVENT ON
  21606.  
  21607.  
  21608.  
  21609.  
  21610.  
  21611.  ' Set up the signal-event trap and enable.
  21612.  
  21613.  
  21614.  ON SIGNAL(4) GOSUB CtrlBreak
  21615.  
  21616.  
  21617.  SIGNAL(4) ON
  21618.  
  21619.  
  21620.  
  21621.  
  21622.  
  21623.  ' Wait until the signal event occurs.
  21624.  
  21625.  
  21626.  DO : LOOP UNTIL UCASE$(INKEY$) = "Q"
  21627.  
  21628.  
  21629.  PRINT "'Q' pressed - Program terminating normally."
  21630.  
  21631.  
  21632.  END
  21633.  
  21634.  
  21635.  
  21636.  
  21637.  
  21638.  CtrlBreak:
  21639.  
  21640.  
  21641.      PRINT "A SIGNAL(4) event occurred."
  21642.  
  21643.  
  21644.      PRINT "Press 'Q' to quit."
  21645.  
  21646.  
  21647.      RETURN
  21648.  
  21649.  
  21650.  SIN Function
  21651.  ────────────────────────────────────────────────────────────────────────────
  21652.  
  21653.  
  21654.  Action
  21655.  
  21656.  Returns the sine of an angle given in radians.
  21657.  
  21658.  
  21659.  Syntax
  21660.  
  21661.  
  21662.  
  21663.   SIN( x)
  21664.  
  21665.  Remarks
  21666.  
  21667.  
  21668.  The argument  x can be of any numeric type.
  21669.  
  21670.  The sine of an angle in a right triangle is the ratio between the length of
  21671.  the side opposite the angle and the length of the hypotenuse.
  21672.  
  21673.   SIN is calculated in single precision if  x# is an integer or
  21674.  single-precision value. If you use any other numeric data type,  SIN is
  21675.  calculated in double precision.
  21676.  
  21677.  To convert values from degrees to radians, multiply the angle (in degrees)
  21678.  times π/180 (or .0174532925199433). To convert a radian value to degrees,
  21679.  multiply it by 180/π (or 57.2957795130824). In both cases, π ≈ 3.141593.
  21680.  
  21681.  
  21682.  
  21683.  See Also
  21684.  
  21685.   ATN,  COS,  TAN
  21686.  
  21687.  
  21688.  Example
  21689.  
  21690.  The following example plots the graph of the polar equation r = 1 + sin (n *
  21691.  Θ). This figure is sometimes known as a cardioid, owing to its resemblance
  21692.  to a heart when n equals 1.
  21693.  
  21694.  CLS
  21695.  
  21696.  
  21697.  CONST PI = 3.141593
  21698.  
  21699.  
  21700.  SCREEN 1 : COLOR 1,1 ' Medium resolution, blue background.
  21701.  
  21702.  
  21703.  WINDOW (-3,-2)-(3,2) ' Convert screen to Cartesian coordinates.
  21704.  
  21705.  
  21706.  INPUT "Number of petals = ", N
  21707.  
  21708.  
  21709.  CLS
  21710.  
  21711.  
  21712.  PSET (1,0) ' Set initial point.
  21713.  
  21714.  
  21715.  FOR Angle = 0 TO 2 * PI STEP .02
  21716.  
  21717.  
  21718.     R = 1 + SIN(N * Angle)  ' Polar equation for "flower."
  21719.  
  21720.  
  21721.     X = R * COS(Angle)' Convert polar coordinates to
  21722.  
  21723.  
  21724.     Y = R * SIN(Angle)' Cartesian coordinates.
  21725.  
  21726.  
  21727.     LINE -(X,Y)' Draw line from previous point to new point.
  21728.  
  21729.  
  21730.  NEXT
  21731.  
  21732.  
  21733.  END
  21734.  
  21735.  
  21736.  SLEEP Statement
  21737.  ────────────────────────────────────────────────────────────────────────────
  21738.  
  21739.  
  21740.  Action
  21741.  
  21742.  Suspends execution of the calling program.
  21743.  
  21744.  
  21745.  Syntax
  21746.  
  21747.  
  21748.  
  21749.   SLEEP  seconds&
  21750.  
  21751.  Remarks
  21752.  
  21753.  
  21754.  The optional argument  seconds& determines the number of seconds to suspend
  21755.  the program. The  SLEEP statement suspends the program until one of the
  21756.  following events occurs:
  21757.  
  21758.    ■         The time period in the argument  seconds& has elapsed.
  21759.  
  21760.    ■         A key is pressed.
  21761.  
  21762.    ■         An enabled event occurs.
  21763.  
  21764.  A BASIC event is one you can trap with an  ON  event statement such as  ON
  21765.  COM or  ON  TIMER. A BASIC event cannot interrupt a  SLEEP suspension unless
  21766.  its trapping is active when the event occurs. This means that trapping must
  21767.  have been initialized with an  ON  event statement, turned on with an  event
  21768.   ON statement, and not have been disabled with an  event  OFF statement or
  21769.  an  event  STOP statement.
  21770.  
  21771.  If  seconds& is 0 or is omitted, the program is suspended until a key is
  21772.  pressed or an enabled event occurs.
  21773.  
  21774.   SLEEP responds only to keystrokes that occur after it executes.  SLEEP
  21775.  ignores characters in the keyboard buffer that were typed before it
  21776.  executed.
  21777.  
  21778.  
  21779.  See Also
  21780.  
  21781.   WAIT
  21782.  
  21783.  
  21784.  Example
  21785.  
  21786.  The following example suspends execution for 10 seconds. There is no  ON
  21787.  event statement, so the only way to interrupt the suspension before 10
  21788.  seconds have passed is to press a key.
  21789.  
  21790.  CLS                               ' Clear the screen.
  21791.  
  21792.  
  21793.  PRINT "Taking a 10 second nap..."
  21794.  
  21795.  
  21796.  SLEEP 10
  21797.  
  21798.  
  21799.  PRINT "Awake!"
  21800.  
  21801.  
  21802.  END
  21803.  
  21804.  
  21805.  SOUND Statement
  21806.  ────────────────────────────────────────────────────────────────────────────
  21807.  
  21808.  
  21809.  Action
  21810.  
  21811.  Generates sound through the speaker.
  21812.  
  21813.  
  21814.  Syntax
  21815.  
  21816.  
  21817.  
  21818.   SOUND  frequency,  duration!
  21819.  
  21820.  Remarks
  21821.  
  21822.  
  21823.  The  SOUND statement uses the following arguments:
  21824.  
  21825. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  21826.  Argument                                Description
  21827.  ────────────────────────────────────────────────────────────────────────────
  21828.   frequency                              The frequency of the sound in
  21829.                                          cycles per second or hertz. It
  21830.                                          must be a numeric expression with
  21831.                                          a value between 37 and 32,767,
  21832.                                          inclusive.
  21833.  
  21834.   duration!                              The number of system clock ticks
  21835.                                          the sound lasts. The duration
  21836.                                          argument accepts any positive
  21837.                                          single-precision, floating-point
  21838.                                          value between 0 and 65,535,
  21839.                                          inclusive. There are 18.2 clock
  21840.                                          ticks per second, regardless of
  21841.                                          CPU speed.
  21842.  Argument                                Description
  21843.  ────────────────────────────────────────────────────────────────────────────
  21844.                                         CPU speed.
  21845.  
  21846.  
  21847.  
  21848.  If  duration! is 0, any current  SOUND statement that is running in the
  21849.  background is turned off. If no  SOUND statement is running, a duration of
  21850.  zero has no effect.
  21851.  
  21852.  
  21853.  Note
  21854.  
  21855.  The  SOUND statement is not available in OS/2 protected mode.
  21856.  
  21857.  
  21858.  See Also
  21859.  
  21860.   PLAY (Music)
  21861.  
  21862.  
  21863.  Example
  21864.  
  21865.  The following example produces a rising and descending glissando:
  21866.  FOR I = 440 TO 1000 STEP 5
  21867.  
  21868.  
  21869.     SOUND I, I/1000
  21870.  
  21871.  
  21872.  NEXT
  21873.  
  21874.  
  21875.  FOR I = 1000 TO 440 STEP -5
  21876.  
  21877.  
  21878.    SOUND I, I/1000
  21879.  
  21880.  
  21881.  NEXT
  21882.  
  21883.  
  21884.  SPACE$ Function
  21885.  ────────────────────────────────────────────────────────────────────────────
  21886.  
  21887.  
  21888.  Action
  21889.  
  21890.  Returns a string of spaces of length  n.
  21891.  
  21892.  
  21893.  Syntax
  21894.  
  21895.  
  21896.  
  21897.   SPACE$( n)
  21898.  
  21899.  Remarks
  21900.  
  21901.  
  21902.  The expression  n specifies the number of spaces you want in the string.  It
  21903.  is rounded to an integer and must be between 0 and 32,767, inclusive.
  21904.  
  21905.  
  21906.  See Also
  21907.  
  21908.  LSET, Print Using,  RSET,  SPC, String $
  21909.  
  21910.  
  21911.  Example
  21912.  
  21913.  The following example demonstrates use of the  SPACE$ function:
  21914.  
  21915.  CLS' Clear the screen.
  21916.  
  21917.  
  21918.  FOR I=1 TO 5
  21919.  
  21920.  
  21921.     X$=SPACE$(I)
  21922.  
  21923.  
  21924.     PRINT X$;I
  21925.  
  21926.  
  21927.  NEXT I
  21928.  
  21929.  
  21930.  
  21931.  
  21932.  Output
  21933.  
  21934.  
  21935.  
  21936.  1
  21937.  
  21938.  
  21939.    2
  21940.  
  21941.  
  21942.     3
  21943.  
  21944.  
  21945.      4
  21946.  
  21947.  
  21948.       5
  21949.  
  21950.  
  21951.  SPC Function
  21952.  ────────────────────────────────────────────────────────────────────────────
  21953.  
  21954.  
  21955.  Action
  21956.  
  21957.  Skips a specified number of spaces in a  PRINT,  LPRINT, OR  PRINT  #
  21958.  statement, starting at the current print position.
  21959.  
  21960.  
  21961.  Syntax
  21962.  
  21963.  
  21964.  
  21965.   SPC( n%)
  21966.  
  21967.  Remarks
  21968.  
  21969.  
  21970.   SPC can only be used with  PRINT,  LPRINT, or  PRINT # statements. The
  21971.  argument  n% is a number between 0 and 32,767, inclusive, that is combined
  21972.  with the width of the output line to determine the number of blank
  21973.  characters to print.
  21974.  
  21975.  A semicolon (;) is assumed to follow the  SPC function. For example, the
  21976.  following two print statements are equivalent:
  21977.  
  21978.  PRINT SPC(10) FixLen1$; SPC(10) FixLen2$; SPC(10) FixLen3$
  21979.  
  21980.  
  21981.  PRINT SPC(10); FixLen1$; SPC(10); FixLen2$; SPC(10); FixLen3$
  21982.  
  21983.  
  21984.  
  21985.  
  21986.  Note that the  SPC function does more than move the text cursor to a new
  21987.  print position. For screen output it also overwrites any existing characters
  21988.  on a display screen with blanks. The  n% blank characters are printed
  21989.  starting at the current print position.
  21990.  
  21991.  
  21992.  The leftmost print position on an output line is always 1; to have any
  21993.  effect, the value of  n% must be greater than or equal to 1.
  21994.  
  21995.  The rightmost print position is the current line width of the output device
  21996.  (which can be set with the  WIDTH statement).
  21997.  
  21998.  The behavior of an  SPC function depends on the relationship between three
  21999.  values:  n%, the output-line print position when the  SPC function is
  22000.  executed, and the current output-line width:
  22001.  
  22002.    ■         If  n% is greater than the output-line width,  SPC calculates
  22003.              n%  MOD width and generates the number of blanks indicated by
  22004.              that calculation, starting at the current print position.
  22005.  
  22006.    ■         If the difference between the current print position and the
  22007.              output-line width is less than  n% (or  n%  MOD width), the  SPC
  22008.              function skips to the beginning of the next line and generates a
  22009.              number of blanks equal to  n% - (width - current print
  22010.              position).
  22011.  
  22012.  See Also
  22013.  
  22014.   SPACE$,  TAB
  22015.  
  22016.  
  22017.  Example
  22018.  
  22019.  
  22020.  The following example demonstrates the use of the  SPC statement to insert a
  22021.  number of spaces within a printed line using either the  PRINT statement or
  22022.  the  LPRINT statement:
  22023.  
  22024.  CLS   ' Clear the screen.
  22025.  
  22026.  
  22027.  PRINT "The following line is printed using standard screen print"
  22028.  
  22029.  
  22030.  PRINT "zones."
  22031.  
  22032.  
  22033.  PRINT : PRINT "Column 1","Column 2","Column 3","Column 4","Column 5"
  22034.  
  22035.  
  22036.  PRINT : PRINT
  22037.  
  22038.  
  22039.  PRINT "The next line is printed using the SPC(n%) statement to achieve"
  22040.  
  22041.  
  22042.  PRINT "the same results."
  22043.  
  22044.  
  22045.  PRINT
  22046.  
  22047.  
  22048.  PRINT "Column 1"; SPC(6); "Column 2"; SPC(6); "Column 3";
  22049.  
  22050.  
  22051.  PRINT SPC(6); "Column 4"; SPC(6); "Column 5"
  22052.  
  22053.  
  22054.  
  22055.  
  22056.  Output
  22057.  
  22058.  
  22059.  
  22060.  The following line is printed using standard screen print
  22061.  
  22062.  
  22063.  zones.
  22064.  
  22065.  
  22066.  
  22067.  
  22068.  
  22069.  Column 1      Column 2      Column 3      Column 4      Column 5
  22070.  
  22071.  
  22072.  
  22073.  
  22074.  
  22075.  
  22076.  
  22077.  
  22078.  The next line is printed using the SPC(n%) statement to achieve
  22079.  
  22080.  
  22081.  the same results.
  22082.  
  22083.  
  22084.  
  22085.  
  22086.  
  22087.  Column 1      Column 2      Column 3      Column 4      Column 5
  22088.  
  22089.  
  22090.  SQR Function
  22091.  ────────────────────────────────────────────────────────────────────────────
  22092.  
  22093.  
  22094.  Action
  22095.  
  22096.  Returns the square root of a numeric expression.
  22097.  
  22098.  
  22099.  Syntax
  22100.  
  22101.  
  22102.  
  22103.   SQR( numeric-expression)
  22104.  
  22105.  Remarks
  22106.  
  22107.  
  22108.  The argument  numeric-expression must be greater than or equal to 0.
  22109.  
  22110.   SQR is calculated in single precision if  numeric-expression is an integer
  22111.  or single-precision value. If you use any other numeric data type,  SQR is
  22112.  calculated in double precision.
  22113.  
  22114.  
  22115.  Example
  22116.  
  22117.  The following example uses the  SQR function to plot the graph of y =
  22118.  sqr(abs(x)) for -9  x  9 :
  22119.  
  22120.  
  22121.  SCREEN 1 : COLOR 1         ' Low-resolution color graphics mode.
  22122.  
  22123.  
  22124.  WINDOW (-9,-.25)-(9,3.25)  ' Convert screen to Cartesian coordinates.
  22125.  
  22126.  
  22127.  LINE (-9,0)-(9,0)          ' Draw x-axis.
  22128.  
  22129.  
  22130.  LINE (0,-.25)-(0,3.25)     ' Draw y-axis.
  22131.  
  22132.  
  22133.  FOR x = -9 TO 9
  22134.  
  22135.  
  22136.      LINE(x,.04)-(x,-.04)   ' Put tick marks on x-axis.
  22137.  
  22138.  
  22139.  NEXT x
  22140.  
  22141.  
  22142.  FOR y = .25 TO 3.25 STEP .25
  22143.  
  22144.  
  22145.      LINE (-.08,y)-(.12,y)  ' Put tick marks on y-axis.
  22146.  
  22147.  
  22148.  NEXT y
  22149.  
  22150.  
  22151.  PSET (-9,3)                ' Plot the first point of function.
  22152.  
  22153.  
  22154.  FOR x = -9 TO 9 STEP .25
  22155.  
  22156.  
  22157.      y = SQR(ABS(x))        ' SQR argument cannot be negative.
  22158.  
  22159.  
  22160.      LINE -(x,y),2          ' Draw a line to the next point.
  22161.  
  22162.  
  22163.  NEXT x
  22164.  
  22165.  
  22166.  SSEG Function
  22167.  ────────────────────────────────────────────────────────────────────────────
  22168.  
  22169.  
  22170.  Action
  22171.  
  22172.  Returns the segment address of a string (or 0 if the argument is a null
  22173.  string).
  22174.  
  22175.  
  22176.  Syntax
  22177.  
  22178.  
  22179.  
  22180.   SSEG( stringvariable$)
  22181.  
  22182.  Remarks
  22183.  
  22184.  
  22185.  The argument  stringvariable$ is the string variable for which you want the
  22186.  segment address. It can be a simple string variable or a single element of a
  22187.  string array. You cannot use fixed-length string arguments.
  22188.  
  22189.  
  22190.   SSEG returns the segment address for strings. It is typically used in
  22191.  mixed-language programming to obtain far addresses before passing far
  22192.  strings to procedures written in other languages.
  22193.  
  22194.   SSEG usually is used with far strings but also can be used with strings
  22195.  stored in DGROUP (in which case it returns DGROUP's address). The offset of
  22196.  a string can be found by using the  SADD function.
  22197.  
  22198.  In OS/2 protected mode, the  SSEG function returns the selector of the
  22199.  specified string variable.
  22200.  
  22201.  
  22202.  See Also
  22203.  
  22204.   BLOAD,  BSAVE,  DEF SEG,  PEEK,  POKE,  SADD,  SSEGADD
  22205.  
  22206.  
  22207.  Example
  22208.  
  22209.  See the sadd function programming example, which uses the  SSEG function.
  22210.  
  22211.  
  22212.  SSEGADD Function
  22213.  ────────────────────────────────────────────────────────────────────────────
  22214.  
  22215.  
  22216.  Action
  22217.  
  22218.  Returns the far address of a string variable (both segment and offset).
  22219.  
  22220.  
  22221.  Syntax
  22222.  
  22223.  
  22224.  
  22225.   SSEGADD( stringvariable$)
  22226.  
  22227.  Remarks
  22228.  
  22229.  
  22230.  The argument  stringvariable$ is the string variable for which you want an
  22231.  address. It can be a simple string variable or a single element of a string
  22232.  array. You cannot use fixed-length string arguments.
  22233.  
  22234.  The  SSEGADD function combines the segment and offset information into one
  22235.  long integer (4 bytes).
  22236.  
  22237.  
  22238.   SSEG returns the far address for a string. It is typically used in
  22239.  mixed-language programming to obtain far addresses before passing far
  22240.  strings to procedures written in other languages.
  22241.  
  22242.   SSEGADD usually is used with far strings but also can be used with strings
  22243.  stored in DGROUP.
  22244.  
  22245.  The offset of a string can be found with the  SADD function, while the
  22246.  segment of a string can be found with the  SSEG function.
  22247.  
  22248.  
  22249.  See Also
  22250.  
  22251.   BLOAD,  BSAVE,  DEF SEG,  SADD,  SSEG,  PEEK,  POKE
  22252.  
  22253.  
  22254.  Example
  22255.  
  22256.  The following example passes a string to a C routine. It uses  SSEGADD to
  22257.  obtain the memory address of the string.
  22258.  
  22259.  DEFINT A-Z
  22260.  
  22261.  
  22262.  DECLARE SUB printmessage CDECL (BYVAL farstring AS LONG)
  22263.  
  22264.  
  22265.  ' Create the message as an ASCIIZ string (last character null),
  22266.  
  22267.  
  22268.  ' as required by the C function printf.
  22269.  
  22270.  
  22271.  a$ = "This is a short example of a message" + CHR$(0)
  22272.  
  22273.  
  22274.  ' Call the C function with pointers
  22275.  
  22276.  
  22277.  CALL printmessage(SSEGADD(a$))
  22278.  
  22279.  
  22280.  
  22281.  
  22282.  This C routine prints a BASIC far string on the screen:
  22283.  
  22284.  
  22285.  #include <stdio.h>
  22286.  
  22287.  
  22288.  /* Define a procedure which inputs a string far pointer */
  22289.  
  22290.  
  22291.  void printmessage (char far *farpointer)
  22292.  
  22293.  
  22294.  {
  22295.  
  22296.  
  22297.  /* print the string addressed by the far pointer */
  22298.  
  22299.  
  22300.  printf( "%s\n", farpointer);
  22301.  
  22302.  
  22303.  }
  22304.  
  22305.  
  22306.  STACK Function
  22307.  ────────────────────────────────────────────────────────────────────────────
  22308.  
  22309.  
  22310.  Action
  22311.  
  22312.  Returns a long integer that is the maximum stack size that can be allocated.
  22313.  
  22314.  
  22315.  Syntax
  22316.  
  22317.  
  22318.  
  22319.   STACK
  22320.  
  22321.  Remarks
  22322.  
  22323.  
  22324.  The  STACK function can be used with the stack statement to set the stack to
  22325.  the maximum possible size. For example:
  22326.  
  22327.  STACK STACK
  22328.  
  22329.  
  22330.  See Also
  22331.  
  22332.  
  22333.   CLEAR,  STACK Statement
  22334.  
  22335.  
  22336.  Example
  22337.  
  22338.  See the  FRE function programming example, which uses the  STACK function.
  22339.  
  22340.  
  22341.  STACK Statement
  22342.  ────────────────────────────────────────────────────────────────────────────
  22343.  
  22344.  
  22345.  Action
  22346.  
  22347.  Resets the size of the stack.
  22348.  
  22349.  
  22350.  Syntax
  22351.  
  22352.  
  22353.  
  22354.   STACK   longinteger&
  22355.  
  22356.  Remarks
  22357.  
  22358.  
  22359.  The default stack size is 3K for DOS and 3.5K for OS/2. The minimum stack
  22360.  size
  22361.  
  22362.  (if  longinteger& is 0) is 0.325K for DOS and 0.825K for OS/2.
  22363.  
  22364.  The argument  longinteger& is the number of bytes to reserve for the stack.
  22365.  If  longinteger& is omitted, the stack is reset to its default size. If you
  22366.  request a stack space that is too large, the  STACK statement allocates as
  22367.  much stack space as possible.
  22368.  
  22369.  The  STACK statement is useful in programs that contain recursion and lots
  22370.  of nesting of sub and function procedures.
  22371.  
  22372.  The  STACK statement is allowed only at the module level.
  22373.  
  22374.  The  STACK function can be used with the stack statement to set the stack to
  22375.  the maximum possible size. For example:
  22376.  
  22377.  STACK STACK
  22378.  
  22379.  
  22380.  See Also
  22381.  
  22382.  
  22383.   CLEAR,  STACK Function
  22384.  
  22385.  
  22386.  Example
  22387.  
  22388.  See the  FRE function programming example, which uses the  STACK statement.
  22389.  
  22390.  
  22391.  $STATIC, $DYNAMIC Metacommands
  22392.  ────────────────────────────────────────────────────────────────────────────
  22393.  
  22394.  
  22395.  Action
  22396.  
  22397.  Set aside storage for arrays, while program is either compiling ( $STATIC)
  22398.  or running ( $DYNAMIC).
  22399.  
  22400.  
  22401.  Syntax
  22402.  
  22403.   REM $STATIC
  22404.   '$STATIC
  22405.  
  22406.   REM $DYNAMIC
  22407.   '$DYNAMIC
  22408.  
  22409.  Remarks
  22410.  
  22411.  
  22412.  The  $STATIC metacommand sets aside storage for arrays during compilation.
  22413.  When the  $STATIC metacommand is used, the  ERASE statement reinitializes
  22414.  all array values to zero (numeric arrays) or the null string (string arrays)
  22415.  but does not remove the array.
  22416.  
  22417.  The  $DYNAMIC metacommand allocates storage for arrays while the program is
  22418.  running. This means that the  ERASE statement removes the array and frees
  22419.  the memory it took for other uses. You also can use the  REDIM statement to
  22420.  change the size of an array allocated using  $DYNAMIC.
  22421.  
  22422.  The  $STATIC and  $DYNAMIC metacommands affect all arrays except implicitly
  22423.  dimensioned arrays (arrays not declared in a  DIM statement). Implicitly
  22424.  dimensioned arrays are always allocated as if  $STATIC had been used. All
  22425.  arrays inside a  SUB or  FUNCTION procedure are dynamic unless the  STATIC
  22426.  keyword is included in the  SUB or  FUNCTION statement.
  22427.  
  22428.  
  22429.  Example
  22430.  
  22431.  See the  ERASE statement programming example, which demonstrates uses of the
  22432.   $DYNAMIC and  $STATIC metacommands.
  22433.  
  22434.  
  22435.  STATIC Statement
  22436.  ────────────────────────────────────────────────────────────────────────────
  22437.  
  22438.  
  22439.  Action
  22440.  
  22441.  Makes simple variables or arrays local to a  DEF  FN function, a  FUNCTION
  22442.  procedure, or a  SUB procedure, and preserves values between calls.
  22443.  
  22444.  
  22445.  Syntax
  22446.  
  22447.  
  22448.  
  22449.   STATIC  variable( )  AS  type ,  variable( )  AS  type...
  22450.  
  22451.  Remarks
  22452.  
  22453.  
  22454.  The  STATIC statement uses the following arguments:
  22455.  
  22456. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  22457.  Argument                                Description
  22458.  ────────────────────────────────────────────────────────────────────────────
  22459.   variable                               The variable the procedure will
  22460.                                          use. It is either an array name
  22461.                                          followed by ( ), or a variable
  22462.                                          name.
  22463.  
  22464.   AS  type                               Declares the type of the variable.
  22465.                                          The type can be  INTEGER,  LONG,
  22466.                                          SINGLE,  DOUBLE,  STRING (for
  22467.                                          variable-length strings),  STRING
  22468.                                          *  length (for fixed-length
  22469.                                          strings),  CURRENCY, or a
  22470.                                          user-defined type.
  22471.  
  22472.  Argument                                Description
  22473.  ────────────────────────────────────────────────────────────────────────────
  22474. 
  22475.  
  22476.  
  22477.   STATIC is a BASIC declaration that makes simple variables or arrays local
  22478.  to a procedure (or a function defined by  DEF FN) and preserves the variable
  22479.  value between procedure calls.
  22480.  
  22481.  The  STATIC statement can appear only in a  SUB or  FUNCTION procedure or
  22482.  DEF  FN function. Earlier versions of BASIC required the number of
  22483.  dimensions in parentheses after an array name. The number of dimensions in
  22484.  BASIC is now optional.
  22485.  
  22486.  Variables declared in a  STATIC statement override variables of the same
  22487.  name shared by  DIM or  COMMON statements in the module-level code.
  22488.  Variables in a  STATIC statement also override global constants of the same
  22489.  name.
  22490.  
  22491.  Usually, variables used in  DEF  FN functions are global to the module;
  22492.  however, you can use the  STATIC statement inside a  DEF  FN statement to
  22493.  declare a variable as local to only that function.
  22494.  
  22495.  The differences between the  STATIC statement, the  STATIC attribute, and
  22496.  the  $STATIC metacommand are:
  22497. ╓┌─────────────────────────────────────┌─────────────────────────────────────╖
  22498.  Statement/Attribute                   Differences
  22499.  ────────────────────────────────────────────────────────────────────────────
  22500.   STATIC attribute on  SUB and         Declares default for variables to be
  22501.  FUNCTION statements                   static. Variables having the same
  22502.                                        name as variables shared by
  22503.                                        module-level code are still shared.
  22504.  
  22505.   STATIC statement                     Makes specific variables static and
  22506.                                        overrides any variables shared by
  22507.                                        the module-level code.
  22508.  
  22509.   $STATIC metacommand                  Affects how memory is allocated for
  22510.                                        arrays.
  22511.  
  22512.  
  22513.  
  22514.  
  22515.  See Also
  22516.  
  22517.   DEF  FN,  FUNCTION,  SUB
  22518.  
  22519.  
  22520.  Example
  22521.  
  22522.  
  22523.  The following example searches for every occurrence of a certain string
  22524.  expression in a file and replaces that string with another string. The
  22525.  program also prints the number of substitutions and the number of lines
  22526.  changed.
  22527.  
  22528.  INPUT "Name of file";F1$
  22529.  
  22530.  
  22531.  INPUT "String to replace";Old$
  22532.  
  22533.  
  22534.  INPUT "Replace with";Nw$
  22535.  
  22536.  
  22537.  Rep = 0 : Num = 0
  22538.  
  22539.  
  22540.  M = LEN(Old$)
  22541.  
  22542.  
  22543.  OPEN F1$ FOR INPUT AS #1
  22544.  
  22545.  
  22546.  CALL Extension
  22547.  
  22548.  
  22549.  OPEN F2$ FOR OUTPUT AS #2
  22550.  
  22551.  
  22552.  DO WHILE NOT EOF(1)
  22553.  
  22554.  
  22555.     LINE INPUT #1, Temp$
  22556.  
  22557.  
  22558.     CALL Search
  22559.  
  22560.  
  22561.     PRINT #2, Temp$
  22562.  
  22563.  
  22564.  LOOP
  22565.  
  22566.  
  22567.  CLOSE
  22568.  
  22569.  
  22570.  PRINT "There were ";Rep;" substitutions in ";Num;" lines."
  22571.  
  22572.  
  22573.  PRINT "Substitutions are in file ";F2$
  22574.  
  22575.  
  22576.  END
  22577.  
  22578.  
  22579.  
  22580.  
  22581.  
  22582.  SUB Extension STATIC
  22583.  
  22584.  
  22585.  SHARED F1$,F2$
  22586.  
  22587.  
  22588.     Mark = INSTR(F1$,".")
  22589.  
  22590.  
  22591.     IF Mark = 0 THEN
  22592.  
  22593.  
  22594.        F2$ = F1$ + ".NEW"
  22595.  
  22596.  
  22597.     ELSE
  22598.  
  22599.  
  22600.        F2$ = LEFT$(F1$,Mark - 1) + ".NEW"
  22601.  
  22602.  
  22603.     END IF
  22604.  
  22605.  
  22606.  END SUB
  22607.  
  22608.  
  22609.  
  22610.  
  22611.  
  22612.  SUB Search STATIC
  22613.  
  22614.  
  22615.  SHARED Temp$,Old$,Nw$,Rep,Num,M
  22616.  
  22617.  
  22618.  STATIC R
  22619.  
  22620.  
  22621.     Mark = INSTR(Temp$,Old$)
  22622.  
  22623.  
  22624.     WHILE Mark
  22625.  
  22626.  
  22627.        Part1$ = LEFT$(Temp$,Mark - 1)
  22628.  
  22629.  
  22630.        Part2$ = MID$(Temp$,Mark + M)
  22631.  
  22632.  
  22633.        Temp$ = Part1$ + Nw$ + Part2$
  22634.  
  22635.  
  22636.        R = R + 1
  22637.  
  22638.  
  22639.        Mark = INSTR(Temp$,Old$)
  22640.  
  22641.  
  22642.     WEND
  22643.  
  22644.  
  22645.     IF Rep = R THEN
  22646.  
  22647.  
  22648.         EXIT SUB
  22649.  
  22650.  
  22651.     ELSE
  22652.  
  22653.  
  22654.         Rep = R
  22655.  
  22656.  
  22657.         Num = Num + 1
  22658.  
  22659.  
  22660.     END IF
  22661.  
  22662.  
  22663.  END SUB
  22664.  
  22665.  
  22666.  STICK Function
  22667.  ────────────────────────────────────────────────────────────────────────────
  22668.  
  22669.  
  22670.  Action
  22671.  
  22672.  Returns joystick coordinates.
  22673.  
  22674.  
  22675.  Syntax
  22676.  
  22677.  
  22678.  
  22679.   STICK( n%)
  22680.  
  22681.  Remarks
  22682.  
  22683.  
  22684.  The argument   n% is a numeric expression whose value is an unsigned integer
  22685.  from 0 to 3 that indicates which joystick coordinate value to return:
  22686.  
  22687. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  22688.  Argument         Value returned
  22689.  ────────────────────────────────────────────────────────────────────────────
  22690.  0                Indicates the x coordinate of joystick A.
  22691.  1                Indicates the y coordinate of joystick A.
  22692.  2                Indicates the x coordinate of joystick B.
  22693.  3                Indicates the y coordinate of joystick B.
  22694.  
  22695.  
  22696.  Joystick coordinates range from 1 to 200 in both directions. You must use
  22697.  STICK(0) before you use STICK(1), STICK(2), or STICK(3) because STICK(0) not
  22698.  only returns the x coordinate of joystick A, but also records the other
  22699.  joystick coordinates. These recorded coordinates are returned by calling
  22700.  STICK(1), STICK(2), or STICK(3).
  22701.  
  22702.  
  22703.  Note
  22704.  
  22705.  The  STICK function is not available in OS/2 protected mode.
  22706.  
  22707.  
  22708.  Example
  22709.  
  22710.  See the  STRIG statements programming example, which uses the  STICK
  22711.  function.
  22712.  
  22713.  STOP Statement
  22714.  ────────────────────────────────────────────────────────────────────────────
  22715.  
  22716.  
  22717.  Action
  22718.  
  22719.  Terminates the program.
  22720.  
  22721.  
  22722.  Syntax
  22723.  
  22724.  
  22725.  
  22726.   STOP  n%
  22727.  
  22728.  Remarks
  22729.  
  22730.  
  22731.  The  STOP statement halts a program and returns the value  n% to the
  22732.  operating system. The value  n% can be used by DOS or OS/2 batch files or by
  22733.  non-BASIC programs. If  n% is omitted, the  STOP statement returns a value
  22734.  of 0. Untrapped errors and fatal errors set the value of  n% to -1.
  22735.  
  22736.  You can place a  STOP statement anywhere in a program to terminate
  22737.  execution.
  22738.  
  22739.  In a stand-alone program,  STOP closes all files and returns to the
  22740.  operating system; in the QBX environment,  STOP leaves files open and
  22741.  returns to that environment.
  22742.  
  22743.  If you use the /D, /E, or /X compiler option on the BC command line, the
  22744.  STOP statement prints line numbers as follows:
  22745. ╓┌──────────────────────────┌────────────────────────────────────────────────╖
  22746.  If your program has:       STOP prints:
  22747.  ────────────────────────────────────────────────────────────────────────────
  22748.  Line numbers               Number of the line where execution stopped.
  22749.  No line number for  STOP   Most recent line number.
  22750.  No line numbers            0
  22751.  
  22752.  
  22753.  In the QBX environment,  STOP always returns an error level of 0, even if
  22754.  you specify a different error level.
  22755.  
  22756.  In some previous versions of BASIC,  STOP statements were used for
  22757.  debugging. In the current version of BASIC, you do not have to use  STOP for
  22758.  debugging.
  22759.  
  22760.  
  22761.  See Also
  22762.  
  22763.   END,  SYSTEM
  22764.  
  22765.  
  22766.  Example
  22767.  
  22768.  See the  ON ERROR statement programming example, which uses the  STOP
  22769.  statement.
  22770.  
  22771.  
  22772.  STR$ Function
  22773.  ────────────────────────────────────────────────────────────────────────────
  22774.  
  22775.  
  22776.  Action
  22777.  
  22778.  Returns a string representation of the value of a numeric expression.
  22779.  
  22780.  
  22781.  Syntax
  22782.  
  22783.  
  22784.  
  22785.   STR$( numeric-expression)
  22786.  
  22787.  Remarks
  22788.  
  22789.  
  22790.  If  numeric-expression is positive, the string returned by the  STR$
  22791.  function contains a leading blank. The  VAL function complements  STR$.
  22792.  
  22793.  
  22794.  See Also
  22795.  
  22796.   VAL
  22797.  
  22798.  
  22799.  Example
  22800.  
  22801.  The following example uses the  STR$ function to convert a number to its
  22802.  string representation and strips out the leading and trailing blanks that
  22803.  BASIC ordinarily prints with numeric output:
  22804.  
  22805.  CLS                            ' Clear the screen.
  22806.  
  22807.  
  22808.  PRINT "Enter 0 to end."
  22809.  
  22810.  
  22811.  DO
  22812.  
  22813.  
  22814.      INPUT "Find cosine of: ",Num
  22815.  
  22816.  
  22817.      IF Num = 0 THEN EXIT DO
  22818.  
  22819.  
  22820.      X$ = STR$(Num)
  22821.  
  22822.  
  22823.      NumRemBlanks$ = LTRIM$(RTRIM$(X$))
  22824.  
  22825.  
  22826.      PRINT "COS(" NumRemBlanks$ ") = " COS(Num)
  22827.  
  22828.  
  22829.  LOOP
  22830.  
  22831.  
  22832.  
  22833.  
  22834.  Output
  22835.  
  22836.  
  22837.  
  22838.  Enter 0 to end.
  22839.  
  22840.  
  22841.  Find cosine of: 3.1
  22842.  
  22843.  
  22844.  COS(3.1) = -.9991351
  22845.  
  22846.  
  22847.  Find cosine of: 0
  22848.  
  22849.  
  22850.  STRIG Function
  22851.  ────────────────────────────────────────────────────────────────────────────
  22852.  
  22853.  
  22854.  Action
  22855.  
  22856.  Returns the status of a joystick trigger.
  22857.  
  22858.  
  22859.  Syntax
  22860.  
  22861.  
  22862.  
  22863.   STRIG( n%)
  22864.  
  22865.  Remarks
  22866.  
  22867.  
  22868.  The  STRIG function is used to test the joystick trigger status.
  22869.  
  22870.  The numeric expression  n% is an unsigned integer between 0 and 7 that
  22871.  indicates the joystick and trigger to check. The following list describes
  22872.  the values returned by the  STRIG( n%) function for different values of  n%:
  22873.  
  22874. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  22875.  Value                                   Returns
  22876.  ────────────────────────────────────────────────────────────────────────────
  22877.  0                                       -1 if the lower trigger on
  22878.                                          joystick A was pressed since the
  22879.                                          last STRIG(0) call, 0 if not.
  22880.  
  22881.  1                                       -1 if the lower trigger on
  22882.                                          joystick A is currently down, 0 if
  22883.                                          not.
  22884.  
  22885.  2                                       -1 if the lower trigger on
  22886.                                          joystick B was pressed since the
  22887.                                          last STRIG(2) call, 0 if not.
  22888.  
  22889.  3                                       -1 if the lower trigger on
  22890.                                          joystick B is currently down, 0 if
  22891.                                          not.
  22892.  Value                                   Returns
  22893.  ────────────────────────────────────────────────────────────────────────────
  22894.                                         not.
  22895.  
  22896.  4                                       -1 if the upper trigger on
  22897.                                          joystick A was pressed since the
  22898.                                          last STRIG(4) call, 0 if not.
  22899.  
  22900.  5                                       -1 if the upper trigger on
  22901.                                          joystick A is currently down, 0 if
  22902.                                          not.
  22903.  
  22904.  6                                       -1 if the upper trigger on
  22905.                                          joystick B was pressed since the
  22906.                                          last STRIG(6) call, 0 if not.
  22907.  
  22908.  7                                       -1 if the upper trigger on
  22909.                                          joystick B is currently down, 0 if
  22910.                                          not.
  22911.  
  22912.  
  22913.  
  22914.  For more information on joystick-event trapping, see the entry for  ON
  22915.  event. You cannot use the  STRIG function inside a joystick-event trap
  22916.  because the trigger information used by the  STRIG function will not be
  22917.  available for  ON  STRIG.
  22918.  
  22919.  In previous versions of BASIC, the statement  STRIG  ON enabled testing of
  22920.  the joystick triggers;  STRIG OFF disabled joystick-trigger testing. The
  22921.  current version of BASIC ignores these statements. (The old  STRIG ON and
  22922.  STRIG OFF statements are different from the  STRIG( n%)  ON,  STRIG( n%)
  22923.  OFF, and  STRIG( n%)  STOP statements. The  STRIG statements enable,
  22924.  disable, and inhibit trapping of joystick events.)
  22925.  
  22926.  
  22927.  Note
  22928.  
  22929.  The  STRIG function is not available in OS/2 protected mode.
  22930.  
  22931.  
  22932.  See Also
  22933.  
  22934.   ON  event,  STRIG Statements
  22935.  
  22936.  
  22937.  Example
  22938.  
  22939.  See the  STRIG statements programming example, which uses the  STRIG
  22940.  function.
  22941.  
  22942.  STRIG Statements
  22943.  ────────────────────────────────────────────────────────────────────────────
  22944.  
  22945.  
  22946.  Action
  22947.  
  22948.  Enable, disable, or suspend trapping of joystick activity.
  22949.  
  22950.  
  22951.  Syntax
  22952.  
  22953.  
  22954.  
  22955.   STRIG( n%)  ON
  22956.  
  22957.  
  22958.   STRIG( n%)  OFF
  22959.  
  22960.  
  22961.   STRIG( n%)  STOP
  22962.  
  22963.  Remarks
  22964.  
  22965.  
  22966.  The argument  n% is the trigger number as defined in the following table:
  22967. ╓┌──┌────────┌───────────────────────────────────────────────────────────────╖
  22968.  n  Trigger  Joystick
  22969.  ────────────────────────────────────────────────────────────────────────────
  22970.  0  Lower    First
  22971.  2  Lower    Second
  22972.  4  Upper    First
  22973.  6  Upper    Second
  22974.  
  22975.  
  22976.   STRIG( n%)  ON enables joystick-event trapping. If joystick trigger  n% is
  22977.  pressed after a  STRIG( n%)  ON statement, the routine specified in the  ON
  22978.  STRIG statement is executed.
  22979.  
  22980.  The  STRIG( n%)  OFF statement disables joystick-event trapping. No joystick
  22981.  event trapping takes place until a  STRIG( n%)  ON statement is executed.
  22982.  Events occurring while trapping is off are ignored. However, remembered
  22983.  events are lost if  STRIG( n%)  OFF is executed.
  22984.  
  22985.  The  STRIG( n%)  STOP statement suspends joystick-event trapping. No
  22986.  joystick-event trapping takes place until a  STRIG( n%)  ON statement is
  22987.  executed. Events occurring while trapping is suspended are remembered and
  22988.  processed when the next  STRIG( n%)  ON statement is executed. However,
  22989.  remembered events are lost if  STRIG( n%)  OFF is executed.
  22990.  
  22991.  When a joystick-event trap occurs (that is, the  GOSUB is performed), an
  22992.  automatic  STRIG  STOP is executed so that recursive traps cannot take
  22993.  place. The  RETURN operation from the trapping routine automatically
  22994.  performs a  STRIG  ON statement unless an explicit  STRIG  OFF was performed
  22995.  inside the routine.
  22996.  
  22997.  In previous versions of BASIC, the  STRIG  ON statement enabled testing of
  22998.  the joystick triggers;  STRIG  OFF disabled joystick-trigger testing. The
  22999.  current version of BASIC ignores the  STRIG  ON and  STRIG  OFF statements.
  23000.  
  23001.  For more information, see Chapter 9, "Event Handling" in the  Programmer's
  23002.  Guide.
  23003.  
  23004.  
  23005.  Note
  23006.  
  23007.  The  STRIG statement is not available for OS/2 protected mode.
  23008.  
  23009.  
  23010.  See Also
  23011.  
  23012.   ON  event,  STRIG Function
  23013.  
  23014.  
  23015.  Example
  23016.  
  23017.  
  23018.  The following example sets up joystick events for two triggers on each of
  23019.  two joysticks. It also displays the current x and y coordinate position of
  23020.  both joysticks. If any trigger is pressed, control is passed to a routine
  23021.  that indicates the state of the trigger; that is, whether the trigger is
  23022.  down or up. This example exercises the  STRIG statements, the  STRIG
  23023.  function, the  ON STRIG statement, the  STICK function, and the  EVENT
  23024.  statements.
  23025.  
  23026.  ' Turn on event processing.
  23027.  
  23028.  
  23029.  EVENT ON
  23030.  
  23031.  
  23032.  
  23033.  
  23034.  
  23035.  ' Enable the upper and lower triggers on both joysticks.
  23036.  
  23037.  
  23038.  STRIG(0) ON 'Lower trigger, joystick A
  23039.  
  23040.  
  23041.  STRIG(2) ON 'Lower trigger, joystick B
  23042.  
  23043.  
  23044.  STRIG(4) ON  'Upper trigger, joystick A
  23045.  
  23046.  
  23047.  STRIG(6) ON  'Upper trigger, joystick B
  23048.  
  23049.  
  23050.  
  23051.  
  23052.  
  23053.  ' Set up joystick-event processing for each trigger.
  23054.  
  23055.  
  23056.  ON STRIG(0) GOSUB JoyTriggerHandler
  23057.  
  23058.  
  23059.  ON STRIG(2) GOSUB JoyTriggerHandler
  23060.  
  23061.  
  23062.  ON STRIG(4) GOSUB JoyTriggerHandler
  23063.  
  23064.  
  23065.  ON STRIG(6) GOSUB JoyTriggerHandler
  23066.  
  23067.  
  23068.  
  23069.  
  23070.  
  23071.  LOCATE 22, 6
  23072.  
  23073.  
  23074.  PRINT "Press a trigger on either joystick to see a complete report."
  23075.  
  23076.  
  23077.  LOCATE 23, 20
  23078.  
  23079.  
  23080.  PRINT "Press ANY keyboard key to end the program."
  23081.  
  23082.  
  23083.  
  23084.  
  23085.  
  23086.  ' Infinite loop waiting for a joystick event or keyboard input.
  23087.  
  23088.  
  23089.  DO
  23090.  
  23091.  
  23092.  LOOP WHILE INKEY$ = ""
  23093.  
  23094.  
  23095.  
  23096.  
  23097.  
  23098.  WrapItUp:
  23099.  
  23100.  
  23101.     CLS
  23102.  
  23103.  
  23104.     STRIG(0) OFF
  23105.  
  23106.  
  23107.     STRIG(2) OFF
  23108.  
  23109.  
  23110.     STRIG(4) OFF
  23111.  
  23112.  
  23113.     STRIG(6) OFF
  23114.  
  23115.  
  23116.     END
  23117.  
  23118.  
  23119.  
  23120.  
  23121.  
  23122.  JoyTriggerHandler:
  23123.  
  23124.  
  23125.      ' Print a label on screen.
  23126.  
  23127.  
  23128.      LOCATE 10, 14: PRINT "Joystick A"
  23129.  
  23130.  
  23131.      LOCATE 10, 45: PRINT "Joystick B"
  23132.  
  23133.  
  23134.      LOCATE 22, 1: PRINT STRING$(80, 32)
  23135.  
  23136.  
  23137.      DO
  23138.  
  23139.  
  23140.          IF STRIG(1) THEN   ' Trigger 1, Joystick A.
  23141.  
  23142.  
  23143.                  TriggerStatus$ = "DOWN"
  23144.  
  23145.  
  23146.          ELSE
  23147.  
  23148.  
  23149.                  TriggerStatus$ = "UP  "
  23150.  
  23151.  
  23152.          END IF
  23153.  
  23154.  
  23155.          EVENT OFF
  23156.  
  23157.  
  23158.          LOCATE 16, 10: PRINT "Trigger 1 is "; TriggerStatus$
  23159.  
  23160.  
  23161.          EVENT ON
  23162.  
  23163.  
  23164.  
  23165.  
  23166.  
  23167.          IF STRIG(3) THEN   ' Trigger 1, Joystick B.
  23168.  
  23169.  
  23170.                  TriggerStatus$ = "DOWN"
  23171.  
  23172.  
  23173.          ELSE
  23174.  
  23175.  
  23176.                  TriggerStatus$ = "UP  "
  23177.  
  23178.  
  23179.          END IF
  23180.  
  23181.  
  23182.          EVENT OFF
  23183.  
  23184.  
  23185.          LOCATE 16, 42: PRINT "Trigger 1 is "; TriggerStatus$
  23186.  
  23187.  
  23188.          EVENT ON
  23189.  
  23190.  
  23191.  
  23192.  
  23193.  
  23194.          IF STRIG(5) THEN   ' Trigger 2, Joystick A.
  23195.  
  23196.  
  23197.                  TriggerStatus$ = "DOWN"
  23198.  
  23199.  
  23200.          ELSE
  23201.  
  23202.  
  23203.                  TriggerStatus$ = "UP  "
  23204.  
  23205.  
  23206.          END IF
  23207.  
  23208.  
  23209.          EVENT OFF
  23210.  
  23211.  
  23212.          LOCATE 18, 10: PRINT "Trigger 2 is "; TriggerStatus$
  23213.  
  23214.  
  23215.          EVENT ON
  23216.  
  23217.  
  23218.  
  23219.  
  23220.  
  23221.          IF STRIG(7) THEN    ' Trigger 2, Joystick B.
  23222.  
  23223.  
  23224.                  TriggerStatus$ = "DOWN"
  23225.  
  23226.  
  23227.          ELSE
  23228.  
  23229.  
  23230.                  TriggerStatus$ = "UP  "
  23231.  
  23232.  
  23233.          END IF
  23234.  
  23235.  
  23236.          EVENT OFF
  23237.  
  23238.  
  23239.          LOCATE 18, 42: PRINT "Trigger 2 is "; TriggerStatus$
  23240.  
  23241.  
  23242.          EVENT ON
  23243.  
  23244.  
  23245.          GOSUB UpdateXY
  23246.  
  23247.  
  23248.      LOOP WHILE INKEY$ = ""
  23249.  
  23250.  
  23251.      RETURN WrapItUp
  23252.  
  23253.  
  23254.  
  23255.  
  23256.  
  23257.  UpdateXY:
  23258.  
  23259.  
  23260.      EVENT OFF
  23261.  
  23262.  
  23263.      LOCATE 12, 10: PRINT USING "X Position = ###"; STICK(0)
  23264.  
  23265.  
  23266.      LOCATE 14, 10: PRINT USING "Y Position = ###"; STICK(1)
  23267.  
  23268.  
  23269.      LOCATE 12, 42: PRINT USING "X Position = ###"; STICK(2)
  23270.  
  23271.  
  23272.      LOCATE 14, 42: PRINT USING "Y Position = ###"; STICK(3)
  23273.  
  23274.  
  23275.      EVENT ON
  23276.  
  23277.  
  23278.  RETURN
  23279.  
  23280.  
  23281.  STRING$ Function
  23282.  ────────────────────────────────────────────────────────────────────────────
  23283.  
  23284.  
  23285.  Action
  23286.  
  23287.  Returns a string whose characters all have a given ASCII code or whose
  23288.  characters are all the first character of a string expression.
  23289.  
  23290.  
  23291.  Syntax 1
  23292.  
  23293.   STRING$( m%,  n%)
  23294.  
  23295.  Syntax 2
  23296.  
  23297.   STRING$( m%,  stringexpression$)
  23298.  
  23299.  
  23300.  Remarks
  23301.  
  23302.  
  23303.  The  STRING$ function uses the following arguments:
  23304.  
  23305. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  23306.  Argument                                Description
  23307.  ────────────────────────────────────────────────────────────────────────────
  23308.   m%                                     A numeric expression indicating
  23309.                                          the length of the string to return.
  23310.  
  23311.   n%                                     The ASCII code of the character to
  23312.  Argument                                Description
  23313.  ────────────────────────────────────────────────────────────────────────────
  23314.  n%                                     The ASCII code of the character to
  23315.                                          use to build the string. It is a
  23316.                                          numeric expression that BASIC
  23317.                                          converts to an integer value
  23318.                                          between 0 and 255, inclusive.
  23319.  
  23320.   stringexpression$                      The string expression whose first
  23321.                                          character is used to build the
  23322.                                          return string.
  23323.  
  23324.  
  23325.  
  23326.  
  23327.  
  23328.  
  23329.  Examples
  23330.  
  23331.  The first example uses  STRING$ to create part of a report heading:
  23332.  
  23333.  Dash$ = STRING$(10,45)
  23334.  
  23335.  
  23336.  PRINT Dash$;"MONTHLY REPORT";Dash$
  23337.  
  23338.  
  23339.  
  23340.  
  23341.  Output
  23342.  
  23343.  
  23344.  
  23345.  ----------MONTHLY REPORT----------
  23346.  
  23347.  
  23348.  
  23349.  
  23350.  This example uses  STRING$ to generate a bar graph:
  23351.  
  23352.  
  23353.  PRINT TAB(7);"Daily Mean Temperature in Seattle" : PRINT
  23354.  
  23355.  
  23356.  ' Read and graph data for each month.
  23357.  
  23358.  
  23359.  FOR Month = 1 TO 12 STEP 2
  23360.  
  23361.  
  23362.      READ Month$, Temp
  23363.  
  23364.  
  23365.      ' Print Temp-35 stars.
  23366.  
  23367.  
  23368.      PRINT Month$;" +"; STRING$(Temp-35,"*")
  23369.  
  23370.  
  23371.      PRINT "    |"
  23372.  
  23373.  
  23374.  NEXT Month
  23375.  
  23376.  
  23377.  ' Print horizontal line.
  23378.  
  23379.  
  23380.  PRINT "    +";
  23381.  
  23382.  
  23383.  FOR X = 1 TO 7
  23384.  
  23385.  
  23386.      PRINT "----+";
  23387.  
  23388.  
  23389.  NEXT X
  23390.  
  23391.  
  23392.  PRINT
  23393.  
  23394.  
  23395.  ' Print temperature labels.
  23396.  
  23397.  
  23398.  FOR X = 4 TO 39 STEP 5
  23399.  
  23400.  
  23401.      PRINT TAB(X); X+31;
  23402.  
  23403.  
  23404.  NEXT X
  23405.  
  23406.  
  23407.  PRINT
  23408.  
  23409.  
  23410.  
  23411.  
  23412.  
  23413.  DATA Jan, 40, Mar, 46, May, 56
  23414.  
  23415.  
  23416.  DATA Jul, 66, Sep, 61, Nov, 46
  23417.  
  23418.  
  23419.  
  23420.  
  23421.  Output
  23422.  
  23423.  
  23424.  
  23425.  Daily Mean Temperature in Seattle
  23426.  
  23427.  
  23428.  Jan +*****
  23429.      |
  23430.  Mar +***********
  23431.      |
  23432.  May +*********************
  23433.      |
  23434.  Jul +*******************************
  23435.      |
  23436.  Sep +**************************
  23437.      |
  23438.  Nov +***********
  23439.      |
  23440.      +----+----+----+----+----+----+----+
  23441.      35   40   45   50   55   60   65   70
  23442.  
  23443.  
  23444.  
  23445.  
  23446.  StringAddress Routine
  23447.  ────────────────────────────────────────────────────────────────────────────
  23448.  
  23449.  
  23450.  Action
  23451.  
  23452.  Used in mixed-language programming to returns the far address of a
  23453.  variable-length string.
  23454.  
  23455.  
  23456.  Syntax
  23457.  
  23458.  
  23459.  
  23460.   far-address =  StringAddress( string-descriptor%);
  23461.  
  23462.  Remarks
  23463.  
  23464.  
  23465.  The syntax above is for the C language. For MASM, Pascal, and FORTRAN
  23466.  examples, see Chapter 13, "Mixed-Language Programming with Far Strings" in
  23467.  the  Programmer's Guide.
  23468.  
  23469.   StringAddress returns the far address of the variable-length string defined
  23470.  by  string-descriptor%. The argument  string-descriptor% is the near address
  23471.  of a string descriptor within a non-BASIC routine.
  23472.  
  23473.  A non-BASIC routine uses  StringAddress to find the far address of a BASIC
  23474.  variable-length string. Calls to the  StringAddress routine always are made
  23475.  from a non-BASIC routine to find the address of a string that was
  23476.  transferred to BASIC from the non-BASIC routine.
  23477.  
  23478.  For example, assume that you have passed a string from a MASM routine to
  23479.  BASIC's string space using  StringAssign. The descriptor for the string
  23480.  exists at offset descriptor. MASM can find the far address of the string
  23481.  data using the following code:
  23482.  
  23483.  leaax, descriptor ; offset of descriptor
  23484.  
  23485.  
  23486.  pushax
  23487.  
  23488.  
  23489.  extrnstringaddress: proc far
  23490.  
  23491.  
  23492.  callstringaddress
  23493.  
  23494.  
  23495.  
  23496.  
  23497.  The far address is returned in DX:AX. DX holds the segment and AX holds the
  23498.  offset.
  23499.  
  23500.  
  23501.  
  23502.  Note
  23503.  
  23504.  If you are not doing mixed-language programming, there usually is no reason
  23505.  to use  StringAddress. Instead, use  SSEGADD to find the far address of a
  23506.  variable-length string.
  23507.  
  23508.  For more information on mixed-language programming with strings, see Chapter
  23509.  12, "Mixed-Language Programming" and Chapter 13, "Mixed-Language Programming
  23510.  with Far Strings" in the  Programmer's  Guide.
  23511.  
  23512.  
  23513.  See Also
  23514.  
  23515.   SSEGADD,  StringAssign,  StringLength,  StringRelease
  23516.  
  23517.  
  23518.  Example
  23519.  
  23520.  
  23521.  The following example shows how to use  StringAddress and  StringLength,
  23522.  routines in the BASIC main library.
  23523.  
  23524.  The program creates a string in BASIC, then passes it to MASM, which uses
  23525.  StringAddress to find the data that needs to be printed. It uses
  23526.  StringLength to tell the system the length of the string.
  23527.  
  23528.  DEFINT A-Z
  23529.  
  23530.  
  23531.  ' Create a variable-length string.
  23532.  
  23533.  
  23534.  Message1$ = "This string was sent to MASM for printing."
  23535.  
  23536.  
  23537.  ' Pass it to MASM to be printed.
  23538.  
  23539.  
  23540.  CALL PrintMessage1(Message1$)
  23541.  
  23542.  
  23543.  
  23544.  
  23545.  The following MASM procedure must be assembled and the .OBJ file linked to
  23546.  the BASIC code listed above.
  23547.  
  23548.  
  23549.  ; *************************PrintMessage1************************
  23550.  
  23551.  
  23552.  ; Prints a string passed by BASIC.
  23553.  
  23554.  
  23555.  
  23556.  
  23557.  
  23558.  .model  medium, basic; Use same model as BASIC.
  23559.  
  23560.  
  23561.  .code
  23562.  
  23563.  
  23564.  
  23565.  
  23566.  
  23567.  ; Define procedure with one-word argument.
  23568.  
  23569.  
  23570.  PrintMessage1 procuses ds, descriptor
  23571.  
  23572.  
  23573.  
  23574.  
  23575.  
  23576.  ; Define external (BASIC library) procedures.
  23577.  
  23578.  
  23579.  extrnStringAddress: proc far
  23580.  
  23581.  
  23582.  extrnStringLength: proc far
  23583.  
  23584.  
  23585.  
  23586.  
  23587.  
  23588.  mov ax, descriptor ; Find length of string.
  23589.  
  23590.  
  23591.  pushax
  23592.  
  23593.  
  23594.  callStringLength
  23595.  
  23596.  
  23597.  pushax; Save length on stack.
  23598.  
  23599.  
  23600.  
  23601.  
  23602.  
  23603.  mov ax, descriptor ; Go find out the
  23604.  
  23605.  
  23606.  pushax; address of the string
  23607.  
  23608.  
  23609.  CALLStringAddress; data.
  23610.  
  23611.  
  23612.  
  23613.  
  23614.  
  23615.  mov ds, dx  ; Address of string.
  23616.  
  23617.  
  23618.  mov dx, ax
  23619.  
  23620.  
  23621.  mov bx, 01  ; Handle of printer.
  23622.  
  23623.  
  23624.  pop cx; Length of string.
  23625.  
  23626.  
  23627.  mov ah, 40h ; Have DOS print it.
  23628.  
  23629.  
  23630.  int 21h
  23631.  
  23632.  
  23633.  ret
  23634.  
  23635.  
  23636.  PrintMessage1 endp
  23637.  
  23638.  
  23639.  
  23640.  
  23641.  
  23642.  end
  23643.  
  23644.  
  23645.  StringAssign Routine
  23646.  ────────────────────────────────────────────────────────────────────────────
  23647.  
  23648.  
  23649.  Action
  23650.  
  23651.  Used in mixed-language programming to transfer string data from one
  23652.  language's memory space to that of another.
  23653.  
  23654.  
  23655.  Syntax
  23656.  
  23657.  
  23658.  
  23659.   StringAssign( sourceaddress&,  sourcelength%,  destaddress&,  destlength%);
  23660.  
  23661.  Remarks
  23662.  
  23663.  
  23664.  The syntax above is for the C language. However, the order of the arguments
  23665.  in the syntax follows BASIC, Pascal and FORTRAN calling conventions rather
  23666.  than the C calling convention. (In BASIC, Pascal and FORTRAN, the arguments
  23667.  are passed in the order in which they appear in the source code. In C, the
  23668.  arguments are passed in the reverse order.)
  23669.  
  23670.  For MASM, Pascal, and FORTRAN examples, see Chapter 13, "Mixed-Language
  23671.  Programming with Far Strings" in the  Programmer's Guide.
  23672.  
  23673.  The  StringAssign routine uses the following arguments:
  23674.  
  23675. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  23676.  Argument                                Description
  23677.  ────────────────────────────────────────────────────────────────────────────
  23678.   sourceaddress&                         The far address of the start of
  23679.                                          string data (if the source is a
  23680.                                          fixed-length string), or the far
  23681.                                          address of the string descriptor
  23682.                                          (if the source is a
  23683.                                          variable-length string). The
  23684.                                          sourceaddress& is a long integer.
  23685.  
  23686.   sourcelength%                          The string length (if the source
  23687.                                          is a fixed-length string), or 0
  23688.                                          (if the source is a
  23689.                                          variable-length string). The
  23690.  Argument                                Description
  23691.  ────────────────────────────────────────────────────────────────────────────
  23692.                                         variable-length string). The
  23693.                                          sourcelength% is an integer.
  23694.  
  23695.   destaddress&                           The far address of the start of
  23696.                                          string data (if the destination is
  23697.                                          a fixed-length string), or the far
  23698.                                          address of the string descriptor
  23699.                                          (if the destination is a
  23700.                                          variable-length string). The
  23701.                                          destaddress& is a long integer.
  23702.  
  23703.   destlength%                            The string length (if the
  23704.                                          destination is a fixed-length
  23705.                                          string), or0 (if the destination
  23706.                                          is a variable-length string). The
  23707.                                          destlength% is an integer.
  23708.  
  23709.  
  23710.  
  23711.  
  23712.  
  23713.  The  StringAssign routine is used in mixed-language programming to transfer
  23714.  a string from BASIC to a non-BASIC routine or from a non-BASIC routine to
  23715.  BASIC. A typical use is to transfer a string from BASIC to a non-BASIC
  23716.  routine, process the string using the non-BASIC routine, and then transfer
  23717.  the modified string back to BASIC.
  23718.  
  23719.  Calls to the  StringAssign routine are usually made from a C, MASM, Pascal,
  23720.  or FORTRAN routine. Seldom, if ever, would you call  StringAssign from
  23721.  inside a BASIC program.
  23722.  
  23723.   StringAssign can be used to transfer both near and far strings. Using
  23724.  StringAssign, you can write mixed-language programs that are
  23725.  near-string/far-string independent.
  23726.  
  23727.  MASM, C, Pascal, and FORTRAN deal only with fixed-length strings. When
  23728.  programming in these languages you can use  StringAssign to create a new
  23729.  BASIC variable-length string and transfer fixed-length string data to it.
  23730.  For example, to transfer a MASM fixed-length string containing the word
  23731.  "Hello" to a BASIC variable-length string, you would use the following data
  23732.  structure:
  23733.  
  23734.  
  23735.  fixedstringdb "Hello" ; source of data
  23736.  
  23737.  
  23738.  descriptor dd 0; descriptor for destination
  23739.  
  23740.  
  23741.  
  23742.  
  23743.  The second data element, descriptor, is a 4-byte string descriptor
  23744.  initialized to zero. BASIC interprets this to mean that it should create a
  23745.  new variable-length string and associate it with the address labelled
  23746.  descriptor.
  23747.  
  23748.  
  23749.  To create a new BASIC variable-length string and transfer fixed-length data
  23750.  to it, the  StringAssign routine requires four arguments:
  23751.  
  23752.    ■         The far address of the fixed-length string in the MASM data
  23753.              segment.
  23754.  
  23755.    ■         The length of the fixed-length string in the MASM data segment.
  23756.  
  23757.    ■         The far address of the string descriptor in the MASM data
  23758.              segment.
  23759.  
  23760.    ■         0 (to indicate that the string in the BASIC data segment will be
  23761.              a variable-length string).
  23762.  
  23763.  The following MASM code pushes these arguments on the stack and calls
  23764.  StringAssign:
  23765.  
  23766.  pushds; segment of fixed-length string
  23767.  
  23768.  
  23769.  lea ax, fixedstring ; offset of fixed-length string
  23770.  
  23771.  
  23772.  pushax
  23773.  
  23774.  
  23775.  mov ax, 5; length of "Hello"
  23776.  
  23777.  
  23778.  pushax
  23779.  
  23780.  
  23781.  pushds; segment of descriptor
  23782.  
  23783.  
  23784.  lea ax, descriptor ; offset of descriptor
  23785.  
  23786.  
  23787.  pushax
  23788.  
  23789.  
  23790.  mov ax, 0 ; 0 = variable-length string
  23791.  
  23792.  
  23793.  pushax
  23794.  
  23795.  
  23796.  extrnstringassign: proc far
  23797.  
  23798.  
  23799.  callstringassign
  23800.  
  23801.  
  23802.  
  23803.  
  23804.  When the call to  StringAssign is made, BASIC will fill in the double-word
  23805.  descriptor with the correct string descriptor.
  23806.  
  23807.  Note
  23808.  
  23809.  When creating a new variable-length string, you must allocate 4 bytes of
  23810.  static data for a string descriptor as shown above. Allocating the data on
  23811.  the stack will not work.
  23812.  
  23813.  For more information on mixed-language programming with strings, see Chapter
  23814.  12, "Mixed-Language Programming" and Chapter 13, "Mixed-Language Programming
  23815.  with Far Strings" in the  Programmer's  Guide.
  23816.  
  23817.  
  23818.  See Also
  23819.  
  23820.  
  23821.   StringAddress,  StringLength,  StringRelease
  23822.  
  23823.  
  23824.  Example
  23825.  
  23826.  The following example shows how to use  StringAssign and  StringRelease,
  23827.  routines in the BASIC main library. The program gets a MASM string and
  23828.  prints it on the screen.
  23829.  
  23830.  DEFINT A-Z
  23831.  
  23832.  
  23833.  ' Declare external MASM procedures.
  23834.  
  23835.  
  23836.  DECLARE FUNCTION MakeString$
  23837.  
  23838.  
  23839.  DECLARE SUB ReleaseIt
  23840.  
  23841.  
  23842.  
  23843.  
  23844.  
  23845.  ' Get string from MASM and print it.
  23846.  
  23847.  
  23848.  PRINT MakeString
  23849.  
  23850.  
  23851.  
  23852.  
  23853.  
  23854.  ' Have MASM release the variable-length string it created.
  23855.  
  23856.  
  23857.  CALL ReleaseIt
  23858.  
  23859.  
  23860.  
  23861.  
  23862.  The following MASM procedure must be assembled and the .OBJ file linked to
  23863.  the BASIC code listed above:
  23864.  
  23865.  
  23866.  ; ************************** MakeString ***************************
  23867.  
  23868.  
  23869.  ; Create a fixed-length string and assign it to a BASIC
  23870.  
  23871.  
  23872.  ; variable-length string. Release the string after BASIC uses it.
  23873.  
  23874.  
  23875.  
  23876.  
  23877.  
  23878.  .model  medium, basic ; Use same model as BASIC.
  23879.  
  23880.  
  23881.  .data
  23882.  
  23883.  
  23884.  ; Create MASM string and a place for BASIC to create a
  23885.  
  23886.  
  23887.  ; variable-length string descriptor.
  23888.  
  23889.  
  23890.  String2db  "This is a string created by MASM."
  23891.  
  23892.  
  23893.  Descriptor dd  0
  23894.  
  23895.  
  23896.  
  23897.  
  23898.  
  23899.  .code
  23900.  
  23901.  
  23902.  
  23903.  
  23904.  
  23905.  ; Declare BASIC library routines to be used.
  23906.  
  23907.  
  23908.  extrnStringAssign: proc far
  23909.  
  23910.  
  23911.  extrnStringRelease: proc far
  23912.  
  23913.  
  23914.  
  23915.  
  23916.  
  23917.  MakeString proc; Push arguments:
  23918.  
  23919.  
  23920.  pushds; MASM string segment
  23921.  
  23922.  
  23923.  lea ax, String2; MASM string offset
  23924.  
  23925.  
  23926.  pushax
  23927.  
  23928.  
  23929.  mov ax, 33; MASM string length
  23930.  
  23931.  
  23932.  pushax
  23933.  
  23934.  
  23935.  pushds; BASIC descriptor segment
  23936.  
  23937.  
  23938.  lea ax, Descriptor
  23939.  
  23940.  
  23941.  pushax; BASIC descriptor offset
  23942.  
  23943.  
  23944.  xor ax, ax; Variable-length indicator
  23945.  
  23946.  
  23947.  pushax
  23948.  
  23949.  
  23950.  callStringAssign; Assign the string.
  23951.  
  23952.  
  23953.  
  23954.  
  23955.  
  23956.  lea ax, descriptor ; Return with descriptor
  23957.  
  23958.  
  23959.  ret ; address in AX.
  23960.  
  23961.  
  23962.  MakeString endp
  23963.  
  23964.  
  23965.  
  23966.  
  23967.  
  23968.  ReleaseIt  proc; Routine to release
  23969.  
  23970.  
  23971.  lea ax, Descriptor ; the string.
  23972.  
  23973.  
  23974.  pushax
  23975.  
  23976.  
  23977.  callStringRelease
  23978.  
  23979.  
  23980.  ret
  23981.  
  23982.  
  23983.  ReleaseIt  endp
  23984.  
  23985.  
  23986.  end
  23987.  
  23988.  
  23989.  StringLength Routine
  23990.  ────────────────────────────────────────────────────────────────────────────
  23991.  
  23992.  
  23993.  Action
  23994.  
  23995.  Used in mixed-language programming to return the length of a variable-length
  23996.  string.
  23997.  
  23998.  
  23999.  Syntax
  24000.  
  24001.  
  24002.  
  24003.   length =  StringLength( string-descriptor%);
  24004.  
  24005.  Remarks
  24006.  
  24007.  
  24008.  The syntax above is for the C language. For MASM, Pascal, and FORTRAN
  24009.  examples, see Chapter 13, "Mixed-Language Programming with Far Strings" in
  24010.  the  Programmer's Guide.
  24011.  
  24012.  A non-BASIC routine uses  StringLength to return the number of characters in
  24013.  a BASIC variable-length string.
  24014.  
  24015.  Calls to the  StringLength routine are usually made from a non-BASIC
  24016.  routine. The argument  string-descriptor% is an integer that is the near
  24017.  address of a string descriptor within a non-BASIC routine.
  24018.  
  24019.  As an example, assume that a MASM routine takes a pointer to a string
  24020.  descriptor as a parameter. MASM can find the length of the string data with
  24021.  the following code:
  24022.  
  24023.  movax, psdparm; offset of descriptor
  24024.  
  24025.  
  24026.  pushax
  24027.  
  24028.  
  24029.  extrnstringlength: proc far
  24030.  
  24031.  
  24032.  callstringlength
  24033.  
  24034.  
  24035.  
  24036.  
  24037.  The length of the string is returned in AX.
  24038.  
  24039.  
  24040.  
  24041.  Note
  24042.  
  24043.  If you are not doing mixed-language programming, there is usually no reason
  24044.  to use  StringLength. Instead, use  LEN to find the length of a
  24045.  variable-length string.
  24046.  
  24047.  For more information on mixed-language programming with strings, see Chapter
  24048.  12, "Mixed-Language Programming" and Chapter 13, "Mixed-Language Programming
  24049.  with Far Strings" in the  Programmer's  Guide.
  24050.  
  24051.  
  24052.  See Also
  24053.  
  24054.  L EN,  StringAddress,  StringAssign,  StringRelease
  24055.  
  24056.  
  24057.  Example
  24058.  
  24059.  See the  StringAddress routine programming example, which uses the
  24060.  StringLength routine.
  24061.  
  24062.  
  24063.  StringRelease Routine
  24064.  ────────────────────────────────────────────────────────────────────────────
  24065.  
  24066.  
  24067.  Action
  24068.  
  24069.  Deallocates variable-length strings that have been transferred to BASIC's
  24070.  string space from a non-BASIC routine.
  24071.  
  24072.  
  24073.  Syntax
  24074.  
  24075.  
  24076.  
  24077.   StringRelease( string-descriptor%);
  24078.  
  24079.  Remarks
  24080.  
  24081.  
  24082.  The syntax above is for the C language. For MASM, Pascal, and FORTRAN
  24083.  examples, see Chapter 13, "Mixed-Language Programming with Far Strings" in
  24084.  the  Programmer's Guide.
  24085.  
  24086.   StringRelease is used in mixed-language programming.  StringRelease is used
  24087.  by a non-BASIC routine to deallocate variable-length strings that have been
  24088.  transferred to BASIC's string space from the non-BASIC routine.
  24089.  
  24090.  Calls to the  StringRelease routine are made from a non-BASIC routine to
  24091.  free up space in BASIC's data area. The argument  string-descriptor% is an
  24092.  integer that is the near address of a string descriptor within a non-BASIC
  24093.  routine.
  24094.  
  24095.  BASIC automatically deallocates strings allocated by BASIC. However, strings
  24096.  that have been transferred to BASIC from a non-BASIC routine should be
  24097.  deallocated from the non-BASIC routine using the  StringRelease routine.
  24098.  (The reason for this is that  StringAssign transfers strings but not string
  24099.  descriptors. Without the string descriptor, BASIC cannot deallocate the
  24100.  string; the deallocation has to be done from the non-BASIC routine with
  24101.  StringRelease.)
  24102.  
  24103.  As an example, assume that you have passed a string from a MASM routine to
  24104.  BASIC's string space using  StringAssign. To deallocate this string,
  24105.  assuming a descriptor for the variable-length string exists at offset
  24106.  descriptor, the code would be as follows:
  24107.  
  24108.  leaax, descriptor ; offset of descriptor
  24109.  
  24110.  
  24111.  pushax
  24112.  
  24113.  
  24114.  extrnstringrelease: proc far
  24115.  
  24116.  
  24117.  call stringrelease
  24118.  
  24119.  
  24120.  Warning
  24121.  
  24122.  
  24123.  Use the  StringRelease routine only to deallocate variable-length strings
  24124.  that have been transferred to BASIC's string space from a non-BASIC routine.
  24125.  Never use it on strings created by BASIC. Doing so may cause unpredictable
  24126.  results.
  24127.  
  24128.  For more information on mixed-language programming with strings, see Chapter
  24129.  12, "Mixed-Language Programming" and Chapter 13, "Mixed-Language Programming
  24130.  with Far Strings" in the  Programmer's  Guide.
  24131.  
  24132.  
  24133.  See Also
  24134.  
  24135.   StringAddress,  StringAssign,  StringLength
  24136.  
  24137.  
  24138.  Example
  24139.  
  24140.  See the  StringAssign routine programming example, which uses the
  24141.  StringRelease routine.
  24142.  
  24143.  
  24144.  SUB Statement
  24145.  ────────────────────────────────────────────────────────────────────────────
  24146.  
  24147.  
  24148.  Action
  24149.  
  24150.  Declares the name and the parameters of a  SUB procedure.
  24151.  
  24152.  
  24153.  Syntax
  24154.  
  24155.  
  24156.  
  24157.   SUB  globalname( parameterlist)  STATIC
  24158.  
  24159.  
  24160.   statementblock
  24161.  
  24162.  
  24163.   EXIT SUB
  24164.  
  24165.  
  24166.   statementblock
  24167.  
  24168.  
  24169.   END SUB
  24170.  
  24171.  Remarks
  24172.  
  24173.  
  24174.  The  SUB statement uses the following arguments:
  24175.  
  24176. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  24177.  Argument                                Description
  24178.  ────────────────────────────────────────────────────────────────────────────
  24179.   globalname                             A variable name up to 40
  24180.                                          characters long. This name cannot
  24181.                                          appear in any other  SUB or
  24182.                                          FUNCTION statement in the same
  24183.                                          program or the user library. The
  24184.                                          name cannot include a
  24185.                                          type-declaration character ( %,  &,
  24186.                                           !,  #,  @, or  $).
  24187.  
  24188.   parameterlist                          The list of variables,
  24189.                                          representing parameters, that will
  24190.                                          be passed to the SUB procedure
  24191.                                          when it is called. Multiple
  24192.                                          variables are separated by commas.
  24193.                                          Parameters are passed by reference,
  24194.  Argument                                Description
  24195.  ────────────────────────────────────────────────────────────────────────────
  24196.                                         Parameters are passed by reference,
  24197.                                          so any change to a parameter's
  24198.                                          value inside the  SUB procedure
  24199.                                          changes its value in the calling
  24200.                                          program.
  24201.  
  24202.   STATIC                                 Indicates that the  SUB
  24203.                                          procedure's local variables are to
  24204.                                          be saved between calls. Without
  24205.                                          STATIC, the local variables are
  24206.                                          allocated each time the  SUB
  24207.                                          procedure is invoked, and the
  24208.                                          variables' values are lost when
  24209.                                          the  SUB returns to the calling
  24210.                                          program. The  STATIC attribute
  24211.                                          does not affect variables that are
  24212.                                          used in a  SUB procedure but
  24213.                                          declared outside the procedure in
  24214.                                          DIM or  COMMON statements using
  24215.  Argument                                Description
  24216.  ────────────────────────────────────────────────────────────────────────────
  24217.                                         DIM or  COMMON statements using
  24218.                                          the  SHARED statement.
  24219.  
  24220.   EXIT                                   Causes an immediate exit from a
  24221.                                          SUB. Program execution continues
  24222.                                          with the statement after the  CALL
  24223.                                          statement.
  24224.  
  24225.  
  24226.  
  24227.  
  24228.  
  24229.  A  SUB  parameterlist argument has the following syntax:
  24230.  
  24231.   variable( )  AS  type  ,  variable( )  AS  type...
  24232. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  24233.  Argument                                Description
  24234.  ────────────────────────────────────────────────────────────────────────────
  24235.   variable                               A BASIC variable name. Previous
  24236.  Argument                                Description
  24237.  ────────────────────────────────────────────────────────────────────────────
  24238.   variable                               A BASIC variable name. Previous
  24239.                                          versions of BASIC required the
  24240.                                          number of dimensions in
  24241.                                          parentheses after an array name.
  24242.                                          In the current version of BASIC,
  24243.                                          the number of dimensions is not
  24244.                                          required.
  24245.  
  24246.   AS  type                               The type of the variable:  INTEGER,
  24247.                                           LONG,  SINGLE,  DOUBLE,  CURRENCY,
  24248.                                           STRING, or a user-defined type.
  24249.                                          You cannot use a fixed-length
  24250.                                          string, or an array of
  24251.                                          fixed-length strings, as a
  24252.                                          parameter. However, you can use a
  24253.                                          simple fixed-length string as an
  24254.                                          argument in a  CALL statement;
  24255.                                          BASIC converts a simple
  24256.                                          fixed-length string argument to a
  24257.  Argument                                Description
  24258.  ────────────────────────────────────────────────────────────────────────────
  24259.                                         fixed-length string argument to a
  24260.                                          variable-length string argument
  24261.                                          before passing the string to a
  24262.                                          SUB procedure.
  24263.  
  24264.  
  24265.  
  24266.  
  24267.  
  24268.  
  24269.  A  SUB procedure is a separate procedure, like a  FUNCTION procedure.
  24270.  However, unlike a  FUNCTION procedure, a  SUB procedure cannot be used in an
  24271.  expression.
  24272.  
  24273.   SUB and  END  SUB mark the beginning and end of a  SUB procedure. You also
  24274.  can use the optional  EXIT  SUB statement to exit a  SUB procedure.
  24275.  
  24276.   SUB procedures are called by a  CALL statement or by using the procedure
  24277.  name followed by the argument list. See the entry for the  CALL statement.
  24278.  BASIC  SUB procedures can be
  24279.  
  24280.  recursive -- they can call themselves to perform a given task. See the
  24281.  second example below.
  24282.  
  24283.  The  STATIC attribute indicates that all variables local to the  SUB
  24284.  procedure are static -- their values are saved between calls. Using the
  24285.  STATIC keyword increases execution speed slightly.  STATIC usually is not
  24286.  used with recursive  SUB procedures.
  24287.  
  24288.  Any  SUB procedure variables or arrays are considered local to that  SUB
  24289.  procedure, unless they are explicitly declared as shared variables in a
  24290.  SHARED statement. You cannot define  SUB procedures,  DEF FN functions, or
  24291.  FUNCTION procedures inside a  SUB procedure.
  24292.  
  24293.  
  24294.  Note
  24295.  
  24296.  You cannot use  GOSUB,  GOTO, or  RETURN to enter or exit a  SUB procedure.
  24297.  
  24298.  
  24299.  See Also
  24300.  
  24301.   CALL (BASIC),  DECLARE (BASIC),  SHARED,  STATIC Statement
  24302.  
  24303.  
  24304.  Examples
  24305.  
  24306.  See the  CALL (BASIC) statement programming example, which uses the  SUB
  24307.  statement.
  24308.  
  24309.  
  24310.  SWAP Statement
  24311.  ────────────────────────────────────────────────────────────────────────────
  24312.  
  24313.  
  24314.  Action
  24315.  
  24316.  Exchanges the values of two variables.
  24317.  
  24318.  
  24319.  Syntax
  24320.  
  24321.  
  24322.  
  24323.   SWAP  variable1,  variable2
  24324.  
  24325.  Remarks
  24326.  
  24327.  
  24328.  Any type of variable can be swapped (integer, long, single precision, double
  24329.  precision, string, currency, or record). However, if the two variables are
  24330.  not exactly the same data type, BASIC generates the error message Type
  24331.  mismatch.
  24332.  
  24333.  
  24334.  Example
  24335.  
  24336.  The following example sorts the elements of a string array in descending
  24337.  order using a shell sort. It uses  SWAP to exchange array elements that are
  24338.  out of order.
  24339.  
  24340.  ' Sort the word list using a shell sort.
  24341.  
  24342.  
  24343.  Num% = 4
  24344.  
  24345.  
  24346.  Array$(1) = "New York"
  24347.  
  24348.  
  24349.  Array$(2) = "Boston"
  24350.  
  24351.  
  24352.  Array$(3) = "Chicago"
  24353.  
  24354.  
  24355.  Array$(4) = "Seattle"
  24356.  
  24357.  
  24358.  Span% = Num% \ 2
  24359.  
  24360.  
  24361.  DO WHILE Span% > 0
  24362.  
  24363.  
  24364.  FOR I% = Span% TO Num% - 1
  24365.  
  24366.  
  24367.  J% = I% - Span% + 1
  24368.  
  24369.  
  24370.  FOR J% = (I% - Span% + 1) TO 1 STEP -Span%
  24371.  
  24372.  
  24373.  IF Array$(J%) <= Array$(J% + Span%) THEN EXIT FOR
  24374.  
  24375.  
  24376.  ' Swap array elements that are out of order.
  24377.  
  24378.  
  24379.  SWAP Array$(J%), Array$(J% + Span%)
  24380.  
  24381.  
  24382.  NEXT J%
  24383.  
  24384.  
  24385.  NEXT I%
  24386.  
  24387.  
  24388.  Span% = Span% \ 2
  24389.  
  24390.  
  24391.  LOOP
  24392.  
  24393.  
  24394.  CLS
  24395.  
  24396.  
  24397.  FOR I% = 1 TO Num%
  24398.  
  24399.  
  24400.      PRINT Array$(I%)
  24401.  
  24402.  
  24403.  NEXT I%
  24404.  
  24405.  
  24406.  END
  24407.  
  24408.  
  24409.  
  24410.  
  24411.  
  24412.  SYSTEM Statement
  24413.  ────────────────────────────────────────────────────────────────────────────
  24414.  
  24415.  
  24416.  Action
  24417.  
  24418.  Closes all open files and returns control to the operating system.
  24419.  
  24420.  
  24421.  Syntax
  24422.  
  24423.  
  24424.  
  24425.   SYSTEM  n%
  24426.  
  24427.  Remarks
  24428.  
  24429.  
  24430.  The  SYSTEM statement returns control to the operating system and returns
  24431.  the value  n% to the operating system. The value  n% can be used by DOS or
  24432.  OS/2 batch files or by non-BASIC programs. If  n% is omitted, the  SYSTEM
  24433.  statement returns a value of 0. Untrapped errors and fatal errors set the
  24434.  value of  n% to -1.
  24435.  
  24436.  In a stand-alone program,  SYSTEM returns to the operating system and closes
  24437.  all files; in the QBX environment,  SYSTEM stops program execution and
  24438.  closes all files.
  24439.  
  24440.  
  24441.  Note
  24442.  
  24443.  A program containing a  SYSTEM statement exits to the operating system if
  24444.  run from the QBX command line with the /RUN option. Entering a  SYSTEM
  24445.  statement in the Immediate window terminates BASIC.
  24446.  
  24447.  
  24448.  BASICA
  24449.  
  24450.   END and  SYSTEM are distinct in BASICA, but act identically in the current
  24451.  version of BASIC.
  24452.  
  24453.  
  24454.  See Also
  24455.  
  24456.   END,  STOP
  24457.  
  24458.  
  24459.  Example
  24460.  
  24461.  See the  ON ERROR statement programming example, which uses the  SYSTEM
  24462.  statement.
  24463.  
  24464.  
  24465.  
  24466.  
  24467.  
  24468.  
  24469.  
  24470.  
  24471.  
  24472.  
  24473.  
  24474.  
  24475.  
  24476.  
  24477.  
  24478.  
  24479.  
  24480.  
  24481.  
  24482.  
  24483.  TAB Function
  24484.  
  24485.  Action
  24486.  
  24487.  Moves the text cursor to a specified print position when used in the  PRINT,
  24488.   PRINT  USING,  LPRINT,  LPRINT  USING, and  PRINT  # statements.
  24489.  
  24490.  Syntax
  24491.  
  24492.  
  24493.  ────────────────────────────────────────────────────────────────────────────
  24494.   TAB( column%)
  24495.  
  24496.  
  24497.  Remarks
  24498.  
  24499.  The argument  column% is a numeric expression that is the column number of
  24500.  the new print position.
  24501.  
  24502.  The leftmost print position is always 1. The rightmost position is the
  24503.  current line width of the output device (which can be set with the  WIDTH
  24504.  statement).
  24505.  
  24506.  This is an example of using  TAB in the  PRINT function:
  24507.  
  24508.  PRINT  TAB(10); City$; TAB(40); State$; TAB(45); Zip$
  24509.  
  24510.  The behavior of  TAB depends on the relationship between three values:
  24511.  column%, the current print position on the current output line when the  TAB
  24512.  function is executed, and the current output-line width:
  24513.  
  24514.    ■   If the current print position on the current line is greater than
  24515.        column%,  TAB skips to  column% on the next output line.
  24516.  
  24517.    ■   If  column% is less than 1,  TAB moves the print position to column 1.
  24518.  
  24519.    ■   If  column% is greater than the output-line width,  TAB calculates:
  24520.  
  24521.    ■   print position =  column%  MOD width.  ■   n
  24522.  
  24523.        If the calculated print position is less than the current print
  24524.        position, the cursor jumps to the next line at the calculated print
  24525.        position. If the calculated print position is greater than the current
  24526.        print position, the cursor moves to the calculated print position on
  24527.        the same line.
  24528.  
  24529.  
  24530.  See Also
  24531.  
  24532.  
  24533.   LPRINT,  PRINT,  SPACE$,  SPC
  24534.  
  24535.  Example
  24536.  
  24537.  In the following example  TAB is also used with the  PRINT statement to
  24538.  center a text string on an 80-column screen.
  24539.  
  24540.  CLS
  24541.  INPUT "What is your full name "; Name$
  24542.  PRINT
  24543.  ' Get the length of Name$, divide by 2, and subtract from screen
  24544.  ' center point.
  24545.  PRINT TAB(40 - (LEN(Name$) \ 2)); Name$
  24546.  END
  24547.  
  24548.  TAN Function
  24549.  
  24550.  Action
  24551.  
  24552.  Returns the tangent of the angle  x, where  x is in radians.
  24553.  
  24554.  Syntax
  24555.  
  24556.  
  24557.   TAN( x)
  24558.  
  24559.  
  24560.  Remarks
  24561.  
  24562.  The tangent of an angle in a right triangle is the ratio between the length
  24563.  of the side opposite an angle and the length of the side adjacent to it.
  24564.  
  24565.   TAN is calculated in single precision if  x is an integer or
  24566.  single-precision value. If you use any other numeric data type,  TAN is
  24567.  calculated in double precision.
  24568.  
  24569.  To convert values from degrees to radians, multiply the angle (in degrees)
  24570.  times /180
  24571.  
  24572.  (or .0174532925199433). To convert a radian value to degrees, multiply it by
  24573.  180/
  24574.  
  24575.   (or 57.2957795130824). In both cases,   3.141593.
  24576.  
  24577.  BASICA
  24578.  
  24579.  In BASICA, if  TAN overflows, the interpreter generates an error message
  24580.  that reads Overflow, returns machine infinity as the result, and continues
  24581.  execution.
  24582.  
  24583.  If  TAN overflows, BASIC does not display machine infinity and execution
  24584.  halts (unless the program has an error-handling routine).
  24585.  
  24586.  See Also
  24587.  
  24588.   ATN,  COS,  SIN
  24589.  
  24590.  Example
  24591.  
  24592.  The following example computes the height of an object using the distance
  24593.  from the object and the angle of elevation. The program draws the triangle
  24594.  produced by the base and the computed height.
  24595.  
  24596.  SCREEN 2' CGA screen mode.
  24597.  
  24598.  INPUT "LENGTH OF BASE: ",Baselen
  24599.  INPUT "ANGLE OF ELEVATION (DEGREES,MINUTES): ",Deg,Min
  24600.  
  24601.  Ang = (3.141593/180) * (Deg + Min/60)' Convert to radians.
  24602.  Height = Baselen * TAN(Ang)' Calculate height.
  24603.  PRINT "HEIGHT =" Height
  24604.  Aspect = 4 * (200 / 640) / 3' Screen 2 is 640 x 200 pixels.
  24605.  H = 180 - Height
  24606.  B = 15 + (Baselen / Aspect)
  24607.  LINE (15,180)-(B,180)' Draw triangle.
  24608.  LINE -(B,H)
  24609.  LINE -(10,180)
  24610.  LOCATE 24,1 : PRINT "Press any key to continue...";
  24611.  DO
  24612.  LOOP WHILE INKEY$=""
  24613.  
  24614.  TEXTCOMP Function
  24615.  
  24616.  Action
  24617.  
  24618.  Compares two strings as they would be compared by ISAM.
  24619.  
  24620.  Syntax
  24621.  
  24622.  
  24623.   TEXTCOMP( a$,  b$)
  24624.  
  24625.  Remarks
  24626.  
  24627.  The arguments  a$ and  b$ are two strings.  TEXTCOMP compares their relative
  24628.  order as they would be sorted by an ISAM index and returns an integer value
  24629.  of 1, 0, or -1:
  24630.  
  24631.    ■   -1 is returned when  a$ compares less than  b$.
  24632.  
  24633.    ■   0 is returned when  a$ compares equal to  b$.
  24634.  
  24635.    ■   1 is returned when  a$ compares greater than  b$.
  24636.  
  24637.  
  24638.  Only the first 255 characters are considered in the comparison.
  24639.  
  24640.  
  24641.  The comparison is not case sensitive ("A" is the same as "a"), and any
  24642.  trailing spaces are removed.  TEXTCOMP uses the International Sorting Tables
  24643.  for sorting international characters. For more information, see Appendix E,
  24644.  "International Sorting Tables."
  24645.  
  24646.  See Also
  24647.  
  24648.   SetFormatCC; Appendix E, "International Character Sort Order Tables"
  24649.  
  24650.  Example
  24651.  
  24652.  The BookLook program uses  TEXTCOMP to compare titles in a table named
  24653.  BookStock and then prints each title that begins with the word QuickBASIC.
  24654.  Because the comparison performed by  TEXTCOMP is not case-sensitive, all
  24655.  variations of titles whose first word is QuickBASIC will be printed.
  24656.  
  24657.  
  24658.  TIME$ Function
  24659.  
  24660.  Action
  24661.  
  24662.  Returns the current time from the operating system.
  24663.  
  24664.  Syntax
  24665.  
  24666.   TIME$
  24667.  
  24668.  
  24669.  Remarks
  24670.  
  24671.  The  TIME$ function returns an eight-character string in the form  hh: mm:
  24672.  ss, where  hh is the hour (00 - 23),  mm is minutes (00 - 59), and  ss is
  24673.  seconds (00 - 59). A 24-hour clock is used; therefore, 8:00 P.M. is shown as
  24674.  20:00:00.
  24675.  
  24676.  To set the time, use the  TIME$ statement.
  24677.  
  24678.  See Also
  24679.  
  24680.   TIME$ Statement,  TIMER Function
  24681.  
  24682.  Example
  24683.  
  24684.  The following example converts the 24-hour clock used by  TIME$ to 12-hour
  24685.  output:
  24686.  
  24687.  T$ = TIME$
  24688.  Hr = VAL(T$)
  24689.  IF Hr < 12 THEN Ampm$ = " AM" ELSE Ampm$ = " PM"
  24690.  IF Hr > 12 THEN Hr = Hr - 12
  24691.  PRINT "The time is" STR$(Hr) RIGHT$(T$,6) Ampm$
  24692.  
  24693.  
  24694.  Output
  24695.  
  24696.  The time is 11:26:31 AM
  24697.  
  24698.  
  24699.  TIME$ Statement
  24700.  
  24701.  Action
  24702.  
  24703.  Sets the time.
  24704.  
  24705.  Syntax
  24706.  
  24707.  
  24708.   TIME$= stringexpression$
  24709.  
  24710.  Remarks
  24711.  
  24712.  The  TIME$ statement changes the system time, which stays changed until you
  24713.  change it again or reboot your computer.
  24714.  
  24715.  The argument  stringexpression$ must be in one of the following forms:
  24716.  
  24717. ╓┌──────────────┌────────────────────────────────────────────────────────────╖
  24718.  Form           Description
  24719.  Form           Description
  24720.  ────────────────────────────────────────────────────────────────────────────
  24721.   hh            Sets the hour; minutes and seconds default to 00.
  24722.   hh:mm         Sets the hour and minutes; seconds default to 00.
  24723.   hh:mm:ss      Sets the hour, minutes, and seconds.
  24724.  
  24725.  
  24726.  
  24727.  
  24728.  A 24-hour clock is used, so 8:00 P.M. would be entered as 20:00:00.
  24729.  
  24730.  This statement complements the  TIME$ function, which returns the current
  24731.  time.
  24732.  
  24733.  See Also
  24734.  
  24735.   TIME$ Function
  24736.  
  24737.  Example
  24738.  
  24739.  The following statement sets the current time to 8:00 A.M.:
  24740.  
  24741.  TIME$="08:00:00"
  24742.  
  24743.  TIMER Function
  24744.  
  24745.  Action
  24746.  
  24747.  Returns the number of seconds elapsed since midnight.
  24748.  
  24749.  Syntax
  24750.  
  24751.  
  24752.   TIMER
  24753.  
  24754.  
  24755.  Remarks
  24756.  
  24757.  The  TIMER function can be used with the  RANDOMIZE statement to generate a
  24758.  random number. It also can be used to time programs or parts of programs.
  24759.  
  24760.  See Also
  24761.  
  24762.  Randomize
  24763.  
  24764.  Example
  24765.  
  24766.  The following example searches for the prime numbers from 3 to 10,000 using
  24767.  a variation of the Sieve of Eratosthenes. The  TIMER function is used to
  24768.  time the program.
  24769.  
  24770.  DEFINT A-Z
  24771.  CONST UNMARK = 0, MARKIT = NOT UNMARK
  24772.  DIM Mark(10000)
  24773.  CLS               ' Clear screen.
  24774.  Start! = TIMER
  24775.  Num = 0
  24776.  FOR N = 3 TO 10000 STEP 2
  24777.     IF NOT Mark(N) THEN
  24778.        'PRINT N,   ' To print the primes, remove the
  24779.                    ' remark delimiter in front of the
  24780.                    ' PRINT statement.
  24781.        Delta = 2 * N
  24782.        FOR I = 3 * N TO 10000 STEP Delta
  24783.           Mark(I) = MARKIT
  24784.        NEXT
  24785.        Num = Num + 1
  24786.     END IF
  24787.  NEXT
  24788.  Finish! = TIMER
  24789.  PRINT
  24790.  PRINT "Program took"; Finish! - Start!;
  24791.  PRINT "seconds to find the"; Num; "primes "
  24792.  END
  24793.  
  24794.  
  24795.  Output
  24796.  
  24797.  Program took .28125 seconds to find the 1228 primes.
  24798.  
  24799.  TIMER Statements
  24800.  
  24801.  Action
  24802.  
  24803.  Enable, disable, or suspend timer-event trapping.
  24804.  
  24805.  Syntax
  24806.  
  24807.  
  24808.   TIMER ON
  24809.  
  24810.   TIMER OFF
  24811.  
  24812.   TIMER STOP
  24813.  
  24814.  
  24815.  Remarks
  24816.  
  24817.   TIMER  ON enables timer-event trapping. A timer event occurs when  n
  24818.  seconds have elapsed (as specified in the  ON  TIMER statement). If a timer
  24819.  event occurs after a  TIMER  ON statement, the routine specified in the  ON
  24820.  TIMER statement is executed.
  24821.  
  24822.   TIMER  OFF disables timer-event trapping. No timer-event trapping takes
  24823.  place until a  TIMER  ON statement is executed. Events occurring while
  24824.  trapping is off are ignored.
  24825.  
  24826.   TIMER  STOP suspends timer-event trapping. No trapping takes place until a
  24827.  TIMER  ON statement is executed. Events occurring while trapping is off are
  24828.  remembered and processed when the next  TIMER  ON statement is executed.
  24829.  However, remembered events are lost if  TIMER  OFF is executed.
  24830.  
  24831.  When a timer-event trap occurs (that is, the  GOSUB is performed), an
  24832.  automatic  TIMER  STOP is executed so that recursive traps cannot take
  24833.  place. The  RETURN operation from the trapping routine automatically
  24834.  performs a  TIMER  ON statement unless an explicit  TIMER  OFF was performed
  24835.  inside the routine.
  24836.  
  24837.  For more information, see Chapter 9, "Event Handling" in the  Programmer's
  24838.  Guide.
  24839.  
  24840.  See Also
  24841.  
  24842.   ON  event,  TIMER Function
  24843.  
  24844.  Example
  24845.  
  24846.  
  24847.  This example uses the  ON TIMER statement to trap timer events. It draws a
  24848.  polygon every three seconds with a random shape (three to seven sides),
  24849.  size, and location.
  24850.  
  24851.  SCREEN 1
  24852.  DEFINT A-Z
  24853.  DIM X(6), Y(6)
  24854.  TIMER ON' Enable timer-event trapping.
  24855.  ON TIMER(3) GOSUB Drawpoly' Draw a new polygon every three seconds.
  24856.  PRINT "Press any key to end program"
  24857.  INPUT "Press <RETURN> to start",Test$
  24858.  
  24859.  DO
  24860.  LOOP WHILE INKEY$ = ""' End program if any key pressed.
  24861.  
  24862.  END
  24863.  
  24864.  Drawpoly:
  24865.     CLS' Erase old polygon.
  24866.     N = INT(5 * RND + 2)' N is random number from 2 to 6.
  24867.     FOR I = 0 TO N
  24868.        X(I) = INT(RND * 319)' Get coordinates of vertices of
  24869.        Y(I) = INT(RND * 199)' polygon.
  24870.     NEXT
  24871.     PSET (X(N), Y(N))
  24872.     FOR I = 0 TO N
  24873.        LINE -(X(I), Y(I)),2' Draw new polygon.
  24874.     NEXT
  24875.     RETURN
  24876.  
  24877.  TRON/TROFF Statements
  24878.  
  24879.  Action
  24880.  
  24881.  Trace the execution of program statements.
  24882.  
  24883.  Syntax
  24884.  
  24885.  
  24886.   TRON
  24887.   TROFF
  24888.  
  24889.  
  24890.  Remarks
  24891.  
  24892.  In the QBX environment, executing a  TRON statement has the same effect as
  24893.  selecting
  24894.  
  24895.   Trace On from the Debug menu -- each statement is highlighted on the screen
  24896.  as it executes.
  24897.  
  24898.  The  TROFF statement turns off the program trace.
  24899.  
  24900.  The  TRON and  TROFF statements display line numbers only when compiled with
  24901.  the Debug option or the /D option on the BC command line.
  24902.  
  24903.  Note
  24904.  
  24905.  The debugging features of the QBX environment make these statements
  24906.  unnecessary.
  24907.  
  24908.  Example
  24909.  
  24910.  There is no programming example for the  TRON statement.
  24911.  
  24912.  
  24913.  TYPE Statement
  24914.  
  24915.  Action
  24916.  
  24917.  Defines a data type or ISAM table type that contains one or more elements or
  24918.  table columns.
  24919.  
  24920.  Syntax
  24921.  
  24922.  
  24923.   TYPE  usertype
  24924.  
  24925.   elementname  AS  typename
  24926.  
  24927.   elementname  AS  typename .
  24928.  
  24929.   .
  24930.   .
  24931.  
  24932.   END  TYPE
  24933.  
  24934.  
  24935.  Remarks
  24936.  
  24937.  The  TYPE statement uses the following arguments:
  24938.  
  24939. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  24940.  Argument                                Description
  24941.  ────────────────────────────────────────────────────────────────────────────
  24942.   usertype                               A user-defined data type or ISAM
  24943.                                          table type. The argument  usertype
  24944.                                          follows the same rules as a BASIC
  24945.                                          variable name. In the case of an
  24946.                                          ISAM table,  usertype identifies a
  24947.                                          user-defined table structure.
  24948.  
  24949.   elementname                            An element or table column of the
  24950.  Argument                                Description
  24951.  ────────────────────────────────────────────────────────────────────────────
  24952.  elementname                            An element or table column of the
  24953.                                          user-defined type. For a data type,
  24954.                                           elementname follows the same
  24955.                                          rules as a BASIC variable name.
  24956.                                          For a table type,  elementname
  24957.                                          follows the ISAM naming
  24958.                                          conventions.
  24959.  
  24960.   typename                               A user-defined data type, nested
  24961.                                          user-defined type (databases only),
  24962.                                          an array, or one of the following
  24963.                                          data types: integer, long, single
  24964.                                          (non-ISAM types only), double,
  24965.                                          fixed-length string, or currency .
  24966.  
  24967.  
  24968.  
  24969.  
  24970.  
  24971.  If  usertype is a table type, any  elementname arguments are the names of
  24972.  columns in the table. The names must be exact matches to existing column
  24973.  names and must follow the ISAM naming conventions.
  24974.  
  24975.  Note
  24976.  
  24977.  Line numbers and line labels aren't allowed in  TYPE... END  TYPE blocks.
  24978.  
  24979.  ISAM names use the following conventions:
  24980.  
  24981.    ■   They have no more than 30 characters.
  24982.  
  24983.    ■   They use only alphanumeric characters (A-Z, a-z, 0-9).
  24984.  
  24985.    ■   They begin with an alphabetic character.
  24986.  
  24987.    ■   They include no BASIC special characters.
  24988.  
  24989.  
  24990.  Note
  24991.  
  24992.  
  24993.  BASIC now supports user-defined types for ISAM tables, the currency data
  24994.  type for dollars-and-cents math and static arrays in user-defined types.
  24995.  Before you can use an ISAM table, you must declare a record type for the
  24996.  records that make up the table. Instances of this type are used to pass
  24997.  records to and from the table.
  24998.  
  24999.  The following  TYPE statement illustrates the use of static arrays. The
  25000.  record StateData includes the CityCode static array, and the record
  25001.  Washington has the same structure
  25002.  
  25003.   as StateData:
  25004.  
  25005.  TYPE StateData
  25006.  
  25007.  CityCode (1 TO 100) AS INTEGER ' Declare a static array.
  25008.  
  25009.  County AS STRING * 30
  25010.  
  25011.  END TYPE
  25012.  
  25013.  DIM Washington(1 TO 100) AS StateData
  25014.  When you declare a static array within a user-defined type, its dimensions
  25015.  must be declared with numeric constants rather than variables. For
  25016.  efficiency, make sure that arrays within a user-defined type start on even
  25017.  offsets. You can create very large records when you include static arrays
  25018.  within records. Putting one of these records within a  SUB procedure can use
  25019.  large amounts of stack space.
  25020.  
  25021.  Strings in user types must be fixed-length strings. String lengths are
  25022.  indicated by an asterisk and a numeric constant. For example, the following
  25023.  line defines an element named Keyword in a user-defined type as a string
  25024.  with length 40:
  25025.  
  25026.  TYPE Keyword AS STRING * 40 END TYPE
  25027.  A user-defined type must be declared in a type declaration before it can be
  25028.  used in the program. Although a user-defined type can be declared only in
  25029.  the module-level code, you can declare a variable to be of a user-defined
  25030.  type anywhere in the module, even in a  SUB or  FUNCTION procedure.
  25031.  
  25032.  Use the  DIM,  REDIM,  COMMON,  STATIC, or  SHARED statements to declare a
  25033.  variable to be of a user-defined type.
  25034.  
  25035.  The keyword  REM cannot be used as a field name in a  TYPE statement. The
  25036.  text that follows  REM is treated as a comment.
  25037.  
  25038.  Note
  25039.  
  25040.  If you have defined a table to have columns A, B, C, and D, you can use a
  25041.  user-defined type that has only the columns you need (any subset of A, B, C,
  25042.  and D).
  25043.  
  25044.  See Also
  25045.  
  25046.   OPEN
  25047.  
  25048.  Example
  25049.  
  25050.  See the  PUT statement (file I/O) programming example, which uses the  TYPE
  25051.  statement.
  25052.  
  25053.  
  25054.  UBOUND Function
  25055.  
  25056.  Action
  25057.  
  25058.  Returns the upper bound (largest available subscript) for the indicated
  25059.  dimension of an array.
  25060.  
  25061.  Syntax
  25062.  
  25063.  
  25064.   UBOUND( array ,  dimension%)
  25065.  
  25066.  
  25067.  Remarks
  25068.  
  25069.  The  UBOUND function is used with the  LBOUND function to determine the size
  25070.  of an array.  UBOUND takes the following arguments:
  25071.  
  25072. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  25073.  Argument                                Description
  25074.  ────────────────────────────────────────────────────────────────────────────
  25075.   array                                  The name of the array variable to
  25076.  Argument                                Description
  25077.  ────────────────────────────────────────────────────────────────────────────
  25078.   array                                  The name of the array variable to
  25079.                                          be tested.
  25080.  
  25081.   dimension%                             An integer ranging from 1 to the
  25082.                                          number of dimensions in  array;
  25083.                                          indicates which dimension's upper
  25084.                                          bound is returned. Use 1 for the
  25085.                                          first dimension, 2 for the second
  25086.                                          dimension, and so on. This
  25087.                                          argument is optional for
  25088.                                          one-dimensional arrays.
  25089.  
  25090.  
  25091.  
  25092.  
  25093.  
  25094.   UBOUND returns the values listed below for an array with the following
  25095.  dimensions:
  25096.  
  25097.  DIM A(1 TO 100, 1 TO 3, -3 TO 4)
  25098.  
  25099. ╓┌───────────────────────────┌───────────────────────────────────────────────╖
  25100.  Invocation                  Value returned
  25101.  ────────────────────────────────────────────────────────────────────────────
  25102.  UBOUND(A,1)                 100
  25103.  UBOUND(A,2)                 3
  25104.  UBOUND(A,3)                 4
  25105.  
  25106.  
  25107.  
  25108.  
  25109.  You can use the shortened syntax  UBOUND( array) for one-dimensional arrays
  25110.  because the default value for  dimension% is 1. Use the  LBOUND function to
  25111.  find the lower limit of an array dimension.
  25112.  
  25113.  See Also
  25114.  
  25115.   DIM,  LBOUND,  OPTION BASE
  25116.  
  25117.  Example
  25118.  
  25119.  
  25120.  The following example shows how  LBOUND and  UBOUND can be used together in
  25121.  a  SUB procedure to determine the size of an array passed to the procedure
  25122.  by a calling program.
  25123.  
  25124.  DECLARE SUB PRNTMAT (A!())
  25125.  DIM A(0 TO 3, 0 TO 3)
  25126.  FOR I% = 0 TO 3
  25127.  FOR J% = 0 TO 3
  25128.  A(I%, J%) = I% + J%
  25129.  NEXT J%
  25130.  NEXT I%
  25131.  CALL PRNTMAT(A())
  25132.  END
  25133.  
  25134.  SUB PRNTMAT (A()) STATIC
  25135.  FOR I% = LBOUND(A, 1) TO UBOUND(A, 1)
  25136.  FOR J% = LBOUND(A, 2) TO UBOUND(A, 2)
  25137.  PRINT A(I%, J%); " ";
  25138.  NEXT J%
  25139.  PRINT : PRINT
  25140.  NEXT I%
  25141.  END SUB
  25142.  
  25143.  UCASE$ Function
  25144.  
  25145.  Action
  25146.  
  25147.  Returns a string expression with all letters in uppercase.
  25148.  
  25149.  Syntax
  25150.  
  25151.  
  25152.   UCASE$ ( stringexpression$)
  25153.  
  25154.  
  25155.  Remarks
  25156.  
  25157.  The  UCASE$ function takes a string variable, string constant, or string
  25158.  expression as its single argument.  UCASE$ works with both variable- and
  25159.  fixed-length strings.
  25160.  
  25161.   UCASE$ and  LCASE$ are helpful in making string comparisons that are not
  25162.  case-sensitive.
  25163.  
  25164.  See Also
  25165.  
  25166.   LCASE$
  25167.  
  25168.  Example
  25169.  
  25170.  This example contains a  FUNCTION procedure, YesQues, that returns a Boolean
  25171.  value depending on how the user responds. The procedure uses  UCASE$ to make
  25172.  a non-
  25173.  
  25174.   case-sensitive test of the user's response.
  25175.  
  25176.  DEFINT A-Z
  25177.  FUNCTION YesQues(Prompt$,Row,Col) STATIC
  25178.  OldRow=CSRLIN
  25179.  OldCol=POS(0)
  25180.  ' Print prompt at Row, Col.
  25181.  LOCATE Row,Col : PRINT Prompt$ "(Y/N):";
  25182.  DO
  25183.  ' Get the user to press a key.
  25184.  DO
  25185.  Resp$=INKEY$
  25186.  LOOP WHILE Resp$=""
  25187.  Resp$=UCASE$(Resp$)
  25188.  ' Test to see if it's yes or no.
  25189.  IF Resp$="Y" OR Resp$="N" THEN
  25190.  EXIT DO
  25191.  ELSE
  25192.  BEEP
  25193.  END IF
  25194.  LOOP
  25195.  PRINT Resp$;' Print the response on the line.
  25196.  LOCATE OldRow,OldCol' Move the cursor back to the old position.
  25197.  YesQues=(Resp$="Y")' Return a Boolean value.
  25198.  END FUNCTION
  25199.  
  25200.  DO
  25201.  LOOP WHILE NOT YesQues("Do you know the frequency?",12,5)
  25202.  
  25203.  UEVENT Statements
  25204.  
  25205.  Action
  25206.  
  25207.  Enable, disable, or suspend a user-defined event.
  25208.  
  25209.  Syntax
  25210.  
  25211.  
  25212.   UEVENT ON
  25213.  
  25214.   UEVENT OFF
  25215.  
  25216.   UEVENT STOP
  25217.  
  25218.  
  25219.  Remarks
  25220.  
  25221.  The effects of the  UEVENT statements are like those of other event-trapping
  25222.  statements (such as  COM or  KEY). When  UEVENT  ON is executed, the
  25223.  event-trapping routine is enabled. Occurrences of the event trigger
  25224.  execution of the event-handling routine.
  25225.  
  25226.  When  UEVENT OFF is executed, the event-trapping routine is disabled. Any
  25227.  occurrences of the event are ignored.
  25228.  
  25229.  When  UEVENT STOP is executed, the event-trapping routine is suspended. An
  25230.  event occurrence is remembered, and the event-trapping routine performed as
  25231.  soon as a  UEVENT ON statement is executed.
  25232.  
  25233.  When a user-defined event trap occurs (that is, the  GOSUB is performed), an
  25234.  automatic  UEVENT STOP is executed so that recursive traps cannot take
  25235.  place. The  RETURN operation from the trapping subroutine automatically
  25236.  performs a  UEVENT ON statement unless an explicit  UEVENT OFF was performed
  25237.  inside the subroutine.
  25238.  
  25239.  See Also
  25240.  
  25241.   ON  event,  SetUEvent
  25242.  
  25243.  Example
  25244.  
  25245.  The following example shows a primitive use of the  ON UEVENT statement.
  25246.  
  25247.  PRINT "Entering an odd number causes a UEVENT to occur."
  25248.  ON UEVENT GOSUB Event1
  25249.  UEVENT ON
  25250.  DO
  25251.      PRINT "Enter a number --> ";
  25252.      N = VAL(INPUT$(1)): PRINT N: PRINT
  25253.      SELECT CASE N
  25254.          CASE 1, 3, 5, 7, 9
  25255.              CALL SetUevent    'Odd number was entered, causing UEVENT.
  25256.          CASE ELSE
  25257.              PRINT "No UEVENT occurred.": PRINT
  25258.      END SELECT
  25259.      LoopCount = LoopCount + 1
  25260.  LOOP UNTIL LoopCount = 10
  25261.  
  25262.  Event1:
  25263.      PRINT "Now processing the UEVENT. The odd number was"; N
  25264.      RETURN
  25265.  
  25266.  UNLOCK Statement
  25267.  
  25268.  Action
  25269.  
  25270.  Releases locks applied to parts of a file.
  25271.  
  25272.  Syntax
  25273.  
  25274.  
  25275.   UNLOCK #  filenumber% , { record& |  start&  TO  end&}
  25276.  
  25277.  
  25278.  Remarks
  25279.  
  25280.  The  UNLOCK statement is used only after a  LOCK statement. See the entry
  25281.  for the  LOCK statement for a complete discussion.
  25282.  
  25283.  The  UNLOCK statement uses the following arguments:
  25284.  
  25285. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  25286.  Argument                                Description
  25287.  ────────────────────────────────────────────────────────────────────────────
  25288.   filenumber%                            The number used in the  OPEN
  25289.                                          statement to open the file.
  25290.  
  25291.   record&                                The number of the record or byte
  25292.                                          to be locked. The argument
  25293.                                          record& can be any number between
  25294.                                          1 and 2,147,483,647 (equivalent to
  25295.                                          231 -1), inclusive. A record can
  25296.                                          be up to 32,767 bytes in length.
  25297.  
  25298.   start&                                 The number of the first record or
  25299.                                          byte to be locked.
  25300.  
  25301.   end&                                   The number of the last record or
  25302.                                          byte to be locked..
  25303.  
  25304.  
  25305.  
  25306.  
  25307.  
  25308.  For binary-mode files,  record&,  start&, and  end& represent the number of
  25309.  a byte relative to the beginning of the file. The first byte in a file is
  25310.  byte 1.
  25311.  
  25312.  For random-access files,  record&,  start&, and  end& represent the number
  25313.  of a record relative to the beginning of the file. The first record is
  25314.  record 1.
  25315.  
  25316.  Warning
  25317.  
  25318.  Be sure to remove all locks with an  UNLOCK statement before closing a file
  25319.  or terminating your program. Failing to remove locks produces unpredictable
  25320.  results.
  25321.  
  25322.  The arguments to  LOCK and  UNLOCK must match exactly.
  25323.  
  25324.  Do not use  LOCK and  UNLOCK on devices or ISAM tables.
  25325.  
  25326.  See Also
  25327.  
  25328.   LOCK... UNLOCK
  25329.  
  25330.  Example
  25331.  
  25332.  See the  LOCK... UNLOCK statement programming example, which uses the
  25333.  UNLOCK statement.
  25334.  
  25335.  
  25336.  UPDATE Statement
  25337.  
  25338.  Action
  25339.  
  25340.  Adds an updated record to an ISAM table, overwriting the current record.
  25341.  
  25342.  Syntax
  25343.  
  25344.  
  25345.   UPDATE #  filenumber%,  recordvariable
  25346.  
  25347.  
  25348.  Remarks
  25349.  
  25350.  The  UPDATE statement uses the following arguments:
  25351.  
  25352. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  25353.  Argument                                Description
  25354.  ────────────────────────────────────────────────────────────────────────────
  25355.   filenumber%                            The number used in the  OPEN
  25356.                                          statement to open the table.
  25357.  
  25358.   recordvariable                         A variable of the user-defined
  25359.                                          type  tabletype that was specified
  25360.                                          in the  OPEN statement. It is the
  25361.                                          record that will overwrite the
  25362.                                          current record.
  25363.  
  25364.  
  25365.  
  25366.  
  25367.  
  25368.   UPDATE replaces the current record with  recordvariable. It remains the
  25369.  current record.
  25370.  
  25371.  Use the  RETRIEVE statement to fetch the current record and place its data
  25372.  into  recordvariable. You can change the data in  recordvariable, then use
  25373.  the  UPDATE statement to update the current record with the changes you've
  25374.  made. Use  INSERT to add a record to a table without overwriting the current
  25375.  record.
  25376.  
  25377.  If the values passed to  recordvariable do not match the record strucure in
  25378.  the user-defined type, BASIC generates the error message Type Mismatch.The
  25379.  record structure includes the names and types of columns or fields.
  25380.  
  25381.  BASIC removes trailing spaces from strings used in an update.
  25382.  
  25383.  See Also
  25384.  
  25385.   INSERT;  RETRIEVE;  SEEKGT,  SEEKGE,  SEEKEQ
  25386.  
  25387.  Example
  25388.  
  25389.  See the programming example for the  SEEKGT,  SEEKGE, and  SEEKEQ
  25390.  statements, which uses the  UPDATE statement.
  25391.  
  25392.  
  25393.  VAL Function
  25394.  
  25395.  Action
  25396.  
  25397.  Returns the numeric value of a string of digits.
  25398.  
  25399.  Syntax
  25400.  
  25401.  
  25402.   VAL( stringexpression$)
  25403.  
  25404.  
  25405.  Remarks
  25406.  
  25407.  The argument  stringexpression$ is a sequence of characters that can be
  25408.  interpreted as a numeric value. The  VAL function stops reading the string
  25409.  at the first character that it cannot recognize as part of a number. The
  25410.  VAL function also strips blanks, tabs, and line feeds from the argument
  25411.  string. For example, the code below returns the value 1615198:
  25412.  
  25413.  VAL("    1615 198th Street")
  25414.  
  25415.  See Also
  25416.  
  25417.  
  25418.  
  25419.   STR$
  25420.  
  25421.  
  25422.  Example
  25423.  
  25424.  
  25425.  The following example prints the names and addresses of people with specific
  25426.  telephone area codes:
  25427.  
  25428.  ' This part of the program builds a sample data file.
  25429.  
  25430.  OPEN "PHONE.DAT" FOR OUTPUT AS #1
  25431.  
  25432.  CLS
  25433.  
  25434.  RESTORE
  25435.  
  25436.  READ FuName$, ACPhone$
  25437.  
  25438.  I = 0
  25439.  
  25440.  DO WHILE UCASE$(FuName$) <> "END"
  25441.  
  25442.     I = I + 1
  25443.  
  25444.     WRITE #1, FuName$, ACPhone$
  25445.  
  25446.     READ FuName$, ACPhone$
  25447.  
  25448.     IF FuName$ = "END" THEN EXIT DO
  25449.  
  25450.  LOOP
  25451.  
  25452.  CLOSE #1
  25453.  
  25454.  DATA "Bob Hartzell ","206-378-3223"
  25455.  
  25456.  DATA "Alice Provan ","213-884-9700"
  25457.  
  25458.  DATA "Alex Landow ","213-456-3111"
  25459.  
  25460.  DATA "Walt Riley ","503-248-0048"
  25461.  
  25462.  DATA "Georgette Gump ","213-222-2222"
  25463.  
  25464.  DATA "END",0,0,0,0,0
  25465.  
  25466.  ' This part of the program demonstrates the VAL function.
  25467.  
  25468.  INPUT "Search for which area (206, 213, or 503): ", Targetarea
  25469.  
  25470.  OPEN "PHONE.DAT" FOR INPUT AS #1
  25471.  
  25472.  DO WHILE NOT EOF(1)
  25473.  
  25474.     INPUT #1, Nm$, Phonenum$
  25475.  
  25476.     'VAL reads everything up to the first non-numeric
  25477.  
  25478.     'character ("-" in this case).
  25479.  
  25480.     Area = VAL(Phonenum$)
  25481.  
  25482.     IF Area = Targetarea THEN
  25483.  
  25484.        PRINT
  25485.  
  25486.        PRINT Nm$;
  25487.  
  25488.        PRINT Phonenum$
  25489.  
  25490.     END IF
  25491.  
  25492.  LOOP
  25493.  
  25494.  CLOSE
  25495.  
  25496.  KILL "PHONE.DAT"
  25497.  
  25498.  END
  25499.  
  25500.  VARPTR$ Function
  25501.  
  25502.  Action
  25503.  
  25504.  Returns a string representation of a variable's address for use in  DRAW and
  25505.   PLAY statements.
  25506.  
  25507.  Syntax
  25508.  
  25509.  
  25510.   VARPTR$( variablename)
  25511.  
  25512.  
  25513.  Remarks
  25514.  
  25515.  The argument  variablename is the name of a variable in the program. If
  25516.  variablename is an array element, dimensions for the array must be specified
  25517.  before  VARPTR$ is used. The array must consist of variable-length strings.
  25518.  
  25519.  Note
  25520.  
  25521.  To guarantee correct results, use the value returned by  VARPTR$ immediately
  25522.  after invoking the function.
  25523.  
  25524.  BASICA
  25525.  
  25526.  In this version of BASIC,  VARPTR$ must be used in the  DRAW and  PLAY
  25527.  statements to execute substrings containing variables. BASICA supports both
  25528.  the  VARPTR$ syntax and the syntax containing just the variable name.
  25529.  
  25530.  See Also
  25531.  
  25532.   DRAW;  PLAY Statement (Music);  VARPTR,  VARSEG
  25533.  
  25534.  Example
  25535.  
  25536.  See the  PLAY function programming example, which uses the  VARPTR$
  25537.  function.
  25538.  
  25539.  
  25540.  VARPTR, VARSEG Functions
  25541.  
  25542.  Action
  25543.  
  25544.  Return the address of a variable or string descriptor.
  25545.  
  25546.  Syntax
  25547.  
  25548.  
  25549.   VARPTR( variablename)
  25550.  
  25551.   VARSEG( variablename)
  25552.  
  25553.  
  25554.  Remarks
  25555.  
  25556.  The argument  variablename can be any BASIC variable, including a record
  25557.  variable or record element.
  25558.  
  25559.   VARPTR and  VARSEG return the address of a variable (for numeric variables)
  25560.  or the address of a string descriptor (for string variables) as indicated in
  25561.  the following table:
  25562.  
  25563. ╓┌────────────────────────┌────────────────────────┌─────────────────────────╖
  25564.  For a variable of type:  VARSEG returns:          VARPTR returns:
  25565.  ────────────────────────────────────────────────────────────────────────────
  25566.  Numeric                  Segment address of       Offset address of
  25567.                           variable                 variable
  25568.  
  25569.  String                   Segment address of       Offset address of string
  25570.                           string  descriptor       descriptor (near strings)
  25571.                           (near strings)
  25572.  
  25573.  Name not previously      Segment address of new   Offset address of new
  25574.  defined                  variable ( VARSEG also   variable ( VARPTR also
  25575.                           creates the new          creates the  new
  25576.                           variable)                variable)
  25577.  
  25578.  
  25579.  
  25580.  
  25581.  
  25582.  When  variablename is a numeric variable, the  VARPTR function returns an
  25583.  unsigned integer (the offset of the variable within its segment). When
  25584.  variablename is a numeric variable, the  VARSEG function returns an unsigned
  25585.  integer (the segment address of the variable). When  variablename is a
  25586.  near-string variable,  VARSEG and  VARPTR return a string-descriptor address
  25587.  that contains the length of the string and the address at which it is
  25588.  stored.
  25589.  
  25590.  If  variablename is not defined before  VARPTR or  VARSEG is called, the
  25591.  variable is created and its address is returned.
  25592.  
  25593.   VARPTR and  VARSEG are often used with  Absolute,  BLOAD,  BSAVE,
  25594.  Interrupt,  PEEK,  POKE, or when passing arrays to procedures written in
  25595.  other languages. When using  VARPTR or  VARSEG to get the address of an
  25596.  array, use the first element of the array as the argument:
  25597.  
  25598.  DIM A(150)
  25599.  
  25600.  .
  25601.  
  25602.  .
  25603.  
  25604.  .
  25605.  
  25606.  ArrAddress=VARPTR(A(1))
  25607.  
  25608.  You can use  VARPTR alone to get the address of a variable stored in DGROUP.
  25609.  You must use both  VARPTR and  VARSEG to get the complete address of a
  25610.  variable stored in far memory.
  25611.  
  25612.  
  25613.  
  25614.  When programming with OS/2 protected mode, the  VARSEG function returns the
  25615.  selector of the specified variable or array.
  25616.  
  25617.  
  25618.  
  25619.  Note
  25620.  
  25621.  
  25622.  Because many BASIC statements move variables in memory, use the values
  25623.  returned by  VARPTR and  VARSEG immediately after the functions are used.
  25624.  
  25625.  
  25626.  It is not meaningful to use  VARSEG and  VARPTR for far strings, since the
  25627.  format of the far strings' string descriptor is different from the string
  25628.  descriptor for near strings. See the entry for  StringAddress for
  25629.  information on locating the address of a far string's string descriptor. See
  25630.  the entries for  SSEG,  SADD, and  SSEGADD for information on locating the
  25631.  segment and offset addresses of far strings.
  25632.  
  25633.  
  25634.  You can no longer use  VARPTR to get the address of a file's buffer. Use the
  25635.   FILEATTR function to get information about a file.
  25636.  
  25637.  
  25638.  Programs written in earlier versions of BASIC that used  VARPTR to access
  25639.  numeric arrays may no longer work. You must now use a combination of  VARPTR
  25640.  and  VARSEG. For example, the following QuickBASIC Version 3.0 fragment no
  25641.  longer works correctly:
  25642.  
  25643.  DIM Cube(675)
  25644.  
  25645.  .
  25646.  
  25647.  .
  25648.  
  25649.  .
  25650.  
  25651.  BSAVE "graph.dat",VARPTR(Cube(1)),2700
  25652.  
  25653.  The fragment could be rewritten as follows to work with the current version
  25654.  of BASIC:
  25655.  
  25656.  
  25657.  DIM Cube(675)
  25658.  
  25659.  .
  25660.  
  25661.  .
  25662.  
  25663.  .
  25664.  
  25665.  ' Change segment to segment containing Cube.
  25666.  
  25667.  DEF SEG=VARSEG(Cube(1))
  25668.  
  25669.  BSAVE "graph.dat",VARPTR(Cube(1)),2700
  25670.  
  25671.  DEF SEG' Restore BASIC segment.
  25672.  
  25673.  The  VARSEG function, combined with  VARPTR, replaces the PTR86 subprogram
  25674.  used in previous versions of BASIC.
  25675.  
  25676.  
  25677.  VARPTR and VARSEG and Expanded Memory Arrays
  25678.  
  25679.  Do not pass expanded memory arrays to non-BASIC procedures. If you start QBX
  25680.  with the /Ea switch, any of these arrays may be stored in expanded memory:
  25681.  
  25682.    ■   Numeric arrays less than 16K in size.
  25683.  
  25684.    ■   Fixed-length string arrays less than 16K in size.
  25685.  
  25686.    ■   User-defined-type arrays less than 16K in size.
  25687.  
  25688.  
  25689.  
  25690.  
  25691.  If you want to pass expanded memory arrays to non-BASIC procedures, first
  25692.  start QBX without the /Ea switch. (Without the /Ea switch, no arrays are
  25693.  stored in expanded memory.)
  25694.  
  25695.  
  25696.  For more information on using expanded memory, see "Memory Management for
  25697.  QBX" in  Getting Started.
  25698.  
  25699.  See Also
  25700.  
  25701.   DEF SEG,  PEEK,  POKE,  SADD,  VARPTR$
  25702.  
  25703.  Example
  25704.  
  25705.  The following example illustrates how to use the  VARPTR and  VARSEG
  25706.  functions in a  CALL statement to pass a BASIC array to a C routine.
  25707.  
  25708.  DEFINT A-Z
  25709.  DECLARE SUB AddArr CDECL (BYVAL Offs, BYVAL Segm, BYVAL Num)
  25710.  DIM A(1 TO 100) AS INTEGER
  25711.  ' Fill the array with the numbers 1 to 15.
  25712.  FOR I = 1 TO 15
  25713.     A(I) = I
  25714.  NEXT I
  25715.  '
  25716.  ' Call the C function. AddArr expects a far address (segment
  25717.  ' and offset). Because CDECL puts things on the stack from
  25718.  ' right to left, put the offset ( VARPTR(A(1)) ) first in the
  25719.  ' list, followed by the segment ( VARSEG(A(1)) ).
  25720.  '
  25721.  CALL AddArr(VARPTR(A(1)), VARSEG(A(1)), 15)
  25722.  '
  25723.  ' Print the modified array.
  25724.  FOR I = 1 TO 15
  25725.     PRINT A(I)
  25726.  NEXT I
  25727.  END
  25728.  
  25729.  This C routine increments values of a BASIC array. It must be compiled and
  25730.  the .OBJ file linked to the BASIC code above.
  25731.  
  25732.  /* Add one to the first num elements of array arr.*/
  25733.  void far addarr(arr,num)
  25734.  int far *arr;
  25735.  int num;
  25736.  {
  25737.     int i;
  25738.     for(i=0;i<num;i++) arr[i]++;
  25739.  }
  25740.  
  25741.  VIEW Statement
  25742.  
  25743.  Action
  25744.  
  25745.  Defines screen limits for graphics output.
  25746.  
  25747.  Syntax
  25748.  
  25749.  
  25750.   VIEW  SCREEN ( x1!,  y1!)-( x2!,  y2!) ,  color& ,  border&
  25751.  
  25752.  
  25753.  Remarks
  25754.  
  25755.  The list below describes the parts of the  VIEW statement:
  25756.  
  25757. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  25758.  Part                                    Description
  25759.  ────────────────────────────────────────────────────────────────────────────
  25760.   SCREEN                                 Specifies that coordinates of
  25761.                                          subsequent graphics statements are
  25762.                                          absolute to the screen, not
  25763.                                          relative to the viewport. Only
  25764.                                          graphics within the viewport are
  25765.                                          plotted. When  SCREEN is omitted,
  25766.                                          all points are plotted relative to
  25767.                                          the viewport ( x1! and  y1! are
  25768.                                          added to the coordinates before
  25769.  Part                                    Description
  25770.  ────────────────────────────────────────────────────────────────────────────
  25771.                                         added to the coordinates before
  25772.                                          plotting the point).
  25773.  
  25774.  ( x1!,  y1!)-( x2!,  y2!)               Indicates a rectangular area on
  25775.                                          the screen. The arguments  x1!,
  25776.                                          y1!,  x2!, and  y2! are numeric
  25777.                                          expressions that are the
  25778.                                          coordinates of diagonally opposite
  25779.                                          corners of the viewport. The
  25780.                                          argument  ( x1!,  y1!)-( x2!,  y2!)
  25781.                                          must be within the physical bounds
  25782.                                          of the screen in the current
  25783.                                          screen mode.
  25784.  
  25785.   color&                                 A numeric expression that
  25786.                                          specifies the color with which to
  25787.                                          fill the viewport. If you omit
  25788.                                          color&, the viewport area is not
  25789.                                          filled (it has the same color as
  25790.  Part                                    Description
  25791.  ────────────────────────────────────────────────────────────────────────────
  25792.                                         filled (it has the same color as
  25793.                                          the screen background color).
  25794.  
  25795.   border&                                Any numeric expression for
  25796.                                          border& causes a line to be drawn
  25797.                                          around the viewport. The value of
  25798.                                          border determines the color of the
  25799.                                          line. If you omit  border&, no
  25800.                                          line is drawn around the viewport.
  25801.  
  25802.  
  25803.  
  25804.  
  25805.  The  VIEW statement defines a viewport or "clipping region," which is a
  25806.  rectangular section of the screen to which graphics output is limited. If
  25807.  VIEW is used with no arguments, the entire screen is defined as the
  25808.  viewport.  RUN and  SCREEN also define the entire screen as the viewport.
  25809.  
  25810.  See Also
  25811.  
  25812.   PRINT,  SCREEN Statement,  WINDOW
  25813.  
  25814.  Examples
  25815.  
  25816.  See the  WINDOW statement programming example, which uses the  VIEW
  25817.  statement.
  25818.  
  25819.  
  25820.  VIEW PRINT Statement
  25821.  
  25822.  Action
  25823.  
  25824.  Sets the boundaries of the screen text viewport.
  25825.  
  25826.  Syntax
  25827.  
  25828.  
  25829.   VIEW PRINT  topline%  TO  bottomline%
  25830.  
  25831.  
  25832.  Remarks
  25833.  
  25834.  The argument  topline% is the number of the upper line in the text viewport;
  25835.   bottomline% is the number of the lower line.
  25836.  
  25837.  Without  topline% and  bottomline% parameters, the  VIEW PRINT statement
  25838.  initializes the whole screen area as the text viewport. The number of lines
  25839.  in the screen depends on the screen mode and whether or not the /H option
  25840.  was used when BASIC was started. For more information, see the entry for the
  25841.   WIDTH statement, and Chapter 3, "File and Device I/O" in the  Programmer's
  25842.  Guide.
  25843.  
  25844.  Statements and functions that operate within the defined text viewport
  25845.  include  CLS,  INPUT,  LOCATE,  PRINT, the  SCREEN function, and  WRITE.
  25846.  
  25847.  See Also
  25848.  
  25849.   CLS,  LOCATE,  PRINT,  SCREEN Function,  SCREEN Statement,  WIDTH
  25850.  
  25851.  Example
  25852.  
  25853.  The following example draws random circles in a graphics viewport and prints
  25854.  in a text viewport. The graphics viewport is cleared after 30 circles have
  25855.  been drawn. The program clears the text viewport after printing to it 45
  25856.  times.
  25857.  
  25858.  RANDOMIZE TIMER
  25859.  
  25860.  SCREEN 1
  25861.  
  25862.  ' Set up a graphics viewport with a border.
  25863.  
  25864.  VIEW (5, 5)-(100, 80), 3, 1
  25865.  
  25866.  ' Set up a text viewport.
  25867.  
  25868.  VIEW PRINT 12 TO 24
  25869.  
  25870.  ' Print a message on the screen outside the text viewport.
  25871.  
  25872.  LOCATE 25, 1: PRINT "Press any key to stop."
  25873.  
  25874.  Count = 0
  25875.  
  25876.  DO
  25877.  
  25878.     ' Draw a circle with a random radius.
  25879.  
  25880.     CIRCLE (50, 40), INT((35 - 4) * RND + 5), (Count MOD 4)
  25881.  
  25882.     ' Clear the graphics viewport every 30 times.
  25883.  
  25884.     IF (Count MOD 30) = 0 THEN CLS 1
  25885.  
  25886.     PRINT "Hello. ";
  25887.  
  25888.     ' Clear the text viewport every 45 times.
  25889.  
  25890.     IF (Count MOD 45) = 0 THEN CLS 2
  25891.  
  25892.     Count = Count + 1
  25893.  
  25894.  LOOP UNTIL INKEY$ <> ""
  25895.  
  25896.  WAIT Statement
  25897.  
  25898.  Action
  25899.  
  25900.  Suspends program execution while monitoring the status of a machine input
  25901.  port.
  25902.  
  25903.  Syntax
  25904.  
  25905.  
  25906.   WAIT  portnumber,  and-expression% ,  xor-expression%
  25907.  
  25908.  
  25909.  Remarks
  25910.  
  25911.  The  WAIT statement uses the following arguments:
  25912.  
  25913. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  25914.  Argument                                Description
  25915.  ────────────────────────────────────────────────────────────────────────────
  25916.  Argument                                Description
  25917.  ────────────────────────────────────────────────────────────────────────────
  25918.   portnumber                             An unsigned integer expression
  25919.                                          between 0 and 65,535, inclusive,
  25920.                                          that is the number of the machine
  25921.                                          input port.
  25922.  
  25923.   and-expression%                        An integer expression that is
  25924.                                          repeatedly combined with the bit
  25925.                                          pattern received at the port,
  25926.                                          using an  AND operator; when the
  25927.                                          result is nonzero, the  WAIT
  25928.                                          statement stops monitoring the
  25929.                                          port, and program execution
  25930.                                          resumes with the next program
  25931.                                          statement.
  25932.  
  25933.   xor-expression%                        Can be used to turn bits on and
  25934.                                          off in the received bit pattern
  25935.                                          before the  AND operation is
  25936.                                          applied.
  25937.  Argument                                Description
  25938.  ────────────────────────────────────────────────────────────────────────────
  25939.                                         applied.
  25940.  
  25941.  
  25942.  
  25943.  
  25944.  
  25945.  The  WAIT statement is an enhanced version of the  INP function; it suspends
  25946.  execution until a specified bit pattern is input from an input port, using
  25947.  the following four steps:
  25948.  
  25949.    ■   1.  The data byte read from the port is combined, using an  XOR
  25950.        operation, with
  25951.  
  25952.          xor-expression%. If  xor-expression% is omitted, it is assumed to be
  25953.         0.
  25954.  
  25955.    ■   2. The result is combined with  and-expression% using an  AND
  25956.        operation.
  25957.  
  25958.    ■   3. If the result is zero, the first two steps are repeated.
  25959.  
  25960.    ■   4. If the result is nonzero, execution continues with the next program
  25961.        statement.
  25962.  
  25963.        It is possible to enter an infinite loop with the  WAIT statement if
  25964.        the input port fails to develop a non-zero bit pattern. In this case,
  25965.        you must manually restart the machine.
  25966.  
  25967.    ■   The following example program line illustrates the syntax of the  WAIT
  25968.        statement:
  25969.  WAIT HandShakePort, 2
  25970.  This statement will cause BASIC to do an  AND operation on the bit pattern
  25971.  received at the DOS I/O port HandShakePort with the bit pattern represented
  25972.  by 2 (00000010).
  25973.  
  25974.  
  25975.  
  25976.  
  25977.  Note
  25978.  
  25979.  The  WAIT statement is not available in OS/2 protected mode.
  25980.  
  25981.  See Also
  25982.  
  25983.   INP,  OUT
  25984.  
  25985.  Example
  25986.  
  25987.  
  25988.  The following example demonstrates the use of the  WAIT statement.
  25989.  
  25990.  ' Open and close the port at the proper baud rate.
  25991.  
  25992.  OPEN "COM1:9600,N,8,1,BIN" FOR RANDOM AS #1
  25993.  
  25994.  CLOSE #1
  25995.  
  25996.   PortNum% = &H3F8 'COM1
  25997.  
  25998.   NonPrintCharMask% = 96
  25999.  
  26000.  ' Wait until there's some activity on COM1.
  26001.  
  26002.  ' Mask out characters less than 32 for the first input character.
  26003.  
  26004.   LOCATE 12, 15: PRINT "Waiting for a printable input character. "
  26005.  
  26006.   WAIT PortNum%, NonPrintCharMask%
  26007.  
  26008.  ' Once a printable character comes in, execution continues.
  26009.  
  26010.  DO
  26011.  
  26012.      'Get a character from the port and evaluate.
  26013.  
  26014.      A% = INP(PortNum%)
  26015.  
  26016.      SELECT CASE A%
  26017.  
  26018.          CASE 7
  26019.  
  26020.              Character$ = "   BELL    "
  26021.  
  26022.          CASE 8
  26023.  
  26024.              Character$ = "BACK SPACE "
  26025.  
  26026.          CASE 9
  26027.  
  26028.              Character$ = "    TAB    "
  26029.  
  26030.          CASE 13
  26031.  
  26032.              Character$ = "    CR     "
  26033.  
  26034.          CASE 32
  26035.  
  26036.              Character$ = "   SPACE   "
  26037.  
  26038.          CASE 127
  26039.  
  26040.              Character$ = "    DEL    "
  26041.  
  26042.          CASE IS < 31, IS > 127
  26043.  
  26044.              Character$ = "unprintable"
  26045.  
  26046.          CASE ELSE
  26047.  
  26048.              Character$ = SPACE$(5) + CHR$(A%) + SPACE$(5)
  26049.  
  26050.      END SELECT
  26051.  
  26052.      LOCATE 12, 15
  26053.  
  26054.      ' Report the input character.
  26055.  
  26056.      PRINT "Numeric Value                    ASCII Character"
  26057.  
  26058.      LOCATE 14, 20
  26059.  
  26060.      PRINT A%; TAB(50); Character$
  26061.  
  26062.      IF A% > 127 THEN STOP
  26063.  
  26064.      LOCATE 23, 25
  26065.  
  26066.      PRINT "Press ANY key to quit."
  26067.  
  26068.  LOOP WHILE INKEY$ = ""
  26069.  
  26070.  END
  26071.  
  26072.  WHILE...WEND Statement
  26073.  
  26074.  Action
  26075.  
  26076.  Executes a series of statements in a loop, as long as a given condition is
  26077.  true.
  26078.  
  26079.  Syntax
  26080.  
  26081.  
  26082.   WHILE  condition
  26083.   .
  26084.  
  26085.   .
  26086.  
  26087.   .
  26088.  
  26089.  
  26090.   WEND
  26091.  
  26092.  
  26093.  Remarks
  26094.  
  26095.  The argument  condition is  a numeric expression that BASIC evaluates as
  26096.  true (nonzero) or
  26097.  
  26098.   false (zero).
  26099.  
  26100.  If  condition is true (that is, if it does not equal zero), then any
  26101.  intervening statements are executed until the  WEND statement is
  26102.  encountered. BASIC then returns to the  WHILE statement and checks
  26103.  condition. If it is still true, the process is repeated. If it is not true
  26104.  (or if it equals zero), execution resumes with the statement following the
  26105.  WEND statement.
  26106.  
  26107.  Note
  26108.  
  26109.  BASIC's  DO... LOOP statement provides a more powerful and flexible
  26110.  loop-control structure.
  26111.  
  26112.   WHILE... WEND loops can be nested to any level. Each  WEND matches the most
  26113.  recent  WHILE. When BASIC encounters an unmatched  WHILE statement, it
  26114.  generates the error message WHILE without WEND. If BASIC encounters an
  26115.  unmatched  WEND statement, it generates the error message WEND without
  26116.  WHILE.
  26117.  
  26118.  Note
  26119.  
  26120.  Do not branch into the body of a  WHILE... WEND loop without executing the
  26121.  WHILE statement. This may cause run-time errors or program problems that are
  26122.  difficult to locate.
  26123.  
  26124.  See Also
  26125.  
  26126.   DO... LOOP
  26127.  
  26128.  Example
  26129.  
  26130.  
  26131.  The following example performs a bubble sort on the array A$. Assigning the
  26132.  variable Exchange a non-zero value (true) forces one pass through the
  26133.  WHILE... WEND loop (this construction is unnecessary with  DO... LOOP). When
  26134.  there are no more swaps, all elements of A$ are sorted, Exchange is false
  26135.  (equal to zero), and the program continues execution with the line following
  26136.  the  WEND statement.
  26137.  
  26138.  ' Bubble sort of array A$.
  26139.  
  26140.  CONST FALSE = 0, TRUE = -1
  26141.  
  26142.  DIM I AS INTEGER
  26143.  
  26144.  DIM A$(4)
  26145.  
  26146.  A$(1) = "New York"
  26147.  
  26148.  A$(2) = "Boston"
  26149.  
  26150.  A$(3) = "Chicago"
  26151.  
  26152.  A$(4) = "Seattle"
  26153.  
  26154.  Max = UBOUND(A$)
  26155.  
  26156.  Exchange = TRUE         ' Force first pass through the array.
  26157.  
  26158.  WHILE Exchange          ' Sort until no elements are exchanged.
  26159.  
  26160.     Exchange = FALSE
  26161.  
  26162.     ' Compare the array elements by pairs. When two are exchanged,
  26163.  
  26164.     ' force another pass by setting Exchange to TRUE.
  26165.  
  26166.     FOR I = 2 TO Max
  26167.  
  26168.        IF A$(I - 1) > A$(I) THEN
  26169.  
  26170.           Exchange = TRUE
  26171.  
  26172.           SWAP A$(I - 1), A$(I)
  26173.  
  26174.        END IF
  26175.  
  26176.     NEXT
  26177.  
  26178.  WEND
  26179.  
  26180.  CLS
  26181.  
  26182.  FOR I = 1 TO 4
  26183.  
  26184.     PRINT A$(I)
  26185.  
  26186.  NEXT I
  26187.  
  26188.  END
  26189.  
  26190.  WIDTH Statements
  26191.  
  26192.  Action
  26193.  
  26194.  Assign an output-line width to a device (such as a printer) or to a file, or
  26195.  change the number of columns and lines displayed on the screen.
  26196.  
  26197.  Syntax
  26198.  
  26199.  
  26200.   WIDTH  screenwidth% ,  screenheight%
  26201.  
  26202.   WIDTH { #filenumber% |  device$},  width%
  26203.  
  26204.   WIDTH LPRINT  width%
  26205.  
  26206.  
  26207.  Remarks
  26208.  
  26209.  The different forms of the  WIDTH statements are explained in the following
  26210.  list:
  26211.  
  26212.   WIDTH  screenwidth% ,  screenheight%
  26213.  
  26214.  Sets number of columns and lines to display on the screen. The value of
  26215.  screenwidth% must be either 40 or 80; default is 80. The table below has
  26216.  details about the value of  screenheight%.
  26217.  
  26218.   WIDTH  # filenumber%,  width%
  26219.  
  26220.  Sets to  width% the output-line width of an output device already opened as
  26221.  a file (for example, LPT1 or CONS). The argument  filenumber% is the number
  26222.  used to open the file with the  OPEN statement. The number sign (#) in front
  26223.  of  filenumber% is not optional.This form permits altering the width while a
  26224.  file is open, because the statement  takes effect immediately.
  26225.  
  26226.   WIDTH  device$, width%
  26227.  
  26228.  Sets to  width% the line width of  device (a device filename). The  device
  26229.  should be a string expression (for example, "LPT1:"). Note that he  width%
  26230.  assignment is deferred until the next  OPEN statement affecting the device.
  26231.  The assignment does not affect output for an already open file.
  26232.  
  26233.   WIDTH  LPRINT  width%
  26234.  
  26235.  Sets to  width% the line width of the line printer, for use by subsequent
  26236.  LPRINT statements. Equivalent to the statement form:WIDTH "LPT1:",
  26237.  width%Not all of the argument values are valid in every case; it depends on
  26238.  the installed display adapter and the screen mode established by the most
  26239.  recently executed  SCREEN statement. The value of  screenheight% may be 25,
  26240.  30, 43, 50, or 60, depending on the display adapter used and the screen
  26241.  mode.
  26242.  
  26243.  
  26244.  Table 1.21 lists the number of lines that can be displayed when a program is
  26245.  started.
  26246.  
  26247.  
  26248.  
  26249.  See Also
  26250.  
  26251.   SCREEN Statement,  VIEW PRINT
  26252.  
  26253.  Example
  26254.  
  26255.  The following example demonstrates the effect of the  WIDTH statement on
  26256.  output:
  26257.  
  26258.  CLS
  26259.  ' Open the port at the proper baud rate.
  26260.  OPEN "COM1:9600,N,8,1,ASC,LF" FOR OUTPUT AS #1
  26261.  Test$ = "1234567890"' Set up a test string.
  26262.  WIDTH #1, 3' Change width to 3.
  26263.  PRINT #1, Test$
  26264.  
  26265.  
  26266.  Output
  26267.  
  26268.  123
  26269.  456
  26270.  789
  26271.  0
  26272.  
  26273.  WINDOW Statement
  26274.  
  26275.  Action
  26276.  
  26277.  Defines the dimensions of the current graphics viewport window.
  26278.  
  26279.  Syntax
  26280.  
  26281.  
  26282.   WINDOW  SCREEN ( x1!,  y1!)  - ( x2!,  y2!)
  26283.  
  26284.  
  26285.  Remarks
  26286.  
  26287.  The  WINDOW statement allows the user to create a customized coordinate
  26288.  system to draw lines, graphs, or objects without being constrained by the
  26289.  physical coordinate values and orientation of the graphics viewport. This is
  26290.  done by redefining the graphics viewport coordinates with the "view
  26291.  coordinates" ( x1!,  y1!) and ( x2!,  y2!). These view coordinates are
  26292.  single-precision numbers.
  26293.  
  26294.   WINDOW defines a coordinate system that is mapped to the physical
  26295.  coordinates of the viewport. All subsequent graphics statements use the
  26296.  window coordinates and are displayed within the current viewport. (The size
  26297.  of the viewport can be changed with the  VIEW statement.)
  26298.  
  26299.  The  RUN statement, or  WINDOW with no arguments, disables the window
  26300.  transformation. (The window coordinates are the same as the viewport
  26301.  coordinates.) The  WINDOW SCREEN variant inverts the normal Cartesian
  26302.  direction of the y coordinate, so y values go from negative to positive from
  26303.  top to bottom.
  26304.  
  26305.  Figure 1.1 shows the effects of  WINDOW and  WINDOW SCREEN on a line drawn
  26306.  in screen mode 2. Notice the change in the coordinates of the screen
  26307.  corners.
  26308.  
  26309.  See Also
  26310.  
  26311.  
  26312.   SCREEN Statement,  VIEW,  WIDTH
  26313.  
  26314.  Example
  26315.  
  26316.  
  26317.  The following example uses BASIC graphics statements to generate a fractal.
  26318.  This fractal shows a subset of a class of numbers known as complex numbers;
  26319.  this subset is called the "Mandelbrot Set," named after an IBM researcher.
  26320.  The program uses the  VIEW,  WINDOW,  PMAP, and  PSET statements.
  26321.  
  26322.  DEFINT A-Z         ' Default variable type is integer.
  26323.  
  26324.  DECLARE SUB ScreenTest (EM%, CR%, VL%, VR%, VT%, VB%)
  26325.  
  26326.  
  26327.  
  26328.  ' Set maximum number of iterations per point.
  26329.  
  26330.  CONST MAXLOOP = 30, MAXSIZE = 1000000
  26331.  
  26332.  CONST FALSE = 0, TRUE = NOT FALSE       ' Boolean constants.
  26333.  
  26334.  ' Set window parameters.
  26335.  
  26336.  CONST WLeft = -1000, WRight = 250, WTop = 625, WBottom = -625
  26337.  
  26338.  
  26339.  
  26340.  ' Call ScreenTest to find out if this is an EGA machine,
  26341.  
  26342.  ' and get coordinates of viewport corners.
  26343.  
  26344.  ScreenTest EgaMode, ColorRange, VLeft, VRight, VTop, VBottom
  26345.  
  26346.  
  26347.  
  26348.  ' Define viewport and corresponding window.
  26349.  
  26350.  VIEW (VLeft, VTop)-(VRight, VBottom), 0, ColorRange
  26351.  
  26352.  WINDOW (WLeft, WTop)-(WRight, WBottom)
  26353.  
  26354.  
  26355.  
  26356.  LOCATE 24, 10: PRINT "Press any key to quit.";
  26357.  
  26358.  XLength = VRight - VLeft
  26359.  
  26360.  YLength = VBottom - VTop
  26361.  
  26362.  ColorWidth = MAXLOOP \ ColorRange
  26363.  
  26364.  
  26365.  
  26366.  ' Loop through each pixel in viewport and calculate
  26367.  
  26368.  '  whether or not it is in the Mandelbrot Set.
  26369.  
  26370.  FOR Y = 0 TO YLength       ' Loop through every line in the viewport.
  26371.  
  26372.     LogicY = PMAP(Y, 3)     ' Get the pixel's logical y coordinate.
  26373.  
  26374.     PSET (WLeft, LogicY)    ' Plot leftmost pixel in the line.
  26375.  
  26376.     OldColor = 0            ' Start with background color.
  26377.  
  26378.     FOR X = 0 TO XLength    ' Loop through every pixel in the line.
  26379.  
  26380.        LogicX = PMAP(X, 2)  ' Get the pixel's logical x coordinate.
  26381.  
  26382.        MandelX& = LogicX
  26383.  
  26384.        MandelY& = LogicY
  26385.  
  26386.        ' Do the calculations to see if this point is in
  26387.  
  26388.        '  the Mandelbrot Set.
  26389.  
  26390.        FOR I = 1 TO MAXLOOP
  26391.  
  26392.           RealNum& = MandelX& * MandelX&
  26393.  
  26394.           ImagNum& = MandelY& * MandelY&
  26395.  
  26396.           IF (RealNum& + ImagNum&) >= MAXSIZE THEN EXIT FOR
  26397.  
  26398.           MandelY& = (MandelX& * MandelY&) \ 250 + LogicY
  26399.  
  26400.           MandelX& = (RealNum& - ImagNum&) \ 500 + LogicX
  26401.  
  26402.        NEXT I
  26403.  
  26404.  ' Assign a color to the point.
  26405.  
  26406.        PColor = I \ ColorWidth
  26407.  
  26408.        ' If color has changed, draw a line from the
  26409.  
  26410.        ' last point referenced to the new point,
  26411.  
  26412.        '  using the old color.
  26413.  
  26414.        IF PColor <> OldColor THEN
  26415.  
  26416.           LINE -(LogicX, LogicY), (ColorRange - OldColor)
  26417.  
  26418.           OldColor = PColor
  26419.  
  26420.        END IF
  26421.  
  26422.        IF INKEY$ <> "" THEN END
  26423.  
  26424.     NEXT X
  26425.  
  26426.     ' Draw the last line segment to the right edge of
  26427.  
  26428.     '  the viewport.
  26429.  
  26430.     LINE -(LogicX, LogicY), (ColorRange - OldColor)
  26431.  
  26432.  NEXT Y
  26433.  
  26434.  DO : LOOP WHILE INKEY$ = ""
  26435.  
  26436.  SCREEN 0, 0             ' Restore the screen to text mode,
  26437.  
  26438.  WIDTH 80                ' 80 columns.
  26439.  
  26440.  END
  26441.  
  26442.  
  26443.  
  26444.  BadScreen:              ' Error handler that is invoked if
  26445.  
  26446.     EgaMode = FALSE      '  there is no EGA graphics card.
  26447.  
  26448.     RESUME NEXT
  26449.  
  26450.  
  26451.  
  26452.  ' The ScreenTest SUB procedure tests to see if user has EGA hardware
  26453.  
  26454.  ' EGA hardware with SCREEN 8. If this causes an error, the EM flag
  26455.  
  26456.  ' is set to FALSE, and the screen is set with SCREEN 1. ScreenTest
  26457.  
  26458.  ' also sets values for corners of viewport (VL = left, VR = right,
  26459.  
  26460.  ' VT = top, VB = bottom), scaled with the correct aspect ratio so
  26461.  
  26462.  ' that the viewport is a perfect square.
  26463.  
  26464.  SUB ScreenTest (EM, CR, VL, VR, VT, VB) STATIC
  26465.  
  26466.     EM = TRUE
  26467.  
  26468.     ON ERROR GOTO BadScreen
  26469.  
  26470.     SCREEN 8, 1
  26471.  
  26472.     ON ERROR GOTO 0
  26473.  
  26474.     IF EM THEN           ' No error, so SCREEN 8 is OK.
  26475.  
  26476.        VL = 110: VR = 529
  26477.  
  26478.        VT = 5: VB = 179
  26479.  
  26480.        CR = 15           ' 16 colors (0 - 15).
  26481.  
  26482.     ELSE                 ' Error, so use SCREEN 1.
  26483.  
  26484.        SCREEN 1, 1
  26485.  
  26486.        VL = 55: VR = 264
  26487.  
  26488.        VT = 5: VB = 179
  26489.  
  26490.        CR = 3            ' 4 colors (0 - 3).
  26491.  
  26492.     END IF
  26493.  
  26494.  END SUB
  26495.  
  26496.  WRITE Statement
  26497.  
  26498.  Action
  26499.  
  26500.  Sends data to the screen.
  26501.  
  26502.  Syntax
  26503.  
  26504.  
  26505.   WRITE  expressionlist
  26506.  
  26507.  
  26508.  Remarks
  26509.  
  26510.  The argument  expressionlist specifies one or more values to be written on
  26511.  the screen, separated by commas, with double quotation marks around the
  26512.  strings and no spaces around numbers.
  26513.  
  26514.  If  expressionlist is omitted, a blank line is written. If  expressionlist
  26515.  is included, the values of the expressions are written to the screen. The
  26516.  expressions in the list can be numeric and/or string expressions. They must
  26517.  be separated by commas.
  26518.  
  26519.  When the printed items are written, each item is separated from the last by
  26520.  a comma. Printed strings are delimited by quotation marks. After the last
  26521.  item in the list is printed, BASIC inserts a carriage-return-and-line-feed
  26522.  sequence. The  WRITE statement writes numeric values without leading or
  26523.  trailing spaces.
  26524.  
  26525.  See Also
  26526.  
  26527.   PRINT, PRINT USING
  26528.  
  26529.  Example
  26530.  
  26531.  The following example shows the difference between the  PRINT and  WRITE
  26532.  statements:
  26533.  
  26534.  CLS         ' Clear screen.
  26535.  
  26536.  A=80 : B=90 : C$="That's all." : D=-1.0E-13
  26537.  
  26538.  WRITE A,B,C$,D
  26539.  
  26540.  PRINT A,B,C$,D
  26541.  
  26542.  
  26543.  
  26544.  Output
  26545.  
  26546.  80,90,"That's all.",-1E-13
  26547.   80            90           That's all.  -1E-13
  26548.  
  26549.  WRITE # Statement
  26550.  
  26551.  Action
  26552.  
  26553.  Writes data to a sequential file.
  26554.  
  26555.  Syntax
  26556.  
  26557.  
  26558.   WRITE  #filenumber%,  expressionlist
  26559.  
  26560.  
  26561.  Remarks
  26562.  
  26563.  The  filenumber% is the number used in the  OPEN statement to open the file
  26564.  that will contain the data being written. The file must be opened in output
  26565.  or append mode. The expressions in the argument  expressionlist are string
  26566.  and/or numeric expressions, separated by commas. If you omit
  26567.  expressionlist, the  WRITE # statement writes a blank line to the file.
  26568.  
  26569.  The  WRITE # statement, unlike the  PRINT # statement, inserts commas
  26570.  between items and quotation marks around strings as they are written to the
  26571.  file. You do not have to put explicit delimiters in the list. A new line is
  26572.  inserted once the last item in the list has been written to
  26573.  
  26574.   the file.
  26575.  
  26576.  If you use  WRITE # in an attempt to write data to a sequential file
  26577.  restricted by a  LOCK statement, BASIC generates the error message
  26578.  Permission denied unless the error is trapped by the program. All of BASIC's
  26579.  usual error-handling routines can trap and examine this error.
  26580.  
  26581.  See Also
  26582.  
  26583.   LOCK,  OPEN,  PRINT #,  WRITE
  26584.  
  26585.  Example
  26586.  
  26587.  See the  LINE INPUT # statement programming example, which uses the  WRITE #
  26588.  statement.
  26589.  
  26590.  
  26591.   Part 2:  Date/Time, Financial, Format Functions
  26592.  
  26593.  
  26594.  Part 2 is an alphabetical reference for each function found in the
  26595.  Date/Time, Financial, and Format add-on libraries. The syntax, options, and
  26596.  action performed by each are described, as well as examples of how to use
  26597.  each in a BASIC program.
  26598.  Leading off Part 2 is a set of summary tables for the add-on libraries. Each
  26599.  table lists the names of the functions to use for specific tasks, along with
  26600.  the results.
  26601.  
  26602.  The following groups of functions are included:
  26603.    ■   Date/time functions
  26604.    ■   Financial functions
  26605.    ■   Format functions
  26606.  
  26607.  
  26608.  
  26609.  DateSerial# Function
  26610.  
  26611.  Action
  26612.  Returns a serial number that represents the date of the arguments.
  26613.  
  26614.  Syntax
  26615.   DateSerial# ( year%,  month%,  day%)
  26616.  
  26617.  Remarks
  26618.  The  DateSerial# function uses the following arguments:
  26619.  
  26620. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  26621.  Argument         Description
  26622.  ────────────────────────────────────────────────────────────────────────────
  26623.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  26624.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  26625.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  26626.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  26627.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  26628.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  26629.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  26630.  Argument         Description
  26631.  ────────────────────────────────────────────────────────────────────────────
  26632. DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  26633.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  26634.  
  26635.  
  26636.  
  26637.  
  26638.  The DATIM.BI header file contains the necessary function declarations for
  26639.  using the date/time functions. For more information on using libraries, see
  26640.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  26641.  Libraries" in the  Programmer's Guide.
  26642.  
  26643.  See Also
  26644.   DateSerial#,  Day&,  Month&,  Now#, Serial Numbers,  Weekday&,  Year&
  26645.  
  26646.  
  26647.  
  26648.  Day& Function
  26649.  
  26650.  
  26651.  Action
  26652.  Takes a date/time serial number and returns the day of the month.
  26653.  
  26654.  Syntax
  26655.   Day& ( serial#)
  26656.  
  26657.  
  26658.  Remarks
  26659.  The  Day& function returns an integer between 1 and 31, inclusive, that
  26660.  represents the day of the month corresponding to the argument.
  26661.  
  26662.  The argument  serial# is  a serial number that represents a date and/or
  26663.  time. For more information, see the topic "Serial Numbers" in this section.
  26664.  
  26665.  To use  Day& in the QBX environment, use the DTFMTER.QLB Quick library. To
  26666.  use  Day& outside of the QBX environment, link your program with the
  26667.  appropriate DTFMT xx.LIB file. Depending on the compiler options you chose
  26668.  when you installed BASIC, one or more of the following files will be
  26669.  available:
  26670.  
  26671. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  26672.  Filename         Compiler options
  26673.  ────────────────────────────────────────────────────────────────────────────
  26674.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  26675.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  26676.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  26677.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  26678.  
  26679.  
  26680.  
  26681.  
  26682.  The DATIM.BI header file contains the necessary function declarations for
  26683.  using the date/time functions. For more information on using libraries, see
  26684.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  26685.  Libraries" in the  Programmer's Guide.
  26686.  
  26687.  See Also
  26688.   Hour&,  Minute&,  Month&,  Now#,  Second&, Serial Numbers,  Weekday&,
  26689.  Year&
  26690.  
  26691.  
  26692.  
  26693.  DDB# Function
  26694.  
  26695.  Action
  26696.  Returns depreciation of an asset for a specific period using the
  26697.  double-declining-balance method.
  26698.  
  26699.  Syntax
  26700.   DDB# ( cost#,  salvage#,  life#,  period#,  status%)
  26701.  
  26702.  
  26703.  Remarks
  26704.  The double-declining-balance method computes depreciation at an accelerated
  26705.  rate. Depreciation is highest in the first period and decreases in
  26706.  successive periods.
  26707.  
  26708.  The  DDB# function uses the following arguments:
  26709.  
  26710. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  26711.  Argument                                Description
  26712.  ────────────────────────────────────────────────────────────────────────────
  26713.   cost#                                  The initial cost of the asset.
  26714.  Argument                                Description
  26715.  ────────────────────────────────────────────────────────────────────────────
  26716.   cost#                                  The initial cost of the asset.
  26717.  
  26718.   salvage#                               The value at the end of the useful
  26719.                                          life of the asset.
  26720.  
  26721.   life#                                  The useful life of the asset.
  26722.  
  26723.   period#                                The period for which asset
  26724.                                          depreciation is desired.
  26725.  
  26726.   status%                                A BASIC variable that indicates
  26727.                                          whether calculation succeeded or
  26728.                                          failed. The value of the variable
  26729.                                          will be 0 if the calculation was
  26730.                                          successful, and 1 if it was not.
  26731.  
  26732.  
  26733.  
  26734.  
  26735.  
  26736.  Note
  26737.  All numeric arguments must be positive values.
  26738.  
  26739.  The arguments  life# and  period# must use the same units. If  life# is
  26740.  given in months,  period# also must be given in months.
  26741.  
  26742.   DDB# uses the formula:
  26743.  
  26744.  Depreciation for a period = (( cost - total depreciation from prior periods)
  26745.  * 2) /  life
  26746.  
  26747.  To use  DDB# in the QBX environment, use the FINANCER.QLB Quick library. To
  26748.  use  DDB# outside of the QBX environment, link your program with the
  26749.  appropriate FINANC xx.LIB file. Depending on the compiler options you chose
  26750.  when you installed BASIC, one or more of the following files will be
  26751.  available:
  26752.  
  26753. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  26754.  Filename          Compiler options
  26755.  ────────────────────────────────────────────────────────────────────────────
  26756.  Filename          Compiler options
  26757.  ────────────────────────────────────────────────────────────────────────────
  26758.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  26759.  FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  26760.  FINANCEP.LIB      80x87 or emulator math; OS/2 protected mode
  26761.  FINANCAP.LIB      Alternate math; OS/2 protected mode
  26762.  
  26763.  
  26764.  
  26765.  
  26766.  The FINANC.BI header
  26767.  file contains the necessary function declarations for using the financial
  26768.  functions. For more information on using libraries, see Chapter 18, "Using
  26769.  LINK and LIB" and Chapter 19, "Creating and Using Quick Libraries" in the
  26770.  Programmer's Guide.
  26771.  
  26772.  
  26773.  See Also
  26774.  SLN #,  SYD#
  26775.  
  26776.  
  26777.  
  26778.  FormatX$ Functions
  26779.  
  26780.  Action
  26781.  Formats a numeric value.
  26782.  
  26783.  Syntax
  26784.   FormatI$ ( expression#,  fmt$)
  26785.   FormatL$ ( expression#,  fmt$)
  26786.   FormatS$ ( expression#,  fmt$)
  26787.   FormatD$ ( expression#,  fmt$)
  26788.   FormatC$ ( expression#,  fmt$)
  26789.  
  26790.  
  26791.  Remarks
  26792.  The  Format X $ functions  return  a string that contains the formatted
  26793.  expression. The functions use the following arguments:
  26794.  
  26795. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  26796.  Argument                                Description
  26797.  ────────────────────────────────────────────────────────────────────────────
  26798.  Argument                                Description
  26799.  ────────────────────────────────────────────────────────────────────────────
  26800.   expression#                            A numeric expression to be
  26801.                                          formatted.
  26802.  
  26803.   fmt$                                   A string expression comprising
  26804.                                          BASIC display-format characters
  26805.                                          that detail how the expression is
  26806.                                          to be displayed.
  26807.  
  26808.  
  26809.  
  26810.  
  26811.  There are five separate add-on-library functions, depending on the data type
  26812.  of  expression#. Use the appropriate function as shown below:
  26813.  
  26814. ╓┌──────────────────────┌────────────────────────────────────────────────────╖
  26815.  Function               Data type of  expression
  26816.  ────────────────────────────────────────────────────────────────────────────
  26817.   FormatI$              Integer
  26818.   FormatL$              Long integer
  26819.  Function               Data type of  expression
  26820.  ────────────────────────────────────────────────────────────────────────────
  26821.  FormatL$              Long integer
  26822.   FormatS$              Single precision
  26823.   FormatD$              Double precision
  26824.   FormatC$              Currency
  26825.  
  26826.  
  26827.  
  26828.  
  26829.  If  fmt$ is a null string, BASIC uses the general format (which gives output
  26830.  identical to output with no formatting).
  26831.  
  26832.  To use the  Format X $ functions in the QBX environment, use the DTFMTER.QLB
  26833.  Quick library. To use the  Format X $ functions outside of the QBX
  26834.  environment, link your program with the appropriate DTFMT xx.LIB file.
  26835.  Depending on the compiler options you chose when you installed BASIC, one or
  26836.  more of the following files will be available:
  26837.  
  26838. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  26839.  Filename         Compiler options
  26840.  Filename         Compiler options
  26841.  ────────────────────────────────────────────────────────────────────────────
  26842.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  26843.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  26844.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  26845.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  26846.  
  26847.  
  26848.  
  26849.  
  26850.  The FORMAT.BI header
  26851.  file contains the necessary function declarations for using the  Format X $
  26852.  functions. For more information on using libraries, see Chapter 18, "Using
  26853.  LINK and LIB" and Chapter 19, "Creating and Using Quick Libraries" in the
  26854.  Programmer's Guide.
  26855.  
  26856.  
  26857.  Available Formats
  26858.  
  26859.  The  Format X $ functions provide a wide range of formats for numeric and
  26860.  date/time data. The following symbols are used to create the formats:
  26861.  
  26862. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  26863.  Symbol                                  Meaning
  26864.  ────────────────────────────────────────────────────────────────────────────
  26865.  Null string                             Display the number in general
  26866.                                          format.
  26867.  
  26868.  0                                       Digit placeholder.
  26869.  
  26870.                                          If the number has fewer digits on
  26871.                                          either side of the decimal point
  26872.                                          than there are zeros on either
  26873.                                          side of the decimal point in the
  26874.                                          format, the extra zeros are
  26875.                                          displayed. If the number has more
  26876.                                          digits to the right of the decimal
  26877.                                          point than there are zeros to the
  26878.                                          right in the format, the number is
  26879.                                          rounded to as many decimal places
  26880.                                          as there are zeros to the right.
  26881.                                          If the number has more digits to
  26882.  Symbol                                  Meaning
  26883.  ────────────────────────────────────────────────────────────────────────────
  26884.                                         If the number has more digits to
  26885.                                          the left of the decimal point than
  26886.                                          there are zeros to the left in the
  26887.                                          format, the extra digits are
  26888.                                          displayed.
  26889.  
  26890.  #                                       Digit placeholder.
  26891.  
  26892.                                          Follows the same rules as for the
  26893.                                          0 digit placeholder, except that
  26894.                                          extra zeros are not displayed if
  26895.                                          the number has fewer digits on
  26896.                                          either side of the decimal point
  26897.                                          than there are number signs (#) on
  26898.                                          either side of the decimal point.
  26899.  
  26900.  .                                       Decimal point.
  26901.  
  26902.                                          This symbol determines how many
  26903.  Symbol                                  Meaning
  26904.  ────────────────────────────────────────────────────────────────────────────
  26905.                                         This symbol determines how many
  26906.                                          digits BASIC displays to the right
  26907.                                          and left of the decimal point.
  26908.                                          Depending on the country code set
  26909.                                          using the  SetFormatCC routine,
  26910.                                          BASIC may use the comma as the
  26911.                                          decimal point. If the format
  26912.                                          contains only number signs (#) to
  26913.                                          the left of this symbol, numbers
  26914.                                          smaller than 1 are begun with a
  26915.                                          decimal point. To avoid this, you
  26916.                                          should use 0 as the first digit
  26917.                                          placeholder to the left of a
  26918.                                          decimal point instead  of #.
  26919.  
  26920.  %                                       Percentage.
  26921.  
  26922.                                          The expression is multiplied by
  26923.                                          100 and the percent character (%)
  26924.  Symbol                                  Meaning
  26925.  ────────────────────────────────────────────────────────────────────────────
  26926.                                         100 and the percent character (%)
  26927.                                          is inserted.
  26928.  
  26929.  
  26930.  
  26931.  
  26932.  
  26933.  
  26934. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  26935.  ────────────────────────────────────────────────────────────────────────────
  26936.  ,                                       Thousands separator.
  26937.  
  26938.                                          BASIC separates thousands by
  26939.                                          commas (or by periods, depending
  26940.                                          on the country code set using the
  26941.                                          SetFormatCC routine) if the format
  26942.                                          contains a comma surrounded by
  26943.                                          digit placeholders (0 or #). Two
  26944.                                          adjacent commas, or a comma
  26945.  ────────────────────────────────────────────────────────────────────────────
  26946.                                         adjacent commas, or a comma
  26947.                                          immediately to the left of the
  26948.                                          decimal point location (whether
  26949.                                          there is a decimal specified or
  26950.                                          not) means "Omit the three digits
  26951.                                          that fall between these commas, or
  26952.                                          between the comma and the decimal
  26953.                                          point, rounding as needed."
  26954.  
  26955.  E-  E+  e-  e+                          Scientific format.
  26956.  
  26957.                                          If a format contains one digit
  26958.                                          placeholder (0 or #) to the right
  26959.                                          of an E-, E+, e-, or e+, BASIC
  26960.                                          displays the number in scientific
  26961.                                          format and inserts an E or e. The
  26962.                                          number of digit placeholders to
  26963.                                          the right determines the number of
  26964.                                          digits in the exponent. Use E- or
  26965.                                          e- to place a minus sign next to
  26966.  ────────────────────────────────────────────────────────────────────────────
  26967.                                         e- to place a minus sign next to
  26968.                                          negative exponents. Use E+ or e+
  26969.                                          to place a minus sign next to
  26970.                                          negative exponents and a plus sign
  26971.                                          next to positive exponents.
  26972.  
  26973.  :  -  +  $  ( )  Space                  Display that literal character.
  26974.  
  26975.                                          To display characters other than
  26976.                                          one of these, precede each
  26977.                                          character with a backslash( \ ) or
  26978.                                          enclose the character(s) in double
  26979.                                          quotation marks ("").
  26980.  
  26981.  \                                       Display the next character in the
  26982.                                          format string.
  26983.  
  26984.                                          Many characters in the format
  26985.                                          string have a special meaning and
  26986.                                          cannot be displayed as literal
  26987.  ────────────────────────────────────────────────────────────────────────────
  26988.                                         cannot be displayed as literal
  26989.                                          characters unless they are
  26990.                                          preceded by a backslash. The
  26991.                                          backslash is not displayed. This
  26992.                                          is the same as enclosing the next
  26993.                                          character in double quotation
  26994.                                          marks.
  26995.  
  26996.                                          Examples of such characters are
  26997.                                          the date- and time-formatting
  26998.                                          characters (y, m, d, h, s, a, and
  26999.                                          p) and the numeric-formatting
  27000.                                          characters (#, 0, %, E, e, comma,
  27001.                                          and period).
  27002.  
  27003.  " abc"                                  Display whatever text is inside
  27004.                                          the double quotation marks.
  27005.  
  27006.                                          To include a text string in  fmt$,
  27007.                                          you must use CHR$(34) to enclose
  27008.  ────────────────────────────────────────────────────────────────────────────
  27009.                                         you must use CHR$(34) to enclose
  27010.                                          the text (34 is the ASCII code for
  27011.                                          double quotation mark).
  27012.  
  27013.  
  27014.  
  27015.  
  27016.  
  27017.  
  27018.  The  Format X $ functions have the following general syntax:  Format X $ (
  27019.  expression#,  fmt$). Some sample numeric formats are shown below for
  27020.  different values of  fmt $ and  expression#. (These examples all assume the
  27021.  country code is set to 1, United States.)
  27022.  
  27023.  The following example has two sections: the first section defines the format
  27024.  for positive numbers and zeros; the second section defines the format for
  27025.  negative numbers.
  27026.  
  27027.  $#,##0;($#,##0)
  27028.  You can use from one to three sections:
  27029.  
  27030. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  27031.  ────────────────────────────────────────────────────────────────────────────
  27032.  One section only                        The format applies to all numbers.
  27033.  
  27034.  Two sections                            The first section applies to
  27035.                                          positive numbers and zeros; the
  27036.                                          second to negative numbers.
  27037.  
  27038.  Three sections                          The first section applies to
  27039.                                          positive numbers, the second to
  27040.                                          negative numbers, and the third to
  27041.                                          zeros.
  27042.  
  27043.  
  27044.  
  27045.  
  27046.  
  27047.  If you have semicolons with nothing between them, the missing section is
  27048.  printed using the format of the positive value. For example, the following
  27049.  format will display positive and negative numbers using the format in the
  27050.  first section, and "Zero" if the value is zero:
  27051.  
  27052.  "$#,##0;;Z\ero"
  27053.  
  27054.  Date/Time Formats
  27055.  
  27056.  Date/time serial numbers can be formatted with date/time or numeric formats
  27057.  (since date/time serial numbers are stored as floating-point values).
  27058.  
  27059.  Date/time formats have the following meanings:
  27060.  
  27061. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  27062.  Symbol                                  Meaning
  27063.  ────────────────────────────────────────────────────────────────────────────
  27064.  d dd ddd dddd                           Display the day as a number
  27065.                                          without leading zeros (1-12), as a
  27066.                                          number with leading zeros (01-12),
  27067.                                          as an abbreviation (Sun-Sat), or
  27068.                                          as a full name (Sunday-Saturday).
  27069.  
  27070.  m mm mmm mmmm                           Display the month as a number
  27071.  Symbol                                  Meaning
  27072.  ────────────────────────────────────────────────────────────────────────────
  27073. m mm mmm mmmm                           Display the month as a number
  27074.                                          without leading zeros (1-12), as a
  27075.                                          number with leading zeros (01-12),
  27076.                                          as an abbreviation (Jan-Dec), or
  27077.                                          as a full month name
  27078.                                          (January-December). If you use m
  27079.                                          or mm immediately after the h or
  27080.                                          hh symbol, the minute rather than
  27081.                                          the month is displayed.
  27082.  
  27083.  yy yyyy                                 Display the year as a two-digit
  27084.                                          number (00 - 99), or as a
  27085.                                          four-digit number (1900 - 2040).
  27086.  
  27087.  h hh                                    Display the hour as a number
  27088.                                          without leading zeros (0 - 23), or
  27089.                                          as a number with leading zeros (00
  27090.                                          - 23). If the format contains an
  27091.                                          AM or PM, the hour is based on the
  27092.  Symbol                                  Meaning
  27093.  ────────────────────────────────────────────────────────────────────────────
  27094.                                         AM or PM, the hour is based on the
  27095.                                          12-hour clock. Otherwise, the hour
  27096.                                          is based on the 24-hour clock.
  27097.  
  27098.  m mm                                    Display the minute as a number
  27099.                                          without leading zeros (0 - 59),
  27100.                                          or as a number with leading zeros
  27101.                                          (00 - 59). The m or mm must appear
  27102.                                          after an h or hh, or the month is
  27103.                                          displayed rather than the minute.
  27104.  
  27105.  s ss                                    Display the second as a number
  27106.                                          without leading zeros (0 - 59), or
  27107.                                          as a number with leading zeros (00
  27108.                                          - 59)..
  27109.  
  27110.  AM / PM am / pm A / P a / p             Display the hour using the 12-hour
  27111.                                          clock. AM, am, A, or a is
  27112.                                          displayed with any time before
  27113.  Symbol                                  Meaning
  27114.  ────────────────────────────────────────────────────────────────────────────
  27115.                                         displayed with any time before
  27116.                                          noon. PM, pm, P, or p is displayed
  27117.                                          with any time between noon and
  27118.                                          11:59 P.M.
  27119.  
  27120.  
  27121.  
  27122.  
  27123.  
  27124.  The following are examples of date and time formats:
  27125.  d-mmmm-yy       7-December-58
  27126.  d-mmmm          7-December
  27127.  mmmm-yy         December-58
  27128.  h:mm AM/PM      8:50 PM
  27129.  h:mm:ss AM/PM   8:50:35 PM
  27130.  h:mm            20:50
  27131.  h:mm:ss         20:50:35
  27132.  m/d/yy h:mm     12/7/58 20:50
  27133.  
  27134.  See Also
  27135.   PRINT,  PRINT  USING,  STR$
  27136.  
  27137.  
  27138.  
  27139.  FV# Function
  27140.  
  27141.  Action
  27142.  Returns the future value of an annuity based on periodic, constant payments
  27143.  and a constant interest rate.
  27144.  
  27145.  Syntax
  27146.   FV# ( rate#,  nper#,  pmt#,  pv#,  type%,  status%)
  27147.  
  27148.  
  27149.  Remarks
  27150.  An annuity is a series of constant cash payments made over a continuous
  27151.  period of time. An annuity can be a loan (such as a home mortgage) or an
  27152.  investment (such as a monthly savings plan).
  27153.  
  27154.  The  FV# function uses the following arguments:
  27155.  
  27156. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  27157.  Argument                                Description
  27158.  ────────────────────────────────────────────────────────────────────────────
  27159.   rate#                                  The interest rate per period. For
  27160.                                          example, if you get a car loan at
  27161.                                          an annual rate of 10 percent and
  27162.                                          make monthly payments, the rate
  27163.                                          per period would be .10/12, or
  27164.                                          .0083.
  27165.  
  27166.   nper#                                  The number of payment periods in
  27167.                                          the annuity. For example, if you
  27168.                                          get a four-year car loan and make
  27169.                                          monthly payments, your loan has a
  27170.                                          total number of 4 times 12, or 48,
  27171.                                          payment periods.
  27172.  
  27173.   pmt#                                   The payment to be made each period.
  27174.                                          It  usually contains principal and
  27175.                                          interest and does not change over
  27176.  Argument                                Description
  27177.  ────────────────────────────────────────────────────────────────────────────
  27178.                                         interest and does not change over
  27179.                                          the life of the annuity.
  27180.  
  27181.   pv#                                    The present value or a lump sum
  27182.                                          that a series of payments to be
  27183.                                          paid in the future is worth now.
  27184.                                          For example, when you borrow money
  27185.                                          to buy a car, the loan amount is
  27186.                                          the present value to the lender of
  27187.                                          the monthly car payments you will
  27188.                                          make.
  27189.  
  27190.   type%                                  An integer expression that
  27191.                                          indicates when payments are due.
  27192.                                          Use 0 as the value for  type if
  27193.                                          payments are due at the end of the
  27194.                                          period; use 1 if due at the
  27195.                                          beginning of the period.
  27196.  
  27197.  Argument                                Description
  27198.  ────────────────────────────────────────────────────────────────────────────
  27199. 
  27200.   status%                                A BASIC variable that indicates
  27201.                                          whether calculation succeeded or
  27202.                                          failed. The value of the variable
  27203.                                          will be 0 if the calculation was
  27204.                                          successful, and 1 if it was not.
  27205.  
  27206.  
  27207.  
  27208.  
  27209.  
  27210.  The arguments  rate# and  nper# must use consistent units. For example:
  27211.  
  27212.  Note
  27213.  For all arguments, cash you pay out, such as deposits to savings, is
  27214.  represented by negative numbers; cash you receive, such as dividend checks,
  27215.  is represented by positive numbers.
  27216.  
  27217.  A number of other functions are related to  FV#:
  27218.    ■    IPmt# returns the interest payment for an annuity for a given period.
  27219.    ■    NPer# returns the number of periods (payments) for an annuity.
  27220.    ■    Pmt# returns the periodic total payment for an annuity.
  27221.    ■    PPmt# returns the principal payment for an annuity for a given
  27222.        period.
  27223.    ■    PV# returns the present value of an annuity.
  27224.    ■    Rate# returns the interest rate per period of an annuity.
  27225.  
  27226.  
  27227.  To use  FV# in the QBX environment, use the FINANCER.QLB Quick library. To
  27228.  use  FV# outside of the QBX environment, link your program with the
  27229.  appropriate FINANC xx.LIB file. Depending on the compiler options you chose
  27230.  when you installed BASIC, one or more of the following files will be
  27231.  available:
  27232.  
  27233.  
  27234. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  27235.  Filename          Compiler options
  27236.  ────────────────────────────────────────────────────────────────────────────
  27237.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  27238.  FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  27239.  Filename          Compiler options
  27240.  ────────────────────────────────────────────────────────────────────────────
  27241. FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  27242.  FINANCEP.LIB      80x87 or emulator math; OS/2 protected mode
  27243.  FINANCAP.LIB      Alternate math; OS/2 protected mode
  27244.  
  27245.  
  27246.  
  27247.  
  27248.  The FINANC.BI header file contains the necessary function declarations for
  27249.  using the financial functions. For more information on using libraries, see
  27250.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  27251.  Libraries" in the  Programmer's Guide.
  27252.  
  27253.  See Also
  27254.   IPmt#,  NPer#,  Pmt#, P Pmt#, PV#, R ate#
  27255.  
  27256.  
  27257.  
  27258.  
  27259.  Hour& Function
  27260.  
  27261.  Action
  27262.  Takes a date/time serial number and returns the hour.
  27263.  
  27264.  Syntax
  27265.  
  27266.   Hour& ( serial#)
  27267.  
  27268.  
  27269.  Remarks
  27270.  The  Hour& function returns an integer between 0 (12:00 A.M.) and 23 (11:00
  27271.  P.M.) that represents the hour of the day corresponding to the argument.
  27272.  
  27273.  The argument  serial# is  a serial number that represents a date and/or
  27274.  time. For more information, see the topic "Serial Numbers" in this section.
  27275.  
  27276.  To use  Hour& in the QBX environment, use the DTFMTER.QLB Quick library. To
  27277.  use  Hour&  outside of the QBX environment, link your program with the
  27278.  appropriate DTFMT xx.LIB file. Depending on the compiler options you chose
  27279.  when you installed BASIC, one or more of the following files will be
  27280.  available:
  27281.  
  27282. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  27283.  Filename         Compiler options
  27284.  ────────────────────────────────────────────────────────────────────────────
  27285.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  27286.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  27287.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  27288.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  27289.  
  27290.  
  27291.  
  27292.  The DATIM.BI header file contains the necessary function declarations for
  27293.  using the date/time functions. For more information on using libraries, see
  27294.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  27295.  Libraries" in the  Programmer's Guide.
  27296.  
  27297.  See Also
  27298.   Day&,  Minute&,  Month&,  Second&, Serial Numbers,  Weekday&,  Year&
  27299.  
  27300.  
  27301.  
  27302.  IPmt# Function
  27303.  
  27304.  Action
  27305.  Returns the interest payment for a given period of an annuity based on
  27306.  periodic, constant payments and a constant interest rate.
  27307.  
  27308.  Syntax
  27309.   IPmt# ( rate#,  per#,  nper#,  pv#,  fv#,  type%,  status%)
  27310.  
  27311.  
  27312.  Remarks
  27313.  An annuity is a series of constant cash payments made over a continuous
  27314.  period of time. An annuity can be a loan (such as a home mortgage) or an
  27315.  investment (such as a monthly savings plan).
  27316.  
  27317.  The  IPmt# function uses the following arguments:
  27318.  
  27319. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  27320.  Argument                                Description
  27321.  ────────────────────────────────────────────────────────────────────────────
  27322.   rate#                                  The interest rate per period. For
  27323.  Argument                                Description
  27324.  ────────────────────────────────────────────────────────────────────────────
  27325.   rate#                                  The interest rate per period. For
  27326.                                          example, if you get a car loan at
  27327.                                          an annual rate of 10 percent and
  27328.                                          make monthly payments, the rate
  27329.                                          per period would be .10 divided by
  27330.                                          12, or .0083.
  27331.  
  27332.   per#                                   The payment period; must be in the
  27333.                                          range from 1 to  nper#.
  27334.  
  27335.   nper#                                  The number of payment periods in
  27336.                                          the annuity. For example, if you
  27337.                                          get a four-year car loan and make
  27338.                                          monthly payments, your loan has a
  27339.                                          total number of 4 times 12, or 48,
  27340.                                          payment periods.
  27341.  
  27342.   pv#                                    The present value or a lump sum
  27343.                                          that a series of payments to be
  27344.  Argument                                Description
  27345.  ────────────────────────────────────────────────────────────────────────────
  27346.                                         that a series of payments to be
  27347.                                          paid in the future is worth now.
  27348.                                          For example, when you borrow money
  27349.                                          to buy a car, the loan amount is
  27350.                                          the present value to the lender of
  27351.                                          the monthly car payments you will
  27352.                                          make.
  27353.  
  27354.   fv#                                    The future value or the cash
  27355.                                          balance you want sometime in the
  27356.                                          future after the last payment is
  27357.                                          made. The future value of a loan,
  27358.                                          for instance, is 0. As another
  27359.                                          example, if you think you will
  27360.                                          need $50,000 in 18 years to pay
  27361.                                          for your child's education, then
  27362.                                          $50,000 is the future value.
  27363.  
  27364.   type%                                  An integer expression that
  27365.  Argument                                Description
  27366.  ────────────────────────────────────────────────────────────────────────────
  27367.  type%                                  An integer expression that
  27368.                                          indicates when payments are due.
  27369.                                          Use 0 as the value for  type% if
  27370.                                          payments are due at the end of the
  27371.                                          period; use 1 if due at the
  27372.                                          beginning of the period.
  27373.  
  27374.   status%                                A BASIC variable that indicates
  27375.                                          whether calculation succeeded or
  27376.                                          failed. The value of the variable
  27377.                                          will be 0 if the calculation was
  27378.                                          successful, and 1 if it was not.
  27379.  
  27380.  
  27381.  
  27382.  
  27383.  
  27384.  The arguments  rate# and  nper# must use
  27385.  consistent units.
  27386.  
  27387.  
  27388.  Note
  27389.  For all arguments, negative numbers equal cash you pay out, and positive
  27390.  numbers equal cash you receive.
  27391.  
  27392.  A number of other functions are related to  IPmt#:
  27393.    ■    FV# returns the the future value of an annuity.
  27394.    ■    NPer# returns the number of periods (payments) for an annuity.
  27395.    ■    Pmt# returns the periodic total payment for an annuity.
  27396.    ■    PPmt# returns the principal payment for an annuity for a given
  27397.        period.
  27398.    ■    PV# returns the present value of an annuity.
  27399.    ■    Rate# returns the interest rate per period of an annuity.
  27400.  
  27401.  
  27402.  To use  IPmt# in the QBX environment, use the FINANCER.QLB Quick library. To
  27403.  use  IPmt# outside of the QBX environment, link your program with the
  27404.  appropriate FINANCxx.LIB file. Depending on the compiler options you chose
  27405.  when you installed BASIC, one or more of the following files will be
  27406.  available:
  27407.  
  27408.  
  27409. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  27410.  Filename          Compiler options
  27411.  ────────────────────────────────────────────────────────────────────────────
  27412.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  27413.  FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  27414.  FINANCEP.LIB      80x87 or emulator math; OS/2 protected mode
  27415.  FINANCAP.LIB      Alternate math; OS/2 protected mode
  27416.  
  27417.  
  27418.  
  27419.  The FINANC.BI header file contains the necessary function declarations for
  27420.  using the financial functions. For more information on using libraries, see
  27421.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  27422.  Libraries" in the  Programmer's Guide.
  27423.  
  27424.  See Also
  27425.  FV#,  NPer#,  Pmt#,  PPmt#, PV#,  Rate#
  27426.  
  27427.  Example
  27428.  
  27429.  
  27430.  This example uses the  IPmt# function to calculate how much you will pay
  27431.  over the lifetime of a loan where all the payments are of equal value.
  27432.  
  27433.  To run this example, you must link it with the appropriate FINANC xx.LIB and
  27434.  DTFMT xx.LIB files or use the FINANCER.QLB and DTFMTER.QLB Quick libraries.
  27435.  The following include files must also be present:
  27436.  
  27437.  ' $INCLUDE: 'FINANC.BI'
  27438.  ' $INCLUDE: 'FORMAT.BI'
  27439.  
  27440.  CONST YEARMONTHS = 12
  27441.  CONST ENDPERIOD = 0
  27442.  CONST BEGINPERIOD = 1
  27443.  CONST DOLLARFORMAT$ = "$###,###,###.00"
  27444.  FutureVal = 0
  27445.  DEFDBL A-Z
  27446.  DIM Status  AS INTEGER
  27447.  
  27448.  ' Get user input.
  27449.  CLS
  27450.  INPUT "Enter the annual percentage rate of your loan"; APR
  27451.  PRINT
  27452.  INPUT "What is the principal amount of your loan"; PresentVal
  27453.  PRINT
  27454.  INPUT "How many monthly payments do you have to make"; NumPeriods
  27455.  PRINT
  27456.  DO WHILE PaymentTypeString$ <> "B" AND PaymentTypeString$ <> "E"
  27457.      PRINT "Payments due at the beginning or end of the month? ";
  27458.      PaymentTypeString$ = UCASE$(INPUT$(1))
  27459.  LOOP
  27460.  
  27461.  ' Set up the correct payment type.
  27462.  IF PaymentTypeString$ = "B" THEN
  27463.      PaymentType = BEGINPERIOD
  27464.      PRINT "Beginning"
  27465.  ELSE
  27466.      PaymentType = ENDPERIOD
  27467.      PRINT "End"
  27468.  END IF
  27469.  PRINT
  27470.  
  27471.  ' Put APR in proper form.
  27472.  IF APR > 1 THEN APR = APR / 100
  27473.  
  27474.  FOR Period = 1 TO
  27475.  NumPeriods
  27476.  
  27477.      ' Calculate the Interest paid each month.
  27478.  InterestPmt = ABS(IPmt#(APR / YEARMONTHS, Period, NumPeriods,_
  27479.                     -PresentVal, FutureVal, PaymentType, Status))
  27480.      ' Check for an error.
  27481.      IF Status THEN
  27482.          PRINT "There was a calculation error."
  27483.          END
  27484.      END IF
  27485.      ' Accumulate a total.
  27486.      TotalInterest = TotalInterest + InterestPmt
  27487.  NEXT Period
  27488.  
  27489.  ' Format and display results.
  27490.  TotalInterest$ = FormatD$(TotalInterest, DOLLARFORMAT$)
  27491.  PresentVal$ = FormatD$(PresentVal, DOLLARFORMAT$)
  27492.  TotalPaid$ = FormatD$(TotalInterest + PresentVal, DOLLARFORMAT$)
  27493.  PRINT
  27494.  PRINT "You'll pay a total of "; TotalPaid$; " on your "; PresentVal$;
  27495.  PRINT " loan, of which "; TotalInterest$; " is interest."
  27496.  
  27497.  
  27498.  
  27499.  IRR# Function
  27500.  
  27501.  Action
  27502.  Returns the internal rate of return for a series of periodic cash flows
  27503.  (payments and receipts).
  27504.  
  27505.  Syntax
  27506.   IRR# ( valuearray# ( ),  valuecount%,  guess#,  status%)
  27507.  
  27508.  
  27509.  Remarks
  27510.  The internal rate of return is the interest rate received for an investment
  27511.  that consists of payments and receipts that occur at regular intervals.
  27512.  
  27513.  The  IRR# function uses the following arguments:
  27514.  
  27515. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  27516.  Argument                                Description
  27517.  ────────────────────────────────────────────────────────────────────────────
  27518.   valuearray#( )                         An array of cash-flow values. The
  27519.                                          argument must contain at least one
  27520.                                          negative value (a payment) and one
  27521.                                          positive value (a receipt).
  27522.  
  27523.   valuecount%                            The total number of items in the
  27524.                                          cash-flow array.
  27525.  
  27526.   guess#                                 A value you guess is close to the
  27527.                                          result of  IRR#. In most cases you
  27528.                                          can assume  guess# to be 0.1 (10
  27529.                                          percent). However, if  IRR#
  27530.                                          returns a status of 1 (failure),
  27531.                                          or if the result is not close to
  27532.                                          what you expected, try different
  27533.  Argument                                Description
  27534.  ────────────────────────────────────────────────────────────────────────────
  27535.                                         what you expected, try different
  27536.                                          values of  guess#.
  27537.  
  27538.   status%                                A BASIC variable that indicates
  27539.                                          whether calculation succeeded or
  27540.                                          failed. The value of the variable
  27541.                                          will be 0 if the calculation was
  27542.                                          successful, and 1 if it was not.
  27543.  
  27544.  
  27545.  
  27546.    ■    MIRR# gives the internal rate of return where positive and negative
  27547.        cash flows are financed at different rates.
  27548.  
  27549.    ■    NPV# gives the net present value of an investment based on cash flows
  27550.        that do not have to be constant.
  27551.  
  27552.    ■    Rate# gives the interest rate per period of an investment.
  27553.  
  27554.  
  27555.  To use  IRR# in the QBX
  27556.  environment, use the FINANCER.QLB Quick library. To use  IRR# outside of the
  27557.  QBX environment, link your program with the appropriate FINANC xx.LIB file.
  27558.  Depending on the compiler options you chose when you installed BASIC, one or
  27559.  more of the following files will be available:
  27560.  
  27561.  
  27562. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  27563.  Filename          Compiler options
  27564.  ────────────────────────────────────────────────────────────────────────────
  27565.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  27566.  FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  27567.  FINANCEP.LIB      80x87 or emulator math; OS/2 protected mode
  27568.  FINANCAP.LIB      Alternate math; OS/2 protected mode
  27569.  
  27570.  
  27571.  
  27572.  The FINANC.BI header file contains the necessary function declarations for
  27573.  using the financial functions. For more information on using libraries, see
  27574.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  27575.  Libraries" in the  Programmer's Guide.
  27576.  
  27577.  See Also
  27578.   MIRR#,  NPV#,  Rate#
  27579.  
  27580.  
  27581.  
  27582.  
  27583.  Minute& Function
  27584.  
  27585.  Action
  27586.  Takes a date/time serial number and returns the minute.
  27587.  
  27588.  Syntax
  27589.   Minute& ( serial# )
  27590.  
  27591.  
  27592.  Remarks
  27593.  The  Minute& function returns an integer between 0 and 59, inclusive, that
  27594.  represents the minute corresponding to the argument.
  27595.  
  27596.  The argument  serial#  is a serial number that represents a date and/or
  27597.  time. For more information, see the topic "Serial Numbers" in this section.
  27598.  
  27599.  To use  Minute& in the QBX environment, use the DTFMTER.QLB Quick library.
  27600.  To use  Minute& outside of the QBX environment, link your program with the
  27601.  appropriate DTFMT xx.LIB file. Depending on the compiler options you chose
  27602.  when you installed BASIC, one or more of the following files will be
  27603.  available:
  27604.  
  27605. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  27606.  Filename         Compiler options
  27607.  ────────────────────────────────────────────────────────────────────────────
  27608.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  27609.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  27610.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  27611.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  27612.  
  27613.  
  27614.  
  27615.  
  27616.  The DATIM.BI header file contains the necessary function declarations for
  27617.  using the date/time functions. For more information on using libraries, see
  27618.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  27619.  Libraries" in the  Programmer's Guide.
  27620.  
  27621.  See Also
  27622.   Day&,  Hour&,  Month&,  Now#,  Second&, Serial Numbers,  Weekday&,  Year&
  27623.  
  27624.  
  27625.  
  27626.  
  27627.  MIRR# Function
  27628.  
  27629.  Action
  27630.  Returns the modified internal rate of return for a series of periodic cash
  27631.  flows (payments and receipts).
  27632.  
  27633.  Syntax
  27634.   MIRR# ( valuearray# ( ),  valuecount%,  fin-rate#,  reinv-rate#,
  27635.  status%)
  27636.  
  27637.  
  27638.  Remarks
  27639.  The modified internal rate of return is the internal rate of return where
  27640.  payments and receipts are financed at different rates.  MIRR# considers both
  27641.  the cost of the investment ( fin-rate#) and the interest received on
  27642.  reinvestment of cash ( reinv-rate#).
  27643.  
  27644.  The  MIRR# function uses the following arguments:
  27645.  
  27646. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  27647.  Argument                                Description
  27648.  ────────────────────────────────────────────────────────────────────────────
  27649.   valuearray# ( )                        An array of cash-flow values. The
  27650.                                          argument must contain at least one
  27651.                                          negative value (a payment) and one
  27652.                                          positive value (a receipt).
  27653.  
  27654.   valuecount%                            The total number of items in the
  27655.                                          cash-flow array.
  27656.  
  27657.   fin-rate#                              The interest rate paid as the cost
  27658.                                          of financing..
  27659.  Argument                                Description
  27660.  ────────────────────────────────────────────────────────────────────────────
  27661.                                         of financing..
  27662.  
  27663.   reinv-rate#                            The interest rate received on
  27664.                                          gains from cash reinvestment.
  27665.  
  27666.   status%                                A BASIC variable that indicates
  27667.                                          whether calculation succeeded or
  27668.                                          failed. The value of the variable
  27669.                                          will be 0 if the calculation was
  27670.                                          successful, and 1 if it was not.
  27671.  
  27672.  
  27673.  
  27674.  
  27675.  
  27676.  The arguments  fin-rate# and  reinv-rate# are percentages expressed as
  27677.  decimal values. For example, 12 percent is expressed as .12.
  27678.  
  27679.   MIRR# uses the order of values within the array to interpret the order of
  27680.  payments and receipts. Be sure to enter your payment and receipt values in
  27681.  the correct sequence.
  27682.  
  27683.  Two other functions are related to  MIRR#:
  27684.    ■    IRR# returns the internal rate of return for an investment.
  27685.    ■    Rate# returns the interest rate per period of an annuity.
  27686.  
  27687.  
  27688.  To use  MIRR# in the QBX environment, use the FINANCER.QLB
  27689.  Quick library. To use  MIRR# outside of the QBX environment,
  27690.  link your program with the appropriate FINANC xx.LIB file.
  27691.  
  27692.  Depending on the compiler options you chose when you installed BASIC,
  27693.  one or more of the following files will be available:
  27694.  
  27695.  
  27696. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  27697.  Filename          Compiler options
  27698.  ────────────────────────────────────────────────────────────────────────────
  27699.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  27700.  FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  27701.  Filename          Compiler options
  27702.  ────────────────────────────────────────────────────────────────────────────
  27703. FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  27704.  FINANCEP.LIB      80x87 or emulator math; OS/2 protected mode
  27705.  FINANCAP.LIB      Alternate math; OS/2 protected mode
  27706.  
  27707.  
  27708.  
  27709.  
  27710.  The FINANC.BI header file contains the necessary function declarations for
  27711.  using the financial functions. For more information on using libraries, see
  27712.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  27713.  Libraries" in the  Programmer's Guide.
  27714.  
  27715.  See Also
  27716.  IRR#,  Rate#
  27717.  
  27718.  
  27719.  
  27720.  Month& Function
  27721.  
  27722.  Action
  27723.  Takes a date/time serial number and returns the month.
  27724.  
  27725.  Syntax
  27726.   Month& ( serial# )
  27727.  
  27728.  
  27729.  Remarks
  27730.  The  Month& function returns an integer between 1 and 12, inclusive, that
  27731.  represents the month corresponding to the argument.
  27732.  
  27733.  The argument  serial# is a serial number that represents a date and/or time.
  27734.  For more information, see the topic "Serial Numbers" in this section.
  27735.  
  27736.  To use  Month& in the QBX environment, use the DTFMTER.QLB Quick library. To
  27737.  use  Month& outside of the QBX environment, link your program with the
  27738.  appropriate DTFMT xx.LIB file. Depending on the compiler options you chose
  27739.  when you installed BASIC, one or more of the following files will be
  27740.  available:
  27741.  
  27742. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  27743.  Filename         Compiler options
  27744.  ────────────────────────────────────────────────────────────────────────────
  27745.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  27746.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  27747.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  27748.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  27749.  
  27750.  
  27751.  
  27752.  The DATIM.BI header file contains the necessary function declarations for
  27753.  using the date/time functions. For more information on using libraries, see
  27754.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  27755.  Libraries" in the  Programmer's Guide.
  27756.  
  27757.  See Also
  27758.   Day&,  Hour&,  Minute&,  Now#,  Second&, Serial Numbers,  Weekday&,  Year&
  27759.  
  27760.  
  27761.  
  27762.  Now# Function
  27763.  
  27764.  Action
  27765.  Returns a serial number that represents the current date and time according
  27766.  to your computer's system date and time.
  27767.  
  27768.  Syntax
  27769.   Now#
  27770.  
  27771.  
  27772.  Remarks
  27773.  For more information, see the topic "Serial Numbers" in this section.
  27774.  
  27775.  To use  Now# in the QBX environment, use the DTFMTER.QLB Quick library. To
  27776.  use  Now# outside of the QBX environment, link your program with the
  27777.  appropriate DTFMT xx.LIB file. Depending on the compiler options you chose
  27778.  when you installed BASIC, one or more of the following files will be
  27779.  available:
  27780.  
  27781. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  27782.  Filename         Compiler options
  27783.  ────────────────────────────────────────────────────────────────────────────
  27784.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  27785.  Filename         Compiler options
  27786.  ────────────────────────────────────────────────────────────────────────────
  27787.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  27788.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  27789.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  27790.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  27791.  
  27792.  
  27793.  
  27794.  The DATIM.BI header file contains the necessary function declarations for
  27795.  using the date/time functions. For more information on using libraries, see
  27796.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  27797.  Libraries" in the  Programmer's Guide.
  27798.  
  27799.  See Also
  27800.   Day&,  Hour&,  Minute&,  Month&,  Second&, Serial Numbers,  Weekday&,
  27801.  Year&
  27802.  
  27803.  
  27804.  Example
  27805.  
  27806.  The following example examines the current date and time information
  27807.  contained by the operating system and displays a formatted version of the
  27808.  date and time as returned by the  Now# function.
  27809.  
  27810.  To run this example, you must link it with the appropriate DTFMT xx.LIB file
  27811.  or use the DTFMTER.QLB Quick library. The following include files must also
  27812.  be present.
  27813.  
  27814.  ' $INCLUDE: 'DATIM.BI'
  27815.  ' $INCLUDE: 'FORMAT.BI'
  27816.  
  27817.  CLS
  27818.  PRINT "Today's date is "; FormatD$(Now#, "dd-mmm-yy"); "."
  27819.  PRINT "The current time is "; FormatD$(Now#, "hh:mm:ss AM/PM"); "."
  27820.  
  27821.  Output
  27822.  
  27823.  Today's date is 02-May-1989.
  27824.  The current time is 2:22:14 PM.
  27825.  
  27826.  
  27827.  
  27828.  
  27829.  NPer# Function
  27830.  
  27831.  Action
  27832.  Returns the number of periods for an annuity based on periodic, constant
  27833.  payments and a constant interest rate.
  27834.  
  27835.  Syntax
  27836.   NPer# ( rate#,  pmt#,  pv#,  fv#,  type%,  status%)
  27837.  
  27838.  
  27839.  Remarks
  27840.  An annuity is a series of constant cash payments made over a continuous
  27841.  period of time. An annuity can be a loan (such as a home mortgage) or an
  27842.  investment (such as a monthly savings plan).
  27843.  
  27844.  The NP er# function uses the following arguments:
  27845.  
  27846. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  27847.  Argument                                Description
  27848.  Argument                                Description
  27849.  ────────────────────────────────────────────────────────────────────────────
  27850.   rate#                                  The interest rate per period. For
  27851.                                          example, if you get a car loan at
  27852.                                          an annual rate of 10 percent and
  27853.                                          make monthly payments, the rate
  27854.                                          per period would be .10 divided by
  27855.                                          12, or .0083.
  27856.  
  27857.   pmt#                                   The payment to be made each period.
  27858.                                          It  usually contains principal and
  27859.                                          interest and does not change over
  27860.                                          the life of the annuity.
  27861.  
  27862.   pv#                                    The present value or a lump sum
  27863.                                          that a series of payments to be
  27864.                                          paid in the future is worth now.
  27865.                                          For example, when you borrow money
  27866.                                          to buy a car, the loan amount is
  27867.                                          the present value to the lender of
  27868.                                          the monthly car payments you will
  27869.  Argument                                Description
  27870.  ────────────────────────────────────────────────────────────────────────────
  27871.                                         the monthly car payments you will
  27872.                                          make.
  27873.  
  27874.   fv#                                    The future value or the cash
  27875.                                          balance you want to be attained
  27876.                                          sometime in the future after the
  27877.                                          last payment is made. The future
  27878.                                          value of a loan, for example is
  27879.                                          zero. As another example, if you
  27880.                                          think you will need $50,000 in 18
  27881.                                          years to pay for your child's
  27882.                                          education, the future value is
  27883.                                          $50,000.
  27884.  
  27885.   type%                                  An integer expression that
  27886.                                          indicates when payments are due.
  27887.                                          Use 0 as the value for  type% if
  27888.                                          payments are due ar the end of the
  27889.                                          period; use 1 if at the beginning
  27890.  Argument                                Description
  27891.  ────────────────────────────────────────────────────────────────────────────
  27892.                                         period; use 1 if at the beginning
  27893.                                          of the period.
  27894.  
  27895.   status%                                A BASIC variable that indicates
  27896.                                          whether calculation succeeded or
  27897.                                          failed. The value of the variable
  27898.                                          will be 0 if the calculation was
  27899.                                          successful, and 1 if it was not.
  27900.  
  27901.  
  27902.  
  27903.  
  27904.  
  27905.  Note
  27906.  For all arguments, cash you pay out, such as deposits to savings, is
  27907.  represented by negative numbers; cash you receive, such as dividend checks,
  27908.  is represented by positive numbers.
  27909.  
  27910.  
  27911.  A number of other functions are related to  NPer#:
  27912.    ■    FV# returns the the future value of an annuity.
  27913.    ■    IPmt# returns the interest payment for an annuity for a given period.
  27914.    ■    Pmt# returns the periodic total payment for an annuity.
  27915.    ■    PPmt# returns the principal payment for an annuity for a given
  27916.        period.
  27917.    ■    PV# returns the present value of an annuity.
  27918.    ■    Rate# returns the interest rate per period of an annuity.
  27919.  
  27920.  
  27921.  To use  NPer# in the QBX environment, use the FINANCER.QLB Quick library. To
  27922.  use  NPer# outside of the QBX environment, link your program with the
  27923.  appropriate FINANC xx.LIB file. Depending on the compiler options you chose
  27924.  when you installed BASIC, one or more of the following files will be
  27925.  available:
  27926.  
  27927.  
  27928. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  27929.  Filename          Compiler options
  27930.  ────────────────────────────────────────────────────────────────────────────
  27931.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  27932.  Filename          Compiler options
  27933.  ────────────────────────────────────────────────────────────────────────────
  27934.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  27935.  FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  27936.  FINANCEP.LIB      80x87 or emulator math; OS/2 protected mode
  27937.  FINANCAP.LIB      Alternate math; OS/2 protected mode
  27938.  
  27939.  
  27940.  
  27941.  
  27942.  The FINANC.BI header file contains the necessary function declarations for
  27943.  using the financial functions. For more information on using libraries, see
  27944.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  27945.  Libraries" in the  Programmer's Guide.
  27946.  
  27947.  See Also
  27948.   FV#,  IPmt#,  Pmt#,  PPmt#,  PV#,  Rate#
  27949.  
  27950.  
  27951.  
  27952.  NPV# Function
  27953.  
  27954.  Action
  27955.  Returns the net present value of an investment based on a series of periodic
  27956.  cash flows (payments and receipts) and a discount rate.
  27957.  
  27958.  Syntax
  27959.   NPV# ( rate#,  valuearray#( ),  valuecount%,  status%)
  27960.  
  27961.  
  27962.  Remarks
  27963.  The net present value of an investment is today's value of a future series
  27964.  of payments and receipts.
  27965.  
  27966.  The  NPV# function uses the following arguments:
  27967.  
  27968. ╓┌─────────────────────────────────────┌─────────────────────────────────────╖
  27969.  Argument                              Description
  27970.  ────────────────────────────────────────────────────────────────────────────
  27971.   rate#                                The discount rate over the length of
  27972.                                        the period, expressed as a decimal.
  27973.  
  27974.  Argument                              Description
  27975.  ────────────────────────────────────────────────────────────────────────────
  27976. 
  27977.   valuearray#( )                       An array of cash-flow values. The
  27978.                                        argument must contain at least one
  27979.                                        negative value (a payment) and one
  27980.                                        positive value (a receipt).
  27981.  
  27982.   valuecount%                          The total number of items in the
  27983.                                        cash-flow array.
  27984.  
  27985.   status%                              A BASIC variable that indicates
  27986.                                        whether calculation succeeded or
  27987.                                        failed. The value of the variable
  27988.                                        will be 0 if the calculation was
  27989.                                        successful, and 1 if it was not.
  27990.  
  27991.  
  27992.  
  27993.  
  27994.  
  27995.  Several other functions are related to  NPV#:
  27996.    ■    FV# returns the the future value of an annuity.
  27997.    ■    IRR# returns the internal rate of return for an investment.
  27998.    ■    PV# returns the present value of an annuity.
  27999.  
  28000.  
  28001.  To use  NPV# in the QBX environment, use the FINANCER.QLB Quick library. To
  28002.  use  NPV# outside of the QBX environment, link your program with the
  28003.  appropriate FINANCxx.LIB file. Depending on the compiler options you chose
  28004.  when you installed BASIC, one or more of the following files will be
  28005.  available:
  28006.  
  28007.  
  28008. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  28009.  Filename          Compiler options
  28010.  ────────────────────────────────────────────────────────────────────────────
  28011.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  28012.  FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  28013.  FINANCEP.LIB      80x87 or emulator math; OS/2 protected mode
  28014.  FINANCAP.LIB      Alternate math; OS/2 protected mode
  28015.  
  28016.  
  28017.  
  28018.  
  28019.  The FINANC.BI header file contains the necessary function declarations for
  28020.  using the financial functions. For more information on using libraries, see
  28021.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  28022.  Libraries" in the  Programmer's Guide.
  28023.  
  28024.  See Also
  28025.   FV#,  IRR#,  PV#
  28026.  
  28027.  
  28028.  
  28029.  Pmt# Function
  28030.  
  28031.  Action
  28032.  Returns the payment for an annuity based on periodic, constant payments and
  28033.  a constant interest rate.
  28034.  
  28035.  Syntax
  28036.   Pmt# ( rate#,  nper#,  pv#,  fv#,  type%,  status%)
  28037.  
  28038.  
  28039.  Remarks
  28040.  An annuity is a series of constant cash payments made over a continuous
  28041.  period of time. An annuity can be a loan (such as a home mortgage) or an
  28042.  investment (such as a monthly savings plan).
  28043.  
  28044.  The  Pmt# function uses the following arguments:
  28045.  
  28046. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  28047.  Argument                                Description
  28048.  ────────────────────────────────────────────────────────────────────────────
  28049.   rate#                                  The interest rate per period. For
  28050.                                          example, if you get a car loan at
  28051.                                          an annual rate of 10 percent and
  28052.                                          make monthly payments, the rate
  28053.                                          per period would be .10 divided by
  28054.                                          12, or .0083.
  28055.  
  28056.   nper#                                  The number of payment periods in
  28057.                                          the annuity. For example, if you
  28058.  Argument                                Description
  28059.  ────────────────────────────────────────────────────────────────────────────
  28060.                                         the annuity. For example, if you
  28061.                                          get a four-year car loan and make
  28062.                                          monthly payments, your loan has a
  28063.                                          total number of 4 times 12, or 48,
  28064.                                          payment periods.
  28065.  
  28066.   pv#                                    The present value or a lump sum
  28067.                                          that a series of payments to be
  28068.                                          paid in the future is worth now.
  28069.                                          For example, when you borrow money
  28070.                                          to buy a car, the loan amount is
  28071.                                          the present value to the lender of
  28072.                                          the monthly car payments you will
  28073.                                          make.
  28074.  
  28075.   fv#                                    The future value or the cash
  28076.                                          balance you want to be attained
  28077.                                          sometime in the future after the
  28078.                                          last payment is made. The future
  28079.  Argument                                Description
  28080.  ────────────────────────────────────────────────────────────────────────────
  28081.                                         last payment is made. The future
  28082.                                          value of a loan, for example is
  28083.                                          zero. As another example, if you
  28084.                                          think you will need $50,000 in 18
  28085.                                          years to pay for your child's
  28086.                                          education, the future value is
  28087.                                          $50,000.
  28088.  
  28089.   type%                                  An integer expression that
  28090.                                          indicates when payments are due.
  28091.                                          Use 0 as the value for  type% if
  28092.                                          payments are due at the end of the
  28093.                                          period; use 1 if due at the
  28094.                                          beginning of the period.
  28095.  
  28096.   status%                                A BASIC variable that indicates
  28097.                                          whether calculation succeeded or
  28098.                                          failed. The value of the variable
  28099.                                          will be 0 if the calculation was
  28100.  Argument                                Description
  28101.  ────────────────────────────────────────────────────────────────────────────
  28102.                                         will be 0 if the calculation was
  28103.                                          successful, and 1 if it was not.
  28104.  
  28105.  
  28106.  
  28107.  
  28108.  
  28109.  The arguments  rate# and  nper# must use consistent units. For example:
  28110.  
  28111.  Note
  28112.  For all arguments, cash you pay out, such as deposits to savings, is
  28113.  represented by negative numbers; cash you receive, such as dividend checks,
  28114.  is represented by positive numbers.
  28115.  
  28116.  A number of other functions are related to  Pmt#:
  28117.    ■    FV# returns the the future value of an annuity.
  28118.    ■    IPmt# returns the interest payment for an annuity for a given period.
  28119.    ■    NPer# returns the number of periods (payments) for an annuity.
  28120.    ■    PPmt# returns the principal payment for an annuity for a given
  28121.        period.
  28122.    ■    PV# returns the present value of an annuity.
  28123.    ■    Rate# returns the interest rate per period of an annuity.
  28124.  
  28125.  
  28126.  To use  Pmt# in the QBX environment, use the FINANCER.QLB Quick library. To
  28127.  use  Pmt# outside of the QBX environment, link your program with the
  28128.  appropriate FINANC xx.LIB file. Depending on the compiler options you chose
  28129.  when you installed BASIC, one or more of the following files will be
  28130.  available:
  28131.  
  28132.  
  28133. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  28134.  Filename          Compiler options
  28135.  ────────────────────────────────────────────────────────────────────────────
  28136.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  28137.  FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  28138.  FINANCEP.LIB      80x87 or emulator math; OS/2 protected mode
  28139.  FINANCAP.LIB      Alternate math; OS/2 protected mode
  28140.  
  28141.  
  28142.  
  28143.  
  28144.  The FINANC.BI header file contains the necessary function declarations for
  28145.  using the financial functions. For more information on using libraries, see
  28146.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  28147.  Libraries" in the  Programmer's Guide.
  28148.  
  28149.  See Also
  28150.   FV#,  IPmt#,  NPer#,  PPmt#,  PV#,  Rate#
  28151.  
  28152.  
  28153.  
  28154.  PPmt# Function
  28155.  
  28156.  Action
  28157.  Returns payment on the principal for a given period of an annuity based on
  28158.  periodic, constant payments and a constant interest rate.
  28159.  
  28160.  Syntax
  28161.   PPmt# ( rate#,  per#,  nper#,  pv#,  fv#,  type%,  status%)
  28162.  
  28163.  
  28164.  Remarks
  28165.  An annuity is a series of constant cash payments made over a continuous
  28166.  period of time. An annuity can be a loan (such as a home mortgage) or an
  28167.  investment (such as a monthly savings plan).
  28168.  
  28169.  The  PPmt# function uses the following arguments:
  28170.  
  28171. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  28172.  Argument                                Description
  28173.  ────────────────────────────────────────────────────────────────────────────
  28174.   rate#                                  The interest rate per period. For
  28175.                                          example, if you get a car loan at
  28176.                                          an annual rate of 10 percent and
  28177.                                          make monthly payments, the rate
  28178.                                          per period would be .10 divided by
  28179.                                          12, or .0083.
  28180.  
  28181.   per#                                   The payment period; must be
  28182.                                          between 1 and  nper#, inclusive.
  28183.                                          If it is not in that range, BASIC
  28184.  Argument                                Description
  28185.  ────────────────────────────────────────────────────────────────────────────
  28186.                                         If it is not in that range, BASIC
  28187.                                          generates the error message
  28188.                                          Overflow.
  28189.  
  28190.   nper#                                  The number of payment periods in
  28191.                                          the annuity. For example, if you
  28192.                                          get a four-year car loan and make
  28193.                                          monthly payments, your loan has a
  28194.                                          total number of 4 times 12, or 48,
  28195.                                          payment periods.
  28196.  
  28197.   pv#                                    The present value or a lump sum
  28198.                                          that a series of payments to be
  28199.                                          paid in the future is worth now.
  28200.                                          For example, when you borrow money
  28201.                                          to buy a car, the loan amount is
  28202.                                          the present value to the lender of
  28203.                                          the monthly car payments you will
  28204.                                          make.
  28205.  Argument                                Description
  28206.  ────────────────────────────────────────────────────────────────────────────
  28207.                                         make.
  28208.  
  28209.   fv#                                    The future value or the cash
  28210.                                          balance you want to be attained
  28211.                                          sometime in the future after the
  28212.                                          last payment is made. The future
  28213.                                          value of a loan, for example is
  28214.                                          zero. As another example, if you
  28215.                                          think you will need $50,000 in 18
  28216.                                          years to pay for your child's
  28217.                                          education, the future value is
  28218.                                          $50,000.
  28219.  
  28220.   type%                                  An integer expression that
  28221.                                          indicates when payments are due.
  28222.                                          Use 0 as the value for  type% if
  28223.                                          payments are due at the end of the
  28224.                                          period; use 1 if due at the
  28225.                                          beginning of the period.
  28226.  Argument                                Description
  28227.  ────────────────────────────────────────────────────────────────────────────
  28228.                                         beginning of the period.
  28229.  
  28230.   status%                                A BASIC variable that indicates
  28231.                                          whether calculation succeeded or
  28232.                                          failed. The value of the variable
  28233.                                          will be 0 if the calculation was
  28234.                                          successful, and 1 if it was not.
  28235.  
  28236.  
  28237.  
  28238.  
  28239.  
  28240.  The arguments  rate# and  nper# must use consistent units.
  28241.  
  28242.  
  28243.  Note
  28244.  
  28245.  For all arguments, cash you pay out, such as deposits to savings, is
  28246.  represented by negative numbers; cash you receive, such as dividend checks,
  28247.  is represented by positive numbers.
  28248.  
  28249.  A number of other functions are related to  PPmt#:
  28250.    ■    FV# returns the the future value of an annuity.
  28251.    ■    IPmt# returns the interest payment for an annuity for a given period.
  28252.    ■    NPer# returns the number of periods (payments) for an annuity.
  28253.    ■    Pmt# returns the periodic total payment for an annuity.
  28254.    ■    PV# returns the present value of an annuity.
  28255.    ■    Rate# returns the interest rate per period of an annuity.
  28256.  
  28257.  
  28258.  To use  PPmt# in the QBX environment, use the FINANCER.QLB Quick library. To
  28259.  use  PPmt# outside of the QBX environment, link your program with the
  28260.  appropriate FINANC xx.LIB file. Depending on the compiler options you chose
  28261.  when you installed BASIC, one or more of the following files will be
  28262.  available:
  28263.  
  28264.  
  28265. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  28266.  Filename          Compiler options
  28267.  ────────────────────────────────────────────────────────────────────────────
  28268.  Filename          Compiler options
  28269.  ────────────────────────────────────────────────────────────────────────────
  28270.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  28271.  FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  28272.  FINANCEP.LIB      80x87 or emulator math; OS/2 protected mode
  28273.  FINANCAP.LIB      Alternate math; OS/2 protected mode
  28274.  
  28275.  
  28276.  
  28277.  
  28278.  The FINANC.BI header file contains the necessary function declarations for
  28279.  using the financial functions. For more information on using libraries, see
  28280.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  28281.  Libraries" in the  Programmer's Guide.
  28282.  
  28283.  See Also
  28284.   FV#,  IPmt#,  NPer#,  Pmt#,  PV#,  Rate#
  28285.  
  28286.  
  28287.  
  28288.  PV# Function
  28289.  
  28290.  Action
  28291.  Returns the present value, or lump sum, that a series of payments to be paid
  28292.  in the future is worth now.
  28293.  
  28294.  Syntax
  28295.   PV# ( rate#,  nper#,  pmt#,  fv#,  type%,  status%)
  28296.  
  28297.  
  28298.  Remarks
  28299.  The  PV# function uses the following arguments:
  28300.  
  28301. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  28302.  Argument                                Description
  28303.  ────────────────────────────────────────────────────────────────────────────
  28304.   rate#                                  The interest rate per period. For
  28305.                                          example, if you get a car loan at
  28306.                                          an annual rate of 10 percent and
  28307.                                          make monthly payments, the rate
  28308.                                          per period would be .10 divided by
  28309.                                          12, or .0083.
  28310.  Argument                                Description
  28311.  ────────────────────────────────────────────────────────────────────────────
  28312.                                         12, or .0083.
  28313.  
  28314.   nper#                                  The number of payment periods in
  28315.                                          the annuity. For example, if you
  28316.                                          get a four-year car loan and make
  28317.                                          monthly payments, your loan has a
  28318.                                          total number of 4 times 12, or 48,
  28319.                                          payment periods.
  28320.  
  28321.   pmt#                                   The payment to be made each period.
  28322.                                          It usually contains principal and
  28323.                                          interest and does not change over
  28324.                                          the life of the annuity.
  28325.  
  28326.   fv#                                    The future value or the cash
  28327.                                          balance you want to be attained
  28328.                                          sometime in the future after the
  28329.                                          last payment is made. The future
  28330.                                          value of a loan, for example is
  28331.  Argument                                Description
  28332.  ────────────────────────────────────────────────────────────────────────────
  28333.                                         value of a loan, for example is
  28334.                                          zero. As another example, if you
  28335.                                          think you will need $50,000 in 18
  28336.                                          years to pay for your child's
  28337.                                          education, the future value is
  28338.                                          $50,000.
  28339.  
  28340.   type%                                  An integer expression that
  28341.                                          indicates when payments are due.
  28342.                                          Use 0 as the value for  type% if
  28343.                                          payments are due at the end of the
  28344.                                          period; use 1 if due at the
  28345.                                          beginning of the period.
  28346.  
  28347.   status%                                A BASIC variable that indicates
  28348.                                          whether calculation succeeded or
  28349.                                          failed. The value of the variable
  28350.                                          will be 0 if the calculation was
  28351.                                          successful, and 1 if it was not.
  28352.  Argument                                Description
  28353.  ────────────────────────────────────────────────────────────────────────────
  28354.                                         successful, and 1 if it was not.
  28355.  
  28356.  
  28357.  
  28358.  
  28359.  Two other functions are related to  PV#:
  28360.    ■    IPmt# returns the interest payment for an annuity for a given period.
  28361.    ■    PPmt# returns the principal payment for an annuity for a given
  28362.        period.
  28363.  
  28364.  
  28365.  To use  PV# in the QBX environment, use the FINANCER.QLB Quick library. To
  28366.  use  PV# outside of the QBX environment, link your program with the
  28367.  appropriate FINANC xx.LIB file. Depending on the compiler options you chose
  28368.  when you installed BASIC, one or more of the following files will be
  28369.  available:
  28370.  
  28371. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  28372.  Filename          Compiler options
  28373.  Filename          Compiler options
  28374.  ────────────────────────────────────────────────────────────────────────────
  28375.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  28376.  FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  28377.  FINANCEP.LIB      80x87 or emulator math; OS/2 protected mode
  28378.  FINANCAP.LIB      Alternate math; OS/2 protected mode
  28379.  
  28380.  
  28381.  
  28382.  
  28383.  The FINANC.BI header file contains the necessary function declarations for
  28384.  using the financial functions. For more information on using libraries, see
  28385.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  28386.  Libraries" in the  Programmer's Guide.
  28387.  
  28388.  See Also
  28389.   IPmt#,  PPmt#
  28390.  
  28391.  
  28392.  
  28393.  
  28394.  Rate# Function
  28395.  
  28396.  Action
  28397.  Returns the interest rate per period for an annuity.
  28398.  
  28399.  Syntax
  28400.   Rate# ( nper#,  mt#,  pv#,  fv#,  type%,  guess#,  status%)
  28401.  
  28402.  
  28403.  Remarks
  28404.  An annuity is a series of constant cash payments made over a continuous
  28405.  period of time. An annuity can be a loan (such as a home mortgage) or an
  28406.  investment (such as a monthly savings plan).
  28407.  
  28408.  The  Rate# function uses the following arguments:
  28409.  
  28410. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  28411.  Argument                                Description
  28412.  ────────────────────────────────────────────────────────────────────────────
  28413.   nper#                                  The number of payment periods in
  28414.                                          the annuity. For example, if you
  28415.  Argument                                Description
  28416.  ────────────────────────────────────────────────────────────────────────────
  28417.                                         the annuity. For example, if you
  28418.                                          get a four-year car loan and make
  28419.                                          monthly payments, your loan has a
  28420.                                          total number of 4 times 12, or 48,
  28421.                                          payment periods.
  28422.  
  28423.   pmt#                                   The payment to be made each period.
  28424.                                          It usually contains principal and
  28425.                                          interest and does not change over
  28426.                                          the life of the annuity.
  28427.  
  28428.   pv#                                    The present value or a lump sum
  28429.                                          that a series of payments to be
  28430.                                          paid in the future is worth now.
  28431.                                          For example, when you borrow money
  28432.                                          to buy a car, the loan amount is
  28433.                                          the present value to the lender of
  28434.                                          the monthly car payments you will
  28435.                                          make.
  28436.  Argument                                Description
  28437.  ────────────────────────────────────────────────────────────────────────────
  28438.                                         make.
  28439.  
  28440.   fv#                                    The future value or the cash
  28441.                                          balance you want to be attained
  28442.                                          sometime in the future after the
  28443.                                          last payment is made. The future
  28444.                                          value of a loan, for example is
  28445.                                          zero. As another example, if you
  28446.                                          think you will need $50,000 in 18
  28447.                                          years to pay for your child's
  28448.                                          education, the future value is
  28449.                                          $50,000.
  28450.  
  28451.   type%                                  An integer expression that
  28452.                                          indicates when payments are due.
  28453.                                          Use 0 as the value for  type% if
  28454.                                          payments are due at the end of the
  28455.                                          period; use 1 if due at the
  28456.                                          beginning of the period.
  28457.  Argument                                Description
  28458.  ────────────────────────────────────────────────────────────────────────────
  28459.                                         beginning of the period.
  28460.  
  28461.   guess#                                 A value you guess is close to the
  28462.                                          result of  Rate#.
  28463.  
  28464.   status%                                A BASIC variable that indicates
  28465.                                          whether calculation succeeded or
  28466.                                          failed. The value of the variable
  28467.                                          will be 0 if the calculation was
  28468.                                          successful, and 1 if it was not.
  28469.  
  28470.  
  28471.  
  28472.  
  28473.  
  28474.  Note%
  28475.  For all arguments, cash you pay out, such as deposits to savings, is
  28476.  represented by negative numbers; cash you receive, such as dividend checks,
  28477.  is represented by positive numbers.
  28478.  
  28479.   Rate# is calculated by iteration. Starting with
  28480.  the value of  guess#,  Rate# cycles
  28481.  through the calculation until the result is accurate within .00001 percent.
  28482.  If after 20 tries it can't find a result that works,  Rate
  28483.  # returns a status of 1.  In most cases you can assume the
  28484.   guess# argument to be 0.1 (10 percent). However, if Rate%# returns a status
  28485.  
  28486.  
  28487.  A number of other functions are related to  Rate#:
  28488.    ■    FV# returns the the future value of an annuity.
  28489.    ■    IPmt# returns the interest payment for an annuity for a given period.
  28490.    ■    NPer# returns the number of periods (payments) for an annuity.
  28491.    ■    Pmt# returns the periodic total payment for an annuity.
  28492.    ■    PPmt# returns the principal payment for an annuity for a given
  28493.        period.
  28494.    ■    PV# returns the present value of an annuity.
  28495.  
  28496.  
  28497.  To use  Rate# in the QBX environment, use the FINANCER.QLB Quick library. To
  28498.  use  Rate# outside of the QBX environment, link your program with the
  28499.  appropriate FINANCxx.LIB file. Depending on the compiler options you chose
  28500.  when you installed BASIC, one or more of the following files will be
  28501.  available:
  28502.  
  28503.  
  28504. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  28505.  Filename          Compiler options
  28506.  ────────────────────────────────────────────────────────────────────────────
  28507.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  28508.  FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  28509.  FINANCEP.LIB      80x87 or emulator math; OS/2 protected mode
  28510.  FINANCAP.LIB      Alternate math; OS/2 protected mode
  28511.  
  28512.  
  28513.  
  28514.  
  28515.  The FINANC.BI header file contains the necessary function declarations for
  28516.  using the financial functions. For more information on using libraries, see
  28517.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  28518.  Libraries" in the  Programmer's Guide.
  28519.  
  28520.  See Also
  28521.   FV#,  IPmt#,  NPer#,  Pmt#,  PPmt#,  PV#
  28522.  
  28523.  
  28524.  
  28525.  Second& Function
  28526.  
  28527.  Action
  28528.  Takes a date/time serial number and returns the second.
  28529.  
  28530.  Syntax
  28531.   Second& ( serial#)
  28532.  
  28533.  
  28534.  Remarks
  28535.  The  Second& function returns an integer between 0 and 59, inclusive, that
  28536.  represents the second corresponding to the argument.
  28537.  
  28538.  The argument serial#  is a serial number that represents a date and/or time.
  28539.  For more information, see the topic "Serial Numbers" in this section.
  28540.  
  28541.  To use  Second& in the QBX environment, use the DTFMTER.QLB Quick library.
  28542.  To use  Second& outside of the QBX environment, link your program with the
  28543.  appropriate DTFMT xx.LIB file. Depending on the compiler options you chose
  28544.  when you installed BASIC, one or more of the following files will be
  28545.  available:
  28546.  
  28547. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  28548.  Filename         Compiler options
  28549.  ────────────────────────────────────────────────────────────────────────────
  28550.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  28551.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  28552.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  28553.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  28554.  
  28555.  
  28556.  
  28557.  
  28558.  The DATIM.BI header file contains the necessary function declarations for
  28559.  using the date/time functions. For more information on using libraries, see
  28560.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  28561.  Libraries" in the  Programmer's Guide.
  28562.  
  28563.  See Also
  28564.   Day&,  Hour&,  Minute&,  Month&,  Now#, Serial Numbers,  Weekday&,  Year&
  28565.  
  28566.  
  28567.  
  28568.  Serial Numbers
  28569.  
  28570.  A serial number is a date/time code used by BASIC to represent dates and
  28571.  times between
  28572.                        Jan. 1, 1753 and Dec. 31, 2078.
  28573.  
  28574.  
  28575.  Serial-Number Format
  28576.  Numbers to the left of the decimal point represent the date; numbers to the
  28577.  right of the decimal point represent the time. For example:
  28578.  
  28579. ╓┌────────────────────────┌──────────────────────────────────────────────────╖
  28580.  Serial number            Date and time represented
  28581.  ────────────────────────────────────────────────────────────────────────────
  28582.  20323.25                 August 22, 1955  6:00 A.M.
  28583.  Serial number            Date and time represented
  28584.  ────────────────────────────────────────────────────────────────────────────
  28585.  20323.25                 August 22, 1955  6:00 A.M.
  28586.  20324.25                 August 23, 1955  6:00 A.M.
  28587.  367.5                    January 1, 1901  12:00 P.M.
  28588.  367.75                   January 2, 1901  6:00 P.M.
  28589.  
  28590.  
  28591.  
  28592.  A serial number with no fractional part represents a date only. A serial
  28593.  number with only a fractional part represents a time only.
  28594.  
  28595.  The date portion of the serial number (to the left of the decimal point) can
  28596.  represent dates ranging from January 1, 1753, through December 31, 2078.
  28597.  Dates before December 30, 1899 are represented by negative numbers; dates
  28598.  after December 30, 1899 are represented by positive numbers:
  28599.  
  28600. ╓┌───────────────────────────┌───────────────────────────────────────────────╖
  28601.  Serial number               Date represented
  28602.  ────────────────────────────────────────────────────────────────────────────
  28603.  -1                          December 29, 1899
  28604.  Serial number               Date represented
  28605.  ────────────────────────────────────────────────────────────────────────────
  28606.  -1                          December 29, 1899
  28607.   0                          December 30, 1899
  28608.   1                          December 31, 1899
  28609.   2                          January 1, 1900
  28610.  
  28611.  
  28612.  
  28613.  The time portion of the serial number (to the right of the decimal point)
  28614.  can represent times that range from 0 (12:00:00 A.M.) to .99999 (11:59:59
  28615.  P.M. or 23:59:59).
  28616.  
  28617.  
  28618.  
  28619.  SetFormatCC Routine
  28620.  
  28621.  Action
  28622.  Sets the country code for the  Format X $ functions.
  28623.  
  28624.  Syntax
  28625.   SetFormatCC ( countrycode%)
  28626.  
  28627.  
  28628.  Remarks
  28629.  The argument  countrycode% is the international telephone dialing prefix for
  28630.  the country chosen as the target audience when using the  Format X $
  28631.  functions.
  28632.  
  28633.  The only reason to use  SetFormatCC is to change what the  Format X $
  28634.  functions expect as thousands-separator and decimal-point formatting
  28635.  characters.
  28636.  
  28637.  The default setting for the country code is the United States (1). If you
  28638.  set the country code to France (33), the following statement would display
  28639.  the number 1,000 (U.S.) as 1.000,00:
  28640.  
  28641.  PRINT FormatD$ (1000, "#.##0,00")
  28642.  The format you use with the  Format X $ functions must be compatible with
  28643.  the current country code in order for formatted numbers to display properly.
  28644.  
  28645.  If you set the country code to one of the following countries, the  Format X
  28646.  $ functions expect alternative formatting characters: Austria, Belgium,
  28647.  Brazil, Denmark, France, Germany, Italy, Netherlands, Norway, Spain, Sweden,
  28648.  or Switzerland. Canada uses one country code for French Canada (2) and
  28649.  another for the remainder of Canada (1).
  28650.  
  28651.  To use  SetFormatCC in the QBX environment, use the DTFMTER.QLB Quick
  28652.  library. To use  SetFormatCC outside of the QBX environment, link your
  28653.  program with the appropriate DTFMT xx.LIB file. Depending on the compiler
  28654.  options you chose when you installed BASIC, one or more of the following
  28655.  files will be available:
  28656.  
  28657. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  28658.  Filename         Compiler options
  28659.  ────────────────────────────────────────────────────────────────────────────
  28660.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  28661.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  28662.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  28663.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  28664.  
  28665.  
  28666.  
  28667.  
  28668.  The FORMAT.BI header file contains the necessary function declarations for
  28669.  using the formatting functions. For more information on using libraries, see
  28670.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  28671.  Libraries" in the  Programmer's Guide.
  28672.  
  28673.  See Also
  28674.   Format X $;  StringAddress Routine,  StringLength Routine (in Part 1).
  28675.  
  28676.  
  28677.  
  28678.  SLN# Function
  28679.  
  28680.  Action
  28681.  Returns straight-line depreciation of an asset for a single period.
  28682.  
  28683.  Syntax
  28684.   SLN# ( cost#,  salvage#,  life#,  status%)
  28685.  
  28686.  
  28687.  Remarks
  28688.  The  SLN# function uses the following arguments:
  28689.  
  28690. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  28691.  Argument                                Description
  28692.  ────────────────────────────────────────────────────────────────────────────
  28693.   cost#                                  The initial cost of the asset.
  28694.  
  28695.   salvage#                               The value at the end of the useful
  28696.                                          life of the asset.
  28697.  
  28698.   life#                                  The useful life of the asset (or
  28699.                                          the number of periods over which
  28700.                                          the asset is being depreciated).
  28701.  
  28702.   status%                                A BASIC variable that indicates
  28703.                                          whether calculation succeeded or
  28704.                                          failed. The value of the variable
  28705.                                          will be 0 if the calculation was
  28706.                                          successful, and 1 if it was not.
  28707.  
  28708.  
  28709.  
  28710.  
  28711.  
  28712.  To use  SLN# in the QBX environment, use the FINANCER.QLB Quick library. To
  28713.  use  SLN# outside of the QBX environment, link your program with the
  28714.  appropriate FINANC xx.LIB file. Depending on the compiler options you chose
  28715.  when you installed BASIC, one or more of the following files will be
  28716.  available:
  28717.  
  28718. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  28719.  Filename          Compiler options
  28720.  ────────────────────────────────────────────────────────────────────────────
  28721.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  28722.  FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  28723.  FINANCEP.LIB      80x87 or emulator math; OS/2 protected mode
  28724.  FINANCAP.LIB      Alternate math; OS/2 protected mode
  28725.  
  28726.  
  28727.  
  28728.  
  28729.  The FINANC.BI header file contains the necessary function declarations for
  28730.  using the financial functions. For more information on using libraries, see
  28731.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  28732.  Libraries" in the  Programmer's Guide.
  28733.  
  28734.  See Also
  28735.   DDB#,  SYD#
  28736.  
  28737.  
  28738.  
  28739.  
  28740.  SYD# Function
  28741.  
  28742.  Action
  28743.  Returns the sum-of-years' digits depreciation of an asset for a specified
  28744.  period.
  28745.  
  28746.  Syntax
  28747.   SYD# ( cost#,  salvage#,  life#,  period#,  status%)
  28748.  
  28749.  
  28750.  Remarks
  28751.  The  SYD# function uses the following arguments:
  28752.  
  28753. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  28754.  Argument                                Description
  28755.  ────────────────────────────────────────────────────────────────────────────
  28756.   cost#                                  The initial cost of the asset.
  28757.  
  28758.   salvage#                               The value at the end of the useful
  28759.                                          life of the asset.
  28760.  
  28761.   life#                                  The useful life of the asset (or
  28762.                                          the number of periods over which
  28763.                                          the asset is being depreciated).
  28764.  
  28765.   period#                                Period for which asset
  28766.                                          depreciation is desired.
  28767.  
  28768.   status%                                A BASIC variable that indicates
  28769.                                          whether calculation succeeded or
  28770.                                          failed. The value of the variable
  28771.                                          will be 0 if the calculation was
  28772.  Argument                                Description
  28773.  ────────────────────────────────────────────────────────────────────────────
  28774.                                         will be 0 if the calculation was
  28775.                                          successful, and 1 if it was not.
  28776.  
  28777.  
  28778.  
  28779.  
  28780.  The arguments  life# and  period# must use the same units. For example, if
  28781.  life# is given in months,  period# also must be given in months.
  28782.  
  28783.  To use  SYD# in the QBX environment, use the FINANCER.QLB Quick library. To
  28784.  use  SYD# outside of the QBX environment, link your program with the
  28785.  appropriate FINANC xx.LIB file. Depending on the compiler options you chose
  28786.  when you installed BASIC, one or more of the following files will be
  28787.  available:
  28788.  
  28789. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  28790.  Filename          Compiler options
  28791.  ────────────────────────────────────────────────────────────────────────────
  28792.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  28793.  Filename          Compiler options
  28794.  ────────────────────────────────────────────────────────────────────────────
  28795.  FINANCER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  28796.  FINANCAR.LIB      Alternate math; DOS or OS/2 real mode
  28797.  FINANCEP.LIB      80x87 or emulator math; OS/2 protected mode
  28798.  FINANCAP.LIB      Alternate math; OS/2 protected mode
  28799.  
  28800.  
  28801.  
  28802.  The FINANC.BI header file contains the necessary function declarations for
  28803.  using the financial functions. For more information on using libraries, see
  28804.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  28805.  Libraries" in the  Programmer's Guide.
  28806.  
  28807.  See Also
  28808.   DDB#,  SLN#
  28809.  
  28810.  
  28811.  
  28812.  
  28813.  TimeSerial# Function
  28814.  
  28815.  Action
  28816.  Returns a serial number that represents the time of the arguments.
  28817.  
  28818.  Syntax
  28819.   TimeSerial# ( hour%,  minute%,  second%)
  28820.  
  28821.  
  28822.  Remarks
  28823.  The  TimeSerial# function uses the following arguments:
  28824.  
  28825. ╓┌──────────┌────────────────────────────────────────────────────────────────╖
  28826.  Argument   Description
  28827.  ────────────────────────────────────────────────────────────────────────────
  28828.   hour%     An hour between 0 (12:00 A.M.) and 23 (11:00 P.M.), inclusive.
  28829.   minute%   A minute between 0 and 59, inclusive.
  28830.   second%   A second between 0 and 59, inclusive.
  28831.  
  28832.  
  28833.  
  28834.  You can use negative numbers as arguments, as long as the resulting serial
  28835.  number is positive. For example, to find the serial number for the time 50
  28836.  seconds before 2:00:02, you could use:
  28837.  
  28838.  TimeSerial#(2,0,2-50)
  28839.  For more information, see the topic "Serial Numbers" in this section.
  28840.  
  28841.  To use  TimeSerial# in the QBX environment, use the DTFMTER.QLB Quick
  28842.  library. To use  TimeSerial# outside of the QBX environment, link your
  28843.  program with the appropriate DTFMT xx.LIB file. Depending on the compiler
  28844.  options you chose when you installed BASIC, one or more of the following
  28845.  files will be available:
  28846.  
  28847. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  28848.  Filename         Compiler options
  28849.  ────────────────────────────────────────────────────────────────────────────
  28850.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  28851.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  28852.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  28853.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  28854.  
  28855.  
  28856.  
  28857.  The DATIM.BI header file contains the necessary function declarations for
  28858.  using the date/time functions. For more information on using libraries, see
  28859.  "Creating and Using Quick Libraries" and "Using LINK and LIB" in the
  28860.  Programmer's Guide.
  28861.  
  28862.  See Also
  28863.   Hour&,  Minute&,  Now#,  Second&, Serial Numbers,  TimeValue#
  28864.  
  28865.  Example
  28866.  The following example calculates the time between now and midnight tonight.
  28867.  The results of the calculations are shown as a total number of seconds, as a
  28868.  combination of hours, minutes, and seconds, and also as a standard time
  28869.  format. The time information is displayed using the  TimeValue#,
  28870.  TimeSerial#,  Hour&,  Minute&, and  Second& functions.
  28871.  
  28872.  To run this example, you must link it with the appropriate DTFMT xx.LIB file
  28873.  or use the DTFMTER.QLB Quick library. The following include files must also
  28874.  be present.
  28875.  
  28876.  ' $INCLUDE: 'DATIM.BI'
  28877.  ' $INCLUDE: 'FORMAT.BI'
  28878.  
  28879.  ' Get a time value for midnight tonight -1 second.
  28880.  Midnight# = TimeValue#("23:59:59")
  28881.  
  28882.  ' Get a time value for right now.
  28883.  Instant# = Now#
  28884.  
  28885.  ' Get the difference in hours, minutes, seconds.
  28886.  HourDiff% = Hour&(Midnight#) - Hour&(Instant#)
  28887.  MinuteDiff% = Minute&(Midnight#) - Minute&(Instant#)
  28888.  
  28889.  ' Add in the odd second between 23:59:59 and midnight.
  28890.  SecondDiff% = Second&(Midnight#) - Second&(Instant#) + 1
  28891.  ' Adjust so that seconds and minutes are less than 60.
  28892.  IF SecondDiff% = 60 THEN
  28893.  MinuteDiff% = MinuteDiff% + 1
  28894.  SecondDiff% = 0
  28895.  END IF
  28896.  
  28897.  IF MinuteDiff% = 60 THEN
  28898.  HourDiff% = HourDiff% + 1
  28899.  MinuteDiff% = 0
  28900.  END IF
  28901.  
  28902.  ' Calculate seconds between now and midnight.
  28903.  TotalMinDiff# = (HourDiff% * 60) + MinuteDiff%
  28904.  TotalSecDiff# = (TotalMinDiff# * 60) + SecondDiff%
  28905.  ' Put the difference back into a standard time format.
  28906.  TotalDiff# = TimeSerial#(HourDiff%, MinuteDiff%, SecondDiff%)
  28907.  ' Display results.
  28908.  CLS
  28909.  PRINT "There are a total of"; TotalSecDiff#; "seconds until midnight."
  28910.  PRINT "That translates to"; HourDiff%; "hours,"; MinuteDiff%;
  28911.  PRINT "minutes, and"; SecondDiff%; "seconds."
  28912.  PRINT
  28913.  PRINT "The difference can also be expressed in standard time notation:"
  28914.  PRINT FormatD$(TotalDiff#, "hh:mm:ss")
  28915.  
  28916.  
  28917.  
  28918.  TimeValue# Function
  28919.  
  28920.  Action
  28921.  Returns a serial number that represents the time of the argument.
  28922.  
  28923.  Syntax
  28924.   TimeValue# ( time$)
  28925.  
  28926.  
  28927.  Remarks
  28928.  The argument  time$ is a time between 0:00:00 (12:00:00 A.M.) and 23:59:59
  28929.  (11:59:59 P.M.), inclusive. Time can be entered as "2:24PM" or "14:24".
  28930.  
  28931.  Any date information used in  time$ is ignored.
  28932.  
  28933.  For more information, see the topic "Serial Numbers" in this section.
  28934.  
  28935.  To use  TimeValue# in the QBX environment, use the DTFMTER.QLB Quick
  28936.  library. To use  TimeValue# outside of the QBX environment, link your
  28937.  program with the appropriate DTFMT xx.LIB file. Depending on the compiler
  28938.  options you chose when you installed BASIC, one or more of the following
  28939.  files will be available:
  28940.  
  28941. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  28942.  Filename         Compiler options
  28943.  ────────────────────────────────────────────────────────────────────────────
  28944.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  28945.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  28946.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  28947.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  28948.  
  28949.  
  28950.  
  28951.  The DATIM.BI header file contains the necessary function declarations for
  28952.  using the date/time functions. For more information on using libraries, see
  28953.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  28954.  Libraries" in the  Programmer's Guide.
  28955.  
  28956.  See Also
  28957.   Hour&,  Minute&,  Now#,  Second&, Serial Numbers,  TimeSerial#,  Year&
  28958.  
  28959.  
  28960.  
  28961.  Weekday& Function
  28962.  
  28963.  Action
  28964.  Takes a date-time serial number and returns the day of the week.
  28965.  
  28966.  Syntax
  28967.   Weekday& ( serial# )
  28968.  
  28969.  
  28970.  Remarks
  28971.  The  Weekday& function returns an integer between 1 (Sunday) and 7
  28972.  (Saturday) that represents the day of the week corresponding to the
  28973.  argument.
  28974.  
  28975.  The argument  serial# is a serial number that represents a date and/or time.
  28976.  For more information, see the topic "Serial Numbers" in this section.
  28977.  
  28978.  To use  Weekday&  in the QBX environment, use the DTFMTER.QLB Quick library.
  28979.  To use  Weekday& outside of the QBX environment, link your program with the
  28980.  appropriate DTFMT xx.LIB file. Depending on the compiler options you chose
  28981.  when you installed BASIC, one or more of the following files will be
  28982.  available:
  28983.  
  28984. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  28985.  Filename         Compiler options
  28986.  ────────────────────────────────────────────────────────────────────────────
  28987.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  28988.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  28989.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  28990.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  28991.  
  28992.  
  28993.  
  28994.  The DATIM.BI header file contains the necessary function declarations for
  28995.  using the date/time functions. For more information on using libraries, see
  28996.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  28997.  Libraries" in the  Programmer's Guide.
  28998.  
  28999.  See Also
  29000.   Day&,  Hour&,  Minute&,  Month&,  Now#,  Second&,  Year&
  29001.  
  29002.  
  29003.  
  29004.  Year& Function
  29005.  
  29006.  Action
  29007.  Takes a date-time serial number and returns the year.
  29008.  
  29009.  Syntax
  29010.   Year& ( serial# )
  29011.  
  29012.  
  29013.  Remarks
  29014.  The  Year& function returns an integer between 1753 and 2078, inclusive,
  29015.  that represents the year corresponding to the argument.
  29016.  
  29017.  The argument  serial# is a serial number that represents a date and/or time.
  29018.  For more information, see the topic "Serial Numbers" in this section.
  29019.  
  29020.  To use  Year& in the QBX environment, use the DTFMTER.QLB Quick library. To
  29021.  use  Year& outside of the QBX environment, link your program with the
  29022.  appropriate DTFMT xx.LIB file. Depending on the compiler options you chose
  29023.  when you installed BASIC, one or more of the following files will be
  29024.  available:
  29025.  
  29026. ╓┌────────────────┌──────────────────────────────────────────────────────────╖
  29027.  Filename         Compiler options
  29028.  ────────────────────────────────────────────────────────────────────────────
  29029.  DTFMTER.LIB      80x87 or emulator math; DOS or OS/2 real mode
  29030.  DTFMTAR.LIB      Alternate math; DOS or OS/2 real mode
  29031.  DTFMTEP.LIB      80x87 or emulator math; OS/2 protected mode
  29032.  DTFMTAP.LIB      Alternate math; OS/2 protected mode
  29033.  
  29034.  
  29035.  
  29036.  The DATIM.BI header file contains the necessary function declarations for
  29037.  using the date/time functions. For more information on using libraries, see
  29038.  Chapter 18, "Using LINK and LIB" and Chapter 19, "Creating and Using Quick
  29039.  Libraries" in the  Programmer's Guide.
  29040.  
  29041.  See Also
  29042.   Day&,  Hour&,  Minute&,  Month&,  Now#,  Second&, Serial Numbers
  29043.  
  29044.  a
  29045.   Toolbox Summary Tables
  29046.  
  29047.  
  29048.  
  29049.  The following groups are summarized here:
  29050.  *    Matrix Math Function procedures
  29051.  *    Presentation Graphics Sub and Function procedures
  29052.  *    Font SUB and Function procedures
  29053.  *    User Interface SUB and Function procedures
  29054.  -    Menu
  29055.  -    Window
  29056.  -    Mouse
  29057.  -    General
  29058.  
  29059.  
  29060.  Matrix Math Function Procedures
  29061.  
  29062.  *    I is integer.
  29063.  *    L is long integer.
  29064.  *    S is single-precision floating point.
  29065.  *    D is double-precision floating point.
  29066.  *    C is currency.
  29067.  
  29068.  
  29069.  Addition
  29070.  --------
  29071.  MatAddI%
  29072.  MatAddL%
  29073.  MatAddS%
  29074.  MatAddD%
  29075.  MatAddC%
  29076.  Finds the sum of two matrixes whose row and column dimensions are identical.
  29077.  
  29078.  
  29079.  Subtraction
  29080.  -----------
  29081.  MatSubI%
  29082.  MatSubL%
  29083.  MatSubS%
  29084.  MatSubD%
  29085.  MatSubC%
  29086.  Finds the difference between two matrixes whose row and column dimensions
  29087.  are identical.
  29088.  
  29089.  
  29090.  Multiplication
  29091.  --------------
  29092.  MatMultI%
  29093.  MatMultL%
  29094.  MatMultS%
  29095.  MatMultD%
  29096.  MatMultC%
  29097.  Finds the product of two matrixes where the first matrix has the same number
  29098.  of columns as the second matrix has rows.
  29099.  
  29100.  
  29101.  Determinant
  29102.  -----------
  29103.  MatDetI%
  29104.  MatDetL%
  29105.  MatDetS%
  29106.  MatDetD%
  29107.  MatDetC%
  29108.  Finds the determinant of a square matrix.
  29109.  
  29110.  
  29111.  Inverse
  29112.  -------
  29113.  MatInvS%
  29114.  MatInvD%
  29115.  MatInvC%
  29116.  Finds the multiplicative inverse of a square matrix, if one exists; that is,
  29117.  if the determinant is not equal
  29118.  to 0.
  29119.  
  29120.  
  29121.  Gaussian elimination
  29122.  --------------------
  29123.  MatSEqnS%
  29124.  MatSEqnD%
  29125.  MatSEqnC%
  29126.  Uses Gaussian elimination to solve, if a solution exists, a system of linear
  29127.  equations contained in a square matrix and a vector.
  29128.  
  29129.  
  29130.  Presentation Graphics Sub and FUNCTION Procedures
  29131.  
  29132.  
  29133.  Chart
  29134.  Draws a bar, column, or line chart.
  29135.  
  29136.  ChartMS
  29137.  Draws a multi-series bar, column, or line chart.
  29138.  
  29139.  ChartPie
  29140.  Draws a pie chart.
  29141.  
  29142.  ChartScatter
  29143.  Draws a single-series scatter chart.
  29144.  
  29145.  ChartScatterMS
  29146.  Draws a multi-series scatter chart.
  29147.  
  29148.  ChartScreen
  29149.  Sets the screen mode to be used when displaying a chart.
  29150.  
  29151.  DefaultChart
  29152.  Initializes a ChartEnvironment structure for the specified chart type and
  29153.  style.
  29154.  
  29155.  GetPaletteDef
  29156.  Gets a copy of the current internal chart palette.
  29157.  
  29158.  GetPattern$
  29159.  Returns a string that can be used by BASIC as a pixel pattern
  29160.  
  29161.  LabelChartH
  29162.  Prints a user-defined string horizontally on a chart.
  29163.  
  29164.  LabelChartV
  29165.  Prints a user-defined string vertically on a chart.
  29166.  
  29167.  MakeChartPattern$
  29168.  Changes fill pattern and color.
  29169.  ResetPaletteDef
  29170.  Builds the internal chart palette for the current screen mode using the
  29171.  current style pool.
  29172.  
  29173.  SetPaletteDef
  29174.  Replaces the internal chart palette with user-defined values.
  29175.  
  29176.  
  29177.  
  29178.  Font SUB and FUNCTION Procedures
  29179.  
  29180.  
  29181.  GetFontInfo
  29182.  Gets font information for the currently selected font.
  29183.  
  29184.  GetGTextLen%
  29185.  Returns the pixel length of a string based on the currently selected font.
  29186.  
  29187.  GetMaxFonts
  29188.  Gets the maximum number of fonts that can be registered and loaded.
  29189.  
  29190.  GetRFontInfo
  29191.  Gets font information for the currently registered fonts.
  29192.  
  29193.  GetTotalFonts
  29194.  Gets the number of fonts currently registered and loaded.
  29195.  
  29196.  LoadFont%
  29197.  Loads the font information from the .fon files or memory for the specified
  29198.  fonts and returns the number of fonts actually loaded.
  29199.  
  29200.  OutGText%
  29201.  Outputs text in the currently selected font using the current graphics color
  29202.  at the current graphics cursor position. Returns pixel length of the
  29203.  character output.
  29204.  
  29205.  RegisterFonts%
  29206.  Registers font-header information from a specified .fon file and returns the
  29207.  number of fonts registered.
  29208.  
  29209.  RegisterMemFont%
  29210.  Registers the font-header information for fonts that reside in memory and
  29211.  returns the number of fonts registered.
  29212.  
  29213.  SelectFont
  29214.  Designates a loaded font as the active font.
  29215.  
  29216.  SetGCharSet
  29217.  Sets the character set used in subsequent graphics characters.
  29218.  
  29219.  SetGTextColor
  29220.  Sets the character color used in subsequent graphic characters.
  29221.  
  29222.  SetGTextDir
  29223.  Sets the horizontal or vertical orientation of graphics characters.
  29224.  
  29225.  SetMaxFonts
  29226.  Sets the maximum number of fonts that are allowed to be registered and
  29227.  loaded.
  29228.  
  29229.  UnRegisterFonts
  29230.  Removes registered fonts from memory.
  29231.  
  29232.  
  29233.  
  29234.  User Interface Procedures
  29235.  
  29236.  The following tables summarize the procedures that make up the User
  29237.  Interface toolbox. These functions are provided in four separate toolbox
  29238.  files. The files are:
  29239.  *    MENU.BAS
  29240.  *    WINDOW.BAS
  29241.  *    MOUSE.BAS
  29242.  *    GENERAL.BAS
  29243.  
  29244.  Each table lists the type of operation performed by the procedure, the
  29245.  procedure name, and the result of the procedure. See the detailed
  29246.  description of each of the procedures later in this part for more
  29247.  information about how to use them in your programs.
  29248.  
  29249.  Menu SUB and FUNCTION Procedures
  29250.  
  29251.  
  29252.  Initialize variables and preprocess menus
  29253.  -----------------------------------------
  29254.  MenuInit
  29255.  Initializes global menu arrays and mouse driver servicing routines.
  29256.  
  29257.  MenuPreProcess
  29258.  Performs calculations and builds indexes so menus run faster.
  29259.  
  29260.  
  29261.  Define and display menus
  29262.  ------------------------
  29263.  MenuColor
  29264.  Assigns color to various components of the menus.
  29265.  
  29266.  MenuSet
  29267.  Defines the structure of menus and the quick keys associated with each menu
  29268.  selection.
  29269.  
  29270.  MenuShow
  29271.  Draws the menu across the top line of the screen.
  29272.  
  29273.  
  29274.  Change the state of menus or menu items
  29275.  ---------------------------------------
  29276.  MenuItemToggle
  29277.  Toggles the state of a menu item between enabled but not selected and
  29278.  enabled and selected.
  29279.  
  29280.  MenuSetState
  29281.  Explicitly assigns the state of a menu item. States are: empty (menu item
  29282.  does not appear on the menu); enabled but not selected; enabled and
  29283.  selected; and disabled.
  29284.  
  29285.  
  29286.  Process menu events
  29287.  -------------------
  29288.  MenuCheck
  29289.  Provides a numeric indication of what menu selection, if any, was made
  29290.  following a menu or shortcut-key event.
  29291.  
  29292.  MenuEvent$
  29293.  Monitors user input to determine if a menu choice is being made with either
  29294.  the mouse or the keyboard.
  29295.  
  29296.  MenuInkey$
  29297.  Performs a BASIC INKEY$ function as well as a MenuEvent$ and
  29298.  ShortCutKeyEvent$ function.
  29299.  
  29300.  MenuOff
  29301.  Turns off menu and shortcut-key event processing.
  29302.  
  29303.  MenuOn
  29304.  Turns on menu and shortcut-key event processing that was previously turned
  29305.  off.
  29306.  
  29307.  
  29308.  Shortcut keys
  29309.  -------------
  29310.  ShortCutKeyDelete$
  29311.  Revokes any previous shortcut-key definitions associated with a particular
  29312.  menu item.
  29313.  
  29314.  ShortCutKeyEvent$
  29315.  Polls user input to determine if a menu item was selected using a shortcut
  29316.  key.
  29317.  
  29318.  ShortCutKeySet
  29319.  Assign shortcut keys to individual menu items.
  29320.  
  29321.  
  29322.  Window SUB and FUNCTION Procedures
  29323.  
  29324.  
  29325.  
  29326.  Initialize window variables
  29327.  ---------------------------
  29328.  WindowInit
  29329.  Initializes global variables for all procedures in WINDOW.BAS.
  29330.  
  29331.  
  29332.  Define windows
  29333.  --------------
  29334.  WindowBox
  29335.  Draws a box with a single-line border at a designated position within the
  29336.  current window.
  29337.  
  29338.  WindowClose
  29339.  Closes a specified window.
  29340.  
  29341.  WindowColor
  29342.  Changes color characteristics of the current window.
  29343.  
  29344.  WindowOpen
  29345.  Defines the size, position, color, and other characteristics of individual
  29346.  windows.
  29347.  
  29348.  WindowSetCurrent
  29349.  Makes the specified window the current window.
  29350.  
  29351.  
  29352.  Get information about windows
  29353.  -----------------------------
  29354.  WindowCols
  29355.  Returns the number of columns in the current window.
  29356.  
  29357.  WindowCurrent
  29358.  Returns the number of the current window handle.
  29359.  
  29360.  WindowNext
  29361.  Returns the number of the next available window handle.
  29362.  
  29363.  WindowRows
  29364.  Returns the number of rows in the current window.
  29365.  
  29366.  
  29367.  Display text in windows
  29368.  -----------------------
  29369.  WindowCls
  29370.  Clears all text from within a window.
  29371.  
  29372.  WindowLine
  29373.  Draws a horizontal line across a window at the row specified.
  29374.  
  29375.  WindowLocate
  29376.  Sets the row and column of the window text cursor to define the next
  29377.  position where a character will be printed.
  29378.  
  29379.  WindowPrint
  29380.  Prints text in a window at the position established by WindowLocate.
  29381.  
  29382.  WindowScroll
  29383.  Scrolls text, in the current window, the number of lines specified.
  29384.  
  29385.  
  29386.  Button actions
  29387.  --------------
  29388.  ButtonClose
  29389.  Erases the specified button from the current window and deletes it from the
  29390.  global arrays.
  29391.  
  29392.  ButtonInquire
  29393.  Returns a value that indicates the state of the specified button. Only used
  29394.  with button types 1, 2, 3, 6, and 7.
  29395.  
  29396.  ButtonOpen
  29397.  Opens a button of a specified type and places it in the current window at
  29398.  the specified window coordinates.
  29399.  
  29400.  ButtonSetState
  29401.  Sets the state of the specified button in the current window.
  29402.  
  29403.  ButtonToggle
  29404.  Toggles the state of the specified button between selected and not selected.
  29405.  
  29406.  
  29407.  Edit field actions
  29408.  ------------------
  29409.  EditFieldClose
  29410.  Erases the specified edit field from the current window and deletes it from
  29411.  the global arrays.
  29412.  
  29413.  EditFieldInquire
  29414.  Returns the string associated with the specified edit field.
  29415.  
  29416.  EditFieldOpen
  29417.  Opens an edit field and places it in the current window at specified
  29418.  coordinates.
  29419.  
  29420.  Miscellaneous actions
  29421.  ---------------------
  29422.  Alert
  29423.  Displays a window containing between one and three buttons that indicate
  29424.  user choices. Returns a value that indicates the number of the button
  29425.  selected by the user.
  29426.  
  29427.  Dialog
  29428.  Returns a value that indicates what type of button, edit field, or window
  29429.  event occurred during window-event processing.
  29430.  
  29431.  ListBox
  29432.  Displays a window containing a list box, a scroll bar, an OK button, and a
  29433.  Cancel button. Returns a value that indicates the number of the item
  29434.  selected in the list box,
  29435.  or 0 if Cancel is selected.
  29436.  
  29437.  MaxScrollLength
  29438.  Returns a value that indicates how many positions are available on a
  29439.  specified scroll bar.
  29440.  
  29441.  
  29442.  
  29443.  Mouse SUB Procedures
  29444.  
  29445.  
  29446.  Initialize the mouse
  29447.  --------------------
  29448.  MouseDriver
  29449.  Calls Interrupt 51 (33H) and passes parameters to the proper CPU registers.
  29450.  
  29451.  MouseInit
  29452.  Initializes mouse driver servicing routines.
  29453.  
  29454.  
  29455.  Establish limits of mouse movement on the screen
  29456.  ------------------------------------------------
  29457.  MouseBorder
  29458.  Defines the area where the mouse can be used.
  29459.  
  29460.  
  29461.  Manipulate the mouse
  29462.  --------------------
  29463.  MouseHide
  29464.  Turns off display of the mouse cursor.
  29465.  
  29466.  MousePoll
  29467.  Polls the mouse driver to establish the position of the mouse cursor and the
  29468.  status of mouse buttons.
  29469.  
  29470.  MouseShow
  29471.  Turns on display of the mouse cursor.
  29472.  
  29473.  
  29474.  General SUB and FUNCTION Procedures
  29475.  
  29476.  
  29477.  Accept and evaluate keyboard input
  29478.  ----------------------------------
  29479.  AltToASCII$
  29480.  Decodes extended key codes associated with the Alt key and returns an
  29481.  individual ASCII character.
  29482.  
  29483.  GetShiftState
  29484.  Returns the status of one of eight possible shift states.
  29485.  
  29486.  
  29487.  Manipulate screen areas
  29488.  -----------------------
  29489.  AttrBox
  29490.  Changes color attributes of text within an area described by specified row
  29491.  and column coordinates.
  29492.  
  29493.  Box
  29494.  Draws a box around a defined area using specified foreground and background
  29495.  colors.
  29496.  
  29497.  GetBackground
  29498.  Saves an area of the screen into a named buffer.
  29499.  
  29500.  PutBackground
  29501.  Restores to specified coordinates a previously saved screen area from a
  29502.  named buffer.
  29503.  
  29504.  Scroll
  29505.  Scrolls the defined area a specified number of lines.
  29506.  
  29507.  
  29508.  
  29509.  
  29510.  Matrix Math Toolbox
  29511.  
  29512.  This section describes the six FUNCTION procedures supported by the Matrix
  29513.  Math toolbox:
  29514.  *    MatAdd FUNCTION
  29515.  *    MatSub FUNCTION
  29516.  *    MatMult FUNCTION
  29517.  *    MatDet FUNCTION
  29518.  *    MatInv FUNCTION
  29519.  *    MatSEqn FUNCTION
  29520.  
  29521.  Matrix Math is the name of a BASIC toolbox (MATB.BAS) included with
  29522.  Microsoft BASIC. The toolbox contains a set of matrix-manipulation
  29523.  procedures that perform math operations on two-dimensional matrixes. There
  29524.  is a separate toolbox procedure for each supported numeric data type. Which
  29525.  one to use depends on the data type of the elements in the matrix. The last
  29526.  letter in the procedure name identifies the data type of the procedure, as
  29527.  follows:
  29528.  
  29529.  
  29530.  Letter    Numeric data type
  29531.  I         Integer
  29532.  S         Single precision floating point
  29533.  C         Currency
  29534.  L         Long integer
  29535.  D         Double precision floating point
  29536.  
  29537.  
  29538.  All numeric data types are supported by MatAdd, MatSub, MatMult, and MatDet.
  29539.  Integer and long integer data types are not supported by MatInv and MatSEqn.
  29540.  
  29541.  Each procedure returns a result code that indicates the success of the
  29542.  operation, or, in the case of an error, the nature of the problem
  29543.  encountered. The following result codes are defined:
  29544.  
  29545.  Result code    Significance
  29546.    0            Normal completion. No error occurred.
  29547.  - 1            Determinant for matrix is 0. No inverse of the input matrix
  29548.  exists.
  29549.  - 2            Matrix not square; doesn't have same number of rows as
  29550.  columns.
  29551.  - 3            Inside dimension not the same. The number of columns in
  29552.  matrix1 is not the same as the number of rows in matrix2.
  29553.  - 4            Matrixes not of the same dimension. That is, there are not
  29554.  the same number of rows in matrix1 that are in matrix2 or there are not the
  29555.  same number of columns in matrix1 that are in matrix2.
  29556.  - 5            Dimensions for the solution matrix not correctly declared.
  29557.  The matrix does not have the proper number of rows and columns.
  29558.  
  29559.  
  29560.  
  29561.  Note
  29562.  ----
  29563.  By default all arrays are zero based; that is, the lower bound of an array
  29564.  is 0. You may wish to use OPTION BASE 1 so that the numbers in the DIM
  29565.  statement accurately reflect the number of row and column elements in your
  29566.  matrixes.
  29567.  
  29568.  
  29569.  
  29570.  Following is a description of the FUNCTION procedures in the Matrix Math
  29571.  toolbox.
  29572.  
  29573.  
  29574.  
  29575.  MatAdd FUNCTION
  29576.  
  29577.  MatAddI%
  29578.  MatAddL%
  29579.  MatAddS%
  29580.  MatAddD%
  29581.  MatAddC%
  29582.  
  29583.  Syntax
  29584.  errcode% = MatAddtype%(matrix1( ), matrix2( ))
  29585.  
  29586.  Remarks
  29587.  MatAddtype% performs matrix addition of two matrixes that are the same in
  29588.  both row (m) and column (n) dimensions. The input matrixes contain values
  29589.  whose data type is defined by the last letter in the procedure name (I, L,
  29590.  S, D, or C). The sum is returned in matrix1( ), replacing any previous
  29591.  values. The solution matrix contains values of the same data type as the
  29592.  input matrixes. Once the procedure has been performed, the contents of
  29593.  matrix2( ) are meaningless.
  29594.  
  29595.  MatAddtype% uses the following arguments:
  29596.  
  29597.  matrix1( )
  29598.  ----------
  29599.  A matrix consisting of m x n dimensions.
  29600.  
  29601.  matrix2( )
  29602.  ----------
  29603.  A matrix consisting of m x n dimensions.
  29604.  
  29605.  
  29606.  A result code indicates the success or failure of the FUNCTION procedure.
  29607.  Possibilities are:
  29608.   0             Normal completion. No error occurred.
  29609.  -4             Matrixes not of the same dimension. That is, there are not
  29610.  the same number of rows in matrix1 as there are in matrix2 or there are not
  29611.  the same number of columns in matrix1 as in matrix2.
  29612.  
  29613.  
  29614.  MatSub FUNCTION
  29615.  
  29616.  MatSubI%
  29617.  MatSubL%
  29618.  MatSubS%
  29619.  MatSubD%
  29620.  MatSubC%
  29621.  
  29622.  Syntax
  29623.  errcode% = MatSubtype%(matrix1( ), matrix2( ))
  29624.  
  29625.  Remarks
  29626.  The MatSubtype% procedure performs matrix subtraction of two matrixes whose
  29627.  row (m) and column (n) dimensions are identical. The input matrixes contain
  29628.  values whose data type is defined by the last letter in the procedure name
  29629.  (I, L, S, D, or C). The first matrix is subtracted from the second and the
  29630.  difference is returned in matrix1( ), replacing any previous values. The
  29631.  solution matrix contains values of the same data type as the input matrixes.
  29632.  Once the procedure has been performed, the contents of matrix2( ) are
  29633.  meaningless.
  29634.  
  29635.  
  29636.  MatSubtype% uses the following arguments:
  29637.  
  29638.  matrix1( )
  29639.  ----------
  29640.  A matrix consisting of m x n dimensions.
  29641.  
  29642.  matrix2( )
  29643.  ----------
  29644.  A matrix consisting of m x n dimensions.
  29645.  
  29646.  
  29647.  A result code is returned that indicates the success or failure of the
  29648.  FUNCTION procedure. Possible result codes are:
  29649.   0    Normal completion. No error occurred.
  29650.  - 4   Matrixes not of the same dimension. That is, there are not the same
  29651.  number of rows in matrix1 as there are in matrix2 or there are not the same
  29652.  number of columns in matrix1 as in matrix2.
  29653.  
  29654.  
  29655.  
  29656.  MatMult FUNCTION
  29657.  
  29658.  MatMultI%
  29659.  MatMultL%
  29660.  MatMultS%
  29661.  MatMultD%
  29662.  MatMultC%
  29663.  
  29664.  Syntax
  29665.  errcode% = MatMulttype%(matrix1( ), matrix2( ), matrix3( ))
  29666.  
  29667.  Remarks
  29668.  The MatMulttype% procedure performs matrix multiplication of two matrixes.
  29669.  The first matrix must have the same number of columns (n in an m x n matrix)
  29670.  as the number of rows in the second matrix (n in an n x k matrix). The input
  29671.  matrixes contain values whose data type is defined by the last letter in the
  29672.  procedure name (I, L, S, D, or C). The first matrix is multiplied by the
  29673.  second and the product is returned in matrix3( ). The solution matrix
  29674.  contains values of the same data type as the input matrixes. Once the
  29675.  procedure has been performed, the contents of the input matrixes are
  29676.  meaningless.
  29677.  
  29678.  MatMulttype% uses the following arguments:
  29679.  
  29680.  matrix1( )
  29681.  ----------
  29682.  A matrix consisting of m x n dimensions.
  29683.  
  29684.  matrix2( )
  29685.  ----------
  29686.  A matrix consisting of n x k dimensions.
  29687.  
  29688.  matrix3( )
  29689.  ----------
  29690.  Solution matrix consisting of m x k dimensions.
  29691.  
  29692.  
  29693.  A result code is returned that indicates the success or failure of the
  29694.  FUNCTION procedure. Possible result codes are:
  29695.   0   Normal completion. No error occurred.
  29696.  - 3  Inside dimension not the same. The number of columns in matrix1 is not
  29697.  the same as the number of rows in matrix2.
  29698.  - 5  Dimensions for the solution matrix not correctly declared. The matrix
  29699.  does not have the proper number of rows and columns.
  29700.  
  29701.  
  29702.  Note
  29703.  ----
  29704.  Matrix division is performed using the MatInvtype% procedure to multiply one
  29705.  matrix by the inverse of the second; that is, A/B = A * Inverse(B).
  29706.  
  29707.  
  29708.  
  29709.  MatDet FUNCTION
  29710.  
  29711.  MatDetI%
  29712.  MatDetL%
  29713.  MatDetS%
  29714.  MatDetD%
  29715.  MatDetC%
  29716.  
  29717.  Syntax
  29718.  errcode% = MatDettype%(matrix ( ), determinant)
  29719.  
  29720.  Remarks
  29721.  The MatDettype% procedure finds the determinant of a square matrix; that is,
  29722.  a matrix that has the same number of rows and columns (n x n). The input
  29723.  matrix contains values whose data type is defined by the last letter in the
  29724.  procedure name (I, L, S, D, or C). The resulting determinant, of the same
  29725.  data type as the input matrix values, is placed in determinant. After the
  29726.  procedure is performed, the contents of matrix( ) are meaningless.
  29727.  
  29728.  MatDettype% uses the following arguments:
  29729.  
  29730.  matrix ( )
  29731.  ----------
  29732.  A matrix consisting of n x n dimensions.
  29733.  
  29734.  determinant
  29735.  -----------
  29736.  The determinant for matrix ( ).
  29737.  
  29738.  
  29739.  A result code indicates the success or failure of the FUNCTION procedure.
  29740.  Possibilities are:
  29741.   0   Normal completion. No error occurred.
  29742.  - 2  Matrix not square. The matrix does not have the same number of rows as
  29743.  columns.
  29744.  
  29745.  
  29746.  
  29747.  
  29748.  MatInv FUNCTION
  29749.  
  29750.  MatInvS%
  29751.  MatInvD%
  29752.  MatInvC%
  29753.  
  29754.  Syntax
  29755.  errcode% = MatInvtype%(matrix ( ))
  29756.  
  29757.  Remarks
  29758.  The MatInvtype% procedure finds the multiplicative inverse of a square
  29759.  matrix; that is, a matrix that has the same number of rows and columns (n x
  29760.  n). The input matrix contains values whose data type is defined by the last
  29761.  letter in the procedure name (S, D, or C). The resulting inverse matrix, of
  29762.  the same data type as the input matrix values, is returned in matrix( ),
  29763.  replacing any previous values.
  29764.  
  29765.  The argument matrix ( ) is a matrix consisting of n x n dimensions.
  29766.  A result code indicates the success or failure of the FUNCTION procedure.
  29767.  Possibilities are:
  29768.   0   Normal completion. No error occurred.
  29769.  - 1  The determinant for the matrix is 0. No inverse of the input matrix
  29770.  exists.
  29771.  - 2  Matrix not square. The matrix does not have the same number of rows as
  29772.  columns.
  29773.  
  29774.  
  29775.  Note
  29776.  ----
  29777.  Matrix division is performed using the MatInvtype% procedure to multiply one
  29778.  matrix by the inverse of the second, that is, A/B = A * Inverse(B).
  29779.  
  29780.  
  29781.  
  29782.  MatSEqn FUNCTION
  29783.  
  29784.  MatSEqnS%
  29785.  MatSEqnD%
  29786.  MatSEqnC%
  29787.  
  29788.  Syntax
  29789.  errcode% = MatSEqntype%(matrix1( ), matrix2( ))
  29790.  
  29791.  Remarks
  29792.  The MatSEqntype% procedure solves a system of linear equations contained in
  29793.  a square matrix; that is, a matrix that has the same number of rows and
  29794.  columns (n x n). Gaussian elimination is used to solve the equations. The
  29795.  input matrix contains values whose data type is defined by the last letter
  29796.  in the procedure name (S, D, or C). The first matrix is the square input
  29797.  matrix that contains the coefficients for a system of simultaneous
  29798.  equations. The second matrix, matrix2( ), is the space where the solution is
  29799.  returned. The solution space is an n x 1 matrix. The solution matrix
  29800.  contains values of the same data type as the input matrix. Once the
  29801.  procedure has been performed, the identity matrix is in matrix1( ).
  29802.  
  29803.  MatSEqntype% uses the following arguments:
  29804.  
  29805.  matrix1( )
  29806.  ----------
  29807.  A matrix consisting of n x n dimensions.
  29808.  
  29809.  matrix2( )
  29810.  ----------
  29811.  Solution array consisting of 1 x n dimensions.
  29812.  
  29813.  
  29814.  A result code is returned that indicates the success or failure of the
  29815.  FUNCTION procedure. Possible result codes are:
  29816.   0   Normal completion. No error occurred.
  29817.  - 1  Determinant for matrix is 0. No inverse of the input matrix exists.
  29818.  - 2  Matrix not square. The matrix does not have the same number of rows as
  29819.  columns.
  29820.  - 3  Inside dimension not the same. The number of columns in matrix1 is not
  29821.  the same as the number of rows in matrix2.
  29822.  
  29823.  
  29824.  
  29825.  Presentation Graphics Toolbox
  29826.  
  29827.  
  29828.  The first part of this section describes the SUB and FUNCTION procedures
  29829.  that are supported by the Presentation Graphics toolbox. The second part
  29830.  describes the SUB and FUNCTION procedures that are supported by the Fonts
  29831.  toolbox. The Fonts toolbox can be used with the Presentation Graphics
  29832.  toolbox or independently to draw graphics text.
  29833.  
  29834.  The Presentation Graphics toolbox (CHRTB.BAS), included with the BASIC 7.0
  29835.  Compiler, contains a set of routines for defining, analyzing, and printing
  29836.  charts on the screen.
  29837.  
  29838.  There are five kinds of charts, each available in two styles as shown here:
  29839.  
  29840.  Style    Bar        Column    Line            Scatter        Pie
  29841.  
  29842.  1        Plain      Plain     Lines and       Lines and      Percent
  29843.                                   points         points         displayed
  29844.  2        Stacked    Stacked   Points only     Points only    No percent
  29845.  
  29846.  To use the toolbox, you first must declare the dimensions for a variable as
  29847.  the user-defined type ChartEnvironment. The definition for this type is
  29848.  found in the CHRTB.BI header file. This file also contains definitions for
  29849.  constants that can be used as arguments to the procedures described in this
  29850.  section. Using these constants in place of hand-coded numerics will make
  29851.  your program cleaner and easier to debug.
  29852.  
  29853.  Presentation Graphics Error Codes
  29854.  If an error occurs during the execution of a presentation graphics
  29855.  procedure, the variable ChartErr will contain a non-zero value.
  29856.  For non-BASIC errors, the error numbers can be tested using numerics or
  29857.  constants as defined in the CHRTB.BI header file. The meaning of a non-BASIC
  29858.  error:
  29859.  
  29860.  Number    Constant name      Type of error
  29861.  
  29862.  15        cBadLogBase        LogBase <= 0
  29863.  20        cBadScaleFactor    ScaleFactor = 0
  29864.  25        cBadScreen         Invalid screen mode
  29865.  30        cBadStyle          Invalid chart style
  29866.  105       cBadDataWindow     Data window calculated
  29867.                                   too small
  29868.  110       cBadLegendWindow   Legend-window coordinates
  29869.                                   invalid
  29870.  135       cBadType           Invalid chart type
  29871.  155       cTooFewSeries      Too few series
  29872.                                   (first% > last%)1
  29873.  160       cTooSmallN         No data in series (n% = 0)2
  29874.  165       cBadPalette        Palette not dimensioned
  29875.                                   correctly
  29876.  170       cPalettesNotSet    SetPaletteDef procedure hasn't
  29877.                                   been used
  29878.  175       cNoFontSpace       No more room for new fonts
  29879.  
  29880.  
  29881.  Numbers greater than 100 are fatal errors and will cause charting routines
  29882.  to exit.
  29883.  If BASIC generates an error, the value of ChartErr is equal to 200 plus the
  29884.  BASIC error number. (See Appendix D, "Error Messages" for a complete list of
  29885.  BASIC error messages.)
  29886.  
  29887.  
  29888.  
  29889.  Chart Sub
  29890.  
  29891.  Action
  29892.  Draws bar, column, and line charts.
  29893.  
  29894.  
  29895.  Syntax
  29896.  Chart env, cat$(), value!(), n%
  29897.  
  29898.  Remarks
  29899.  The Chart procedure uses the following arguments:
  29900.  
  29901.  env
  29902.  ---
  29903.  A variable dimensioned as type ChartEnvironment.
  29904.  
  29905.  cat$()
  29906.  ------
  29907.  A one-dimensional string array of category names.
  29908.  
  29909.  value!()
  29910.  --------
  29911.  A one-dimensional single-precision array that contains the
  29912.  chart data.
  29913.  
  29914.  n%
  29915.  --
  29916.  An integer that contains the number of data items in value!().
  29917.  
  29918.  
  29919.  The value!() and cat$() arrays must have a lower bound of 1.
  29920.  The AnalyzeChart routine uses the same arguments as Chart. AnalyzeChart
  29921.  analyzes and defines parameters in the chart environment based on the input
  29922.  data, but it does not print a chart on the screen.
  29923.  
  29924.  
  29925.  ChartMS Sub
  29926.  
  29927.  Action
  29928.  Draws multi-series bar, column, and line charts.
  29929.  
  29930.  
  29931.  Syntax
  29932.  ChartMS env, cat$(), value!(), n%, first%, last%, serieslabel$()
  29933.  
  29934.  Remarks
  29935.  The ChartMS procedure uses the following arguments:
  29936.  
  29937.  env
  29938.  ---
  29939.  A variable dimensioned as type ChartEnvironment.
  29940.  
  29941.  cat$()
  29942.  ------
  29943.  A one-dimensional string array of category labels.
  29944.  
  29945.  value!()
  29946.  --------
  29947.  A two-dimensional single-precision array of values that contains multiple
  29948.  series of data.
  29949.  
  29950.  n%
  29951.  --
  29952.  An integer that contains the number of data items in each series to be
  29953.  charted.
  29954.  
  29955.  first%
  29956.  ------
  29957.  An integer that indicates the first series in array value!() to be charted.
  29958.  
  29959.  last%
  29960.  -----
  29961.  An integer that indicates the last series in array value!() to be charted.
  29962.  
  29963.  serieslabel$()
  29964.  --------------
  29965.  A one-dimensional string array that contains labels for the different data
  29966.  series.
  29967.  
  29968.  
  29969.  Dimensions for the value!() and serieslabel$() arrays are declared as
  29970.  follows:
  29971.  
  29972.  DIM Val!( 1 to n%, first% to last%)
  29973.  DIM serieslabel$( first% to last%)
  29974.  
  29975.  To chart all series, set first% to 1 and last% to the last series number in
  29976.  array value!(). To chart several contiguous series, set first% to the lowest
  29977.  series number and last% to the highest series number desired.
  29978.  An analysis routine called AnalyzeChartMS (included in the Presentation
  29979.  Graphics toolbox) uses the same arguments as ChartMS. AnalyzeChartMS
  29980.  analyzes and defines parameters in the chart environment based on the input
  29981.  data, but it does not print a chart on the screen.
  29982.  
  29983.  
  29984.  ChartPie Sub
  29985.  
  29986.  Action
  29987.  Draws bar, column, and line charts.
  29988.  
  29989.  
  29990.  Syntax
  29991.  ChartPie env, cat$(), value!(), expl%(), n%
  29992.  
  29993.  Remarks
  29994.  The ChartPie procedure uses the following arguments:
  29995.  
  29996.  env
  29997.  ---
  29998.  A variable dimensioned as type ChartEnvironment.
  29999.  
  30000.  cat$()
  30001.  ------
  30002.  A one-dimensional string array of category names.
  30003.  
  30004.  value!()
  30005.  --------
  30006.  A one-dimensional single-precision array that contains the
  30007.  chart data.
  30008.  
  30009.  expl%()
  30010.  -------
  30011.  A one-dimensional integer array containing flags that determine whether each
  30012.  element of the pie chart is exploded. If the value of an expl%() array
  30013.  element is nonzero, that slice of the pie chart is exploded. If the array
  30014.  element is zero, the slice is not exploded.
  30015.  
  30016.  n%
  30017.  --
  30018.  An integer that contains the number of data items in value!().
  30019.  
  30020.  
  30021.  The value!(), cat$(), and expl%() arrays must have a lower bound of 1.
  30022.  An analysis routine called AnalyzePie (included in the Presentation Graphics
  30023.  toolbox) uses the same arguments as ChartPie. AnalyzePie analyzes and
  30024.  defines parameters in the chart environment based on the input data, but it
  30025.  does not print a chart on the screen.
  30026.  
  30027.  
  30028.  
  30029.  ChartScatter Sub
  30030.  
  30031.  Action
  30032.  Draws single-series scatter charts.
  30033.  
  30034.  
  30035.  Syntax
  30036.  ChartScatter env, valx!(), valy!(), n%
  30037.  
  30038.  Remarks
  30039.  The ChartScatter procedure uses the following arguments:
  30040.  
  30041.  env
  30042.  ---
  30043.  A variable dimensioned as type ChartEnvironment.
  30044.  
  30045.  valx!()
  30046.  -------
  30047.  A one-dimensional single-precision array of values for the x axis.
  30048.  
  30049.  valy!()
  30050.  -------
  30051.  A one-dimensional single-precision array of values for the y axis.
  30052.  
  30053.  n%
  30054.  --
  30055.  An integer that contains the number of data items to be charted.
  30056.  
  30057.  
  30058.  The valx!() and valy!() arrays must have a lower bound of 1.
  30059.  An analysis routine called AnalyzeScatter (included in the Presentation
  30060.  Graphics toolbox) uses the same arguments as ChartScatter. AnalyzeScatter
  30061.  analyzes and defines parameters in the chart environment based on the input
  30062.  data, but it does not print a chart on the screen.
  30063.  
  30064.  
  30065.  
  30066.  ChartScatterMS Sub
  30067.  
  30068.  Action
  30069.  Draws multi-series scatter charts.
  30070.  
  30071.  
  30072.  Syntax
  30073.  ChartScatterMS env, valx!(), valy!(), n%, first%, last%, serieslabel$()
  30074.  
  30075.  Remarks
  30076.  The ChartScatterMS procedure uses the following arguments:
  30077.  
  30078.  env
  30079.  ---
  30080.  A variable dimensioned as type ChartEnvironment.
  30081.  
  30082.  valx!()
  30083.  -------
  30084.  A two-dimensional single-precision array of values for multiple series of
  30085.  data for the x axis.
  30086.  
  30087.  valy!()
  30088.  -------
  30089.  A two-dimensional single-precision array of values for multiple series of
  30090.  data for the y axis.
  30091.  
  30092.  n%
  30093.  --
  30094.  An integer that contains the number of data items to be charted.
  30095.  
  30096.  first%
  30097.  ------
  30098.  An integer that indicates the first series to be charted.
  30099.  
  30100.  last%
  30101.  -----
  30102.  An integer that indicates the last series to be charted.
  30103.  
  30104.  serieslabel$()
  30105.  --------------
  30106.  A one-dimensional string array that contains labels for the different data
  30107.  series.
  30108.  
  30109.  
  30110.  Dimensions for the valx!(), valy!() and serieslabel$() arrays are declared
  30111.  as follows:
  30112.  
  30113.  DIM valx!( 1 to n%, first% to last%)
  30114.  DIM valy!( 1 to n%, first% to last%)
  30115.  DIM serieslabel$( first% to last%)
  30116.  
  30117.  To chart all series, set first% to 1 and last% to the last series number in
  30118.  array value!(). To chart several contiguous series, set first% to lowest
  30119.  series number and last% to the highest series number desired.
  30120.  
  30121.  An analysis routine called AnalyzeScatterMS (included in the Presentation
  30122.  Graphics toolbox) uses the same arguments as ChartScatterMS.
  30123.  AnalyzeScatterMS analyzes and defines parameters in the chart environment
  30124.  based on the input data, but it does not print a chart on the screen.
  30125.  
  30126.  
  30127.  
  30128.  ChartScreen Sub
  30129.  
  30130.  Action
  30131.  Sets the screen mode to be used when displaying a chart.
  30132.  
  30133.  
  30134.  Syntax
  30135.  ChartScreen n%
  30136.  
  30137.  Remarks
  30138.  The argument n% is an integer that contains a valid screen-mode number.
  30139.  This procedure must be used to set the screen mode instead of the standard
  30140.  BASIC SCREEN statement.
  30141.  If an invalid screen mode is used, the variable ChartErr will contain the
  30142.  number 25.
  30143.  
  30144.  
  30145.  See Also:  SCREEN Statement
  30146.  
  30147.  
  30148.  
  30149.  
  30150.  DefaultChart Sub
  30151.  
  30152.  Action
  30153.  Initializes the elements of the variable type ChartEnvironment for the
  30154.  specified chart type and style.
  30155.  
  30156.  
  30157.  Syntax
  30158.  DefaultChart env, type%, style%
  30159.  
  30160.  Remarks
  30161.  The DefaultChart procedure uses the following arguments:
  30162.  
  30163.  env
  30164.  ---
  30165.  A variable dimensioned as type ChartEnvironment.
  30166.  
  30167.  type%
  30168.  -----
  30169.  An integer that defines the type of chart (1-5).
  30170.  
  30171.  style%
  30172.  ------
  30173.  An integer that defines the style of the chart (1-2).
  30174.  
  30175.  
  30176.  The variable type% can use either numeric data or constants found in the
  30177.  CHRTB.BI file to define the chart as shown in the following table:
  30178.  
  30179.  Value    Constant    Type of chart
  30180.  
  30181.  1        cBar        Bar
  30182.  2        cColumn     Column
  30183.  3        cLine       Line
  30184.  4        cScatter    Scatter
  30185.  5        cPie        Pie
  30186.  
  30187.  The value of the variable style% determines the style of the chart as shown
  30188.  here:
  30189.  
  30190.  Value   Bar      Column    Line             Scatter          Pie
  30191.  
  30192.  1       Plain    Plain     Lines & points   Lines & points   Percent
  30193.  2       Stacked  Stacked   Points only      Points only      No percent
  30194.  
  30195.  For program clarity, the following constants (found in the CHRTB.BI file)
  30196.  should be used in place of numeric arguments:
  30197.  
  30198.  Numeric argument    Equivalent constant
  30199.  
  30200.  1                   cPlain, cLines, cPercent
  30201.  2                   cStacked, cNoLines, cNoPercent
  30202.  
  30203.  
  30204.  
  30205.  GetPaletteDef Sub
  30206.  
  30207.  Action
  30208.  Gets a copy of the current internal chart palette.
  30209.  
  30210.  
  30211.  Syntax
  30212.  GetPaletteDef palc%(), pals%(), palp$(), palch%(), palb%()
  30213.  
  30214.  Remarks
  30215.  The GetPaletteDef procedure uses the following arguments:
  30216.  
  30217.  palc%()
  30218.  -------
  30219.  A one-dimensional integer array of color numbers corresponding to the
  30220.  palette entries.
  30221.  
  30222.  pals%()
  30223.  -------
  30224.  A one-dimensional integer array of line styles corresponding to the palette
  30225.  entries.
  30226.  
  30227.  palp$()
  30228.  -------
  30229.  A one-dimensional string array of fill patterns corresponding to the palette
  30230.  entries.
  30231.  
  30232.  palch%()
  30233.  --------
  30234.  A one-dimensional integer array of plot-character numbers corresponding to
  30235.  the palette entries.
  30236.  
  30237.  palb%()
  30238.  -------
  30239.  A one-dimensional integer array of line styles used for drawing window
  30240.  borders and grid lines.
  30241.  
  30242.  
  30243.  Dimensions for each array should be declared from 0 to cPalLen, a constant
  30244.  found in the CHRTB.BI header file. Note that all palette arrays have a lower
  30245.  bound of 0 (not 1, which is used for data and category-string arrays).
  30246.  
  30247.  
  30248.  For more information on fill patterns, see the entries for PAINT and PALETTE
  30249.  in Part 1, "Language Reference."
  30250.  
  30251.  
  30252.  
  30253.  GetPattern$ FUNCTION
  30254.  
  30255.  Action
  30256.  Returns a string that can be used by BASIC as a pixel pattern.
  30257.  
  30258.  
  30259.  Syntax
  30260.  GetPattern$(bits%, patternNum%)
  30261.  
  30262.  Remarks
  30263.  The GetPattern$ and MakeChartPattern$ procedures are used in combination
  30264.  with the GetPaletteDef and SetPaletteDef procedures to change the fill
  30265.  pattern for pie, column, and bar charts. GetPattern$ constructs a value for
  30266.  refPattern$, which is one of the arguments used by MakeChartPattern$.
  30267.  The GetPattern$ procedure uses the following arguments:
  30268.  
  30269.  Parameter      Description
  30270.  
  30271.  bits%          Use 2 for screen mode 1, 8 for screen mode 13, and 1 for all
  30272.  other screen modes.
  30273.  patternNum%    An integer between one and cPalLen.
  30274.  
  30275.  For more information, see the entry for the MakeChartPattern$ procedure
  30276.  later in this section.
  30277.  
  30278.  
  30279.  LabelChartH Sub
  30280.  
  30281.  Action
  30282.  Prints a user-defined string horizontally on a chart.
  30283.  
  30284.  
  30285.  Syntax
  30286.  LabelChartH env, x%, y%, font%, color%, string$
  30287.  
  30288.  Remarks
  30289.  The LabelChartH procedure uses the following arguments:
  30290.  
  30291.  env
  30292.  ---
  30293.  A variable dimensioned as type ChartEnvironment.
  30294.  
  30295.  x%
  30296.  --
  30297.  An integer that indicates the left position of the first character, in
  30298.  pixels, relative to the chart window.
  30299.  
  30300.  y%
  30301.  --
  30302.  An integer that indicates the bottom of the first character, in pixels,
  30303.  relative to the chart window.
  30304.  
  30305.  font%
  30306.  -----
  30307.  An integer that contains the number of the font (in currently loaded list)
  30308.  to use.
  30309.  
  30310.  color%
  30311.  ------
  30312.  An integer that contains the color number in the chart palette used to
  30313.  assign color to the string.
  30314.  
  30315.  string$
  30316.  -------
  30317.  The text string to be printed.
  30318.  
  30319.  
  30320.  The LabelChartH procedure must be called after calling the charting sub.
  30321.  If an invalid font number (such as 0) is contained in font%, the first font
  30322.  loaded is used. If no fonts are loaded, the default font contained in the
  30323.  Presentation Graphics toolbox files is used.
  30324.  
  30325.  
  30326.  
  30327.  LabelChartV Sub
  30328.  
  30329.  Action
  30330.  Prints a user-defined string vertically on a chart.
  30331.  
  30332.  
  30333.  Syntax
  30334.  LabelChartV env, x%, y%, font%, color%, string$
  30335.  
  30336.  Remarks
  30337.  The LabelChartV procedure uses the following arguments:
  30338.  
  30339.  env
  30340.  ---
  30341.  A variable dimensioned as type ChartEnvironment.
  30342.  
  30343.  x%
  30344.  --
  30345.  An integer that indicates the left position of the first character, in
  30346.  pixels, relative to the chart window.
  30347.  
  30348.  y%
  30349.  --
  30350.  An integer that indicates the top of the first character, in pixels,
  30351.  relative to the chart window.
  30352.  
  30353.  font%
  30354.  -----
  30355.  An integer that contains the number of the font (in currently loaded list)
  30356.  to use.
  30357.  
  30358.  color%
  30359.  ------
  30360.  An integer that contains the color number in the chart palette used to
  30361.  assign color to the string.
  30362.  
  30363.  string$
  30364.  -------
  30365.  The text string to be printed.
  30366.  
  30367.  
  30368.  The LabelChartV procedure must be called after calling the charting sub.
  30369.  
  30370.  Each character is printed vertically and appears in a vertical column.
  30371.  If an invalid font number (such as 0) is contained in font%, the first font
  30372.  loaded is used. If no fonts are loaded, the default font contained in the
  30373.  Presentation Graphics toolbox files is used.
  30374.  
  30375.  
  30376.  
  30377.  
  30378.  MakeChartPattern$ FUNCTION
  30379.  
  30380.  Action
  30381.  Changes fill pattern and color.
  30382.  
  30383.  
  30384.  Syntax
  30385.  MakeChartPattern$(refPattern$, foreground%, background%)
  30386.  
  30387.  Remarks
  30388.  The MakeChartPatern$ and GetPattern$ procedures are used in combination with
  30389.  the GetPaletteDef and SetPaletteDef procedures to change the fill pattern
  30390.  for pie, column, and bar charts.
  30391.  
  30392.  The GetPattern$ procedure uses the following arguments:
  30393.  
  30394.  refPattern$    A string representing the pixel pattern.
  30395.  foreground%    Attribute to map to the pixels in refPattern$ that are
  30396.  defined as being on.
  30397.  background%    Attribute to map to the pixels in refPattern$ that are
  30398.  defined as off.
  30399.  
  30400.  Note that if foreground% and background% are the same value, the fill
  30401.  pattern appears as a solid color.
  30402.  Constructing a value for refPattern$ is difficult. When using the
  30403.  Presentation Graphics toolbox, you can simplify the process by using the
  30404.  GetPattern$ procedure to choose an internally-defined pattern.
  30405.  MakeChartPattern$ maps colors to the string returned by GetPattern$ to
  30406.  produce the combination of color and pattern you want. For more information,
  30407.  see the entry for the GetPattern$ procedure earlier in this section.
  30408.  
  30409.  
  30410.  ResetPaletteDef Sub
  30411.  
  30412.  Action
  30413.  Rebuilds the internal chart palette for the current screen mode.
  30414.  
  30415.  
  30416.  Syntax
  30417.  ResetPaletteDef
  30418.  
  30419.  
  30420.  
  30421.  
  30422.  SetPaletteDef Sub
  30423.  
  30424.  Action
  30425.  Replaces the internal chart palette with new values.
  30426.  
  30427.  
  30428.  Syntax
  30429.  SetPaletteDef palc%(), pals%(), palp$(), palch%(), palb%()
  30430.  
  30431.  Remarks
  30432.  The SetPaletteDef procedure uses the following arguments:
  30433.  
  30434.  palc%()
  30435.  -------
  30436.  A one-dimensional integer array of color numbers corresponding to the
  30437.  palette entries.
  30438.  
  30439.  pals%()
  30440.  -------
  30441.  A one-dimensional integer array of line styles corresponding to the palette
  30442.  entries.
  30443.  
  30444.  palp$()
  30445.  -------
  30446.  A one-dimensional string array of fill patterns corresponding to the palette
  30447.  entries.
  30448.  
  30449.  palch%()
  30450.  --------
  30451.  A one-dimensional integer array of plot-character numbers corresponding to
  30452.  the palette entries.
  30453.  
  30454.  palb%()
  30455.  -------
  30456.  A one-dimensional integer array of line styles used for drawing window
  30457.  borders and grid lines.
  30458.  
  30459.  
  30460.  The dimensions for each array must be declared from 0 to cPalLen, a constant
  30461.  found in the CHRTB.BI header file. Note that all palette arrays have a lower
  30462.  bound of 0 (not 1, which is used for data and category string arrays).
  30463.  For more information on fill patterns, see the entries for PAINT and PALETTE
  30464.  in Part 1, "Language Reference."
  30465.  
  30466.  
  30467.  Part 3:  Fonts Tool Box
  30468.  
  30469.  
  30470.  The Fonts toolbox (FONTB.BAS), included with this version of BASIC, contains
  30471.  a set of routines that perform font-management tasks such as registering,
  30472.  loading, selecting, and printing fonts on the screen.
  30473.  Nine font files are supplied: Courier fonts in COURA.FON, COURB.FON, and
  30474.  COURE.FON, Helvetica fonts in HELVA.FON, HELVB.FON and HELVE.FON, and Times
  30475.  Roman fonts in TMSRA.FON, TMSRB.FON and TMSRE.FON. Each of these files
  30476.  contains six font sizes. Besides these two font files, the Fonts toolbox
  30477.  will work with any standard Windows bitmap .FON file.
  30478.  
  30479.  To use the Fonts toolbox, you must compile and link the FONTASM.OBJ and
  30480.  FONTB.BAS modules into a .LIB or .QLB library file. Once this library
  30481.  exists, you can use it just like any other library. The Fonts toolbox can be
  30482.  used independently of the Presentation Graphics toolbox to draw graphics
  30483.  text.
  30484.  
  30485.  Several of the procedures use the font-header information defined in the
  30486.  user-defined type FontInfo. This type is defined in the FONTB.BI header
  30487.  file. This file also contains definitions for constants that can be used as
  30488.  arguments to the procedures described in this section. Using these constants
  30489.  in place of hand-coded numbers makes your program cleaner and easier to
  30490.  debug.
  30491.  
  30492.  
  30493.  
  30494.  Font Error Codes
  30495.  
  30496.  If an error occurs during the execution of a font function or sub procedure,
  30497.  the variable FontErr will contain a non-zero value.
  30498.  
  30499.  For non-BASIC errors, the error numbers can be tested using numerics or
  30500.  constants as defined in the FONTB.BI header file. The meaning of a non-BASIC
  30501.  error is shown in Table 3.9.
  30502.  
  30503. ╓┌───────────┌────────────────────────────────────────────────┌──────────────╖
  30504.  Number      Constant name                                    Type of error
  30505.  ────────────────────────────────────────────────────────────────────────────
  30506.  FontNum     The location of the font in the registered list
  30507.              or the loaded list.
  30508.  
  30509.  Ascent      The pixel distance from the character baseline
  30510.              to the top of the character box.
  30511.  
  30512.  Points      The point size of the current font as defined
  30513.              in the  LoadFont% function.
  30514.  
  30515.  Number      Constant name                                    Type of error
  30516.  ────────────────────────────────────────────────────────────────────────────
  30517. 
  30518.  PixWidth    The width of the character bitmap. A value of 0
  30519.              specifies a proportional font. A nonzero value
  30520.              specifies the pixel width of the characters in
  30521.              a fixed-space font.
  30522.  
  30523.  PixHeight   The height of the character bitmap.
  30524.  
  30525.  Leading     The number of blank lines at the top of the
  30526.              character definition to act as leading between
  30527.              lines.
  30528.  
  30529.  AvgWidth    The average width of characters in pixels.
  30530.  
  30531.  MaxWidth    The pixel width of the widest character in the
  30532.              font.
  30533.  
  30534.  FileName    The filename from which the font was loaded.
  30535.              The filename has the extension .FON.
  30536.  Number      Constant name                                    Type of error
  30537.  ────────────────────────────────────────────────────────────────────────────
  30538.             The filename has the extension .FON.
  30539.  
  30540.  FaceName    The name of the typeface (for example,
  30541.              Helvetica, Courier) taken from the filename.
  30542.  
  30543.  
  30544.  
  30545.  
  30546.  
  30547.  
  30548.  Note
  30549.  
  30550.  When using the  GetFontInfo procedure, be sure you have access to the .FON
  30551.  file on disk so that it can find the FontNum, FileName, and FaceName values
  30552.  for the currently selected font.
  30553.  
  30554.  For more information on the elements of the variable type FontInfo, see
  30555.  documentation on font file format in Chapter 7, "File Formats" in the
  30556.  Programmer's Reference, which is part of the Microsoft Windows Software
  30557.  Development Kit.
  30558.  
  30559.  
  30560.  GetGTextLen% Function
  30561.  
  30562.  Action
  30563.  Returns the pixel length of a string based on the currently selected font.
  30564.  
  30565.  Syntax
  30566.   GetGTextLen% ( txt$)
  30567.  
  30568.  
  30569.  Remarks
  30570.   GetGTextLen% is an integer that contains the pixel length of the string
  30571.  supplied in the argument  txt$. The pixel length returned from the
  30572.  GetGTextLen% function is based on the currently selected font. From this
  30573.  pixel length, you then can determine whether a string will fit on a
  30574.  particular screen (for example, CGA, EGA).
  30575.  
  30576.  
  30577.  
  30578.  GetMaxFonts Sub
  30579.  
  30580.  Action
  30581.  Gets the maximum number of fonts that can be registered and loaded.
  30582.  
  30583.  Syntax
  30584.   GetMaxFonts ( maxregistered%,  maxloaded%)
  30585.  
  30586.  
  30587.  Remarks
  30588.  The  GetMaxFonts procedure uses the following arguments:
  30589.  
  30590. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  30591.  Argument                                Description
  30592.  ────────────────────────────────────────────────────────────────────────────
  30593.   maxregistered%                         An integer that is the maximum
  30594.                                          number of fonts that can be
  30595.                                          registered.
  30596.  
  30597.   maxloaded%                             An integer that is the maximum
  30598.                                          number of fonts that can be loaded.
  30599.  Argument                                Description
  30600.  ────────────────────────────────────────────────────────────────────────────
  30601.                                         number of fonts that can be loaded.
  30602.  
  30603.  
  30604.  
  30605.  
  30606.  
  30607.   GetMaxFonts returns the current number of fonts that can be registered and
  30608.  loaded as set in the  SetMaxFonts routine. The default is 10.
  30609.  
  30610.  See Also
  30611.   GetTotalFonts,  SetMaxFonts
  30612.  
  30613.  
  30614.  
  30615.  GetRFontInfo Sub
  30616.  
  30617.  Action
  30618.  Gets the font information on the currently registered font.
  30619.  
  30620.  Syntax
  30621.   GetRFontInfo ( n%, fontinfo)
  30622.  
  30623.  
  30624.  Remarks
  30625.  The  GetRFontInfo procedure uses the following arguments:
  30626.  
  30627. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  30628.  Argument                                Description
  30629.  ────────────────────────────────────────────────────────────────────────────
  30630.   n%                                     The number of the registered font.
  30631.  
  30632.   fontinfo                               A variable of type FontInfo that
  30633.                                          receives the font-header
  30634.                                          information.
  30635.  
  30636.  
  30637.  
  30638.  
  30639.  
  30640.  The FontInfo data structure type is defined as follows:
  30641.  
  30642.  FontInfo
  30643.  TYPE FontInfo
  30644.  FontNumASINTEGER
  30645.  AscentASINTEGER
  30646.  PointsASINTEGER
  30647.  PixWidthASINTEGER
  30648.  PixHeightASINTEGER
  30649.  LeadingASINTEGER
  30650.  AvgWidthASINTEGER
  30651.  MaxWidthASINTEGER
  30652.  FileNameASSTRING   *   cMaxFileName
  30653.  FaceNameASSTRING   *   cMaxFaceName
  30654.  END TYPE
  30655.  
  30656.  The following list describes the parts of the FontInfo data structure:
  30657.  
  30658. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  30659.  Part                                    Description
  30660.  ────────────────────────────────────────────────────────────────────────────
  30661.  FontNum                                 The location of the font in the
  30662.  Part                                    Description
  30663.  ────────────────────────────────────────────────────────────────────────────
  30664.  FontNum                                 The location of the font in the
  30665.                                          registered list or the loaded list.
  30666.  
  30667.  Ascent                                  The pixel distance from the
  30668.                                          character baseline to the top of
  30669.                                          the character box.
  30670.  
  30671.  Points                                  The point size of the current font
  30672.                                          as defined in the  LoadFont%
  30673.                                          function.
  30674.  
  30675.  PixWidth                                The width of the character bitmap.
  30676.                                          A value of 0 specifies a
  30677.                                          proportional font. A non-zero
  30678.                                          value specifies the pixel width of
  30679.                                          the characters in a fixed-space
  30680.                                          font.
  30681.  
  30682.  PixHeight                               The height of the character bitmap.
  30683.  Part                                    Description
  30684.  ────────────────────────────────────────────────────────────────────────────
  30685. PixHeight                               The height of the character bitmap.
  30686.  
  30687.  Leading                                 The number of blank lines at the
  30688.                                          top of the character definition to
  30689.                                          act as leading between lines.
  30690.  
  30691.  AvgWidth                                The average width of characters in
  30692.                                          pixels.
  30693.  
  30694.  MaxWidth                                The pixel width of the widest
  30695.                                          character in the font.
  30696.  
  30697.  FileName                                The filename from which the font
  30698.                                          was loaded. The filename has the
  30699.                                          extension .FON.
  30700.  
  30701.  FaceName                                The name of the typeface (for
  30702.                                          example, Helvetica, Courier) taken
  30703.                                          from the filename.
  30704.  Part                                    Description
  30705.  ────────────────────────────────────────────────────────────────────────────
  30706.                                         from the filename.
  30707.  
  30708.  
  30709.  
  30710.  
  30711.  
  30712.  Note
  30713.  When using  GetRFontInfo, make sure you have access to the .FON file on disk
  30714.  so that it can find the FontNum, FileName, and FaceName values for the
  30715.  currently selected font.
  30716.  
  30717.  For more information on the elements of the variable type FontInfo, see the
  30718.  Microsoft Windows developer documentation on font file format.
  30719.  
  30720.  
  30721.  
  30722.  GTextWindow Sub
  30723.  
  30724.  Action
  30725.  Retains the logical coordinates of window boundaries. (See note below.)
  30726.  
  30727.  Syntax
  30728.  
  30729.   GTextWindow ( x1,  y1,  x2,  y2,  Scrn%)
  30730.  
  30731.  
  30732.  Remarks
  30733.  The  GTextWindow procedure uses the following arguments:
  30734.  
  30735. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  30736.  Argument                                Description
  30737.  ────────────────────────────────────────────────────────────────────────────
  30738.   x1                                     Integer containing the minimum X
  30739.                                          value (logical coordinate).
  30740.  
  30741.   y1                                     Integer containing the minimum Y
  30742.                                          value.
  30743.  
  30744.   x2                                     Integer containing the maximum X
  30745.                                          value.
  30746.  Argument                                Description
  30747.  ────────────────────────────────────────────────────────────────────────────
  30748.                                         value.
  30749.  
  30750.   y2                                     Integer containing the maximum Y
  30751.                                          value.
  30752.  
  30753.   Scrn%                                  Integer containing either cTRUE
  30754.                                          (used with WINDOW SCREEN statement
  30755.                                          to show Y values increase top to
  30756.                                          bottom) or cFALSE (used with
  30757.                                          WINDOW statement to show window Y
  30758.                                          values increase bottom to top).
  30759.  
  30760.   registered%                            The number of currently registered
  30761.                                          fonts.
  30762.  
  30763.   loaded%                                The number of currently loaded
  30764.                                          fonts.
  30765.  
  30766.  
  30767.  
  30768.  
  30769.  
  30770.  See Also
  30771.   GetMaxFonts,  SetMaxFonts
  30772.  
  30773.  
  30774.  
  30775.  LoadFont% Function
  30776.  
  30777.  Action
  30778.  Loads the font information from the .FON files or memory for the specified
  30779.  registered fonts and returns the number of fonts actually loaded.
  30780.  
  30781.  Syntax
  30782.   LoadFont% ( fontspec$)
  30783.  
  30784.  
  30785.  Remarks
  30786.  The argument  fontspec$ is a specification used to load one or more of the
  30787.  registered fonts. The specification for each font consists of one or more of
  30788.  the following:
  30789.  
  30790. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  30791.  Specification                           Description
  30792.  ────────────────────────────────────────────────────────────────────────────
  30793.  n #                                     Loads font number  # in the list
  30794.                                          of currently registered fonts.
  30795.  
  30796.  t  name                                 Specifies the desired font  name.
  30797.                                          (There must be a space between t
  30798.                                          and  name.)
  30799.  
  30800.  s #                                     Specifies point size  #. When s is
  30801.                                          specified, only the fonts designed
  30802.                                          for the screen mode specified by m
  30803.                                          are used.
  30804.  
  30805.  h #                                     Specifies pixel height  # of a
  30806.                                          font.
  30807.  
  30808.  m #                                     Specifies screen mode  #. This is
  30809.  Specification                           Description
  30810.  ────────────────────────────────────────────────────────────────────────────
  30811. m #                                     Specifies screen mode  #. This is
  30812.                                          used for sizing fonts with s.  The
  30813.                                          default is the current screen mode.
  30814.  
  30815.  b                                       Selects the best fit based on the
  30816.                                          size specified in the s or h
  30817.                                          options. The specification b is
  30818.                                          ignored with vector fonts because
  30819.                                          they can be any size.
  30820.  
  30821.  
  30822.  
  30823.  
  30824.  
  30825. ╓┌────┌──────────────────────────────────────────────────────────────────────╖
  30826.  ────────────────────────────────────────────────────────────────────────────
  30827.  f    Loads only a single fixed-space font.
  30828.  p    Loads only the first proportionally spaced font that registered.
  30829.  
  30830.  
  30831.  
  30832.  
  30833.  Any previously loaded fonts are removed from memory. To load more than one
  30834.  font, multiple specifications are needed.
  30835.  
  30836.  Multiple specifications are separated by slash characters, and blanks are
  30837.  ignored. If the specifications do not match a registered font or if an
  30838.  invalid font is specified, then font number one (n1) is used.
  30839.  
  30840.  The  LoadFont% function loads the character-bit maps into the loaded fonts
  30841.  array. This array corresponds to the registered fonts array which stores the
  30842.  font-header information. Before you can use the  LoadFont% function, you
  30843.  must use the  RegisterFont% function.
  30844.  
  30845.  Note
  30846.  The total size of the font data should be less than or equal to 64K unless
  30847.  the /AH option is used when invoking QBX. The /AH option allows the use of
  30848.  larger arrays.
  30849.  
  30850.  For more information on selecting a particular loaded font, see the
  30851.  SelectFont procedure.
  30852.  
  30853.  Example
  30854.  
  30855.  The following example demonstrates the  LoadFont% function.
  30856.  
  30857.  r% = RegisterFonts("tmsrb.fon")' r% should = 6 after call.
  30858.  l% = LoadFont("h8/h12/h24")' l% should = 3 after call.
  30859.  ' 3 fonts (8,12,24 pts) will be loaded and usable.
  30860.  SelectFont 2' The 12-point font is current.
  30861.  SetGTextColor 10' Color 10 is light green.
  30862.  textlen% = OutGText (1,1,"TmsRmn 12-point")
  30863.  END
  30864.  
  30865.  
  30866.  Note that to load fonts according to their order in the font file, l% would
  30867.  take the form:
  30868.  
  30869.  
  30870.  l% = LoadFont%("n1,n3,n6")' Load the first, third, and sixth fonts.
  30871.  
  30872.  
  30873.  
  30874.  
  30875.  OutGText% Function
  30876.  
  30877.  Action
  30878.  Outputs text in the currently selected font, using the current graphics
  30879.  color at the current graphics cursor position, and returns the pixel length
  30880.  of the character output.
  30881.  
  30882.  Syntax
  30883.   OutGText% ( x,  y,
  30884.  txt$)
  30885.  
  30886.  
  30887.  
  30888.  Remarks
  30889.  The  OutGText% function uses the following arguments:
  30890.  
  30891. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  30892.  Argument                                Description
  30893.  Argument                                Description
  30894.  ────────────────────────────────────────────────────────────────────────────
  30895.   x                                      A single-precision number that is
  30896.                                          the x coordinate of the upper-left
  30897.                                          boundary of the first character.
  30898.  
  30899.   y                                      A single-precision number that is
  30900.                                          the y coordinate of the upper-left
  30901.                                          boundary of the first character.
  30902.  
  30903.   txt$                                   Text string to output.
  30904.  
  30905.  
  30906.  
  30907.  
  30908.  
  30909.  After the  OutGText% function has completed outputting the text, it returns
  30910.  the pixel length of the character string, and  x and  y are changed to the
  30911.  upper-right position of the last character.
  30912.  
  30913.  
  30914.  
  30915.  RegisterFonts% function
  30916.  
  30917.  Action
  30918.  Registers the font-header information from a specified .FON file and returns
  30919.  the number of fonts registered.
  30920.  
  30921.  Syntax
  30922.   RegisterFonts% ( filename$)
  30923.  
  30924.  
  30925.  Remarks
  30926.  The  RegisterFonts% procedure registers the font-header information from the
  30927.  .FON file specified in  filename$. The font-header information is stored in
  30928.  the registered-fonts array. This array corresponds to the loaded-fonts array
  30929.  which contains the character-bit maps of the fonts stored in the .FON file.
  30930.  Because an .FON file may hold one or more fonts,  RegisterFonts% returns the
  30931.  number of fonts registered by the function.
  30932.  
  30933.  This procedure will register any number of fonts up to the maximum set with
  30934.  the  SetMaxFonts procedure or to the limit of available memory.
  30935.  
  30936.  
  30937.  Note
  30938.  When using the  RegisterFonts% procedure, be sure you have access to the
  30939.  .FON file on disk so that it can find the filename of the currently selected
  30940.  font.
  30941.  
  30942.  For more information on loading the fonts, see the  LoadFont% procedure.
  30943.  
  30944.  
  30945.  
  30946.  RegisterMemFont% function
  30947.  
  30948.  Action
  30949.  Registers the font-header information of fonts that reside in memory and
  30950.  returns the number of fonts registered.
  30951.  
  30952.  Syntax
  30953.   RegisterMemFont% ( fontseg%,  fontoffset%)
  30954.  
  30955.  
  30956.  Remarks
  30957.  The  RegisterMemFont% procedure uses the following arguments:
  30958.  
  30959. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  30960.  Argument                                Description
  30961.  ────────────────────────────────────────────────────────────────────────────
  30962.   fontseg%                               An integer that is the segment
  30963.                                          address of the in-memory font.
  30964.  
  30965.   fontoffset%                            An integer that is the offset
  30966.                                          address of the in-memory font..
  30967.  
  30968.  
  30969.  
  30970.   SelectFont ( n)
  30971.  
  30972.  
  30973.  
  30974.  Remarks
  30975.  The argument  n contains the number of the loaded font that is selected and
  30976.  becomes the active font.
  30977.  
  30978.  If  n is greater than the maximum number of loaded fonts, the procedure
  30979.  automatically selects the font number that corresponds to the remainder from
  30980.  the modular division between  n and the number of currently loaded fonts.
  30981.  For example, if  n is 12 and the maximum of loaded fonts is 8, then the font
  30982.  number selected is 4.
  30983.  
  30984.  
  30985.  
  30986.  SetGCharSet Sub
  30987.  
  30988.  Action
  30989.  Sets the character set used in subsequent graphics characters.
  30990.  
  30991.  Syntax
  30992.   SetGCharSet  (charset%)
  30993.  
  30994.  
  30995.  Remarks
  30996.  The argument  charset% is the character set used in mapping input characters
  30997.  to output characters.  charset% is an integer with two possible values:
  30998.  cIBMChars and cWindowsChars. The two values are constants defined in the
  30999.  FONTB.BI file.
  31000.  
  31001.  
  31002.  
  31003.  SetGTextColor Sub
  31004.  
  31005.  Action
  31006.  Sets the character color used in subsequent graphic characters.
  31007.  
  31008.  Syntax
  31009.   SetGTextColor ( color%)
  31010.  
  31011.  
  31012.  Remarks
  31013.  The argument  color% is  an integer that is the pixel value of the color to
  31014.  use in graphic characters.
  31015.  
  31016.  
  31017.  
  31018.  SetGTextDir Sub
  31019.  
  31020.  Action
  31021.  Sets the horizontal or vertical orientation of graphics characters.
  31022.  
  31023.  Syntax
  31024.   SetGTextDir (dir%)
  31025.  
  31026.  
  31027.  Remarks
  31028.  The argument  dir% is an integer that specifies a direction for the graphics
  31029.  characters. Possible values for  dir%, and the resulting character
  31030.  orientation (counterclockwise rotation) are:
  31031.  
  31032. ╓┌────────────┌──────────────────────────────────────────────────────────────╖
  31033.  Value        Character direction
  31034.  ────────────────────────────────────────────────────────────────────────────
  31035.  0            0 degrees (no rotation)
  31036.  1            90 degrees (top of character is to the left)
  31037.  2            180 degrees (characters are inverted)
  31038.  3            270 degrees (top of character is to the right)
  31039.  
  31040.  
  31041.  
  31042.  
  31043.  
  31044.  SetMaxFonts Sub
  31045.  
  31046.  Action
  31047.  Sets the maximum number of fonts that are allowed to be registered and
  31048.  loaded.
  31049.  
  31050.  Syntax
  31051.   SetMaxFonts ( maxregistered%,  maxloaded%)
  31052.  
  31053.  
  31054.  Remarks
  31055.  The  SetMaxFonts procedure uses the following arguments:
  31056.  
  31057. ╓┌───────────────────────────────────────┌───────────────────────────────────╖
  31058.  Argument                                Description
  31059.  ────────────────────────────────────────────────────────────────────────────
  31060.   maxregistered%                         An integer that specifies the
  31061.  Argument                                Description
  31062.  ────────────────────────────────────────────────────────────────────────────
  31063.   maxregistered%                         An integer that specifies the
  31064.                                          maximum number of fonts that can
  31065.                                          be registered.
  31066.  
  31067.   maxloaded%                             An integer that specifies the
  31068.                                          maximum number of fonts that can
  31069.                                          be loaded.
  31070.  
  31071.  
  31072.  
  31073.  
  31074.  
  31075.  The  SetMaxFonts procedure allocates a maximum number of font-header
  31076.  elements to hold font information. The font information is registered when
  31077.  the  RegisterFonts% function is called. Therefore,  SetMaxFont is called
  31078.  prior to  RegisterFonts% or  LoadFont%. If  SetMaxFonts is not called, the
  31079.  default number is 10.
  31080.  
  31081.   SetMaxFonts acts as a complete reinitialization by removing any previously
  31082.  registered or loaded fonts from memory and then setting the new maximum
  31083.  limits of fonts that can be loaded or registered.
  31084.  
  31085.  
  31086.  
  31087.  UnRegisterFonts Sub
  31088.  
  31089.  Action
  31090.  Removes registered fonts from memory.
  31091.  
  31092.  Syntax
  31093.   UnRegisterFonts ( )
  31094.  
  31095.  
  31096.  Remarks
  31097.  The  UnRegisterFonts procedure reduces the array storing the font headers to
  31098.  one element, thereby removing the registered fonts from memory.
  31099.  
  31100.  Note
  31101.  When you use  UnRegisterFonts to remove the font-header information from the
  31102.  registered fonts array, you reduce the array to only one position.
  31103.  Therefore, if you want to re-register fonts, you must call  SetMaxFonts to
  31104.  reset the maximum number of fonts that can be registered; for example,
  31105.  SetMaxFonts(6,6), before calling the  RegisterFonts% function.
  31106.  
  31107.  
  31108.  
  31109.  
  31110.  
  31111.   The User Interface Toolbox
  31112.  
  31113.  The User Interface toolbox is a group of BASIC procedures and
  31114.  assembly-language routines that is included with Microsoft BASIC. Together,
  31115.  these tools allow you to add professional-looking windows and menus to your
  31116.  programs.
  31117.  
  31118.  The User Interface toolbox includes many of the user interface features of
  31119.  the QBX programming environment. When you use the QBX user interface, you
  31120.  are using many of the features that the toolbox can bring to your own
  31121.  programs.
  31122.  *    You can define pull-down menus to support:
  31123.       Color
  31124.       Mouse
  31125.       Access keys
  31126.       Shortcut keys
  31127.  
  31128.  *    You can choose these options in overlapping character-based windows:
  31129.       Color
  31130.       Closable windows
  31131.       Movable windows
  31132.       Resizable windows
  31133.       Title bars
  31134.       Window-border character
  31135.  
  31136.  *    You can use list boxes and alert boxes.
  31137.  
  31138.  *    You can specify dialog boxes with:
  31139.       Edit fields
  31140.       Option buttons
  31141.       Command buttons
  31142.       Area buttons
  31143.  
  31144.  
  31145.  The BASIC source code to all of the toolbox procedures is provided with
  31146.  Microsoft BASIC. You can use these procedures as listed, or alter or expand
  31147.  their functionality to meet your requirements. Even though most of the
  31148.  procedures are written in BASIC, they are fast enough for most applications.
  31149.  There is also an assembly-language object routine, UIASM.OBJ, to ensure that
  31150.  you get quick response from your user-interface design. This
  31151.  assembly-language module is linked into the libraries and Quick libraries
  31152.  created from the User Interface toolbox.
  31153.  
  31154.  What Makes Up the User Interface Toolbox
  31155.  
  31156.  The User Interface toolbox actually consists of four parts - that is, four
  31157.  separate BASIC source-code files - and an include file for each. The files
  31158.  are:
  31159.  
  31160.  *    MENU.BAS, MENU.BI
  31161.  *    WINDOW.BAS, WINDOW.BI
  31162.  *    MOUSE.BAS, MOUSE.BI
  31163.  *    GENERAL.BAS, GENERAL.BI
  31164.  
  31165.  In each case, the .BAS file contains the actual code for the procedures and
  31166.  the .BI file contains user-defined type definitions and procedure
  31167.  declarations used in the .BAS file.
  31168.  
  31169.  The following discussion briefly explains the contents of each part of the
  31170.  User Interface toolbox.
  31171.  
  31172.  Menus
  31173.  The MENU.BAS source-code file contains all the procedures that let you
  31174.  create custom menus in your programs. These procedures are dependent on the
  31175.  other parts of the User Interface toolbox (GENERAL.BAS and MOUSE.BAS). If
  31176.  you use the procedures in MENU.BAS, you must include GENERAL.BI, MOUSE.BI,
  31177.  and MENU.BI in your program so you have the proper declarations and
  31178.  definitions. In addition to procedure declarations, the header file MENU.BI
  31179.  contains definitions of several user-defined types that are used in global
  31180.  variables to store menu configuration information.
  31181.  
  31182.  A more detailed explanation of menus and their application is described in
  31183.  the MENU.BAS section below.
  31184.  
  31185.  Windows
  31186.  The WINDOW.BAS source-code file contains the procedures that let you create
  31187.  custom character-based windows in your programs. WINDOW.BAS is dependent on
  31188.  all the other parts of the User Interface toolbox; therefore, when you use
  31189.  the procedures in WINDOW.BAS, you must include GENERAL.BI, MOUSE.BI,
  31190.  MENU.BI, and WINDOW.BI so that all declarations and definitions on which
  31191.  WINDOW.BAS depends are available.
  31192.  
  31193.  The header file WINDOW.BI contains procedure declarations along with the
  31194.  definitions of user-defined types. These user-defined types are used to
  31195.  store information about the characteristics of windows, buttons, and edit
  31196.  fields.
  31197.  
  31198.  
  31199.  Mouse
  31200.  The MOUSE.BAS source-code file provides mouse support. The procedures in
  31201.  this code can be used by themselves if need be, but they were designed as an
  31202.  integral part of the User Interface toolbox. The routines specifically
  31203.  support the Microsoft Mouse. A Microsoft Mouse and driver are recommended.
  31204.  However, the procedures support any pointing device with a 100 percent
  31205.  Microsoft-Mouse-compatible driver. A Microsoft driver (MOUSE.COM) is shipped
  31206.  with BASIC.
  31207.  
  31208.  If you use the procedures in MOUSE.BAS, you must include GENERAL.BI and
  31209.  MOUSE.BI in your program so you will have the proper declarations and
  31210.  definitions. The header file MOUSE.BI includes procedure declarations for
  31211.  the MOUSE.BAS file.
  31212.  
  31213.  
  31214.  General
  31215.  The GENERAL.BAS source-code file contains a number of general purpose
  31216.  character-based routines that are used in both the MENU.BAS and WINDOW.BAS
  31217.  files. While these files can be used by themselves, they are intended to
  31218.  support the other procedures in the User Interface toolbox. If you use any
  31219.  of the procedures in GENERAL.BAS, you must include the header file,
  31220.  GENERAL.BI.
  31221.  
  31222.  The header file GENERAL.BI contains a user-defined type definition (RegType)
  31223.  that is used with the Interrupt routine to access DOS interrupt services for
  31224.  mouse support. This DOS interrupt also returns the shift state of special
  31225.  keys, and scrolls screen areas. GENERAL.BI contains a number of global
  31226.  constant definitions that apply throughout the User Interface toolbox. These
  31227.  definitions are described in the following table:
  31228.  
  31229.  Constant    Value    Comment
  31230.  
  31231.  FALSE         0
  31232.  TRUE         -1
  31233.  MINROW        2      Minimum number of rows on screen
  31234.  MAXROW       25      Maximum number of rows on screen
  31235.  MINCOL        1      Minimum number of columns on screen
  31236.  MAXCOL       80      Maximum number of columns on screen
  31237.  MAXMENU      10      Maximum number of menus on menu bar
  31238.  MAXITEM      20      Maximum number of items on a menu
  31239.  MAXWINDOW    10      Maximum number of windows on screen
  31240.  MAXBUTTON    50      Maximum number of buttons on screen
  31241.  MAXEDITFIELD 20      Maximum number of edit fields on screen
  31242.  MAXHOTSPOT   20      Maximum number of active areas on screen
  31243.  
  31244.  Note
  31245.  ----
  31246.  An active area is defined as any area that can be selected by the user,
  31247.  including all types of buttons and edit fields, and any of the special
  31248.  characters used to affect windows.
  31249.  
  31250.  
  31251.  
  31252.  How to Use the Toolbox in Your Programs
  31253.  
  31254.  You can incorporate the User Interface toolbox into your programs in three
  31255.  ways. The first is to simply include the source-code files you plan to use
  31256.  in your program. For each source-code file you include, be sure to also
  31257.  include the associated .BI file. Use the $INCLUDE metacommand to include
  31258.  external files in your program.
  31259.  
  31260.  The second way is to load each BASIC source-code file as a separate module
  31261.  and use a Quick library only for the assembly-language routines. You should
  31262.  use this method if you are planning to alter or expand the functionality of
  31263.  the User Interface toolbox. Create the Quick library you need with the
  31264.  following command:
  31265.  
  31266.  LINK /Q UIASM.OBJ QBX.LIB, UIASM.QLB,,QBXQLB.LIB;
  31267.  
  31268.  The final method - and most practical when creating stand-alone programs -
  31269.  is to create a Quick library that uses the procedures in the BASIC
  31270.  source-code files and the assembly-language files. This is somewhat more
  31271.  difficult, but is still quite easy. If you chose to have Quick libraries
  31272.  created when you first installed BASIC, you already have the Quick library
  31273.  you need. If you didn't, you'll have to make it yourself. To begin, be sure
  31274.  that you are in the QBX directory where all of the .LIB files that came with
  31275.  the program are located.
  31276.  
  31277.  Creating a complete Quick library involves several steps. First you'll have
  31278.  to create a Quick library that includes needed procedures that are already
  31279.  in the QBX libraries (QBX.QLB and QBX.LIB) plus the User Interface toolbox
  31280.  object file, UIASM.OBJ. You can do this at the system prompt with the
  31281.  following command:
  31282.  
  31283.  LINK /Q UIASM.OBJ QBX.LIB, UIASM.QLB,,QBXQLB.LIB;
  31284.  
  31285.  Next, create the parallel .LIB library using the same files you just used to
  31286.  make the Quick library. Use the following command:
  31287.  LIB UIASM.LIB+UIASM.OBJ+QBX.LIB;
  31288.  
  31289.  Once you've created the first two libraries, you can create the libraries
  31290.  that include not only the assembly-language routines, but the BASIC
  31291.  procedures as well. The easiest way is to do this from the QBX programming
  31292.  environment. Start QBX with the /L option and specify the Quick library that
  31293.  you just created, as follows:
  31294.  
  31295.  QBX /L UIASM.QLB
  31296.  
  31297.  Once you are in the QBX programming environment, use the File menu to load
  31298.  each of the individual files you want to include in your User Interface
  31299.  toolbox library. For example, if you want to use menus in your program, load
  31300.  GENERAL.BAS, MOUSE.BAS, and MENU.BAS. GENERAL.BAS and MOUSE.BAS are required
  31301.  because of dependencies that exist between the components of the User
  31302.  Interface toolbox. If you want windows, load GENERAL.BAS, MOUSE.BAS,
  31303.  MENU.BAS, and WINDOW.BAS.
  31304.  
  31305.  With all of the files loaded, choose Make Library from the Run menu. When
  31306.  prompted for a library name, use the name UITBEFR.QLB. Press Return and two
  31307.  libraries will be created for you. The first is the Quick library that you
  31308.  will use whenever you want to incorporate menus into your programs that run
  31309.  in QBX. The second is the parallel .LIB file that will allow you to create a
  31310.  stand-alone .EXE file from your BASIC program.
  31311.  
  31312.  If you change any of the BASIC code that comprises the User Interface
  31313.  toolbox, you can relink those object modules and create new libraries and
  31314.  Quick libraries as needed. More complete information about creating
  31315.  libraries and using mixed-language programming can be found in Chapter 18,
  31316.  "Using LINK and LIB" in the Programmer's Guide.
  31317.  
  31318.  If you use a library or Quick library that contains procedures from one or
  31319.  more of the User Interface toolbox source-code files, you must include the
  31320.  .BI file for that source-code file into your program before you call any of
  31321.  the library's procedures. If you include a complete source-code file, it is
  31322.  not necessary to include the .BI file, because an $INCLUDE metacommand is
  31323.  already in the source-code file. However, if you include the source-code
  31324.  file in your program, you must ensure that you also include any other files
  31325.  (either .BAS or .BI) that the included code might depend on. For example, if
  31326.  you use WINDOW.BAS, you must also include all of the other parts of the User
  31327.  Interface toolbox. The procedures in WINDOW.BAS depend on definitions,
  31328.  declarations, and procedures in each of the other parts.
  31329.  
  31330.  
  31331.  Detailed Description
  31332.  The following sections contain a detailed descriptions of each of the
  31333.  individual parts of the User Interface toolbox. Because the User Interface
  31334.  toolbox is character based, many procedures require row and column
  31335.  coordinates as arguments. Where these are required, the following
  31336.  definitions apply:
  31337.  
  31338.  row%, col%     An integer pair that describes a screen position.
  31339.  row1%, col1%   An integer pair that describes the upper-left corner of an
  31340.  area.
  31341.  row2%, col 2%  An integer pair that describes the lower-right corner of an
  31342.  area.
  31343.  
  31344.  
  31345.  Note
  31346.  ----
  31347.  The row% and col% coordinates can be actual screen coordinates. However,
  31348.  often they are coordinates that are relative to the upper-left corner of the
  31349.  current window.
  31350.  
  31351.  
  31352.  MENU.BAS
  31353.  Using the procedures in MENU.BAS is straightforward. In most cases, the
  31354.  demonstration program UIDEMO.BAS provides enough information for a BASIC
  31355.  programmer of some experience to get started. However, a few notes of
  31356.  introduction are in order.
  31357.  
  31358.  When you use the procedures in MENU.BAS, you must provide the following
  31359.  global array declarations in your program, in the order shown:
  31360.  
  31361.  COMMON SHARED /uitools/GloMenu AS MenuMiscType
  31362.  COMMON SHARED /uitools/GloTitle() AS MenuTitleType
  31363.  COMMON SHARED /uitools/GloItem() AS MenuItemType
  31364.  DIM GloTitle(MAXMENU) AS MenuTitleType
  31365.  DIM GloItem(MAXMENU, MAXITEM) AS MenuItemType
  31366.  
  31367.  The order is important because the block defined by COMMON in the Quick
  31368.  library must agree with the block defined by COMMON in the programming
  31369.  environment. These global arrays are used to store information about the
  31370.  menus you define.
  31371.  
  31372.  As previously mentioned, the menus in the User Interface toolbox work like
  31373.  those in the QBX programming environment. Menu titles are displayed on a
  31374.  menu bar that extends across the top of the screen in row 1. Associated with
  31375.  each menu are one or more menu items. From the programmer's standpoint,
  31376.  menus are numbered from left to right, beginning at 1. Menu items -that is,
  31377.  those choices associated with each menu - are numbered from top to bottom,
  31378.  also beginning at 1. For any given menu, menu item 0 is always the menu
  31379.  title.
  31380.  
  31381.  The MenuColor procedure lets you select the color scheme for your menus. A
  31382.  single MenuSet statement is all that is required to set up each menu title
  31383.  on the menu bar or each menu item associated with a menu.
  31384.  
  31385.  Menus can be selected with the mouse - by pointing and clicking - or with
  31386.  the keyboard, by pressing the Alt key and the highlighted letter in the
  31387.  desired menu title. When a menu is selected, the choices associated with
  31388.  that menu will pull down, or drop, from the menu bar so that you can see the
  31389.  choices available. When a pull-down menu is displayed, menu items can be
  31390.  chosen by pointing and clicking with the mouse, or pressing the highlighted
  31391.  key associated with that choice. The key combinations used in the latter
  31392.  selection technique are called access keys. Access keys consist of a series
  31393.  of menu-item-selection keystrokes; each series begins by pressing the Alt
  31394.  key.
  31395.  
  31396.  You also can set up shortcut keys to use in lieu of the mouse or the regular
  31397.  access keys. Shortcut keys can use any character or extended character,
  31398.  except those that use the Alt key. For example, you can use Ctrl+X,
  31399.  Ctrl+F10, or simply F3). To enable a shortcut key, use a ShortCutKeySet
  31400.  statement to identify the menu and menu item with the definition of the
  31401.  short-cut key.
  31402.  
  31403.  Before actually building your menus, you need to initialize global arrays to
  31404.  speed up menu response. Use the MenuInit procedure to initialize the arrays
  31405.  you declared and initialize the mouse.
  31406.  
  31407.  The following code fragment illustrates how to put together a short menu
  31408.  with one title, two item choices and a means of exiting the menu:
  31409.  
  31410.  MenuInit             ' Initialize everything, including the mouse.
  31411.  MenuSet 1,0,1,"Menu Title",1     ' Set up menu title.
  31412.  MenuSet 1,1,1,"Selection 1 F1",11     ' Set up first selection.
  31413.  MenuSet 1,2,1,"Selection 2 F2",11     ' Last parameter determines
  31414.                                  ' highlight.
  31415.  MenuSet 1,3,1,"-",1            ' Make a line across the menu.
  31416.  MenuSet 1,4,1,"Exit Ctrl-X",2     ' Set up way to get out.
  31417.  
  31418.  ShortCutKeySet 1,1,CHR$(0)+CHR$(59)     ' Set F1 as shortcut key for 1.
  31419.  ShortCutKeySet 1,2,CHR$(0)+CHR$(60)
  31420.  ShortCutKeySet 1,4,CHR$(24)     ' Set Ctrl-X for Exit.
  31421.  
  31422.  MenuColor 14,1,12,8,14,3,12     ' Specify color scheme
  31423.  MenuPreProcess                 ' Do all necessary calculations.
  31424.  MenuShow                        ' Display the menu.
  31425.  MouseShow                        ' Make mouse cursor visible.
  31426.  
  31427.  
  31428.  
  31429.  Notice that the menu title is described as menu 1, item 0. Item 0 means that
  31430.  the MenuSet statement specifies a menu title, not a menu item. Numbers from
  31431.  1 through 4 are the remaining selections. Item 3 is special. It's not really
  31432.  a selection item. The hyphen character (-) causes a bar to be placed across
  31433.  the pull-down menu. It is useful for breaking up functional groupings of
  31434.  menu selections. You can't select it, so you should remember to use a SELECT
  31435.  CASE statement that excludes that item number when processing the
  31436.  selections. See the demonstration program UIDEMO.BAS for a working example.
  31437.  
  31438.  Also notice that within the text for Selection 1, F1 is shown to the right.
  31439.  F1 is the shortcut key for Selection 1 that is programmed using the first
  31440.  ShortCutKeySet statement. The extended keyboard code for the F1 key is
  31441.  CHR$(0) + CHR$(59).
  31442.  Use MenuColor to set up the colors for your menus, the highlighted colors to
  31443.  use when an item is selected, and the highlighted characters to use when
  31444.  choosing a menu item from the keyboard.
  31445.  MenuPreProcess performs the necessary calculations and builds indexes that
  31446.  help speed up menu execution. MenuShow actually displays the menu bar on the
  31447.  screen. The three-dimensional shadow and other programming chores are
  31448.  handled for you automatically. Once the menu bar is displayed, the call to
  31449.  MouseShow makes the mouse cursor visible.
  31450.  
  31451.  After you've displayed your menus, you want to be able to have the program
  31452.  translate the available choices into action. Processing menu selections is
  31453.  also very straightforward. The MenuInkey$ procedure within a WHILE...WEND
  31454.  control-flow structure serves well to poll user input. The following code
  31455.  fragment illustrates how to process user input and translate a user's choice
  31456.  to a desired action:
  31457.  
  31458.  
  31459.  Finished = FALSE
  31460.  WHILE NOT Finished
  31461.      kbd$ = MenuInkey$         ' Monitor all user input.
  31462.      SELECT CASE kbd$            ' See what the user entered.
  31463.      CASE "menu"                ' If kbd$ = "menu".
  31464.          menu = MenuCheck(0)     ' Get menu number.
  31465.          item = MenuCheck(1)     ' Get item number.
  31466.          GOSUB HandleMenuEvent     ' Handle selection.
  31467.      CASE ELSE
  31468.          .
  31469.          .                        ' If kbd$ = anything else.
  31470.          .
  31471.      END SELECT
  31472.  WEND
  31473.  
  31474.  HandleMenuEvent:
  31475.  SELECT CASE menu
  31476.  CASE 1                         ' Handles Menu 1 .
  31477.      SELECT CASE item
  31478.      CASE 1
  31479.          Selection1Routine        ' Handle selection 1.
  31480.      CASE 2
  31481.          Selection2Routine        ' Handle selection 2.
  31482.      CASE 4
  31483.          Finished = TRUE        ' Handle Exit.
  31484.      END SELECT
  31485.  END SELECT
  31486.  RETURN
  31487.  
  31488.  
  31489.  
  31490.  The code shown above processes keyboard input and mouse input with
  31491.  MenuInkey$. If you wanted to preclude any keyboard input, you could use
  31492.  MenuEvent instead of MenuInkey$, as follows:
  31493.  
  31494.  WHILE NOT Finished
  31495.      MenuEvent                    ' Monitor menu events only.
  31496.      IF MenuCheck(2) THEN
  31497.          menu = MenuCheck(0)     ' Get menu number.
  31498.          item = MenuCheck(1)     ' Get item number.
  31499.          GOSUB HandleMenuEvent    ' Determine which item.
  31500.      END IF
  31501.      .                            ' What to do if MenuCheck(2)
  31502.      .                            ' hasn't changed.
  31503.      .
  31504.  WEND
  31505.  
  31506.  
  31507.  The preceding information is intended to give you an overview of how the
  31508.  menus work. With this information and the detailed information provided for
  31509.  each procedure, you should be able to incorporate menus into your BASIC
  31510.  applications. Be sure to see the example code in UIDEMO.BAS that
  31511.  demonstrates how most of the procedures are used.
  31512.  A description of each procedure that comprises MENU.BAS is next.
  31513.  
  31514.  
  31515.  
  31516.  MenuCheck FUNCTION
  31517.  
  31518.  Action
  31519.  Returns an integer that indicates which menu selection, if any, was made
  31520.  following a menu or shortcut-key event.
  31521.  
  31522.  
  31523.  Syntax
  31524.  variablename% = MenuCheck(action%)
  31525.  
  31526.  Remarks
  31527.  The MenuCheck procedure uses the following arguments:
  31528.  
  31529.  variablename%
  31530.  -------------
  31531.  Any BASIC variable name, including the name of a record variable or record
  31532.  element.
  31533.  
  31534.  action%
  31535.  -------
  31536.  An integer that identifies the specific information requested. Values are as
  31537.  follows:
  31538.  
  31539.  Value     Associated action/Return value
  31540.  
  31541.  0        Checks to see if a menu item was selected since
  31542.               MenuCheck was last called.
  31543.               If a menu item was selected, MenuCheck returns the number of
  31544.  the menu and sets the global variables so that when  MenuCheck(1) is called,
  31545.  the appropriate menu item number is returned. If no menu item was selected,
  31546.  returns 0.
  31547.  1        Returns the matching menu item of the last menu selection.
  31548.  MenuCheck(1) is reset each after each call to MenuCheck(0).
  31549.  2        Returns true (-1) if menu item has been selected as of the last
  31550.  MenuCheck(0) call, or false (0) if not. If a selection has occurred, use
  31551.  MenuCheck(0) and MenuCheck(1) to determine what selection was made.
  31552.  MenuCheck(2) changes no values.
  31553.  
  31554.  The MenuCheck procedure simulates polling for a menu event. When a menu
  31555.  event occurs, global variables are set to their appropriate values.
  31556.  MenuCheck(0) then returns the menu number, or 0 if no menu was selected
  31557.  since the last call to MenuCheck.
  31558.  You can use MenuCheck to provide information about menu selection as
  31559.  follows:
  31560.  
  31561.  kbd$ = MenuInkey$
  31562.  SELECT CASE kbd$
  31563.  CASE "menu"
  31564.      menu = MenuCheck(0)
  31565.      item = MenuCheck(1)
  31566.      MouseHide
  31567.      PRINT menu, item
  31568.      MouseShow
  31569.  CASE ELSE
  31570.      PRINT kbd$
  31571.  END SELECT
  31572.  
  31573.  or
  31574.  
  31575.  MenuEvent
  31576.  IF MenuCheck(2) THEN
  31577.      menu = MenuCheck(0)
  31578.      item = MenuCheck(1)
  31579.      MouseHide
  31580.      PRINT menu, item
  31581.      MouseShow
  31582.  END IF
  31583.  
  31584.  See Also
  31585.  MenuEvent, MenuInkey$, ShortCutKeyEvent
  31586.  
  31587.  Example
  31588.  See the main loop of the code example UIDEMO.BAS for a practical
  31589.  implementation of the MenuCheck procedure.
  31590.  
  31591.  
  31592.  
  31593.  
  31594.  MenuColor SUB
  31595.  
  31596.  Action
  31597.  Assigns colors to the components of a menu.
  31598.  
  31599.  
  31600.  Syntax
  31601.  MenuColor fore%, back%, highlight%, disabled%, cursorfore%, cursorback%,
  31602.  cursorhi%
  31603.  
  31604.  Remarks
  31605.  The MenuColor procedure uses the following arguments:
  31606.  
  31607.  fore%
  31608.  -----
  31609.  An integer that defines menu foreground color (0 - 15).
  31610.  
  31611.  back%
  31612.  -----
  31613.  An integer that defines menu background color (0 - 7).
  31614.  
  31615.  highlight%
  31616.  ----------
  31617.  An integer that defines text color (0 - 15) of the access key character.
  31618.  
  31619.  disabled%
  31620.  ---------
  31621.  An integer that defines text color of disabled items (0 - 15).
  31622.  
  31623.  cursorfore%
  31624.  -----------
  31625.  An integer that defines the menu cursor foreground color (0 - 15).
  31626.  
  31627.  cursorback%
  31628.  -----------
  31629.  An integer that defines the menu cursor background color (0 - 7).
  31630.  
  31631.  cursorhi%
  31632.  ---------
  31633.  An integer that defines text color (0 - 15) of the access key character when
  31634.  the menu cursor is on that menu item.
  31635.  
  31636.  
  31637.  The values specified are placed into global variables. You can use any color
  31638.  scheme you choose within the range of available colors. Shadows that appear
  31639.  beneath menu windows are always black.
  31640.  
  31641.  Use MenuColor in your program to set up menu colors. Colors should be
  31642.  initialized before the menu is displayed the first time. If colors are not
  31643.  initialized, the default monochrome color scheme places the following
  31644.  integers into the argument list (in order): 0, 7, 15, 8, 7, 0, 15. This
  31645.  results in a monochrome display.
  31646.  
  31647.  If you change colors while your program is running, use MenuShow to show the
  31648.  changes.
  31649.  
  31650.  See Also:  MenuShow
  31651.  
  31652.  
  31653.  Example
  31654.  See the SetupMenu procedure in the code example UIDEMO.BAS for the specific
  31655.  implementation of the MenuColor procedure.
  31656.  
  31657.  
  31658.  
  31659.  
  31660.  MenuDo SUB
  31661.  
  31662.  Action
  31663.  Used internally by other procedures in MENU.BAS. Do not use or alter this
  31664.  procedure.
  31665.  
  31666.  
  31667.  Syntax
  31668.  MenuDo
  31669.  
  31670.  Remarks
  31671.  The MenuDo procedure is used only within MENU.BAS to process menu selection
  31672.  using the mouse and keyboard. To process menu selections in your program,
  31673.  you should use MenuInkey$ or MenuEvent, both of which use this procedure.
  31674.  
  31675.  If menus are enabled (using MenuOn), MenuDo takes control of the program
  31676.  when the user is selecting a menu item by any means. MenuDo controls the
  31677.  display and responds to user input until a selection has been made. Once a
  31678.  selection has been made, use the MenuCheck procedure to determine which menu
  31679.  item was selected.
  31680.  
  31681.  
  31682.  
  31683.  Warning
  31684.  -------
  31685.  Do not use or alter this procedure unless you are customizing the User
  31686.  Interface toolbox and you know how the use or alteration of this procedure
  31687.  will affect the operation of all other procedures in the toolbox.
  31688.  
  31689.  
  31690.  
  31691.  See Also:  MenuEvent, MenuInkey$
  31692.  
  31693.  
  31694.  
  31695.  
  31696.  MenuEvent SUB
  31697.  
  31698.  Action
  31699.  Monitors user input to determine if a menu item is being chosen, with either
  31700.  the mouse or the keyboard.
  31701.  
  31702.  
  31703.  Syntax
  31704.  MenuEvent
  31705.  
  31706.  Remarks
  31707.  If MenuEvent detects either a pressed Alt key or a mouse button press while
  31708.  the mouse cursor is on the top row, program control is transferred to
  31709.  MenuDo. MenuDo retains program control until an item is selected or the user
  31710.  aborts the menu process either by releasing the mouse button somewhere other
  31711.  than the top row or by pressing the Esc key. Once an item is selected, use
  31712.  MenuCheck to evaluate the selection.
  31713.  
  31714.  MenuEvent is used by the MenuInkey$ procedure to determine when a user has
  31715.  pressed the Alt key in conjunction with a keyboard selection or has selected
  31716.  a menu by moving the mouse cursor to the top row and pressing the left mouse
  31717.  button.
  31718.  
  31719.  
  31720.  See Also:  MenuInkey$, ShortCutKeyEvent
  31721.  
  31722.  
  31723.  
  31724.  
  31725.  MenuInit SUB
  31726.  
  31727.  Action
  31728.  Initializes global menu arrays and the mouse driver-servicing routines.
  31729.  
  31730.  
  31731.  Syntax
  31732.  MenuInit
  31733.  
  31734.  Remarks
  31735.  To enable mouse driver servicing, MenuInit calls MouseInit in MOUSE.BAS.
  31736.  
  31737.  Use MenuInit at or near the beginning of any program that uses the menu
  31738.  procedures provided in the User Interface toolbox. You must call MenuInit
  31739.  before any other menu procedures are used.
  31740.  
  31741.  See Also:  MenuPreProcess
  31742.  
  31743.  
  31744.  Example
  31745.  See the initialization section in the code example UIDEMO.BAS for a specific
  31746.  implementation.
  31747.  
  31748.  
  31749.  
  31750.  
  31751.  MenuInkey$ FUNCTION
  31752.  
  31753.  Action
  31754.  Performs a BASIC INKEY$ procedure, as well as both a MenuEvent procedure and
  31755.  a ShortCutKeyEvent procedure, returning a string.
  31756.  
  31757.  
  31758.  Syntax
  31759.  variablename$ = MenuInkey$
  31760.  
  31761.  Remarks
  31762.  The MenuInkey$ procedure operates exactly like the standard BASIC INKEY$
  31763.  procedure, but additionally performs MenuEvent and ShortCutKeyEvent
  31764.  procedures. If either a menu event or a shortcut-key event occurs,
  31765.  MenuInkey$ returns the word "menu" instead of the normally expected INKEY$
  31766.  value. When MenuInkey$ returns the word "menu," use MenuCheck to determine
  31767.  which menu and menu item was selected.
  31768.  
  31769.  
  31770.  See Also:  MenuDo, MenuEvent, ShortCutKeyEvent
  31771.  
  31772.  
  31773.  Example
  31774.  See the main loop in the code example UIDEMO.BAS for a specific
  31775.  implementation.
  31776.  
  31777.  
  31778.  
  31779.  
  31780.  MenuItemToggle SUB
  31781.  
  31782.  Action
  31783.  Toggles the state of of the selected menu item between 1 (enabled) and 2
  31784.  (enabled with a check mark) to indicate selection of the menu item.
  31785.  
  31786.  
  31787.  Syntax
  31788.  MenuItemToggle menu%, item%
  31789.  
  31790.  Remarks
  31791.  The MenuItemToggle procedure uses the following arguments:
  31792.  
  31793.  menu%
  31794.  -----
  31795.  An integer that identifies the position (from left to right) of the affected
  31796.  menu.
  31797.  
  31798.  item%
  31799.  -----
  31800.  An integer that identifies the number (from top to bottom) of the menu item
  31801.  within the menu.
  31802.  
  31803.  
  31804.  Use MenuItemToggle whenever you want to indicate that a particular menu item
  31805.  has been selected. It is not necessary to re-execute MenuPreProcess after
  31806.  performing a MenuItemToggle operation.
  31807.  
  31808.  See Also:  MenuPreProcess, MenuSetState
  31809.  
  31810.  
  31811.  
  31812.  
  31813.  MenuOff SUB
  31814.  
  31815.  Action
  31816.  Turns off menu and shortcut-key event processing.
  31817.  
  31818.  
  31819.  Syntax
  31820.  MenuOff
  31821.  
  31822.  Remarks
  31823.  Menu and shortcut-key event processing is disabled by setting the global
  31824.  variable GloMenu.MenuOn to FALSE (0). When menu event processing is off,
  31825.  MenuDo ignores any mouse or keyboard activity that would normally trigger a
  31826.  menu event.
  31827.  Use MenuOff anytime you want to turn menu event processing off.
  31828.  
  31829.  
  31830.  See Also:  MenuOn
  31831.  
  31832.  
  31833.  
  31834.  
  31835.  MenuOn SUB
  31836.  
  31837.  Action
  31838.  Turns on menu and shortcut-key event processing.
  31839.  
  31840.  
  31841.  Syntax
  31842.  MenuOn
  31843.  
  31844.  Remarks
  31845.  Menu and shortcut-key event processing is enabled by setting the global
  31846.  variable GloMenu.MenuOn to TRUE (-1). When menu event processing is on,
  31847.  MenuDo takes control of the display and the program when any mouse or
  31848.  keyboard activity occurs to trigger a menu event.
  31849.  
  31850.  Use MenuOn anytime you want to turn menu event processing back on after
  31851.  disabling with MenuOff.
  31852.  
  31853.  See Also:  MenuOff
  31854.  
  31855.  
  31856.  
  31857.  MenuPreProcess SUB
  31858.  
  31859.  Action
  31860.  Performs calculations and builds indexes so the menu procedures run faster.
  31861.  
  31862.  
  31863.  Syntax
  31864.  MenuPreProcess
  31865.  
  31866.  Remarks
  31867.  Use MenuPreProcess anytime MenuSet is performed one or more times, and any
  31868.  time the state of a menu item is changed using MenuSetState to change to or
  31869.  from the empty (-1) or  not displayed state. You must call MenuPreProcess
  31870.  anytime changes other than item selection changes are made to the menus.
  31871.  
  31872.  See Also:  MenuSet, MenuSetState
  31873.  
  31874.  
  31875.  Example
  31876.  See the SetupMenu procedure in the code example UIDEMO.BAS for a specific
  31877.  implementation.
  31878.  
  31879.  
  31880.  
  31881.  
  31882.  MenuSet SUB
  31883.  
  31884.  Action
  31885.  Defines the structure of your menus and defines the access keys associated
  31886.  with individual menu selections.
  31887.  
  31888.  
  31889.  Syntax
  31890.  MenuSet menu%, item%, state%, text$, accesskey%
  31891.  
  31892.  Remarks
  31893.  The MenuSet procedure uses the following arguments:
  31894.  
  31895.  menu%
  31896.  -----
  31897.  An integer that identifies the position (from left to right) of a menu on
  31898.  the menu bar.
  31899.  
  31900.  item%
  31901.  -----
  31902.  An integer that identifies the position (from top to bottom) of the menu
  31903.  item within the menu. If item% is 0, then text$ is the menu title. Other
  31904.  numbers indicate consecutive menu selections.
  31905.  
  31906.  state%
  31907.  ------
  31908.  An integer that indicates the state of the menu item:
  31909.  
  31910.  
  31911.  Value     Menu state that appears on menu
  31912.  
  31913.  0         Disabled - appears in color defined by the disabled% variable set
  31914.  with MenuColor.
  31915.  1         Enabled - this is the normal state.
  31916.  2         Enabled with a check mark.
  31917.  
  31918.  text$
  31919.  -----
  31920.  A string that is the name of the menu item. Menu titles are limited to 15
  31921.  characters; individual menu items are limited to 30 characters.
  31922.  
  31923.  accesskey%
  31924.  ----------
  31925.  An integer that indicates the position, within text$, of the character that
  31926.  is used to choose the menu item. This access key is highlighted in color
  31927.  defined by the highlight% variable set with MenuColor.
  31928.  
  31929.  Use MenuSet to initialize the contents of your menus. A separate MenuSet
  31930.  entry is required for each item, including the title on each menu. Each
  31931.  MenuSet entry defines either a menu title or a menu item that is to be
  31932.  displayed and the state of individual menu items. Menu items can be enabled,
  31933.  disabled, checked, or even made invisible. You also can specify access keys
  31934.  for menu items to allow one-stroke selection.
  31935.  
  31936.  MenuPreProcess must be executed after a series of MenuSet statements or any
  31937.  time the state of a menu item is changed using MenuSetState. MenuShow must
  31938.  be re-executed if any change to the menu title has occurred.
  31939.  
  31940.  See Also:  MenuPreProcess, MenuSetState, MenuShow
  31941.  
  31942.  
  31943.  Example
  31944.  See the SetupMenu procedure in the code example UIDEMO.BAS for a specific
  31945.  implementation.
  31946.  
  31947.  
  31948.  
  31949.  
  31950.  MenuSetState SUB
  31951.  
  31952.  Action
  31953.  Explicitly assigns the state of a menu item.
  31954.  
  31955.  
  31956.  Syntax
  31957.  MenuSetState menu%, item%, state%
  31958.  
  31959.  Remarks
  31960.  The MenuSetState procedure uses the following arguments:
  31961.  
  31962.  menu%
  31963.  -----
  31964.  An integer that identifies the position (from left to right) of the affected
  31965.  menu.
  31966.  
  31967.  item%
  31968.  -----
  31969.  An integer that identifies the number of the menu item within the menu.
  31970.  
  31971.  state%
  31972.  ------
  31973.  An integer that indicates the state of the menu item:
  31974.  -1    Empty - does not appear on menu.
  31975.   0    Disabled - appears in color defined by the disabled%  variable set
  31976.  with MenuColor.
  31977.   1    Enabled - this is the normal state.
  31978.   2    Enabled with a check mark.
  31979.  
  31980.  Use MenuSetState whenever you want to change the state of a particular menu
  31981.  item. You must re-execute MenuPreProcess if the state of the menu item
  31982.  changes to or from the empty or not displayed state.
  31983.  
  31984.  
  31985.  See Also:  MenuPreProcess
  31986.  
  31987.  
  31988.  
  31989.  
  31990.  MenuShow SUB
  31991.  
  31992.  Action
  31993.  Draws the menu bar across the top of the screen.
  31994.  
  31995.  
  31996.  Syntax
  31997.  MenuShow
  31998.  
  31999.  Remarks
  32000.  All menu titles that have been established with MenuSet are displayed. Use
  32001.  MenuShow to initially display your menu bar once it has been defined with
  32002.  MenuSet, and use it each time you change the menu bar.
  32003.  
  32004.  See Also:  MenuPreProcess
  32005.  
  32006.  
  32007.  Example
  32008.  See the initialization section in the code example UIDEMO.BAS for a specific
  32009.  implementation.
  32010.  
  32011.  
  32012.  
  32013.  
  32014.  ShortCutKeyDelete SUB
  32015.  
  32016.  Action
  32017.  Deletes the shortcut key associated with a particular menu item.
  32018.  
  32019.  
  32020.  Syntax
  32021.  ShortCutKeyDelete menu%, item%
  32022.  
  32023.  Remarks
  32024.  The ShortCutKeyDelete procedure uses the following arguments:
  32025.  
  32026.  menu%
  32027.  -----
  32028.  An integer that identifies the position (from left to right) of the affected
  32029.  menu.
  32030.  
  32031.  item%
  32032.  -----
  32033.  An integer that identifies the number of the menu item within the menu.
  32034.  Use ShortCutKeyDelete anytime you want to void shortcut keys that were
  32035.  previously established with ShortCutKeySet.
  32036.  
  32037.  See Also:  ShortCutKeyEvent, ShortCutKeySet
  32038.  
  32039.  
  32040.  
  32041.  
  32042.  ShortCutKeyEvent SUB
  32043.  
  32044.  Action
  32045.  Polls user input to determine if a menu item is being selected by using one
  32046.  of the shortcut keys.
  32047.  
  32048.  
  32049.  Syntax
  32050.  ShortCutKeyEvent kbd$
  32051.  
  32052.  Remarks
  32053.  The argument kbd$ is a string that contains a character entered at the
  32054.  keyboard. ShortCutKeyEvent checks kbd$ against a list of shortcut keys
  32055.  defined using ShortCutKeySet. If a match is found, the proper menu and item
  32056.  are selected. This duplicates exactly the functionality of the MenuEvent
  32057.  procedure. Use MenuCheck to determine which menu and item were selected.
  32058.  
  32059.  If you use MenuInkey$ in your program, ShortCutKeyEvent is automatically
  32060.  performed; if you use the BASIC INKEY$ procedure, you must explicitly call
  32061.  ShortCutKeyEvent to process shortcut-key events.
  32062.  
  32063.  
  32064.  See Also:  MenuCheck, ShortCutKeyDelete, ShortCutKeySet
  32065.  
  32066.  
  32067.  
  32068.  
  32069.  ShortCutKeySet SUB
  32070.  
  32071.  Action
  32072.  Assigns shortcut keys to individual menu items.
  32073.  
  32074.  
  32075.  Syntax
  32076.  ShortCutKeySet menu%, item%, kbd$
  32077.  
  32078.  Remarks
  32079.  The ShortCutKeySet procedure uses the following arguments:
  32080.  
  32081.  menu%
  32082.  -----
  32083.  An integer that identifies the position (from left to right) of the affected
  32084.  menu.
  32085.  
  32086.  item%
  32087.  -----
  32088.  An integer that identifies the number of the menu item within the menu.
  32089.  
  32090.  kbd$
  32091.  ----
  32092.  A string that indicates which character is allowed as a shortcut key for
  32093.  selection of the menu item. The string argument kbd$ can be any single
  32094.  character, or any extended characters, except those that use the Alt key.
  32095.  
  32096.  Without shortcut keys, each menu item can be selected by pressing the Alt
  32097.  key and the highlighted character in the menu name, followed by the
  32098.  highlighted letter in the menu item. CommandKeySet provides additional
  32099.  functionality by allowing you to specify a single character, such as
  32100.  Shift+F1 or F1, as a shortcut to menu item selection. A separate
  32101.  ShortCutKeySet entry is required for each shortcut key you assign.
  32102.  
  32103.  Use ShortCutKeySet statements during menu initialization at the same place
  32104.  where MenuSet is used.
  32105.  
  32106.  
  32107.  See Also:  MenuSet, ShortCutKeyDelete, ShortCutKeyEvent
  32108.  
  32109.  
  32110.  Example
  32111.  See the SetupMenu procedure in the code example UIDEMO.BAS for a specific
  32112.  implementation.
  32113.  
  32114.  
  32115.  WINDOW.BAS
  32116.  As with MENU.BAS, you can learn much about using the procedures in
  32117.  WINDOW.BAS by studying the demonstration program UIDEMO.BAS, which is
  32118.  provided as a code example. However, a few words of introduction will be
  32119.  helpful. The best way to get a feel for the ease of use of the window
  32120.  procedures is to experiment for yourself, using the code in the
  32121.  demonstration as an example.
  32122.  
  32123.  
  32124.  In addition to the global-array declarations used with MENU.BAS, you must
  32125.  declare the following global arrays in your program, in the order shown, if
  32126.  you use the procedures in WINDOW.BAS:
  32127.  
  32128.  
  32129.  COMMON SHARED /uitools/GloWindow()     AS WindowType
  32130.  COMMON SHARED /uitools/GloButton()     AS ButtonType
  32131.  COMMON SHARED /uitools/GloEdit()    AS EditFieldType
  32132.  COMMON SHARED /uitools/GloStorage     AS WindowStorageType
  32133.  COMMON SHARED /uitools/GloBuffer$()
  32134.  DIM GloWindow(MAXWINDOW)         AS WindowType
  32135.  DIM GloButton(MAXBUTTON)         AS ButtonType
  32136.  DIM GloEdit(MAXEDITFIELD)        AS EditFieldType
  32137.  DIM GloWindowStack(MAXWINDOW)     AS INTEGER
  32138.  DIM GloBuffer$(MAXWINDOW +1,2)
  32139.  
  32140.  
  32141.  These global arrays are used to store information about the windows you plan
  32142.  to use in your program. The window effects provided by WINDOW.BAS let you
  32143.  open and use text windows virtually anywhere on your screen. For each
  32144.  window, you can independently define the following window characteristics:
  32145.  *    Initial position, by row and column
  32146.  *    Color
  32147.  *    Ability to close window or not
  32148.  *    Ability to move window or not
  32149.  *    Ability to resize window or not
  32150.  *    Window title
  32151.  *    Border characters
  32152.  
  32153.  
  32154.  You also can define as modal windows any of the windows you make. A modal
  32155.  window is a window that forces the user to respond to a prompt within the
  32156.  window itself. You cannot select, either with the mouse or the keyboard,
  32157.  anything outside the window's border. An alert message box is an example of
  32158.  a modal window.
  32159.  
  32160.  A single WindowOpen statement lets you open your window. Once you've opened
  32161.  a window, you can fill it with text, edit fields, list boxes with scroll
  32162.  bars, and push buttons of several types, all of which behave much like the
  32163.  QBX user interface. If you open several windows, you can move between them
  32164.  by using the mouse to select the one you want. A single procedure, WindowDo,
  32165.  monitors your mouse and keyboard activity while a window is open, and
  32166.  responds according to your input.
  32167.  
  32168.  To put text in whatever window is active, WindowLocate lets you specify
  32169.  where the text is to go and WindowPrint lets you print it there. Edit fields
  32170.  (boxes that contain some text for you to either accept or change) are
  32171.  created in a window using EditFieldOpen. They are closed with
  32172.  EditFieldClose.
  32173.  
  32174.  List boxes with scroll bars are displayed by passing an array containing the
  32175.  items in the list to the ListBox procedure. In addition to a list of items,
  32176.  List boxes always contain OK and Cancel command buttons.
  32177.  
  32178.  An assortment of buttons, with a full range of features, are placed on the
  32179.  screen with the ButtonOpen procedure. Supported button types and their
  32180.  behavior are described in the following table:
  32181.  
  32182.  Button type            Explanation
  32183.  
  32184.  Command button         Confirms settings, gets help, or escapes.
  32185.  Option button          Selects one of several options (use direction keys).
  32186.  Check box              Turns one option on or off (use Spacebar).
  32187.  Area button            An invisible button on the screen that occupies a
  32188.  defined area. When selected, causes some event to occur.
  32189.  Vertical scroll bar    Vertically scrolls long lists or screen areas.
  32190.  Horizontal scroll bar  Horizontally scrolls screen areas that are wider than
  32191.  the active window.
  32192.  
  32193.  Before opening a window - in fact, before using any of the routines in
  32194.  WINDOW.BAS - you must do some program initialization. The following code
  32195.  fragment illustrates how to do the initialization and how to use some of the
  32196.  procedures in WINDOW.BAS:
  32197.  
  32198.  
  32199.  MenuInit                             ' Initialize menus and mouse.
  32200.  WindowInit                         ' Initialize windows.
  32201.  MouseShow                            ' Make mouse cursor visible.
  32202.  
  32203.  WindowOpen 1,5,25,15,45,0,3,0,3,0,-1,-1,0,0,0,"-Window 1-"
  32204.  WindowPrint 1,""                    ' Put a blank line at the top.
  32205.  WindowPrint 1,"Features:"        ' Put text in the window.
  32206.  WindowPrint 1,"Title bar"
  32207.  WindowPrint 1,"Closable window"
  32208.  WindowPrint 1,"No border"
  32209.  
  32210.  ButtonOpen 1,2,"OK",11,8,1,0,1        ' Open an OK button.
  32211.  
  32212.  WindowOpen 2,8,29,17,49,0,5,0,5,15,-1,-1,0,0,1,"-Window 2-"
  32213.  WindowPrint 1, ""                 ' Put a blank line at the top.
  32214.  WindowPrint 1, "Features:"        ' Put text in the window.
  32215.  WindowPrint 1, "Title bar"
  32216.  WindowPrint 1, "Closable window"
  32217.  WindowPrint 1, "Single-line border"
  32218.  WindowLine 9                         ' Put a line across the bottom.
  32219.  ButtonOpen 1,2,"OK",11,8,1,0,1
  32220.  
  32221.  ExitFlag = FALSE
  32222.  
  32223.  WHILE NOT ExitFlag
  32224.      WindowDo 1,0                     ' Monitor for a window event.
  32225.      SELECT CASE Dialog(0)         ' Return what event occurred.
  32226.      CASE 1,4,6                     ' Handle user actions:
  32227.          WindowClose WindowCurrent     ' Selecting OK, selecting the
  32228.                                      ' close box, or pressing Enter.
  32229.          IF WindowCurrent = 0 THEN     ' Just in case it's the last
  32230.              ExitFlag = TRUE         ' or only window.
  32231.          END IF
  32232.      CASE 3                            ' Handle selecting another window
  32233.          WindowSetCurrent Dialog(3)    ' and making it current.
  32234.      CASE 9                            ' Handle pressing Esc.
  32235.          ExitFlag = TRUE
  32236.      CASE ELSE                        ' Handle everything else.
  32237.      END SELECT
  32238.  WEND
  32239.  
  32240.  WindowClose 0                     ' Close all windows.
  32241.  MouseHide                            ' Hide the mouse cursor.
  32242.  COLOR 15, 0                         ' Change colors back to original.
  32243.  CLS                                 ' Clear the screen.
  32244.  END
  32245.  
  32246.  
  32247.  
  32248.  The code fragment opens two windows, each of a different color. Both contain
  32249.  some text about the features that are available in that window. Both also
  32250.  contain an OK command button that, when chosen, causes the selected window
  32251.  to close.
  32252.  
  32253.  Both windows are movable. To move a window, move the mouse cursor to any of
  32254.  the dot-pattern (ASCII 176) characters adjacent to the title bar, or to the
  32255.  title bar itself. Press the left mouse button and drag a window by moving
  32256.  the mouse. Release the button when you are satisfied with the position.
  32257.  
  32258.  Close a window by selecting the equal sign (=) in the upper-left corner of
  32259.  the window. Pressing Enter while either window is selected has the same
  32260.  effect as choosing the OK command button or selecting the window-close
  32261.  control character (=). Close a window by using WindowClose. WindowClose
  32262.  closes the window and any buttons or edit fields that may be open within the
  32263.  window.
  32264.  
  32265.  
  32266.  You can move between the two windows and close either or both of them in any
  32267.  order. When both are closed, the program ends. When a window can be resized
  32268.  (the windows in the example cannot), a plus (+) character is displayed in
  32269.  the lower-right corner. Select the plus character and drag the mouse to
  32270.  resize the window.
  32271.  
  32272.  The preceding information is intended to give you an overview of how the
  32273.  toolbox windows work. With this overview and the following detailed
  32274.  information about each procedure, you should be able to easily incorporate
  32275.  windows into your BASIC programs. The example code in UIDEMO.BAS
  32276.  demonstrates how most of the procedures are used.
  32277.  
  32278.  A description of each procedure that comprises WINDOW.BAS follows.
  32279.  
  32280.  
  32281.  Alert FUNCTION
  32282.  
  32283.  Action
  32284.  Displays a window with one to three buttons that indicate choices for the
  32285.  user.
  32286.  
  32287.  
  32288.  Syntax
  32289.  variablename$ = Alert(style%, text$, row1%, col1%, row2%, col 2%, b1$, b2$,
  32290.  b3$)
  32291.  
  32292.  Remarks
  32293.  The Alert procedure returns an integer from 1 to 3, inclusive, indicating
  32294.  which button was selected by the user. Use Alert whenever you want to
  32295.  display a dialog box and force a user decision. The Alert procedure uses the
  32296.  following arguments:
  32297.  
  32298.  variablename$
  32299.  -------------
  32300.  Any BASIC variable name, including the name of a record variable or record
  32301.  element.
  32302.  
  32303.  style%
  32304.  ------
  32305.  An integer that indicates the style of the text to be displayed. The values
  32306.  of style% are:
  32307.  1     Truncated printing. If text is longer than the window, it is
  32308.  truncated. The text cursor is moved to the first character of the next line.
  32309.  
  32310.  2     Character wrapping. If text is longer than the window, the text
  32311.  continues on the next line.
  32312.  3     Text wrapping. Same as style 2 except that text is wrapped only at
  32313.  spaces.
  32314.  4     Truncated centering. Text is centered on the current line. If text is
  32315.  too long, it is truncated.
  32316.  
  32317.  text$
  32318.  -----
  32319.  A string that contains the text to be displayed in the dialog box. You can
  32320.  force a new line in text$ by using the vertical bar character ( | ). Use
  32321.  several together for more than one blank line.
  32322.  
  32323.  row1%, col1%
  32324.  ------------
  32325.  An integer pair that specifies absolute screen row and column coordinates.
  32326.  
  32327.  row2%, col 2%
  32328.  -------------
  32329.  An integer pair that specifies the lower-right-corner coordinates of
  32330.  an area.
  32331.  
  32332.  b1$
  32333.  ---
  32334.  A string that contains the text for button 1.
  32335.  
  32336.  b2$
  32337.  ---
  32338.  A string that contains the text for button 2.
  32339.  
  32340.  b3$
  32341.  ---
  32342.  A string that contains the text for button 3.
  32343.  
  32344.  If you use fewer than three buttons, use a null string ("") for the text of
  32345.  any unused buttons. All alert windows are modal; that is, they do not allow
  32346.  selection outside their boundaries. If you do not provide at least one
  32347.  button in your alert window, the Alert procedure will place a single OK
  32348.  button in the window for you.
  32349.  
  32350.  You must ensure that the window you have described is large enough to
  32351.  contain all three buttons on the bottom row, that the window is at least
  32352.  three rows high, and that the window is large enough to contain text$. If
  32353.  the window is too small or any other problem occurs, the Alert procedure
  32354.  returns 0.
  32355.  
  32356.  
  32357.  See Also:  Dialog, ListBox
  32358.  
  32359.  Example
  32360.  See the DemoAlert procedure in the code example UIDEMO.BAS for a specific
  32361.  implementation.
  32362.  
  32363.  
  32364.  BackgroundRefresh SUB
  32365.  
  32366.  Action
  32367.  Used internally by other procedures in WINDOW.BAS. Do not use or alter this
  32368.  procedure.
  32369.  
  32370.  Syntax
  32371.  BackgroundRefresh handle%
  32372.  
  32373.  Remarks
  32374.  The BackgroundRefresh procedure restores a previously saved background from
  32375.  a global array to the area where a window was displayed. The argument
  32376.  handle% is an integer that indicates the number of the window whose
  32377.  background is being restored. This can be any number between 1 and the value
  32378.  declared in the constant MAXWINDOW.
  32379.  
  32380.  
  32381.  If you want to restore a background, use the PutBackground procedure in
  32382.  GENERAL.BAS.
  32383.  
  32384.  
  32385.  Warning
  32386.  -------
  32387.  Do not use or alter this procedure  unless you are customizing the User
  32388.  Interface toolbox and you know how the use or alteration of this procedure
  32389.  will affect the operation of all other procedures in the toolbox.
  32390.  
  32391.  
  32392.  
  32393.  
  32394.  See Also:  WindowClose, WindowDo, WindowSetCurrent
  32395.  
  32396.  
  32397.  
  32398.  
  32399.  BackgroundSave SUB
  32400.  
  32401.  Action
  32402.  Used internally by the other procedures in WINDOW.BAS. Do not use or alter
  32403.  this procedure.
  32404.  
  32405.  
  32406.  Syntax
  32407.  BackgroundSave handle%
  32408.  
  32409.  Remarks
  32410.  The BackgroundSave procedure saves the background (the area behind where a
  32411.  window is to be displayed) in a global array. The argument handle% is an
  32412.  integer that indicates the number of the window whose background is being
  32413.  saved. This can be any number between 1 and the value declared in the
  32414.  constant MAXWINDOW.
  32415.  
  32416.  
  32417.  If you want to save a background, use the GetBackground procedure in
  32418.  GENERAL.BAS.
  32419.  
  32420.  
  32421.  
  32422.  Warning
  32423.  -------
  32424.  Do not use or alter this procedure unless you are customizing the User
  32425.  Interface toolbox and you know how the use or alteration of this procedure
  32426.  will affect the operation of all other procedures in the toolbox.
  32427.  
  32428.  
  32429.  
  32430.  See Also:  WindowDo, WindowOpen,WindowSetCurrent
  32431.  
  32432.  
  32433.  ButtonClose SUB
  32434.  
  32435.  Action
  32436.  Erases the specified button from the current window and deletes it from the
  32437.  global arrays.
  32438.  
  32439.  
  32440.  Syntax
  32441.  ButtonClose handle%
  32442.  
  32443.  Remarks
  32444.  The ButtonClose procedure is used to close individual buttons that have been
  32445.  opened with ButtonOpen. The argument handle% is an integer that indicates
  32446.  the number of the button being closed. This can be any number between 0 and
  32447.  the value declared in the constant MAXBUTTON, inclusive. If handle% is 0,
  32448.  all buttons in the current window are closed.
  32449.  
  32450.  If the WindowClose procedure is used to close a window that contains
  32451.  buttons, you need not use this procedure, because all buttons associated
  32452.  with a closing window are closed automatically.
  32453.  
  32454.  See Also:  ButtonOpen, WindowClose
  32455.  
  32456.  
  32457.  
  32458.  
  32459.  ButtonInquire FUNCTION
  32460.  
  32461.  Action
  32462.  Returns an integer that identifies the state of a specified button.
  32463.  
  32464.  
  32465.  Syntax
  32466.  variablename% = ButtonInquire(handle%)
  32467.  
  32468.  Remarks
  32469.  The ButtonInquire procedure uses the following arguments:
  32470.  
  32471.  variablename%
  32472.  -------------
  32473.  Any BASIC variable name, including the name of a record variable or record
  32474.  element.
  32475.  
  32476.  handle%
  32477.  -------
  32478.  An integer that indicates the number of the button whose state is requested.
  32479.  This can be any number between 1 and the value declared in the constant
  32480.  MAXBUTTON, inclusive.
  32481.  
  32482.  
  32483.  The ButtonInquire procedure is used when you need to determine the state of
  32484.  a type 1, 2, 3, 6, or 7 button, as specified in ButtonOpen.
  32485.  
  32486.  
  32487.  See Also:   ButtonSetState
  32488.  
  32489.  
  32490.  ButtonOpen SUB
  32491.  
  32492.  Action
  32493.  Opens a button of the specified type, and places it in the current window at
  32494.  the window coordinates specified.
  32495.  
  32496.  
  32497.  Syntax
  32498.  ButtonOpen handle%, state%, text$, row1%, col1%, row2%, col 2%, buttonType%
  32499.  
  32500.  Remarks
  32501.  Use ButtonOpen when you want to place any kind of buttons in open windows.
  32502.  The ButtonOpen procedure uses the following arguments:
  32503.  
  32504.  handle%
  32505.  -------
  32506.  An integer that indicates the number of the button that is being opened.
  32507.  This can be any number between 1 and the value declared in the constant
  32508.  MAXBUTTON, inclusive.
  32509.  
  32510.  state%
  32511.  ------
  32512.  An integer that indicates the initial state of the button that is being
  32513.  opened. For each different button type and state% value, the following
  32514.  applies:
  32515.  
  32516.  Type     Value   Significance
  32517.  
  32518.  1          1     Normal.
  32519.             2     Default choice (brackets highlighted).
  32520.             3    Chosen (highlighted in reverse video).
  32521.  
  32522.  2 & 3      1     Normal.
  32523.             2     Selected (checked).
  32524.  
  32525.  4          0     Does not apply to type 4 (area button).
  32526.  5                Reserved for future use.
  32527.  
  32528.  6 & 7      n     Indicates the initial position of the scroll bar's position
  32529.  indicator. It can be between 1 and the maximum position.
  32530.  
  32531.  text$
  32532.  -----
  32533.  A string that contains the text to be displayed in the button. Does not
  32534.  apply to button types 4, 6, or 7.
  32535.  
  32536.  row1%, col1%
  32537.  ------------
  32538.  An integer pair that describes the upper-left corner of an area relative to
  32539.  the upper-left corner of the current window, not the screen.
  32540.  
  32541.  row2%, col 2%
  32542.  -------------
  32543.  An integer pair that specifies the lower-right corner of an area, relative
  32544.  to the upper-left corner of the current window, not the screen. The
  32545.  coordinates row2% and col 2% apply only to button types 4, 6, and 7. Any
  32546.  values in these arguments are ignored by other button types; however,
  32547.  arguments must be in the argument list, even if their value is 0.
  32548.  
  32549.  buttonType%
  32550.  -----------
  32551.  An integer that indicates the type of button to be opened. The following is
  32552.  a list of valid button types:
  32553.      1     Command button
  32554.      2     Check box
  32555.      3     Option button
  32556.      4     Area button
  32557.      5     Reserved for future use
  32558.      6     Vertical scroll bar
  32559.      7     Horizontal scroll bar
  32560.  
  32561.  Note that the positioning coordinates are relative to the current window,
  32562.  not absolute from the top-left corner of the screen. Within each window,
  32563.  each button has a unique handle% value. Because buttons are local to
  32564.  specific windows it is permissible to have more than one button with the
  32565.  same handle% value, provided they are in different windows.
  32566.  
  32567.  See Also:  ButtonClose
  32568.  
  32569.  
  32570.  
  32571.  
  32572.  ButtonSetState SUB
  32573.  
  32574.  Action
  32575.  Sets the state of the specified button and redraws it.
  32576.  
  32577.  
  32578.  Syntax
  32579.  ButtonSetState handle%, state%
  32580.  
  32581.  Remarks
  32582.  The ButtonSetState procedure operates on buttons in the current window. Use
  32583.  ButtonSetState to change button state in response to user selection of
  32584.  different buttons. The ButtonSetState procedure uses the following
  32585.  arguments:
  32586.  
  32587.  handle%
  32588.  -------
  32589.  An integer that indicates the number of the button whose state is being set.
  32590.  This can be any number between 1 and the value declared in the constant
  32591.  MAXBUTTON, inclusive.
  32592.  
  32593.  state%
  32594.  ------
  32595.  An integer that indicates the state of the button. For each different button
  32596.  type and state% value, the following applies:
  32597.  
  32598.  Type     Value   Significance
  32599.  1          1     Normal.
  32600.             2     Default choice (brackets highlighted).
  32601.             3     Chosen (highlighted in reverse video).
  32602.  
  32603.  2 & 3      1     Normal.
  32604.             2     Selected (checked).
  32605.  
  32606.  4          0     Does not apply to type 4.
  32607.  
  32608.  5                Reserved for future use.
  32609.  
  32610.  6 & 7      n     Sets the initial position of the scroll bar's position
  32611.  indicator. It can be between 1 and the maximum position.
  32612.  
  32613.  
  32614.  See Also:  ButtonInquire
  32615.  
  32616.  
  32617.  
  32618.  
  32619.  ButtonShow SUB
  32620.  
  32621.  Action
  32622.  Used internally by the other procedures in WINDOW.BAS. Do not use or alter
  32623.  this procedure.
  32624.  
  32625.  
  32626.  Syntax
  32627.  ButtonShow handle%
  32628.  
  32629.  Remarks
  32630.  The ButtonShow  procedure draws a button on the screen, and is used
  32631.  automatically by WINDOW.BAS. Normally, you never need to call this procedure
  32632.  directly since it is automatically called when needed. The argument handle%
  32633.  is an integer that indicates the number of the button that is being opened.
  32634.  This can be any number between 1 and the value declared in the constant
  32635.  MAXBUTTON, inclusive.
  32636.  
  32637.  
  32638.  Warning
  32639.  -------
  32640.  Do not alter this procedure unless you are customizing the User Interface
  32641.  toolbox and know how the use or alteration of this procedure will affect the
  32642.  operation of all other procedures in the toolbox.
  32643.  
  32644.  
  32645.  
  32646.  See Also:  ButtonOpen, ButtonSetState, ButtonToggle
  32647.  
  32648.  
  32649.  ButtonToggle SUB
  32650.  
  32651.  Action
  32652.  Toggles a button state between state 1 (normal) and state 2 (selected).
  32653.  
  32654.  
  32655.  Syntax
  32656.  ButtonToggle handle%
  32657.  
  32658.  Remarks
  32659.  Use ButtonToggle to toggle button state in response to user selection of
  32660.  different buttons. The argument handle% is an integer that indicates the
  32661.  number of the button whose state is being toggled. This can be any number
  32662.  between 1 and the value declared in the constant MAXBUTTON. ButtonToggle
  32663.  applies only to type 1, 2, or 3 buttons.
  32664.  
  32665.  
  32666.  See Also:  ButtonSetState
  32667.  
  32668.  
  32669.  
  32670.  
  32671.  Dialog FUNCTION
  32672.  
  32673.  Action
  32674.  Returns an integer whose value indicates what type of button, edit-field, or
  32675.  window event occurred within the WindowDo procedure.
  32676.  
  32677.  
  32678.  Syntax
  32679.  variablename% = Dialog(op%)
  32680.  
  32681.  Remarks
  32682.  The Dialog procedure uses the following arguments:
  32683.  
  32684.  variablename%
  32685.  -------------
  32686.  Any BASIC variable name, including the name of a record variable or record
  32687.  element.
  32688.  
  32689.  op%
  32690.  ---
  32691.  An integer that defines a specific operation that Dialog is to evaluate. The
  32692.  following table lists the possible values of op% and the information that is
  32693.  returned:
  32694.  
  32695.  op%    Return    Event/significance
  32696.  
  32697.  0        0    No event took place.
  32698.           1    A button was pressed. Use Dialog(1) to determine which button.
  32699.           2    An edit field was selected. Use Dialog(2) to determine which
  32700.  field.
  32701.           3    A window other than the current window was selected. Use
  32702.  Dialog(3) to determine which window.
  32703.           4    Current window's close box was selected.
  32704.           5    Current window needs to be refreshed because it was resized.
  32705.           6    Enter key was pressed.
  32706.           7    Tab key was pressed.
  32707.           8    Shift+Tab was pressed.
  32708.           9    Esc was pressed.
  32709.          10    Up Arrow key was pressed.
  32710.          11    Down Arrow key was pressed.
  32711.          12    Left Arrow key was pressed.
  32712.          13    Right Arrow key was pressed.
  32713.          14    Spacebar was pressed.
  32714.          15    Current window was moved.
  32715.          16    Home key was pressed.
  32716.          17    End key was pressed.
  32717.          18    PgUp key was pressed.
  32718.          19    PgDn key was pressed.
  32719.          20    Menu item was chosen.
  32720.  
  32721.  1        *    Returns the number of the button just pressed. May be from 1
  32722.  to the value declared in MAXBUTTON, inclusive.
  32723.  
  32724.  2        *    Returns the number of the edit field just selected. May be
  32725.  from 1 to the value declared in MAXEDITFIELD, inclusive.
  32726.  
  32727.  3        n    Returns the number of the window just selected. May be from 1
  32728.  to the value declared in MAXWINDOW, inclusive.
  32729.  
  32730.  4 - 15        Reserved for future use.
  32731.  
  32732.  17       *    Returns the row of the cursor within the field of button type
  32733.  4. (See ButtonOpen.) May be from 1 to the value declared in MAXROW
  32734.  inclusive.
  32735.  
  32736.  18       *    Returns the column of the cursor within the field of button
  32737.  type 4. (See ButtonOpen.) May be from 1 to the value declared in MAXCOL,
  32738.  inclusive.
  32739.  19      -2    Selected Down or Right direction key on scroll bar (button
  32740.  type 6 or 7).
  32741.          -1    Selected Up or Left direction key on scroll bar (button type 6
  32742.  or 7)
  32743.           *    Selected a position on grayed area of scroll bar. May be from
  32744.  1 to the maximum number of positions on the scroll bar.
  32745.  
  32746.  20            Reserved for future use.
  32747.  
  32748.  Using an op% value of 0, you can determine what happened; using the other
  32749.  arguments, you can determine where it happened.
  32750.  
  32751.  
  32752.  See Also:  Alert, ListBox
  32753.  
  32754.  
  32755.  Example
  32756.  See the individual procedures in the code example UIDEMO.BAS for examples of
  32757.  specific usage.
  32758.  
  32759.  
  32760.  
  32761.  
  32762.  ditFieldClose SUB
  32763.  
  32764.  Action
  32765.  Erases the specified edit field from the current window and deletes it from
  32766.  the global arrays.
  32767.  
  32768.  
  32769.  Syntax
  32770.  EditFieldClose handle%
  32771.  
  32772.  Remarks
  32773.  Use EditFieldClose when you want to erase an edit field from a window rather
  32774.  than close the window. The argument handle% is an integer that indicates the
  32775.  number of the edit field being closed. This can be any number between 0 and
  32776.  the value declared in the constant MAXEDITFIELD, inclusive. If handle% is 0,
  32777.  all edit fields in the current window are closed. If the WindowClose
  32778.  procedure is used to close a window that contains edit fields, you need not
  32779.  use this procedure since all edit fields associated with a closing window
  32780.  are automatically closed.
  32781.  
  32782.  See Also:  EditFieldOpen, WindowClose
  32783.  
  32784.  
  32785.  EditFieldInquire FUNCTION
  32786.  
  32787.  Action
  32788.  Returns the string associated with the specified edit field.
  32789.  
  32790.  
  32791.  Syntax
  32792.  variablename$ = EditFieldInquire(handle%)
  32793.  
  32794.  Remarks
  32795.  Use EditFieldInquire when you need to return the edit string associated with
  32796.  a particular edit field. The EditFieldInquire procedure uses the following
  32797.  arguments:
  32798.  
  32799.  variablename$
  32800.  -------------
  32801.  Any BASIC variable name, including the name of a record variable or record
  32802.  element.
  32803.  
  32804.  handle%
  32805.  -------
  32806.  An integer that indicates the number of the edit field whose edit string is
  32807.  requested. This can be any number between 1 and the value declared in the
  32808.  constant MAXEDITFIELD, inclusive.
  32809.  
  32810.  See Also:  EditFieldOpen
  32811.  
  32812.  
  32813.  Example
  32814.  See the DemoDialog procedure in the code example UIDEMO.BAS for a specific
  32815.  implementation.
  32816.  
  32817.  
  32818.  
  32819.  
  32820.  Argument    Description
  32821.  
  32822.   EditFieldOpen SUB
  32823.  
  32824.  Action
  32825.  Opens an edit field and places it in the current window at the window
  32826.  coordinates specified.
  32827.  
  32828.  
  32829.  Syntax
  32830.  EditFieldOpen handle%, text$, row%, col%, fore%, back%, visLength%,
  32831.  maxLength%
  32832.  
  32833.  Remarks
  32834.  Use the EditFieldOpen procedure anytime you want to open an edit field in
  32835.  the current window. The EditFieldOpen procedure uses the following
  32836.  arguments:
  32837.  
  32838.  handle%
  32839.  -------
  32840.  An integer that indicates the number of the edit field that is being opened.
  32841.  This can be any number between 1 and the value declared in the constant
  32842.  MAXEDITFIELD, inclusive.
  32843.  
  32844.  text$
  32845.  -----
  32846.  A string that contains the text that is to be initially placed in the edit
  32847.  field for editing.
  32848.  
  32849.  row%, col%
  32850.  ----------
  32851.  An integer pair that describes the upper-left corner of an area, relative to
  32852.  the upper-left corner of the current window, not the screen.
  32853.  
  32854.  fore%
  32855.  -----
  32856.  An integer that defines the edit field foreground color (0 - 15)
  32857.  
  32858.  back%
  32859.  -----
  32860.  An integer that defines the edit field background color (0 - 7)
  32861.  
  32862.  visLength%
  32863.  ----------
  32864.  An integer that indicates the length of the edit field that is visible on
  32865.  the screen.
  32866.  
  32867.  maxLength%
  32868.  ----------
  32869.  An integer that indicates the maximum length of the edit field, up to a
  32870.  maximum of 255 characters.
  32871.  
  32872.  Note that the positioning coordinates are relative to the current window,
  32873.  not absolute from the top left of the screen. The edit field foreground and
  32874.  background colors may be different from the rest of the window. If the
  32875.  maximum length of the edit field is greater than the visible length of the
  32876.  edit field, the field will scroll left and right, as needed, during editing.
  32877.  
  32878.  
  32879.  See Also:  EditFieldClose
  32880.  
  32881.  
  32882.  Example
  32883.  See the DemoDialog procedure in the code example UIDEMO.BAS for specific
  32884.  usage.
  32885.  
  32886.  
  32887.  
  32888.  
  32889.  FindButton FUNCTION
  32890.  
  32891.  ebAction
  32892.  Used internally by the button procedures in WINDOW.BAS. Do not use or alter
  32893.  this procedure.
  32894.  
  32895.  
  32896.  Syntax
  32897.  variablename% = FindButton(handle%)
  32898.  
  32899.  Remarks
  32900.  The FindButton procedure returns an index into the global array where a
  32901.  button is stored. Each button is uniquely described by the window in which
  32902.  it exists, and a button handle. FindButton assumes the current window.
  32903.  The FindButton procedure uses the following arguments:
  32904.  
  32905.  variablename%
  32906.  -------------
  32907.  Any BASIC variable name, including the name of a record variable or record
  32908.  element.
  32909.  
  32910.  handle%
  32911.  -------
  32912.  An integer that indicates the number of the button whose index is requested.
  32913.  This can be any number between 1 and the value declared in the constant
  32914.  MAXBUTTON, inclusive.
  32915.  
  32916.  
  32917.  
  32918.  Warning
  32919.  -------
  32920.  Do not alter this procedure unless you are customizing the User Interface
  32921.  toolbox and you know how the alteration of this procedure will affect the
  32922.  operation of all other procedures in the toolbox.
  32923.  
  32924.  
  32925.  See Also:  ButtonClose, ButtonInquire, ButtonSetState, ButtonShow,
  32926.                ButtonToggle, MaxScrollLength, WindowDo
  32927.  
  32928.  
  32929.  
  32930.  
  32931.  FindEditField FUNCTION
  32932.  
  32933.  Action
  32934.  Used internally by WINDOW.BAS. Do not use or alter this procedure.
  32935.  
  32936.  
  32937.  Syntax
  32938.  variablename% = FindEditField(handle%)
  32939.  
  32940.  Remarks
  32941.  The FindEditField procedure uses the following arguments:
  32942.  
  32943.  variablename%
  32944.  -------------
  32945.  Any BASIC variable name, including the name of a record variable or record
  32946.  element.
  32947.  
  32948.  handle%
  32949.  -------
  32950.  An integer that indicates the number of the edit field whose index is
  32951.  requested. This can be any number between 1
  32952.  and the number declared in the constant MAXEDITFIELD, inclusive.
  32953.  
  32954.  The FindEditField procedure returns an index into the global array where an
  32955.  edit field is stored. Each edit field is uniquely described by the window in
  32956.  which it exists, and an edit field handle. FindEditField assumes the current
  32957.  window.
  32958.  
  32959.  
  32960.  
  32961.  Warning
  32962.  -------
  32963.  Do not alter this procedure unless you are customizing the User Interface
  32964.  toolbox and you know how the alteration of this procedure will affect the
  32965.  operation of all other procedures in the toolbox.
  32966.  
  32967.  
  32968.  
  32969.  
  32970.  See Also:  EditFieldClose, EditFieldInquire, WindowDo
  32971.  
  32972.  
  32973.  ListBox FUNCTION
  32974.  
  32975.  Action
  32976.  Displays a window containing a list box, a scroll bar, an OK button, and a
  32977.  Cancel button.
  32978.  
  32979.  Syntax
  32980.  variablename% = ListBox (text$( ), maxRec%)
  32981.  
  32982.  Remarks
  32983.  
  32984.  variablename%
  32985.  -------------
  32986.  Any BASIC variable name, including the name of a record variable or record
  32987.  element.
  32988.  
  32989.  text$( )
  32990.  --------
  32991.  A string array that contains the text items to be displayed in the
  32992.  list box.
  32993.  
  32994.  maxRec%
  32995.  -------
  32996.  An integer that defines the maximum number of entries in the
  32997.  list box.
  32998.  
  32999.  With the ListBox procedure, you can use the mouse or keyboard to select any
  33000.  single item from the text in a list box. To accept the current choice,
  33001.  select OK. Use Cancel to reject all choices and close the list box. The
  33002.  ListBox procedure returns an integer that is the number of the item selected
  33003.  from the text in the list box when OK is selected, or 0 if Cancel is
  33004.  selected.
  33005.  
  33006.  Use ListBox when you have a list of things to choose from that may be longer
  33007.  than the available screen space.
  33008.  
  33009.  
  33010.  See Also:  Alert, Dialog
  33011.  
  33012.  
  33013.  Example
  33014.  See the DemoListBox procedure in the code example UIDEMO.BAS for a specific
  33015.  usage.
  33016.  
  33017.  
  33018.  
  33019.  
  33020.  MaxScrollLength FUNCTION
  33021.  
  33022.  Action
  33023.  Returns an integer that is the maximum number of positions in the specified
  33024.  scroll bar.
  33025.  
  33026.  Syntax
  33027.  variablename% = MaxScrollLength(handle%)
  33028.  
  33029.  Remarks
  33030.  The MaxScrollLength procedure uses the following arguments:
  33031.  
  33032.  variablename%
  33033.  -------------
  33034.  Any BASIC variable name, including the name of a record variable or record
  33035.  element.
  33036.  
  33037.  handle%
  33038.  -------
  33039.  An integer that specifies the scroll bar for which the maximum number of
  33040.  positions is requested. This is the number that is used to identify the
  33041.  scroll bar when it is opened using ButtonOpen. This can be any number
  33042.  between 1 and the value declared in the constant MAXBUTTON, inclusive.
  33043.  
  33044.  The MaxScrollLength procedure is used to determine how many positions your
  33045.  scroll bar has. Use this procedure to increment or decrement the cursor
  33046.  position in response to user selection of the direction arrows to move the
  33047.  cursor.
  33048.  
  33049.  See Also:  ListBox
  33050.  
  33051.  
  33052.  Example
  33053.  See the DemoScrollBar procedure in the code example UIDEMO.BAS for a
  33054.  specific usage.
  33055.  
  33056.  
  33057.  
  33058.  
  33059.  WhichWindow FUNCTION
  33060.  
  33061.  Action
  33062.  Used internally by the other procedures in WINDOW.BAS. Do not use or alter
  33063.  this procedure.
  33064.  
  33065.  
  33066.  Syntax
  33067.  variablename% = WhichWindow(row%, col%)
  33068.  
  33069.  Remarks
  33070.  The WhichWindow procedure returns an integer that is the window number for
  33071.  the location specified on the screen. Overlapping windows are taken into
  33072.  account. The WhichWindow procedure uses the following arguments:
  33073.  
  33074.  variablename%
  33075.  -------------
  33076.  Any BASIC variable name, including the name of a record variable or record
  33077.  element.
  33078.  
  33079.  row%, col%
  33080.  ----------
  33081.  An integer pair that describes a particular point on the screen.
  33082.  
  33083.  
  33084.  Warning
  33085.  -------
  33086.  Do not alter this procedure unless You're customizing the User Interface
  33087.  toolbox and know how the alteration of this procedure will affect the
  33088.  operation of all other procedures in the toolbox.
  33089.  
  33090.  
  33091.  
  33092.  See Also:  WindowDo
  33093.  
  33094.  
  33095.  
  33096.  WindowBorder FUNCTION
  33097.  
  33098.  Action
  33099.  Returns a 14-character string that describes the border of the window.
  33100.  
  33101.  
  33102.  Syntax
  33103.  border$ = WindowBorder (windowType%)
  33104.  
  33105.  Remarks
  33106.  The argument windowType% is an integer that describes a particular window
  33107.  type.
  33108.  
  33109.  The border of the window actually determines what characteristics a window
  33110.  will have. Each character position in the returned string is representative
  33111.  of a particular component of the border. Some positions in the border have
  33112.  added significance, in that special characters in those positions implement
  33113.  certain features. The following list indicates the significance of each
  33114.  border$ character position and the features implemented by special
  33115.  characters:
  33116.  
  33117.  Position    Character defined     Special effect character
  33118.  
  33119.   1          Upper-left corner     Equal sign (=) makes window closable.
  33120.   2          Top line              Dot-pattern character (ASCII 176) makes
  33121.  window movable.
  33122.   3          Upper-right corner
  33123.   4          Left-side line
  33124.   5          Middle fill character
  33125.   6          Right-side line
  33126.   7          Lower-left corner
  33127.   8          Bottom line
  33128.   9          Lower-right corner    Plus sign (+) makes window resizable.
  33129.  10          Left-side intersection
  33130.  11          Middle line
  33131.  12          Right-side intersection
  33132.  13          Shadow flag          "S" in this position puts a 3D shadow on
  33133.  window.
  33134.                  All predefined window types have shadows.
  33135.  14          Title flag           "T" in this position puts a title bar
  33136.  across the top of
  33137.                  the window if the length of title$ in WindowOpen
  33138.                  is greater than 0.
  33139.  
  33140.  Twenty-four basic predefined window types are provided in WINDOW.BAS. These
  33141.  combinations include all of the special features (movable, closable,
  33142.  resizable, shadow, and title) with three different borders. You can have no
  33143.  border, a single-line border, or a double-line border. All available options
  33144.  can be specified with arguments to the WindowOpen procedure.
  33145.  
  33146.  If you want to create other custom window types, modify the WindowBorder
  33147.  procedure in WINDOW.BAS to add more window types. By observing the
  33148.  conventions in the list above, you can create windows that have the features
  33149.  and any special borders you want. To create custom window types, modify this
  33150.  procedure and recompile it into your Quick library and .LIB file.
  33151.  
  33152.  Note
  33153.  ----
  33154.  The WindowBorder procedure is used internally by WINDOW.BAS and under normal
  33155.  circumstances will not be called directly by your program. You may wish to
  33156.  modify and recompile this procedure to extend or alter its functionality.
  33157.  
  33158.  
  33159.  
  33160.  See Also:  ButtonOpen, EditFieldOpen, WindowClose, WindowDo, WindowOpen,
  33161.                WindowPrintTitle, WindowSetCurrent
  33162.  
  33163.  
  33164.  
  33165.  
  33166.  WindowBox SUB
  33167.  
  33168.  Action
  33169.  Draws a box with a single-line border, within the current window at the
  33170.  coordinates specified.
  33171.  
  33172.  
  33173.  Syntax
  33174.  WindowBox box Row1%, boxCol1%, box Row2%, boxCol 2%
  33175.  
  33176.  Remarks
  33177.  The WindowBox procedure uses the following arguments:
  33178.  
  33179.  box Row1%, boxCol%
  33180.  ------------------
  33181.  An integer pair that describes the upper-left corner of an area relative to
  33182.  the upper-left corner of the current window.
  33183.  
  33184.  box Row2%, boxCol 2%
  33185.  --------------------
  33186.  An integer pair that describes the lower-right corner of an area relative to
  33187.  the upper-left corner of the current window.
  33188.  
  33189.  The WindowBox procedure is used by the ListBox procedure to create a
  33190.  single-line box within the window. WindowBox can be used to box any window
  33191.  area as desired.
  33192.  
  33193.  See Also:  ListBox
  33194.  
  33195.  
  33196.  
  33197.  
  33198.  WindowClose SUB
  33199.  
  33200.  Action
  33201.  Closes a specified window, closing all buttons and edit fields associated
  33202.  with that window.
  33203.  
  33204.  Syntax
  33205.  WindowClose handle%
  33206.  
  33207.  Remarks
  33208.  The argument handle% is an integer that indicates the number of the window
  33209.  being closed. This can be any number between 0 and the value declared in the
  33210.  constant MAXWINDOW, inclusive. When you close the current window, the top
  33211.  window becomes the current window. Any button and edit fields associated
  33212.  with the closing window are also closed. If handle% is 0, all windows are
  33213.  closed.
  33214.  
  33215.  
  33216.  See Also:  WindowOpen
  33217.  
  33218.  
  33219.  Example
  33220.  See the DemoWindow procedure in the code example UIDEMO.BAS for a specific
  33221.  usage that closes all open windows.
  33222.  
  33223.  
  33224.  
  33225.  
  33226.  
  33227.  WindowCls SUB
  33228.  
  33229.  Action
  33230.  Clears the current window.
  33231.  
  33232.  
  33233.  Syntax
  33234.  WindowCls
  33235.  
  33236.  Remarks
  33237.  The WindowCls procedure is used whenever you want to erase the text
  33238.  contained in a window. WindowCls clears the current window using the window
  33239.  background color (not the text background color) defined when the window was
  33240.  first opened with WindowOpen.
  33241.  
  33242.  
  33243.  See Also:  WindowColor, WindowOpen, WindowScroll
  33244.  
  33245.  
  33246.  Example
  33247.  See the DemoResize procedure in the code example UIDEMO.BAS for a specific
  33248.  implementation.
  33249.  
  33250.  
  33251.  
  33252.  
  33253.  WindowColor SUB
  33254.  
  33255.  Action
  33256.  Reassigns the values of the text color variables for the current window.
  33257.  
  33258.  
  33259.  Syntax
  33260.  WindowColor textFore%, textBack%
  33261.  
  33262.  Remarks
  33263.  The WindowColor procedure uses the following arguments:
  33264.  
  33265.  textFore%
  33266.  ---------
  33267.  An integer that defines foreground color (0 - 15) of text.
  33268.  
  33269.  textBack%
  33270.  ---------
  33271.  An integer that defines background color (0 - 7) of text.
  33272.  
  33273.  Use WindowColor whenever you want to change the color of the text being
  33274.  printed in a window. Any printing after using WindowColor is done in the
  33275.  newly defined colors.
  33276.  
  33277.  
  33278.  See Also:  WindowOpen
  33279.  
  33280.  
  33281.  
  33282.  
  33283.  WindowCols FUNCTION
  33284.  
  33285.  Action
  33286.  Returns an integer that is the number of interior columns in the current
  33287.  window.
  33288.  
  33289.  
  33290.  Syntax
  33291.  variablename% = WindowCols (handle%)
  33292.  
  33293.  Remarks
  33294.  The WindowCols procedure uses the following arguments:
  33295.  
  33296.  variablename%
  33297.  -------------
  33298.  Any BASIC variable name, including the name of a record variable or record
  33299.  element.
  33300.  
  33301.  handle%
  33302.  -------
  33303.  An integer that indicates the number of the window whose column count is
  33304.  requested. This can be any number between
  33305.  1 and the value declared in the constant MAXWINDOW, inclusive.
  33306.  
  33307.  Use WindowCols when you want to determine the number of columns in a window,
  33308.  especially when dealing with resizable windows. These "interior" columns are
  33309.  those where text can be displayed.
  33310.  Argument    Description
  33311.  
  33312.  
  33313.  See Also:  WindowRows
  33314.  
  33315.  
  33316.  WindowCurrent FUNCTION
  33317.  
  33318.  Action
  33319.  Returns an integer that is the handle number of the current window.
  33320.  
  33321.  
  33322.  Syntax
  33323.  variablename% = WindowCurrent
  33324.  
  33325.  Remarks
  33326.  The argument variablename% is any BASIC variable name, including the name of
  33327.  a record variable or record element. Use WindowCurrent anywhere you need the
  33328.  number of the current window as an argument for other window procedures (for
  33329.  example, WindowClose and WindowCurrent).
  33330.  
  33331.  
  33332.  See Also:  WindowSetCurrent
  33333.  
  33334.  
  33335.  Example
  33336.  See the DemoWindow procedure in the code example UIDEMO.BAS for a specific
  33337.  usage example.
  33338.  
  33339.  
  33340.  
  33341.  
  33342.  WindowDo SUB
  33343.  
  33344.  Action
  33345.  Takes control of the program and waits for a button, edit-field, or window
  33346.  event to occur in an open window.
  33347.  
  33348.  
  33349.  Syntax
  33350.  WindowDo currButton%, currEdit%
  33351.  
  33352.  Remarks
  33353.  The WindowDo procedure uses the following arguments:
  33354.  
  33355.  currButton%
  33356.  -----------
  33357.  An integer that indicates the number of the current button. The current
  33358.  button is that button where the text cursor is located at the time of the
  33359.  call to WindowDo.
  33360.  
  33361.  
  33362.  currEdit%
  33363.  ---------
  33364.  An integer that indicates the number of the current edit field. The current
  33365.  edit field is the edit field where the text cursor is located at the time of
  33366.  the call to WindowDo. If it is 0, it is assumed that the text cursor is not
  33367.  currently in an edit field. If it is nonzero, WindowDo lets the user edit
  33368.  the current edit field.
  33369.  
  33370.  Only buttons and edit fields in the current window are active. If no buttons
  33371.  or edit fields are used in the window, use 0 for both arguments. Once an
  33372.  event takes place, use Dialog(0)
  33373.  to determine which event occurred.
  33374.  Program execution continues after an event occurs.
  33375.  
  33376.  See Also:  Dialog
  33377.  
  33378.  
  33379.  Example
  33380.  See the DemoDialog, DemoDialogEZ, DemoResize, DemoScrollBar, and DemoWindow
  33381.  procedures in the code example UIDEMO.BAS for specific usage examples.
  33382.  
  33383.  
  33384.  
  33385.  
  33386.  WindowInit SUB
  33387.  
  33388.  Action
  33389.  Initializes the global window, button, and edit-field arrays.
  33390.  
  33391.  Syntax
  33392.  WindowInit
  33393.  
  33394.  Remarks
  33395.  The WindowInit procedure is used at or near the beginning of any program
  33396.  that uses the window procedures provided by the User Interface toolbox. You
  33397.  must call WindowInit before any other window procedures are used. You can
  33398.  execute WindowInit again anytime you need to reset the windowing
  33399.  environment.
  33400.  
  33401.  See Also:  ButtonOpen, EditFieldOpen, WindowOpen
  33402.  
  33403.  
  33404.  
  33405.  
  33406.  WindowLine SUB
  33407.  
  33408.  Action
  33409.  Draws a horizontal line across the current window at the row specified.
  33410.  
  33411.  
  33412.  Syntax
  33413.  WindowLine row%
  33414.  
  33415.  Remarks
  33416.  The argument row% is an integer that describes a row relative to the top of
  33417.  the current window. The WindowLine procedure is used in dialog boxes to
  33418.  separate parts. WindowLine is used by the Alert procedure to draw a
  33419.  horizontal line above the buttons.
  33420.  
  33421.  
  33422.  See Also:  WindowPrint
  33423.  
  33424.  
  33425.  Example
  33426.  See the DemoDialogEZ procedure in the code example UIDEMO.BAS for a specific
  33427.  implementation.
  33428.  
  33429.  
  33430.  WindowLocate SUB
  33431.  
  33432.  Action
  33433.  Sets the row and column of the window text cursor in a window.
  33434.  
  33435.  
  33436.  Syntax
  33437.  WindowLocate row%, col%
  33438.  
  33439.  Remarks
  33440.  The coordinates row% and col% are integers that describe a print position
  33441.  relative to the upper-left corner of the current window. The WindowLocate
  33442.  procedure is used, once a window has been opened, to position the window
  33443.  text cursor to the starting point of a line of text. This is the position
  33444.  where the next character will be placed when a WindowPrint operation occurs.
  33445.  
  33446.  
  33447.  See Also:  WindowPrint
  33448.  
  33449.  
  33450.  Example
  33451.  See the DemoDialog procedure in the code example UIDEMO.BAS for a specific
  33452.  implementation.
  33453.  
  33454.  
  33455.  
  33456.  
  33457.  WindowNext FUNCTION
  33458.  
  33459.  Action
  33460.  Returns an integer that is the handle number of the next available window.
  33461.  
  33462.  
  33463.  Syntax
  33464.  variablename% = WindowNext
  33465.  
  33466.  Remarks
  33467.  The WindowNext procedure is used in situations where a window is to be
  33468.  opened, but the opening routine has no information about other windows that
  33469.  may already be open. The argument variablename% is any BASIC variable name,
  33470.  including the name of a record variable or record element.
  33471.  
  33472.  
  33473.  See Also:  WindowCurrent, WindowOpen
  33474.  
  33475.  
  33476.  
  33477.  
  33478.  WindowOpen SUB
  33479.  
  33480.  Action
  33481.  Defines and opens a window.
  33482.  
  33483.  
  33484.  Syntax
  33485.  WindowOpen handle%, row1%, col1%, row2%, col 2%, textFore%, textBack%,
  33486.  fore%, back%, highlight%, movewin%, closewin%, sizewin%, modalwin%,
  33487.  borderchar%, title$
  33488.  
  33489.  
  33490.  Remarks
  33491.  The WindowOpen procedure uses the following arguments:
  33492.  
  33493.  handle%
  33494.  -------
  33495.  An integer that indicates the number of the window that is being opened.
  33496.  This can be any number between 1 and the value declared in the constant
  33497.  MAXWINDOW, inclusive.
  33498.  
  33499.  row1%, col1%
  33500.  ------------
  33501.  An integer pair that specifies absolute screen row and column coordinates.
  33502.  
  33503.  row2%, col2%
  33504.  ------------
  33505.  An integer pair that specifies the lower-right-corner coordinates of an
  33506.  area.
  33507.  
  33508.  textFore%
  33509.  ---------
  33510.  An integer that defines text foreground color (0 - 15).
  33511.  
  33512.  textBack%
  33513.  ---------
  33514.  An integer that defines text background color (0 - 7).
  33515.  
  33516.  fore%
  33517.  -----
  33518.  An integer that defines window foreground color (0 - 15).
  33519.  
  33520.  back%
  33521.  -----
  33522.  An integer that defines window background color (0 - 7).
  33523.  
  33524.  highlight%
  33525.  ----------
  33526.  An integer that defines color (0 - 15) of highlighted buttons.
  33527.  
  33528.  movewin%
  33529.  --------
  33530.  TRUE indicates a movable window; FALSE indicates a stationary window.
  33531.  
  33532.  closewin%
  33533.  ---------
  33534.  TRUE indicates a window that can be closed; FALSE indicates a window that
  33535.  can't be closed.
  33536.  
  33537.  sizewin%
  33538.  --------
  33539.  TRUE indicates a resizable window; FALSE indicates a window that can't be
  33540.  resized.
  33541.  
  33542.  modalwin%
  33543.  ---------
  33544.  TRUE indicates a modal window; FALSE indicates a nonmodal window. When a
  33545.  window is modal, any attempt to select outside the window is unsuccessful
  33546.  and results in a beep.
  33547.  
  33548.  borderchar%
  33549.  -----------
  33550.  0 indicates no border; 1 indicates a single-line border; 2 indicates a
  33551.  double-line border.
  33552.  
  33553.  title$
  33554.  ------
  33555.  A string that is the title of the window. If title$ is a null string (""),
  33556.  no title is displayed.
  33557.  
  33558.  The WindowOpen procedure is used to open windows anywhere on the screen.
  33559.  Twenty-four basic window types are predefined in WINDOW.BAS; however, the
  33560.  fact that any of the basic types can be created as either a standard or
  33561.  modal window increases the available number to 48.
  33562.  
  33563.  See Also:  WindowBorder, WindowClose, WindowNext
  33564.  
  33565.  
  33566.  Example
  33567.  See the DemoWindow procedure in the code example UIDEMO.BAS for a specific
  33568.  implementation.
  33569.  
  33570.  
  33571.  
  33572.  WindowPrint SUB
  33573.  
  33574.  Action
  33575.  Prints text, in the style specified, in the current window at the position
  33576.  established by WindowLocate.
  33577.  
  33578.  
  33579.  Syntax
  33580.  WindowPrint style%, text$
  33581.  
  33582.  Remarks
  33583.  The WindowPrint procedure uses the following arguments:
  33584.  
  33585.  style%
  33586.  ------
  33587.  An integer that indicates the style of the text to be displayed.
  33588.  Possible values for style% and their significance are described as follows:
  33589.  
  33590.  Value     Significance
  33591.  
  33592.  1         Truncated printing. If text is longer than the window, it is
  33593.  truncated. The text cursor is moved to the first character of the next line.
  33594.  The window is scrolled, if necessary.
  33595.  2         Character wrapping. If text is longer than the window, the text
  33596.  continues on the next line, scrolling if necessary. The text cursor is moved
  33597.  to the first character on the next line, scrolling if necessary.
  33598.  3         Text wrapping. Same as style 2 except that text is wrapped only at
  33599.  spaces.
  33600.  4         Truncated centering. Text is centered on the current line. If text
  33601.  is too long, it is truncated.
  33602.  -1        Same as style 1 except, after printing, text cursor is positioned
  33603.  immediately following the last character printed.
  33604.  -2        Same as style 2 except, after printing, text cursor is positioned
  33605.  immediately following the last character printed.
  33606.  -3        Same as style 3 except, after printing, text cursor is positioned
  33607.  immediately following the last character printed.
  33608.  
  33609.  text$
  33610.  -----
  33611.  A string that contains the text to be displayed in the window.
  33612.  
  33613.  Use WindowPrint whenever you want to display text in a window.
  33614.  
  33615.  See Also:  WindowLocate
  33616.  
  33617.  
  33618.  Example
  33619.  See the DemoWindow procedure in the code example UIDEMO.BAS for a specific
  33620.  implementation.
  33621.  
  33622.  
  33623.  
  33624.  
  33625.  WindowPrintTitle SUB
  33626.  
  33627.  Action
  33628.  Used internally by the other procedures in WINDOW.BAS. Do not use or alter
  33629.  this procedure.
  33630.  
  33631.  
  33632.  Syntax
  33633.  WindowPrintTitle
  33634.  
  33635.  Remarks
  33636.  The WindowPrintTitle procedure prints a window's title bar.
  33637.  
  33638.  
  33639.  
  33640.  Warning
  33641.  -------
  33642.  Do not use or alter this procedure unless you are customizing the User
  33643.  Interface toolbox and you know how the use or alteration of this procedure
  33644.  will affect the operation of all other procedures in the toolbox.
  33645.  
  33646.  
  33647.  
  33648.  See Also:  WindowDo
  33649.  
  33650.  
  33651.  
  33652.  
  33653.  WindowRefresh SUB
  33654.  
  33655.  Action
  33656.  Used internally by the other procedures in WINDOW.BAS. Do not use or alter
  33657.  this procedure.
  33658.  
  33659.  
  33660.  Syntax
  33661.  WindowRefresh handle%
  33662.  
  33663.  Remarks
  33664.  The WindowRefresh procedure restores a window to the screen from a global
  33665.  array. The handle% is an integer that indicates the number of the window
  33666.  being restored. This can be any number between 1 and the value declared in
  33667.  the constant MAXWINDOW, inclusive.
  33668.  
  33669.  To restore part of the screen, use the PutBackground procedure in
  33670.  GENERAL.BAS.
  33671.  
  33672.  
  33673.  
  33674.  
  33675.  Warning
  33676.  -------
  33677.  Do not use or alter this procedure unless you are customizing the User
  33678.  Interface toolbox and you know how the use or alteration of this procedure
  33679.  will affect the operation of all other procedures in the toolbox.
  33680.  
  33681.  
  33682.  
  33683.  See Also:  WindowDo
  33684.  
  33685.  
  33686.  WindowRows FUNCTION
  33687.  
  33688.  Action
  33689.  Returns an integer that is the number of interior rows in the current
  33690.  window.
  33691.  
  33692.  
  33693.  Syntax
  33694.  variablename% = WindowRows (handle%)
  33695.  
  33696.  Remarks
  33697.  The WindowRows procedure uses the following arguments:
  33698.  
  33699.  variablename%
  33700.  -------------
  33701.  Any BASIC variable name, including the name of a record variable or record
  33702.  element.
  33703.  
  33704.  handle%
  33705.  -------
  33706.  An integer that indicates the number of the window whose row count is
  33707.  requested. This can be any number between 1 and the value declared in the
  33708.  constant MAXWINDOW, inclusive.
  33709.  
  33710.  Use WindowRows when you need to determine the number of interior rows in a
  33711.  window. Interior rows are those where text can be displayed. The WindowRows
  33712.  procedure can be used when resizing windows that contain text, to ensure
  33713.  that you don't print more text than there are lines available to print on.
  33714.  
  33715.  See Also:  WindowCols
  33716.  
  33717.  
  33718.  Example
  33719.  See the DemoWindow procedure in the code example UIDEMO.BAS for a specific
  33720.  implementation.
  33721.  
  33722.  
  33723.  
  33724.  
  33725.  WindowSave SUB
  33726.  
  33727.  Action
  33728.  Used internally by the other procedures in WINDOW.BAS. Do not use or alter
  33729.  this procedure.
  33730.  
  33731.  Syntax
  33732.  WindowSave handle%
  33733.  
  33734.  Remarks
  33735.  The WindowSave procedure saves a window into a global array.  If you want to
  33736.  save part of the screen, use the GetBackground procedure in GENERAL.BAS. The
  33737.  argument handle% is an integer that indicates the number of the window being
  33738.  saved. This can be any number between 1 and the value declared in the
  33739.  constant MAXWINDOW, inclusive.
  33740.  
  33741.  
  33742.  Warning
  33743.  -------
  33744.  Do not use or alter this procedure unless you are customizing the User
  33745.  Interface toolbox and you know how the use or alteration of this procedure
  33746.  will affect the operation of all other procedures in the toolbox.
  33747.  
  33748.  
  33749.  
  33750.  
  33751.  See Also:  WindowDo
  33752.  
  33753.  
  33754.  
  33755.  
  33756.  WindowScroll SUB
  33757.  
  33758.  Action
  33759.  Scrolls text in the current window by the number of lines specified.
  33760.  
  33761.  
  33762.  Syntax
  33763.  WindowScroll lines%
  33764.  
  33765.  Remarks
  33766.  The WindowScroll procedure is used in the WindowPrint procedure of the User
  33767.  Interface toolbox. The argument lines% is an integer that defines the number
  33768.  of lines to scroll. If lines% is greater than 0, the window scrolls up; if
  33769.  lines% is less than 0, the window scrolls down. If lines% equals 0, the
  33770.  window is cleared.
  33771.  
  33772.  
  33773.  See Also:  WindowCls, WindowPrint
  33774.  
  33775.  
  33776.  
  33777.  
  33778.  WindowSetCurrent SUB
  33779.  
  33780.  Action
  33781.  Makes the specified window the current window, placing it on top (in front)
  33782.  of any other windows that may be open.
  33783.  
  33784.  
  33785.  Syntax
  33786.  WindowSetCurrent handle%
  33787.  
  33788.  
  33789.  Remarks
  33790.  The WindowSetCurrent procedure is used to change to a new window. Only the
  33791.  current window is displayed with a shadow effect. The argument handle% is an
  33792.  integer that indicates the number of the window to make current. This can be
  33793.  any number between 1 and the value declared in the constant MAXWINDOW,
  33794.  inclusive.
  33795.  
  33796.  See Also:  WindowCurrent
  33797.  
  33798.  
  33799.  Example
  33800.  See the DemoWindow procedure in the code example UIDEMO.BAS for a specific
  33801.  implementation.
  33802.  
  33803.  
  33804.  WindowShadowRefresh SUB
  33805.  
  33806.  Action
  33807.  Used internally by the other procedures in WINDOW.BAS. Do not use or alter
  33808.  this procedure.
  33809.  
  33810.  
  33811.  Syntax
  33812.  WindowShadowRefresh handle%
  33813.  
  33814.  Remarks
  33815.  The WindowShadowRefresh procedure restores the background behind a shadow
  33816.  from a global array.  If you want to restore part of the screen, use the
  33817.  PutBackground procedure in GENERAL.BAS. The argument handle% is an integer
  33818.  that indicates the number of the window whose shadow background is being
  33819.  restored. This can be any number between 1 and the value declared in the
  33820.  constant MAXWINDOW, inclusive.
  33821.  
  33822.  
  33823.  
  33824.  Warning
  33825.  -------
  33826.  Do not use or alter this procedure  unless you are customizing the User
  33827.  Interface toolbox and you know how the use or alteration of this procedure
  33828.  will affect the operation of all other procedures in the toolbox.
  33829.  
  33830.  
  33831.  
  33832.  See Also:  WindowDo
  33833.  
  33834.  
  33835.  
  33836.  
  33837.  WindowShadowSave SUB
  33838.  
  33839.  Action
  33840.  Used internally by the other procedures in WINDOW.BAS. Do not use or alter
  33841.  this procedure.
  33842.  
  33843.  
  33844.  Syntax
  33845.  WindowShadowSave handle%
  33846.  
  33847.  Remarks
  33848.  The WindowShadowSave procedure saves the background (the area behind where a
  33849.  window's shadow is to be displayed) into a global array. If you want to save
  33850.  part of the screen, use the GetBackground procedure in GENERAL.BAS. The
  33851.  argument handle% is an integer that indicates the number of the window whose
  33852.  shadow background is being saved. This can be any number between 1 and the
  33853.  value declared in the constant MAXWINDOW, inclusive.
  33854.  
  33855.  
  33856.  Warning
  33857.  -------
  33858.  Do not use or alter this procedure  unless you are customizing the User
  33859.  Interface toolbox and you know how the use or alteration of this procedure
  33860.  will affect the operation of all other procedures in the toolbox.
  33861.  
  33862.  
  33863.  See Also:  WindowDo
  33864.  
  33865.  
  33866.  MOUSE.BAS
  33867.  
  33868.  The MOUSE.BAS source-code file supports the Microsoft Mouse and other
  33869.  pointing devices that have a 100 percent Microsoft-Mouse-compatible driver.
  33870.  Although the procedures can be used by themselves, they were designed as an
  33871.  integral part of the User Interface toolbox.
  33872.  
  33873.  If you use the procedures in MOUSE.BAS, you must include GENERAL.BI and
  33874.  MOUSE.BI in your program so you will have the proper declarations and
  33875.  definitions. The header file MOUSE.BI includes procedure declarations for
  33876.  the MOUSE.BAS file.
  33877.  A description of the procedures that comprise MOUSE.BAS follows.
  33878.  
  33879.  
  33880.  
  33881.  
  33882.  MouseBorder SUB
  33883.  
  33884.  Action
  33885.  Establishes the limits of mouse movement on the screen.
  33886.  
  33887.  
  33888.  Syntax
  33889.  MouseBorder row1%, col1%, row2%, col 2%
  33890.  
  33891.  Remarks
  33892.  The MouseBorder procedure uses the following arguments:
  33893.  
  33894.  row1%, col1%
  33895.  ------------
  33896.  An integer pair that specifies absolute screen row and column coordinates.
  33897.  
  33898.  row2%, col 2%
  33899.  -------------
  33900.  An integer pair that specifies the lower-right corner coordinates of an
  33901.  area.
  33902.  
  33903.  MouseBorder is used in WINDOW.BAS to establish the limits of mouse movement
  33904.  when windows are moved or resized. Mouse movement is permitted only within
  33905.  the boundary described by the parameters of MouseBorder.
  33906.  
  33907.  
  33908.  See Also:  WindowDo, MouseInit
  33909.  
  33910.  
  33911.  MouseDriver SUB
  33912.  
  33913.  Action
  33914.  Calls Interrupt 51 (33H) and passes the parameters to the proper registers.
  33915.  
  33916.  
  33917.  Syntax
  33918.  MouseDriver M0%, M1%, M2%, M3%
  33919.  
  33920.  Remarks
  33921.  The MouseDriver procedure uses the following arguments:
  33922.  
  33923.  M0%    An integer that is placed into the AX register.
  33924.  M1%    An integer that is placed into the BX register.
  33925.  M2%    An integer that is placed into the CX register.
  33926.  M3%    An integer that is placed into the DX register.
  33927.  
  33928.  Interrupt 51 provides DOS mouse services. Refer to the Microsoft Mouse
  33929.  Programmer's Guide for detailed information about mouse servicing routines.
  33930.  MouseDriver is used in MOUSE.BAS (all procedures) where access to operating
  33931.  system mouse routines is required.
  33932.  
  33933.  See Also:  MouseBorder, MouseHide, MouseInit, MousePoll,
  33934.                MouseShow
  33935.  
  33936.  
  33937.  
  33938.  
  33939.  MouseHide SUB
  33940.  
  33941.  Action
  33942.  Decrements a cursor flag in the mouse driver, causing the mouse cursor to be
  33943.  hidden.
  33944.  
  33945.  
  33946.  Syntax
  33947.  MouseHide
  33948.  
  33949.  Remarks
  33950.  Use this procedure before each time you print something on the screen, to
  33951.  prevent the mouse cursor from being overwritten. Once you've written to the
  33952.  screen, be sure to use a corre-sponding MouseShow procedure to turn the
  33953.  mouse cursor back on; otherwise you will be unable to see your mouse cursor.
  33954.  
  33955.  When the internal cursor flag is less than 0, the mouse cursor is hidden.;
  33956.  when it is 0, the mouse cursor is displayed. It is never greater than 0.
  33957.  
  33958.  
  33959.  MouseHide is used throughout the User Interface toolbox anytime something is
  33960.  displayed on the screen.
  33961.  
  33962.  
  33963.  Note
  33964.  ----
  33965.  The cursor flag is part of the mouse driver, not part of these mouse
  33966.  procedures or the User Interface toolbox.
  33967.  
  33968.  
  33969.  
  33970.  See Also:  MouseDriver, MouseShow
  33971.  
  33972.  
  33973.  
  33974.  
  33975.  MouseInit SUB
  33976.  
  33977.  Action
  33978.  Initializes the mouse-driver-servicing routines.
  33979.  
  33980.  
  33981.  Syntax
  33982.  MouseInit
  33983.  
  33984.  Remarks
  33985.  MouseInit is used at or near the beginning of any program that uses the
  33986.  procedures provided by the mouse procedures of the User Interface toolbox.
  33987.  MouseInit must be called before any other mouse procedures are used.
  33988.  
  33989.  The MouseInit procedure sets the cursor flag in the mouse driver to -1. When
  33990.  the internal cursor flag is less than 0, the mouse cursor is hidden; when it
  33991.  is 0, the mouse cursor is displayed. It is never greater than 0.
  33992.  
  33993.  
  33994.  
  33995.  Note
  33996.  ----
  33997.  The cursor flag is part of the mouse driver, not part of these mouse
  33998.  procedures or the User Interface toolbox.
  33999.  
  34000.  
  34001.  
  34002.  See Also:  MenuInit, MouseDriver
  34003.  
  34004.  
  34005.  
  34006.  
  34007.  MousePoll SUB
  34008.  
  34009.  Action
  34010.  Polls the mouse driver.
  34011.  
  34012.  
  34013.  Syntax
  34014.  MousePoll row%, col%, lbutton%, rbutton%
  34015.  
  34016.  Remarks
  34017.  The MousePoll procedure uses the following arguments:
  34018.  
  34019.  row%
  34020.  ----
  34021.  A variable that contains the row coordinate for the mouse cursor.
  34022.  
  34023.  col%
  34024.  ----
  34025.  A variable that contains the column coordinate for the mouse cursor.
  34026.  
  34027.  lbutton%
  34028.  --------
  34029.  A variable that contains the status of the left mouse button.
  34030.  
  34031.  rbutton%
  34032.  --------
  34033.  A variable that contains the status of the right mouse button.
  34034.  
  34035.  MousePoll places the row and column position of the mouse cursor into the
  34036.  row% and col% variables. The MousePoll procedure also determines the status
  34037.  of the left and right mouse buttons, and places the status (TRUE if pressed
  34038.  or FALSE if not) into the lbutton% and rbutton% variables, as appropriate.
  34039.  
  34040.  MousePoll is used throughout the User Interface toolbox whenever the
  34041.  location of the mouse cursor or the status of the mouse buttons is required.
  34042.  
  34043.  
  34044.  See Also:  MouseDriver
  34045.  
  34046.  
  34047.  
  34048.  
  34049.  MouseShow SUB
  34050.  
  34051.  Action
  34052.  Increments a cursor flag in the mouse driver that causes the mouse cursor to
  34053.  be displayed.
  34054.  
  34055.  
  34056.  Syntax
  34057.  MouseShow
  34058.  
  34059.  Remarks
  34060.  The MouseShow procedure is used each time you print something to the screen;
  34061.  it rewrites the mouse cursor to the screen. You should use a MouseShow
  34062.  procedure for each MouseHide you use in your program.
  34063.  
  34064.  
  34065.  When the internal cursor flag is less than 0, the mouse cursor is hidden.
  34066.  When it is 0, the mouse cursor is displayed. It is never greater than 0. If
  34067.  the internal cursor flag is already 0, this procedure has no effect.
  34068.  MouseShow is used throughout the User Interface toolbox whenever anything is
  34069.  displayed on the screen.
  34070.  
  34071.  
  34072.  
  34073.  Note
  34074.  ----
  34075.  The cursor flag is part of the mouse driver, not part of these mouse
  34076.  procedures or the User Interface toolbox.
  34077.  
  34078.  
  34079.  
  34080.  See Also:  MouseDriver, MouseHide
  34081.  
  34082.  
  34083.  GENERAL.BAS
  34084.  
  34085.  The GENERAL.BAS source-code file contains a number of  general purpose
  34086.  character-based routines that are used in both the MENU.BAS and WINDOW.BAS
  34087.  files. While these files can be used by themselves, they are intended to
  34088.  support the other procedures in the User Interface toolbox. If you use any
  34089.  of the procedures in GENERAL.BAS, you must include the header file,
  34090.  GENERAL.BI.
  34091.  
  34092.  A description of the procedures that comprise GENERAL.BAS follows
  34093.  
  34094.  
  34095.  
  34096.  
  34097.  AltToASCII$ FUNCTION
  34098.  
  34099.  Action
  34100.  Decodes the extended key codes associated with the Alt key, and returns only
  34101.  the individual ASCII character.
  34102.  
  34103.  
  34104.  Syntax
  34105.  variablename$ = AltToASCII$ (kbd$)
  34106.  
  34107.  Remarks
  34108.  The AltToASCII$ procedure uses the following arguments:
  34109.  
  34110.  variablename$
  34111.  -------------
  34112.  Any BASIC variable name, including the name of a record variable or record
  34113.  element.
  34114.  
  34115.  kbd$
  34116.  ----
  34117.  A string that contains a character entered at the keyboard.
  34118.  
  34119.  AltToASCII$ is used in the procedures in MENU.BAS to identify access keys
  34120.  that have been pressed for menu-item selection (Alt + 0 - 9, A - Z, - and
  34121.  =).
  34122.  For instance, pressing the Alt key with the "A" key places two scan-code
  34123.  values into the keyboard buffer, CHR$(0)+CHR$(30). AltToASCII$ strips off
  34124.  CHR$(0) and returns "A," which is the letter represented by scan code 30.
  34125.  
  34126.  The keyboard can be polled with either the BASIC INKEY$ procedure or the
  34127.  MenuInkey$ procedure (preferred) included in the MENU.BAS file in the User
  34128.  Interface toolbox.
  34129.  
  34130.  
  34131.  
  34132.  See Also:  MenuDo
  34133.  
  34134.  
  34135.  AttrBox SUB
  34136.  
  34137.  Action
  34138.  Changes the color of the characters within a box.
  34139.  
  34140.  
  34141.  Syntax
  34142.  AttrBox row1%, col1%, row2%, col 2%, attr%
  34143.  
  34144.  Remarks
  34145.  The AttrBox procedure uses the following arguments:
  34146.  
  34147.  row1%, col1%
  34148.  ------------
  34149.  An integer pair that specifies absolute screen row and column coordinates.
  34150.  
  34151.  row2%, col2%
  34152.  ------------
  34153.  An integer pair that specifies the lower-right corner coordinates of an
  34154.  area.
  34155.  
  34156.  attr%
  34157.  -----
  34158.  An integer that defines the color and intensity attributes for your
  34159.  particular display adapter. The number is derived by adding the product of
  34160.  16 times the value of the background color (0 - 7) to the value of the
  34161.  foreground color (0 - 15). See the entries for the SCREEN and PALETTE
  34162.  statement for more information.
  34163.  
  34164.  AttrBox changes the color attribute of characters within a box, described by
  34165.  column and row coordinates, to the attribute contained in the argument
  34166.  attr%. The characters within the described area are unaffected, except for
  34167.  changes in color.
  34168.  AttrBox is used in MENU.BAS to provide shadows for the menus, and in
  34169.  WINDOW.BAS to draw the shadow on newly displayed windows.
  34170.  
  34171.  
  34172.  See Also:  MenuDo, WindowShadowSave
  34173.  
  34174.  
  34175.  
  34176.  
  34177.  Box SUB
  34178.  
  34179.  Action
  34180.  Draws a box around a defined area, using the foreground and background
  34181.  colors specified.
  34182.  
  34183.  
  34184.  Syntax
  34185.  Box row1%, col1%, row2%, col 2%,  fore%, back%, border$,  fillflag%
  34186.  
  34187.  Remarks
  34188.  The Box procedure uses the following arguments:
  34189.  
  34190.  row1%, col1%
  34191.  ------------
  34192.  An integer pair that specifies absolute screen row and column coordinates.
  34193.  
  34194.  row2%, col 2%
  34195.  -------------
  34196.  An integer pair that specifies the lower-right corner coordinates of an
  34197.  area.
  34198.  fore%    An integer that defines the foreground color (0 - 7)
  34199.  
  34200.  back%
  34201.  -----
  34202.  An integer that defines the background color (0 - 15).
  34203.  
  34204.  border$
  34205.  -------
  34206.  Nine-character string that defines the characters that are used to create
  34207.  the box. Each character position is significant because it defines a
  34208.  particular part of the box. Characters are defined as follows:
  34209.  
  34210.  Position    Character described
  34211.  
  34212.      1        Upper-left-corner character
  34213.      2        Top-line character
  34214.      3        Upper-right-corner character
  34215.      4        Left-side line character
  34216.      5        Fill character for middle area
  34217.      6        Right-side line character
  34218.      7        Lower-left-corner character
  34219.      8        Bottom-line character
  34220.      9        Lower-right-corner character
  34221.  
  34222.  fillflag%
  34223.  ---------
  34224.  TRUE (-1) if the interior of the box is to be cleared;
  34225.  FALSE (0) if it is not.
  34226.  
  34227.  The Box procedure is used in WINDOW.BAS to draw boxes on the screen.
  34228.  
  34229.  The individual character entries in the argument border$ define which
  34230.  characters are used to draw the box. You can use any characters in either
  34231.  the standard ASCII or extended character set. Normally, box characters in
  34232.  the range CHR$(179) through CHR$(218) are used. (The figure on the following
  34233.  page shows the box characters and their corresponding ASCII codes.)
  34234.  
  34235.  
  34236.  Figure 3.1  Box border characters and their corresponding ASCII codes
  34237.  
  34238.  Box characters can be entered by pressing the Alt key and the appropriate
  34239.  numbers on the keypad. The function of each of the nine character positions
  34240.  in the argument border$ is shown in the table above.
  34241.  
  34242.  If fewer than nine characters are included in border$, a default single-line
  34243.  box is drawn; if more than nine characters are included, only the first nine
  34244.  are used.
  34245.  
  34246.  See Also:  WindowBox, WindowDo, WindowOpen
  34247.  
  34248.  
  34249.  GetBackground SUB
  34250.  
  34251.  Action
  34252.  Saves an area of the screen into a named buffer.
  34253.  
  34254.  
  34255.  Syntax
  34256.  GetBackground row1%, col1%, row2%, col 2%, buffer$
  34257.  
  34258.  Remarks
  34259.  The GetBackground procedure uses the following arguments:
  34260.  
  34261.  row1%, col1%
  34262.  ------------
  34263.  An integer pair that specifies absolute screen row and column coordinates.
  34264.  
  34265.  row2%, col 2%
  34266.  -------------
  34267.  An integer pair that specify the lower-right corner coordinates of an area.
  34268.  
  34269.  buffer$
  34270.  -------
  34271.  Name of the buffer variable where the defined area is to be stored.
  34272.  
  34273.  GetBackground is used in MENU.BAS to store in a buffer the area (for
  34274.  example, the background where a window is to be displayed) that a menu is to
  34275.  occupy, before the menu is displayed. GetBackground is also used in
  34276.  WINDOW.BAS to store in a buffer the area that a window is to occupy, before
  34277.  the window is displayed. When used with MENU.BAS or WINDOW.BAS, a buffer is
  34278.  created for each menu or window, up to the maximum allowable (normally 10 of
  34279.  each).
  34280.  
  34281.  There must be a buffer for each different area that is to be stored. The
  34282.  GetBackground procedure creates enough space in each buffer to hold the
  34283.  defined screen area. It then uses an assembly-language routine (GetCopyBox)
  34284.  to perform the actual screen-save operation.
  34285.  
  34286.  
  34287.  See Also:  MenuDo, PutBackground, WindowDo, WindowSave,
  34288.                  WindowShadowSave
  34289.  
  34290.  
  34291.  
  34292.  
  34293.  GetShiftState FUNCTION
  34294.  
  34295.  Action
  34296.  Returns the status of one of eight shift states.
  34297.  
  34298.  
  34299.  Syntax
  34300.  variablename% = GetShiftState (bit%)
  34301.  
  34302.  Remarks
  34303.  The GetShiftState procedure uses the following arguments:
  34304.  
  34305.  
  34306.  variablename%
  34307.  -------------
  34308.  Any BASIC variable name, including the name of a record variable or record
  34309.  element.
  34310.  
  34311.  bit%
  34312.  ----
  34313.  An integer between 0 and 7, inclusive, that defines which key status is
  34314.  requested.
  34315.  
  34316.      The returned value is TRUE if the state of the key is pressed (Alt,
  34317.  Ctrl, Shift) or On if the key operates as a toggle (Scroll Lock, NumLock,
  34318.  Caps Lock, Ins). If the key is not pressed or On, FALSE (0) is returned. The
  34319.  values for bit% and the keys represented are described as follows:
  34320.  
  34321.  Value    Key status (return value)
  34322.  
  34323.  0     Right Shift pressed (TRUE)/not pressed (FALSE)
  34324.  1     Left Shift pressed (TRUE)/not pressed (FALSE)
  34325.  2     Ctrl pressed (TRUE)/not pressed (FALSE)
  34326.  3     Alt pressed (TRUE)/not pressed (FALSE)
  34327.  4     Scroll Lock pressed (TRUE)/not pressed (FALSE)
  34328.  5     NumLock toggle on (TRUE)/off (FALSE)
  34329.  6     Caps Lock toggle on (TRUE)/off (FALSE)
  34330.  7     Ins toggle on (TRUE)/off (FALSE)
  34331.  
  34332.  The GetShiftState procedure is used in MENU.BAS to determine whether the Alt
  34333.  key has been pressed, so that user input can be properly processed to select
  34334.  the desired menu item. GetShiftState is also used in WINDOW.BAS when editing
  34335.  edit fields.
  34336.  
  34337.  See Also:  MenuDo, MenuEvent, WindowDo
  34338.  
  34339.  
  34340.  
  34341.  
  34342.  PutBackground SUB
  34343.  
  34344.  Action
  34345.  Restores the background from the named buffer to the row and column
  34346.  coordinates specified.
  34347.  
  34348.  
  34349.  Syntax
  34350.  PutBackground row%, col%, buffer$
  34351.  
  34352.  Remarks
  34353.  The PutBackground procedure uses the following arguments:
  34354.  
  34355.  row%, col%
  34356.  ----------
  34357.  An integer pair that specifies absolute screen row and column coordinates.
  34358.  
  34359.  buffer$
  34360.  -------
  34361.  Name of the buffer variable where the defined area was stored by the
  34362.  GetBackground procedure.
  34363.  
  34364.  PutBackground is used in MENU.BAS to restore an area on the screen from a
  34365.  buffer, after closing a menu. PutBackground is also used in WINDOW.BAS to
  34366.  restore an area on the screen from a buffer, after closing a window. The
  34367.  complementary action, that of storing the background in a buffer before a
  34368.  menu or window is displayed, is performed by the GetBackground procedure.
  34369.  
  34370.  Normally, a background is restored to the coordinates from which it was
  34371.  previously saved before a menu or window was displayed. The PutBackground
  34372.  procedure checks the screen boundaries to ensure that the area can be
  34373.  properly restored to the screen. It then actually uses an assembly-language
  34374.  routine (PutCopyBox) to restore the screen background. When used with
  34375.  MENU.BAS and WINDOW.BAS, buffers created for each menu or window contain the
  34376.  background for the area occupied by the menu or window. When the menu or
  34377.  window is no longer displayed, the background for that area is restored to
  34378.  the screen.
  34379.  
  34380.  
  34381.  See Also:  GetBackground, MenuDo, WindowDo, WindowRefresh,
  34382.                 WindowShadowRefresh
  34383.  
  34384.  
  34385.  
  34386.  
  34387.  Scroll SUB
  34388.  
  34389.  Action
  34390.  Scrolls the defined area.
  34391.  
  34392.  
  34393.  Syntax
  34394.  Scroll row1%, col1%, row2%, col 2%, lines%, attr%
  34395.  
  34396.  Remarks
  34397.  Scroll is used in WINDOW.BAS to scroll an area within a defined window. The
  34398.  Scroll procedure uses the following arguments:
  34399.  
  34400.  row1%, col1%
  34401.  ------------
  34402.  An integer pair that specifies absolute screen row and column coordinates.
  34403.  
  34404.  row2%, col2%
  34405.  ------------
  34406.  An integer pair that specifies the lower-right corner coordinates of an
  34407.  area.
  34408.  
  34409.  lines%
  34410.  ------
  34411.  An integer that defines the scrolling behavior that occurs within the
  34412.  defined area. If lines% is less than 0, the area scrolls down by that number
  34413.  of lines. If lines% is greater than 0, the area scrolls up by that number of
  34414.  lines. If lines% is 0, the defined area is cleared.
  34415.  
  34416.  attr%
  34417.  -----
  34418.  An integer in the range 0 - 7 that defines the color to fill any newly
  34419.  created blank lines.
  34420.  
  34421.  See Also:  WindowScroll
  34422.  
  34423.  
  34424.  Compatibility with Microsoft QuickBASIC  for the Macintosh
  34425.  Every effort has been made to retain a high degree of compatibility between
  34426.  the functionality in the User Interface toolbox and that which exists in
  34427.  QuickBASIC for the Apple Macintosh. Many programs from the Macintosh
  34428.  platform can be readily converted for use with the PC. However, there are
  34429.  some limitations that you should be aware of.
  34430.  Programs that use graphics windows on the Macintosh cannot be converted
  34431.  because this user interface package is text (character) based.
  34432.  
  34433.  Programs that use event trapping on the Macintosh must be converted to
  34434.  polling before conversion can be effected.
  34435.  
  34436.  Each Macintosh QuickBASIC window command has a functional counterpart in the
  34437.  User Interface toolbox. Often a Macintosh QuickBASIC command has more than
  34438.  one function. Where this is true, there may be more than one corresponding
  34439.  procedure for QuickBASIC on the PC. The following table can be used as a
  34440.  general guideline for converting programs from one platform to the other:
  34441.  
  34442.  Macintosh QuickBASIC     PC BASIC
  34443.  
  34444.  ALERT    Alert
  34445.  BUTTON function    ButtonInquire
  34446.  BUTTON statement    ButtonOpen, ButtonSetState, ButtonToggle
  34447.  BUTTON CLOSE    ButtonClose
  34448.  CLS     WindowCls
  34449.  COMMAND     ShortCutKeyDelete, ShortCutKeyEvent, ShortCutKeySet
  34450.  DIALOG     Dialog, WindowDo
  34451.  EDIT$    EditFieldInquire
  34452.  EDIT FIELD     EditFieldOpen
  34453.  EDIT FIELD     CLOSE, EditFieldClose
  34454.  LOCATE     WindowLocate
  34455.  PRINT     WindowPrint
  34456.  MENU function    MenuCheck, MenuEvent, MenuInkey$
  34457.  MENU statement    MenuColor, MenuItemToggle, MenuPreProcess, MenuSet,
  34458.  MenuSetState, MenuShow
  34459.  MENU RESET     MenuInit
  34460.  MENU ON    MenuOn
  34461.  MENU OFF     MenuOff
  34462.  MOUSE     MouseHide, MouseInit, MousePoll, MouseShow
  34463.  SCROLL     WindowScroll
  34464.  WINDOW function    WindowCols, WindowCurrent, WindowRows
  34465.  WINDOW statement    WindowColor, WindowInit, WindowOpen, WindowSetCurrent
  34466.  WINDOW CLOSE     WindowClose
  34467.  Miscellaneous     WindowBox, WindowLine
  34468.  
  34469.  A number of features are similar, but not exactly the same in both
  34470.  environments. Some of the differences are outlined below:
  34471.  
  34472.  *    Buttons cannot be disabled on the PC, only opened or closed.
  34473.  
  34474.  *    On the Macintosh, the active window may differ from the current output
  34475.  window. On the PC, the active window and the current window are the same.
  34476.  
  34477.  *    On the PC, the Dialog(0) procedure returns 2 whenever an edit field is
  34478.  selected, not just when there is more than one edit field, as occurs on the
  34479.  Macintosh.
  34480.  
  34481.  *    On the PC, edit fields cannot be centered or right justified. They are
  34482.  always left justified.
  34483.  
  34484.  *    Macintosh MOUSE functions 3 through 6 are not implemented on the PC.
  34485.  
  34486.  *    Macintosh WINDOW type 7 is not implemented in any manner on the PC.
  34487.  Window types are somewhat different on the PC than they are on the
  34488.  Macintosh. Each of the windows on the Macintosh - numbered 1 through 7 - has
  34489.  a slightly different functionality. The PC window types allow you to specify
  34490.  any combination of available features with WindowOpen, so that you have full
  34491.  control over the features of your PC windows. Custom window configurations,
  34492.  beyond the 24 basic types provided, can be created by modifying the
  34493.  WindowBorder procedure.
  34494.  
  34495.  
  34496.  A number of new or extended features have been implemented to enhance the
  34497.  usability of this package. These features are described as follows:
  34498.  
  34499.  *    The Dialog procedure has been greatly extended to cover the full range
  34500.  of menu and keyboard events.
  34501.  
  34502.  *    All menus are keyboard accessible by two means. Access keys (standard)
  34503.  are provided and shortcut keys (optional) can be user defined.
  34504.  
  34505.  *    Print formatting (word wrap, centering, and so on) can be specified.
  34506.  
  34507.  *    Window contents are automatically saved when windows overlap, so
  34508.  windows do not need to be refreshed. An exception is that a window must be
  34509.  refreshed when a window is resized. The programmer must ensure that
  34510.  refreshing occurs when a window is resized.
  34511.  
  34512.  *    Buttons and menus can be toggled.
  34513.  
  34514.  *    Scroll bars are implemented as button types 6 (vertical) and 7
  34515.  (horizontal).
  34516.  
  34517.  *    List boxes are implemented.
  34518.  
  34519.  *    Field buttons (invisible buttons that occupy an area of the screen) are
  34520.  implemented as button type 4.
  34521.  
  34522.  
  34523.