home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / DATABASE / SCRIVNER.LBR / SCRIV.DZC / SCRIV.DOC
Text File  |  2000-06-30  |  112KB  |  2,846 lines

  1.  
  2.  
  3. Both program and documentation Copyright (C) MML Systems Ltd 
  4.  
  5. 11 Sun Street,
  6. Finsbury Sq,
  7. London EC2M2QD
  8. 01 247 0691
  9.  
  10. Pentlow Mill
  11. Cavendish
  12. Suffolk.
  13. 0787 281072
  14.  
  15.  
  16. This software is supplied on the express understanding that the liability of 
  17. the authors and vendors is strictly limited to the cost of replacement. Under 
  18. no circumstances does this include any consequential liability of any sort 
  19. whatsoever.
  20.     
  21. This version of the program and documentation is in the public domain. Under 
  22. no circumstances may it be sold for profit. Copyright is retained by MML:
  23.  
  24. You are welcome to copy it and give it to your friends. You are not, however, 
  25. allowed to sell it.
  26.  
  27.  
  28.  
  29. 0.1 Preface
  30.  
  31.      Scrivener was developed as an exercise in creative programming, a 
  32. training experience for a novice programmer at MML, and as a rest from 
  33. writing a particularly long and tedious program for another company. We did, 
  34. however, seek to cover our expenses with it. To start with, we were asked by 
  35. Amstrad to come up with a program that would do calculations on ordinary 
  36. text files. Neither Locoscript nor NewWord 2 can do calculations, and so it 
  37. seemed a good idea to write a utility to do so. We discussed the various 
  38. ways that the program might work, and discovered why it was that no one had 
  39. previously thought of such a simple program. Essentially, we thought, it 
  40. would be an easy and quick program to write; if something needed to be 
  41. calculated, the program would substitute the answer for the expression. How, 
  42. then does one tell the program what needs to be calculated? one might, 
  43. perfectly reasonably, want expressions in the text that should be left as 
  44. they are, so one cannot assume that every number or formula should be 
  45. evaluated. We decided that the user should delimit, by double square 
  46. brackets, the expressions that they wanted calculated. We chose double 
  47. square brackets simply because they do not normally occur in text. If, for 
  48. example, one had the line:-
  49.  
  50. the answer to the expression (3+7+8)/6 is [[(3+7+8)/6 ]]
  51.  
  52. the first expression, (3+7+8)/6, would be ignored, but the second one, 
  53. between the angle brackets, would be changed into the answer. simple.
  54.  
  55.      There is, however, a real world out there. When we asked real people 
  56. whether this was what they really wanted, they said no. It was all right up 
  57. to a point, but then, what about being able to put text into a file too?; 
  58. what about being able to type in prices as one goes along?; what about 
  59. having variables?; what about being able to line up the decimal points? how 
  60. could one add up columns, and calculate averages? should'nt one be able to 
  61. specify the precision of the answer? We decided to go back to scratch and 
  62. find some real end users who would need this program. "Oh yes," they would 
  63. all say with innocent looks, "our requirements are very simple." The more 
  64. one looked, the more complex they became until the idea of a simple little 
  65. utility started to look rather sick. There was a land drainage company, for 
  66. example, who had to prepare estimates based on the materials needed, the 
  67. plant to be used, and the time the job would take. Each director liked the 
  68. estimate laid out a different way, and the estimate was much greater in 
  69. length for more complex jobs where an entire estate needed to be quoted for. 
  70. Once the estimate was prepared, the result needed to go into a file awaiting 
  71. an invoice. If the job was accepted by the customer, the invoice had to be 
  72. prepared from the estimate and the result entered into the ledgers. It 
  73. seemed like a perfect example of a use for the new package, in that the 
  74. invoice could be prepared with the text editor, calculated up, and then 
  75. given a final knock into shape with the text editor once again. It actually 
  76. stretched the package to its limits and set us thinking that the users 
  77. actually needed something much more powerful. I looked at various small 
  78. businesses, and asked them what they required from their computer. "Yes", 
  79. they said brightly "a nice little program to add up rows and columns; just 
  80. like a spreadsheet, only without having all those cells. What we want is 
  81. something like a spreadsheet which will work on plain text from a 
  82. wordprocessor." Everyone was agreed. they wanted it, and could get nothing 
  83. like it anywhere. They wanted something flexible and adaptable to all sorts 
  84. of paperwork that the myriad small businesses require to prepare. Each small 
  85. business seems to run its business in a unique way, so no program bought 
  86. 'off the shelf' would do. It needed to be something that could be adapted 
  87. for applications about which the creator of the program had never even 
  88. dreamed. It is no use asking an end user to put time and effort into a 
  89. system if it did not answer all his needs. It had to be flexible enough to 
  90. cope. We set to work with the new brief, and found ourselves designing and 
  91. programming a completely new sort of utility. Scrivener is the result.
  92.  
  93.  
  94.      The idea that the computer user has some sort of intelligence is 
  95. somewhat novel. A program such as Scrivener, the result of several months of 
  96. labour, struck all the pundits who saw it as being impossibly complex. The 
  97. software industry originally said the same about DBASEII, possibly the most 
  98. successful program ever written. Everything we put in the language was there 
  99. for a reason, but the result required some initial hard work from the user. 
  100. As far as the microcomputer is concerned, we live in the age of shrink-
  101. wrapped convenience software, where adaptability and flexibility is 
  102. sacrificed for a user-interface that requires little from the user. Our 
  103. program seemed like something from the bad old days of minis and mainframes. 
  104. My own experience is that a small business that is determined to make best 
  105. use of a microcomputer, is prepared to put in a lot of effort if it is 
  106. convinced that the results will be worthwhile. Motivation is everything. 
  107. What is more important than a friendly user-interface is a good manual and 
  108. plenty of examples.
  109.  
  110.      We agree that there is room for improvement in Scrivener. Even though 
  111. we know that we will never profit from it, we are continuing to develop the 
  112. ideas we had for Scrivener as a sort of hobby, and a second version is 
  113. planned, that is more intuitive to use  and has many more features. We have 
  114. MSDOS versions of the program, and have started on a new manual. We keep 
  115. getting ideas, and they give us no peace until we code them up. It is a sort 
  116. of lunacy, but then, that is what hacking is all about.
  117.  
  118.      So what does Scrivener do? We see it as a sort of panacea for small 
  119. businesses, accountants, engineers and scientists. At its simplest, it will 
  120. produce letters, memos and documents; hence its name. It will also do more 
  121. complex calculations that traditionally require a spreadsheet. It will not 
  122. do interactive financial modelling, where one plays about with figures 
  123. onscreen and sees the figures change before ones eyes, but for delivery 
  124. notes, statements, quotations, estimates, acknowlegement slips, form letters 
  125. and so on it is extraordinarily useful. In the documentation that follows, 
  126. we use an invoice from a mythical private school as one of the examples of 
  127. how a Scrivener task is built up. Just as spreadsheets work on models, 
  128. Scrivener works on tasks, the simplest being a text file with a bit of 
  129. adding up to do, and the more complex being such things as analysis of 
  130. variance, corporation tax calculation ,profit and loss accounting, and such 
  131. esoteric stuff. Unlike a spreadsheet, Scrivener task files are just ordinary 
  132. text files, and can be created with a text file. We give away a few example 
  133. tasks, such as a simple cashbook, but these are only to provide insiration 
  134. and examples. It is up to the individual user to make up the task files to 
  135. suit his or her own usage. No two people seem to perform even the simplest 
  136. task such as an invoice in exactly the same way and this is the whole reason 
  137. for Scrivener. Scrivener allows you to do it your way. What you get when 
  138. Scrivener finishes its work is a text file that can be used by your 
  139. favourite text processor such as NewWord to make the final touches to the 
  140. document.
  141.  
  142.      Scrivener tasks are best written in stages. For an accounting function, 
  143. one starts with a layout that can be taken simply from an accountancy 
  144. textbook, using symbols and variables to make things clear. An accounting 
  145. task can be set up to conform closely to the layout with which an accountant 
  146. is familiar. As long as things calculate correctly, one knows that one is on 
  147. the right track. (do not forget the double-square brackets!). Then comes the 
  148. process of refinement. What figures are best entered when the task is 
  149. calculated up? how should the decimal point be aligned? should entries that 
  150. calculate to zero be left as zero or be left as blanks? What text is best 
  151. entered when the task is run? how is it made more flexible? Should entered 
  152. text overwrite or be inserted? One can go on fiddling with tasks until they 
  153. conform exactly to what one wants. Be warned, though, a complex and lengthy 
  154. task takes a long time to process!
  155.  
  156.  
  157.  
  158.  
  159. 1. Introduction.
  160.  
  161. 1.1 What does Scrivener do?
  162.  
  163.      SCRIVENER is an extraordinarily useful program, if you are handling 
  164. text. We are constantly thinking up new uses for the program and use it 
  165. ourselves in-house. Operating Scrivener is easy. Constructing SCRIVENER 
  166. files takes patience and some time, but repays effort. 
  167.  
  168.  
  169.      Scrivener works with a text file. It can do computation and text 
  170. substitution on it and producing more text. It can send the processed text 
  171. to the screen, serial port or printer. Scrivener is designed to deal with 
  172. repetitive clerical work. It is an aid to a text-editing or wordprocessing 
  173. program. Scrivener is a program that is designed to make life easier for 
  174. anyone who has to do calculations, prepare documents or letters, or do a 
  175. repetitive typing or clerical job for which no program exists. It is useful 
  176. to be able to do calculations and totalling on simple text files, rather 
  177. than having to use a special program. Using simple text files means that the 
  178. user can alter the layout and the details before and after processing it. 
  179. Scrivener will also produce tabular information just like a spreadsheet, but 
  180. the spreadsheet size is not limited and the layout is completely under the 
  181. users control. Unlike a spreadsheet, a Scrivener task can be 'run' like a 
  182. program, making it easy for anyone to enter variable data into a spreadsheet 
  183. model, without knowing anything about how to construct a 'task'.
  184.  
  185.      Scrivener is good for form letters, diaries, journals, ledgers, 
  186. cashbooks, statistical computations, reports, form filling, repetitive 
  187. letters, thankyou letters, text conversion work, financial modelling, 
  188. accounting work and so on. We keep hearing of new uses, do do not feel 
  189. restricted by these examples but try out new uses.
  190.  
  191.      Scrivener is not a derivative program. We cannot say that it is a macro 
  192. processor because it does so much more: We cannot say that it is a 
  193. spreadsheet, because it allows requests for data entry and free-form layout 
  194. rather than column and row entry: We wrote Scrivener because we had ideas 
  195. that we wanted to try, and wanted to see where they lead us. It is, perhaps, 
  196. a new way of approaching clerical tasks on a microcomputer. Scrivener should 
  197. be particularly useful for the self-employed or small businesses in order to 
  198. help with the paperwork.
  199.  
  200.  
  201.  
  202. 1.2 Using Scrivener
  203.  
  204. To operate Scrivener takes very little practice. 
  205.  
  206.      You have the choice between two ways of operating Scrivener. 
  207.      Firstly, you can type:-
  208.  
  209. Scrivner input.fil output.fil
  210.  
  211. where input.fil is the text file with the calculation or insertion commands 
  212. already inserted.
  213.  
  214.      If INVOICE is the name of the file that you wish to use, to produce an 
  215. actual invoice called SMITH.LET, then all you need to do is type:-
  216.  
  217. Scrivner INVOICE SMITH.LET
  218.  
  219.      You will probably be prompted for the necessary information to complete 
  220. the invoice.
  221.  
  222.      The second way to use Scrivener is to type
  223.  
  224. Scrivner
  225.  
  226.      and the program will prompt for the names of the files. On the 
  227. distribution disc are a number of sample files to practice with. Once you 
  228. have gained familiarity with using these files, then try experimenting by 
  229. making small changes in the files, or using different output destinations.
  230. If you type CON: as the output file, then the output just goes to the screen 
  231. (useful for trial runs). If you type LST: then the output goes straight to 
  232. the printer.
  233.  
  234.  
  235.      This is the way to use Scrivener simply.
  236.  
  237.  
  238. 1.3 Creating a new Scrivener file
  239.  
  240.  
  241.      To create new 'task' or 'model' files, particularly if they use the 
  242. more sophisticated features of the package, takes more time and practice. If 
  243. you persevere, you will be able to set scrivener up do tasks which can be 
  244. done by no other program. The tasks can then be run by the way we described 
  245. in the previous paragraph. You will need a text processing program such as 
  246. Wordstar, Newword, or Pmate. You can use ED but we do not recommend it. 
  247. Scrivener files are designed using your wordprocessor.
  248.  
  249. For the time being, lets keep our new 'model' simple.
  250.  
  251.      Perhaps you are writing a document on your wordprocessor and find 
  252. yourself typing a column of figures that you need to add-up. I might look 
  253. like this.
  254.  
  255. (but is more likely to have text,  numbers, or expressions around it):-
  256.  
  257. 4454
  258. 4564
  259. 8646      
  260. 5.67
  261. 654.78    
  262. 5.864
  263. 68        
  264. 130.687
  265.  
  266.      In order to tell Scrivener that you want it to work on these particular 
  267. figures and not something else in the text, you must mark the figures you 
  268. want processed. Scrivener uses the 'double-square-brackets' delimeters, 
  269. simply because they do not occur in normal text. (you'll get used to this 
  270. convention!). We want, in this instance, to add-up this column of figures so 
  271. we put a 't' (t for total) under the column with the word (or 'symbol') 
  272. total after it.
  273.  
  274. [[ 4454 ]]
  275. [[ 4564 ]]
  276. [[ 8646 ]]      
  277. [[ 5.67 ]]
  278. [[ 654.78 ]]    
  279. [[ 5.863 ]]
  280. [[ 68 ]]        
  281. [[ 130.687 ]]
  282. ---------
  283. [[t total]]
  284.  
  285. We feed the file through Scrivener with the following result:-
  286.  
  287.  
  288. 4454      
  289. 4564      
  290. 8646            
  291. 5.67      
  292. 654.78          
  293. 5.863      
  294. 68              
  295. 130.687      
  296. ---------
  297. 18529      
  298.  
  299.      If you make a mistake, the program may fuss around for a while, in the 
  300. mistaken impression that you have given it a particularly subtle 
  301. computation, and then will report an error as soon as it is sure that you 
  302. have goofed. Instead of numbers in your columns, it might have been 
  303. 'expressions' such as 78.9867*34.6, sin(576/10.86453), or (7010.207- 
  304. ((167.17^2)/4))/3. Not only can you do this, but you can also use variables 
  305. to make your expressions more meaningful. Giving values to expressions is 
  306. done simply by using the 'equals' sign. eg:- [[vat = 15]]. So far, this is 
  307. not particularly exciting, but the idea can be extended to incorporate most 
  308. of the work done by a spreadsheet, and includes several ideas that are not 
  309. possible on a spreadsheet. Some of the calculation facilities are a joy only 
  310. to a programmer or mathematician, but are nevertheless essential for certain 
  311. applications. Expressions use precedence rules but it is always a good idea 
  312. to use parentheses (brackets) to ensure that Scrivener understands the 
  313. expression exactly the same way that you do. For example, 5 + 3 / 2 could 
  314. result in 4 or 6.5, depending whether 5 is added to 3 and then divided by 2, 
  315. or 3 is divided by 2 and the result added to 5. This ambiguity is easily 
  316. removed by writing (5 + 3) / 2  or 5 + (3 / 2) depending on what you 
  317. intended. We will explain more about calculations later. Rest assured that 
  318. it will do a lot more than the four basic functions!
  319.  
  320.      Note that the total at the bottom of the list of figures is requested 
  321. by a rather terse notation. '[[t total]]'. This is deliberate; it allows the 
  322. commands to be placed in generally the same area as the number or phrase 
  323. that is finally put there. It is much easier to envisage and design the 
  324. final layout if this is the case. You will get used to the terse, 
  325. 'unfriendly' commands.
  326.  
  327.      Essentially Scrivener takes a 'task' file, or model, and produces a new 
  328. text file that can be used just like any other text file. A 'task' or 
  329. 'model' file is simply an ordinary text file as would come from a text 
  330. editor or wordprocessor, that has some commands to Scrivener to do text 
  331. insertions, substitutions or calculations. It will fill in forms, do 
  332. complicated calculations, and add up both columns and rows of figures. Once 
  333. one has constructed a 'task' file, it is simple to use it to generate 
  334. repeated forms, letter or documents is simple. There is nothing magical 
  335. about a 'task' file, it is simply an ordinary text file that has something 
  336. in it that Scrivener can work on. It could be a letter, a chapter of a 
  337. novel, a dumped page from Prestel, an invoice, or some annual results.
  338.  
  339.  
  340.      Scrivener will not only process numbers, it will also process text.
  341.  Lets take an example:-
  342.  
  343.       Imagine that you wish to quickly produce acknowledgement letters to 
  344. enquiries. You already have a scrivener task file looking something like 
  345. this:-
  346.  
  347. #input his name,,What is the enquirer's name?
  348. #input His address1,,And the first line of the address?
  349. #input His address2,,And the second line of the address?
  350. #input His address3,,And the third line of the address?
  351. #input His address4,,And the fourth line of the address?
  352. #input Date,, What is the date, please?
  353.  
  354. His name                                     MML Systems Ltd,
  355. His address1                                 Pentlow Mill
  356. His address2                                 Cavendish
  357. His Address3                                 Suffolk
  358. His Address4                                 Date
  359.  
  360.      Dear His name,
  361.           Thank  you  for your enquiry about our  program  called 
  362. Scrivener.  We  enclose details of the package.  If you have  any 
  363. questions  about the package please do not hesitate to phone  me. 
  364. Should  you  wish to purchase the product we would be pleased  to 
  365. supply  it  for  a licence fee of  #29.95.  ex  VAT.  in  one-off 
  366. quantities.
  367.  
  368.           Yours Faithfully
  369.  
  370.  
  371.                          A. R. M. Clarke.
  372.  
  373.  
  374.      Do not worry for the time being about the strange lines at the top. If 
  375. the scrivener task file reproduced above is called ACK.IT then all that one 
  376. would have to do is to type
  377.  
  378. SCRIVNER ACK.IT LETTER.1
  379.  
  380. to produce a text file with the completed letter on it. Typing
  381.  
  382. SCRIVNER ACK.IT LST:
  383.  
  384. would send the output straight to the printer. 
  385. The user would get the prompt
  386.  
  387. What is the enquirer's name? -->
  388. And the first line of the address? -->
  389. And the second line of the address? -->
  390. And the third line of the address? -->
  391. And the fourth line of the address? -->
  392. what is the date, please? -->
  393.  
  394. When  all these questions have been answered,  the result might look like  the 
  395. following:-
  396.  
  397. Mr Stephen Lee                               MML Systems Ltd,
  398. The Ship Hotel                               Pentlow Mill
  399. Brightlingsea                                Cavendish
  400. Essex                                        Suffolk
  401.                                              23rd Sept 1985
  402.  
  403.      Dear Mr Stephen Lee,
  404.           Thank  you  for your enquiry about our  program  called 
  405. Scrivener.  We  enclose details of the package.  If you have  any 
  406. questions  about the package please do not hesitate to phone  me. 
  407. Should  you  wish to purchase the product we would be pleased  to 
  408. supply  it  for  a licence fee of  #29.95.  ex  VAT.  in  one-off 
  409. quantities.
  410.  
  411.           Yours Faithfully
  412.  
  413.  
  414.                          A. R. M. Clarke.
  415.  
  416.      Notice that all the mysterious stuff at the top of the task file has 
  417. gone, and his name and address has been filled-in. The Task file is a text 
  418. file just like the resulting file. It can be changed at will by anyone, one 
  419. needs no computer knowledge, just the ability to use a text editor. If you 
  420. wish to insert more text for all further letters to this model, change the 
  421. task file to suit, if you wish to make a unique modification to this letter, 
  422. then, edit the result file (letter.1). If you wish to print it out, read it 
  423. into your favourite wordprocessor program and use its specialised features. 
  424.  
  425.  
  426. Making a task file.
  427.  
  428.      At some point, you will want to make a task file. Let us take another 
  429. imaginary example. You are the school secretary for a private school who is 
  430. faced with the daunting task of sending out 200 invoices before the start of 
  431. every new term. They look something like this:-
  432.  
  433.                Dotheboys Hall School Ltd
  434.  
  435.                     Duncayning
  436.  
  437.                     Duncayning 3549
  438.  
  439.                                         Spring Term 1986
  440.  
  441.  
  442. Name:- Arthur Megabyte                       Form 5b
  443.  
  444. --------------------------------------------------------------------------
  445. Fees                                              |180.00
  446. Less 5% for 2nd child                             |  9.00
  447.                                                   |171.00
  448.                                                   |
  449.  Lunches                                          |
  450.                                                   |
  451.  Piano                                            |
  452.  Music Books                                      |
  453.  Speech Training                                  |
  454.  Brass                                            |
  455.  Instrument Hire                                  |
  456.  Milk                                             |  5.50
  457.  Extras                                           |
  458.                                                   |
  459.  Surcharge                                        |
  460.                                                   |-------------------
  461.                                              #    |176.50
  462.  
  463. Cheques should be crossed and made payable to Dotheboys Hall School Ltd
  464.  
  465. FEES ARE PAYABLE STRICTLY IN ADVANCE AND MUST BE RECEIVED BY THE FIRST DAY
  466. OF THE NEW TERM
  467.  
  468. Next Term Begins ..Tuesday 8th Jan
  469.  
  470.  
  471.  
  472.  
  473.      Now the school already has a spreadsheet program on the computer. It is 
  474. of little use for this task because it is impossible to set up the file to 
  475. print the invoices in the exact format of the invoices, and anyway, it is 
  476. complex and slow to use for repetitive jobs. The computer has a good 
  477. wordprocesser, but it will not do the adding up or work out the percentage 
  478. discount. What you want to be able to do is to simply 'feed in' the things 
  479. that change, such as the various charges, the date or the name of the child 
  480. (we call these 'variables').
  481.  
  482.      So the whole process can be done if we set up a 'model' of how the 
  483. thing ought to look, into which we can put all the variables, just as if we 
  484. were filling in a form. We can print it out, adjust the layout, the pitch of 
  485. the printing, and so on until everyone is happy. We will make up labels for 
  486. every part of the form that requires an entry. (where, on a printed form, we 
  487. might put a '.........'). Just to make it a bit clearer, we use the '_' 
  488. character at the start and end of each label, though this not at all 
  489. necessary. It might then look like this. 
  490.  
  491.  
  492.  
  493.  
  494.                Dotheboys Hall School Ltd
  495.  
  496.                     Duncayning
  497.  
  498.                     Duncayning 3549
  499.  
  500.                                         _TERM_ Term _YEAR_
  501.  
  502.  
  503. Name:- _THE BOYS NAME_                       Form _HIS FORM_
  504.  
  505. --------------------------------------------------------------------------
  506. Fees                                              |_THE FEES_
  507. Less _DISCOUNT_% for 2nd child                    |_THE FEES_*(_DISCOUNT_/100)
  508.                                                   |_THE FEES_-Discount
  509.                                                   |
  510.  Lunches                                          |  _LUNCHES_
  511.                                                   |
  512.  Piano                                            |  _PIANO_
  513.  Music Books                                      |  _MUSIC BOOKS_
  514.  Speech Training                                  |  _SPEECH_TRAINING_
  515.  Brass                                            |  _BRASS_
  516.  Instrument Hire                                  |  _INSTRUMENT HIRE_
  517.  Milk                                             |  _MILK_
  518.  Extras                                           |  _EXTRAS_
  519.                                                   |
  520.  Surcharge                                        |  _SURCHARGE_
  521.                                                   |-------------------
  522.                                              #    | _BOTTOM LINE_
  523.  
  524. Cheques should be crossed and made payable to Dotheboys Hall School Ltd
  525.  
  526. FEES ARE PAYABLE STRICTLY IN ADVANCE AND MUST BE RECEIVED BY THE FIRST DAY
  527. OF THE NEW TERM
  528.  
  529. Next Term Begins  _WHEN IT BEGINS_
  530.  
  531.      Now, obviously, the column of figures should line up 'right justified', 
  532. in pounds and pence format. We need _BOTTOM LINE_  to be the sum of the 
  533. column from ' _THE FEES_ - DISCOUNT' to _SURCHARGE_,  and DISCOUNT must be 
  534. the value of the line above.
  535.  
  536.      You will notice that there are some variables that are not much 
  537. altered. The time and date for the beginning of the term is the same for all 
  538. two hundred invoices but is different for each term. We wish to alter it 
  539. occasionally as we use the 'model' invoice. We therefore have one of two 
  540. alternatives. We can simply not have them as variables at all but alter the 
  541. 'model' itself each term, or we can, rather more conveniently, 'define' them 
  542. as having a certain value at the start of the file, and then simply alter 
  543. the start of the 'model' file every term and not have to search through it 
  544. for parts needing alteration.
  545.  
  546.      Let us now 'define' these variables. (we put a '#' sign in front of the 
  547. word 'define', to tell Scrivener that it is a special command and not the 
  548. word 'define' that just so happens to be in the text.)
  549.  
  550.  
  551.  
  552. #define _TERM_,,Autumn 
  553. #define _YEAR_,,1986
  554. #define _WHEN IT BEGINS_,,September 11th 1986.
  555.  
  556.  
  557.      This is asking Scrivener to substitute the phrase 'September 11th 
  558. 1986.' for the phrase '_WHEN IT BEGINS_', 'Autumn ' for _TERM_, and 1986 for 
  559. _YEAR_ 
  560.  
  561.      This way of defining variables is fine for the things which change very 
  562. rarely, say once each term as in the case of the term start date, the year 
  563. and when it begins. It means merely that before each new set of invoices is 
  564. to be sent, you edit these define statements under your word processor and 
  565. on each new invoice sent out, the appropriate changes will have been made 
  566. correctly. It would, however, be inconvenient to have to enter your word 
  567. processor for each invoice. It would be easier if we could make Scrivener 
  568. accept an input from the keyboard for the things which change such as the 
  569. boys name, the form and all the costs.
  570.  
  571.      In order to do this, we use the '#input' statement. At the beginning of 
  572. the file we put a number of these statements and prompts, so that on each 
  573. invoice, the person using Scrivener could type in each variable. The prompts 
  574. are yours to make up, and can be as long as you like. The #input statements 
  575. might look something like.
  576.  
  577. #input _THE BOYS NAME_,,Enter the pupil's name
  578. #input _HIS FORM_,,What form is he in
  579.  
  580.      These two statements will handle the replacement of the boys name and 
  581. his form, so that every time Scrivener came across _THE BOYS NAME_ in the 
  582. text, it would substitute whatever you typed at the keyboard. 
  583.  
  584.      We now need to consider how we are going to get the figures into the 
  585. invoice. Let us forget, for one moment that there are certain important 
  586. calculations to do; let us just concentrate on getting the figures in.
  587.  
  588.      To obtain all the normal costs we would use the '#input' much as we did 
  589. with the name and form. So now we have, at the head of the file, all the 
  590. instructions to Scrivener that are necessary. They might look something like 
  591. this (though if you are ambitious you can make it much more slick!)
  592.  
  593. #define _TERM_,,Autumn 
  594. #define _YEAR_,,1986
  595. #define _WHEN IT BEGINS_,,September 11th 1986.
  596. #input _THE BOYS NAME_,,Enter the pupil's name
  597. #input _HIS FORM_,,What form is he in
  598. #input _THE FEES_,,What fees should be paid
  599. #input _DISCOUNT_,,What discount (if any) for second child 
  600. #input _LUNCHES_,,What are the lunch costs
  601. #input _PIANO_,,Enter his piano costs
  602. #input _MUSIC BOOKS_,,Enter the costs of music books
  603. #input _SPEECH_TRAINING_,,Enter the costs of speech training
  604. #input _BRASS_,,Enter the brass costs
  605. #input _INSTRUMENT HIRE_,,Enter the costs of instrument hire
  606. #input _MILK_,,Enter the costs of milk
  607. #input _EXTRAS_,,Enter the costs of extras
  608. #input _SURCHARGE_,,Enter the surcharge
  609.  
  610.      The next problem to tackle is that we have to convince Scrivener to do 
  611. all the calculations and totalling for us. In order to do this, we must put 
  612. '[[' and ']]' around any calculations, or numbers that are to be used for 
  613. calculations. We do this because we need to tell Scrivener to get to work on 
  614. what is between the delimeters. If Scrivener grasped every expression given 
  615. to it, then we would not be able to put mathematical expressions into any 
  616. text. So the main section  now looks like:-
  617.  
  618.  
  619.                Dotheboys Hall School Ltd
  620.  
  621.                     Duncayning
  622.  
  623.                     Duncayning 3549
  624.  
  625.                                         _TERM_ Term _YEAR_
  626.  
  627.  
  628. Name:- _THE BOYS NAME_                       Form _HIS FORM_
  629.  
  630. --------------------------------------------------------------------------
  631. Fees                                              | [[ _THE FEES_]]
  632. discount for 2nd child                            | [[z -_THE FEES_*(_DISCOUNT_/100)]]
  633.                                                   | [[t ftotal]]
  634.                                                   |
  635.  Lunches                                          | [[ _LUNCHES_]]
  636.                                                   |
  637.  Piano                                            | [[ _PIANO_]]
  638.  Music Books                                      | [[ _MUSIC BOOKS_]]
  639.  Speech Training                                  | [[ _SPEECH_TRAINING_]]
  640.  Brass                                            | [[ _BRASS_]]
  641.  Instrument Hire                                  | [[ _INSTRUMENT HIRE_]]
  642.  Milk                                             | [[ _MILK_]]
  643.  Extras                                           | [[ _EXTRAS_]]
  644.                                                   |
  645.  Surcharge                                        | [[z _SURCHARGE_]]
  646.                                                   |-------------------
  647.                                              #    | [[t total]]
  648.  
  649.  
  650. Cheques should be crossed and made payable to Dotheboys Hall School Ltd
  651.  
  652. FEES ARE PAYABLE STRICTLY IN ADVANCE AND MUST BE RECEIVED BY THE FIRST DAY
  653. OF THE NEW TERM
  654.  
  655. Next Term Begins  _WHEN IT BEGINS_
  656.  
  657.  
  658.      This introduces a few new points. First of all, each calculation inside 
  659. the brackets has two sections. This is because there are a great number of 
  660. ways of representing numbers or quantities in commercial or scientific use. 
  661. You can rely on Scrivener's way of doing it, but you can actually specify 
  662. other ways that may be more suitable for your application. The first section 
  663. after the '[[' allows you to specify any special ways that you would like 
  664. the value put in the file. If you wish to use this facility, it consists of 
  665. one or more letters followed by a space. It is put before the actual 
  666. calculation. 
  667.  
  668.      We need to use only two single-letter commands here, 't' and 'z'. The 
  669. 't' indicates that we want a total of all the numbers in the same column up 
  670. to that point. So we use it for totalling the entire column, as well as 
  671. taking the discount away from the fees. The 'z' indicates that we want the 
  672. line deleted if the result of the calculation is zero. So if the discount is 
  673. zero we remove the line completely. Similarly with the surcharge.
  674.  
  675.      Well let's try it out. Let us pass the file through Scrivener. This 
  676. might be the result:-
  677.  
  678. Version 1.0
  679.  
  680. MML Systems Ltd 
  681.  
  682. ***Enter the pupil's name --> Arthur Megabyte
  683. What fees should be paid --> 180
  684. What form is he in --> 2BJ
  685. What discount for second child  --> 9
  686. Enter the lunch costs --> 56
  687. Enter piano costs --> 0
  688. Enter the costs of music books --> 0
  689. Enter the costs of speech training --> 70
  690. Enter the brass costs --> 0
  691. Enter the costs of instrument hire --> 0
  692. Enter the cost for milk --> 5.5
  693. Enter the surcharge --> 0
  694.  
  695.   giving  the 
  696. appropriate reply to prompts, results in:-
  697.  
  698.  
  699.                Dotheboys Hall School Ltd
  700.  
  701.                     Duncayning
  702.  
  703.                     Duncayning 3549
  704.  
  705.                                         Autumn  Term 1986
  706.  
  707.  
  708. Name:- Arthur Megabyte                       Form 2BJ
  709.  
  710. --------------------------------------------------------------------------
  711. Fees                                              | 180     
  712. discount for 2nd child                            | -9                
  713.                                                   | 171         
  714.                                                   |
  715.  Lunches                                          | 56      
  716.                                                   |
  717.  Piano                                            | 0      
  718.  Music Books                                      | 0      
  719.  Speech Training                                  | 70      
  720.  Brass                                            | 0      
  721.  Instrument Hire                                  | 0      
  722.  Milk                                             | 5.5     
  723.  Extras                                           | 0      
  724.                                                   |
  725.                                                   |-------------------
  726.                                              #    | 176.5      
  727.  
  728.  
  729. Cheques should be crossed and made payable to Dotheboys Hall School Ltd
  730.  
  731. FEES ARE PAYABLE STRICTLY IN ADVANCE AND MUST BE RECEIVED BY THE FIRST DAY
  732. OF THE NEW TERM
  733.  
  734. Next Term Begins  September 11th 1986.
  735.  
  736.  
  737.      That shows that we have at least got the logic right. When preparing a 
  738. model like this it is always best to make sure that your logic and 
  739. mathematics are correct, before improving the appearence of the output. Add 
  740. new ideas and features in easy stages, testing things out as you go.
  741.  
  742.  
  743.      A moments inspection of the result of the 'model' so far will convince 
  744. us that there is some work still to do to get what we want. For a start, the 
  745. columns are not lined up accurately. This requires that we tell Scrivener 
  746. something about the way we want the numbers formatted. This is done by using 
  747. the single letter 'f' command (meaning format). This has three parts to it; 
  748. the field width, the number of decimal places to print to and whether or not 
  749. to include trailing zeros. In this case the field width would be about 8 
  750. characters, we want 2 places of decimals and we want trailing zeroes kept.
  751.  
  752. So at the beginning of the file we put
  753. [[def 8.2t]]
  754.  
  755.      This mysterious legend tells Scrivener what we want to do. Although its 
  756. meaning is rather opaque to us, It is very easy for the program to 
  757. understand. Long meaningful commands and labels are easier to learn, but 
  758. they spoil the layout through taking too much space. The '[[' at the start 
  759. gives Scrivener a nudge and signals that something significant is following. 
  760. What actually follows is the optional section that we have mentioned. The 
  761. 'd' (Delete line) at the beginning means that the line should be deleted, 
  762. and not put in the final output. The  'e'  that follows commands Scrivener 
  763. not to attempt to evaluate the second section, which, in fact, is left 
  764. blank. What follows is the 'f' command (Format) which, in the '8.2t', is 
  765. asking Scrivener to allow eight spaces for the column, represent the number 
  766. to two decimal places, and put trailing zeros in the number. This command is 
  767. so often used in commercial work that it can be copied without spending too 
  768. much effort into understanding the whys and wherefores.
  769.  
  770.      It also looks out of place to have zeroes for all the sections which do 
  771. not apply to a particular child. We could use the 'delete if zero' command 
  772. to delete the entire line if it is unused, but as the headmaster insists 
  773. that the new Scrivener invoice should conform to the old handwritten ones 
  774. (so as not to confuse the parents) we choose, instead, to use the 'b' 
  775. command to blank out the zeroes. The choice is in our control, by using the 
  776. first section after the '[['.
  777.  
  778.      So we now have a usable file, though there is still much we can do to 
  779. improve it. The source should now be:-
  780.  
  781.  
  782. #define _TERM_,,Autumn 
  783. #define _YEAR_,,1986
  784. #define _WHEN IT BEGINS_,,September 11th 1986.
  785. #input _THE BOYS NAME_,,Enter the pupil's name
  786. #input _HIS FORM_,,What form is he in
  787. #input _THE FEES_,,What fees should be paid
  788. #input _DISCOUNT_,,What discount for second child 
  789. #input _LUNCHES_,,Enter the lunch costs
  790. #input _PIANO_,,Enter piano costs
  791. #input _MUSIC BOOKS_,,Enter the costs of music books
  792. #input _SPEECH_TRAINING_,,Enter the costs of speech training
  793. #input _BRASS_,,Enter the brass costs
  794. #input _INSTRUMENT HIRE_,,Enter the costs of instrument hire
  795. #input _MILK_,,Enter the costs of milk
  796. #input _EXTRAS_,,Enter the costs of extras
  797. #input _SURCHARGE_,,Enter the surcharge
  798.  
  799. [[def 8.2t]]
  800.                Dotheboys Hall School Ltd
  801.  
  802.                     Duncayning
  803.                     Duncayning 3549
  804.  
  805.                                         _TERM_ Term _YEAR_
  806.  
  807.  
  808. Name:- _THE BOYS NAME_                       Form _HIS FORM_
  809.  
  810. --------------------------------------------------------------------------
  811. Fees                                              | [[ _THE FEES_]]
  812. discount for 2nd child                            | [[ -_THE FEES_*(_DISCOUNT_/100)]]
  813.                                                   |-----------------------
  814.                                                   |
  815. Total fees                                        | [[t ftotal]]
  816.                                                   |
  817.  Lunches                                          | [[b _LUNCHES_]]
  818.                                                   |
  819.  Piano                                            | [[b _PIANO_]]
  820.  Music Books                                      | [[b _MUSIC BOOKS_]]
  821.  Speech Training                                  | [[b _SPEECH_TRAINING_]]
  822.  Brass                                            | [[b _BRASS_]]
  823.  Instrument Hire                                  | [[b _INSTRUMENT HIRE_]]
  824.  Milk                                             | [[b _MILK_]]
  825.  Extras                                           | [[b _EXTRAS_]]
  826.                                                   |
  827.  Surcharge                                        | [[b _SURCHARGE_]]
  828.                                                   |----------------------
  829.                                              #    | [[t total]]
  830.  
  831.  
  832. Cheques should be crossed and made payable to Dotheboys Hall School Ltd
  833.  
  834. FEES ARE PAYABLE STRICTLY IN ADVANCE AND MUST BE RECEIVED BY THE FIRST DAY
  835. OF THE NEW TERM
  836.  
  837. Next Term Begins  _WHEN IT BEGINS_
  838.  
  839.  
  840. and we get an output file something like:-
  841.  
  842.  
  843.                Dotheboys Hall School Ltd
  844.  
  845.                     Duncayning
  846.  
  847.                     Duncayning 3549
  848.  
  849.                                         Autumn  Term 1986
  850.  
  851.  
  852. Name:- Arthur Megabyte                       Form 2BJ
  853.  
  854. --------------------------------------------------------------------------
  855. Fees                                              |   180.00
  856. discount for 2nd child                            |    -9.00          
  857.                                                   |-----------------------
  858.                                                   |
  859. Total fees                                        |   171.00    
  860.                                                   |
  861.  Lunches                                          |        
  862.                                                   |
  863.  Piano                                            |        
  864.  Music Books                                      |        
  865.  Speech Training                                  |        
  866.  Brass                                            |        
  867.  Instrument Hire                                  |        
  868.  Milk                                             |     5.50  
  869.  Extras                                           |        
  870.                                                   |
  871.  Surcharge                                        |        
  872.                                                   |----------------------
  873.                                              #    |   176.50   
  874.  
  875.  
  876. Cheques should be crossed and made payable to Dotheboys Hall School Ltd
  877.  
  878. FEES ARE PAYABLE STRICTLY IN ADVANCE AND MUST BE RECEIVED BY THE FIRST DAY
  879. OF THE NEW TERM
  880.  
  881. Next Term Begins  September 11th 1986.
  882.  
  883.  
  884.      Note that all the '#define' and '#input' commands have been removed 
  885. automatically by Scrivener, all the numbers are now in a neat column and all 
  886. the zeroes have been blanked out. If the headmaster, who never liked those 
  887. d**ned computers anyway, insists on a change in the format on seeing the 
  888. output, then you can smile sweetly and merely change the format command ( 
  889. that was the one looking like '[[def 8.2t]]' ). 
  890.  
  891.  
  892.      We now have something workable to produce all those invoices neatly and 
  893. conveniently. However, there are many ways of improving the process. We have 
  894. no facilities for adding other chargeable items that may only apply to one 
  895. or two children in the school. (Those Ballet lessons for Basil, for 
  896. example). We may also want to print out the total for each child or 'post' 
  897. the results of the invioce into another file which can, in turn, be passed 
  898. through Scrivener..
  899.  
  900. #announce ^j^j^j
  901. #define _TERM_,,Autumn 
  902. #define _YEAR_,,1986
  903. #define _WHEN IT BEGINS_,,September 11th 1986.
  904. #input _THE BOYS NAME_,,Enter the pupil's name
  905. #input _HIS FORM_,,What form is he in
  906. #input _THE FEES_,,What fees should be paid
  907. #input _DISCOUNT_,,What discount for second child 
  908. #input _LUNCHES_,,Enter the lunch costs
  909. #input _PIANO_,,Enter piano costs
  910. #input _MUSIC BOOKS_,,Enter the costs of music books
  911. #input _SPEECH_TRAINING_,,Enter the costs of speech training
  912. #input _BRASS_,,Enter the brass costs
  913. #input _INSTRUMENT HIRE_,,Enter the costs of instrument hire
  914. #input _SURCHARGE_,,Enter the surcharge
  915. #input _HOW MANY_,,Enter the number of extras
  916. [[def 8.2t]]
  917.  
  918.  
  919.                Dotheboys Hall School Ltd
  920.  
  921.                     Duncayning
  922.  
  923.                     Duncayning 3549
  924.  
  925.                                         _TERM_ Term _YEAR_
  926.  
  927. Name:- _THE BOYS NAME_                      Form _HIS FORM_
  928.  
  929. ----------------------------------------------------------------
  930. Fees                                              | [[ _THE FEES_]]
  931. discount for 2nd child                            | [[z -_THE FEES_*(_DISCOUNT_/100)]]
  932.                                                   |-------------
  933.                                                   |
  934. Total fees                                        | [[t ftotal]]
  935.                                                   |
  936. Lunches                                           | [[b _LUNCHES_]]
  937.                                                   |
  938. Piano                                             | [[b _PIANO_]]
  939.  Music Books                                      | [[b _MUSIC BOOKS_]]
  940.                                                   |
  941. Speech Training                                   | [[b _SPEECH_TRAINING_]]
  942.                                                   |
  943. Brass                                             | [[b _BRASS_]]
  944.  Instrument Hire                                  | [[b _INSTRUMENT HIRE_]]
  945.                                                   |
  946. Extras:-                                          | [[sz _HOW MANY_]]
  947. #repeat #include school.inc,,_HOW MANY_
  948.                                                   |
  949. Surcharge                                         | [[b _SURCHARGE_]]
  950.                                                   |-------------
  951.                                                   |
  952.                                              #    | [[t total]]
  953.                                                    =============
  954. [[dp Total of _THE BOYS NAME_ is ,,total,,]]
  955. [[dm totals]]
  956. [[dp [[,,total,,^]^] _THE BOYS NAME_>]
  957. [[dm con:>]
  958. Cheques should be crossed and made payable to Dotheboys Hall School Ltd
  959.  
  960. FEES ARE PAYABLE STRICTLY IN ADVANCE AND MUST BE RECEIVED BY THE FIRST DAY
  961. OF THE NEW TERM
  962.  
  963. Next Term Begins  _WHEN IT BEGINS_
  964.  
  965.      The .pa at the end of the file is only applicable if you are using 
  966. Scrivener with NEWWord or WordStar. It would produce each new invoice on a 
  967. new sheet. The #repeat function includes the file school.inc:
  968.  
  969. #input _DESCRIPTION_,,Enter the description
  970. #input _COST_,,Enter the cost
  971. #overtype
  972.   _DESCRIPTION_                                   | [[b _COST_]]
  973. #insert
  974.  
  975. HOW MANY times. The dp command prints out the total to the screen.The dm 
  976. command will redirect the print commands that follow it to the file name 
  977. given, in this case 'totals'. This will allow a file of the total invoice 
  978. returns expected to be built up. This can then, with minor changes, be passed 
  979. through Scrivener, to inform the headmaster exactly how much he is skinning 
  980. the parents for.
  981.  
  982.      This would produce output like:-
  983.  
  984.  
  985.  
  986.                Dotheboys Hall School Ltd
  987.  
  988.                     Duncayning
  989.  
  990.                     Duncayning 3549
  991.  
  992.                                         Autumn  Term 1986
  993.  
  994. Name:- Arthur Megabyte                      Form 2BJ
  995.  
  996. ----------------------------------------------------------------
  997. Fees                                              |   180.00
  998.                                                   |-------------
  999.                                                   |
  1000. Total fees                                        |   180.00    
  1001.                                                   |
  1002. Lunches                                           |        
  1003.                                                   |
  1004. Piano                                             |        
  1005.  Music Books                                      |        
  1006.                                                   |
  1007. Speech Training                                   |    17.50  
  1008.                                                   |
  1009. Brass                                             |        
  1010.  Instrument Hire                                  |        
  1011.                                                   |
  1012. Extras:-                                          |         
  1013.   Milk                                            |     5.50    
  1014.                                                   |
  1015. Surcharge                                         |    12.00
  1016.                                                   |-------------
  1017.                                                   |
  1018.                                              #    |   216.00   
  1019.                                                    =============
  1020.  
  1021. Cheques should be crossed and made payable to Dotheboys Hall School Ltd
  1022.  
  1023. FEES ARE PAYABLE STRICTLY IN ADVANCE AND MUST BE RECEIVED BY THE FIRST DAY
  1024. OF THE NEW TERM
  1025.  
  1026. Next Term Begins  September 11th 1986.
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.      Obviously, a fair amount of work has gone into getting the invoice just 
  1035. right. However, it can now be used over and over again. It can be modified 
  1036. over a period of time in the light of changing needs, and so on. Once the 
  1037. work is done, the 'task file' is always there.
  1038.  
  1039.      If you are using Scrivener, it pays to build up a library of task files 
  1040. to suit the work you have to do. Using or altering an existing task file is 
  1041. very easy and takes little time. Making a new task requires a bit of 
  1042. patience. Look for an example that approximates to what you want and alter 
  1043. it to suit. Add and test out new features one by one. Scrivener is not 
  1044. dressed-up with gimmicks, but rewards a little bit of time to master the 
  1045. conventions of using it.
  1046.  
  1047.  
  1048.      Imagine that we have a simple calculation to do, and for some reason, 
  1049. wanted to do it on the computer rather than the pocket calculator. The 
  1050. calculation is to calculate the depreciation of a piece of machinery :- 
  1051.  
  1052. #input _COST_,,The cost of the asset was
  1053. #input _LIFE_,,Enter the estimated lifetime of the asset
  1054. #input _EDV_,,Enter the estimated disposal value of the asset
  1055. [[d of=(_EDV_/_COST_)]]
  1056. [[d root=of^(1/_LIFE_)]]
  1057. [[d rate=100-(100*(root))]]
  1058. [[def 8.3]]
  1059. [[dp the rate of depreciation of the asset is ,,rate,,%]]
  1060.  
  1061.      This takes the user input for cost,life and estimated disposal value of 
  1062. the machinery and calculates the rate according to the equation
  1063.  
  1064. rate=100-(100*(estimated disposal value/cost)^(1/life))
  1065.  
  1066. (a power of 1/n is equivalent to the nth root).
  1067.  
  1068.      Using the Scrivener 'm' statement to mail the print statements to an 
  1069. output file, it would be possible to build up a large number of depreciation 
  1070. of assets, which could further be included in other calculations with or 
  1071. without uing Scrivener.
  1072.  
  1073.      It is very easy to customise such a task file to your own taste, using 
  1074. the flexibility of your own text editor. For example, you may wish to 
  1075. present to the managing director of a firm, a detailed list of all the 
  1076. depreciation rates of all his equipment. This can be done by simple changes 
  1077. to the above file :-
  1078.  
  1079. #input _NAME_,,Enter the name of the asset (max 20 letters)
  1080. #input _COST_,,The cost of the asset was
  1081. #input _LIFE_,,Enter the estimated lifetime of the asset
  1082. #input _EDV_,,Enter the estimated disposal value of the asset
  1083. [[def 8.6]]
  1084. [[d of=(_EDV_/_COST_)]]
  1085. [[d root=of^(1/_LIFE_)]]
  1086. [[d rate=100-(100*(root))]]
  1087. [[def 8.3]]
  1088. #overtype
  1089. [[dm deprec.out]]
  1090. [[dp the rate of depreciation of the _NAME_                 is      ,,rate,,^j^j^m]]
  1091. #insert
  1092.  
  1093. this will produce an output to the file deprec.out which looks like:-
  1094.  
  1095.  the rate of depreciation of the Mole Drainer           is        33.126
  1096.  
  1097.  the rate of depreciation of the Trencher               is        20.63 
  1098.  
  1099.  the rate of depreciation of the Digger                 is        16.375
  1100.  
  1101.  the rate of depreciation of the Trailer                is        29.289
  1102.  
  1103.  the rate of depreciation of the Tractor                is        33.167
  1104.  
  1105. for the appropriate input. The file can be made even flashier to produce a 
  1106. file which can again be passed through Scrivener to work out average 
  1107. depreciation, total loss on assets for one year and so on, as you become more 
  1108. adept at Scrivener's powers and uses.
  1109.  
  1110.  
  1111. 1.4 Using the calculator.
  1112.  
  1113.      So  far,  we  have  not  dwelt at length  on  the  calculator  functions. 
  1114. 'Expressions' can range from the simple:-
  1115. [[ 1 ]]
  1116. to the complex, involving assignments, operators, operations and functions. 
  1117. These  can  be  written  just as if they were included  in  a  BASIC  program. 
  1118. Naturally,  the left hand side of the expression,  if it exists, can only be a 
  1119. variable, (not another expression).
  1120. so,
  1121. [[ vat*10=150 ]] is wrong
  1122. whereas:-
  1123. [[ vat = 150/10 ]]
  1124. is all  right.
  1125.  
  1126. are in two parts, though the first is only optional. In order to be able to 
  1127. specify exactly how you wish the result, you can specify a series of 
  1128. characters, each of which have certain significance. The second part of any 
  1129. expression you want Scrivener to evaluate is the calculation itself. This 
  1130. can be anything from a simple addition to hyperbolic trigonometrical 
  1131. functions. It may include extensive use of variables.
  1132.  
  1133.      Variables may be a maximum of eight letters in length and can be 
  1134. assigned to, or used in a calculation after they have been assigned. 
  1135.  
  1136.      When you make an assignment to a variable, and it does not already 
  1137. exist, Scrivener decides that you want to create it with an initial value 
  1138. equivalent to the value you assign to it. In this way, you can use variables 
  1139. in your computations, to make them more easily readable. All the normal 
  1140. mathematical operators are allowed. We will need to wait until later in the 
  1141. documentation for the full details on the calculator and the functions that 
  1142. provide boolean and trigonometric functions.
  1143.      
  1144.      The mathematical expressions follow the standard conventions and are 
  1145. readily grasped by anyone familiar with elementary mathematics. A useful way 
  1146. to practice, or to key-in simple expressions is to use the simple two-line 
  1147. program:-
  1148.  
  1149. #input mac_calc,,^j^j^jWhat do you wish calculated
  1150. [[dp mac_calc = ,,mac_calc,, ]]
  1151.  
  1152.      If you run this and answer with a variety of expressions you will soon 
  1153. become familiar with the way SCRIVENER does calculations.
  1154.  
  1155. 2. How Scrivener works.
  1156.  
  1157.      Scrivener is basically a macro translator and multiple pass calculator, 
  1158. with added unusual macro functions to improve its ease of use and 
  1159. flexibility. It can accept parameters to be used in macros and can also 
  1160. accept input from the keyboard (or a redirection file). It can also append 
  1161. lines of output to the end of other files.
  1162.  
  1163.      The macro pass can be used to great effect, in manipulating 
  1164. calculations, producing standard letters, doing mail shots as well as 
  1165. complex text manipulation. 
  1166.    
  1167.      The multiple pass calculator allows delimited calculations to be 
  1168. computed and can include forward references to variables. It also includes 
  1169. many logical functions as well as a full range of scientific ones. It also 
  1170. includes column and row totals, a user stack with average, sum and lookup 
  1171. functions. Normal operator precedence is assumed by the calculator and 
  1172. unusual forms of calculations can assign variables inside calculations. 
  1173. Unlike spreadsheets, Scrivener does not require calculations to be placed in 
  1174. specific places, nor does it assume standard, meaningless variable names 
  1175. such as H35, but allows more flexible use, with variable names such as 
  1176. cost,total etc.
  1177.  
  1178. 2.1 Scrivener in operation.
  1179.  
  1180.      Scrivener takes an input file name, either from the command line or via 
  1181. a prompt as well as an output file name in the same way. The command line 
  1182. may also contain one other parameter, a -m mail merge option.
  1183.  
  1184.      The input file is opened as is a temporary file, called 'temp.fil'. On 
  1185. the first pass, each line of the input file is read, all the macro 
  1186. translations are made, and the result of each line is output to the 
  1187. temporary file. Hereafter, the input file remains untouched and is not used.
  1188.  
  1189.      On the next pass, each line of the temporary file is read in and all 
  1190. the calculations are done, this pass is repeated until either all the 
  1191. calculations have successfully been completed, or five such passes have been 
  1192. made. 
  1193.  
  1194.      The final pass opens the output file for appending (or creates it if it 
  1195. does not already exist). It then procedes much as the other passes, taking 
  1196. each line from the temporary file, and evaluating the necessary 
  1197. calculations. All the appropriate formatting of results is done, and the 
  1198. final polished line is output. All lines set for deletion are deleted at 
  1199. this point.
  1200.  
  1201.      If, on the final pass, some calculations are not completed, due to 
  1202. errors in the input file, mathematical errors or undefined symbols, the 
  1203. result is given as zero.
  1204.  
  1205.      In most cases, Scrivener will announce errors as they occur, though in 
  1206. some cases, due to its flexible syntax, will make sense of some calculations 
  1207. with missing brackets etc., and so may not gice an error where one is 
  1208. expected.
  1209.  
  1210.  
  1211. 3. Macros.
  1212.  
  1213.      The macro translator is one of the more powerful aspects of the 
  1214. Scrivener package and can be used for everything from simple search and 
  1215. replace functions, to complex personalization of letters and mail shots. 
  1216. Generally, the functions are variations of the 'define' function and can be 
  1217. treated similarly. Essentially the 'define' function allows a piece of text 
  1218. such as a word or phrase to be substituted for another.
  1219.  
  1220.      Each definition consists of two parts, the first is the part by which 
  1221. it is recognized (the name), the last is the part which will replace this 
  1222. (the definition). The two parts are separated by a double comma (,,). Before 
  1223. each definition is assigned it is searched to see if it contains a 
  1224. previously defined macro name. If any are found they are replaced.
  1225.  
  1226.      Either the name or the definition may contain control characters 
  1227. signified by a ^. These are generally specific to the machine being used, 
  1228. but it is possible, for example, to replace all the tabs in a file with a 
  1229. single space by including
  1230.  
  1231. #define ^I,, 
  1232.  
  1233. at the files beginning.
  1234.  
  1235.      A name may be redefined at any time by just defining it again via any 
  1236. of the defining macro commands.
  1237.  
  1238.      All macro commands are deleted in the final output file.
  1239.  
  1240.  
  1241.  
  1242.  
  1243.      The commands available to the macro translator are :-
  1244.  
  1245.  
  1246.                 DEFINE
  1247.  
  1248. #define name,,definition
  1249.  
  1250.                          This is the easiest form of the macro translator. 
  1251.                          It simply will replace all appearances of name by 
  1252.                          definition. This definition may include anything up 
  1253.                          to nine parameters given after name in the text.
  1254.  
  1255.    For example:-
  1256.  
  1257. #define cust_name,,Customer Name
  1258.  
  1259.                          will replace cust_name in the text which follows 
  1260.                          the definition by Customer name.
  1261.  
  1262. #define cost_of_item,,The $1 costs #$2
  1263.  
  1264.                          will find all cost_of_items in the text and will 
  1265.                          replace them with the text and parameters 1 and 2 
  1266.                          (shown by the dollar) imbedded in the appropriate 
  1267.                          point. So if
  1268.  
  1269. cost_of_item [bag of cement,,3.80]
  1270.  
  1271.                          occurs in the text following the definition, it 
  1272.                          will be replaced by
  1273.  
  1274. The bag of cement costs #3.80.
  1275.  
  1276.                          The parameters are recognized in the definition by 
  1277.                          the dollar sign (note that a single dollar symbol 
  1278.                          may be obtained by a $$) and all parameters in the 
  1279.                          text must be enclosed in square brackets. It is 
  1280.                          possible to use parameters in the definition in a 
  1281.                          different order than they occur after the name. If 
  1282.                          we redefine cost_of_item by, later in the text, 
  1283.                          typing:-
  1284.  
  1285. #define cost_of_item,,The #$2 you paid was for $1
  1286.  
  1287.                          then the occurrence of
  1288.  
  1289. cost_of_item [3 yards of piping,,2.80]
  1290.  
  1291.                          will, after this definition, be replaced by
  1292.  
  1293. the #2.80 you paid was for 3 yards of piping
  1294.  
  1295.  
  1296.                 OVERTYPE
  1297. #overtype 
  1298.  
  1299.                          After this function appears in the text, and until 
  1300.                          a #insert appears, all replacements made are either 
  1301.                          padded out with enough spaces to fill the area 
  1302.                          occupied by the name, or they overtype any text in 
  1303.                          front of them if necessary. This is particularly 
  1304.                          useful in setting up columns of figures with macros 
  1305.                          in them.
  1306.                          Problems can occur if macros overtype a single tab 
  1307.                          character. This causes columns to 'pull back' 
  1308.                          towards the left. The safest way to avoid this is 
  1309.                          to ensure that, where macro replacements are going 
  1310.                          to be made, columns are padded out with spaces and 
  1311.                          not tabs.
  1312.  
  1313.  
  1314.  
  1315.                 INSERT
  1316. #insert
  1317.  
  1318.                          After this appears in the text, all replacements 
  1319.                          are inserted into the space previously used by the 
  1320.                          name, no text is overwritten and no spaces added as 
  1321.                          with overtype. This is the default value, at the 
  1322.                          beginning of the file.
  1323.  
  1324.  
  1325.                 INPUT
  1326.  
  1327. #input name,,prompt[,,definition]
  1328.  
  1329.                          This function will stop processing of Scrivener and 
  1330.                          display a prompt to the screen (or outward 
  1331.                          redirection file) and will wait for an input from 
  1332.                          the keyboard (or the inward redirection file). It 
  1333.                          will then create a definition recognized by name 
  1334.                          and consisting either of definition (which may or 
  1335.                          may not include the input in it) or by default, 
  1336.                          just the input. For example:-
  1337.  
  1338. #input inv_no,,Please enter the invoice number
  1339.  
  1340.                          will print
  1341.  
  1342. Please enter the invoice number -->
  1343.  
  1344.                          on the screen and will then wait for a user input 
  1345.                          (or that from a redirection file). Thereafter, it 
  1346.                          will replace all occurrences of inv_no by the input 
  1347.                          given at this prompt.
  1348.  
  1349. #input inv_no,,Please enter the invoice number,,Invoice number is $I
  1350.  
  1351.                          will print
  1352.  
  1353. Please enter the invoice number -->
  1354.  
  1355.                          again and will again accept an input. This time it 
  1356.                          will replace the $I in the definition by the input, 
  1357.                          and will define inv_no as that resultant 
  1358.                          definition. So if the input was 
  1359.  
  1360. 67245
  1361.  
  1362.                          all following occurrences of inv_no will be 
  1363.                          replaced by
  1364.  
  1365. Invoice number is 67245
  1366.  
  1367.                          throughout the text file.
  1368.  
  1369.                          This form of input is the same as doing
  1370. #input mac_inv,,Please enter the invoice number
  1371. #define inv_no,,Invoice number is mac_inv
  1372.  
  1373.  
  1374.  
  1375.                 DEFAULT
  1376. #default default_value
  1377.  
  1378.                             This function is used to provide a default for 
  1379.                          the input statement, so that, if, at run time, the 
  1380.                          user merely types return to an input request, 
  1381.                          sensible values can be obtained.
  1382.  
  1383.                          For example:-
  1384.  
  1385. #input _PRICE_,,Enter the price
  1386.  
  1387. total cost              [[ _PRICE_ * 1.15]]
  1388.  
  1389.                          would give an error message if no input is given, 
  1390.                          whilst
  1391.  
  1392. #default 0
  1393. #input _PRICE_,,Enter the price
  1394.  
  1395. total cost              [[ _PRICE_ * 1.15]]
  1396.  
  1397.                          would give no error message, and the default zero 
  1398.                          would be used if no input was given,
  1399.  
  1400.  
  1401.  
  1402.  
  1403.  
  1404.                 INCLUDE
  1405.  
  1406. #include filename
  1407.  
  1408.                          This function can be used to include a separate 
  1409.                          file inside the original one. This file can consist 
  1410.                          of any text, more macro definitions, Scrivener 
  1411.                          calculations (though not requests for totals or 
  1412.                          clear totals) or even other includes. Nesting 
  1413.                          'include' statements may cause problems in large 
  1414.                          files or if they are nested too deeply, as it can 
  1415.                          cause interference with the stack. In general try 
  1416.                          not to nest include requests more than twice or 
  1417.                          three times.
  1418.  
  1419. #include extra.fil
  1420.  
  1421.                          found in a source text file, will ask Scrivener to 
  1422.                          open the file called "extra.fil" and will then take 
  1423.                          lines from that file as if they were lines from the 
  1424.                          original file. So if extra.fil contains
  1425.  
  1426. #input mac_date,,Enter the date,,today's date:-
  1427.  
  1428.                                         Company X Ltd   
  1429.                                         Our Premises
  1430.                                         The Street
  1431.                                         The Town
  1432.  
  1433.                                 mac_date
  1434.  
  1435.                          upon entering '29th August, 1985.', it will insert 
  1436.                          into the file
  1437.  
  1438.                                         Company X Ltd   
  1439.                                         Our Premises
  1440.                                         The Street
  1441.                                         The Town
  1442.  
  1443.                                 29th August, 1985.
  1444.  
  1445.  
  1446.  
  1447.                 ANNOUNCE
  1448.  
  1449. #announce output line
  1450.  
  1451.                            This function allows the source text file to 
  1452.                          output something to the screen. This may include 
  1453.                          control characters (as may the input function in 
  1454.                          its prompt). 
  1455.  
  1456. For example:-
  1457.  
  1458. #announce ^m^j^jThis is the program beginning
  1459.  
  1460.                          will print on the screen two new lines (the control 
  1461.                          m is signified by the ^m - a ^ is obtained by ^^ 
  1462.                          and a control^ is signified by a ^~ ). It is 
  1463.                          important to note that the announce line is passed 
  1464.                          through the replacement routine so macros may be 
  1465.                          included in it.
  1466.  
  1467. #define current_price_of_cheese,,98p per lb
  1468. #announce  The cost of cheese is current_price_of_cheese.
  1469.  
  1470.                          will print
  1471.  
  1472. The cost of cheese is 98p per lb.
  1473.  
  1474.                          on the screen.
  1475.  
  1476.  
  1477.                 RANDOM
  1478.  
  1479. #random name,,phrase[,,phrase[,,phrase .... ]]
  1480.  
  1481.                          This unusual function can be used to "personalize" 
  1482.                          letters by using random synonymous phrases. Up to 
  1483.                          six phrases can be chosen from by the random 
  1484.                          function. For example:-
  1485.  
  1486. #random thank_phrase,,Thank you for,,Many thanks for,,It was kind of you to send 
  1487.  
  1488.                          in the text will assign one of the three phrases 
  1489.                          following it as the definition of thank_phrase, so 
  1490.                          that when
  1491.  
  1492. thank_phrase the parcel.
  1493.  
  1494.                          occurs in the text it will be replaced by either
  1495.  
  1496. Thank you for the parcel.
  1497.                          or
  1498. Many thanks for the parcel.
  1499.                          or
  1500. It was kind of you to send the parcel.
  1501.  
  1502.                          As this function merely produces a random 
  1503.                          definition within the limits you set it, it is 
  1504.                          identical to the define function in use and can 
  1505.                          contain parameters etc. (cf define). 
  1506.  
  1507.  
  1508.                 REPEAT
  1509. #repeat line,,no of times
  1510.  
  1511.                          This function can be used to repeat one line many 
  1512.                          times in the output file (or many lines - see 
  1513.                          techniques). A line cannot be repeated more than 
  1514.                          100 times (if you try, only a maximum of 100 will 
  1515.                          be replaced).
  1516.  
  1517. #repeat #include another.fil,,4
  1518.  
  1519.                          will include (cf include function) the file 
  1520.                          "another.fil" four times, doing all the macro 
  1521.                          functions and replacements within that file as it 
  1522.                          inserts it.
  1523.  
  1524.  
  1525.  
  1526.  
  1527. 5. Calculator.
  1528.  
  1529.      The calculator is a full function multi-pass calculator, which allows 
  1530. the assignments of variables, includes a stack,last answer recall,simple 
  1531. lookups, boolean and bitwise logic as well as a conditional.
  1532.  
  1533.      All calculator functions are performed after the macro pass, so, though 
  1534. Scrivener's macro ability can be used powerfully to alter calculations, the 
  1535. reverse is not true. Some additional commands have been added to the 
  1536. calculator to go some way to compensate for this.
  1537.  
  1538.      Full formatting of numbers is allowed, deletion of working is possible 
  1539. and a 'delete if zero' command is available.
  1540.  
  1541.      The calculator recognises all its calculations by delimiters which 
  1542. consist of '[[' (open square brackets and less than) at the beginning and 
  1543. ']]' (greater than and close square brackets) at the end. The calculation 
  1544. itself is broken into two parts, a header and a body. 
  1545.  
  1546.      The header controls exactly how Scrivener handles the calculation, and 
  1547. what it does with the result, whilst the body handles the mathematics and 
  1548. expressions. Header commands consist of a single letter and can be mixed to 
  1549. create other effects. The two parts of the section must be separates by a 
  1550. space (even if either of them are actually nothing).
  1551.  
  1552.      By default (ie if you type a space then an expression, after the 
  1553. opening brackets ), Scrivener assumes that the expression is to be 
  1554. calculated and the result is to replace the expression in the text  (padded 
  1555. by spaces to make sure columns don't go out of alignment).
  1556.  
  1557.      This default can be altered or added to by the following set of 
  1558. commands:-
  1559.  
  1560.                 D - Delete line
  1561.  
  1562.    The d command can be used to delete the line on which appears. 
  1563. It is normally used to remove side working (against any 
  1564. mathematics teacher's advice). It is also useful for squeezing 
  1565. large expressions into small places (see techniques).
  1566.  
  1567.                 L - Line total
  1568.  
  1569.    The l command is to allow you to assign the total of all the 
  1570. calculations to a variable. If
  1571.  
  1572. [[ x = 10]] [[ y = 19]] [[ x * y]] [[l var1]]
  1573.  
  1574. appeared in the text, Scrivener would assign var1 the value of 
  1575. x+y+xy ie 219 and on output would produce
  1576.  
  1577. 10          19          190        219       
  1578.  
  1579. in the output file.
  1580.  
  1581.    It is possible to include more than one line total in a line, 
  1582. each of which would give a total up to that point, e.g.
  1583.  
  1584. [[ x = 10]] [[ y = 19]] [[l var1]] [[ x * y]] [[l var2]] 
  1585.  
  1586. would give an output
  1587.  
  1588. 10          19          29         190        219        
  1589.  
  1590. (note that the l command automatically prevents addition of its 
  1591. result to the line total - i.e. in the above example var1 does 
  1592. not get added to var2).
  1593.  
  1594.                 F - Format
  1595.  
  1596.    This command allows the user to format numbers, declaring the 
  1597. number of decimal places of accuracy,  minimum field width and 
  1598. whether or not to remove trailing zeroes. 
  1599.  
  1600.    The format of this command is
  1601. [[f A.BT]]
  1602. where A is the minimum field width,B is the number of decimal 
  1603. places the numbers are to be taken to and T is a flag which if 
  1604. set means that trailing zeroes (after the decimal point) are to 
  1605. be included (otherwise they are removed).
  1606.  
  1607.   If the field width is larger than the length of the 
  1608. resultant number then it is right justified by adding leading 
  1609. spaces ( a minus sign will left justify the number ).
  1610.  
  1611.    So, if 
  1612.  
  1613. [[f 4.2t]]
  1614. [[ x=9]]        [[ y=10.5]]
  1615.  
  1616. appeared in the source
  1617.  
  1618.           
  1619. 9.00            10.50   
  1620.  
  1621. would be output (note that the format command is automatically 
  1622. replaced with spaces in the output), whereas if
  1623.  
  1624. [[f 8.2]]
  1625. [[ x=9]]        [[ y=10.5]]
  1626.  
  1627. occurs
  1628.  
  1629.          
  1630.     9              10.5    
  1631.  
  1632. would be output, the trailing spaces having been removed (and the 
  1633. trailing decimal point in the case of x=9).
  1634.  
  1635.                 E - do not Express
  1636.  
  1637.    This is a useful addition to the Scrivener set to add a comment 
  1638. beside some working in the source file which will be replaced by 
  1639. spaces in the final output file.
  1640.  
  1641. For example:-
  1642.  
  1643. [[ x=10]] [[e this comment could tell you what x is]]
  1644.         
  1645. would give
  1646.  
  1647. 10
  1648.  
  1649. as its result, the comment having been replaced by spaces for the 
  1650. output. The use of comments to explain in the source exactly what 
  1651. is going on is very useful (especially if you - or someone else - 
  1652. tries to understand it months or years after it was written).
  1653.  
  1654.                 A - do not Add to totals
  1655.  
  1656.    This function prevents the result of the calculation being 
  1657. added to both line and column totals. This is useful if side 
  1658. calculations are not required to be added and to allow 
  1659. calculations in columns where column totals are requested.
  1660.  
  1661.    If
  1662.  
  1663. [[ x=9]] [[ y=13]] [[a z=15]] [[l atotal]]
  1664.                    [[ z2=15]]
  1665.                    [[t total2]]
  1666.  
  1667. will result in 
  1668.  
  1669.  
  1670. 9        13        15         22          
  1671.                    15        
  1672.                    15          
  1673.  
  1674. instead of
  1675.  
  1676.  
  1677. 9        13        15         37          
  1678.                    15        
  1679.                    30          
  1680.  
  1681. if the a command had been missing ( and the 15 been added to both 
  1682. the line and column total).
  1683.  
  1684.                 T - column Total
  1685.  
  1686.    This powerful feature of Scrivener can be used to sum all the 
  1687. results of the calculations in a column. The t command must be 
  1688. applied to a variable which will hold the sum of the column, so 
  1689. the body of this command must be the name of the variable you 
  1690. want this assigned to. The column is defined by the open square 
  1691. bracket of the delimiter i.e. all the calculations whose open 
  1692. +brackets are in the same column as those of the total request.
  1693.  E.g.
  1694.  
  1695. [[f 8.2]]
  1696. cost of pipes  [[ 12     ]]
  1697. cost of taps   [[ 15     ]]
  1698. cost of basins [[ 756    ]]
  1699.  
  1700. total          [[t total ]]
  1701.  
  1702. vat            [[ vat=total*0.15]]
  1703.  
  1704. final total    [[t ftotal]]
  1705.  
  1706.  
  1707. will result in
  1708.  
  1709.          
  1710. cost of pipes     12       
  1711. cost of taps      15       
  1712. cost of basins   756       
  1713.  
  1714. total            783       
  1715.  
  1716. vat              117.45           
  1717.  
  1718. final total      900.45    
  1719.  
  1720. Note that the results of total requests are not themselves added 
  1721. to totals further down the column.
  1722.  
  1723.  
  1724.                 C - Clear total
  1725.  
  1726.    This command can be used to reset the column total, so two 
  1727. separate column totals can be done one under the other in the 
  1728. same column (cf T - column total command).
  1729.  
  1730.    For example
  1731.  
  1732. [[f 8.2]]
  1733. 9 bags of cement        [[ 9*3.20]]
  1734. 3 tons gravel           [[ 3*8.70]]
  1735. hire of lorry           [[ 10.80]]
  1736.  
  1737. sub-total               [[t total]]
  1738.  
  1739.                         [[ce ]]
  1740. 3 days labour           [[ 3*15.00]]
  1741. 4 hours overtime        [[ 4*3.50]]
  1742.  
  1743. labour total            [[t ltotal]]
  1744.  
  1745. total cost              [[ total+ltotal]] 
  1746.  
  1747. would give
  1748.  
  1749. 9 bags of cement           28.8    
  1750. 3 tons gravel              26.1    
  1751. hire of lorry              10.8   
  1752.  
  1753. sub-total                  65.7    
  1754.  
  1755.                                
  1756. 3 days labour              45       
  1757. 4 hours overtime           14      
  1758.  
  1759. labour total               59       
  1760.  
  1761. total cost                124.7           
  1762.  
  1763.  
  1764.  
  1765.  
  1766.                 Z - delete line if Zero
  1767.  
  1768.    This conditional command is useful for removing redundant 
  1769. phrases from text calculations, for instance to remove lines 
  1770. referring to discount if the discount is zero can be removed. 
  1771.  
  1772. E.g.
  1773.  
  1774. Discount given                  [[z dis]]
  1775.  
  1776. will remove the entire line if the variable 'dis' is zero, 
  1777. otherwise it will leave it and replace the command by the value 
  1778. of dis.
  1779.  
  1780.  
  1781.                 S - replace with Spaces
  1782.  
  1783.    Similarly to delete line, this command will replace the 
  1784. section that it is in by an appropriate number of spaces - this 
  1785. would be used to remove side working.
  1786.  
  1787. For example:=
  1788.  
  1789. [[ x=10]]       [[s y=19]]      [[ x*y]]
  1790.  
  1791. will give
  1792.  
  1793. 10                              190
  1794.  
  1795. the middle command having been replaced with spaces, but having 
  1796. actually been calculated and the assignment made.
  1797.  
  1798.  
  1799.  
  1800.                 P - Print
  1801.  
  1802.    This command allows the user to output to the screen (or 
  1803. redirection file) some information which may include the contents 
  1804. of variables. Note that all print commands are executed after all 
  1805. the macro announce commands (cf #announce).
  1806.  
  1807.    This command produces no output to the output file, but only 
  1808. to the screen or redirection file.
  1809.  
  1810.    Any variables or calculations must be enclosed by double 
  1811. commas to separate direct screen output from that which needs to 
  1812. be calculated.
  1813.  
  1814. [[ x=9]]        [[ y=15]]
  1815.  
  1816. [[p The product of x and y is ,,x*y,, the sum is ,,x+y,,]]
  1817.  
  1818. would result in
  1819.  
  1820.  The product of x and y is 135     the sum is 24     
  1821.  
  1822. being output on the screen with an output file of
  1823.  
  1824. 9               15       
  1825.  
  1826.  
  1827. being produced with the print statement having been replaced with 
  1828. spaces - if dp is used as an alternative the entire line would be 
  1829. removed.
  1830.  
  1831.  
  1832.                 M - Mail to file
  1833.  
  1834. Using this function, it is possible to redirect the output of a 
  1835. print statement (cf p - print) to append to a file (or create it 
  1836. if it does not already exist). This is useful to create files of 
  1837. invoice totals, which can, later, be used for cash management 
  1838. etc. and can even be passed through Scrivener (using minor 
  1839. changes) for further calculations.
  1840.  
  1841. For example:-
  1842.  
  1843. [[m output.fil]]
  1844. [[p This result should go to "output.fil" ]]
  1845. [[m CON:]]
  1846. [[p and this should go to the screen]]
  1847.  
  1848. would output the result of the first print statement to the file 
  1849. called 'output.fil' and the second to the screen (con: meaning 
  1850. console - we could use lst: for list device or pun: for RS232 
  1851. out). It is still possible to write the results of calculations 
  1852. using the print statement, merely that the result is appended to 
  1853. a file rather than cast to the screen.
  1854.  
  1855.  
  1856.                 O - Overtype
  1857.  
  1858.    This function prevents Scrivener from padding out the answer 
  1859. with spaces so that it fills the same space as the original 
  1860. source. This it does by default, in order that columns will not 
  1861. be destroyed as answers of varying length are output. In text 
  1862. however, it may be necessary for numbers to appear "naturally" in 
  1863. a line.
  1864.  
  1865. If, for example
  1866.  
  1867. [[def 4.2t]]
  1868. The #[[ 3*7.5]] you paid was received with thanks
  1869.  
  1870. were to appear, Scrivener would interpret this as
  1871.  
  1872.  
  1873. The #22.50      you paid was received with thanks
  1874.  
  1875. whereas, if
  1876.  
  1877. [[def 4.2t]]
  1878. The #[[o 3*7.5]] you paid was received with thanks
  1879.  
  1880. were in the file, it would be interpreted as
  1881.  
  1882. The #22.50 you paid was received with thanks
  1883.  
  1884.  
  1885.                 B - Blank if zero
  1886.  
  1887. This function will replace a result with spaces, if it is zero. 
  1888. It is similar, and has similar uses, to the z, delete if zero, 
  1889. command.
  1890.  
  1891. So
  1892.  
  1893. Discount                        [[b dis]]
  1894.  
  1895. will have the result
  1896.  
  1897. Discount                                 
  1898.  
  1899. if dis is zero
  1900.  
  1901. and
  1902.  
  1903. Discount                         9.85
  1904.  
  1905. or similar if dis is non zero.
  1906.  
  1907.  
  1908.  
  1909.  
  1910.    The second part of any expression you want Scrivener to 
  1911. evaluate is the calculation itself. This can be anything from a 
  1912. simple addition to hyperbolic trigonometrical functions. It may 
  1913. include extensive use of variables.
  1914.  
  1915.    Variables may be a maximum of eight letters in length and can 
  1916. be assigned to, or used in a calculation after they have been 
  1917. assigned. 
  1918.  
  1919.    The simple operators used by Scrivener are
  1920.  
  1921. +  addition
  1922. -  subtraction
  1923. *  multiplication
  1924. /  division
  1925. \  modulus
  1926. ^  to the power of
  1927. |  bitwise or
  1928. &  bitwise and
  1929. '  bitwise exclusive or
  1930.  
  1931. these have precedence as follows
  1932.  
  1933.         -> -> -> Precedence increasing -> -> ->
  1934.  
  1935. Precedence      0       1       2       3       4
  1936. -------------------------------------------------------
  1937.                 |       +       *       ^       ()
  1938.                 &       -       /               
  1939.                 '               \                       
  1940.  
  1941. this conforms to the precedence given by PL/I
  1942.  
  1943.    The calculator also has built in function which include some 
  1944. boolean functions such as if, greater etc.
  1945.  
  1946.    The full range of functions are:-
  1947.  
  1948. sin(x)          the sine of x radians
  1949. cos(x)          the cosine of x radians
  1950. tan(x)          the tangent of x radians
  1951. log(x)          the log (to the base 10) of x
  1952. ln(x)           the natural log (to the base e) of x
  1953. abs(x)          the absolute value of x
  1954. sqrt(x)         the square root of x
  1955. fac(x)          x factorial
  1956. answer          last answer recall
  1957. stack           stack handling (see text)
  1958. sum             sum of the stack
  1959. count           no of items on stack
  1960. average(x)      average of x stack items (see text)
  1961. lookup(x)       returns the xth member of the stack
  1962. clear(0)        returns the sum of the stack and clears it
  1963. e               the value of e 
  1964. pi              the value of pi
  1965. arctan(x)       the inverse tangent of x
  1966. sec(x)          the secant of x
  1967. cosec(x)        the cosecant of x
  1968. cot(x)          the cotangent of x
  1969. arcsin(x)       the inverse sine of x
  1970. arccos(x)       the inverse cosine of x
  1971. arcsec(x)       the inverse secant of x
  1972. arccosec(x)     the inverse cosecant of x
  1973. arccot(x)       the inverse cotangent of x
  1974. sinh(x)         the hyperbolic sine of x
  1975. cosh(x)         the hyperbolic cosine of x
  1976. tanh(x)         the hyperbolic tangent of x
  1977. max(x,y)        returns the larger of x and y
  1978. min(x,y)        returns the smaller of x and y
  1979. greater(x,y)    returns non zero if x > y otherwise it returns zero
  1980. less(x,y)       returns non zero if x < y otherwise it returns zero
  1981. lesseq(x,y)     returns non zero if x <= y otherwise it returns zero
  1982. greateq(x,y)    returns non zero if x >= y otherwise it returns zero
  1983. equal(x,y)      returns non zero if x = y otherwise it returns zero
  1984. if(x,y,z)       returns y if x is non zero otherwise it returns z
  1985. deg(x)          converts x from radians to degrees
  1986. sign(x)         returns -1 if x is negative, 0 if zero , 1 if positive
  1987. round(x,y)      returns x rounded to y decimal places 
  1988. or(x,y)         returns non zero if x or y is non zero, otherwise returns zero
  1989. and(x,y)        returns non zero if x and y are non zero, otherwise returns zero
  1990. not(x)          returns non zero if x is zero, zero if x is non zero
  1991. eor(x,y)        returns non zero if x or y (but not both) are non zero
  1992. comp(x)         returns the two's complement of x
  1993. ran(x,y)        returns a random number between x and y.
  1994.  
  1995.    Many of these functions are reasonably self-explanatory, 
  1996. though some do need further discussion.
  1997.  
  1998.                 Abs - Absolute
  1999.  
  2000.      This function returns the positive value of a number (or variable). 
  2001. Abs(10) would return 10, abs(-10) would also return 10.
  2002.  
  2003.                 Fac - Factorial
  2004.  
  2005.      This function returns the factorial (shriek) value of a number, that is 
  2006. fac(x) returns x*(x-1)*(x-2)*...*2*1. So fac(6) would return 
  2007. 6*5*4*3*2*1=720. If this is passed a non integer, Scrivener automatically 
  2008. strips off the fractional part.
  2009.  
  2010.                 Answer - Last answer recall
  2011.  
  2012.      This function will give an expression access to the result of the last 
  2013. calculation that Scrivener performed. Scrivener performs all its 
  2014. calculations much in the same way as we would read them, left to right and 
  2015. down the page.
  2016.  
  2017.    For instance, if
  2018.  
  2019. [[ 7*5]]        [[ answer-6]]
  2020.  
  2021. were in the file the result would be
  2022.  
  2023. 35              29
  2024.  
  2025.  
  2026.                 Stack - Stack handling
  2027.  
  2028.      This function can push a result onto a stack or it can take a result 
  2029. off the stack, depending on the context of the command. If it is an 
  2030. assignment ie stack=7.35, 7.35 would be pushed onto the stack, whereas 
  2031. result=stack would assign the upper most value of stack to result, then move 
  2032. the stack up one. When stack is used like this, it may be considered as any 
  2033. normal variable.
  2034.  
  2035.                 Lookup - find a member of the stack.
  2036.  
  2037.      With the use of this command it is possible to implement  a lookup 
  2038. table using the stack. If a number of results are pushed on to the stack, 
  2039. they can be looked up by this function, either in the order in which they 
  2040. were put on, or, in the more conventional way, of the last one in considered 
  2041. as the first. For example lookup(1) will find the first member put on the 
  2042. stack (assuming it has not since been removed) whilst lookup(-1) will find 
  2043. the last member put on.
  2044.  
  2045.      If lookup looks beyond the bound of the stack - zero is returned.
  2046.  
  2047.  
  2048.                 Sum - the sum of all members on the stack.
  2049.  
  2050.      This variable is a sum of all the members of the stack and is updated 
  2051. as more things are put on or removed form the stack. This is cleared by the 
  2052. clear command.
  2053.  
  2054.                 Count - the number of members on the stack.
  2055.  
  2056.      This variable holds the number of members on the stack and is 
  2057. incremented as things are put on the stack and decremented as they era 
  2058. removed. This is cleared by the clear command.
  2059.  
  2060.                 Average - the average of a number of members.
  2061.  
  2062.      Average(x) will return the average of the first x members of the stack, 
  2063. average(-x) will return the average of the last x members to be put on the 
  2064. stack. Average(0) will average all the members on the stack.
  2065.      If a number of members is specified which is greater than the number on 
  2066. the stack, the others will be assumed to be zero.
  2067.  
  2068.                 If - conditional
  2069.  
  2070.      This function allows conditional calculations to be made, so if a 
  2071. different calculation has to made dependent on the value of a variable, this 
  2072. should be able to do it. If for instance, discount is given depending on the 
  2073. number of objects bought
  2074.  
  2075. dis=if(and(great(no,100),less(no,1000)),10,5)
  2076.  
  2077. will assign to variable dis the value 10 if variable no is greater than 
  2078. 100,and less than 1000  otherwise it will assign the value 5 to dis. The if 
  2079. statement merely looks to see if its first parameter is non zero, and does 
  2080. the assignments appropriate, the functions and,great and less actually do 
  2081. the comparisons and return non zero or zero according to the conditions.
  2082.  
  2083.  
  2084.                 Round - round a number 
  2085.  
  2086.      This function can round a figure to an appropriate number of decimal 
  2087. places given by its second parameter. If this number is positive, Scrivener 
  2088. rounds to that many decimal places and if it is negative it will round to 
  2089. that many places prior to the decimal point.
  2090.  
  2091. For example
  2092.  
  2093. round(12345.6789,2)
  2094.  
  2095. will give
  2096.  
  2097. 12345.67
  2098.  
  2099. while
  2100.  
  2101. round(12345.6789,-2)
  2102.  
  2103. will give
  2104.  
  2105. 12300
  2106.  
  2107.    To actually round a variable you must reassign it. E.g
  2108.  
  2109. round(x,3)
  2110.  
  2111. will not actually round x to 3 places, but it will make the 
  2112. answer equal to x rounded to 3 decimal places,
  2113.  
  2114. x=round(x,3)
  2115.  
  2116. will, however, round x to 3 places and then reassign that to the 
  2117. variable x.
  2118.  
  2119.                 Comp - two's complement
  2120.  
  2121.      This function will return the two's complement value of the integer 
  2122. passed to it. If not passed an integer, it will strip off the fractional 
  2123. section.
  2124.  
  2125. For example
  2126.  
  2127. x=comp(10)
  2128.  
  2129. will assign to x the value of -11 (the two's complement of 10).
  2130.  
  2131.  
  2132.                 Ran - generate a random number
  2133.  
  2134.      Ran(x,y) will return a decimal value between x and y. If only one 
  2135. parameter is specified, the other is assumed as zero. So ran(5) will return 
  2136. a value between zero and five.
  2137. ran(10,-3) will return a value between -3 and 10.
  2138.  
  2139.  
  2140.  
  2141.  
  2142. 6. Techniques.
  2143.  
  2144.      This section will attempt to cover the techniques of using Scrivener in 
  2145. some way towards its full extent, covering those little tricks which can be 
  2146. used to improve the performance of your source file.
  2147.  
  2148.      The first thing to be aware of is that Scrivener output file can be 
  2149. associated with a physical device such as the console, printer, modem etc. 
  2150. This is done by naming the output file as follows:-
  2151.  
  2152. If you want output to:
  2153.  
  2154. the console use file name con:
  2155. the list device use file name lst:
  2156. the RS232 port use file name pun:
  2157.  
  2158.  
  2159.  
  2160.      This is useful when testing out some of Scrivener functions, or to 
  2161. check if your source file is going to give out exactly what you expect 
  2162. before putting it to disk. The use of con: is especially useful.
  2163.  
  2164.      Equally it is possible to name con: as the input file name, this will 
  2165. then take lines from the keyboard rather than an input file, this allows 
  2166. testing of small sections of Scrivener source.
  2167.  
  2168.  
  2169. Mail Shots.
  2170.  
  2171.      It is possible to use redirection files to allow the use of Scrivener 
  2172. as a mail shot utility in addition to its other functions. A redirection 
  2173. file is specified in the command line (ie when you actually type "Scrivener" 
  2174. to the prompt). This is done by preceding the file name by a "<" (less than) 
  2175. symbol.
  2176.  
  2177. E.G.
  2178.  
  2179. Scrivener <in.fil
  2180.  
  2181. will take all subsequent input from the file called "in.fil". This means 
  2182. that at any point that you have used a #input function, the input will no 
  2183. longer come from the keyboard, but will come from the redirection file. 
  2184.  
  2185. So if we created a file as follows:-
  2186.  
  2187. #input mac_name,,Please enter the customer name
  2188. #input mac_add1,,Please enter the address line 1
  2189. #input mac_add2,,line 2
  2190. #input mac_add3,,line 3
  2191. #input mac_add4,,line 4
  2192. #input mac_add5,,line 5
  2193. #input mac_title,,Enter the title (Sir, Madam etc)
  2194.  
  2195.  
  2196. mac_name
  2197. mac_add1
  2198. mac_add2
  2199. mac_add3
  2200. mac_add4
  2201. mac_add5
  2202.  
  2203. Dear mac_title,
  2204.         Many thanks for your order which we received today, we 
  2205. will send off your goods as soon as possible.
  2206.  
  2207.         Yours sincerely,
  2208.  
  2209.  
  2210.         Mr. M. Director.
  2211.  
  2212. and passed it through Scrivener as normal, everything would occur as we 
  2213. should expect, asking you for the name and address and producing the output 
  2214. file consisting of a standard letter thanking the customer for his order, 
  2215. something along the lines of:-
  2216.  
  2217. Mr. C. Ustomer
  2218. The House
  2219. The Street
  2220. The Town
  2221. The County
  2222. The Postcode
  2223.  
  2224. Dear Sir,
  2225.         Many thanks for your order which we received today, we 
  2226. will send off your goods as soon as possible.
  2227.  
  2228.         Yours sincerely,
  2229.  
  2230.  
  2231.         Mr. M. Director.
  2232.  
  2233. depending upon the input you gave. Using a redirection file, however, we 
  2234. could have Mr. Ustomer's name, address and title held in a separate file so 
  2235. you need only type in
  2236.  
  2237. Scrivener <address.fil
  2238.  
  2239. and the name of the input and output files at the prompt. Scrivener then 
  2240. takes a line of the redirection file to act as each line of input which you 
  2241. would give, so Mr. Ustomer's file would look like:-
  2242.  
  2243. Mr. C. Ustomer
  2244. The House
  2245. The Street
  2246. The Town
  2247. The County
  2248. The Postcode
  2249. Sir
  2250.  
  2251.    The full potential of this feature is only realised when doing a mail 
  2252. shot, which is specified by typing a -m in the command line.
  2253.  
  2254.    Let us assume that the source file given above was called stanlet on the 
  2255. disk and we wanted to mail merge this with a file which contained some 
  2256. names, addresses and titles called address.fil. At the CP/M prompt we would 
  2257. type
  2258.  
  2259. Scrivener -m <address.fil
  2260.  
  2261. and Scrivener would ask for the input file. We would type 
  2262.  
  2263. stanlet
  2264.  
  2265. and then the output file name at the prompt. Scrivener would then 
  2266. churn through the names and addresses an produce a long file of 
  2267. standard letters each with a separate name, address and title 
  2268. given by the redirection file. This can then be split up or 
  2269. printed directly or used in whatever way you wish.
  2270.  
  2271. For example, if address.fil was
  2272.  
  2273. Mr. C. Ustomer
  2274. The House
  2275. The Street
  2276. The Town
  2277. The County
  2278. The Postcode
  2279. Sir
  2280. A.N. Other
  2281. A Different House
  2282. Possibly the same Street
  2283. A town
  2284. And A County
  2285. An all important Postcode
  2286. Anthony
  2287. J.C. Scrivener
  2288. A Flat number, In a block
  2289. In a road
  2290. In a City
  2291. In a county
  2292. With a Postcode
  2293. Sir
  2294.  
  2295. and we used it with the stanlet above we would get a file which 
  2296. would read:-
  2297.  
  2298.  
  2299. Mr. C. Ustomer
  2300. The House
  2301. The Street
  2302. The Town
  2303. The County
  2304. The Postcode
  2305.  
  2306. Dear Sir,
  2307.         Many thanks for your order which we received today, we 
  2308. will send off your goods as soon as possible.
  2309.  
  2310.         Yours sincerely,
  2311.  
  2312.  
  2313.         Mr. M. Director.
  2314.  
  2315.  
  2316.  
  2317. A.N. Other
  2318. A Different House
  2319. Possibly the same Street
  2320. A town
  2321. And A County
  2322. An all important Postcode
  2323.  
  2324. Dear Anthony,
  2325.         Many thanks for your order which we received today, we 
  2326. will send off your goods as soon as possible.
  2327.  
  2328.         Yours sincerely,
  2329.  
  2330.  
  2331.         Mr. M. Director.
  2332.  
  2333.  
  2334.  
  2335. J.C. Scrivener
  2336. A Flat number, In a block
  2337. In a road
  2338. In a City
  2339. In a county
  2340. With a Postcode
  2341.  
  2342. Dear Sir,
  2343.         Many thanks for your order which we received today, we 
  2344. will send off your goods as soon as possible.
  2345.  
  2346.         Yours sincerely,
  2347.  
  2348.  
  2349.         Mr. M. Director.
  2350.  
  2351.    This file can then be printed under your word processor etc.
  2352.  
  2353.    It is possible to mail merge directly from the keyboard, ie not using a 
  2354. redirection file. To do this merely don't use the "<" symbol or redirection 
  2355. file name (still use the -m directive, though). All input will be expected 
  2356. from the keyboard. Once all input has been finished type ^z (control z) 
  2357. before pressing return for the last line.
  2358.  
  2359. Use of #repeat.
  2360.  
  2361.    The #repeat function was described briefly in the macro section of this 
  2362. documentation. It was said that this could only repeat a single line of 
  2363. text. Strictly speaking this is true, but it is not difficult to overcome 
  2364. this. By repeating a line which contains a #include, it is possible to 
  2365. repeatedly include a file which may further consist of text and macro 
  2366. commands (even more repeats and includes). This is useful for calculation 
  2367. based applications. One such example is given here to calculate correlation 
  2368. coefficients for a number of points:-
  2369.  
  2370.  
  2371.  
  2372.  
  2373. #announce Calculating a population correlation coefficient.
  2374.  
  2375.               Population Correlation Coefficients
  2376.               ===================================
  2377.  
  2378.  
  2379. [[def4.0]] [[de This is a comment the def4.0 defines the format as floating point of field 4 ]]
  2380. [[d n=0]] [[de set up number of points as zero]]
  2381.  
  2382.  
  2383. +----------------------------------------------------------------------------+
  2384. |    x           y            x^2              y^2              xy           |
  2385. +----------------------------------------------------------------------------+
  2386. #input mac_number,,Enter the number of points
  2387. #repeat #include correl.fil,,mac_number
  2388. [[d n=mac_number]] [[de number of points]]
  2389. ----------------------------------------------------------------------------
  2390.  
  2391.  [[t   sx ]]    [[t   sy ]]  [[t sxs   ]]    [[t sys    ]]   [[t sxy ]] 
  2392.  
  2393. ===========================================================================
  2394. [[de sx is the sum of all the x co-ordinates]]
  2395. [[de sy the sum of all y co-ordinates]]
  2396. [[de sxs the sum of x squared]]
  2397. [[de sys the sum of y squared]]
  2398. [[de sxy the sum of x*y ]]
  2399.  
  2400. Population coefficient is given by           sum(xy) - sum(x)*sum(y)/n
  2401.                                     -------------------------------------------------
  2402.                                     sqr[((sum(x)^2)-(sum(x)^2)/n))*((sum(y)^2)-((sum(y)^2)/n)]
  2403.  
  2404.  
  2405.                                  =           [[o sxy ]] - [[o a= sx*sy/n]]
  2406.                                     ---------------------------------------
  2407.                                              sqr[ [[o b=sxs-((sx^2)/n)]] * [[o c=sys-((sy^2)/n)]] ]
  2408.  
  2409. [[def5.1]]
  2410.                                  =     [[o a=sxy-a]]
  2411.                                     ------------------ 
  2412.                                        [[o b=(b*c)^0.5 ]]
  2413.  
  2414.  
  2415. [[def5.4]]
  2416.  
  2417.                                  =  [[ a/b   ]]
  2418.  
  2419.  
  2420.  
  2421.  
  2422.      This file is quite straight forward, the first section dealing with 
  2423. producing columns of figures. The initial input statement takes the number 
  2424. of points that we want to correlate. The following statement is a repeated 
  2425. include. This will include the file correl.fil the number of times that is 
  2426. has been asked for. correl.fil looks like this:-
  2427.  
  2428. #input mac_x,,Enter the x co-ordinate
  2429. #input mac_y,,Enter the y co_ordinate
  2430. [[d x=mac_x]] [[d y=mac_y]]
  2431.  [[ x      ]]   [[ y      ]] [[ x^2  ]]      [[ y^2  ]]      [[ x*y  ]] 
  2432.  
  2433. and each time it is repeated, it asks for the x and y co-ordinates and sets 
  2434. up columns of figures ready for the correlation. Care has to be used to 
  2435. ensure that the columns line up with the total requests. All this is 
  2436. included in the file as Scrivener churns through, doing all the calculations 
  2437. at the end of the original file, to calculate the correlation.
  2438.  
  2439. Ultimately it produces an output file like :-
  2440.  
  2441.               Population Correlation Coefficients
  2442.               ===================================
  2443.  
  2444.  
  2445.  
  2446. +----------------------------------------------------------------------------+
  2447. |    x           y            x^2              y^2              xy           |
  2448. +----------------------------------------------------------------------------+
  2449.    10              6          100              36              60       
  2450.     7              4           49              16              28       
  2451.    12              7          144              49              84       
  2452.    12              8          144              64              96       
  2453.     9             10           81             100              90       
  2454.    16              7          256              49             112       
  2455.    12             10          144             100             120       
  2456.    18             15          324             225             270       
  2457.     8              5           64              25              40       
  2458.    12              6          144              36              72       
  2459.    14             11          196             121             154       
  2460.    16             13          256             169             208       
  2461. ----------------------------------------------------------------------------
  2462.  
  2463.   146            102         1902             990            1334       
  2464.  
  2465. ===========================================================================
  2466.  
  2467.  
  2468. Population coefficient is given by           sum(xy) - sum(x)*sum(y)/n
  2469.                                     -------------------------------------------------
  2470.                                     sqr[((sum(x)^2)-(sum(x)^2)/n))*((sum(y)^2)-((sum(y)^2)/n)]
  2471.  
  2472.  
  2473.                                  =           1334 - 1241
  2474.                                     ---------------------------------------
  2475.                                              sqr[  126 *  123 ]
  2476.  
  2477.                                  =      93  
  2478.                                     ------------------ 
  2479.                                        124.3
  2480.  
  2481.  
  2482.  
  2483.                                  =  0.748      
  2484.  
  2485. as you input all the points, and Scrivener does the necessary calculations, 
  2486. and adding up all the totals requested for on the line above the line of 
  2487. ===.
  2488.  
  2489.    This example also illustrates the use of the delete line function for 
  2490. both comments in the source file, for the side working done in the included 
  2491. file and for side working in the main file.
  2492.  
  2493.  
  2494. Macro Names.
  2495.  
  2496.    When setting up names for macros, try (as far as is possible) to use 
  2497. names likely to be unique in the text file (apart from where you want them 
  2498. used). As some examples show in this text, I have a habit of starting my 
  2499. macros with "mac_" (or "scr_" etc. as I find it easier to understand) as I 
  2500. can think of no time when I would use "mac_" to begin a word.
  2501.  
  2502.     Macro names can be more than one word (though the separating space is 
  2503. taken literally and Scrivener looks specifically for that space - not a tab, 
  2504. two spaces or a new line) and using more than one word can be helpful as is
  2505. illustrated under the section about using control characters for setting up 
  2506. a printer.
  2507.  
  2508.  
  2509. Use of #random.
  2510.  
  2511.    The #random function and its syntax is outlined in the macro section, its 
  2512. use, however may need some explanation. 
  2513.  
  2514.    The random function allows the output of the likes of a standard letter 
  2515. to be varied slightly, making each actual letter appear to have been written 
  2516. specifically for the individual concerned. As an example, a thank you letter 
  2517. generator, can be written quite simply under Scrivener, and using this 
  2518. function we can vary the way of actually saying thank you, and using the 
  2519. input function we can add little comments here and there. A sample one would 
  2520. go something like
  2521.  
  2522. #input who_to,,Who is this letter to
  2523. #input from_who,,Who is it from
  2524. #input what_for,,What are you thanking them for
  2525. #input use_for,,What would you use it for
  2526. #input a_comment,,What comment will you make
  2527. #input end_it,,How will you end the letter (Yours sincerely etc.)
  2528.  
  2529. #random thank_1,,thank you for,,many thanks for,,It was kind of you to give me,,How generous it was of you to send me,,I was most pleased with
  2530.  
  2531. Dear who_to,
  2532.         thank_1 what_for that you sent me recently. I will
  2533. use_for a lot. a_comment
  2534.  
  2535.         end_it
  2536.  
  2537.  
  2538.         from_who
  2539.  
  2540. and this will produce a letter with a random way of saying thank you.
  2541.  
  2542.    Obviously this function has many more applications where mailshots need 
  2543. de-mechanization.
  2544.  
  2545. A use of #include.
  2546.  
  2547.      The #input function can be used to influence an '#include' function to 
  2548. great effect, allowing the user to specify an included file which may differ 
  2549. from letter to letter. For example you could set up a library of standard 
  2550. letter headings each of which can be #included into a letter at the run 
  2551. time, setting up the beginning of a letter which looks like:-
  2552.  
  2553. #input file_to_use,,Enter the file which contains the letter heading
  2554. #include file_to_use
  2555.  
  2556.      and this will then allow the person running this letter under Scrivener 
  2557. to specify the letter heading (again, good file names make this function far 
  2558. more natural to use - especially for some third party).
  2559.  
  2560.    It is possible to have
  2561.  
  2562. #include con:
  2563.  
  2564. in your source, and this will (as expected) take input from the keyboard as 
  2565. if it were a file (ending with a control z to return back to the calling 
  2566. file). Equally rdr: could be used to accept input from the RS232 port.
  2567.  
  2568.  
  2569. Producing a neat screen output.
  2570.  
  2571.      The ability to use control characters both inside definitions and 
  2572. inside the names they are recognized by, is particularly useful. One such 
  2573. use for them is to be able to produce neat screen output by embedding screen 
  2574. control characters for your terminal in announce and publish statements. 
  2575. More easily done is to set up a file of definitions which can be #included 
  2576. when writing an application. These would go something like:-
  2577.  
  2578. #define scr_clear,,^z
  2579. #define scr_home,,^~
  2580. #define scr_bs,,^h
  2581.  
  2582. and so on. In a file the author could write
  2583.  
  2584. #announce scr_clearThe screen should now be clear
  2585.  
  2586.    Equally it is possible to have a library of printer control 
  2587. definitions which can replace a printer command with the 
  2588. appropriate characters. So it is possible to set up something 
  2589. like:-
  2590.  
  2591. #define prn_form,,^L
  2592. #define prn_condensed,,^O
  2593. #define prn_condense_off,,^Q
  2594.  
  2595. and then in file typing
  2596.  
  2597. prn_condensed
  2598.  
  2599. will insert the control characters necessary to set up condensed 
  2600. mode (for an Epson printer) when this is sent to the printer. It 
  2601. is a good idea if setting up a letter to be used with mail merge, 
  2602. to end the letter with a form feed, then the output file can be 
  2603. sent immediately (or using prn: as the output file) with the 
  2604. printer form feeding after each letter.
  2605.  
  2606.    An interesting form of this, is to set up your library along 
  2607. the lines of:-
  2608.  
  2609. #define condensed on,,^O
  2610. #define condensed off,,^Q
  2611. #define elite on,,^[M
  2612. #define elite off,,^[!0
  2613.  
  2614. and so on (though be careful that your source does not contain 
  2615. these names where you don't want them - such is the advantage of 
  2616. using uncommon macro names). Then in the source you can have
  2617.  
  2618. #input p_type,,What printer feature do you want
  2619. p_type
  2620.  
  2621. and at run time, typing "condensed on" to the prompt will replace 
  2622. p_type with the control characters needed (ie control O). Using  
  2623. this effect as well as using the ^^ to obtain a single ^ in 
  2624. a macro can have unforeseen effects and is best avoided if 
  2625. possible.
  2626.  
  2627.    One thing to be careful of is the use of control z, this is 
  2628. recognized as an end of file marker and can cause problems if put 
  2629. in files.
  2630.  
  2631.  
  2632. Using control characters in definitions.
  2633.  
  2634.    It is quite possible to use control character sequences in both 
  2635. definitions and names. 
  2636.  
  2637.    The use of control characters in names can be used for 
  2638. removing control characters etc. or for making them show up more 
  2639. clearly for typesetting applications (as one example).
  2640.  
  2641.    As an illustration (for all you typesetters out there) this 
  2642. Scrivener source file would ask you for the file you want tabs 
  2643. replaced in and what character (or characters) you wish it 
  2644. replaced by. This will produce, in your specified output file, a 
  2645. copy of your named file with all the tabs replaced by the 
  2646. appropriate characters.
  2647.  
  2648. #input mac_file,,Which file need its tabs replaced
  2649. #input mac_tab,,What character(s) do you wish tab replaced by
  2650. #define ^I,,mac_tab
  2651. #include mac_file
  2652.  
  2653.    This illustrates another point about definitions of macros, 
  2654. that is, that the definition is always checked to see if it 
  2655. contains previously defined macros and they are replaced before 
  2656. the definition is made. 
  2657.  
  2658.  
  2659. Long calculations.
  2660.  
  2661.    It is quite likely that some calculations may be far longer 
  2662. than would be liked and will not fit into columns easily (and not 
  2663. without having to leave huge spaces in between the columns). Use 
  2664. of booleans and conditionals are especially prone to this.
  2665.  
  2666.    The easiest way around this is to have the calculation 
  2667. performed on a deleted line, assign the result to a short 
  2668. variable and use that in your columns, e.g.
  2669.  
  2670. [[ rebate=if(and(less(tax,50),greater(tax,10)),7,0)]]
  2671.  
  2672. can be more conveniently written as
  2673.  
  2674. [[d rebate=if(and(less(tax,50),greater(tax,10)),7,0)]]
  2675. [[ rebate]]
  2676.  
  2677. as in the final output file the upper line will be deleted and 
  2678. the resultant lower line is much smaller and easier to put into 
  2679. columns.
  2680.  
  2681. Generating an integral random number.
  2682.  
  2683.    Using the ran and round functions it is easy to generate an 
  2684. integral random number. For instance
  2685.  
  2686. [[ round(ran(3,18),0)]]
  2687.  
  2688. will give an integer between 3 and 18.
  2689.  
  2690. A calculator in Scrivener.
  2691.  
  2692.    A simple two line Scrivener source will turn it into a 
  2693. calculator which will do all the basic functions of the 
  2694. calculator (though not stack or variable use).
  2695.  
  2696. #input mac_calc,,^j^j^jWhat do you wish calculated
  2697. [[dp mac_calc = ,,mac_calc,, ]]
  2698.  
  2699. is the simple program needed and if combined with mail merge you 
  2700. can do repeated calculations until ^Z is typed.
  2701.  
  2702. The accuracy of the expression analyser.
  2703.  
  2704.      The expression analyser uses floating point numbers (using 64 bits in 
  2705. standard I.E.E.E. format), and as such, is prone to slight inaccuracies when 
  2706. calculations to large numbers of decimal places are attempted. This package 
  2707. is to be accurate to  10 places (or 0.01 pence in a million pounds). 
  2708. truncation errors will obviously occur if large divisions are made and then 
  2709. the result multiplied back up.
  2710.  
  2711. unusual forms of calculations.
  2712.  
  2713.      The calculator section of Scrivener is remarkably powerful, albeit 
  2714. using a floating point package. It allows assignments of variables inside 
  2715. brackets in some very unusual positions. For example:-
  2716.  
  2717. b=(c=10)+(d=9/(e=5-2))
  2718.  
  2719. will set up e=3 (5-2)
  2720.             d=3 (9/e)
  2721.             c=10
  2722. and         b=13 (10+d)
  2723.  
  2724.     This can lead to a valuable, if confusing at first, 
  2725. shorthand, especially in connection with a conditional statement.
  2726.  
  2727.    Rather than having to set up each calculation individually and then apply 
  2728. a conditional i.e.:-
  2729.  
  2730. [[ code1=7]] [[ code2=8]]
  2731. [[ code=if(equal(tax,9),code1,code2)]]
  2732.  
  2733. which sets code1 to 7, code2 to 8, and will set code to code1 if tax is 9 or 
  2734. code2 if it isn't,
  2735.  
  2736. [[ code=if(equal(tax,9),(code1=7),(code2=8))]]
  2737.  
  2738. will do exactly the same thing.
  2739.  
  2740.  
  2741. The use of the '^' symbol.
  2742.  
  2743.    The '^', as has previously been said, can be used to insert control 
  2744. characters into definitions, names, announce lines, calculator print lines 
  2745. etc.. In general, using the '^' symbol results in the next character being 
  2746. turned into a control character, E.g. ^A would be replaced with ASCII 1 ^B 
  2747. with ASCII 2 etc.
  2748.  
  2749.    There are, however, a few exceptions to this rule. A '^^' will give a 
  2750. single '^' on output (to obtain the ASCII character 30 use ^~). Using '^@' 
  2751. will merely give an '@' symbol as ASCII 0 is an en of line marker and can 
  2752. cause problems. The '^]' will give a ']', this allows output of a Scrivener 
  2753. file to contain Scrivener commands, which can be used at a later date by 
  2754. Scrivener.
  2755.  
  2756. E.g.
  2757.  
  2758. [[p [[ 12*5 ^]^] is the result of 12*5 ]]
  2759.  
  2760. will cause an output to the screen (or redirection file with the M - mail to 
  2761. file command) which would be:-
  2762.  
  2763. [[ 12*5]] is the result of 12*5
  2764.  
  2765. As this has set up the correct brackets ( with the sneaky use of the control 
  2766. characters ), this can then be passed through Scrivener again for other 
  2767. functions.
  2768.  
  2769.  
  2770. 7. Worked Examples.
  2771.  
  2772. A fictitious invoice generator.
  2773.  
  2774.    This invoice generator, will adequately cope with handling small 
  2775. invoices, using an easily changeable look up table of prices. It is more 
  2776. convenient to have the lookup table #included at the beginning of a file. 
  2777. The main source would look like
  2778.  
  2779. #include price.fil
  2780. #include names
  2781. #input h_file,,Which file contains your business header
  2782. #include h_file
  2783. mac_name
  2784. mac_add1
  2785. mac_add2
  2786. mac_add3
  2787. mac_add4
  2788. mac_add5
  2789.  
  2790. [[def 4.2t]]
  2791. Invoice for:-
  2792.  
  2793. Items           Description             cost/item               sub-total
  2794.  
  2795. #input mac_items,,Please Enter the number of Boogle flips
  2796. [[d no=mac_items]]
  2797. [[ no]]         Boogle flips            [[ c= lookup(1)]]       [[z no*c]]
  2798. #input mac_items,,Please Enter the number of Grobel brendels
  2799. [[d no=mac_items]]
  2800. [[ no]]         Grobel brendels         [[ c=lookup(2)]]        [[z no*c]]
  2801. #input mac_items,,Please Enter the number of Farent Zotrons
  2802. [[d no=mac_items]]
  2803. [[ no]]         Farent Zotrons          [[ c=lookup(3)]]        [[z no*c]]
  2804.  
  2805.  
  2806. sub-total                                                       [[t stotal]]
  2807.  
  2808. vat                                                             [[ tax=stotal*0.15]]
  2809.  
  2810. Total                                                           [[ stotal+tax]]
  2811.  
  2812.  
  2813.  
  2814. note that all the lines will be deleted with the z - delete if zero - 
  2815. function if no items are required. The files which are #included at the 
  2816. beginning are the file of prices which would look like:-
  2817.  
  2818. #announce ^m^j^jIncluding price list
  2819. [[d stack=2.50]] [[de cost of boogle flips]]
  2820. [[d stack=3.80]] [[de cost of Grobel brendels]]
  2821. [[d stack=0.80]] [[de cost of Farent Zotrons]]
  2822. [[d stack=0.50]]
  2823. [[d stack=1.45]]
  2824. [[d stack=9.95]]
  2825. [[d stack=6.95]]
  2826. [[d stack=6.5]]
  2827.  
  2828. and a file of questions to ask for customer name and address. This is 
  2829. generally a good idea, as they can be #included in many source texts, 
  2830. without having to be re-typed each time. These would look something like:-
  2831.  
  2832. #input mac_name,,Enter Customer Name
  2833. #input mac_add1,,Enter the address (5 lines)
  2834. #input mac_add2,, 
  2835. #input mac_add3,, 
  2836. #input mac_add4,, 
  2837. #input mac_add5,, 
  2838.  
  2839. the other include asks the user to type in the business header, again a good 
  2840. idea, so that different headers can be used, without recourse to changing 
  2841. the original source (this ability is essential when handling standard 
  2842. letters).
  2843.  
  2844. A.R.M.C.  A.S.
  2845. (c) MML Systems Ltd    1985 1986
  2846.