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

  1. '***********************************************************************
  2. '*  This is module level code for BOOKMOD2.BAS. It contains procedures *
  3. '*  that use ISAM statements as well as procedures that support them.  *
  4. '*  It is the third module of the BOOKLOOK program.                    *
  5. '***********************************************************************
  6. DEFINT A-Z
  7. '$INCLUDE: 'booklook.bi'
  8.  
  9. EditMessage:
  10. DATA "╔═══════════════════════════╗"
  11. DATA "║ A log is being kept while ║"
  12. DATA "║ you edit fields in this   ║"
  13. DATA "║ record. Press U to undo   ║"
  14. DATA "║ each preceding edit, or   ║"
  15. DATA "║ CTRL+U to undo all of the ║"
  16. DATA "║ pending edits as a group. ║"
  17. DATA "║                           ║"
  18. DATA "╚═════╡ To Undo Edits ╞═════╝"
  19.  
  20. OperandBox:
  21. DATA "╔═══════════════════════════╗"
  22. DATA "║                           ║"
  23. DATA "║ Greater Than              ║"
  24. DATA "║ or                        ║"
  25. DATA "║ Equal To     Value Entered║"
  26. DATA "║ or                        ║"
  27. DATA "║ Less Than                 ║"
  28. DATA "║                           ║"
  29. DATA "╚══╡ Relationship to Key ╞══╝"
  30.  
  31. '************************************************************************
  32. '*                                                                      *
  33. '*  This SUB checks the real current index after a try to set an index. *
  34. '*  If the index was successfully set, it's name is displayed, other-   *
  35. '*  wise the current index is displayed. IndexBox is called to update   *
  36. '*  Current Sorting Order box on the screen.                            *
  37. '*                                                                      *
  38. '************************************************************************
  39. SUB AdjustIndex (TablesRec AS RecStruct)
  40.   RealIndexName$ = GETINDEX$(TablesRec.TableNum)
  41.   CALL Indexbox(TablesRec, CheckIndex%(TablesRec, 0))
  42.   IF RealIndexName$ <> EMPTYSTRING THEN
  43.     Alert$ = "Records are now ordered by the index called " + RealIndexName$
  44.   ELSE
  45.     Alert$ = "Records now ordered by the default (NULL) index"
  46.   END IF
  47.   CALL ShowMessage(Alert$, 0)
  48. END SUB
  49.  
  50. '***************************************************************************
  51. '*  The ChangeRecord FUNCTION gets the new field value with MakeString. It *
  52. '*  then assigns the value (converted if necessary) to its proper element  *
  53. '*  in the recordvariable (TablesRec) used to update the table.            *
  54. '*                                Parameters                               *
  55. '*  FirstLetter   If the user has started typing, this contains a letter   *
  56. '*  Argument      Tells what field the cursor is currently in              *
  57. '*  TablesRec     RecStruct type variable holding all table information    *
  58. '*  Task          Tells which operation is being performed                 *
  59. '***************************************************************************
  60. FUNCTION ChangeRecord (FirstLetter$, Argument, TablesRec AS RecStruct, Task AS INTEGER)
  61.   STATIC SaveTitle AS STRING
  62.   Prompt$ = "New Field Value: "
  63.  
  64.   IF Task <> SEEKFIELD THEN            ' Adjust the Argument --- It is in-
  65.     IF Argument = TITLEFIELD THEN      ' cremented as part of PlaceCursor.
  66.       Argument = IDFIELD               ' But it needs the user's original
  67.     ELSE                               ' choice in this function.
  68.        Argument = Argument - 2
  69.     END IF
  70.   END IF
  71.  
  72.   Filter% = ASC(FirstLetter$)                ' Convert FirstLetter$ to ascii
  73.   Remainder$ = MakeString$(Filter%, Prompt$) ' number to pass to MakeString.
  74.   IF Filter% = ESCAPE THEN                   ' This lets the user press ESC
  75.     ChangeRecord = 0                         ' to abandon function.
  76.     CALL ShowRecord(TablesRec)
  77.     EXIT FUNCTION
  78.   END IF
  79.                                            ' Select for proper assignment of
  80.   SELECT CASE Argument                     ' string user makes with MakeString
  81.     CASE TITLEFIELD, NAMEFIELD
  82.       IF Task = EDITRECORD OR Task = ADDRECORD OR Task = SEEKFIELD THEN
  83.         IF TablesRec.TableNum = cBookStockTableNum THEN
  84.           TablesRec.Inventory.Title = Remainder$
  85.         ELSE
  86.           TablesRec.Lendee.TheName = Remainder$
  87.         END IF
  88.       END IF
  89.       COLOR FOREGROUND, BACKGROUND
  90.     CASE AUTHORFIELD, STREETFIELD
  91.       IF Task = EDITRECORD OR Task = ADDRECORD THEN
  92.         IF TablesRec.TableNum = cBookStockTableNum THEN
  93.           TablesRec.Inventory.Author = Remainder$
  94.         ELSE
  95.           TablesRec.Lendee.Street = Remainder$
  96.         END IF
  97.       END IF
  98.       COLOR FOREGROUND, BACKGROUND
  99.     CASE PUBFIELD, CITYFIELD
  100.       IF Task = EDITRECORD OR Task = ADDRECORD THEN
  101.         IF TablesRec.TableNum = cBookStockTableNum THEN
  102.           TablesRec.Inventory.Publisher = Remainder$
  103.         ELSE
  104.           TablesRec.Lendee.City = Remainder$
  105.         END IF
  106.       END IF
  107.       COLOR FOREGROUND, BACKGROUND
  108.     CASE EDFIELD, STATEFIELD
  109.       IF Task = EDITRECORD OR Task = ADDRECORD THEN
  110.         IF TablesRec.TableNum = cBookStockTableNum THEN
  111.           TablesRec.Inventory.Edition = VAL(Remainder$)
  112.         ELSE
  113.           TablesRec.Lendee.State = Remainder$
  114.         END IF
  115.       END IF
  116.       COLOR FOREGROUND, BACKGROUND
  117.     CASE PRICEFIELD, ZIPFIELD
  118.       IF Task = EDITRECORD OR Task = ADDRECORD THEN
  119.         IF TablesRec.TableNum = cBookStockTableNum THEN
  120.           TablesRec.Inventory.Price = VAL(Remainder$)
  121.         ELSE
  122.           TablesRec.Lendee.Zip = VAL(Remainder$)
  123.         END IF
  124.       END IF
  125.       COLOR FOREGROUND, BACKGROUND
  126.     CASE IDFIELD, CARDNUMFIELD
  127.       IF Task = EDITRECORD OR Task = ADDRECORD THEN
  128.         IF TablesRec.TableNum = cBookStockTableNum THEN
  129.           size = LEN(Remainder$)
  130.           FOR counter = 1 TO size
  131.             IF ASC(MID$(Remainder$, counter, 1)) = 0 THEN
  132.               Remainder$ = MID$(Remainder$, (counter + 1), size)
  133.             END IF
  134.           NEXT counter
  135.           TablesRec.Inventory.IDnum = VAL(LTRIM$(RTRIM$(Remainder$)))
  136.         ELSE
  137.           TablesRec.Lendee.CardNum = VAL(Remainder$)
  138.         END IF
  139.       END IF
  140.       COLOR FOREGROUND, BACKGROUND
  141.     CASE ELSE
  142.         CALL ShowMessage("  Can't change that field ", 0)
  143.         BEEP
  144.         SLEEP 1
  145. END SELECT
  146.  ChangeRecord = 1
  147. END FUNCTION
  148.  
  149. '***************************************************************************
  150. '*  The CheckIndex uses the GETINDEX function to find the current index.   *
  151. '*  Since only some displayed fields correspond to indexes, the number     *
  152. '*  returned is a code indicating what to do, not the index name           *
  153. '*                                Parameters                               *
  154. '*  TablesRec   RecStuct type variable holding all table information       *
  155. '*  FirstTime   If first time is TRUE, Index is NULL index                 *
  156. '***************************************************************************
  157. FUNCTION CheckIndex% (TablesRec AS RecStruct, FirstTime)
  158.   Check$ = GETINDEX$(TablesRec.TableNum)
  159.   SELECT CASE Check$
  160.     CASE "TitleIndexBS", "NameIndexCH"
  161.       CheckIndex% = 0
  162.     CASE "AuthorIndexBS"
  163.       CheckIndex% = 1
  164.     CASE "PubIndexBS"
  165.       CheckIndex% = 2
  166.     CASE "StateIndexCH"
  167.       CheckIndex% = 3
  168.     CASE "ZipIndexCH"
  169.       CheckIndex% = 4
  170.     CASE "IDIndex", "CardNumIndexCH"
  171.       CheckIndex% = 5
  172.     CASE "BigIndex"                 ' There's no combined index on
  173.       CheckIndex% = 6               ' CardHolders table
  174.     CASE ""
  175.       CheckIndex% = 7               ' This is a special case for the
  176.                                     ' Blank line in CardHolders table
  177.     IF FirstTime% THEN
  178.       CALL Indexbox(TablesRec, 7)
  179.     END IF
  180.   END SELECT
  181. END FUNCTION
  182.  
  183. '***************************************************************************
  184. '*  The EdAddCursor function is used to place the cursor in the proper     *
  185. '*  when the task is to Edit or Add a record.  Note when printing numeric  *
  186. '*  fields LOCATE 1 column left to compensate  for the implicit "+" sign.  *
  187. '*                                Parameters                               *
  188. '*  NextField   Tells which field is to be highlighted next                *
  189. '*  Job         Tells operation user wants to engage in                    *
  190. '*  TablesRec   RecStruct type variable holding all table information      *
  191. '*  FirstShot   Nonzero value indicates this is first time through         *
  192. '***************************************************************************
  193. FUNCTION EdAddCursor (NextField%, Job%, TablesRec AS RecStruct, FirstShot%)
  194.   SELECT CASE TablesRec.TableNum
  195.     CASE cBookStockTableNum                       ' BookStock table is 1
  196.       SELECT CASE NextField
  197.         CASE TITLEFIELD, NAMEFIELD
  198.           LOCATE IDFIELD, 17
  199.           IF FirstShot THEN COLOR FOREGROUND, BACKGROUND
  200.           PRINT TablesRec.Inventory.IDnum
  201.           COLOR BACKGROUND, BRIGHT + FOREGROUND
  202.           LOCATE TITLEFIELD, 18
  203.           PRINT TablesRec.Inventory.Title
  204.           NextField% = AUTHORFIELD
  205.         CASE AUTHORFIELD, STREETFIELD
  206.           LOCATE TITLEFIELD, 18
  207.           PRINT TablesRec.Inventory.Title
  208.           COLOR BACKGROUND, BRIGHT + FOREGROUND
  209.           LOCATE AUTHORFIELD, 18
  210.           PRINT TablesRec.Inventory.Author
  211.           NextField% = PUBFIELD
  212.         CASE PUBFIELD, CITYFIELD
  213.           LOCATE AUTHORFIELD, 18
  214.           PRINT TablesRec.Inventory.Author
  215.           COLOR BACKGROUND, BRIGHT + FOREGROUND
  216.           LOCATE PUBFIELD, 18
  217.             PRINT TablesRec.Inventory.Publisher
  218.             NextField% = EDFIELD
  219.         CASE EDFIELD, STATEFIELD
  220.           LOCATE PUBFIELD, 18
  221.           PRINT TablesRec.Inventory.Publisher
  222.           COLOR BACKGROUND, BRIGHT + FOREGROUND
  223.           LOCATE EDFIELD, 17
  224.           PRINT TablesRec.Inventory.Edition
  225.           NextField% = PRICEFIELD
  226.         CASE PRICEFIELD, ZIPFIELD
  227.           LOCATE EDFIELD, 17
  228.           PRINT TablesRec.Inventory.Edition
  229.           COLOR BACKGROUND, BRIGHT + FOREGROUND
  230.           LOCATE PRICEFIELD, 19
  231.           PRINT ; TablesRec.Inventory.Price
  232.           NextField% = IDFIELD
  233.         CASE IDFIELD, CARDNUMFIELD
  234.           LOCATE PRICEFIELD, 18
  235.           PRINT "$"; TablesRec.Inventory.Price
  236.           COLOR BACKGROUND, BRIGHT + FOREGROUND
  237.           LOCATE IDFIELD, 17
  238.           PRINT TablesRec.Inventory.IDnum
  239.           NextField% = TITLEFIELD
  240.       END SELECT
  241.     CASE cCardHoldersTableNum                       ' CardHolders table is 2
  242.       SELECT CASE NextField
  243.         CASE NAMEFIELD
  244.           LOCATE CARDNUMFIELD, 17
  245.           IF FirstShot THEN COLOR FOREGROUND, BACKGROUND
  246.           PRINT TablesRec.Lendee.CardNum
  247.           COLOR BACKGROUND, BRIGHT + FOREGROUND
  248.           LOCATE NAMEFIELD, 18
  249.           PRINT TablesRec.Lendee.TheName
  250.           NextField% = STREETFIELD
  251.         CASE STREETFIELD
  252.           LOCATE NAMEFIELD, 18
  253.           PRINT TablesRec.Lendee.TheName
  254.           COLOR BACKGROUND, BRIGHT + FOREGROUND
  255.           LOCATE STREETFIELD, 18
  256.           PRINT TablesRec.Lendee.Street
  257.           NextField% = CITYFIELD
  258.         CASE CITYFIELD
  259.           LOCATE STREETFIELD, 18
  260.           PRINT TablesRec.Lendee.Street
  261.           COLOR BACKGROUND, BRIGHT + FOREGROUND
  262.           LOCATE CITYFIELD, 18
  263.           PRINT TablesRec.Lendee.City
  264.           NextField% = STATEFIELD
  265.         CASE STATEFIELD
  266.           LOCATE CITYFIELD, 18
  267.           PRINT TablesRec.Lendee.City
  268.           COLOR BACKGROUND, BRIGHT + FOREGROUND
  269.           LOCATE STATEFIELD, 18
  270.           PRINT TablesRec.Lendee.State
  271.           NextField% = PRICEFIELD
  272.         CASE ZIPFIELD
  273.           LOCATE STATEFIELD, 18
  274.           PRINT TablesRec.Lendee.State
  275.           COLOR BACKGROUND, BRIGHT + FOREGROUND
  276.           LOCATE ZIPFIELD, 17
  277.           PRINT TablesRec.Lendee.Zip
  278.           NextField% = IDFIELD
  279.         CASE CARDNUMFIELD
  280.           LOCATE ZIPFIELD, 17
  281.           PRINT TablesRec.Lendee.Zip
  282.           COLOR BACKGROUND, BRIGHT + FOREGROUND
  283.           LOCATE CARDNUMFIELD, 17
  284.           PRINT TablesRec.Lendee.CardNum
  285.           NextField% = TITLEFIELD
  286.       END SELECT
  287.   END SELECT
  288.   COLOR FOREGROUND, BACKGROUND
  289. END FUNCTION
  290.  
  291. '***************************************************************************
  292. '*  The EditField function lets the user choose whether or not to actually *
  293. '*  change the current field (by calling ChangeRecord) or move on to the   *
  294. '*  next field. It also displays a message telling how to Undo edits. If   *
  295. '*  EditField returns TRUE, a SAVEPOINT is set at module level. If the task*
  296. '*  is ADDRECORD, the user is taken through the fields one at a time until *
  297. '*  they have all been entered.                                            *
  298. '*                              Parameters                                 *
  299. '*  Argument    Tells which field is currently being dealt with            *
  300. '*  TablesRec   RecStruct type variable holding current table information  *
  301. '*  FirstLetter If the user has started typing, the letter is passed in    *
  302. '*  Task        Tells what type of operation the user is performing        *
  303. '*  Answer      Same as Task, but passed to ChangeRecord
  304. '***************************************************************************
  305. FUNCTION EditField (Argument%, TablesRec AS RecStruct, FirstLetter$, Task%, Answer%)
  306.   ' Show the transaction block message dealing with undoing edits:
  307.   IF Task = EDITRECORD THEN CALL DrawIndexBox(1, Task)
  308.  
  309.   STATIC NextField
  310.   FirstLetter$ = ""
  311.   IF Task = EDITRECORD THEN CALL ShowMessage("Edit this field or TAB to another", 0)
  312.   Argument = TITLEFIELD
  313.   Value = PlaceCursor(Argument, TablesRec, FirstLetter$, 1, Task%)
  314.   IF Argument THEN
  315.     IF Task = EDITRECORD THEN CALL ShowMessage("Edit this field or TAB to another", 0)
  316.     COLOR FOREGROUND, BACKGROUND
  317.     WasFieldChanged = ChangeRecord(FirstLetter$, Argument, TablesRec, Answer)
  318.  
  319.     IF Task = EDITRECORD AND WasFieldChanged <> 0 THEN
  320.       CALL ShowMessage("Press E to Edit another field ", 0)
  321.       EditField = TRUE            ' If True is returned, a SAVEPOINT is set
  322.     ELSEIF Task = EDITRECORD AND WasFieldChanged = 0 THEN
  323.       CALL ShowRecord(TablesRec)
  324.       CALL ShowMessage("Please try again...", 0)
  325.       EditField = FALSE     'Don't set SAVEPOINT if user escapes from edit
  326.     ELSEIF Task = SEEKFIELD THEN
  327.       EditField = FALSE: EXIT FUNCTION
  328.     END IF
  329.     IF Task = ADDRECORD THEN
  330.       NextField = 1
  331.       DO WHILE NextField <> 0 AND Argument <> 0
  332.         CALL ShowMessage("Enter value for field or ESC to abandon addition ", 0)
  333.         SELECT CASE NextField
  334.           CASE 1
  335.             Argument = AUTHORFIELD
  336.             FieldsDone = FieldsDone + 1
  337.           CASE 2
  338.             Argument = PUBFIELD
  339.             FieldsDone = FieldsDone + 1
  340.           CASE 3
  341.             Argument = EDFIELD
  342.             FieldsDone = FieldsDone + 1
  343.           CASE 4
  344.             Argument = PRICEFIELD
  345.             FieldsDone = FieldsDone + 1
  346.           CASE 5
  347.             Argument = IDFIELD
  348.             FieldsDone = FieldsDone + 1
  349.             NextField = 0
  350.           CASE ELSE
  351.             CALL ShowMessage("Problem in the CASE assignments to Argument", 0): SLEEP
  352.         END SELECT
  353.         FirstLetter$ = ""
  354.         Value = PlaceCursor(Argument, TablesRec, FirstLetter$, 1, Task%)
  355.         IF Argument THEN
  356.           COLOR FOREGROUND, BACKGROUND
  357.           WasFieldChanged = ChangeRecord(FirstLetter$, Argument, TablesRec, Answer)
  358.           NextField = NextField + 1
  359.           IF FieldsDone = 5 THEN EditField% = 1: EXIT FUNCTION
  360.         END IF
  361.       LOOP
  362.       EditField = FALSE 'No need for SAVEPOINT with ADDRECORD
  363.     END IF
  364.   ELSE
  365.   CALL ShowRecord(TablesRec)
  366.   CALL ShowMessage("Please try again...", 0)
  367.   SLEEP: CALL EraseMessage
  368.   CALL DrawIndexBox(TablesRec.TableNum, 0)' Replace Edit stuff with Index stuff
  369.   EditField = FALSE     'Don't set SAVEPOINT if user escapes from edit
  370.   END IF
  371.  
  372. END FUNCTION
  373.  
  374. '***************************************************************************
  375. '*  The GetKeyVals SUB gathers the Keys for searching on a combined index. *
  376. '*  It shows the fields as they are entered.                               *
  377. '*                                Parameters                               *
  378. '*  TablesRec   Contains all the information for the tables                *
  379. '*  Key1        Represents the Title field of BookStock table              *
  380. '*  Key2        Represents the Author field of BookStock table             *
  381. '*  Key3        Represents the IDnum field of BookStock table              *
  382. '*  Letter      Holds the first letter the user tries to enter at prompt   *
  383. '***************************************************************************
  384. SUB GetKeyVals (TablesRec AS RecStruct, Key1$, Key2$, Key3#, Letter$)
  385.   WhichTable = TablesRec.TableNum
  386.   Prompt$ = "Value to Seek: "
  387.  
  388.   CALL DrawScreen(WhichTable)
  389.   DO
  390.     ' Have the user ENTER the Title value to search for
  391.     COLOR BACKGROUND, FOREGROUND
  392.     LOCATE TITLEFIELD, 18
  393.     PRINT "Please enter the Title to find"
  394.     Key1$ = MakeString$(ASC(Letter$), Prompt$)
  395.     CALL ShowIt(TablesRec, "TitleIndexBS", WhichTable, Key1$)
  396.   LOOP UNTIL Key1$ <> ""
  397.  
  398.   Letter$ = " "    ' Set it to a blank space for typing
  399.  
  400.     ' Have the user ENTER the Author value to search for
  401.   DO
  402.     COLOR BACKGROUND, FOREGROUND
  403.     LOCATE AUTHORFIELD, 18
  404.     PRINT "Please enter the Author name to find"
  405.     Key2$ = MakeString$(ASC(Letter$), Prompt$)
  406.     ' Show it just shows the input user has entered, not a record from file
  407.     CALL ShowIt(TablesRec, "AuthorIndexBS", WhichTable, Key2$)
  408.   LOOP UNTIL Key2$ <> ""
  409.  
  410.   Letter$ = " "    ' Set it to a blank space for typing
  411.     ' Have the user ENTER the ID number value to search for
  412.   DO
  413.     COLOR BACKGROUND, FOREGROUND
  414.     LOCATE IDFIELD, 18
  415.     PRINT "Please enter the ID number to find"
  416.     ValueToSeek$ = MakeString$(ASC(Letter$), Prompt$)
  417.     Key3# = CDBL(VAL(ValueToSeek$))       ' CURRENCY field
  418.     CALL ShowIt(TablesRec, "IDIndex", WhichTable, ValueToSeek$)
  419. LOOP UNTIL Key3# <> 0
  420. END SUB
  421.  
  422. '****************************** GetOperand FUNCTION ************************
  423. '* The GetOperand FUNCTION displays a choice of operators to allow user a  *
  424. '* choice in how a SEEKoperand search will be conducted. If the user makes *
  425. '* a valid choice, it is assigned to HoldOperand. An invalid choice or a   *
  426. '* choice of ESC results in "<>" being passed back. This permits an exit   *
  427. '* from the function (which is recursive). Otherwise, the user's choice is *
  428. '* trapped in HoldOperand when ENTER is pressed.                           *
  429. '* Note that this function is recursive so use the calls menu to keep      *
  430. '* track of the nesting depth when stepping through it. Unlike PlaceCursor *
  431. '* GetOperand doesn't keep track of the stack - the stack set should be OK.*
  432. '*                              Parameters                                 *
  433. '*   HoldOperand    Contains operand to check each time function calls     *
  434. '*                  itself; Let's user ESC from function if desired.       *
  435. '***************************************************************************
  436. FUNCTION GetOperand% (HoldOperand$)
  437.   STATIC WhichOne     ' Keep track of which case from call to call
  438.  
  439.   ' If user has chose ESC then exit back to caller
  440.   IF HoldOperand$ = "<>" THEN WhichOne = 0: EXIT FUNCTION
  441.  
  442.   ' if this is the first time through the function then
  443.   ' Replace the Sort Order box with box of operand choices
  444.   IF WhichOne = 0 THEN
  445.     RESTORE OperandBox
  446.     FOR Row = BOXTOP TO BOXEND
  447.       LOCATE Row, 42
  448.       READ Temp$
  449.       PRINT Temp$
  450.       IF Row = BOXEND THEN
  451.         COLOR FOREGROUND + BRIGHT, BACKGROUND
  452.         LOCATE Row, INDBOX + 5
  453.         PRINT "Relationship to Key"
  454.       END IF
  455.     NEXT Row
  456.     LOCATE VLINE, 44
  457.     PRINT "Equal To     Value Entered"     ' This is default --- if user
  458.     COLOR FOREGROUND, BACKGROUND           ' presses ENTER without tabbing,
  459.   END IF                                   ' SeekRecord sets the operand
  460.                                            ' to =    Note: a more flexible
  461.                                            ' default choice might be >=
  462.  
  463.   Alert$ = "Now press TAB to select how search should be conducted"
  464.   CALL ShowMessage(Alert$, 0)
  465.   DO
  466.   Answer$ = INKEY$
  467.   LOOP WHILE Answer$ <> CHR$(TABKEY) AND Answer$ <> CHR$(ENTER) AND Answer$ <> CHR$(ESCAPE)
  468.  
  469.   IF LEN(Answer$) = 1 THEN
  470.     SELECT CASE ASC(Answer$)
  471.       CASE TABKEY
  472.         SELECT CASE WhichOne
  473.           CASE 0
  474.             COLOR FOREGROUND, BACKGROUND
  475.             LOCATE VLINE, 44
  476.             PRINT "Equal To"
  477.             COLOR BRIGHT + FOREGROUND, BACKGROUND
  478.             LOCATE RLINE, 44
  479.             PRINT "Greater Than"
  480.             WhichOne = WhichOne + 1
  481.             HoldOperand$ = ">"
  482.           CASE 1
  483.             COLOR BRIGHT + FOREGROUND, BACKGROUND
  484.             LOCATE VLINE, 44
  485.             PRINT "Equal To"
  486.             LOCATE WLINE, 44
  487.             PRINT "or"
  488.             WhichOne = WhichOne + 1
  489.             HoldOperand$ = ">="
  490.           CASE 2
  491.             COLOR FOREGROUND, BACKGROUND
  492.             LOCATE RLINE, 44
  493.             PRINT "Greater Than"
  494.             LOCATE WLINE, 44
  495.             PRINT "or"
  496.             COLOR BRIGHT + FOREGROUND, BACKGROUND
  497.             LOCATE ALINE, 44
  498.             PRINT "or"
  499.             LOCATE ELINE, 44
  500.             PRINT "Less Than"
  501.             WhichOne = WhichOne + 1
  502.             HoldOperand$ = "<="
  503.           CASE 3
  504.             COLOR FOREGROUND, BACKGROUND
  505.             LOCATE VLINE, 44
  506.             PRINT "Equal To"
  507.             LOCATE ALINE, 44
  508.             PRINT "or"
  509.             WhichOne = WhichOne + 1
  510.             HoldOperand$ = "<"
  511.             SLEEP
  512.           CASE 4
  513.             COLOR FOREGROUND, BACKGROUND
  514.             LOCATE ELINE, 44
  515.             PRINT "Less Than"
  516.             COLOR BRIGHT + FOREGROUND, BACKGROUND
  517.             LOCATE VLINE, 44
  518.             PRINT "Equal To     Value Entered"
  519.             WhichOne = WhichOne + 1
  520.             HoldOperand$ = "="
  521.           CASE ELSE
  522.         END SELECT                          ' If no choice was made, call
  523.         IF WhichOne > 4 THEN WhichOne = 0   ' GetOperand again
  524.         COLOR FOREGROUND, BACKGROUND
  525.         OK = GetOperand%(HoldOperand$)
  526.       CASE ENTER
  527.         WhichOne = 0
  528.         EXIT FUNCTION
  529.     CASE ESCAPE                 ' If user chooses ESC, signal the function
  530.       HoldOperand$ = "<>"       ' to exit and keep exiting back through
  531.       GetOperand% = 0           ' all levels of recursion
  532.       WhichOne = 0
  533.     CASE ELSE                   ' If user chooses invalid key, try again
  534.       BEEP
  535.       CALL ShowMessage("Use TAB to select relationship to search for...", 0)
  536.       COLOR white, BACKGROUND
  537.       OK = GetOperand%(HoldOperand$)
  538.   END SELECT
  539. ELSE
  540. END IF
  541.  
  542. END FUNCTION
  543.  
  544. '***************************************************************************
  545. '*  The IndexBox SUB highlights the proper index name in the Current Index *
  546. '*  box at the bottom right section of the screen.                         *
  547. '                                                                          *
  548. '*  TablesRec   RecStruct type variable containing all table information   *
  549. '*  MoveDown    Integer representing line on which index name resides      *
  550. '***************************************************************************
  551. SUB Indexbox (TablesRec AS RecStruct, MoveDown)
  552.    Table = TablesRec.TableNum
  553.    COLOR BRIGHT + FOREGROUND, BACKGROUND
  554.    LOCATE 17 + MoveDown, 44
  555.    SELECT CASE MoveDown
  556.      CASE 0
  557.       IF Table = cBookStockTableNum THEN PRINT "By Titles   " ELSE PRINT "By Name    "
  558.       COLOR FOREGROUND, BACKGROUND
  559.       LOCATE ELINE, 44
  560.       PRINT "Default = Insertion Order"
  561.      CASE 1
  562.       IF Table = cBookStockTableNum THEN PRINT "By Authors   "
  563.       COLOR FOREGROUND, BACKGROUND
  564.       LOCATE NLINE, 44
  565.       IF Table = cBookStockTableNum THEN PRINT "By Titles   " ELSE PRINT "By Name     "
  566.      CASE 2
  567.       IF Table = cBookStockTableNum THEN PRINT "By Publishers   "
  568.       COLOR FOREGROUND, BACKGROUND
  569.       LOCATE RLINE, 44
  570.       IF Table = cBookStockTableNum THEN PRINT "By Authors    "
  571.      CASE 3
  572.       IF Table = cCardHoldersTableNum THEN
  573.         LOCATE RLINE, 44
  574.         PRINT "By States     "
  575.         COLOR FOREGROUND, BACKGROUND
  576.         LOCATE NLINE, 44
  577.         PRINT "By Names     "
  578.       ELSE
  579.         COLOR FOREGROUND, BACKGROUND
  580.         LOCATE WLINE, 44
  581.         PRINT "By Publishers"
  582.       END IF
  583.      CASE 4
  584.       IF Table = cCardHoldersTableNum THEN
  585.         LOCATE WLINE, 44
  586.         PRINT "By Zipcodes   "
  587.         COLOR FOREGROUND, BACKGROUND
  588.         LOCATE RLINE, 44
  589.         PRINT "By States     "
  590.       END IF
  591.      CASE 5
  592.       LOCATE VLINE, 44
  593.       IF Table = cBookStockTableNum THEN
  594.         PRINT "By ID Numbers   "
  595.         COLOR FOREGROUND, BACKGROUND
  596.       ELSE
  597.         PRINT "By Card numbers   "
  598.         COLOR FOREGROUND, BACKGROUND
  599.         LOCATE WLINE, 44
  600.         PRINT "By Zipcodes    "
  601.       END IF
  602.      CASE 6
  603.       IF Table = cBookStockTableNum THEN
  604.         LOCATE ALINE, 44
  605.         PRINT "By Title + Author + ID"
  606.         COLOR FOREGROUND, BACKGROUND
  607.         LOCATE VLINE, 44
  608.         PRINT "By ID Numbers"
  609.       ELSE
  610.         LOCATE VLINE, 44
  611.         COLOR FOREGROUND, BACKGROUND
  612.         PRINT "By Card numbers   "
  613.       END IF
  614.      COLOR FOREGROUND, BACKGROUND
  615.      CASE 7
  616.       LOCATE ELINE, 44
  617.       PRINT "Default = Insertion Order"
  618.       COLOR FOREGROUND, BACKGROUND
  619.       IF Table = cBookStockTableNum THEN
  620.         LOCATE ALINE, 44
  621.         PRINT "By Title + Author + ID"
  622.       ELSE
  623.         LOCATE VLINE, 44
  624.         PRINT "By Card numbers"
  625.       END IF
  626.     END SELECT
  627.    IF MoveDown < 7 THEN
  628.     MoveDown = MoveDown + 1
  629.    ELSE
  630.     MoveDown = 0
  631.    END IF
  632. COLOR FOREGROUND, BACKGROUND
  633. END SUB
  634.  
  635. '***************************************************************************
  636. '* The OrderCursor FUNCTION returns TRUE or FALSE for user index choice.   *
  637. '* Each time the user places the cursor on an Index to sort on, this       *
  638. '* function displays an instruction message in the field(s) corresponding  *
  639. '* to the Index, It then associates the highlighted index name (in the     *
  640. '* Sorting Order box) with the name it is known by in the program, and     *
  641. '* places that name in the .WhichIndex element of a structured variable of *
  642. '* RecStruct type.                                                         *
  643. '*                                   Parameters:                           *
  644. '* Index       Integer telling which index user has highlighted            *
  645. '* NextField   Manifest Constant telling big cursor field position         *
  646. '* Job         Manifest Constant indicating task being performed           *
  647. '* TablesRec   Variable of RecStruct type, whose .WhichInded element is    *
  648. '*             used to return the index name to be used by SETINDEX.       *
  649. '***************************************************************************
  650. FUNCTION OrderCursor (Index%, NextField%, Job%, TablesRec AS RecStruct, Letter$)
  651.   OrderCursor = FALSE
  652.   CALL Indexbox(TablesRec, Index)         ' Light up the new index
  653.   COLOR BACKGROUND, BRIGHT + FOREGROUND   ' in Sorting Order box
  654.   LOCATE NextField, 18
  655.   IF Job = REORDER THEN         ' Tell the user what is expected of him
  656.  
  657.     IF TablesRec.TableNum = cBookStockTableNum THEN
  658.       IF NextField <> PRICEFIELD AND NextField <> EDFIELD THEN
  659.         PRINT "Press enter to resort, or TAB to move on"
  660.       ELSE
  661.         LOCATE NextField, 20 '19
  662.         PRINT "Sorry, cannot sort on an unindexed field"
  663.       END IF
  664.     ELSE
  665.       IF NextField <> STREETFIELD AND NextField <> CITYFIELD THEN
  666.         PRINT "Press enter to resort, or TAB to move on"
  667.       ELSE
  668.         PRINT "Sorry, cannot sort on an unindexed field"
  669.       END IF
  670.     END IF
  671.    END IF
  672.  
  673.         ' The following places the name of the index to sort on in the
  674.         ' WhichIndex element of the structured variable TablesRec --- it
  675.         ' retrieved at the module-level code
  676.  
  677.         LOCATE NextField, 18
  678.         SELECT CASE NextField
  679.           CASE TITLEFIELD, NAMEFIELD
  680.             IF Job = SEEKFIELD THEN
  681.               IF TablesRec.TableNum = cBookStockTableNum THEN
  682.                 PRINT "Type Title to search for, or press TAB to move on"
  683.               ELSE
  684.                 PRINT "Type Name to search for, or press TAB to move on"
  685.               END IF
  686.             END IF
  687.             IF ConfirmEntry%(Letter$) THEN
  688.               IF TablesRec.TableNum = cBookStockTableNum THEN
  689.                 TablesRec.WhichIndex = "TitleIndexBS"
  690.               ELSE
  691.                 TablesRec.WhichIndex = "NameIndexCH"
  692.               END IF
  693.               OrderCursor = TRUE
  694.               EXIT FUNCTION
  695.             ELSE
  696.               OrderCursor = FALSE
  697.               NextField% = AUTHORFIELD
  698.             END IF
  699.           CASE AUTHORFIELD, STREETFIELD
  700.             IF Job = SEEKFIELD THEN
  701.               IF TablesRec.TableNum = cBookStockTableNum THEN
  702.                 PRINT "Type Author name to search for, or TAB to move on"
  703.               ELSE
  704.                 PRINT "Sorry, can't search on an unindexed field"
  705.               END IF
  706.             END IF
  707.             IF ConfirmEntry%(Letter$) THEN
  708.               IF TablesRec.TableNum = cBookStockTableNum THEN
  709.                 TablesRec.WhichIndex = "AuthorIndexBS"
  710.               END IF
  711.               OrderCursor = TRUE
  712.               EXIT FUNCTION
  713.             ELSE
  714.               OrderCursor = FALSE
  715.               NextField% = PUBFIELD
  716.             END IF
  717.           CASE PUBFIELD, CITYFIELD
  718.             IF Job = SEEKFIELD THEN
  719.               IF TablesRec.TableNum = cBookStockTableNum THEN
  720.                 PRINT "Type Publisher name to search for, or TAB to move on"
  721.               ELSE
  722.                 PRINT "Sorry, can't search on an unindexed field"
  723.               END IF
  724.             END IF
  725.             IF ConfirmEntry%(Letter$) THEN
  726.               IF TablesRec.TableNum = cBookStockTableNum THEN
  727.                 TablesRec.WhichIndex = "PubIndexBS"
  728.               END IF
  729.               OrderCursor = TRUE
  730.               EXIT FUNCTION
  731.             ELSE
  732.               OrderCursor = FALSE
  733.               NextField% = EDFIELD
  734.             END IF
  735.           CASE EDFIELD, STATEFIELD
  736.             IF Job = SEEKFIELD THEN
  737.               IF TablesRec.TableNum = cCardHoldersTableNum THEN
  738.                 PRINT "Type State (2 letters), or TAB to move on"
  739.               ELSE
  740.                 PRINT "Sorry, can't search on an unindexed field"
  741.               END IF
  742.             END IF
  743.             IF ConfirmEntry%(Letter$) THEN
  744.               IF TablesRec.TableNum = cCardHoldersTableNum THEN
  745.                 TablesRec.WhichIndex = "StateIndexCH"
  746.               END IF
  747.               OrderCursor = TRUE
  748.               EXIT FUNCTION
  749.             ELSE
  750.               OrderCursor = FALSE
  751.               NextField% = PRICEFIELD
  752.             END IF
  753.           CASE PRICEFIELD, ZIPFIELD
  754.             IF Job = SEEKFIELD THEN
  755.               IF TablesRec.TableNum = cCardHoldersTableNum THEN
  756.                 PRINT "Type Zipcode to search for, or TAB to move on"
  757.               ELSE
  758.                 LOCATE PRICEFIELD, 20
  759.                 PRINT "Sorry, can't search on an unindexed field"
  760.               END IF
  761.             END IF
  762.             IF ConfirmEntry%(Letter$) THEN
  763.               IF TablesRec.TableNum = cCardHoldersTableNum THEN
  764.                 TablesRec.WhichIndex = "ZipIndexCH"
  765.               END IF
  766.               OrderCursor = TRUE
  767.               EXIT FUNCTION
  768.             ELSE
  769.               OrderCursor = FALSE
  770.               NextField% = IDFIELD
  771.             END IF
  772.           CASE IDFIELD, CARDNUMFIELD
  773.             IF Job = SEEKFIELD THEN
  774.               IF TablesRec.TableNum = cBookStockTableNum THEN
  775.                 PRINT "Type ID number to search for, or TAB to move on"
  776.               ELSE
  777.                 PRINT "Type Card number to seek, or press TAB to move on"
  778.               END IF
  779.             END IF
  780.             ' Setting Letter$ to "" may be unnecessary now
  781.             Letter$ = ""
  782.             IF ConfirmEntry%(Letter$) THEN
  783.               IF TablesRec.TableNum = cBookStockTableNum THEN
  784.                 TablesRec.WhichIndex = "IDIndex"
  785.               ELSE
  786.                 TablesRec.WhichIndex = "CardNumIndexCH"
  787.               END IF
  788.               OrderCursor = TRUE
  789.               EXIT FUNCTION
  790.             ELSE
  791.               OrderCursor = FALSE
  792.               NextField% = BIGINDEX
  793.             END IF
  794.         END SELECT
  795.  IF Letter$ = "eScApE" THEN OrderCursor = 3: FirstLetter$ = ""
  796. END FUNCTION
  797.  
  798. '***************************************************************************
  799. '*  The PlaceCursor FUNCTION lets the user tab around on the displayed form*
  800. '*  when performing field-specific operations on the table. Since this     *
  801. '*  function is recursive it keeps track of available stack space. The two *
  802. '*  major possibilities are SEEKs/REORDERs (for which OrderCursor is then  *
  803. '*  called) and EDIT/ADD records (for which EdAddCursor is called. Note    *
  804. '*  the combined index (BigIndex) and the default index are handled as     *
  805. '*  special cases, since they don't correspond to a single field.Recursive *
  806. '*  construction lets the user cycle through the fields as long as         *
  807. '*  sufficient stack remains to keep calling PlaceCursor. Note that since  *
  808. '*  it is recursive, it may take while to step out while stepping with F8. *
  809. '*                                Parameters                               *
  810. '*  WhichField    Integer identifier specifying current field on form      *
  811. '*  TablesRec     Variable of type RecStruct holding all table information *
  812. '*  FirstLetter$  Carries user response to initial prompt shown            *
  813. '*  FirstTime     Boolean telling whether this is first cal or recursion   *
  814. '*  Task          Tells operation being performed                          *
  815. '***************************************************************************
  816. '
  817. FUNCTION PlaceCursor% (WhichField, TablesRec AS RecStruct, FirstLetter$, FirstTime AS INTEGER, Task AS INTEGER)
  818. STATIC ReturnValue, InitialLetter$, GetOut, counter, WhichOne
  819. WhichTable = TablesRec.TableNum
  820. IF ExitFlag THEN EXIT FUNCTION
  821.  
  822. ReturnValue = WhichField
  823. ' Keep tabs on the stack and exit and reset it if it gets too low
  824. IF FRE(-2) < 400 THEN
  825.   WhichField = 0
  826.   PlaceCursor = 0
  827.   GetOut = -1
  828.   EXIT FUNCTION
  829. END IF
  830.  
  831. ' Set up for each of the possible operations that use PlaceCursor
  832. IF Task = REORDER THEN
  833.    COLOR FOREGROUND, BACKGROUND
  834.    CALL ShowMessage("Press TAB to choose field to sort on, ESC to escape", 0)
  835.    IF WhichField = TITLEFIELD THEN WhichOne = 0
  836. ELSEIF Task = SEEKFIELD THEN
  837.    CALL ShowMessage("TAB to a field, then enter a value to search", 0)
  838. ELSEIF Task = ADDRECORD THEN
  839.   IF FirstTime THEN FirstLetter$ = CHR$(TABKEY) ELSE FirstLetter$ = ""
  840. END IF
  841.  
  842. ' The following IF... lets function handle either an entered letter or TAB
  843. IF FirstLetter$ <> "" THEN
  844.     Answer$ = FirstLetter$
  845. ELSEIF FirstTime THEN
  846.   IF Task = EDITRECORD THEN
  847.     Answer$ = CHR$(TABKEY)
  848.   END IF
  849. ELSE
  850.   DO
  851.   Answer$ = INKEY$
  852.   LOOP WHILE Answer$ = EMPTYSTRING
  853. END IF
  854.  
  855. IF LEN(Answer$) = 1 THEN
  856.  
  857. ' Clear the fields for the appropriate messages
  858. IF Task <> EDITRECORD AND Task <> ADDRECORD THEN
  859. CALL ClearEm(TablesRec.TableNum, 1, 1, 1, 1, 1, 1)
  860. END IF
  861.  
  862.    SELECT CASE ASC(Answer$)
  863.     CASE IS = TABKEY, ENTER
  864.            SELECT CASE WhichField
  865.             CASE TITLEFIELD, AUTHORFIELD, PUBFIELD, EDFIELD, PRICEFIELD, IDFIELD
  866.               IF Task = REORDER OR Task = SEEKFIELD THEN
  867.                 RetVal = OrderCursor(WhichOne, WhichField, Task, TablesRec, FirstLetter$)
  868.                 IF RetVal THEN
  869.                   ' trap a magic value for an escape here then call the Draw stuff
  870.                   IF RetVal <> 3 THEN
  871.                     WhichOne = 0: EXIT FUNCTION
  872.                   ELSE
  873.                     WhichOne = 0
  874.                     WhichField = 0
  875.                     PlaceCursor = 0
  876.                     CALL ShowRecord(TablesRec)
  877.                     CALL ShowMessage("You've escaped! Try again", 0)
  878.                     CALL DrawTable(WhichTable)
  879.                     CALL DrawHelpKeys(WhichTable)
  880.                     CALL ShowKeys(TablesRec, FOREGROUND + BRIGHT, 0, 0)
  881.                     EXIT FUNCTION
  882.                   END IF
  883.                 END IF
  884.               ELSEIF Task = EDITRECORD OR Task = ADDRECORD THEN
  885.                 Placed = EdAddCursor(WhichField, Task, TablesRec, FirstTime)
  886.               END IF
  887.            
  888.             CASE BIGINDEX
  889.                 CALL Indexbox(TablesRec, WhichOne)
  890.                 IF WhichTable = cBookStockTableNum THEN
  891.                   COLOR BACKGROUND, BRIGHT + FOREGROUND
  892.                   IF Task = REORDER THEN
  893.                     LOCATE TITLEFIELD, 18
  894.                     PRINT "Press ENTER to sort first by Title..."
  895.                     LOCATE AUTHORFIELD, 18
  896.                     PRINT "... then subsort by Author..."
  897.                     LOCATE IDFIELD, 18
  898.                     PRINT "... then subsort again by ID "
  899.                     SLEEP
  900.                   ELSEIF Task = SEEKFIELD THEN
  901.                     LOCATE TITLEFIELD, 18
  902.                     PRINT "First, type in the Title to search for,"
  903.                     LOCATE AUTHORFIELD, 18
  904.                     PRINT "... then type in the Author's name"
  905.                     LOCATE IDFIELD, 18
  906.                     PRINT "... then type in the ID number "
  907.                     CALL ShowMessage("Typing in a value for a combined index is tricky...", 0)
  908.                     SLEEP
  909.                   END IF
  910.                   COLOR FOREGROUND, BACKGROUND
  911.                   IF ConfirmEntry%(FirstLetter$) THEN
  912.                     TablesRec.WhichIndex = "BigIndex"
  913.                     IF Task = SEEKFIELD THEN
  914.                       WhichOne = 0
  915.                       WhichField = TITLEFIELD
  916.                     END IF
  917.                     EXIT FUNCTION
  918.                   END IF
  919.                 END IF
  920.                 CALL ClearEm(TablesRec.TableNum, 1, 1, 0, 0, 1, 0)
  921.                 WhichField = NULLINDEX   ' TITLEFIELD
  922.  
  923.             CASE NULLINDEX
  924.                 CALL Indexbox(TablesRec, WhichOne)
  925.                 IF Task = SEEKFIELD THEN
  926.                   CALL ShowMessage("Can't SEEK on the default index", 0)
  927.                   DO
  928.                     KeyIn$ = INKEY$
  929.                     IF KeyIn$ <> "" THEN
  930.                       IF ASC(KeyIn$) = ESCAPE THEN EXIT FUNCTION
  931.                     END IF
  932.                   LOOP WHILE KeyIn$ = ""
  933.                   'SLEEP
  934.                 '  EXIT FUNCTION
  935.                 'END IF
  936.                 ELSEIF ConfirmEntry%(FirstLetter$) THEN
  937.                   TablesRec.WhichIndex = "NULL"
  938.                   EXIT FUNCTION
  939.                 END IF
  940.                 WhichField = TITLEFIELD
  941.               
  942.             CASE ELSE
  943.                 EraseMessage
  944.                  CALL ShowMessage("Not a valid key --- press Space bar", 0)
  945.                 EXIT FUNCTION
  946.           END SELECT
  947.         ' Placecursor calls itself for next user response
  948.         Value = PlaceCursor(WhichField, TablesRec, FirstLetter$, 0, Task)
  949.  
  950.     CASE ESCAPE
  951.       WhichOne = 0
  952.       WhichField = 0
  953.       PlaceCursor = 0
  954.       CALL ShowRecord(TablesRec)
  955.       CALL ShowMessage("You've escaped! Try again", 0)
  956.       CALL DrawTable(WhichTable)
  957.       CALL DrawHelpKeys(WhichTable)
  958.       CALL ShowKeys(TablesRec, FOREGROUND + BRIGHT, 0, 0)
  959.       EXIT FUNCTION
  960.     CASE 32 TO 127                        ' Acceptable ASCII characters
  961.      InitialLetter$ = Answer$
  962.      FirstLetter$ = InitialLetter$
  963.      EXIT FUNCTION
  964.     CASE ELSE
  965.         BEEP
  966.         EraseMessage
  967.          CALL ShowMessage("Not a valid key --- press Space bar", 0)
  968.         WhichField = 0
  969.         PlaceCursor = 0
  970.         EXIT FUNCTION
  971.     END SELECT
  972. ELSEIF Answer$ <> CHR$(9) THEN
  973.   EraseMessage
  974.   CALL ShowMessage("Not a valid key --- press Space bar", 0)
  975.   WhichField = 0
  976.   EXIT FUNCTION
  977. ELSE
  978.      CALL ShowMessage("  Press TAB key or ENTER  ", 0)
  979. END IF
  980.  
  981. IF GetOut THEN
  982.   counter = counter + 1
  983.   IF counter < 15 THEN
  984.     WhichField = 0
  985.     WhichOne = 0
  986.     EXIT FUNCTION
  987.   ELSE
  988.     GetOut = 0
  989.     counter = 0
  990.  END IF
  991. END IF
  992.  
  993. END FUNCTION
  994.  
  995. '***************************************************************************
  996. '*  The TransposeName FUNCTION takes a  string and decideds whether it is  *
  997. '*  a comma-delimited, last-name-first name, a first-name-first name or a  *
  998. '*  single word name. In the last case, the string is returned unchanged.  *
  999. '*  In either of the other cases, the string is translated to the comple-  *
  1000. '*  mentary format.                                                        *
  1001. '*                              Parameters                                 *
  1002. '*  TheName   A string representing a CardHolders table TheName element,   *
  1003. '*            or a BookStock table Author Element                          *
  1004. '***************************************************************************
  1005. FUNCTION TransposeName$ (TheName AS STRING)
  1006. SubStrLen = (INSTR(TheName, ","))
  1007. IF SubStrLen = 0 THEN
  1008.   SubStrLen = INSTR(TheName, " ")
  1009.   IF SubStrLen = 0 THEN TransposeName$ = TheName: EXIT FUNCTION
  1010. END IF
  1011. TheName = LTRIM$(RTRIM$(TheName))
  1012.   IF INSTR(TheName, ",") THEN
  1013.     LastNameLen = INSTR(TheName, ",")
  1014.     LastName$ = LTRIM$(RTRIM$(LEFT$(TheName, LastNameLen - 1)))
  1015.     FirstName$ = LTRIM$(RTRIM$(MID$(TheName, LastNameLen + 1)))
  1016.     TransposeName$ = LTRIM$(RTRIM$(FirstName$ + " " + LastName$))
  1017.   ELSE
  1018.     FirstNameLen = INSTR(TheName, " ")
  1019.     IF FirstNameLen THEN
  1020.       FirstName$ = LTRIM$(RTRIM$(LEFT$(TheName, FirstNameLen - 1)))
  1021.       LastName$ = LTRIM$(RTRIM$(MID$(TheName, FirstNameLen + 1)))
  1022.     ELSE
  1023.       LastName$ = LTRIM$(RTRIM$(TheName))
  1024.     END IF
  1025.     TransposeName$ = LTRIM$(RTRIM$(LastName$ + ", " + FirstName$))
  1026.   END IF
  1027. END FUNCTION
  1028.  
  1029. '****************************** ValuesOK FUNCTION **************************
  1030. '* The ValuesOK FUNCTION checks the values input by the user for various   *
  1031. '* purposes. The checking is very minimal and checks the format of what is *
  1032. '* entered. For example, the IDnum field needs a double value, but the form*
  1033. '* (5 digits, followed by a decimal point, followed by 4 digits) is more   *
  1034. '* important than the data type.                                           *
  1035. '*                                Parameters:                              *
  1036. '*   Big Rec      User-defined type containing all table information       *
  1037. '*   Key1, Key2   Represent strings to check                               *
  1038. '*   ValueToSeek  Represents the final value of a combined index           *
  1039. '***************************************************************************
  1040. FUNCTION ValuesOK (BigRec AS RecStruct, Key1$, Key2$, ValueToSeek$)
  1041.   IndexName$ = BigRec.WhichIndex
  1042.   ValueToSeek$ = LTRIM$(RTRIM$(ValueToSeek$))
  1043.   SELECT CASE RTRIM$(LTRIM$(IndexName$))
  1044.     CASE "TitleIndexBS", "PubIndexBS"       ' LEN <= 50
  1045.       IF LEN(Key1$) > 50 THEN ValuesOK = FALSE: EXIT FUNCTION
  1046.  
  1047.     CASE "AuthorIndexBS", "NameIndexCH"     ' LEN <= 36
  1048.       IF LEN(Key1$) > 36 THEN ValuesOK = FALSE: EXIT FUNCTION
  1049.  
  1050.     CASE "StateIndexCH"                     ' LEN = 2
  1051.       IF LEN(Key1$) > 2 THEN ValuesOK = FALSE: EXIT FUNCTION
  1052.  
  1053.     CASE "IDIndex", "IDIndexBO"             ' 5 digits befor d.p., 4 after
  1054.       IF LEN(ValueToSeek$) <> 10 THEN ValuesOK = FALSE: EXIT FUNCTION
  1055.       IF MID$(ValueToSeek$, 6, 1) <> "." THEN
  1056.         ValuesOK = FALSE: EXIT FUNCTION
  1057.       END IF
  1058.     CASE "CardNumIndexCH", "CardNumIndexBO" ' 5 digits, value <= LONG
  1059.       IF LEN(ValueToSeek$) <> 5 THEN ValuesOK = FALSE: EXIT FUNCTION
  1060.  
  1061.     CASE "ZipIndexCH"                       ' 5 digits, value <= LONG
  1062.       IF LEN(ValueToSeek$) <> 5 THEN ValuesOK = FALSE: EXIT FUNCTION
  1063.  
  1064.     CASE "BigIndex"                         ' Key1$ <= 50, Key2$ <= 36
  1065.       IF LEN(Key1$) > 50 THEN ValuesOK = FALSE: EXIT FUNCTION
  1066.       IF LEN(Key2$) > 36 THEN ValuesOK = FALSE: EXIT FUNCTION
  1067.       IF MID$(ValueToSeek$, 6, 1) <> "." THEN
  1068.         ValuesOK = FALSE: EXIT FUNCTION
  1069.       END IF
  1070.   END SELECT
  1071.   ValuesOK = TRUE
  1072. END FUNCTION
  1073.  
  1074.