home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / MISCTI10.ZIP / TI416.ASC < prev    next >
Encoding:
Text File  |  1988-05-02  |  5.0 KB  |  169 lines

  1.  
  2.   TITLE  :  CREATING MULTIPLE INDICES
  3.  
  4. This program shows you how to create multiple indices with the
  5. Turbo Basic Database Toolbox.
  6.  
  7. The program creates a data file for which each record contains a
  8. field for a person's first name, last name and an associated
  9. number. Each of these three fields has an associated index file.
  10. The first index file is created with high-level TB-Access calls
  11. and the next two index files are created with low-level TB-Access
  12. calls. Only the first index file can be created with high-level
  13. TB-Access calls. All subsequent index files must be created with
  14. low-level TB-Access calls.
  15.  
  16. CLS
  17. DEFINT A - Z
  18.  
  19. CALL  dbInit           'initialize TB-Access constants
  20.  
  21. IF Client.File > 0 THEN GOTO EndClientInc 'skip if already open
  22.   INCR LastFileNum
  23.   Client.File = LastFileNum
  24.  
  25.  
  26. 'Creates the data file and the index file for first name
  27. 'using high-level TB-Access calls
  28.  
  29.   CALL dbCreate(Client.File, FileNo, _
  30.     "Example.DBI", 15, "Example.DBD", 40)
  31.  
  32.   IF dbStatus = %FileAlreadyCreated THEN _
  33.     CALL dbOpen(Client.File, FileNo,      _
  34.       "Example.DBI", 15, 40)
  35.  
  36.   FIELD FileNo,_
  37.       04 AS Client.Skip$,_
  38.       15 AS First$,_
  39.       15 AS Last$,_
  40.       05 AS S.Num$
  41.  
  42. PRODUCT : TURBO BASIC                              Number 416
  43. VERSION : 1.1
  44.      OS : PC-DOS
  45.    DATE : January 5, 1988                          Page 2/4
  46.  
  47.   TITLE : CREATING MULTIPLE INDICES
  48. ------------------------------------------------------------------
  49.  
  50.  
  51. EndClientInc:
  52.  
  53.  
  54. 'Creates the index file for last name using
  55. 'low-level TB-Access calls.
  56.  
  57.   INCR LastFileNum
  58.   CLIENT.Aux1 = LastFileNum
  59.  
  60.   CALL MakeIndex(CLIENT.Aux1, "Example.DB1", 15, _
  61.        "Example.DBD", 40, -1)
  62.  
  63.   IF dbStatus = %FileAlreadyCreated THEN _
  64.     CALL OpenIndex(CLIENT.Aux1, "Example.DB1", 15, _
  65.          "Example.DBD", 40, -1)
  66.  
  67. 'Creates the index file for the associated number
  68. 'using low-level TB-Access calls.
  69.  
  70.   INCR LastFileNum
  71.   CLIENT.Aux2 = LastFileNum
  72.   CALL MakeIndex(CLIENT.Aux2, "Example.DB2", 15, _
  73.       "Example.DBD", 40, -1)
  74.  
  75.   IF dbStatus = %FileAlreadyCreated THEN _
  76.     CALL OpenIndex(CLIENT.Aux2, "Example.DB2",15, _
  77.          "Example.DBD", 40, -1)
  78.  
  79. 'Sets the file pointer to the beginning of each index file
  80.  
  81.   CALL ClearKey(Client.Aux2)
  82.   CALL ClearKey(Client.File)
  83.   CALL ClearKey(Client.Aux1)
  84.  
  85. INPUT "Enter the number of clients";ClientNum
  86. FOR I% = 1 TO ClientNum
  87.   INPUT "Enter First Name  :";TFirst$
  88.   INPUT "Enter Last  Name  :";TLast$
  89.   INPUT "Enter Number      :";TS.Num$
  90.  
  91. PRODUCT : TURBO-BASIC                                 Number 416
  92. VERSION : 1.1
  93.      OS : PC-DOS
  94.    DATE : January 5, 1988                             Page 3/4
  95. ------------------------------------------------------------------
  96.  
  97.  
  98.   LSET First$ = TFirst$
  99.   LSET Last$  = TLast$
  100.   'RSET is used to insure that the associated numbers are output
  101.   'in numeric ascending order.
  102.   'For example, if the numbers 1, 2, 10 and 11 are entered in any
  103.   'order the effect of the LSET and RSET statements on the
  104.   'associated number field is shown below.
  105.  
  106.   '  Using LSET                               Using RSET
  107.   '       1                                        1
  108.   '       10                                       2
  109.   '       11                                      10
  110.   '       2                                       11
  111.  
  112.   'The ASCII code for a blank is less than the ASCII code for any
  113.   'numeral so CHR$(32) + CHR$(50) <  CHR$(49) + CHR$(48). 
  114.   'For more information on the RSET statement refer to page 330 
  115.   'of the Turbo Basic reference manual.
  116.  
  117.   RSET S.Num$ = TS.Num$
  118.  
  119.   CALL dbWrite(Client.File, First$)
  120.   CALL AddKey(Client.Aux1, DataRef&, Last$)
  121.   CALL AddKey(Client.Aux2, DataRef&, S.Num$)
  122. NEXT I%
  123.  
  124. CLS
  125. PRINT "FIRST NAME INDEX"
  126. PRINT "================"
  127.       CALL ClearKey(Client.File)
  128.       CALL dbNext(Client.File, First$)
  129.       WHILE dbStatus = 0
  130.         PRINT First$; "  "; Last$;" ";S.Num$; " "
  131.         CALL dbNext(Client.FIle, First$)
  132.       WEND
  133.  
  134. PRODUCT : TURBO BASIC                                 Number 416
  135. VERSION : 1.1
  136.      OS : PC-DOS
  137.    DATE : January 5, 1988                             Page 4/4
  138. ------------------------------------------------------------------
  139.  
  140.  
  141. PRINT "LAST NAME INDEX"
  142. PRINT "==============="
  143.       CALL ClearKey(Client.Aux1)
  144.       CALL NextKey(Client.Aux1, DataRef&, KeyVal$)
  145.       WHILE dbStatus = 0
  146.         CALL GetRec(Client.File, DataRef&)
  147.         PRINT First$; "  "; Last$;" ";S.Num$; " "
  148.         CALL NextKey(Client.Aux1, DataRef&, KeyVal$)
  149.       WEND
  150.  
  151. PRINT "NUMBER INDEX"
  152. PRINT "============"
  153.       CALL ClearKey(Client.Aux2)
  154.       CALL NextKey(Client.Aux2, DataRef&, KeyVal$)
  155.       WHILE dbStatus = 0
  156.         CALL GetRec(Client.File, DataRef&)
  157.         PRINT First$; "  "; Last$;" ";S.Num$; " "
  158.         CALL NextKey(Client.Aux2, DataRef&, KeyVal$)
  159.       WEND
  160.  
  161. CALL dbClose(Client.File)
  162. CALL CloseIndex(Client.Aux1)
  163. CALL CloseIndex(Client.Aux2)
  164.  
  165.  
  166. $INCLUDE "DBHIGH.BOX" 'High-level Access calls
  167. $INCLUDE "DBLOW.BOX"  'Low-level Access calls
  168.  
  169.