|
The following VB DOS example demonstrates the use of the FATS  indexing commands:
"C" Create Indexfile (Creates a index file with the specified characteristics.) | |
"O" Open Indexfile (Makes a index file available for access.) | |
"K" Close Indexfile (Releases a index file from availability.) | |
"I" Insert Record (Insert a new record.) | |
"F" Search First (Gets the key value and record number of the data record with the first key value.) | |
"L" Search Last (Gets the key value and record number of the data record with the last key value.) | |
"N" Search Next (Gets the key value and record number of the data record following the current record.) | |
"A" Search Next After (Gets the key value and record number of the data record whose key value is greater than the requested key value.) | |
"E" Search Previous Before (Gets the key value and record number of the data record whose key value is less than the requested key value.) | |
"Y" Auto Refresh (Specifies file locking and cache modes in single- and multi-user environments.) |
REM FATS 02.30 REM (c) GCS Software, Udo Gertz 1993-1998 REM REM Test program (Visual Basic for DOS) REM REM Build the test data file customer.dat. REM REM 19-03-2009 U.Gertz PRINT "This Test Program was designed for Visual Basic (MS-DOS)" PRINT PRINT "To compile and link the test program, use ONE of the following methods:" PRINT PRINT " 1. METHOD: Linking FATS to the program" PRINT PRINT " BC TST1_ENG" PRINT " LINK TST1_ENG FATS.OBJ FATS_VBD.OBJ" PRINT PRINT " 2. METHOD: Calling the Workstation Engine" PRINT PRINT " BC TST1_ENG" PRINT " LINK TST1_ENG FATSVBDR.LIB (FATS Standard Version FATS_WE.EXE)" PRINT PRINT " or if you own the extended version of FATS:" PRINT PRINT " LINK TST1_ENG FATSXVBR.LIB (FATS Extended Version FATSXWE.EXE)" PRINT INPUT "Please press the [ENTER] key ...", X$ PRINT REM -------> Activation of Network Operation REM REM FATS is standardly equiped for the network environment. REM Nearly all commands can be executed both in single workstation REM and network environment. With the "Y" Auto Refresh command you REM determine the behavior of FATS accessing all index files. REM Normally it is sufficient to apply this instruction one time at REM the program start whereby the specified access mode will apply REM to all coming opened files, i.e. they are accessed either with REM network (Y\2) or single workstation access (Y\0). REM CALL FATSBASIC( "Y\2", ERRORCODE%, RECNO&, KEYLEN% ) REM -------> Open file with test data OPEN "R", #1, "..\..\..\DEMODATA\CUSTOMER.ASC", 105 FIELD #1, 5 AS F1$, 25 AS F2$, 25 AS F3$, 25 AS F4$, 5 AS F5$, 20 AS F6$ REM -------> create data file PRINT "Creating Data File ..." OPEN "R", #2, "CUSTOMER.DAT", 128 FIELD #2, 1 AS DELETEDMARK$,_ 5 AS CUSTID$,_ 25 AS NAME$,_ 25 AS JOB$,_ 25 AS STREET$,_ 5 AS ZIP$,_ 20 AS CITY$ REM -------> Create index file REM "C" Create Indexfile REM REM With this command you create an index file, whereby a possibly REM already existing file with the same name is deleted. REM After the file is created it will be opened with the opening REM flags defined with the command Auto Refresh (Y) and can be REM accessed under the file number you specified. REM REM Max. 200 primary keys per data record can be administered in an REM index file, the max. key length amounts to 240 characters. REM REM Full path names must be specified using forward slashes (/) REM instead of Backslashes (\), because FATS normally uses the REM Backslash character as delimiter. REM You may change the delimiters by placing the desired character REM as the first character of the command string, REM e.g. szCmnd = "&C&C:\ARTICLES.KEY&1&1&A&1". Any character with REM an Ascii code less then 48 will be accepted. REM REM The syntax of the command string: REM REM szCmnd = "C\{Filename}\{KeyLength}\{KeyCount}\{KeyType}\{FileNo}" REM REM FileName filename, perhaps with an additional path REM (e.g. C:/DATA/ARTICLES.KEY or ARTICLES.KEY) REM REM KeyLength Maximum key length (1-250) REM If you choose to have more than one key for REM this index file, you may specify the length REM for each key (separated by a semicolon ";") REM to conserve diskette space. REM Otherwise, the maximum length applies to all REM keys, i.e. every key will occupy the maximum REM space. REM REM KeyCount Number of primary keys (1-200) REM REM KeyType Key type (A = Ascii text, I = Integer) REM REM FileNo File number (1-40) PRINT "Creating Index File ..." CALL FATSBASIC( "C\CUSTOMER.KEY\5;25\4\A\1", ERRORCODE%, RECNO&, KEYLEN% ) IF ERRORCODE% <> 0 GOTO ENDE REM ======================================================================== REM Insert Records REM ======================================================================== PRINT PRINT "290 records will be inserted into the data file." PRINT "For each record 4 keys will be stored in the index file." INPUT "Please press the [ENTER] key ...", X$ FOR X=1 TO 290 GET #1, X LSET DELETEDMARK$ = " " LSET CUSTID$ = F1$ LSET NAME$ = F2$ LSET JOB$ = F3$ LSET STREET$ = F4$ LSET ZIP$ = F5$ LSET CITY$ = F6$ REM "I" Insert Record REM REM This command is used to insert the primary keys of a new REM data record into the index file. After the insert, the REM record number of the new record is returned in the "RECNO" REM variable. You can use this record number to write the data REM record to the data file. REM REM The number of keys included in the command string must equal REM the number of primary keys you specified in the REM Create Indexfile (C) command. REM REM The length of the transferred keys may not exceed the maximum REM key length specified with the Create Indexfile (C) command. REM Variable length keys will be padded with the Ascii char 0 to REM the maximum key length. REM REM The syntax of the command string: REM REM szCmnd = "I\{FileNo}\{KeyStr1}[\{KeyStr2}[\{KeyStr3}]]" REM REM FileNo File number REM REM KeyStr# Key value CMND$ = "I\1\" CMND$ = CMND$ + RTRIM$(CUSTID$) + "\" + RTRIM$(NAME$) + "\" + RTRIM$(JOB$) + "\" + RTRIM$(ZIP$ + CITY$) CALL FATSBASIC( CMND$, ERRORCODE%, RECNO&, KEYLEN% ) IF ERRORCODE% <> 0 GOTO ENDE PRINT NAME$; " --> RecNo "; RECNO& PUT #2, RECNO& NEXT X CLOSE #1 REM "K" Close Indexfile REM REM This command closes the index file with the specified REM file number. REM REM If you have activated the cache algorithm with the command REM Auto Refresh (Y), the possibly still in the cache buffers REM presented data are automatically written on the disk. REM REM If the cache is inactive after every FATS command all REM changed data are written on the disk. Therefore closing of REM a file is necessary only before terminating the application. REM REM If you omit the parameter "FileNo", then all opened index REM files are closed. This version is recommended before the REM termination of the application program. REM REM The syntax of the command string: REM REM szCmnd = "K\{FileNo}" REM REM FileNo File number CALL FATSBASIC( "K\1", ERRORCODE%, RECNO&, KEYLEN% ) REM ======================================================================== REM Search REM ======================================================================== REM "O" Open Indexfile REM REM With this command you open an existing index file with REM the opening flags defined with the command Auto Refresh (Y). REM After the file was opened it can be accessed under the REM file number you specified. An index file already opened REM with the same file number is closed before this command REM is executed. REM REM Full path names must be specified using forward slashes (/) REM instead of Backslashes (\), because FATS normally uses the REM Backslash character as delimiter. REM You may change the delimiters by placing the desired character REM as the first character of the command string, e.g. REM szCmnd = "&O&C:\ARTICLES.KEY&1". Any character with an Ascii REM code less then 48 will be accepted. REM REM The syntax of the command string: REM REM szCmnd = "O\{FileName}\{FileNo}" REM REM Filename filename, perhaps with an additional path REM (e.g. C:/DATEN/ARTICLES.KEY or ARTICLES.KEY) REM REM FileNo File number CALL FATSBASIC( "O\CUSTOMER.KEY\1", ERRORCODE%, RECNO&, KEYLEN% ) REM -------> Print all customers, sorted in ascending order by NAME PRINT PRINT "This list shows some fields from the Customer Table," PRINT "sorted in ascending alphabetical order on the Customers" PRINT "surname and forename." PRINT INPUT "Please press the [ENTER] key ...", X$ REM "F" Search First REM REM This command enables your application to retrieve the REM record number corresponding to the first key value for REM the specified key number. REM REM The syntax of the command string: REM REM szCmnd = "F\{KeyNo}\{FileNo}" REM REM KeyNo Key number REM REM FileNo File number CMND$ = "F\2\1" LOOP1: CALL FATSBASIC( CMND$, ERRORCODE%, RECNO&, KEYLEN% ) IF ERRORCODE% <> 0 GOTO LABEL1 FATSKEY$ = SPACE$( KEYLEN% ) CALL FATSGETKEY( FATSKEY$ ) GET #2, RECNO& PRINT NAME$; " "; JOB$; " --> RecNo "; RECNO& REM "A" Search Next After REM REM With this command your application can retrieve the record REM number corresponding to the first key value which is greater REM than the key value you specify. REM If a duplicate key exists, the next higher record number of REM the next duplicate will be returned. The key value you specify REM with "KeyString" don't have to be a valid key in the index file. REM REM Unlike the "Search Next" command, this command can be used in REM a network environment. REM REM The syntax of the command string: REM REM szCmnd = "A\{KeyNo}\{RecNo}\{FileNo}\{KeyString}" REM REM KeyNo Key number REM REM RecNo Record number REM REM FileNo File number REM REM KeyString Key value CMND$ = "A\2\" + STR$( RECNO& ) + "\1\" + FATSKEY$ GOTO LOOP1 LABEL1: REM --------> print all customers, sorted in ascending order by JOB PRINT PRINT "Two columns - JOB and NAME are displayed, sorted in ascending" PRINT "order by the JOB field." PRINT INPUT "Please press the [ENTER] key ...", X$ CMND$ = "F\3\1" LOOP2: CALL FATSBASIC( CMND$, ERRORCODE%, RECNO&, KEYLEN% ) IF ERRORCODE% <> 0 GOTO LABEL2 GET #2,RECNO& PRINT JOB$; " "; NAME$; " --> RecNo "; RECNO& REM "N" Search Next REM REM With this command your application can retrieve REM the record number corresponding to the first key REM value which is greater than the key value recently REM returned by one of the search commands, which have REM to be executed as the latest command. REM If a duplicate key exists, the next higher record REM number of the next duplicate will be returned. REM REM Each modification of the index file by inserting or REM deletion of keys makes an internal pointer invalid REM that is necessary for this instruction. You better REM use the command Search Next After (A) because this REM can happen in the network environment from any station. REM REM If there is no key in sequence FATS will return an REM errorcode of 15. REM REM The syntax of the command string: REM REM szCmnd = "N\{FileNo}" REM REM FileNo File number CMND$ = "N\1" GOTO LOOP2 LABEL2: REM --------> print list with records sorted by ZIP and CITY PRINT PRINT "Three columns - ZIP, CITY and NAME are displayed, sorted in" PRINT "descending order by ZIP then CITY." PRINT INPUT "Please press the [ENTER] key ...", X$ REM "L" Search Last REM REM This command enables your application to retrieve the REM record number corresponding to the last key value for REM the specified key number. If duplicates exist for the REM last key value, the record number returned identifies REM the last duplicate, that is, the one inserted most REM recently. REM REM The syntax of the command string: REM REM szCmnd = "L\{KeyNo}\{FileNo}" REM REM KeyNo Key number REM REM FileNo File number CMND$ = "L\4\1" LOOP3: CALL FATSBASIC( CMND$, ERRORCODE%, RECNO&, KEYLEN% ) IF ERRORCODE% <> 0 GOTO LABEL3 FATSKEY$ = SPACE$( KEYLEN% ) CALL FATSGETKEY( FATSKEY$ ) GET #2, RECNO& PRINT ZIP$; " "; CITY$; " "; NAME$; " --> RecNo "; RECNO& REM "E" Search Previous Before REM REM With this command your application can retrieve the record REM number corresponding to the first key value which is less REM than the key value you specify. REM If a duplicate key exists, the next lower record number of REM the previous duplicate will be returned. The key value you REM specify with "KeyString" don't have to be a valid key in the REM index file. REM REM Unlike the "Search Prev" command, this command can be used in REM a network environment. REM REM The syntax of the command string: REM REM szCmnd = "E\{KeyNo}\{RecNo}\{FileNo}\{KeyString}" REM REM KeyNo Key number REM REM RecNo Record number REM REM FileNo File number REM REM KeyString Key value CMND$ = "E\4\" + STR$( RECNO& ) + "\1\" + FATSKEY$ GOTO LOOP3 LABEL3: ENDE: REM --------> Close index file CALL FATSBASIC( "K\1", ERRORCODE%, RECNO&, KEYLEN% ) CLOSE #2 END
© 2008 GCS Software, Udo Gertz