Good afternoon,
I need to create a text file like the one attached, with data from a cursor. What command should I use to put the data in the text file and how to respect the columns of each piece of information?
I appreciate any help.
Viewing this without automatic line breaks, I see a long record structure which is of the type SDF. At least from line 6 onwards. The clues are defined column widths without delimiters, neither tabs nor commas.
To give an example of producing such a line here's the output of a cursor with 3 char(10) fields:
Code:
Create Cursor crsExport (c1 C(10), c2 c(10), c3 c(10))
Insert into crsExport values ("aaaaaaaaaa","bbbbbbbbbb","cccccccccc")
Insert into crsExport values ("dddddddddd","eeeeeeeeee","ffffffffff")
COPY TO demo.sdf TYPE SDF
Modify File demo.sdf
You can also give it the file extension txt, VFP is not needing the file extension but the TYPE SDF option is outputting the way you need. Ther are still a lot of details to fiddle with, when it comes to fields of other types like numbers, dates, etc., but you get the gist, all it needs is mainly a COPY TO... TYPE SDF.
I guess you'll need several iterations and have other detail problems than getting the first few lines added. Indeed one thing is unfortunate about COPY TO TYPE SDF, it doesn't allow to append to an existing file. You could also always use FilToStr to create the file line by line, aas that function also allows to append to an existing file, you can obviously also use FOPEN/FWRITE/FCLOSE and there's Textmerge to a file available. It's always possible to create any file you want and that doesn't only apply to ASCII/ANSI, none of the file output functions limit you to printable characters.
I guess you asked for the simplest command doing things as concentrated as you can, COPY TO TYPE SDF is that answer, but it may take some preparing work to get the cursor as it needs to be to create the same output, think alone of the right aligned numeric columns or any other detail. In he end it can also be simpler to work with FWRITE or FILETOSTR, that's depending on what data you have in which form already.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.