Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

End of File Marker 1

Status
Not open for further replies.

Blorf

Programmer
Dec 30, 2003
1,608
US
Hello.

Writing updates to old Dbase Iv for Dos software that has to interact with modern stuff. Problem I have is all my exports or outputs from Dbase terminate with the old EOF marker 0x0A.

Any body know haw to make Dbase not do that?

Thanks
 
Do you want to append to the file latter on ?
(Using External Programs or DOS copy program ?)
 
No. Once the file is written, will be e-mailed and used on another windows based system. No appending.

The other system will import the data as a flat file, and sees the eof marker as an invlaid charachter.

 
Note: This code to truncate the file and remove the last END OF FILE marker has been tested but not thoroughly, so please try it only on copies until you are sure it works as you expect!
Code:
nSz=250
cFile="C:\temp\rpt.TXT"
nHandle=FOPEN(cFile,"RW")
IF nHandle=0
   ? cFile+" could not be opened low level."
ELSE
   ? "Processing "+cFile+"..."
   fEnd=FSEEK(nHandle,0,2)  && this is EOF
   xVal=FSEEK(nHandle,-1,1)  &&  one char before EOF
   fChr=FREAD(nHandle,1)  && get character
   IF fChr=CHR(26)
      ? "Found: CHR(26) at end of file."
      fEnd=FSEEK(nHandle,-1,1)  && one char before EOF
      xVal=FWRITE(nHandle,"",0)  && write nothing
   ELSE
      ? "Not found: CHR(26) - No action taken."
   ENDIF
   xVal=FCLOSE(nHandle)  && close truncates file after write of 0
   ? cFile+" has been closed."
ENDIF
RETURN
If you run the program against the file a second time it will say no action taken.

dbMark
 
I will give the code a try, but first must ask, what language? Is this Dbase Iv? Hope so.

I already wrote a C version of the above, but had trouble running through dbase, because the server is old Novell, and it is forcing the following:
set comspec = Some old dos version compatible with Novell

And this caused problems for my C program.

Any way, will give the code a try.

Appreciate the help.

ChaZ
 
This was tested in dBase 5 for DOS, but I don't see anything that probably wasn't already functional in dBase IV.
 
Hi. Tried the code, and it worked splendidly.

This is Odd, I wrote a very similar set of code in C to do this, and had the comspec problems I mentioned above. I have been writing stuff in Dbase for these folks for years, and never had a need to even know it had such file handeling abilities.

What a trip.

Thanks very much again.

ChaZ
 
Glad to hear it helps. It shouldn't be hard at all to incorporate this method after the code that creates your reports and other output.

If this really works out for you as a good solution, there is a way to show your appreciation. No money passes hands around here, but getting a Star as thanks for really helpful replies is the next best thing.
 
Then you shall receive a star. Being that I have programmed in Dbase since about 1982 and was not aware of fopen and fwrite options, you certainly added to my knowledge base.

Thanks,
ChaZ
 
Sorry missed at first instance, End of File Marker is 0x1A that is Decimal 26, not 0x0A and stipulated by Blorf. Howeve, dbMark has correctly solved the puzzle(Eof Mark).

Nasib Kalsi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top