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

Exporting from FoxPro to text --Please help

Status
Not open for further replies.
Oct 22, 2001
215
US
Hi I really appreciate if any one can get some input.

I got a foxpro database that got a memo field along some other field. I need to export it to either fixed length or comma delimeted flat file (text file).

What is the best way to this? I imported the foxpro (dbf) file well in Access but when I try to export it to Txt file, The memo field is coming max 255 char in length. It seems it has got multiple lines w carrage return. I need to take the carrage return out. So I tried fixed length but multiple lines on the memo fields are not exporting properly...
Any idea what is going on??
Thanks a lot
 
You can remove a carrage return using the chtran() function, which replaces one character with another.

A carrage return is chr(13) on the asci map, so the command:
CHRTRAN(cSearchedExpression, cSearchExpression, cReplacementExpression)

can be used as: CHRTRAN(MemoField,chr(13),"|") to make a carriage return a "|".

BUT I think your problem may have to do with the fact that a memo will not export cleanly to a text file the same way the rest of the information in a table does. You will probably have to export the memo information seperately.

You will probably find more than you need in this recent tread:
thread184-278353

Brian
 
Hi
Thanks,
IS this function a FoxPro one? How do I run? Can you please explain little details....I am just new at this.
Even I use the export.prg that you referred in thread-278353.... Is this some thing I need to type on the command window that shoud export the memo field seperately? Thanks again...
 
You can create programs "prg" files, which basically contain many lines as you would type them into the command window which saves you commands and allows you to run all of them at one. It is basically a text file with a "prg" extension.

You can create one by typing "modi comm MyProgram". One you have your code in there you can run it using "do MyProgram".

You should send a little time with the help files...

Brian
 
to add: yes, the chrtran function is a foxpro-command - see help in vfp

Klaus
 
Thanks all of you. I finally decided make it program and run it. It works well on Visual Foxpro 6.x and so on.

However I get an error on runing the same script on 2.6x (Visual FoxPro). Can any one tell me what are the commands that I should change or where I can get a list of equivalent command? Customer has this 2.6 version and I got 6.x!
>>>
The code that I am using as follows:
One error that for sure I am getting at this line:

FPUTS(lcTextFile, lcFieldString) && Writes string to the text file.
??
>>>>>>>>
CLOSE ALL
CLEAR ALL

lcFieldString = ''
lcMemo = ''

USE GETFILE('dbf', 'Select DBF') && Prompts for table to be used.

lnFieldCount = AFIELDS(laGetFields) && Builds array of fields from the
&& selected table.

*!* Prompt for Output file and use Low-Level functions
*!* to create it.
lcTextFile = FCREATE(GETFILE('txt', 'Select Text'))

*!* Starts scanning the table and converts the fields
*!* values according to their types **
SCAN
WAIT WINDOW STR(RECNO()) + ' Of ' + STR(RECCOUNT()) NOWAIT

FOR lnCount = 1 TO lnFieldCount
lcType = laGetFields(lnCount, 2)

IF lcType # 'G' && Don't try to turn a general field into a string
lcString = EVALUATE(laGetFields(lnCount, 1))
EndIf

DO CASE
CASE lcType = 'M' && Process the Memo Fields
lnMemoLines = MEMLINES(EVALUATE(laGetFields(lnCount,1)))
FOR lnLoop = 1 TO lnMemoLines
IF lnLoop < lnMemoLines
lcMemo = lcMemo + ;
ALLTRIM(MLINE(EVALUATE(laGetFields(lnCount, 1)), ;
lnLoop)) + ' '
ELSE
lcMemo = lcMemo + ;
ALLTRIM(MLINE(EVALUATE(laGetFields(lnCount, 1)), ;
lnLoop))
ENDif
ENDfor

lcString = lcMemo
lcMemo = ''
CASE lcType = 'G' && Process the General Fields
lcString = 'Gen'
CASE lcType = 'D' && Process the Date Fields
lcString = DTOC(lcString)
CASE lcType = 'T' && Process the DateTime Fields
lcString = TTOC(lcString)
CASE lcType = 'N' && Process the Numeric Fields
lcString = STR(lcString, LEN(STR(lcString)), 2)
CASE lcType = 'I' && Process the Integer Fields
lcString = STR(lcString)
CASE lcType = 'L' && Process the Logical Fields
IF lcString = .T.
lcString = 'T'
ELSE
lcString = 'F'
ENDif
ENDcase

IF lnCount < lnFieldCount && Determines if the last field was
&& processed and sets the closing quote.
lcFieldString = lcFieldString + '&quot;' + lcString + '&quot;' + ','
ELSE
lcFieldString = lcFieldString + '&quot;' + lcString + '&quot;'
ENDif
ENDfor

FPUTS(lcTextFile, lcFieldString) && Writes string to the text file.
lcFieldString = ''
ENDscan

FCLOSE(lcTextFile)

CLOSE All
CLEAR All
WAIT WINDOW 'Text File Creation Completed' NOWAIT
 
I've duplicated my FoxPro (1.0 - 2.x) response here, just in case anyone that doesn't visit there can see THE answer <g>.

So you don't have to get a 2.x Compiler, I think I've found all the problems!
1) Put an '=' character in front of FPUTS() and FCLOSE(). i.e.

[red] = [/red]FPUTS(lcTextFile, lcFieldString) && Writes string to the text file.
...
[red] = [/red]FCLOSE(lcTextFile)

This is because 2.x requires an opportunity to &quot;store&quot; the value returned from these functions - even if you just throw them away. VFP doesn't care!

2) To add the field name header record, add in the following code toward the top (New also in Red):

...
lcTextFile = FCREATE(GETFILE('txt', 'Select Text'))

[red]*!* Write out Field Names
FOR lnCount = 1 TO lnFieldCount
lcFieldName = laGetFields(lnCount, 1)
IF lnCount < lnFieldCount && Determines if the last field was
&& processed and sets the closing quote.
lcFieldString = lcFieldString + '&quot;' + lcFieldName + '&quot;' + ','
ELSE
lcFieldString = lcFieldString + '&quot;' + lcFieldName + '&quot;'
ENDif
ENDFOR
= FPUTS(lcTextFile, lcFieldString) && Writes string to the text file.
lcFieldString = &quot;&quot;
[/red]
*!* Starts scanning the table and converts the fields
...

Rick

P.S. For the &quot;lurkers&quot;, when running this under 2.x, it's also necessary to kill the DateTime check in the CASE, as it doesn't know about DateTime fields and TTOC().

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top