home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / basic / QB4NOTES.ZIP / QB4NOTES.TXT
Encoding:
Text File  |  1989-04-04  |  32.0 KB  |  929 lines

  1. Answers to Common Questions about QuickBASIC Version 4.00 for the IBM PC 
  2.  
  3. Summary:
  4.  
  5. The following application note was developed to provide users of
  6. QuickBASIC Version 4.00 with answers to common questions along with
  7. supplementary information. A copy of this application note 
  8. can be obtained from Microsoft Product Support
  9. Services by calling (206) 454-2030. 
  10.  
  11. This document contains the following sections:
  12.  
  13.   I. Answers to Common Questions about QuickBASIC Version 4.00
  14.  II. Enhancements/Changes from Previous Versions
  15. III. Documentation Errata for the LOF Function
  16.  
  17. More Information:
  18.  
  19. Microsoft QuickBASIC Version 4.00 for the IBM PC and Compatibles
  20.                              12/4/87
  21.  
  22. Answers to Common Questions about QuickBASIC Version 4.00
  23.  
  24. Question
  25.  
  26. Am I still limited to a maximum of 64K per dynamic numeric array?
  27.  
  28. Response
  29.  
  30. No. By using the /ah switch when invoking either QuickBASIC or the
  31. BASIC compiler, you can allocate dynamic arrays larger than 64K.
  32. Additionally, you are no longer restricted to only using dynamic
  33. arrays whose type are real. Huge arrays may be arrays of records,
  34. fixed-length strings, and numeric data, and may occupy all of
  35. available memory. The following example demonstrates how to allocate a
  36. dynamic string-array using a user-defined type: 
  37.  
  38. TYPE AddressType
  39.      Street              AS STRING * 30
  40.      AptNum              AS INTEGER
  41.      City                AS STRING * 20
  42.      STATE               AS STRING * 2
  43.      ZIP                 AS INTEGER
  44.      Pad                 AS STRING * 8       ' record size of 64 bytes
  45. END TYPE
  46.  
  47. DIM AddressBook(71680) AS AddressType        ' must compile using /ah
  48.                                              ' switch
  49.  
  50. Question:
  51.  
  52. Is it possible to reduce the size of the .EXE files?
  53.  
  54. Response
  55.  
  56. The following is a list of methods you can use to reduce the size of
  57. .EXE files: 
  58.  
  59. 1. Use the /E[XEPACK] linker switch. This linker option removes
  60.    sequences of repeated bytes and optimizes the "load-time relocation
  61.    table." The result is that executable files linked with this option 
  62.    may be smaller and load faster than files linked without this
  63.    option. When you make an .EXE file from within the QuickBASIC
  64.    Version 4.00 environment, the /E switch on the linker is on;
  65.    therefore, files are automatically EXEPACKed. 
  66.  
  67.    Note: You cannot use the /EXEPACK option with the /Q option.
  68.  
  69. 2. If you are creating a stand-alone .EXE file (i.e., using BCOM40),
  70.    and your program does NOT use the OPEN COM statement, your program 
  71.    will be about 4K smaller if you link with the supplied object file
  72.    NOCOM.OBJ (found on Disk 3, or Disk 2 if you are using 3.5-inch
  73.    disks). 
  74.  
  75. 3. NOEM.OBJ is another supplied object file. It allows stand-alone
  76.    executable files compiled with the /O option to be substantially
  77.    smaller when run on machines equipped with a math coprocessor. For
  78.    more information on the use of NOEM.OBJ, refer to the README.DOC
  79.    file found on Disk 1. 
  80.  
  81. Question
  82.  
  83. QuickBASIC Version 4.00 now supports calls to routines written in
  84. FORTRAN, C, QuickC and Pascal, as well as those written in QuickBASIC
  85. and Assembly. Which versions of these compilers can be used to develop
  86. mixed-language programs? 
  87.  
  88. Response
  89.  
  90. Calls can be made from QuickBASIC to routines developed with the
  91. following compiler versions: 
  92.  
  93. Language            Version Supported
  94.  
  95. FORTRAN                  4.00
  96. Pascal                   4.00
  97. C                        5.00
  98. QuickC                   1.00
  99. Assembly                 4.00
  100.  
  101. Question
  102.  
  103. How do I go into 43-line mode in the editor and debugger?
  104.  
  105. Response
  106.  
  107. The new /H option for QuickBASIC displays the highest resolution
  108. possible on your hardware. For example, if you have an EGA, QuickBASIC
  109. displays 43 lines and 80 columns of text. This option is used with the
  110. QB command, e.g. QB DEMO1.BAS /H. 
  111.  
  112. As with previous versions of QuickBASIC, your programs can also put
  113. the screen into 43-line mode on an EGA-equipped machine. See the entry
  114. for the WIDTH statement in the BASIC language reference manual for
  115. more information. 
  116.  
  117. Question
  118.  
  119. Are QuickBASIC and its compiled programs compatible with Microsoft
  120. Windows? 
  121.  
  122. Response
  123.  
  124. The QuickBASIC Version 4.00 compiler and its compiled programs will
  125. only run as "Bad Applications" in Microsoft Windows. "Bad
  126. Applications" require you to create a PIF (Program Information File)
  127. using the Windows PIFEDIT.EXE program. When you make the .PIF file
  128. for QuickBASIC and its compiled programs, you will need to specify
  129. "Directly Modifies: Screen, Keyboard, COM1, COM2, and Memory".
  130. QuickBASIC Version 4.00 programs have been successfully tested under
  131. Microsoft Windows. 
  132.  
  133. The QB.PIF files provided on the Version 4.00 release disk can be
  134. studied in PIFEDIT.EXE as a guideline for making your own PIF files
  135. for your .EXE programs compiled in QuickBASIC. 
  136.  
  137. QuickBASIC Versions 3.00 and earlier have not been tested under
  138. Microsoft Windows, and may or may not run successfully as "Bad
  139. Applications." 
  140.  
  141. Question
  142.  
  143. How is memory allocated for static and dynamic arrays?
  144.  
  145. Response
  146.  
  147. The BASIC run-time system allocates a full 64K data segment,
  148. regardless of array usage. In the environment, all arrays are NOT
  149. taken out of this space, and are rounded up to the nearest paragraph
  150. in size. Note that there is, of course, symbol-table overhead also
  151. associated with these arrays that takes additional space. 
  152.  
  153. In stand-alone EXE files, static arrays are in the 64K data segment,
  154. but have no overhead information. The size allocated is the size
  155. dimensioned. $DYNAMIC numeric arrays and $DYNAMIC arrays of
  156. user-defined types are not taken out of the data segment, but do have
  157. some overhead information that is taken out of the data segment. 
  158.  
  159. When determining size requirements for programs, it is not enough to
  160. consider only your program's size and its associated data. The
  161. run-time system for stand-alone EXEs, and the QuickBASIC environment
  162. itself, have additional memory requirements, based on what you are
  163. attempting to do and the compile options selected. 
  164.  
  165. Question
  166.  
  167. When linking with BCOM (i.e., using /O compiler option), are all
  168. routines from the BCOM.LIB linked in, or only those that are needed to
  169. execute the program? Similarly, when using BRUN, is the entire file
  170. loaded into memory or are only the needed routines loaded in? 
  171.  
  172. Response
  173.  
  174. When linking with /O, QuickBASIC searches the BCOM.LIB library for
  175. modules containing the procedures referenced in the program. If an
  176. object module in the library does not contain procedures referenced in
  177. the program, it is not included in the executable file. 
  178.  
  179. When linking without /O, the entire run-time module (BRUN40.EXE) is
  180. always loaded into memory prior to execution. 
  181.  
  182. Question
  183.  
  184. Now that the FIELD statement is optional, does its use have any effect
  185. on how programs execute? Is it "better" to define records through the
  186. TYPE...END TYPE statement versus the FIELD statement? 
  187.  
  188. Response
  189.  
  190. The FIELD statement has not been degraded in comparison to earlier
  191. versions. However, the use of user-defined types is definitely
  192. recommended over use of the FIELD statement. Using TYPEs is indeed
  193. somewhat faster than the FIELD statement in some respects. It is most
  194. certainly less complex internally, and a more powerful programming
  195. tool. We strongly recommend its use over the FIELD statement. 
  196.  
  197. Question
  198.  
  199. When the following program is compiled, a subscript-out-of-range
  200. message is generated, even when the switch /ah (for huge arrays) is
  201. used. Why? 
  202.  
  203. DEFINT A-Z
  204. TYPE test
  205.   a AS DOUBLE
  206.   b AS STRING * 288
  207. END TYPE
  208. max = 453
  209.  
  210. REM $DYNAMIC
  211. DIM x(1 TO max)  AS test
  212.  
  213. Response
  214.  
  215. When space is allocated for huge arrays, it is done so in 64K blocks.
  216. If a record size cannot evenly be divided into 64K, a "gap" will
  217. appear between the allocated blocks. However, DOS will only permit one
  218. gap to appear within any huge array. Subsequently, more than two 64K
  219. blocks cannot be allocated when gaps occur. 
  220.  
  221. You can compensate for this limitation by padding each array element
  222. to a size that can be evenly divided into 64K (i.e., 128, 512, etc.).
  223. For the above example, this workaround would be as follows: 
  224.  
  225. DEFINT A-Z
  226. TYPE test
  227.    a   AS DOUBLE            ' 8 BYTES
  228.    b   AS STRING * 288      ' 288 BYTES
  229.    PAD AS STRING * 216      ' workaround: pads to a
  230.                             ' record size of 512 bytes
  231. END TYPE
  232. max = 453
  233. REM $DYNAMIC
  234.  
  235. DIM x(1 TO max) AS test
  236.  
  237. Question
  238.  
  239. Whenever I link a QuickBASIC Version 4.00 program with a FORTRAN
  240. routine that contains WRITE statements, an out-of-heap-space message
  241. is displayed at run time. 
  242.  
  243. Response
  244.  
  245. The following sequence demonstrates a workaround to this problem:
  246.  
  247. ' QuickBASIC program CALLTEST2.BAS
  248. '
  249. DECLARE SUB test2()
  250. CALL test2
  251. END
  252.  
  253.  
  254. ' QuickBASIC routine NEARHEAP.BAS
  255. ' that increases heap space by 2k
  256. '
  257. DIM x%(2048)
  258. COMMON SHARED /nmalloc/ x%()
  259.  
  260.  
  261. C
  262. C   FORTRAN routine TEST2.FOR
  263. C
  264.      subroutine test2()
  265.      write(*,*) 'this is FORTRAN'
  266.      pause
  267.      end
  268.  
  269. 1. Compile the FORTRAN subroutine as follows:
  270.  
  271.    fl /FPi /c test2.for
  272.  
  273. 2. Compile NEARHEAP.BAS as follows:
  274.  
  275.    bc nearheap.bas;
  276.  
  277. 3. Create the Quick library TEST2.QLB containing the FORTRAN routine
  278.    TEST2.FOR and NEARHEAP.OBJ:
  279.  
  280.    link test2+nearheap /q /noe,,nul,bqlb40.lib;
  281.  
  282. 4. Create the library file TEST2.LIB, which contains the FORTRAN
  283.    routine and NEARHEAP.OBJ:
  284.  
  285.    lib test2+test2+nearheap;
  286.  
  287. 5. At this point you can now work inside the QuickBASIC Version 4.00
  288.    editor using the following command:
  289.  
  290.    qb calltest2 /l test2.qlb
  291.  
  292.  
  293.    Or, you can create an EXE file as follows:
  294.  
  295.    qb calltest2;
  296.    link calltest2,,,test2.lib;
  297.  
  298. Question
  299.  
  300. When using the communications port, QuickBASIC will not run with eight
  301. data bits plus parity on the serial port. Why? 
  302.  
  303. Response
  304.  
  305. QuickBASIC defines a 10-bit data frame. The frame is as follows:
  306.  
  307.                         1 2  -  8 9 A
  308.                         S DDDDDDD P S
  309.  
  310. Bit  1     = Start Bit  (Always)
  311. Bits 2 - 8 = Data Bits  (Optional 7 or 8)
  312. Bit  9     = Parity     (Optional Odd, Even, One)
  313. Bit  A     = Stop Bit   (Optional 1 or 2)
  314.  
  315. The combination of the bits should always add up to ten bits. When you
  316. try to set 1 start + 8 data + 1 parity + 1 stop, that adds up to an
  317. 11-bit data frame. 
  318.  
  319. Question
  320.  
  321. Can a program that accesses the communications port (COM1: or COM2:)
  322. be affected by a QuickBASIC program that was run previously? 
  323.  
  324. Response
  325.  
  326. The answer is yes for Versions 1.x, 2.x, and 3.00 of QuickBASIC. If a
  327. program leaves any of the communications port lines ON when it exits,
  328. a program can have problems opening that communications port on any
  329. subsequent execution. 
  330.  
  331. In Version 3.00, if a program exits after a "Device Timeout" on the
  332. communications port, DTR and RTS remain ON. 
  333.  
  334. In Version 4.00, the DTR and RTS lines are cleared after a "Device
  335. Timeout" error. 
  336.  
  337. Question
  338.  
  339. Is it possible to use the COM2: port without having COM1: addressed?
  340. When COM2: is opened for I/O, a bad filename error is issued. 
  341.  
  342. Response
  343.  
  344. Yes, the hardware for COM2: can work without COM1:. QuickBASIC looks
  345. in the BIOS data area at RS232_BASE. This area stores the addresses of
  346. up to four serial communications ports. When you start your system,
  347. the BIOS initialization code checks for serial ports, puts in the
  348. addresses of any it finds, and sets the rest of the locations to zero.
  349. When both COM1: and COM2: are present, the address of COM1: (3F8h), is
  350. in the first word of RS232_BASE and the address of COM2: (2F8h) is in
  351. the second word. However, when QuickBASIC is loaded, it looks at
  352. RS232_BASE to see what serial ports are present, but it only
  353. recognizes COM2: when its address is in the second word. 
  354.  
  355. There is a way to work around this. The following program patches the
  356. second word of RS232_BASE with the address of COM2: 
  357.  
  358. DEF SEG = &H40
  359. IF (PEEK(0)) + 256 * PEEK(1)) = &H2F8 THEN
  360.    POKE 2, &HF8
  361.    POKE 3, &H2
  362.    PRINT "COM2 patch made"
  363. ELSE
  364.    PRINT "COM2 patch NOT made"
  365. END IF
  366.  
  367. This program must be run before you run your QuickBASIC application
  368. that uses COM2:. If you put this code at the beginning of your
  369. program, it will be executed too late to do any good because
  370. QuickBASIC checks for serial ports before it starts running your first
  371. BASIC statement. 
  372.  
  373. Question
  374.  
  375. When I put SOUND statements at the end of the program and run the .EXE
  376. file, the SOUND is truncated at the end. Why? 
  377.  
  378. Response
  379.  
  380. When a program ends, the BASIC run-time system is exited, which
  381. immediately stops any SOUND whose duration exceeds the time taken to
  382. execute any remaining statements in the program. This problem will not
  383. occur in the editor environment since the run-time system is still
  384. available. 
  385.  
  386. To allow the program enough time to complete its SOUND statements,
  387. give the program something to do after the SOUND (a dummy loop for
  388. example) so that the SOUND has time to finish before the program
  389. terminates. 
  390.  
  391. Question
  392.  
  393. My assembly subroutine, which worked with my QuickBASIC Version 3.00
  394. program, now hangs the machine without even calling the MASM routine
  395. when linked with a QuickBASIC Version 4.00 program and run. However,
  396. it runs correctly inside the editor when placed inside a Quick
  397. Library. 
  398.  
  399. Response
  400.  
  401. The problem is due to the use of a label with the END directive in the
  402. assembly routine. This syntax indicates to the linker where program
  403. execution will start. When the linker is used to create an executable
  404. program, it examines each .OBJ file in order to determine whether that
  405. file has an entry point specified. The first .OBJ that specifies an
  406. entry point is assumed by the linker to be the main program, i.e.,
  407. where program execution is to begin. 
  408.  
  409. In earlier versions of the compiler, the QuickBASIC object code
  410. contains an entry-point specifier; therefore, by simply listing your
  411. QuickBASIC object files before the assembly files, the linker
  412. recognizes that the QuickBASIC program is the main program. However,
  413. in QuickBASIC Version 4.00, the entry-point information is no longer
  414. in the object file; rather it resides in the run-time module (i.e.,
  415. BCOM40.LIB or BRUN40.LIB). Therefore, because these files are linked
  416. in after the QuickBASIC and Assembly object files, if the Assembly
  417. routine specifies an entry point, the linker will incorrectly assume
  418. that program execution is to begin in the Assembly routine. 
  419.  
  420. The workaround for this problem is simply to omit the entry-point
  421. specification in your Assembly routine. 
  422.  
  423. The following is an example of the problem:
  424.  
  425. code     segment byte    public  'code'
  426. .
  427. .
  428. temp     proc    far
  429. .
  430. .
  431. temp     endp
  432.  
  433. code     ends
  434.  
  435.          end     temp           ; Problem here
  436.  
  437. The following is a workaround for this problem:
  438.  
  439. code     segment byte    public  'code'
  440. .
  441. .
  442. temp     proc    far
  443. .
  444. .
  445. temp     endp
  446.  
  447. code     ends
  448.  
  449.          end
  450.  
  451. Enhancements/Changes from Previous Versions
  452.  
  453. DOS Patching
  454.  
  455. Users of IBM PC-DOS Version 3.20 no longer need to patch their DOS.
  456. This patch, which was supplied with QuickBASIC Version 3.00, was only
  457. necessary with QuickBASIC Version 3.00 when running QB87.EXE on
  458. machines equipped with math coprocessors AND using IBM PC-DOS Version
  459. 3.20. 
  460.  
  461. OPEN COM Statement
  462.  
  463. Three new options have been added to the OPEN COM statement (these
  464. options are more fully described in the QuickBASIC language reference
  465. manual): 
  466.  
  467. 1. OP[m]  Controls how long the statement waits for the OPEN to be
  468.           successful. 
  469. 2. RB[m]  Sets the size of the receive buffer. If omitted, the
  470.           default value is used. The default value can be set by the
  471.           /c option on the QuickBASIC or the BASIC compiler command
  472.           line. 
  473. 3. TB[m]  Sets the size of the transmit buffer. If omitted, the
  474.           default size of 128 bytes is used.
  475.  
  476. LOF Function
  477.  
  478. When used with the OPEN COM statement, the LOF function now returns
  479. the number of bytes free in the OUTPUT buffer. In earlier versions of
  480. QuickBASIC, this function returned the number of bytes in the input
  481. buffer, a function that nearly duplicated that of the LOC function. 
  482.  
  483. Previously, the LOF function could also be used to verify the size of
  484. the input buffer (which could be set with the /c option). The buffer
  485. size can still be verified within a program using the following
  486. formula: 
  487.  
  488. beforeopen = SETMEM(640000)     ' -> beforeopen = #bytes in far heap
  489.                                 ' setmem will not be able to allocate
  490.                                 ' 640000 bytes, rather only as much as
  491.                                 ' possible.
  492.  
  493. OPEN "COM1: 1200,e,7,1,RB(512),TB(512)" FOR OUTPUT AS #1
  494.                                 ' opening comm port will reduce the # of
  495.                                 ' bytes in the far heap by the sum of
  496.                                 ' bytes used by the transmitting and
  497.                                 ' receiving buffers (i.e., 1024 bytes).
  498.  
  499. spaceused = beforeopen - SETMEM(640000)
  500.                                 ' -> spaceused = # bytes allocated for
  501.                                 ' the two com buffers plus about 32
  502.                                 ' to compensate for the bytes needed
  503.                                 ' for paragraph alignment.
  504.  
  505. CALL PTR86 => VARSEG and VARPTR Commands
  506.  
  507. The PTR86 interrupt routine used in previous versions of QuickBASIC to
  508. obtain the address of a large numeric-array variable is no longer
  509. supported in QuickBASIC Version 4.00. The same information is now
  510. available through the commands VARPTR and VARSEG. 
  511.  
  512. The program below demonstrates how PTR86 is used in QuickBASIC Version
  513. 3.00 and QuickBASIC Version 2.x. This example is followed by an
  514. equivalent program using the QuickBASIC Version 4.00 statements VARSEG
  515. and VARPTR. 
  516.  
  517. ' QB3 and QB2.x version using CALL PTR86
  518. '
  519. REM $DYNAMIC
  520. DIM buffer%(25)
  521.  
  522. FOR i% = 0 TO 25                        ' initialize array
  523.      buffer%(i%) = i%
  524.      PRINT buffer%(i%);
  525. NEXT i%
  526.  
  527. PRINT
  528. CALL PTR86(varseg%, varoff%, VARPTR(buffer%(0)))
  529.  
  530. DEF SEG = varseg%
  531.  
  532. FOR i% = 0 TO 25
  533.      x% = PEEK(varoff% + ( 2 * i%))
  534.      PRINT x%;
  535. NEXT I%
  536.  
  537. END
  538.  
  539.  
  540. =============================================
  541.  
  542. ' QB4 version using VARSEG and VARPTR
  543. '
  544. REM $DYNAMIC
  545. DIM buffer%(25)
  546.  
  547. FOR i% = 0 TO 25                        ' initialize array
  548.      buffer%(i%) = i%
  549.      PRINT buffer%(i%);
  550. NEXT i%
  551.  
  552. PRINT
  553. DEF SEG = VARSEG(buffer%(0))
  554.  
  555. FOR i% = 0 TO 25
  556.      x% = PEEK(VARPTR(buffer%(i%)))
  557.      PRINT x%;
  558. NEXT I%
  559.  
  560. END
  561.  
  562. The following is the output from either program:
  563.  
  564. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
  565.  
  566. CALL INT86 =>  CALL INT86OLD or CALL INTERRUPT Statement
  567.  
  568. QuickBASIC programs that use the CALL INT86 and INT86X interrupt
  569. routines will need to be modified to run under QuickBASIC Version
  570. 4.00. The CALL INTERRUPT, CALL INTERRUPTX, CALL INT86OLD and CALL
  571. INT86XOLD routines provide compatibility with older programs using
  572. INT86 and INT86X. Like the previous routines, these new statements are
  573. distributed in a Quick library (QB.QLB and QB.LIB) on the distribution
  574. disks. 
  575.  
  576. The following program provides an example of how the CALL INT86
  577. statement is used in QuickBASIC Version 2.x and QuickBASIC Version
  578. 3.00. Corresponding versions of the program using CALL INT86OLD and
  579. CALL INTERRUPT follow. 
  580.  
  581. '
  582. '  This QuickBASIC program will send a copy of the screen output
  583. '  to the line printer using the INT86 routine. The DOS
  584. '  interrupt &H05 will direct the screen output to be printed
  585. '  to the line printer.
  586. '
  587. '
  588. dim inary%(7), outary%(7)
  589. '
  590. for i=1 to 10
  591.    print
  592.    for j=1 to 10
  593.      print "*";
  594.    next j
  595. next i
  596. '
  597. '
  598. call int86(&h05,varptr(inary%(0)),varptr(outary%(0)))
  599. '
  600. end
  601. =======================================================
  602.  
  603. ' Same program converted to use the QB4 statement CALL INT86OLD
  604.  
  605. DIM inary%(7), outary%(7)
  606.  
  607. FOR i = 1 TO 10
  608.     FOR j = 1 TO 10
  609.         PRINT "*";
  610.     NEXT j
  611.     PRINT
  612. NEXT i
  613.  
  614. CALL int86old(&H05, inary%(), outary%())           'screen dump
  615. '
  616. END
  617.  
  618.  
  619. ======================================================
  620.  
  621. ' QB4 version using the CALL INTERRUPT statement
  622.  
  623. TYPE RegType
  624.     AX AS INTEGER
  625.     BX AS INTEGER
  626.     CX AS INTEGER
  627.     DX AS INTEGER
  628.     BP AS INTEGER
  629.     SI AS INTEGER
  630.     DI AS INTEGER
  631.     FLAGS AS INTEGER
  632. END TYPE
  633.  
  634. DIM inary AS RegType
  635. DIM outary AS RegType
  636.  
  637. CLS
  638. FOR i = 1 TO 10
  639.     FOR j = 1 TO 10
  640.         PRINT "*";
  641.     NEXT j
  642.     PRINT
  643. NEXT i
  644.  
  645. CALL interrupt(&H05, inary, outary)           'screen dump
  646. '
  647. END
  648.  
  649. Quick Libraries
  650.  
  651. Quick Libraries are analogous to the User Libraries created with
  652. QuickBASIC Versions 2.00, 2.01, and 3.00. Like User Libraries, a Quick
  653. Library is composed of compiled or assembled modules. These modules
  654. can then be CALLed from QuickBASIC programs during an editing session
  655. within the QuickBASIC Version 4.00 editor. 
  656.  
  657. However, unlike User Libraries, a Quick Library can only be used
  658. within an editing session; Quick Libraries are not used in the
  659. creation or running of an .EXE file. To create an executable program,
  660. the LIB.EXE utility program must be used to create a .LIB file that is
  661. composed of the same .OBJ files contained in the Quick Library. This
  662. library file can then be linked to a compiled QuickBASIC program that
  663. CALLs the procedures in the .LIB file. 
  664.  
  665. Another new characteristic of Quick Libraries is their "granularity."
  666. This feature implies that when linked to a CALLing QuickBASIC module,
  667. only those modules in that Quick Library that are actually called will
  668. be linked into the executable program. Therefore, in order to fully
  669. benefit from this feature, each .OBJ file linked into a Quick Library
  670. should contain either only one procedure (i.e., a subprogram or a
  671. function) or those procedures that will always be called together. 
  672.  
  673. This granular concept can be illustrated using the following
  674. QuickBASIC files: 
  675.  
  676. 'MAIN.BAS - main module that calls the subprogram "a"
  677. CALL a
  678. END
  679.  
  680.  
  681. 'A.BAS - separately compiled module containing the
  682. '        subprogram a that is CALLed from MAIN.BAS
  683. SUB a
  684.      PRINT "in sub a"
  685. END SUB
  686.  
  687.  
  688. 'B.BAS - separately compiled module containing the
  689. '        subprogram b that is never CALLed.
  690. SUB b
  691.      PRINT "in sub b"
  692. END SUB
  693.  
  694.  
  695. 'AB.BAS - separately compiled module containing both
  696. '         subprograms a and b.
  697. SUB a
  698.      PRINT "in sub a"
  699. END SUB
  700.  
  701. SUB b
  702.      PRINT "in sub b"
  703. END SUB
  704.  
  705.  
  706. First, each of the files is compiled as follows:
  707.  
  708. MAIN.BAS -> MAIN.OBJ
  709. A.BAS    -> A.OBJ
  710. B.BAS    -> B.OBJ
  711. AB.BAS   -> AB.OBJ
  712.  
  713. Next, two Quick Libraries and two corresponding library files are
  714. created. 
  715.  
  716. The first one, A.QLB, combines the object files A.OBJ and B.OBJ as
  717. follows: 
  718.  
  719. A.OBJ \
  720.        ==> A.QLB and A.LIB
  721. B.OBJ /
  722.  
  723. The second Quick Library will be created from the file AB.OBJ as
  724. follows: 
  725.  
  726. AB.OBJ => AB.QLB and AB.LIB
  727.  
  728. Finally, using MAIN.OBJ, two executable programs are created as
  729. follows: 
  730.  
  731. link MAIN.OBJ, MAINA.EXE, A.LIB;
  732. link MAIN.OBJ, MAINAB.EXE, AB.LIB;
  733.  
  734. The resulting .EXE files will execute identically; however, the
  735. version created using AB.LIB (i.e., MAINAB.EXE) will be larger because
  736. even though only one subprogram is called from MAIN.BAS, both SUB a
  737. and SUB b will be linked in because they are both contained in the
  738. same .OBJ file. 
  739.  
  740. Creating Quick Libraries inside the QuickBASIC Version 4.00
  741. Environment 
  742.  
  743. There are now two methods of creating Quick Libraries. The first, and
  744. easiest method, is to create them within the QuickBASIC Version 4.00
  745. editor by selecting the Make Lib option from the Run menu. To create a
  746. Quick Library in this manner, perform the following steps: 
  747.  
  748. 1. Using the Load option from the File menu, Load into the editor all
  749.    the BASIC files you want to be included in the Quick Library. 
  750.  
  751. 2. Select the Make Lib option from the Run menu. Once this option is
  752.    selected, the following events automatically occur: 
  753.  
  754.    a. BC.EXE is invoked and each currently loaded BASIC module is
  755.       compiled and its object file saved to disk. 
  756.  
  757.    b. The LINK.EXE utility is invoked with the /Q[UICKLIB] switch to
  758.       combine all the previously compiled object files plus the
  759.       supplied file BQLB40.LIB (which contains the support routines
  760.       need to create a Quick Library) into a Quick Library. The Quick
  761.       Library will by default have as its name the base name given by
  762.       the user plus the extension .QLB. This .QLB file is then written
  763.       to disk. 
  764.  
  765.    c. The LIB.EXE utility is invoked to create a .LIB file from the
  766.       object files previously created with the BASIC compiler. This
  767.       library file must be present if you intend to create an EXE
  768.       (i.e., executable) program that uses these routines. 
  769.  
  770.          NOTE: This method for creating a Quick Library can only be
  771.       used when placing QuickBASIC routines in your library. When
  772.       non-BASIC routines are included (i.e., those written in
  773.       Assembly, FORTRAN, Pascal, or C), the Quick Library must be 
  774.       created from the DOS command line. The following section
  775.       describes this method. 
  776.  
  777. Creating Quick Libraries from the DOS Command Line
  778.  
  779. Previous versions of QuickBASIC allowed you to create only User
  780. Libraries from the DOS command line. This was accomplished through the
  781. use of the BUILDLIB.EXE utility. With QuickBASIC Version 4.00, the
  782. BUILDLIB.EXE file is no longer provided; instead, Quick Libraries are
  783. created using the command-line /Q[UICKLIB] option with the linker
  784. (LINK.EXE). 
  785.  
  786. For example, the files A.BAS and B.BAS described above can be made
  787. into a Quick Library and parallel .LIB file using the following DOS
  788. commands: 
  789.  
  790. BC A.BAS;                                    => A.OBJ
  791. BC B.BAS;                                    => B.OBJ
  792. LINK /Q A.OBJ B.OBJ,AB.QLB,,BQLB40.LIB;      => AB.QLB
  793. LIB AB.LIB+A.OBJ+B.OBJ;                      => AB.LIB
  794.  
  795. Run-Time Memory Maps
  796.  
  797. This section contains illustrations of three different run-time memory
  798. maps. The following figure shows the run-time memory map as it appears
  799. when the run-time module BRUN40.EXE is used with the separate
  800. compilation method: 
  801.  
  802. 0000:0000----------> ______________
  803.                     |    MS-DOS    |  MS-DOS Operating System
  804.                     |              |
  805. Low Memory--------->|   User Code  |  User program separately linked
  806.                     |              |     with BRUN40.LIB
  807. User data---------->|              |
  808. Start DS:0          |    _DATA     |  QuickBASIC run-time data
  809.                     |    CONST     |     areas, used during user code
  810.                     |    _BSS      |     execution
  811.                     |              |
  812.                     |              |
  813.                     |Quick Library |  Quick library data loaded during
  814.                     |    data      |     startup (optional)
  815.                     |              |
  816.                     | Blank COMMON |  Quick library and user
  817.                     |              |     definitions
  818. Up to               |   BC_CONST   |
  819. 64k bytes           |              |  User program constants
  820.                     |   BC_DATA    |
  821.                     |              |  User program variables
  822.                     |    Named     |
  823.                     |    COMMON    |  Named COMMON areas
  824.                     |              |
  825.                     |  User Stack  |  Preset to 512 bytes
  826.                     | String heap  |
  827. User data---------->|Run-time heap |
  828. End DS:xxxx         |              |  This area contains less
  829.                     |              |     frequently used items, such
  830.                     |   FAR heap   |     as large numeric arrays, the
  831.                     |              |     user environment table, and
  832.                     |              |     error-information tables for
  833.                     |              |     debugging mode.
  834.                     |Communication |
  835.                     |   buffers    |  User specified size
  836.                     |  BRUN40.EXE  |  Separately loaded run-time
  837.                     |              |     code
  838.  
  839.    Figure 1 (above) The BRUN40.EXE Run-Time Module Environment
  840.  
  841. The following figure shows the run-time memory map when the run-time
  842. library BCOM40.LIB is used: 
  843.  
  844. 0000:0000----------> ______________
  845.                     |    MS-DOS    |  MS-DOS Operating System
  846.                     |              |
  847. Low Memory--------->|   User Code  |  User codelinked
  848.                     |              |     with BCOM40.LIB
  849.                     |Run-time code |  Run-time code linked into
  850.                     |              |     file
  851.                     |    Library   |  .LIB Library code linked
  852.                     |    file      |     into file
  853. User data---------->|              |
  854. Start DS:0          |    _DATA     |  QuickBASIC run-time data
  855.                     |    CONST     |     areas, used during user
  856.                     |    _BSS      |     code execution
  857.                     |              |
  858.                     |    Library   |  library data loaded during
  859.                     |    data      |     startup (optional)
  860.                     |              |
  861.                     | Blank COMMON |  library and user
  862.                     |              |     definitions
  863. Up to               |   BC_CONST   |
  864. 64k bytes           |              |  User program constants
  865.                     |   BC_DATA    |
  866.                     |              |  User program variables
  867.                     |    Named     |
  868.                     |    COMMON    |  Named COMMON areas
  869.                     |              |
  870.                     |  User Stack  |  Preset to 512 bytes
  871.                     | String heap  |
  872. User data---------->|Run-time heap |  File buffers,dynamic arrays, etc
  873. End DS:xxxx         |              |  This area contains less
  874.                     |              |     frequently used items, such
  875.                     |   FAR heap   |     as large numeric arrays, the
  876.                     |              |     user environment table, and
  877.                     |              |     error-information tables for
  878.                     |              |     debugging mode.
  879.                     |Communication |
  880.                     |   buffers    |  User specified size
  881.  
  882.    Figure 2 (above) The BCOM40.LIB Run-Time Library Environment
  883.  
  884. The following figure shows the run-time memory map when the QuickBASIC
  885. program is executed within the QuickBASIC Version 4.00 environment: 
  886.  
  887. 0000:0000----------> ______________
  888.                     |    MS-DOS    |  MS-DOS Operating System
  889.                     |              |
  890. Low Memory--------->|  QuickBASIC  |  QB.EXE
  891.                     |    Code      |
  892.                     |              |
  893. User data---------->|  QB static   |
  894. Start DS:0          |    data      |
  895.                     |              |
  896.                     |  Quick Lib   |
  897.                     |    data      |
  898.                     |              |
  899.                     |  User Stack  |
  900.                     | User Program |
  901.                     |    data      |
  902.                     |              |
  903.                     | String heap  |
  904. User data---------->|Run-time heap |  File buffers,dynamic arrays, etc
  905. End DS:xxxx         |              |
  906.                     |              |  This area contains items, such
  907.                     |   FAR heap   |     as large/huge arrays and user
  908.                     |              |     code
  909.                     |              |
  910.                     |              |
  911.                     |Communication |
  912.                     |   buffers    |  User specified size
  913.                     |    Quick     |
  914.                     |   Library    |
  915.  
  916.    Figure 3 (above) The Memory Map for the QuickBASIC Version 4.00
  917.                         Environment 
  918.  
  919. Documentation Errata for the LOF Function
  920.  
  921. Changes for Programming in BASIC: Selected Topics
  922.  
  923. 141   In the "Information Returned" column for the LOF function,
  924.       the description should read: "The amount of space remaining
  925.       (in bytes) in the output buffer." (Note: this is a change
  926.       from the behavior of LOF in previous versions of QuickBASIC).
  927.  
  928. END OF ARTICLE.
  929.