Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
More control in a .txt
Message
From
26/11/2010 05:41:05
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01490543
Message ID:
01490545
Views:
58
This message has been marked as a message which has helped to the initial question of the thread.
You have several options to write to a text file one line at a time (or even less).

Option 1: Save everything to a variable first. Save the entire file to disk at once, with the FileToStr() command.

Option 2: Save to the file, one line at a time, with FileToStr(). This function has an option to add to the end of a file. (The first invocation of FileToStr() would not use this option - so that, if the file already exists, it is overwritten.)

Option 3: Use low-level file-functions. Create a file with fcreate(), write bytes with fwrite() or lines with fputs(), at the end, close the file with fclose().

For options 1 and 2, don't forget to add a chr(13) + chr(10) at the end of each line.

>I need to write to a .txt but I can not just use "copy to type", because I need more control over the txt file.
>
>
> I have two tables: maintable.dbf and item.dbf and I need something as below:
>
>
>open my.txt file
>
> use table 1
>
> scan
>
> write: field1 + "|" + field2 + "|" + field3
>
> in the next line
>
> write: field4 + "|" + field5 + "|" + field6
>
>use item
> scan for condition
>
>write: field1 + "|" + field2
>
> in the next line
>
> write: field3 + "|" + field4
>
>endscan
> endscan
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform