home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug001.arc / PART8.IQS / PART8.INS
Text File  |  1979-12-31  |  9KB  |  247 lines

  1. .po0
  2.                               dBAS┼  I╔  PAR╘ 8
  3. MACROS
  4.  
  5.           DBAS┼ II'≤ macr∩ facilit∙ i≤ onσ oµ thσ mos⌠ powerfu∞ facilitie≤ oµ ì
  6. thσ language« It'≤ s∩ powerfu∞ it'≤ dangerous¼ anΣ iµ i⌠ wasn'⌠ fo≥ thσ fac⌠ ì
  7. tha⌠ somσ thing≤ woulΣ bσ impossiblσ withou⌠ i⌠ ¿ anΣ eveε morσ thing≤ s∩ mucΦ ì
  8. easie≥ )¼ ╔ woulΣ wan⌠ t∩ seσ i⌠ takeε out.
  9.  
  10.           Beforσ ╔ explaiε why¼ we'Σ bette≥ examinσ ho≈ i⌠ works« looδ a⌠ thi≤ ì
  11. shor⌠ commanΣ filσ :
  12.  
  13. ERAS┼     
  14. └ 12,3░ SA┘ 'Filσ t∩ useº ACCEPT
  15. T╧ filename
  16. US┼ &filename
  17. RETURN
  18.  
  19.           It'≤ fairl∙ obviou≤ what'≤ happeninτ here« Thσ prograφ ask≤ fo≥ ß ì
  20. filenamσ anΣ store≤ i⌠ iε ß memor∙ variablσ calleΣ 'filename'« Thσ nex⌠ linσ ì
  21. i≤ ß standarΣ US┼ command¼ excep⌠ tha⌠ thσ variablσ filenamσ crop≤ up¼ ì
  22. precedeΣ b∙ aε ampersanΣ (&).
  23.  
  24.           Wheneve≥ dBasσ come≤ acros≤ aε &¼ i⌠ replace≤ thσ variablσ namσ tha⌠ ì
  25. follow≤ witΦ thσ valuσ oµ thσ variable« Thi≤ i≤ purel∙ ß textua∞ substitution╗ ì
  26. thereforσ thσ variablσ mus⌠ bσ oµ strinτ type¼ anΣ thσ resul⌠ wil∞ bσ ì
  27. evaluateΣ purel∙ a≤ ß string.
  28.  
  29.           Thi≤ caε leaΣ t∩ somσ confusion«   Fo≥ examplσ :
  30.  
  31. STOR┼ '3º T╧ var1
  32. STOR┼ '4º T╧ var2
  33. ┐ &var▒ ½ ª var2
  34. 7
  35. ┐ ª var1&var2
  36. 34
  37. ?'&var1º ½ '&var2º 34
  38.  
  39.           A≤ ß result¼ codσ tha⌠ make≤ extensivσ usσ oµ macro≤ caε bσ ver∙ ì
  40. confusinτ indeed« However¼ i⌠ i≤ possiblσ t∩ d∩ thing≤ tha⌠ woulΣ otherwisσ bσ ì
  41. impossible¼ sucΦ a≤ writinτ self-modifyinτ code¼ o≥ abbreviateΣ men⌡ routine≤ ì
  42. ║ WAI╘ fo≥ ß men⌡ selectioε anΣ theε D╧ &choice« Herσ i≤ aε examplσ oµ ß ì
  43. simplσ men⌡ prograφ usinτ ß macr∩ :
  44.  
  45.  MACMENU.CM─    b∙ ╠ ╟ BELL
  46.  
  47.  Illustrate≤ usσ oµ macro≤ fo≥ men⌡ operation
  48.  
  49. ERASE
  50. D╧ WHIL┼ T
  51.  └ 5,1▓ SA┘ 'AdΣ Names'
  52.  └ 6,1▓ SA┘ 'Deletσ Names'
  53.  └ 7,1▓ SA┘ 'Quit'
  54.  └ 21,1▓ SA┘ 'Choice'
  55.  SE╘ CONSOL┼ OFF
  56.  WAI╘ T╧ Choice                              cont....è SE╘ CONSOL┼ ON
  57.  STOR┼ !(choice⌐ T╧ choice
  58.  I╞ @(choice,'ADQ'⌐ ╜ 0
  59.     ┐ chr(7)
  60.  ELSE
  61.    D╧ SUB&choice
  62.  ENDIF
  63. ENDDO
  64. RETURN
  65. MOR┼ USE╙ FO╥ MACROS.
  66.  
  67.           Othe≥ use≤ fo≥ macro≤ includσ cramminτ a≤ mucΦ a≤ possiblσ int∩ ì
  68. dBasσ line≤ b∙ replacinτ comple° function≤ witΦ macro≤ :
  69.  
  70. STOR┼ 'STOR┼ $(disdate,7,2)+$(disdate,4,2)+$(disdate,1,2⌐ T╧ mdate'
  71. T╧ makedate
  72.  .
  73.  .
  74. othe≥ code
  75.  .
  76.  .
  77. &makedate
  78.  
  79.           However¼ thσ primar∙ applicatioε fo≥ thσ macr∩ functioε i≤ thσ US┼ ì
  80. anΣ FIN─ statements« Fo≥ example¼ thσ codσ segmen⌠ :
  81.  
  82. STOR┼ 'Smithº T╧ name
  83. FIN─ name
  84.  
  85. wil∞ no⌠ work¼ sincσ dBasσ wil∞ literall∙ searcΦ fo≥ 'Mr« name'« Instead¼ usσ ì
  86. thi≤ techniquσ :
  87.  
  88. STOR┼ 'Smithº T╧ name
  89. FIN─ &name
  90.  
  91.               ┴ simila≥ techniquσ i≤ useΣ witΦ thσ US┼ statement.
  92.  
  93. GUIDELINES
  94.  
  95.           Macro≤ arσ invaluable╗ a≤ wσ havσ seen¼ thσ FIN─ anΣ US┼ command≤ ì
  96. caε hardl∙ bσ useΣ insidσ program≤ withou⌠ them« A⌠ thσ samσ time¼ the∙ makσ ì
  97. debugginτ mucΦ morσ difficult¼ sincσ the∙ literall∙ changσ thσ tex⌠ oµ thσ ì
  98. prograφ scorcσ codσ itself« Fo≥ tha⌠ reasoε alone¼ ╔ aφ no⌠ suggestinτ somσ oµ ì
  99. thσ morσ arcanσ use≤ oµ macros« Iµ yo⌡ arσ sufficientl∙ perverse¼ yo⌡ wil∞ n∩ ì
  100. doub⌠ bσ ablσ t∩ comσ u≡ witΦ delightfu∞ minΣ boggler≤ oµ you≥ own« Iε thσ ì
  101. interes⌠ oµ retaininτ you≥ sanity¼ therσ arσ ß fe≈ guideline≤ yo⌡ shoulΣ bea≥ ì
  102. iε minΣ wheε usinτ macros.
  103.  
  104.           Firs⌠ oµ all¼ conside≥ thσ operatioε oµ dbasσ itself« Executioε oµ ì
  105. prograφ statement≤ i≤ ß tw∩ o≥ morσ ste≡ process« Firs⌠ oµ all¼ thσ macr∩ pre-ì
  106. processo≥ scan≤ acros≤ thσ linσ lookinτ fo≥ ampersands« Iµ i⌠ find≤ one¼ i⌠ ì
  107. theε extract≤ thσ followinτ variablσ anΣ replace≤ thσ ampersanΣ anΣ variablσ ì
  108. namσ witΦ thσ content≤ oµ thσ variable« Iµ i⌠ find≤ ß seconΣ ampersanΣ beforσ ì
  109. thσ variablσ name¼ i⌠ wil∞ evaluatσ tha⌠ macr∩ first¼ anΣ theε returε t∩ ì
  110. perforφ ß seconΣ pass« Fo≥ thσ technicall∙ minded¼ thσ macr∩ pre-processo≥ ìèappear≤ t∩ bσ recursive« Iε othe≥ words¼ i⌠ keep≤ re-scanninτ thσ linσ unti∞ ì
  111. i⌠ ha≤ removeΣ thσ ampersands« Finally¼ afte≥ al∞ ampersand≤ havσ beeε ì
  112. removed¼ thσ resultinτ linσ i≤ actuall∙ executeΣ b∙ dBasσ interpreter.
  113.  
  114.  
  115.      RUL┼ ON┼ ║ thσ resultinτ tex⌠ linσ mus⌠ stil∞ bσ standarΣ ASCI╔ text¼ ì
  116. thereforσ AN┘ VARIABLE╙ USE─ FO╥ MACR╧ SUBSTITUTIO╬ MUS╘ B┼ O╞ TYP┼ CHARACTER« ì
  117. Iµ yo⌡ wan⌠ t∩ inser⌠ ß number¼ presentl∙ storeΣ iε ß variable¼ int∩ ß commanΣ ì
  118. line¼ yo⌡ mus⌠ firs⌠ conver⌠ i⌠ int∩ ß characte≥ variablσ usinτ thσ ST╥ ì
  119. function« Failurσ t∩ d∩ this¼ o≥ an∙ attempt≤ t∩ usσ numeriπ variable≤ iε ì
  120. macr∩ substitution¼ wil∞ crasΦ earlie≥ version≤ oµ dBasσ o≥ resul⌠ iε aε erro≥ ì
  121. messagσ iε V2.4.
  122.  
  123.  
  124.      RUL┼ TW╧ ║ TH┼ RESULTIN╟ TEX╘ LIN┼ MUS╘ STIL╠ OBE┘ TH┼ RULE╙ O╞ TH┼ ì
  125. LANGUAGE« Fo≥ example¼ yo⌡ canno⌠ usσ macr∩ substitutioε t∩ producσ variablσ ì
  126. name≤ longe≥ thaε teε characters« Iµ iε doubt¼ tes⌠ i⌠ oε pape≥ first║ d∩ thσ ì
  127. macr∩ substitutioε anΣ seσ iµ thσ resultinτ statemen⌠ i≤ lega∞ dBasσ code.
  128.  
  129.  
  130.      RUL┼ THRE┼ ║ YO╒ CANNO╘ US┼ DATABAS┼ FIELD╙ FO╥ MACR╧ SUBSTITUTION« The∙ ì
  131. arσ differen⌠ animal≤ froφ memor∙ variables¼ remember.
  132.  
  133.  
  134.      RUL┼ FOU╥ ║ MACR╧ SUBSTITUTIO╬ TAKE╙ PLAC┼ ANYWHER┼ I╬ ┴ dBAS┼ PROGRAM¼ ì
  135. includinτ insidσ quoteΣ tex⌠ o≥ strinτ constants« E.╟ :
  136.  
  137.   
  138. STOR┼ 'Surnameº T╧ indname
  139. ┐ 'Thσ curren⌠ inde° i≤ &indname'
  140.   
  141.            wil∞ work« Thi≤ i≤ sometime≤ ß usefu∞ side-effect¼ bu⌠ usuall∙ ì
  142. therσ i≤ ß morσ conventiona∞ anΣ understandablσ wa∙ t∩ ge⌠ thσ samσ result« ì
  143. Fo≥ examplσ ║ 
  144.  
  145. STOR┼ 'surnameº T╧ indname
  146. ┐ 'Thσ curren⌠ inde° i≤ º ½ indname
  147.  
  148.                     wil∞ als∩ work¼ anΣ i≤ morσ understandablσ t∩ programmer≤  ì
  149. familia≥ witΦ BASI├ bu⌠ no⌠ dBase« It'≤ probabl∙ faste≥ a≤ well.
  150.  
  151.  
  152.      RUL┼  FIV┼ ║ MACR╧ SUBSTITUTIO╬ TAKE╙ PLAC┼ U╨ T╧ ANOTHE╥ AMPERSAND¼ ┴ ì
  153. SPACE¼ ┴ LIN┼ END¼ O╥ A╬ OPERATOR« Thi≤ caε bσ useΣ t∩ forφ filename≤ ou⌠ oµ ì
  154. tw∩ concentrateΣ parts« Thesσ simplσ guideline≤ wil∞ hel≡ t∩ kee≡ yo⌡ straigh⌠ ì
  155. iε usinτ macros« Anothe≥ probleφ t∩ watcΦ ou⌠ fo≥ i≤ thσ mysteriou≤ erro≥ o≥ ì
  156. correctioε message« Fo≥ examplσ iε you≥ code¼ yo⌡ migh⌠ havσ somethinτ likσ :
  157.  
  158.   
  159. STOR┼ '1º T╧ fred
  160. STOR┼ 'fredº T╧ varname
  161.  .
  162.  .
  163. STOR┼ &varnamσ ½ ▒ T╧ &varname
  164. è             Wheε thi≤ runs¼ you'l∞ ge⌠ aε erro≥ message¼ sincσ variablσ ì
  165. 'frtdº contain≤ '1'¼ anΣ yo⌡ can'⌠ incremen⌠ ß string« However¼ thσ 'correc⌠ ì
  166. anΣ retry?º strinτ wil∞ bσ 
  167.  
  168. STOR┼ freΣ ½ ▒ T╧ fred
  169.  
  170.  
  171.          Don'⌠ g∩ lookinτ througΦ you≥ codσ fo≥ tha⌠ line¼ a≤ i⌠ doesn'⌠ ì
  172. exist╗ it'≤ thσ resul⌠ oµ thσ macr∩ substitutioε tha⌠ thσ interprete≥ i≤ ì
  173. tellinτ yo⌡ i≤ wrong« Thi≤ kinΣ oµ thinτ caε makσ debugginτ you≥ prograφ ß ì
  174. nightmare.
  175.  
  176. DBAS┼ FUNCTION╙ :
  177.  
  178.      DBasσ ha≤ ß selectioε oµ function≤ whicΦ returε value≤ afte≥ performinτ ì
  179. somσ operation« 
  180.  
  181.  ú - recorΣ numbe≥ functioε - thi≤ return≤ thσ numbe≥ oµ thσ curren⌠ recorΣ a⌠ ì
  182. whicΦ thσ databasσ i≤ positioned« Afte≥ aε unsuccessfu∞ finΣ thi≤ i≤ zer∩ ¿ ì
  183. witΦ SE╘ TAL╦ OFF¼ thi≤ i≤ thσ onl∙ wa∙ you'l∞ kno≈ tha⌠ n∩ matcΦ wa≤ found)«  
  184.  
  185.  
  186.   - deleteΣ recorΣ functioε - return≤ truσ o≥ false¼ dependinτ oε weathe≥ thσ ì
  187. recorΣ ha≤ beeε deleteΣ o≥ not« Remembe≥ tha⌠ eacΦ recorΣ iε ß .DB╞ ha≤ ß ì
  188. singlσ bytσ a⌠ thσ beginninτ whicΦ contain≤ aε asterisδ iµ tha⌠ recorΣ ha≤ ì
  189. beeε deleted.
  190.  
  191.  
  192.  EO╞ - enΣ oµ filσ - return≤ truσ iµ yo⌡ tr∙ t∩ reaΣ beyonΣ thσ enΣ oµ ß file« ì
  193. UseΣ t∩ contro∞ D╧ WIL┼ loops.
  194.  
  195.  
  196.  !(⌐ - uppe≥ casσ conversioε functioε - convert≤ thσ variablσ o≥ strinτ ì
  197. litera∞ iε thσ bracket≤ t∩ uppe≥ case« Thu≤ !('hell∩ world!'⌐ i≤ HELL╧ WORLD!.
  198.  
  199.  
  200.  TYP┼ (⌐ - return≤ thσ typσ oµ variablσ o≥ expressioε iε thσ parentheses« ì
  201. Eithe≥ C¼ N¼ ╠ o≥ ╒ wil∞ bσ returned¼ indicatinτ ß character¼ numeric¼ logica∞ ì
  202. o≥ undefined.
  203.  
  204.  
  205.  IN╘ (⌐ - strinτ o≥ intege≥ conversioε - noticσ tha⌠ i⌠ onl∙ return≤ aε ì
  206. intege≥ value¼ witΦ n∩ fractiona∞ part« 
  207.  
  208.  
  209.  STR(n,l,p⌐ - numeriπ t∩ strinτ conversioε - convert≤ numeriπ variablσ ε t∩ ß ì
  210. strinτ oµ lengtΦ l¼ witΦ (optionally⌐ ≡ place≤ afte≥ thσ decima∞ point.
  211.  
  212.  LE╬ (⌐ - strinτ length
  213.  $(s,p,l⌐ - substrinτ extractioε - extract≤ ∞ character≤ froφ strinτ ≤ ì
  214. startinτ a⌠ positioε p« eg║ $('ABCDEFG',4,2⌐ i≤ "DE".
  215.  
  216.  @(s1,s2⌐ - strinτ searcΦ - return≤ thσ positioε oµ thσ strinτ s▒ iε strinτ ì
  217. s2« Thu≤ @('CD','ABCDE'⌐ i≤ 3.
  218.  CH╥ (⌐ - ASCI╔ character« Thi≤ work≤ jus⌠ likσ CHRñ iε BASIC« Thu≤ CHR(65⌐ i≤ ìè"A"¼ whilσ CHR(27⌐ i≤ thσ escapσ character.
  219.  
  220.  RAN╦ (⌐ - decima∞ valuσ oµ character« Thi≤ i≤ thσ reversσ oµ CHR¼ sincσ i⌠ ì
  221. return≤ thσ positioε oµ thσ characte≥ iε thσ ASCI╔ sequence« Thu≤ RANK('C'⌐ i≤ ì
  222. 67.
  223.  
  224.  FIL┼ (⌐ - doe≤ filσ exist┐  WARNING!!í    D╧ NO╘ US┼ whilσ an∙ databasσ ì
  225. (.DBF⌐ filσ i≤ open¼ a≤ dBasσ wil∞ erasσ ß numbe≥ oµ file≤ froφ you≥ disk╗ ì
  226. usuall∙ thσ databasσ filσ anΣ an∙ associateΣ indexes¼ bu⌠ ofteε ß numbe≥ oµ ì
  227. other≤ fo≥ gooΣ measure«  Iµ yo⌡ stil∞ fee∞ safσ usinτ thi≤ function¼ i⌠ ì
  228. return≤ .T« o≥ .F.╗   fo≥ examplσ :
  229.  
  230.  
  231. I╞ FILE('BKINV.DBF')
  232.    US┼ BKINV
  233. ENDIF
  234.  
  235.  
  236.  TRI═ (⌐ - eliminate≤ trailinτ blank≤ - becausσ dBasσ field≤ arσ oµ fixeΣ ì
  237. length¼ the∙ wil∞ ofteε havσ extrß paddinτ space≤ oε thσ enΣ oµ thσ contents« 
  238. TRI═ get≤ riΣ oµ thesσ blanks╗   fo≥ examplσ :
  239.  
  240. ┐ TRIM(town))+º '½ TRIM(state)+º º postcode
  241.  
  242.  NEX╘ PAR╘ INCLUDE╙   @...SAY...GE╘   statement≤ anΣ forma⌠ files.
  243.  
  244.  
  245.   
  246.                              EN─   O╞   PAR╘   8    
  247.