*********************************************************** * Program Name: FIXRECNT.PRG * Author: Tom Bellmer * Purpose: Write correct RECCOUNT() value to header * Last Modified: 08/11/1993 * Usage: DO fixrecnt WITH <dbf name> OR * =fixrecnt(<dbf name>) * Returns: nothing *********************************************************** PARAMETERS lcfname PRIVATE ALL LIKE l* *-- Open the file with unbuffered read/write access lnhandle = FOPEN(lcfname,12) *-- Test for possible file opening error IF lnhandle = -1 WAIT WINDOW "Error: "+STR(FERROR(),2) RETURN ENDIF *-- Read the first 12 characters of the header lchdrinfo =FREAD(lnhandle,12) *-- Calculate the header length lnhdrsize = INT(ASC(SUBSTR(lchdrinfo,09,01)) + ; ASC(SUBSTR(lchdrinfo,10,01)) * 256) *-- Calculate the record length lnreclngth = INT(ASC(SUBSTR(lchdrinfo,11,01)) + ; ASC(SUBSTR(lchdrinfo,12,01)) * 256) *-- lafsize[2] contains the file size in bytes =ADIR(lafsize,lcfname) *-- Calculate the number of records lnreccnt = INT((lafsize[2] - lnhdrsize) / lnreclngth) lcfirst8 = LEFT(lchdrinfo,4) + SPACE(4) FOR lni = 3 TO 0 STEP -1 *-- Replace characters from left to right starting *-- at 8 and going to 5 (RECCOUNT() area) lcfirst8 = STUFF(lcfirst8,lni+5,1, ; CHR(INT(lnreccnt / 256^lni))) *-- Perform modulus division and use the remainder *-- as the remaining record count in the next pass *-- of the FOR ... NEXT loop. lnreccnt = lnreccnt % 256^lni NEXT *-- Go to top of the file. =FSEEK(lnhandle,0,0) *-- Write 1st 8 positions back to the header record. =FWRITE(lnhandle,m.lcfirst8) *-- Close the file =FCLOSE(lnhandle) RETURN * EOF fixrecnt.prg