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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unwanted Carriage Return & EOF Character

Status
Not open for further replies.

sqleptical

Programmer
Sep 26, 2001
112
US
I use a FoxPro 7 .prg to export .dbf data to a .txt file, however it always appends a carriage return & a black box as what I assume to be an EOF character () after the last line. Does anyone know a way to avoid this from happening?
 
tools -> options -> editor -> save options -> deselect 'Save with end-of-file-marker'?

You might also want to try using a different code page e.g.
COPY TO test SDF as 1252.

If you mean something else it'd be helpful to describe what version of VFP and what export method you are using.

Brian
 
I'm using FoxPro 7.0 and do not have a "save options" under
tools -> options -> editor. Below is a slimmed-down version of the .prg code used to export the data to a file named out.xml. As I mentioned, after all the records are output to the file from the procedure, it inserts a carriage return & EOF character...

use "L:\xmlout.dbf" share
set console off
set alternate to "L:\xmlOutput\out.xml"
set alternate on

do while .T.
if EOF() && Loop until last record
Exit
endif
Do buildXML
skip
enddo

set alternate to
set alternate off
use

PROCEDURE buildXML

?? XMLHeader
?? XMLLead
?? XMLVendorId
?? "<LeadDisposition>"
?? XMLLeadId
?? XMLLeadDispOutcmCd
?? XMLLeadDispositionDt
?? XMLLeadDispositionTm
?? XMLConsumerEMailAddress
?? XMLConsumerPhoneNbr
?? XMLClientId1
?? XMLClientId2
?? "</LeadDisposition>"
?

ENDPROC
 
Thank you. While I did search for a thread dealing with this issue, I missed this one. However, while the code provided compiles & runs without error, I am still left with both the carriage return and the  at the end of the file. I know this seems petty as it does not take much time to open a file and manually erase these, however this is the last step in automating a long series of processes without any human intervention.
 
I believe SET ALTERNATE always appends an EOF character when it's turned off. And '?' basically means "Add CRLF, advance to next line, then output the following data".
I don't think StrToFile() writes the extra EOF marker. Try using that instead:
Code:
use "L:\xmlout.dbf" share
*...set console off
*...set alternate to "L:\xmlOutput\out.xml"
*...set alternate on

SCAN
   Do buildXML
ENDSCAN


PROCEDURE buildXML
STORE '' TO cTmpStr
cTmpStr = XMLHeader
cTmpStr = cTmpStr + XMLLead
    cTmpStr = cTmpStr + XMLVendorId
    cTmpStr = cTmpStr + "<LeadDisposition>"
        cTmpStr = cTmpStr + XMLLeadId
        cTmpStr = cTmpStr + XMLLeadDispOutcmCd
        cTmpStr = cTmpStr + XMLLeadDispositionDt
        cTmpStr = cTmpStr + XMLLeadDispositionTm
        cTmpStr = cTmpStr + XMLConsumerEMailAddress
        cTmpStr = cTmpStr + XMLConsumerPhoneNbr
        cTmpStr = cTmpStr + XMLClientId1
        cTmpStr = cTmpStr + XMLClientId2
    cTmpStr = cTmpStr + "</LeadDisposition>"
cTmpStr = cTmpStr + CHR(13) + CHR(10)
StrToFile(cTmpStr, "L:\xmlOutput\out.xml", 1)  &&... 1 = append
ENDPROC

-Dave Summers-
[cheers]
Even more Fox stuff at:
 
That's slow if the file is big. I suggest TEXTMERGE

Code:
USE "L:\xmlout.dbf" SHARE 
LOCATE 

SET CONSOLE OFF
SET TEXTMERGE ON
SET TEXTMERGE TO "L:\xmlOutput\out.xml"

SCAN 
  buildXML()
ENDSCAN 

SET TEXTMERGE OFF
SET TEXTMERGE TO
USE 

PROCEDURE buildXML
	\\ <<XMLHeader>>
	\\ <<XMLLead>>
	    \\ <<XMLVendorId>>
	    \\ "<LeadDisposition>"
	        \\ <<XMLLeadId>>
	        \\ <<XMLLeadDispOutcmCd>>
	        \\ <<XMLLeadDispositionDt>>
	        \\ <<XMLLeadDispositionTm>>
	        \\ <<XMLConsumerEMailAddress'>>
	        \\ <<XMLConsumerPhoneNbr>>
	        \\ <<XMLClientId1>>
	        \\ <<XMLClientId2>>
	    \\ "</LeadDisposition>"
	    \
ENDPROC

Brian
 
Beautiful, Thank you Mr. Summers! That got rid of the EOF character, but I still get the carriage return after the last record is written out due to the cTmpStr = cTmpStr + CHR(13) + CHR(10). I'm trying to use a counter to avoid this on the last pass, but I can't seem to find a command to count all the records in the table & store as a value. Does anyone know how to do something like this?

recordcnt=recordcnt+1
if recordcnt < COUNT("L:\xmlout.dbf")
cTmpStr = cTmpStr + CHR(13) + CHR(10)
endif
 
And thank you to you BALTMAN! You were correct, TEXTMERGE did run much faster, and without the EOF character. I still get the unwanted carriage return after the last record of course...
 
Eureka!

To avoid the unwanted character return I was able to use:

recordcnt=recordcnt+1
if recordcnt < reccount()
\
endif

I found this in thread1254-1244098.

Thank you to ALL for your help!
 
I missed that you didn't want it. I was duplicating your logic. Glad it helped.

Brian
 
sqleptical, your RECCOUNT() test should look like this in case some records are deleted and therefore skipped. This should work unless you've already exited the SCAN/ENDSCAN loop.
Code:
if RECNO() < RECCOUNT()
   \
endif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top