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!

Write a cursor to a flat file

Status
Not open for further replies.

ewhubby

MIS
Nov 9, 2001
8
US
I have a dynamic cursor and I want to write those fields to a text file each field in one line.....
Can somebody give me an idea?
Thank you,
Mike
 
Are you sure you want to put each field, not each record on separate lines?

Here's some of the options:

If it's records that you need to put on each line, check out help on COPY TO ... TYPE ...

For putting each field on a new line, you probably have to scan your cursor and use STRTOFILE() function for each record.


 
So basically you have a cursor that looks something like this:

Field1 Field2 Field3 Field4
1 2 3 4

and you want to send it to a text file so the text file reads like this:

1
2
3
4

Am I understanding you correctly?

If so, you can achieve something like this by using STRTOFILE and scanning through the cursor.

I'm not sure I understand why you would want to put every field on a new line though. Have you considered using COPY TO and just making it deliminated?

Hope this helps

-Kevin
 
Here is some code, let me know if anyone thinks I should make it into an FAQ?

Code:
************************************************************
* Name:			_ListCursor.prg
* Author:		justamistere 2004/10/08
* Description:	Dumps a cursor's fields in one column.
*
*				This can easily be adapted to a .DBF and
*				multiple columns, too. Have fun.
*************************************************************
CLOSE DATABASE ALL
OPEN DATABASE "C:\MYDATABASE.DBC"

SELECT * FROM MYTABLE INTO CURSOR ABC

SET SAFETY OFF
SET CONSOLE OFF
WAIT WINDOW AT SROWS()/2, SCOLS()/2 ;
	CHR(13) + PADC("Please wait...", 20) + CHR(13) NOWAIT NOCLEAR

SET ALTERNATE TO "XYZ.TXT"
SET ALTERNATE ON
GO TOP

lnI = 1
lnMAXWidth = 0

FOR lnI = 1 TO FCOUNT()
	lnMAXWidth = MAX(LEN(FIELD(lnI)), lnMAXWidth)
NEXT

SCAN
	?REPLICATE("_", lnMAXWidth)
	FOR lnI = 1 TO FCOUNT()
		?PADR(FIELD(lnI), lnMAXWidth, ".") + ": "
		??EVALUATE(FIELD(lnI))
	NEXT
	?
ENDSCAN
SET ALTERNATE OFF
SET ALTERNATE TO

SET SAFETY ON
SET CONSOLE ON

WAIT CLEAR
MESSAGEBOX("ALL DONE!")

CLOSE DATABASE ALL

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top