home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progc / c_all592.arj / TI416.ASC < prev    next >
Text File  |  1991-08-27  |  6KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  TURBO BASIC                            NUMBER  :  416
  9.   VERSION  :  1.1
  10.    OS  :  PC-DOS
  11.    DATE  :  January 5, 1988                            PAGE  :  1/4
  12.  
  13.    TITLE  :  CREATING MULTIPLE INDICES
  14.  
  15.  
  16.  
  17.  
  18.   This  program  shows  you how to create multiple indices with the
  19.   Turbo Basic Database Toolbox.
  20.  
  21.   The program creates a data file for which each record  contains a
  22.   field  for a person's first name, last  name  and  an  associated
  23.   number. Each of these three  fields has an associated index file.
  24.   The first index  file  is created with high-level TB-Access calls
  25.   and the next two index files are created with low-level TB-Access
  26.   calls. Only the first index file can be  created  with high-level
  27.   TB-Access calls.  All subsequent index files must be created with
  28.   low-level TB-Access calls.
  29.  
  30.   CLS
  31.   DEFINT A - Z
  32.  
  33.   CALL  dbInit           'initialize TB-Access constants
  34.  
  35.   IF Client.File > 0 THEN GOTO EndClientInc 'skip if already open
  36.     INCR LastFileNum
  37.     Client.File = LastFileNum
  38.  
  39.  
  40.   'Creates the data file and the index file for first name
  41.   'using high-level TB-Access calls
  42.  
  43.     CALL dbCreate(Client.File, FileNo, _
  44.       "Example.DBI", 15, "Example.DBD", 40)
  45.  
  46.     IF dbStatus = %FileAlreadyCreated THEN _
  47.       CALL dbOpen(Client.File, FileNo,      _
  48.         "Example.DBI", 15, 40)
  49.  
  50.     FIELD FileNo,_
  51.         04 AS Client.Skip$,_
  52.         15 AS First$,_
  53.         15 AS Last$,_
  54.         05 AS S.Num$
  55.  
  56.   EndClientInc:
  57.  
  58.   'Creates the index file for last name using
  59.   'low-level TB-Access calls.
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  TURBO BASIC                            NUMBER  :  416
  75.   VERSION  :  1.1
  76.    OS  :  PC-DOS
  77.    DATE  :  January 5, 1988                            PAGE  :  1/4
  78.  
  79.    TITLE  :  CREATING MULTIPLE INDICES
  80.  
  81.  
  82.  
  83.  
  84.     INCR LastFileNum
  85.     CLIENT.Aux1 = LastFileNum
  86.  
  87.     CALL MakeIndex(CLIENT.Aux1, "Example.DB1", 15, _
  88.          "Example.DBD", 40, -1)
  89.  
  90.     IF dbStatus = %FileAlreadyCreated THEN _
  91.       CALL OpenIndex(CLIENT.Aux1, "Example.DB1", 15, _
  92.            "Example.DBD", 40, -1)
  93.  
  94.   'Creates the index file for the associated number
  95.   'using low-level TB-Access calls.
  96.  
  97.     INCR LastFileNum
  98.     CLIENT.Aux2 = LastFileNum
  99.     CALL MakeIndex(CLIENT.Aux2, "Example.DB2", 15, _
  100.         "Example.DBD", 40, -1)
  101.  
  102.     IF dbStatus = %FileAlreadyCreated THEN _
  103.       CALL OpenIndex(CLIENT.Aux2, "Example.DB2",15, _
  104.            "Example.DBD", 40, -1)
  105.  
  106.   'Sets the file pointer to the beginning of each index file
  107.  
  108.     CALL ClearKey(Client.Aux2)
  109.     CALL ClearKey(Client.File)
  110.     CALL ClearKey(Client.Aux1)
  111.  
  112.   INPUT "Enter the number of clients";ClientNum
  113.   FOR I% = 1 TO ClientNum
  114.     INPUT "Enter First Name  :";TFirst$
  115.     INPUT "Enter Last  Name  :";TLast$
  116.     INPUT "Enter Number      :";TS.Num$
  117.     LSET First$ = TFirst$
  118.     LSET Last$  = TLast$
  119.     'RSET is used to insure that the associated numbers are output
  120.     'in numeric ascending order.
  121.     'For example, if the numbers 1, 2, 10 and 11 are entered in any
  122.     'order the effect of the LSET and RSET statements on the
  123.     'associated number field is shown below.
  124.  
  125.     '  Using LSET                               Using RSET
  126.     '       1                                        1
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  TURBO BASIC                            NUMBER  :  416
  141.   VERSION  :  1.1
  142.    OS  :  PC-DOS
  143.    DATE  :  January 5, 1988                            PAGE  :  1/4
  144.  
  145.    TITLE  :  CREATING MULTIPLE INDICES
  146.  
  147.  
  148.  
  149.  
  150.     '       10                                       2
  151.     '       11                                      10
  152.     '       2                                       11
  153.  
  154.     'The ASCII code for a blank is less than the ASCII code for any
  155.     'numeral so CHR$(32) + CHR$(50) <  CHR$(49) + CHR$(48).
  156.     'For more information on the RSET statement refer to page 330
  157.     'of the Turbo Basic reference manual.
  158.  
  159.     RSET S.Num$ = TS.Num$
  160.  
  161.     CALL dbWrite(Client.File, First$)
  162.     CALL AddKey(Client.Aux1, DataRef&, Last$)
  163.     CALL AddKey(Client.Aux2, DataRef&, S.Num$)
  164.   NEXT I%
  165.  
  166.   CLS
  167.   PRINT "FIRST NAME INDEX"
  168.   PRINT "================"
  169.         CALL ClearKey(Client.File)
  170.         CALL dbNext(Client.File, First$)
  171.         WHILE dbStatus = 0
  172.           PRINT First$; "  "; Last$;" ";S.Num$; " "
  173.           CALL dbNext(Client.FIle, First$)
  174.         WEND
  175.   PRINT "LAST NAME INDEX"
  176.   PRINT "==============="
  177.         CALL ClearKey(Client.Aux1)
  178.         CALL NextKey(Client.Aux1, DataRef&, KeyVal$)
  179.         WHILE dbStatus = 0
  180.           CALL GetRec(Client.File, DataRef&)
  181.           PRINT First$; "  "; Last$;" ";S.Num$; " "
  182.           CALL NextKey(Client.Aux1, DataRef&, KeyVal$)
  183.         WEND
  184.  
  185.   PRINT "NUMBER INDEX"
  186.   PRINT "============"
  187.         CALL ClearKey(Client.Aux2)
  188.         CALL NextKey(Client.Aux2, DataRef&, KeyVal$)
  189.         WHILE dbStatus = 0
  190.           CALL GetRec(Client.File, DataRef&)
  191.           PRINT First$; "  "; Last$;" ";S.Num$; " "
  192.           CALL NextKey(Client.Aux2, DataRef&, KeyVal$)
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  TURBO BASIC                            NUMBER  :  416
  207.   VERSION  :  1.1
  208.    OS  :  PC-DOS
  209.    DATE  :  January 5, 1988                            PAGE  :  1/4
  210.  
  211.    TITLE  :  CREATING MULTIPLE INDICES
  212.  
  213.  
  214.  
  215.  
  216.         WEND
  217.  
  218.   CALL dbClose(Client.File)
  219.   CALL CloseIndex(Client.Aux1)
  220.   CALL CloseIndex(Client.Aux2)
  221.  
  222.  
  223.   $INCLUDE "DBHIGH.BOX" 'High-level Access calls
  224.   $INCLUDE "DBLOW.BOX"  'Low-level Access calls
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.