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

VFP6 Copy To issue with quotation marks around data

Status
Not open for further replies.

Eliott

Programmer
Nov 8, 2009
91
BA
I have some old app in VFP6 SP5 and I wanted to export some tables into file by using COPY TO. But despite all my tries to remove quotation marks around text field content they remained there or I got error! In VFP9 it goes well, but here it won't! I need just character ; between fields and nothing more but couldn't help myself. Due that I wrote some prg that did ti for me:
Code:
*dump free table to file without quotation marks
*Visual FoxPro 6
*E.Podic ©2010 aka Littlefloor 

clear
tbl='kolegij'
use (tbl)
bp=fcount((tbl))
go top

nof='out_'+tbl+'.txt'
n1 = fcreate(nof)

cstring=''
scan all
for sb=1 to bp
p=alltrim(field(sb))
do case
	case type('&p')='C'
	cString = cstring+alltrim(&p)+';'
	case type('&p')='D'
	cString = cstring+dtoc(&p)+';'
	case type('&p')='N'
	cString = cstring+alltrim (str((&p), fsize(p)))+';'
	case type('&p')='U'
	cString = cstring+alltrim (str((&p),0))+';'
	case type('&p')='L'
	cString = iif(&p=.f., cstring+'0'+';', cstring+'1'+';')
endcase
next sb
=fput(n1,cString)
cstring=''
endscan

=fclose(n1)
close data
If anybody has better solution I would like to see it. Thank you.

There is no good nor evil, just decisions and consequences.
 
Having chr(1) in fields that would be copied to a text file is very unusual so you can use it as a temp value:
Code:
lcFieldDelimiter = chr(1)
OutFileName = 'out_'+m.tbl+'.txt'
copy to (m.OutFileName) ;
  type delimited with &lcFDelimiter with character ";"
StrToFile(;
chrtran(FileToStr(m.OutFileName),chr(1),''),m.OutFileName)[code]

PS: VFP9 could do this directly with a 'Copy To' command:
[code]copy to (m.OutFileName) ;
  type delimited with "" with character ";"




Cetin Basoz
MS Foxpro MVP, MCP
 
sorry about the formatting, can not figure out what TT does not like about it.
Code:
local nFields, fh, i
set textmerge on to c:\temp\output.txt noshow

nFields = fcount()-1
fh = _text
scan
   for i = 1 to nFields
      if type(field(i))="C"
	      \\<<( alltrim(eval(field(i))) )>>
      else
			\\<<( eval(field(i)) )>>
      endif
		\\;
   next
	\\<<( eval(field(i)) )>>
	\
endscan

=fclose(fh)
set textmerge to
set textmerge off
if you do not care about the slack space, take out the IF and just use the eval(field(i))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top