HOWTO: Export Memo Fields with Other Field Types to a Text File
ID: Q241424
|
The information in this article applies to:
-
Microsoft Visual FoxPro for Windows, versions 5.0, 5.0a, 6.0
SUMMARY
This article demonstrates how to dynamically export records that contain Memo fields in a table, together with the other field types, into a comma delimited text file.
MORE INFORMATION
The sample code in this article follows this order:
- Prompts for a source table (.dbf file).
- Prompts for a target text file (.txt file).
- Export the contents of the table to the text file.
The code scans and determines every field type and every record in the table and then processes them accordingly to the data type:
Close All
Clear All
cFieldString = ''
MyMemo = ''
Use GetFile('dbf','Select DBF') && Prompts for table to be used.
gnFieldCount = AFIELDS(GetFieldArray) && Builds array of fields from the && selected table.
TextFile = Fcreate(getfile('txt','Select Text')) && Prompts for Output file
&& and uses Low Level
&& function to create it.
** Starts scanning the table and converts the fields values according to their types **
Scan
Wait Window Str(RecNo()) + ' Of ' + Str(RecCount()) NoWait
For nCount = 1 to gnFieldCount
MyType = GetFieldArray(nCount,2)
If MyType # 'G' && Evaluates if the Field is General Type
MyString = evaluate(GetFieldArray(nCount,1))
EndIf
Do Case
Case MyType = 'M' && Process the Memo Fields
MemoLines = memlines(evaluate(GetFieldArray(nCount,1)))
For nLoop = 1 to MemoLines
If nLoop < MemoLines
MyMemo = MyMemo + AllTrim(mline(evaluate(GetFieldArray(nCount,1)),nLoop)) + ' '
Else
MyMemo = MyMemo + AllTrim(mline(evaluate(GetFieldArray(nCount,1)),nLoop))
EndIf
EndFor
MyString = MyMemo
MyMemo = ''
Case MyType = 'G' && Process the General Fields
MyString = 'Gen'
Case MyType = 'D' && Process the Date Fields
MyString = DtoC(MyString)
Case MyType = 'T' && Process the DateTime Fields
MyString = TtoC(MyString)
Case MyType = 'N' && Process the Numeric Fields
MyString = str(MyString,Len(Str(MyString)),2)
Case MyType = 'I' && Process the Integer Fields
MyString = Str(MyString)
Case MyType = 'L' && Process the Logical Fields
If MyString = .T.
MyString = 'T'
Else
MyString = 'F'
EndIf
EndCase
If nCount < gnFieldCount && Determines if the last field was
&& processed and sets the closing quote.
cFieldString = cFieldString + '"' + MyString + '"' + ','
Else
cFieldString = cFieldString + '"' + MyString + '"'
EndIf
EndFor
Fputs(TextFile,cFieldString) && Writes string to the text file.
cFieldString = ''
EndScan
FClose(TextFile)
Close All
Clear All
Wait Window 'Text File Creation Completed' Nowait
REFERENCES
For additional information exporting memo fields, click the article number below
to view the article in the Microsoft Knowledge Base:
Q95722 How to Export Memo Fields to an ASCII File
Additional query words:
kbdse
Keywords : kbAutomation kbVFp500 kbVFp500a kbVFp600 kbXBase kbGrpFox kbDSupport kbCodeSnippet
Version : WINDOWS:5.0,5.0a,6.0
Platform : WINDOWS
Issue type : kbhowto