home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l196 / 3.ddi / BOOKMOD3.BA$ / BOOKMOD3.bin
Encoding:
Text File  |  1990-06-24  |  25.9 KB  |  633 lines

  1. '***************************************************************************
  2. '* This is module level code for BOOKMOD3.BAS, the fourth                  *
  3. '* module of BOOKLOOK.BAS.                                                 *
  4. '*                                                                         *
  5. '* The module contains a procedure, MakeOver, you can use to convert text  *
  6. '* files containing the right format and type of information for the tables*
  7. '* used by the BOOKLOOK program to a .MDB file. However, you need to call  *
  8. '* MakeOver from the Immediate Window, and in order for it to work, you    *
  9. '* must use the PROISAMD version of the TSR, because MakeOver needs the    *
  10. '* data dictionary functionality for creating indexes, etc.                *
  11. '* If you use the DTFMTER.QLB library functions you must include the files *
  12. '* DATIM.BI and FORMAT.BI at this level, using syntax as shown below.      *
  13. '***************************************************************************
  14. DEFINT A-Z
  15. '$INCLUDE: 'booklook.bi'
  16.  
  17. '***************************************************************************
  18. '*  The BooksBorrowed SUB takes the CardNum in BooksOut associated with the*
  19. '*  currently displayed CardHolder, then looks up each book in BooksOut    *
  20. '*  assigned to that CardNum. Note that you can use SEEKoperand to find the*
  21. '*  first matching record, but thereafter you need to MOVENEXT and check   *
  22. '*  each succeeding record to see if the CardNum matches. When a match is  *
  23. '*  made, look up the IDnum in the BooksOut table and retrieve the title.  *
  24. '*  Put all the titles in the Titles array, then display with PeekWindow.  *
  25. '*                                   Parameters                            *
  26. '*  TablesRec   Structure containing information on all database tables    *
  27. '***************************************************************************
  28. SUB BooksBorrowed (TablesRec AS RecStruct)
  29.     DIM Titles(50) AS STRING
  30.     ' First, get the card number of the current record in Bookstock - then
  31.     ' at the end of this procedure, restore that book
  32.     IF LOF(cBooksOutTableNum) = 0 THEN EXIT SUB
  33.     IF GETINDEX$(cBooksOutTableNum) <> "CardNumIndexBO" THEN
  34.         SETINDEX cBooksOutTableNum, "CardNumIndexBO"
  35.     END IF
  36.     RevName$ = TransposeName$(TablesRec.Lendee.TheName)
  37.     SEEKEQ cBooksOutTableNum, TablesRec.Lendee.CardNum
  38.      IF NOT EOF(cBooksOutTableNum) THEN
  39.         DO
  40.             RETRIEVE cBooksOutTableNum, TablesRec.OutBooks
  41.              IF TablesRec.OutBooks.CardNum = TablesRec.Lendee.CardNum THEN
  42.                     IF GETINDEX$(cBookStockTableNum) <> "IDIndex" THEN
  43.                         SETINDEX cBookStockTableNum, "IDIndex"
  44.                     END IF
  45.                     SEEKEQ cBookStockTableNum, TablesRec.OutBooks.IDnum
  46.                     IF NOT EOF(cBookStockTableNum) THEN
  47.                         RETRIEVE cBookStockTableNum, TablesRec.Inventory
  48.                         Titles(Index) = RTRIM$(TablesRec.Inventory.Title)
  49.                         ThisSize = LEN(RTRIM$(Titles(Index)))
  50.                             IF ThisSize > Biggest THEN
  51.                                 Biggest = ThisSize
  52.                             END IF
  53.                      Index = Index + 1
  54.                     END IF
  55.                 END IF
  56.         MOVENEXT cBooksOutTableNum
  57.         LOOP UNTIL EOF(cBooksOutTableNum)
  58.     ELSE
  59.         Alert$ = RevName$ + " currently has no books checked out"
  60.         CALL ShowMessage(Alert$, 0)
  61.     END IF
  62.     IF Index <> 0 THEN
  63.         HeadMessage$ = " Books borrowed by " + RevName$ + " "
  64.         FootMessage$ = " Press a key to continue "
  65.         CALL PeekWindow(Titles(), HeadMessage$, FootMessage$, Biggest)
  66.         CALL DrawTable(TablesRec.TableNum)
  67.         CALL ShowMessage(KEYSMESSAGE, 0)
  68.     END IF
  69. END SUB
  70.  
  71. '***************************************************************************
  72. '*  The BorrowBook SUB prompts the user to enter the name of the Cardholder*
  73. '*  who wants to borrow the book, then updates all the other tables accord-*
  74. '*  ingly. The name or cardnumber can be entered --- if conversion to a    *
  75. '*  number fails, the user entered a name. If the name isn't of the right  *
  76. '*  format, it is transposed to last-first, comma delimited. If no exact   *
  77. '*  match is found, the next best match is attempted and presented for the *
  78. '*  approval of the user.
  79. '*                                  Parameter                              *
  80. '*  TablesRec   RecStruct type variable holding current table information  *
  81. '***************************************************************************
  82. SUB BorrowBook (TablesRec AS RecStruct)
  83.  
  84. DIM SaveBook AS RecStruct
  85. DIM PeekString(10) AS STRING
  86.  
  87. Prompt$ = "Name or Card Number to Seek: "
  88. SaveBook = TablesRec                          ' Save book information
  89.     ' Prompt user and catch keystroke
  90. CALL ShowMessage("Enter borrower cardnumber or name: ", 1)
  91. FirstChar = ASC(ReturnKey$)                   ' ReturnKey$ is a function
  92. IF FirstChar = ESCAPE THEN CALL ShowMessage("", 0): EXIT SUB
  93. Answer$ = MakeString$(FirstChar, Prompt$)
  94. IF FirstChar = ESCAPE THEN CALL ShowMessage("", 0): EXIT SUB
  95. NumToCheck& = VAL(Answer$)
  96. IF NumToCheck& = 0 THEN
  97.     IF INSTR(Answer$, ",") = 0 THEN
  98.         StraightName$ = Answer$
  99.         Answer$ = TransposeName$(Answer$)
  100.     ELSE
  101.         StraightName$ = TransposeName$(Answer$)
  102.     END IF
  103.  
  104.     SETINDEX cCardHoldersTableNum, "NameIndexCH"
  105.     SEEKEQ cCardHoldersTableNum, Answer$
  106.     IF EOF(cCardHoldersTableNum) THEN
  107.         MOVEFIRST cCardHoldersTableNum
  108.         SEEKGE cCardHoldersTableNum, Answer$     ' If EQ fails, try GE
  109.         IF EOF(cCardHoldersTableNum) THEN
  110.             Alert$ = "Sorry, couldn't find " + StraightName$ + " in CardHolders table..."
  111.             CALL ShowMessage(Alert$, 0)
  112.             EXIT SUB
  113.         END IF
  114.     END IF
  115.     IF NOT EOF(cCardHoldersTableNum) THEN
  116.         RETRIEVE cCardHoldersTableNum, SaveBook.Lendee
  117.         IF TEXTCOMP(LEFT$(SaveBook.Lendee.TheName, 2), LEFT$(Answer$, 2)) = 0 THEN
  118.             NumToCheck& = SaveBook.Lendee.CardNum
  119.         ELSE
  120.             Alert$ = "Sorry, couldn't match " + StraightName$ + " in CardHolders table..."
  121.             CALL ShowMessage(Alert$, 0): ' SLEEP: EraseMessage
  122.             EXIT SUB
  123.         END IF
  124.     END IF
  125. ELSE
  126.     SETINDEX cCardHoldersTableNum, "CardNumIndexCH"
  127.     SEEKEQ cCardHoldersTableNum, NumToCheck&
  128.     IF EOF(cCardHoldersTableNum) THEN
  129.         Alert$ = "Sorry, could not match " + Answer$
  130.         CALL ShowMessage(Alert$, 0):  ' SLEEP: EraseMessage
  131.         EXIT SUB
  132.     ELSE
  133.         RETRIEVE cCardHoldersTableNum, SaveBook.Lendee
  134.         NumToCheck& = SaveBook.Lendee.CardNum
  135.     END IF
  136. END IF
  137.                                                 ' You can replace this phoney date with a call to
  138. DateDue# = 32950#     ' the Date/Time library as shown on these 2 lines:
  139. 'DateDue# = Now# + 30#
  140. 'DateDue$ = STR$(Month&(DateDue#)) + "/" + LTRIM$(STR$(Day&(DateDue#))) + "/" + LTRIM$(STR$(Year&(DateDue#)))
  141.  
  142. ' Show the information on the Cardholder you found...
  143. DO
  144.     PeekString(0) = " This book will be checked out to: "
  145.     PeekString(1) = ""
  146.     PeekString(2) = RTRIM$(SaveBook.Lendee.TheName)
  147.     PeekString(3) = RTRIM$(SaveBook.Lendee.Street)
  148.     PeekString(4) = RTRIM$(SaveBook.Lendee.City) + ", " + RTRIM$(SaveBook.Lendee.State)
  149.     PeekString(5) = "Card number: " + STR$(SaveBook.Lendee.CardNum)
  150.     PeekString(6) = ""
  151.     PeekString(7) = "The Due Date will be " + STR$(DateDue# + 30)
  152.     IF LEN(DateDue$) THEN PeekString(7) = "The Due Date will be " + DateDue$
  153.     FOR Index = 0 TO 8
  154.         ThisSize = LEN(RTRIM$(PeekString(Index)))
  155.         IF ThisSize > Biggest THEN
  156.             Biggest = ThisSize
  157.         END IF
  158.     NEXT Index
  159.  
  160.     HeadMessage$ = " Cardholder checking out this book "
  161.     FootMessage$ = " Press ENTER to confirm this checkout "
  162.     Alert$ = "Press N seek next similar match, ESC to abort checkout"
  163.     CALL ShowMessage(Alert$, 0)
  164.     CALL PeekWindow(PeekString(), HeadMessage$, FootMessage$, Biggest)
  165.  
  166.     ' Let the user press "N" to see the next best match, ESC to abort checkout
  167.     ' anything else to confirm this as person to whom to check book out to
  168.  
  169.     Reply$ = ReturnKey$
  170.     SELECT CASE Reply$
  171.         CASE CHR$(ESCAPE)
  172.             DoneFlag = TRUE
  173.         CASE "N", "n"
  174.             MOVENEXT cCardHoldersTableNum
  175.             IF EOF(cCardHoldersTableNum) THEN
  176.                 DoneFlag = TRUE
  177.             ELSE
  178.                 RETRIEVE cCardHoldersTableNum, SaveBook.Lendee
  179.                 NumToCheck& = SaveBook.Lendee.CardNum
  180.                 IF LEFT$(SaveBook.Lendee.TheName, 2) <> LEFT$(Answer$, 2) THEN
  181.                     DoneFlag = TRUE
  182.                 END IF
  183.             END IF
  184.         CASE ELSE
  185.                 TablesRec.OutBooks.CardNum = NumToCheck&
  186.                 TablesRec.OutBooks.IDnum = SaveBook.Inventory.IDnum
  187.                 TablesRec.OutBooks.DueDate = DateDue#
  188.                 DoneFlag = TRUE
  189.                 MOVEFIRST (cBooksOutTableNum)
  190.                 INSERT cBooksOutTableNum, TablesRec.OutBooks
  191.                 CALL ShowMessage("", 0)
  192.     END SELECT
  193. LOOP UNTIL DoneFlag
  194.  
  195. CALL DrawTable(TablesRec.TableNum)
  196. CALL ShowMessage(KEYSMESSAGE, 0)
  197.     
  198. END SUB
  199.  
  200. '**************************************************************************
  201. '*  The Borrowed FUNCTION simply makes sure there are records in the      *
  202. '*  BooksOut table. If there are none, a message is displayed             *
  203. '**************************************************************************
  204. FUNCTION Borrowed
  205.     IF LOF(cBooksOutTableNum) = 0 THEN
  206.         CALL ShowMessage("Sorry, no records in the BooksOut table", 0): SLEEP
  207.         Borrowed = FALSE
  208.     ELSE
  209.         Borrowed = TRUE
  210.     END IF
  211. END FUNCTION
  212.  
  213. '***************************************************************************
  214. '* The CatchKey function gets a keystroke and returns TRUE if it was ENTER,*
  215. '* otherwise it returns FALSE.                                             *
  216. '***************************************************************************
  217. FUNCTION CatchKey%
  218.     DO
  219.     Answer$ = INKEY$
  220.     LOOP WHILE Answer$ = ""
  221.     SELECT CASE ASC(Answer$)
  222.         CASE ENTER
  223.             CatchKey% = -1
  224.         CASE ELSE
  225.             CatchKey% = 0
  226.     END SELECT
  227. END FUNCTION
  228.  
  229. '***************************************************************************
  230. '*  The GetStatus FUNCTION looks up the status of a book in the BooksOut   *
  231. '*  table. If the SEEK fails it means the book isn't checked out, and that *
  232. '*  message is displayed. Otherwise, it is placed in DateToShow parameter. *
  233. '*  The final message about retrieving borrow info relates to LendeeProfile*
  234. '*                                   Parameters                            *
  235. '*  TablesRec     Structure containing the information about all the tables*
  236. '*  DateToShow    The due date to show in the ShowStatus SUB               *
  237. '***************************************************************************
  238. FUNCTION GetStatus (TablesRec AS RecStruct, DateToShow#)
  239.         IF GETINDEX$(cBooksOutTableNum) <> "IDIndexBO" THEN
  240.             SETINDEX cBooksOutTableNum, "IDIndexBO"
  241.         END IF
  242.         SEEKEQ cBooksOutTableNum, TablesRec.Inventory.IDnum
  243.         IF NOT EOF(cBooksOutTableNum) THEN
  244.             RETRIEVE cBooksOutTableNum, TablesRec.OutBooks
  245.         ELSE
  246.             Alert$ = "This book is not checked out"   ' the book wasn't in BooksOut
  247.             CALL ShowMessage(Alert$, 0)               ' table, so it wasn't out
  248.             DateToShow# = 0: GetStatus = FALSE
  249.             EXIT FUNCTION
  250.         END IF
  251.         DateToShow# = TablesRec.OutBooks.DueDate#
  252.         GetStatus = TRUE
  253. END FUNCTION
  254.  
  255. '***************************************************************************
  256. '*  The LendeeProfile takes the IDnum of the currently displayed book, then*
  257. '*  looks that up in the BooksOut table and fetches the CardHolder record  *
  258. '*  that corresponds to the CardNum entry in BooksOut. Then the CardNum is *
  259. '*  looked up in the CardHolders table and the borrower information shown. *
  260. '*                                Parameters                               *
  261. '*  TablesRec   Contains information on all the tables in the database     *
  262. '***************************************************************************
  263. SUB LendeeProfile (TablesRec AS RecStruct)
  264.     ' Make sure the CardHolders table actually has records
  265.     IF LOF(cCardHoldersTableNum) = 0 THEN
  266.         CALL ShowMessage("Sorry, there are no cardholder records", 0): SLEEP
  267.         EXIT SUB
  268.     END IF
  269.     ' Create an array to hold information from CardHolders table
  270.     DIM LendeeInfo(10)  AS STRING
  271.     ' Set the index if it is not the one you want
  272.     IF GETINDEX$(cBooksOutTableNum) <> "IDIndexBO" THEN
  273.         SETINDEX cBooksOutTableNum, "IDIndexBO"
  274.     END IF
  275.     SEEKEQ cBooksOutTableNum, TablesRec.Inventory.IDnum    ' Seek the record.
  276.     IF EOF(cBooksOutTableNum) THEN                         ' If you find it,
  277.         CALL ShowMessage("This book is not checked out", 0)  ' the book is out,
  278.         EXIT SUB                                             ' otherwise not.
  279.     ELSE                                                   ' If it's there,
  280.         RETRIEVE cBooksOutTableNum, TablesRec.OutBooks       ' fetch it.
  281.  
  282.         ' If the CardNum exists, set an index in CardHolders and SEEK the
  283.         ' CardNum. If SEEK fails, print a warning; if it succeeds, get the
  284.         ' information about the borrower, and display it using PeekWindow
  285.  
  286.         IF TablesRec.OutBooks.CardNum <> 0 THEN
  287.             IF GETINDEX$(cCardHoldersTableNum) <> "CardNumIndexCH" THEN
  288.                 SETINDEX cCardHoldersTableNum, "CardNumIndexCH"
  289.             END IF
  290.             SEEKEQ cCardHoldersTableNum, TablesRec.OutBooks.CardNum
  291.             IF EOF(cBooksOutTableNum) THEN
  292.                 Alert$ = "Cardholder number associated with book ID is not valid"
  293.                 CALL ShowMessage(Alert$, 0)
  294.                 EXIT SUB
  295.             ELSE
  296.                 RETRIEVE cCardHoldersTableNum, TablesRec.Lendee
  297.                 LendeeInfo(0) = RTRIM$(TablesRec.Lendee.TheName)
  298.                 LendeeInfo(1) = ""
  299.                 LendeeInfo(2) = RTRIM$(TablesRec.Lendee.Street)
  300.                 LendeeInfo(3) = RTRIM$(TablesRec.Lendee.City)
  301.                 LendeeInfo(4) = RTRIM$(TablesRec.Lendee.State)
  302.                 LendeeInfo(5) = LTRIM$(STR$(TablesRec.Lendee.Zip))
  303.                 LendeeInfo(7) = STR$(TablesRec.Lendee.CardNum)
  304.                 LendeeInfo(6) = ""
  305.                 LendeeInfo(7) = "Card number: " + LendeeInfo(7)
  306.                 LendeeInfo(8) = ""
  307.                 FOR Index = 1 TO 6
  308.                     ThisBig = LEN(LendeeInfo(Index))
  309.                     IF ThisBig > BiggestYet THEN
  310.                         BiggestYet = ThisBig
  311.                     END IF
  312.                 NEXT Index
  313.                 Alert$ = "Press V to access the record for this cardholder"
  314.                 CALL ShowMessage(Alert$, 0)
  315.                 HeadMessage$ = "Borrower of this Book"
  316.                 FootMessage$ = "Press a key to clear box"
  317.                 CALL ClearEm(TablesRec.TableNum, 1, 1, 1, 1, 1, 1)
  318.                 CALL PeekWindow(LendeeInfo(), HeadMessage$, FootMessage$, BiggestYet)
  319.                 CALL DrawTable(TablesRec.TableNum)
  320.                 CALL ShowMessage(KEYSMESSAGE, 0)
  321.             END IF
  322.         END IF
  323.     END IF
  324. END SUB
  325.  
  326. '***************************************************************************
  327. '* The MakeOver SUB lets the user input the names of properly formatted    *
  328. '* text files, then creates a database file of the same type as BOOKS.MDB. *
  329. '* There is also a prompt for the new database name. The text files must   *
  330. '* contain comma-delimited fields, with strings within double quote marks. *
  331. '* The last part of this SUB demonstrates how indexes are created. You need*
  332. '* to have loaded PROISAMD.EXE to run this procedure.                      *
  333. '*                            Parameters:                                  *
  334. '*   Big Rec      User-defined type containing all table information       *
  335. '***************************************************************************
  336. '
  337. SUB MakeOver (BigRec AS RecStruct)
  338.     CLOSE
  339.     Alert$ = "Type name of file containing Cardholders table data: "
  340.     CALL ShowMessage(Alert$, 1)
  341.     INPUT "", CardFile$
  342.     Alert$ = "Type name of file containing BooksOut table data: "
  343.     CALL ShowMessage(Alert$, 1)
  344.     INPUT "", OutBooks$
  345.     Alert$ = "Type name of file containing BookStock table data: "
  346.     CALL ShowMessage(Alert$, 1)
  347.     INPUT "", BookFile$
  348.     Alert$ = "Type name of ISAM file to create: "
  349.     CALL ShowMessage(Alert$, 1)
  350.     INPUT "", IsamFile$
  351.     IF UCASE$(IsamFile$) = "BOOKS.MDB" THEN KILL "BOOKS.MDB"
  352.     CALL ShowMessage("Loading database...", 0)
  353.  
  354.     CLOSE
  355.     ON LOCAL ERROR GOTO FileHandler
  356.     LenFileNo% = 10
  357.     OPEN CardFile$ FOR INPUT AS LenFileNo%
  358.     OutFileNo% = 11
  359.     OPEN OutBooks$ FOR INPUT AS OutFileNo%
  360.     RecFileNo% = 12
  361.     OPEN BookFile$ FOR INPUT AS RecFileNo%
  362.     ON ERROR GOTO 0
  363.     
  364.     ' Open the database and the BookStock table
  365.     OPEN IsamFile$ FOR ISAM Books "BookStock" AS cBookStockTableNum
  366.     OPEN IsamFile$ FOR ISAM Borrowers "CardHolders" AS cCardHoldersTableNum
  367.     OPEN IsamFile$ FOR ISAM BookStatus "BooksOut" AS cBooksOutTableNum
  368.     CALL ShowMessage(" Opened all isam tables", 0)
  369.  
  370.     SeqFile% = LenFileNo
  371.     DO WHILE (Reader%(BigRec, SeqFile%))
  372.      INSERT cCardHoldersTableNum, BigRec.Lendee
  373.     LOOP
  374.     SeqFile% = OutFileNo
  375.     DO WHILE (Reader%(BigRec, SeqFile))
  376.      INSERT cBooksOutTableNum, BigRec.OutBooks
  377.     LOOP
  378.     SeqFile = RecFileNo
  379.     DO WHILE (Reader%(BigRec, SeqFile))
  380.      INSERT cBookStockTableNum, BigRec.Inventory
  381.     LOOP
  382.     CALL ShowMessage("Finished reading in records---Indexes next", 0)
  383. ' These indexes are already in the BOOKS.MDB database --- the following
  384. ' is the syntax that was used to create them
  385.  
  386.     ON LOCAL ERROR GOTO FileHandler
  387.     CREATEINDEX cBookStockTableNum, "TitleIndexBS", 0, "Title"
  388.     CREATEINDEX cBookStockTableNum, "AuthorIndexBS", 0, "Author"
  389.     CREATEINDEX cBookStockTableNum, "PubIndexBS", 0, "Publisher"
  390.     CREATEINDEX cBookStockTableNum, "IDIndex", 1, "IDnum"     ' Note unique index
  391.     CREATEINDEX cBookStockTableNum, "BigIndex", 0, "Title", "Author", "IDnum"
  392.  
  393.     CREATEINDEX cBooksOutTableNum, "IDIndexBO", 0, "IDnum"
  394.     CREATEINDEX cBooksOutTableNum, "CardNumIndexBO", 0, "CardNum"
  395.  
  396.     CREATEINDEX cCardHoldersTableNum, "NameIndexCH", 0, "TheName"
  397.     CREATEINDEX cCardHoldersTableNum, "StateIndexCH", 0, "State"
  398.     CREATEINDEX cCardHoldersTableNum, "ZipIndexCH", 0, "Zip"
  399.     CREATEINDEX cCardHoldersTableNum, "CardNumIndexCH", 1, "CardNum"  ' Unique index
  400.     ON ERROR GOTO 0
  401.     CALL ShowMessage(" All done with indexes...", 0)
  402.     'CLOSE
  403.  
  404.     EXIT SUB
  405.  
  406. FileHandler:
  407.     IF ERR = 73 THEN
  408.         CALL ShowMessage("You need to Exit QBX and load PROISAMD /Ib:24 /Ii:16", 0)
  409.     ELSEIF ERR = 10 THEN
  410.         Alert$ = "Finished appending the records to " + IsamFile$
  411.         CALL ShowMessage(Alert$, 0)
  412.         END
  413.     ELSEIF ERR = 86 THEN
  414.         Alert$ = "Tried to add record with duplicate value on a unique index"
  415.         CALL ShowMessage(Alert$, 0)
  416.         ELSE
  417.         CALL ShowMessage("Can't find textfiles needed to make the database", 0)
  418.     END IF
  419.     END
  420. END SUB
  421.  
  422. '***************************************************************************
  423. '*  The PeekWindow SUB displays the elements of the OutBookNames array in  *
  424. '*  a window on top of the currently displayed table.                      *
  425. '*                                Parameters                               *
  426. '*  OutBookNames    Array of strings containing lines displayed in window  *
  427. '*  Header$         String to show at top of window                        *
  428. '*  Footer$         String to show at bottom of window                     *
  429. '*  BiggestYet      Length of the longest string to be shown               *
  430. '***************************************************************************
  431. SUB PeekWindow (OutBookNames() AS STRING, Header$, Footer$, BiggestYet%)
  432. HeadLen = LEN(Header$)        ' + 4
  433. FootLen = LEN(Footer$)        ' + 4
  434. IF HeadLen > FootLen THEN Bigger = HeadLen ELSE Bigger = FootLen
  435. IF Bigger > BiggestYet THEN BiggestYet = Bigger
  436.                                                                                      
  437. InnerBox = 9          ' InnerBox is total number of lines allowed inside box
  438. first = 0: last = 8
  439. DO
  440.  
  441.     ' Calculate header and footer placement
  442.  
  443.         IF (HeadLen MOD 2) THEN
  444.             HeadStart = ((BiggestYet - HeadLen) \ 2) + 13
  445.         ELSE
  446.             HeadStart = ((BiggestYet - HeadLen) \ 2) + 12
  447.         END IF
  448.         IF (FootLen MOD 2) THEN
  449.             FootStart = ((BiggestYet - FootLen) \ 2) + 13
  450.         ELSE
  451.             FootStart = ((BiggestYet - FootLen) \ 2) + 12
  452.         END IF
  453.  
  454.         ' Print a box and fill it with titles
  455.         Inset = TABLETOP + 2
  456.  
  457.         Lines = Inset + 1
  458.         IF MoreBoxes = FALSE THEN
  459.             LOCATE Inset, 3
  460.             PRINT "       ╔"; STRING$(BiggestYet + 2, CHR$(205)); "╗"
  461.         END IF
  462.         FOR PrintEm = first TO last
  463.             LOCATE Lines + NextSpace, 3
  464.             PRINT "       ║ "; OutBookNames(Total); SPACE$(BiggestYet - LEN((OutBookNames(Total)))); " ║"
  465.             Total = Total + 1: NextSpace = NextSpace + 1
  466.         NEXT PrintEm
  467.         IF MoreBoxes = FALSE THEN                       ' Means first group
  468.             LOCATE Lines + NextSpace, 3
  469.             PRINT "       ╚"; STRING$(BiggestYet + 2, CHR$(205)); "╝"
  470.             COLOR BACKGROUND, FOREGROUND + BRIGHT
  471.             LOCATE Inset, HeadStart
  472.             PRINT Header$;                          '"╡ "; Header$; " ╞"
  473.             LOCATE Lines + NextSpace, FootStart
  474.             PRINT Footer$                           '"╡ "; Footer$; " ╞"
  475.             COLOR FOREGROUND, BACKGROUND
  476.         END IF
  477.         SLEEP
  478.     first = first + InnerBox: last = last + InnerBox
  479.     NextSpace = 0: HowMany = 0
  480.  
  481.     MoreBoxes = TRUE
  482.  
  483. LOOP UNTIL LEN(RTRIM$(OutBookNames(Total))) = 0
  484.  
  485. END SUB
  486.  
  487. '***************************************************************************
  488. '*  The Reader FUNCTION reads specified text files and returns each line   *
  489. '*  as a separate record for the corresponding table.                      *
  490. '*                               Parameters                                *
  491. '*  BigRec    RecStruct variable containing information on tables          *
  492. '*  SeqFile   File number used to open the text file to be read
  493. '***************************************************************************
  494. FUNCTION Reader% (BigRec AS RecStruct, SeqFile%)
  495.     SELECT CASE SeqFile
  496.         CASE 10
  497.             IF NOT EOF(SeqFile) THEN
  498.              INPUT #SeqFile, BigRec.Lendee.CardNum, BigRec.Lendee.Zip, BigRec.Lendee.TheName, BigRec.Lendee.City, BigRec.Lendee.Street, BigRec.Lendee.State
  499.              Reader = -1
  500.             ELSE
  501.                 Reader = 0
  502.             END IF
  503.         CASE 11
  504.             IF NOT EOF(SeqFile) THEN
  505.              INPUT #SeqFile, BigRec.OutBooks.IDnum, BigRec.OutBooks.CardNum, BigRec.OutBooks.DueDate
  506.              Reader = -1
  507.             ELSE
  508.              Reader = 0
  509.             END IF
  510.         CASE 12
  511.             IF NOT EOF(SeqFile) THEN
  512.                 INPUT #SeqFile, BigRec.Inventory.IDnum, BigRec.Inventory.Price, BigRec.Inventory.Edition, BigRec.Inventory.Title, BigRec.Inventory.Author, BigRec.Inventory.Publisher
  513.                 Reader = -1
  514.              ELSE
  515.                 Reader = 0
  516.              END IF
  517.     END SELECT
  518. END FUNCTION
  519.  
  520. '***************************************************************************
  521. '*  The ReturnBook SUB checks the book currently being displayed back into *
  522. '*  the library --- that is, it eliminates the appropriate entry from the  *
  523. '*  BooksOut table. It checks to see if the book is overdue, and if so, it *
  524. '*  displays the amount of the fine to be paid.                            *
  525. '*                                Parameters                               *
  526. '*  TablesRec   RecStruct type variable holding current table information  *
  527. '***************************************************************************
  528. SUB ReturnBook (TablesRec AS RecStruct, DueDate#)
  529.  
  530. DIM ReturnLines(10) AS STRING
  531.  
  532. Alert$ = "Press ENTER to check current book in, N to abort checkin..."
  533. CALL ShowMessage(Alert$, 0)
  534.  
  535. SETINDEX cBooksOutTableNum, "IDIndexBO"
  536. SEEKEQ cBooksOutTableNum, TablesRec.Inventory.IDnum
  537. IF NOT EOF(cBooksOutTableNum) THEN
  538.     RETRIEVE cBooksOutTableNum, TablesRec.OutBooks
  539. END IF
  540. SETINDEX cCardHoldersTableNum, "CardNumIndexCH"
  541. SEEKEQ cCardHoldersTableNum, TablesRec.OutBooks.CardNum
  542.  
  543. IF NOT EOF(cBooksOutTableNum) THEN
  544.     IF LOF(cCardHoldersTableNum) THEN
  545.         RETRIEVE cCardHoldersTableNum, TablesRec.Lendee
  546.     END IF
  547. END IF
  548.  
  549. Today# = 32000    'Replace this with call to DTFMTER.QLB library routine
  550.                                     'as shown on the next 2 lines
  551. 'Today# = Now#
  552. 'ShowDate$ = STR$(Month&(Today#)) + "/" + LTRIM$(STR$(Day&(Today#))) + "/" + LTRIM$(STR$(Year&(Today#)))
  553. IF Today# > TablesRec.OutBooks.DueDate THEN
  554.     Fine = Today# - TablesRec.OutBooks.DueDate
  555. END IF
  556.  
  557. DateDue# = (TablesRec.OutBooks.DueDate)
  558. ' If you have DTFMTER.QLB loaded, use in to get date to display
  559. ' DateDue$ = STR$(Month&(DateDue#)) + "/" + LTRIM$(STR$(Day&(DateDue#))) + "/" + LTRIM$(STR$(Year&(DateDue#)))
  560. ReturnLines(0) = ""
  561. ReturnLines(1) = RTRIM$(TablesRec.Inventory.Title)
  562. ReturnLines(2) = "is checked out to card number: " + STR$(TablesRec.OutBooks.CardNum)
  563. ReturnLines(3) = RTRIM$(TablesRec.Lendee.TheName)
  564. ReturnLines(4) = ""
  565. ReturnLines(5) = "Today's Date:     " + STR$(Today#) + " - A phoney date"
  566. IF LEN(ShowDate$) THEN ReturnLines(5) = "Today's Date:     " + ShowDate$
  567. ReturnLines(6) = "Due Date of Book: " + STR$(TablesRec.OutBooks.DueDate)
  568. IF LEN(DateDue$) THEN ReturnLines(6) = "Due Date of Book: " + DateDue$
  569. ReturnLines(7) = "Fine Payable:     $" + STR$(ABS(Fine / 100))
  570. ReturnLines(8) = ""
  571. ReturnLines(9) = ""
  572. FOR Index = 0 TO 10
  573.     ThisOne = LEN(ReturnLines(Index))
  574.     IF ThisOne > BiggestYet THEN BiggestYet = ThisOne
  575. NEXT Index
  576. Header$ = "Press ENTER to check book in..."
  577. Footer$ = "Press N or n to abort checkin..."
  578. CALL PeekWindow(ReturnLines(), Header$, Footer$, BiggestYet%)
  579.  
  580. IF CatchKey THEN                              ' If user confirms, delete
  581.     IF LOF(cBooksOutTableNum) <> 0 THEN         ' the entry to BooksOut table
  582.         DELETE cBooksOutTableNum
  583.     END IF
  584. END IF
  585. CALL DrawTable(TablesRec.TableNum)
  586. CALL EraseMessage
  587.  
  588. END SUB
  589.  
  590. '***************************************************************************
  591. '* The ShowStatus SUB uses the due date associated with the book IDnum from*
  592. '* of the BooksOut table. This date is in serial form which is not decoded *
  593. '* here, but can be decoded with the date/time function library supplied   *
  594. '* with BASIC 7.1. The due date is displayed centered on the top line of   *
  595. '* the ShowMessage box.                                                    *
  596. '*                                Parameters                               *
  597. '*  Stat$       Message introducing the due date when displayed in its box *
  598. '*  ValueToShow The due date of the book from the BooksOut table           *
  599. '***************************************************************************
  600. SUB ShowStatus (Stat$, ValueToShow AS DOUBLE)
  601.  
  602. COLOR FOREGROUND, BACKGROUND
  603. DataEndLine$ = STRING$(60, 205)       'redraw the bottom line
  604.  
  605. StringToShow$ = Stat$       ' Figure out where to locate the text
  606. IF ValueToShow = 0 THEN
  607.     LOCATE TABLEEND, 4
  608.     PRINT DataEndLine$
  609.     EXIT SUB
  610. ELSE
  611.     ' The dates in the file are in serial form. Use the DTFMTER.QLB library
  612.     ' to decode serial dates for normal display. In the code below, the
  613.     ' calls to the library are commented out.
  614.  
  615.     'TheDate$ = STR$(Month&(ValueToShow)) + "/" + LTRIM$(STR$(Day&(ValueToShow))) + "/" + LTRIM$(STR$(Year&(ValueToShow)))
  616.     IF Stat$ = " Total records in table: " OR LEN(TheDate$) = 0 THEN
  617.         StringToShow$ = StringToShow$ + " " + STR$(ValueToShow)
  618.     ELSE
  619.         StringToShow$ = StringToShow$ + " " + TheDate$
  620.     END IF
  621.     HowLong = LEN(StringToShow$)
  622.     PlaceStatus = (73 \ 2) - (HowLong \ 2)
  623.     StatusSpace$ = CHR$(181) + STRING$(HowLong, 32) + CHR$(198)
  624. END IF
  625. LOCATE TABLEEND, PlaceStatus
  626. PRINT StatusSpace$
  627. COLOR BACKGROUND, BRIGHT + FOREGROUND
  628. LOCATE TABLEEND, PlaceStatus + 1
  629. PRINT StringToShow$
  630. COLOR FOREGROUND, BACKGROUND
  631.  
  632. END SUB
  633.