Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Header Record
Message
From
03/12/2001 04:53:00
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
03/12/2001 04:23:17
Steve Jones
Business Systems Services Uk Ltd
Swansea, United Kingdom
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00588602
Message ID:
00588605
Views:
37
>Hi all,
>
>We have a file in which there are thousands of records with a size of about 10 meg. The header record seems to have been corrupted so it says there are no records. We can export into excel, but the maximum number of records is exceeded. Any ideas?
>
>Many thanks
>
>Steve

Steve,
Fix the header record. Take a backup first. Then calculate how many records should exist :

lnRecords = floor((lnFileSize-(lnHeaderSize+1))/lnRecordSize)

Below code takes care of 'only' this issue :
Function RepairHeader
Lparameters tcDBF
Local handle, lnFileSize, lnReccount, lnHeaderSize, lnRecordSize, ;
	lnCalculatedReccount, llHasMemo
handle=fopen(tcDBF,12) && Opened readwrite
lnFileSize = fseek(handle,0,2) && Get file size
* Read header info
*With this
	lnReccount   = ReadBytes(handle, 4,4)
	lnHeaderSize = ReadBytes(handle, 8,2)
	lnRecordSize = ReadBytes(handle,10,2)

	lnCalculatedReccount = floor((lnFileSize-(lnHeaderSize+1))/lnRecordSize)
	If lnCalculatedReccount # lnReccount && If calculated # recorded fix it
		WriteBytes(handle, 4,4,lnCalculatedReccount)
	Endif
*Endwith
=fclose(handle)

function WriteBytes
Lparameters tnHandle, tnPos, tnSize, tnNumber, tlLR
Local lcString, lnLowDword, lnHighDword,ix
lcString=''
If tlLR
	For ix=tnSize-1 to 0 step -1
		lcString=lcString+chr(tnNumber/256^ix%256)
	Endfor
Else
	For ix=0 to tnSize-1
		lcString=lcString+chr(tnNumber/256^ix%256)
	Endfor
Endif
=fseek(tnHandle, tnPos,0) && Go to pos
Return fwrite(tnHandle,lcString)

function ReadBytes
Lparameters tnHandle, tnPos, tnSize, tlLR
Local lcString, lnRetValue,ix
=fseek(tnHandle, tnPos,0) && Go to pos
lcString = fread(tnHandle, tnSize) && Read tnSize bytes
lnRetValue = 0
For ix=0 to tnSize-1  && Convert to a number
	lnRetValue = lnRetValue + asc(substr(lcString,ix+1)) * ;
		iif(tlLR,256^(tnSize-1-ix),256^ix)
Endfor
Return int(lnRetValue)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform