home *** CD-ROM | disk | FTP | other *** search
- CAR LOG BOOK
- BY GREG ABERNETHY OF RUSH SOFTWARE, WOLLONGONG
-
- Based on a tutorial published in Australian Commodore and Amiga Review,
- 1993. Greg writes a monthly column with CanDo tutorials and tips in ACAR.
- This was the 21st tutorial, so there is now a very substantial resource on
- CanDo techniques there. Contact ACAR on Sydney (02) 298 5111 or talk to the
- editor, Andrew Farrell on (02) 879 7455, about back numbers and
- subscriptions.
-
- INTRODUCTION
-
- This computerised log book, enables the user to keep records of distance
- travelled in his/her car/s. Also a printout can be obtained of the log
- book at any time. This is useful for taxation purposes. The idea for this
- tutorial was given to me by Gary Simmonds of Gateshead West. I would like
- to thank Gary for the idea, and for several other ideas that may appear in
- future tutorials.
-
- The program will consist of one card with a document for displaying the log
- book entries, some fields for entering data, and buttons for loading and
- saving log books. I have not included any fancy features, such as a print
- requester or a custom file requester. It would greatly enhance the program
- to add these features.
-
- CREATING THE LOG BOOK PAGE
-
- WINDOW SPECIFICATIONS
-
- WINDOW TITLE "CanDo Log Book...."
- WINDOW SIZE X = 640: Y = 256 4 COLOURS
- VISIBLE BORDERS
- ALWAYS OPEN ON OWN SCREEN
- CLOSE GADGET:WINDOW BACK/FRONT GADGET:WINDOW DRAG GADGET
-
- CLOSE GADGET SCRIPT
- Quit
-
- BEFOREATTACHMENT SCRIPT
- If Not Exists(TheCurrentDirectory||"LogBooks")
- Dos "c:makedir"|||TheCurrentDirectory||"LogBooks"
- EndIf
-
- Explanation
- This script will examine the current directory, where the application is
- located, and look for a directory call "LogBooks". If the directory
- doesn't exist it will use the "Dos" command to create a directory for
- holding the log book files. In this way it is irrelevant where the
- application is located as there will always be a directory created to use
- as a default location for loading and saving the log books. This is
- especially useful for applications that are hard disk installable, as it is
- only necessary to create a drawer on the hard drive, drag the application
- into the drawer and the application can then create its own directories
- necessary for file control. This saves the user the need to create
- directories or have to assign the application to specific locations.
-
- AFTERATTACHMENT SCRIPT
- SetPrintFont "topaz",8
- SetPrintStyle OUTLINE ,1,3
- SetPen 2,0
- SetDrawMode JAM1
- PrintText "Trip",16,156
- PrintText "Start Date",16,170
- PrintText "End Date",16,186
- PrintText "Purpose",16,202
- PrintText "Odometer Start",16,218
- PrintText "Odometer End",16,234
- PrintText "Dist. Travelled",289,218
- PrintText "Total Dist. to Date",480,218
- SetObjectState ".DStart",ON
- Dispose Log
- Let Index = 1
- DrawBorder 316,157,315,56,DOUBLEBEVEL ,2,1
- Let Heading = " St. Date End Date Purpose O. Begin
- O. End Distance " ; this line has been split to fit the page
-
- Explanation
- This script writes text labels in the window, disposes the "Log" variable,
- sets the Databse Index to one, and sets the Heading text for the Log Book
- display document.
-
- LOG BOOK DISPLAY DOCUMENT SPECIFICATIONS
-
- OBJECT NAME "LogDoc"
- DOCUMENT NAME "Log"
- ORIGIN X = 9: Y = 14
- SIZE X = 623: Y = 136
- BORDER = DOUBLEBEVEL
- LIST DOCUMENT
-
- Release Script
- If TrimString(TheLine) <> "" and TheLineNumber > 2
- Let Index = TheLineNumber - 2
- Do "Display"
- PositionOnLine Index + 2
- EndIf
-
- Explanation
- When the document is clicked, I check to see if the line number selected is
- greater than two, as the header text and a blank line take the first two
- lines of the document. If the user has clicked on a log book entry and not
- a blank line, The Index variable is set to the line number - 2, as the
- first entry is actually on the third line of the document. The information
- for that entry is then displayed in the fields.
-
- DATABASE FIELDS SPECIFICATIONS
-
- The Fields for entering and displaying entries are;
-
- StartDate Field - Starting Date of Trip
-
- FIELD NAME ".DStart"
- ORIGIN Horiz = 110 : Vert = 170 : Width = 80
- TEXT 10 Characters
- BORDER = DOUBLEBEVEL : RIGHT JUSTIFICATION
-
- Return Script
- SetObjectState ".DEnd",ON
-
- EndDate Field - Finishing Date of Trip
-
- FIELD NAME ".DEnd"
- ORIGIN Horiz = 110 : Vert = 186 : Width = 80
- TEXT 10 Characters
- BORDER = DOUBLEBEVEL : RIGHT JUSTIFICATION
-
- Return Script
- SetObjectState ".Purpose",ON
-
- Purpose Field - The purpose of the journey
-
- FIELD NAME ".Purpose"
- ORIGIN Horiz = 110 : Vert = 202 : Width = 192
- TEXT 24 Characters
- BORDER = DOUBLEBEVEL : LEFT JUSTIFICATION
-
- Return Script
- SetObjectState ".OStart",ON
-
- Odometer Start Field - initial speedo reading
-
- FIELD NAME ".OStart"
- ORIGIN Horiz = 150 : Vert = 218 : Width = 80
- TEXT 10 Characters
- BORDER = DOUBLEBEVEL : RIGHT JUSTIFICATION
-
- Return Script
- SetObjectState ".OEnd",ON
-
- Odometer End Field - final speedo reading
-
- FIELD NAME ".OEnd"
- ORIGIN Horiz = 150 : Vert = 234 : Width = 80
- TEXT 10 Characters
- BORDER = DOUBLEBEVEL : RIGHT JUSTIFICATION
-
- Return Script
- Let a = TrimString(TextFrom(".OEnd"))
- Let b = TrimString(TextFrom(".OStart"))
- SetText ".Dist",Absolute(a - b)
- SetObjectState ".DStart",ON
-
- Explanation
- This script works out the actual distance travelled and displays it in the
- "Total Distance Travelled" field. I have not used INTEGER fields for the
- database as I find that the need to have an initial number displayed in the
- field is annoying, as you must delete this number before entering your
- number. I find it easier to use TEXT fields and then interpret the
- information entered.
-
- Total Distance Travelled Field - total distance for this trip
-
- FIELD NAME ".Dist"
- ORIGIN Horiz = 312 : Vert = 234 : Width = 80
- TEXT 10 Characters
- BORDER = DOUBLEBEVEL : RIGHT JUSTIFICATION
-
- No Return Script
-
- Overall Distance Travelled Field - total distance for LOG BOOK
-
- FIELD NAME "TDist"
- ORIGIN Horiz = 516 : Vert = 234 : Width = 80
- TEXT 10 Characters
- BORDER = DOUBLEBEVEL : RIGHT JUSTIFICATION
-
- No Return Script
-
- Note that this field does not begin with a fullstop and is therefore not a
- database field object. This is because it is not necessary to have this
- information in the database as it is calculated in a routine and then
- displayed.
-
- SPECIFICATIONS FOR LOG BOOK FUNCTION BUTTONS
-
- LOAD LOG BOOK Button
-
- BUTTON NAME "Load"
- ORIGIN Horiz = 327: Vert = 160
- BORDER = SHADOW : HIGHLIGHT = COMPLEMENT
- TEXT = "Load LOG BOOK"
-
- Release Script
- Let File = AskForFileName(TheCurrentDirectory||"LogBooks/",
- "Select LOGBOOK to LOAD..",173,62)
- If FileOf(File) <> ""
- Let CurrFile = File
- Dispose Log
- Let Log = LoadVariable(CurrFile)
- Let Index = 1
- Do "Display"
- EndIf
-
- Explanation
- I use the standard CanDo requester to ask the user to select a LOG BOOK to
- load. Note that I have defaulted the directory location to the "LogBooks"
- directory in the application directory. If they select a file, it is
- loaded and displayed.
-
- SAVE LOG BOOK Button
-
- BUTTON NAME "Save"
- ORIGIN Horiz = 494: Vert = 160
- BORDER = SHADOW : HIGHLIGHT = COMPLEMENT
- TEXT = "Save LOG BOOK"
-
- Release Script
- If CurrFile = ""
- Let File = AskForFileName(TheCurrentDirectory||"LogBooks/",
- "Enter NAME of LOGBOOK to SAVE..",173,62)
- If FileOf(File) <> ""
- Let CurrFile = File
- SaveVariable Log,CurrFile
- EndIf
- Else
- SaveVariable Log,CurrFile
- EndIf
-
- Explanation
- If the Log Book has not been previously saved I use the standard CanDo
- requester to ask the user to enter a name for the LOG BOOK to save. If the
- Log Book was previously saved, I use the filename of the log book when
- saving the log book. The filename is contained in the CurrFile variable.
-
- ADD ENTRY Button
-
- BUTTON NAME "Add"
- ORIGIN Horiz = 338: Vert = 180
- BORDER = SHADOW : HIGHLIGHT = COMPLEMENT
- TEXT = " Add Entry "
-
- Release Script
-
- Let Log[Index] = GetDBObjects
- Let Index = Index + 1
- InsertArrayEntry Log,Index
- Do "Display"
-
- Explanation
- When an entry is added, I get the currently displayed entry, increment the
- index and insert a blank entry into the database and then display the blank
- entry.
-
- DELETE ENTRY Button
-
- BUTTON NAME "Delete"
- ORIGIN Horiz = 457: Vert = 180
- BORDER = SHADOW : HIGHLIGHT = COMPLEMENT
- TEXT = " Delete This Entry "
-
- Release Script
-
- DeleteArrayEntry Log,Index
- Do "Display"
-
- Explanation
- When an entry is deleted, I delete the currently displayed entry, and then
- display the previous entry.
-
- PRINT LOG BOOK Button
-
- BUTTON NAME "Print"
- ORIGIN Horiz = 409: Vert = 198
- BORDER = SHADOW : HIGHLIGHT = COMPLEMENT
- TEXT = " Print Log Book "
-
- Release Script
-
- MakeDocument "Temp"
- WorkWithDocument "Temp"
- InsertDocument "Log"
- MoveCursorTo STARTOF DOCUMENT
- If CurrFile = ""
- Type CenterString("LOG BOOK DETAILS FOR Untitled",74)
- Else
- Type CenterString("LOG BOOK DETAILS FOR"|||FileOf(CurrFile),74)
- EndIf
- SplitLine
- SplitLine
- MoveCursorTo ENDOF DOCUMENT
- NewLine
- NewLine
- Type RightJustify("Total Distance Travelled "|||TDist,74)
- NewLine
- NewLine
- SaveDocument "Temp","PRT:"
- IfError
- nop ; some print error routines required here
- EndIf
- Flush "Temp"
-
- Explanation
-
- This script copies the log book document into a spare document, adds a
- title and enters the overall distance at the bottom. It is then sent to
- the printer. Note that some type of printer error routines are required,
- for checking that the printer is on and ready.
-
- GLOBAL ROUTINE "Display"
-
- Script
-
- SetDBObjects Log[Index]
- SetObjectState ".DStart",ON
- WorkWithDocument "Log"
- Clear DOCUMENT
- Type Heading,NEWLINE
- NewLine
- Let TDist = 0
- Let n = NumberOfArrayEntries(Log)
- If n > 0
- Let x = 0
- Loop
- Let x = x + 1
- Type RightJustify(Log[x].DStart,10)
- Type RightJustify(Log[x].DEnd,10)
- Type LeftJustify(" "||Log[x].Purpose,23)
- Type RightJustify(Log[x].OStart,10)
- Type RightJustify(Log[x].OEnd,10)
- Type RightJustify(Log[x].Dist,10)
- Let TDist = TDist + Log[x].Dist
- NewLine
- Until x = n
- Delete CHARACTER ,-1
- EndIf
- SetText "TDist",TDist
-
- Explanation
- This routine handles displaying the log book entries in the document,
- setting the selected entry into the database fields and calculating the
- overall distance travelled.
-
- FINAL WORDS
- The computerised log book has been designed from a log book that complies
- with the Australian Taxation Office Substantiation Requirements with the
- exception of the signature and name entry sections.
-