Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
FUNCTION FixRecCount( pTable )
LOCAL cTable, objErr, nErrNo, cErrMsg, nTmp, nTmpCount, nHandle, nAscValue, nSuccess
LOCAL nTabLen, cHdrRead, nCurCount, nHdrLen, nRecLen, nRecCount, cHdrWrite
DO CASE
CASE !EMPTY(pTable) AND FILE(pTable)
cTable = pTable
CASE !EMPTY(pTable) AND FILE(pTable + ".dbf")
cTable = pTable + ".dbf"
OTHERWISE
cTable = GETFILE("DBF")
ENDCASE
nErrNo = 0
cErrMsg = ""
SET TABLEVALIDATE TO 3 && normal table validation
IF FILE(cTable)
TRY
USE (cTable) IN 0 ALIAS _OPENTEST SHARED
CATCH TO objErr
nErrNo = objErr.ErrorNo
cErrMsg = objErr.Message
RELEASE objErr
ENDTRY
IF NOT EMPTY(SELECT("_OPENTEST"))
USE IN "_OPENTEST"
ENDIF
IF nErrNo = 2091 OR "corrupted" $ cErrMsg
nHandle = FOPEN(cTable, 2)
IF nHandle <> 0
nTabLen = FSEEK(nHandle, 0, 2) && go to EOF to determine file size
IF nTabLen <> 0
nTmp = FSEEK(nHandle, 0, 0) && go to BOF()
* We only need data from the first 12 bytes of the header
cHdrRead = FREAD(nHandle, 12)
nCurCount = ASC(SUBSTR(cHdrRead,5,1)) * (256^0) + ASC(SUBSTR(cHdrRead,6,1)) * (256^1) + ASC(SUBSTR(cHdrRead,7,1)) * (256^2) + ASC(SUBSTR(cHdrRead,8,1)) * (256^3)
nHdrLen = ASC(SUBSTR(cHdrRead,9,1)) * (256^0) + ASC(SUBSTR(cHdrRead,10,1)) * (256^1) && Header length
nRecLen = ASC(SUBSTR(cHdrRead,11,1)) * (256^0) + ASC(SUBSTR(cHdrRead,12,1)) * (256^1) && Record Length
nRecCount = (nTabLen - (nHdrLen + 1)) / nRecLen
nAscValue = INT(nRecCount/(256^3))
nTmpCount = MOD(nRecCount, 256^3)
cHdrWrite = CHR(nAscValue)
nAscValue = INT(nTmpCount/(256^2))
nTmpCount = MOD(nTmpCount, 256^2)
cHdrWrite = CHR(nAscValue) + cHdrWrite
nAscValue = INT(nTmpCount/(256^1))
nTmpCount = MOD(nTmpCount, 256^1)
cHdrWrite = CHR(nAscValue) + cHdrWrite
nAscValue = INT(nTmpCount)
cHdrWrite = CHR(nAscValue) + cHdrWrite
IF nCurCount <> nRecCount
MESSAGEBOX("Table record count ("+LTRIM(STR(nCurCount))+") will be updated to "+LTRIM(STR(nRecCount))+".", 48, "Record count incorrect")
nTmp = FSEEK(nHandle, 4, 0) && BOF() + 4
nSuccess = FWRITE(nHandle, cHdrWrite, 12)
MESSAGEBOX("Table record count was " + IIF(EMPTY(nSuccess), "NOT ", "") + "updated to "+LTRIM(STR(nRecCount))+".", 48, "Write results")
ELSE
MESSAGEBOX("Table record count ("+LTRIM(STR(nCurCount))+") is correct.", 48, "No action needed")
ENDIF
ELSE
MESSAGEBOX("Cannot low-level open table.", 48, "Unable to continue.")
ENDIF
nTmp = FCLOSE(nHandle)
ELSE
MESSAGEBOX("File has zero size or unable to properly open table", 64, "Table not open")
ENDIF
ELSE
MESSAGEBOX("No table validation errors", 64, "No issues detected")
ENDIF
ELSE
MESSAGEBOX("No table selected", 64, "Nothing to do")
ENDIF
RETURN