TURBO BASIC: CREATING MULTIPLE INDICES
PRODUCT : TURBO BASIC NUMBER : 416
VERSION : 1.1
OS : PC-DOS
DATE : January 5, 1988 PAGE : 1/4
TITLE : CREATING MULTIPLE INDICES
This program shows you how to create multiple indices with the
Turbo Basic Database Toolbox.
The program creates a data file for which each record contains a
field for a person's first name, last name and an associated
number. Each of these three fields has an associated index file.
The first index file is created with high-level TB-Access calls
and the next two index files are created with low-level TB-Access
calls. Only the first index file can be created with high-level
TB-Access calls. All subsequent index files must be created with
low-level TB-Access calls.
CLS
DEFINT A - Z
CALL dbInit 'initialize TB-Access constants
IF Client.File > 0 THEN GOTO EndClientInc 'skip if already open
INCR LastFileNum
Client.File = LastFileNum
'Creates the data file and the index file for first name
'using high-level TB-Access calls
CALL dbCreate(Client.File, FileNo, _
"Example.DBI", 15, "Example.DBD", 40)
IF dbStatus = %FileAlreadyCreated THEN _
CALL dbOpen(Client.File, FileNo, _
"Example.DBI", 15, 40)
FIELD FileNo,_
04 AS Client.Skip$,_
15 AS First$,_
15 AS Last$,_
05 AS S.Num$
EndClientInc:
'Creates the index file for last name using
'low-level TB-Access calls.
PRODUCT : TURBO BASIC NUMBER : 416
VERSION : 1.1
OS : PC-DOS
DATE : January 5, 1988 PAGE : 1/4
TITLE : CREATING MULTIPLE INDICES
INCR LastFileNum
CLIENT.Aux1 = LastFileNum
CALL MakeIndex(CLIENT.Aux1, "Example.DB1", 15, _
"Example.DBD", 40, -1)
IF dbStatus = %FileAlreadyCreated THEN _
CALL OpenIndex(CLIENT.Aux1, "Example.DB1", 15, _
"Example.DBD", 40, -1)
'Creates the index file for the associated number
'using low-level TB-Access calls.
INCR LastFileNum
CLIENT.Aux2 = LastFileNum
CALL MakeIndex(CLIENT.Aux2, "Example.DB2", 15, _
"Example.DBD", 40, -1)
IF dbStatus = %FileAlreadyCreated THEN _
CALL OpenIndex(CLIENT.Aux2, "Example.DB2",15, _
"Example.DBD", 40, -1)
'Sets the file pointer to the beginning of each index file
CALL ClearKey(Client.Aux2)
CALL ClearKey(Client.File)
CALL ClearKey(Client.Aux1)
INPUT "Enter the number of clients";ClientNum
FOR I% = 1 TO ClientNum
INPUT "Enter First Name :";TFirst$
INPUT "Enter Last Name :";TLast$
INPUT "Enter Number :";TS.Num$
LSET First$ = TFirst$
LSET Last$ = TLast$
'RSET is used to insure that the associated numbers are output
'in numeric ascending order.
'For example, if the numbers 1, 2, 10 and 11 are entered in any
'order the effect of the LSET and RSET statements on the
'associated number field is shown below.
' Using LSET Using RSET
' 1 1
PRODUCT : TURBO BASIC NUMBER : 416
VERSION : 1.1
OS : PC-DOS
DATE : January 5, 1988 PAGE : 1/4
TITLE : CREATING MULTIPLE INDICES
' 10 2
' 11 10
' 2 11
'The ASCII code for a blank is less than the ASCII code for any
'numeral so CHR$(32) + CHR$(50) < CHR$(49) + CHR$(48).
'For more information on the RSET statement refer to page 330
'of the Turbo Basic reference manual.
RSET S.Num$ = TS.Num$
CALL dbWrite(Client.File, First$)
CALL AddKey(Client.Aux1, DataRef&, Last$)
CALL AddKey(Client.Aux2, DataRef&, S.Num$)
NEXT I%
CLS
PRINT "FIRST NAME INDEX"
PRINT "================"
CALL ClearKey(Client.File)
CALL dbNext(Client.File, First$)
WHILE dbStatus = 0
PRINT First$; " "; Last$;" ";S.Num$; " "
CALL dbNext(Client.FIle, First$)
WEND
PRINT "LAST NAME INDEX"
PRINT "==============="
CALL ClearKey(Client.Aux1)
CALL NextKey(Client.Aux1, DataRef&, KeyVal$)
WHILE dbStatus = 0
CALL GetRec(Client.File, DataRef&)
PRINT First$; " "; Last$;" ";S.Num$; " "
CALL NextKey(Client.Aux1, DataRef&, KeyVal$)
WEND
PRINT "NUMBER INDEX"
PRINT "============"
CALL ClearKey(Client.Aux2)
CALL NextKey(Client.Aux2, DataRef&, KeyVal$)
WHILE dbStatus = 0
CALL GetRec(Client.File, DataRef&)
PRINT First$; " "; Last$;" ";S.Num$; " "
CALL NextKey(Client.Aux2, DataRef&, KeyVal$)
PRODUCT : TURBO BASIC NUMBER : 416
VERSION : 1.1
OS : PC-DOS
DATE : January 5, 1988 PAGE : 1/4
TITLE : CREATING MULTIPLE INDICES
WEND
CALL dbClose(Client.File)
CALL CloseIndex(Client.Aux1)
CALL CloseIndex(Client.Aux2)
$INCLUDE "DBHIGH.BOX" 'High-level Access calls
$INCLUDE "DBLOW.BOX" 'Low-level Access calls
Comments
Post a Comment