home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / db3tips2.zip / DB3MISC.TXT < prev    next >
Text File  |  1986-07-01  |  8KB  |  205 lines

  1.                         dBASE Speed Tips
  2.        (PC Magazine Vol 5 No 1 January 14,1986 Power User)
  3.  
  4.      These tips help shave off every possible microsecond from you
  5. dBASE command files.  While some of the more general suggestions may
  6. contradict everything you've ever learned about writing dBASE programs,
  7. they cut the execution time for your programs to the bare minimum.
  8. Code-optimizing measures like these should not be used if program
  9. readibility is important.  Your applications should be thoroughly
  10. debugged and tested before you implement the following procedures.
  11. With complicated programs, however, the cumulative effect these steps
  12. can have on the speed of operation is impressive.
  13.      1. Left justify everything: No indentations for IFs, DO CASESs
  14. or DO WHILEs.
  15.      2. All field, variable and filenames should use as few letters
  16. as possible.
  17.      3. Locate those field used in indexing, sorts or LOCATES at the
  18. top of your data files' structures.
  19.      4. Eliminate all comment lines (any line beginning with *).
  20.      5. Use commands such as SET TALK OFF and SET CONSOLE OFF when
  21. you don't need messages, preventing unnecessary use of the processor.
  22.      6. Trim line lengths by eliminating spaces wherever dBASE allows,
  23. e.g., turn  DO WHILE K = 5 .AND. I = "MOM"  into  DO WHILE K=5.AND.I=
  24. "MOM".
  25.      7. Delete redundant statements such as a GO TOP after a USE
  26. <filename> command, a CLEAR GETS after ERASE, or LOOP as the last line
  27. of a DO WHILE routine.
  28.      8. Use capital letters as much as possible.  Lowercase letters
  29. take a little longer to identify.
  30.      9. Take advantage of the fact that dBASE only reads the first
  31. four letters of a command.  Never use APPEND where APPE will suffice.
  32.  
  33. -----------------------------------------------------------------
  34.                   A Pseudocompiler for dBASE II
  35.         (PC Magazine Vol 5 No 5 Mar 11, 1986 Power User)
  36.  
  37.      Too often, dBASE II command file writers are disappointed with
  38. the speed at which their lengthy programs run, especially with large
  39. data files.  Many times, this degradation in speed occurs because of
  40. the way in which the application was programmed, not because of an
  41. increase in the number of records in the files.
  42.      One good way to improve the speed at which a program executes is
  43. to limit the number of STORE and REPLACE commands used.  dBASE must
  44. access your disk every time it encounters one of these commands.
  45. Therefore, changing your code from:
  46.  
  47. STORE ' ' TO m:one
  48. STORE ' ' TO m:two
  49. STORE " " TO m:three
  50. REPLACE one WITH m:one
  51. REPLACE two WITH m:two
  52. REPLACE three WITH m:three
  53.  
  54. to read:
  55.  
  56. STORE ' ' TO m:one,m:two,m:three
  57. REPLACE one WITH m:one,two WITH m:two,three WITH m:three
  58.  
  59. instead, will dramatically limit the number of disk accesses, speeding
  60. things up considerably.
  61.      Because of dBASE's interpretive nature, such things as blank
  62. lines, comments (lines starting with *), and the indenting of program
  63. lines also slow a command file's execution times.  However, eliminating
  64. all these items from your program may be more trouble than it's worth
  65. if you must later rewrite or debug your program.
  66.      The "pseudocompiler" below, while not even close to a true
  67. compiler, will take your program and strip all blank and comment lines
  68. from it while left-justifying all code.  It produces a second version
  69. of your code with a C on the end of the original name, which you can
  70. use in place or your original.  Your original program is left intact
  71. for documentation, debugging, and other purposes.
  72.      Editor's Note:  This routine automatically adjusts your existing
  73. command files to take advantage of many of these tricks while leaving
  74. your original programs untouched.  COMPILE.PRG is shown with indenta-
  75. tions, comment lines, etc. but you might want to run its code through
  76. itself to make it run faster.  Be sure you have a data file called
  77. COMPILE.DBF (consisting of one character field 254 bytes in length)
  78. on your disk before running COMPILE.PRG.
  79.      One word of caution: COMPILE.PRG strips away semicolons at the
  80. end of each line of code that is continued on the next line. Therefore,
  81. you should go through the "compiled" version of your code and replace
  82. the missing semicolon on any partial lines remaining in the program.
  83.  
  84. * COMPILE.PRG
  85. * Requires COMPILE.DBF file that has one field called LINE which is
  86. * defined as character and is 254 characters in length.
  87. CLEAR
  88. SET COLON OFF
  89. SET TALK OFF
  90. SET ECHO OFF
  91. SET BELL OFF
  92. USE COMPILE
  93. COPY STRU TO TEMP
  94. USE TEMP
  95. ERASE
  96. STORE '        ' TO PROGNAME
  97. @ 10,20 SAY 'ENTER THE NAME OF THE PROGRAM TO BE COMPILED'
  98. @ 11,30 GET PROGNAME PICTURE '!!!!!!!!'
  99. @ 11,38 SAY '.PRG'
  100. READ
  101. STORE TRIM($(PROGNAME,1,7))+'C.PRG' TO M:PROG
  102. STORE TRIM(PROGNAME)+'.PRG' TO PROGNAME
  103. APPEND FROM &PROGNAME SDF
  104. GO TOP
  105. SET ALTERNATE TO &M:PROG
  106. SET ALTERNATE ON
  107. DO WHILE .NOT. EOF
  108.   STORE 1 TO CNT
  109.   DO WHILE ($(LINE,CHT,1)=' ' .AND. CNT<50) .OR. $(LINE,CNT,1) = CHR(9)
  110.     STORE CNT+1 TO CNT
  111.   ENDDO
  112.   IF $(LINE,CNT,1) = '*' .OR. $(LINE,CNT,1) = ' '
  113.     DELETE
  114.   ELSE
  115.     STORE TRIM($(LINE,CNT,254-CNT)) TO M:LINE
  116.     ? M:LINE
  117.   ENDIF
  118.   SKIP
  119. ENDDO
  120. SET ALTERNATE OFF
  121. USE
  122. DELETE FILE TEMP
  123. QUIT
  124.  
  125. -----------------------------------------------------------------
  126.                  More on dBASE III Function Keys
  127.              (PC World February 1986 Star-Dot-Star)
  128.  
  129.      Another tip on setting dBASE III function keys ...  This technique
  130. does not require changing the key definitions.  When the WAIT TO
  131. statement is active, the function keys will return ASCII values 246
  132. through 255.  The program DKEYDEMO.PRG below demonstrates how those
  133. key codes can be handled by a dBASE III application.  The demonstration
  134. merely displays the name of the function key you press.  An actual
  135. application would most likely execute a DO statement instead.
  136.      A second unrelated technique involves eliminating the CASE
  137. statement entirely; instead, use the SET FUNCTION statement to define
  138. each key with "DO program-name;" (the semicolon will appear as the
  139. <Enter> key when the statement executes).  Your menu progran can ACCEPT
  140. the user's response to a variable, then execute that variable using the
  141. dBASE III &variablename macro feature.
  142.  
  143. DKEYDEMO.PRG:
  144.  
  145. * This menu uses function keys without chaning their definitions.
  146. * When the WAIT TO statement is active the function keys return
  147. * ASCII values from 246 to 255.  Since 255 is a null character it
  148. * must be handled differently than the others, as shown by the
  149. * last item in the CASE statement below.
  150.  
  151. DO WHILE 1=1
  152.   CLEAR
  153. * (Use @SAY statements to display a menu more quickly)
  154.   TEXT
  155.                    ***** SAMPLE MENU *****
  156.  
  157.                      [F1]       Whatever
  158.  
  159.                      [F2]       etc.
  160.   ENDTEXT
  161.   WAIT '          Press a Function Key:   ' TO action
  162.   DO CASE
  163.     CASE ASC(action) = 254
  164.       ? "F2"
  165.     CASE ASC(action) = 253
  166.       ? "F3"
  167.     CASE ASC(action) = 252
  168.       ? "F4"
  169.     CASE ASC(action) = 251
  170.       ? "F5"
  171.     CASE ASC(action) = 250
  172.       ? "F6"
  173.     CASE ASC(action) = 249
  174.       ? "F7"
  175.     CASE ASC(action) = 248
  176.       ? "F8"
  177.     CASE ASC(action) = 247
  178.       ? "F9"
  179.     CASE ASC(action) = 246
  180.       ? "F10"
  181.     CASE action = ''
  182.       ? "F1"
  183.   ENDCASE
  184.   WAIT
  185. ENDDO
  186.  
  187. -----------------------------------------------------------------
  188.                           dBASE Defect
  189.                (PC World April 1986 Star-Dot-Star)
  190.  
  191.      dBASE III v1.1 has a problem that could result in the loss of
  192. significant amounts of data.  When the SET CARRY ON condition is in
  193. effect and records are APPENDed to the end of a file, the image of the
  194. last record is copied into the appended record.  If, however, the last
  195. record has its delete flag set on, the delete flag on the appended
  196. records will be set on as well.  When the data base is PACKed, all the
  197. new records will be removed from the file because they are flagged for
  198. deletion.  The problem also exists when you use the INSERT command but
  199. does not occur when you issue the APPEND FROM filename command.
  200.      Ashton-Tate advises that you use the SET CARRY ON and APPEND
  201. commands with caution to avert potential data loss.  One solution is
  202. to always issue the SET DELETE OFF command prior to writing new
  203. records to disk.
  204.  
  205.