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

copy to temp.txt delimited with tab (keeping field names)?

Status
Not open for further replies.

intel2000

MIS
Jan 22, 2003
25
US
use temp.dbf
COPY TO temp.txt DELIMITED WITH tab

This works fine and dandy but the program I am using to import the next files need the have the fieldnames in there.

Does anyone know a work around?

Thanks,

Ross
 
Hi Ross,

You could try something like this (untested):
Code:
cString = ""
nFieldNumber = AFIELDS(aFieldArray)
FOR nCount = 1 TO nFieldNumber
   cString = cString + aFieldArray[nCount, 1] + CHR(9)
NEXT nCount
cString = LEFT(cString, LEN(cString) - 1) + CHR(13) + CHR(10)
Then add the COPY TO file after it.

No guarantee that the fields will be in the proper order, though.

Regards,

Mike
 
Ross;
COPY TO temp.txt type CSV.

A CSV file has the field names as the first line in the file, and the field values in the remainder of the file are separated with commas.

HTH

Ed


Please let me know if the suggestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.
smallbug.gif
 
intel2000,

I suppose you could create a cursor, insert the field names into the cursor, append temp.dbf to the cursor, then copy the cursor instead of the table.

For example:

Code:
USE temp.dbf

CREATE CURSOR myCursor (field1 c(10),field2 c(10), field3 c(10))

INSERT INTO myCursor (field1,field2,field3) ;
			  VALUES ('field1','field2','field3')

SELECT myCursor

APPEND FROM temp

COPY TO temp.txt DELIMITED WITH TAB


Hope this helps.

-Kevin
 
There are several ways to do this. I have tried all.

1) Create a temporary cursor/.dbf and APPEND-BLANK, do a FOR...NEXT loop replacing all fields with FIELDS(lnI). This works if all fieldsare Character and Field names are wide enough for their names. Fails on "State C(2)"

2) Use Vfp's famous low-level file functions. They're really not difficult to use. FOPEN(), FREAD(), FWRITE(), FCLOSE() to add a "header/label" line of field names, using MSPRATT's suggestion. Then use the same functions to read/write one line at a time frrom your Tab-Dilimited data file.

3) Fill a string with the field names and Tabs, then use the excellent, newer Vfp STRTOFILE(lcFieldList, lcMyFile). Then SCAN...ENDSCAN the data and do the same STRTOFILE(lcConvertedToCharData, lcMyFile, ADDITIVE)


 
Brian

Code:
close all
lcHandle=fcreate([MyOutput.txt])
lcString=[]

USE GETFILE('dbf')

FOR ln = 1 TO FCOUNT()
 lcString=lcString+CHR(9)+FIELD(ln)
ENDFOR
lcString=RIGHT(lcString,LEN(lcString)-1)

FPUTS(lcHandle,lcString)

SCAN

IF MOD(RECNO(),1000)=0
 WAIT WINDOW NOWAIT [On record ]+TRANSFORM(RECNO())
ENDIF

lcString=[]
FOR ln = 1 TO FCOUNT()

IF VARTYPE(EVALUATE(FIELD(ln)))=[D]
 lcString=lcString+CHR(9)+TRANSFORM(MONTH(EVALUATE(FIELD(ln))))+[/]+TRANSFORM(DAY(EVALUATE(FIELD(ln))))+[/]+TRANSFORM(YEAR(EVALUATE(FIELD(ln))))
ELSE
 lcString=lcString+CHR(9)+IIF(RTRIM(TRANSFORM(EVALUATE(FIELD(ln))))==[0],[],RTRIM(TRANSFORM(EVALUATE(FIELD(ln)))))
ENDIF

ENDFOR
lcString=RIGHT(lcString,LEN(lcString)-1)

FPUTS(lcHandle,lcString)
ENDSCAN

FCLOSE(lcHandle)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top