home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 4 / AACD04.ISO / AACD / Programming / CanDo / Decks3 / LogBook / LogDeck.doc < prev    next >
Encoding:
Text File  |  1994-04-28  |  10.2 KB  |  357 lines

  1. CAR LOG BOOK
  2. BY GREG ABERNETHY OF RUSH SOFTWARE, WOLLONGONG
  3.  
  4. Based on a tutorial published in Australian Commodore and Amiga Review,
  5. 1993. Greg writes a monthly column with CanDo tutorials and tips in ACAR.
  6. This was the 21st tutorial, so there is now a very substantial resource on
  7. CanDo techniques there. Contact ACAR on Sydney (02) 298 5111 or talk to the
  8. editor, Andrew Farrell on (02) 879 7455, about back numbers and
  9. subscriptions.
  10.  
  11. INTRODUCTION
  12.  
  13. This computerised log book, enables the user to keep records of distance
  14. travelled in his/her car/s.  Also a printout can be obtained of the log
  15. book at any time.  This is useful for taxation purposes.  The idea for this
  16. tutorial was given to me by Gary Simmonds of Gateshead West.  I would like
  17. to thank Gary for the idea, and for several other ideas that may appear in
  18. future tutorials.
  19.  
  20. The program will consist of one card with a document for displaying the log
  21. book entries, some fields for entering data, and buttons for loading and
  22. saving log books.  I have not included any fancy features, such as a print
  23. requester or a custom file requester.  It would greatly enhance the program
  24. to add these features.
  25.  
  26. CREATING THE LOG BOOK PAGE
  27.  
  28. WINDOW SPECIFICATIONS
  29.  
  30. WINDOW TITLE "CanDo Log Book...."
  31. WINDOW SIZE    X  = 640: Y = 256 4 COLOURS
  32. VISIBLE BORDERS
  33. ALWAYS OPEN ON OWN SCREEN
  34. CLOSE GADGET:WINDOW BACK/FRONT GADGET:WINDOW DRAG GADGET
  35.  
  36. CLOSE GADGET SCRIPT
  37. Quit
  38.  
  39. BEFOREATTACHMENT SCRIPT
  40. If Not Exists(TheCurrentDirectory||"LogBooks")       
  41.     Dos "c:makedir"|||TheCurrentDirectory||"LogBooks"
  42. EndIf
  43.  
  44. Explanation
  45. This script will examine the current directory, where the application is
  46. located, and look for a directory call "LogBooks".  If the directory
  47. doesn't exist it will use the "Dos" command to create a directory for
  48. holding the log book files.  In this way it is irrelevant where the
  49. application is located as there will always be a directory created to use
  50. as a default location for loading and saving the log books.  This is
  51. especially useful for applications that are hard disk installable, as it is
  52. only necessary to create a drawer on the hard drive, drag the application
  53. into the drawer and the application can then create its own directories
  54. necessary for file control.  This saves the user the need to create
  55. directories or have to assign the application to specific locations.
  56.  
  57. AFTERATTACHMENT SCRIPT
  58. SetPrintFont "topaz",8
  59. SetPrintStyle OUTLINE ,1,3
  60. SetPen 2,0
  61. SetDrawMode JAM1
  62. PrintText "Trip",16,156
  63. PrintText "Start Date",16,170
  64. PrintText "End Date",16,186
  65. PrintText "Purpose",16,202
  66. PrintText "Odometer Start",16,218
  67. PrintText "Odometer End",16,234
  68. PrintText "Dist. Travelled",289,218
  69. PrintText "Total Dist. to Date",480,218
  70. SetObjectState ".DStart",ON
  71. Dispose Log
  72. Let Index = 1
  73. DrawBorder 316,157,315,56,DOUBLEBEVEL ,2,1
  74. Let Heading = " St. Date  End Date  Purpose                 O. Begin
  75.   O. End     Distance  " ; this line has been split to fit the page
  76.  
  77. Explanation
  78. This script writes text labels in the window, disposes the "Log" variable,
  79. sets the Databse Index to one, and sets the Heading text for the Log Book
  80. display document.
  81.  
  82. LOG BOOK DISPLAY DOCUMENT SPECIFICATIONS
  83.  
  84. OBJECT NAME    "LogDoc"
  85. DOCUMENT NAME  "Log"
  86. ORIGIN X = 9: Y = 14
  87. SIZE X = 623: Y = 136
  88. BORDER = DOUBLEBEVEL
  89. LIST DOCUMENT
  90.  
  91. Release Script
  92. If TrimString(TheLine) <> "" and TheLineNumber > 2
  93.     Let Index = TheLineNumber - 2
  94.     Do "Display"
  95.     PositionOnLine Index + 2
  96. EndIf
  97.  
  98. Explanation
  99. When the document is clicked, I check to see if the line number selected is
  100. greater than two, as the header text and a blank line take the first two
  101. lines of the document.  If the user has clicked on a log book entry and not
  102. a blank line, The Index variable is set to the line number - 2, as the
  103. first entry is actually on the third line of the document.  The information
  104. for that entry is then displayed in the fields.
  105.  
  106. DATABASE FIELDS SPECIFICATIONS
  107.  
  108. The Fields for entering and displaying entries are;
  109.  
  110. StartDate Field - Starting Date of Trip
  111.  
  112. FIELD NAME    ".DStart"
  113. ORIGIN        Horiz = 110 : Vert = 170 : Width = 80
  114. TEXT 10 Characters
  115. BORDER = DOUBLEBEVEL : RIGHT JUSTIFICATION
  116.  
  117. Return Script
  118. SetObjectState ".DEnd",ON
  119.  
  120. EndDate Field - Finishing Date of Trip
  121.  
  122. FIELD NAME    ".DEnd"
  123. ORIGIN        Horiz = 110 : Vert = 186 : Width = 80
  124. TEXT 10 Characters
  125. BORDER = DOUBLEBEVEL : RIGHT JUSTIFICATION
  126.  
  127. Return Script
  128. SetObjectState ".Purpose",ON
  129.  
  130. Purpose Field - The purpose of the journey
  131.  
  132. FIELD NAME    ".Purpose"
  133. ORIGIN        Horiz = 110 : Vert = 202 : Width = 192
  134. TEXT 24 Characters
  135. BORDER = DOUBLEBEVEL : LEFT JUSTIFICATION
  136.  
  137. Return Script
  138. SetObjectState ".OStart",ON
  139.  
  140. Odometer Start Field - initial speedo reading
  141.  
  142. FIELD NAME    ".OStart"
  143. ORIGIN        Horiz = 150 : Vert = 218 : Width = 80
  144. TEXT 10 Characters
  145. BORDER = DOUBLEBEVEL : RIGHT JUSTIFICATION
  146.  
  147. Return Script
  148. SetObjectState ".OEnd",ON
  149.  
  150. Odometer End Field - final speedo reading
  151.  
  152. FIELD NAME    ".OEnd"
  153. ORIGIN        Horiz = 150 : Vert = 234 : Width = 80
  154. TEXT 10 Characters
  155. BORDER = DOUBLEBEVEL : RIGHT JUSTIFICATION
  156.  
  157. Return Script
  158. Let a = TrimString(TextFrom(".OEnd"))
  159. Let b = TrimString(TextFrom(".OStart"))
  160. SetText ".Dist",Absolute(a - b)
  161. SetObjectState ".DStart",ON
  162.  
  163. Explanation
  164. This script works out the actual distance travelled and displays it in the
  165. "Total Distance Travelled" field.  I have not used INTEGER fields for the
  166. database as I find that the need to have an initial number displayed in the
  167. field is annoying, as you must delete this number before entering your
  168. number.  I find it easier to use TEXT fields and then interpret the
  169. information entered.
  170.  
  171. Total Distance Travelled Field - total distance for this trip
  172.  
  173. FIELD NAME    ".Dist"
  174. ORIGIN        Horiz = 312 : Vert = 234 : Width = 80
  175. TEXT 10 Characters
  176. BORDER = DOUBLEBEVEL : RIGHT JUSTIFICATION
  177.  
  178. No Return Script
  179.  
  180. Overall Distance Travelled Field - total distance for LOG BOOK
  181.  
  182. FIELD NAME    "TDist"
  183. ORIGIN        Horiz = 516 : Vert = 234 : Width = 80
  184. TEXT 10 Characters
  185. BORDER = DOUBLEBEVEL : RIGHT JUSTIFICATION
  186.  
  187. No Return Script
  188.  
  189. Note that this field does not begin with a fullstop and is therefore not a
  190. database field object.  This is because it is not necessary to have this
  191. information in the database as it is calculated in a routine and then
  192. displayed.
  193.  
  194. SPECIFICATIONS FOR LOG BOOK FUNCTION BUTTONS
  195.  
  196. LOAD LOG BOOK Button
  197.  
  198. BUTTON NAME     "Load"
  199. ORIGIN       Horiz = 327: Vert = 160
  200. BORDER = SHADOW : HIGHLIGHT = COMPLEMENT
  201. TEXT =  "Load LOG BOOK"
  202.  
  203. Release Script
  204. Let File = AskForFileName(TheCurrentDirectory||"LogBooks/",
  205. "Select LOGBOOK to LOAD..",173,62)
  206. If FileOf(File) <> ""
  207.     Let CurrFile = File
  208.     Dispose Log
  209.     Let Log = LoadVariable(CurrFile)
  210.     Let Index = 1
  211.     Do "Display"
  212. EndIf
  213.  
  214. Explanation
  215. I use the standard CanDo requester to ask the user to select a LOG BOOK to
  216. load.  Note that I have defaulted the directory location to the "LogBooks"
  217. directory in the application directory.  If they select a file, it is
  218. loaded and displayed.
  219.  
  220. SAVE LOG BOOK Button
  221.  
  222. BUTTON NAME     "Save"
  223. ORIGIN       Horiz = 494: Vert = 160
  224. BORDER = SHADOW : HIGHLIGHT = COMPLEMENT
  225. TEXT =  "Save LOG BOOK"
  226.  
  227. Release Script
  228. If CurrFile  = ""
  229.     Let File = AskForFileName(TheCurrentDirectory||"LogBooks/",
  230.     "Enter NAME of  LOGBOOK to SAVE..",173,62)
  231.     If FileOf(File) <> ""
  232.         Let CurrFile = File
  233.         SaveVariable Log,CurrFile
  234.     EndIf
  235. Else
  236.     SaveVariable Log,CurrFile
  237. EndIf
  238.  
  239. Explanation
  240. If the Log Book has not been previously saved I use the standard CanDo
  241. requester to ask the user to enter a name for the LOG BOOK to save.  If the
  242. Log Book was previously saved, I use the filename of the log book when
  243. saving the log book.  The filename is contained in the CurrFile variable.
  244.  
  245. ADD ENTRY Button
  246.  
  247. BUTTON NAME     "Add"
  248. ORIGIN       Horiz = 338: Vert = 180
  249. BORDER = SHADOW : HIGHLIGHT = COMPLEMENT
  250. TEXT =  " Add Entry "
  251.  
  252. Release Script
  253.  
  254. Let Log[Index] = GetDBObjects
  255. Let Index = Index + 1
  256. InsertArrayEntry Log,Index
  257. Do "Display"
  258.  
  259. Explanation
  260. When an entry is added, I get the currently displayed entry, increment the
  261. index and insert a blank entry into the database and then display the blank
  262. entry.
  263.  
  264. DELETE ENTRY Button
  265.  
  266. BUTTON NAME     "Delete"
  267. ORIGIN       Horiz = 457: Vert = 180
  268. BORDER = SHADOW : HIGHLIGHT = COMPLEMENT
  269. TEXT =  " Delete This Entry "
  270.  
  271. Release Script
  272.  
  273. DeleteArrayEntry Log,Index
  274. Do "Display"
  275.  
  276. Explanation
  277. When an entry is deleted, I delete the currently displayed entry, and then
  278. display the previous entry.
  279.  
  280. PRINT LOG BOOK Button
  281.  
  282. BUTTON NAME     "Print"
  283. ORIGIN       Horiz = 409: Vert = 198
  284. BORDER = SHADOW : HIGHLIGHT = COMPLEMENT
  285. TEXT =  " Print Log Book "
  286.  
  287. Release Script
  288.  
  289. MakeDocument "Temp"
  290. WorkWithDocument "Temp"
  291. InsertDocument "Log"
  292. MoveCursorTo STARTOF DOCUMENT 
  293. If CurrFile = ""
  294.     Type CenterString("LOG BOOK DETAILS FOR Untitled",74)
  295. Else
  296.     Type CenterString("LOG BOOK DETAILS FOR"|||FileOf(CurrFile),74)
  297. EndIf
  298. SplitLine
  299. SplitLine
  300. MoveCursorTo ENDOF DOCUMENT 
  301. NewLine
  302. NewLine
  303. Type RightJustify("Total Distance Travelled "|||TDist,74)
  304. NewLine
  305. NewLine
  306. SaveDocument "Temp","PRT:"
  307. IfError
  308.  nop ; some print error routines required here
  309. EndIf
  310. Flush "Temp"
  311.  
  312. Explanation
  313.  
  314. This script copies the log book document into a spare document, adds a
  315. title and enters the overall distance at the bottom.  It is then sent to
  316. the printer.  Note that some type of printer error routines are required,
  317. for checking that the printer is on and ready.
  318.  
  319. GLOBAL ROUTINE "Display"
  320.  
  321. Script
  322.  
  323. SetDBObjects Log[Index]
  324. SetObjectState ".DStart",ON
  325. WorkWithDocument "Log"
  326. Clear DOCUMENT 
  327. Type Heading,NEWLINE 
  328. NewLine
  329. Let TDist = 0
  330. Let n = NumberOfArrayEntries(Log)
  331. If n > 0
  332.     Let x = 0
  333.     Loop
  334.         Let x = x + 1
  335.         Type RightJustify(Log[x].DStart,10)
  336.         Type RightJustify(Log[x].DEnd,10)
  337.         Type LeftJustify(" "||Log[x].Purpose,23)
  338.         Type RightJustify(Log[x].OStart,10)
  339.         Type RightJustify(Log[x].OEnd,10)
  340.         Type RightJustify(Log[x].Dist,10)
  341.         Let TDist = TDist + Log[x].Dist
  342.         NewLine
  343.     Until x = n
  344.     Delete CHARACTER ,-1
  345. EndIf
  346. SetText "TDist",TDist
  347.  
  348. Explanation
  349. This routine handles displaying the log book entries in the document,
  350. setting the selected entry into the database fields and calculating the
  351. overall distance travelled.
  352.  
  353. FINAL WORDS
  354. The computerised log book has been designed from a log book that complies
  355. with the Australian Taxation Office Substantiation Requirements with the
  356. exception of the signature and name entry sections.
  357.