Microsoft KB Archive/95722

= How to Export Memo Fields to an ASCII File =

Article ID: 95722

Article Last Modified on 12/1/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft FoxPro 2.0
 * Microsoft FoxPro 2.6a Professional Edition for Macintosh

-



This article was previously published under Q95722



SUMMARY
The COPY TO TYPE DELIMITED command ignores memo fields. To create an ASCII, delimited file from a .DBF file that contains memo fields, you must either convert the memo fields to character fields or use low-level file I/O commands.



MORE INFORMATION
The following examples assume the .DBF file has the following structure:   FIELD NAME            TYPE Numfield             Numeric Memo1                Memo Charfield            Character

Method 1 (For FoxPro 2.x Only)
To convert the memo field to a character field:  In the Command window, type:

USE

 From the Database menu, choose Setup. In the Setup dialog box, choose the Modify button. In the Structure dialog box, add a field &quot;Newchar&quot; of type character. The length of the character field should be large enough to accommodate the largest memo field. To save your changes, choose the OK button in the Structure dialog box, choose the Yes button in the &quot;Make structure changes permanent?&quot; message box, and choose the OK button in the Setup dialog box. In the Command window, type:

REPLACE ALL newchar WITH memo1

</li></ol>

You can now create an ASCII, delimited file from the database with the following command:

COPY TO FIELDS numfield, charfield, newchar ;

TYPE DELIMITED

The limitation of this method is that the maximum number of characters allowed in a character field is 254. If the memo field is longer than this, it will be truncated.

Method 1 (For Visual FoxPro)
To convert the memo field to a character field: <ol> In the Command window, type:

USE <database_name>! <table_name>

</li> From the Window menu, choose View.</li> In the View dialog box, choose the Properties button.</li> In the Work area Properties dialog box, choose Modify.</li> In the Table designer dialog box, add a field &quot;Newchar&quot; of type Character. The length of the character field should be large enough to accommodate the largest memo field.</li> To save your changes, choose the OK button in the Table designer dialog box, choose the Yes button in the &quot;Make structure changes permanent?&quot; dialog box, and choose the OK button in the Work area Properties dialog box.</li> In the Command window, type:

REPLACE ALL newchar WITH memo1

</li></ol>

You can now create an ASCII-delimited file from the database with the following command:

COPY TO FIELDS numfield, charfield, newchar ;

TYPE DELIMITED

The limitation of this method is that the maximum number of characters allowed in a character field is 254. If the memo field is longer than this, it will be truncated.

Method 2
This method uses low-level file I/O commands to create the ASCII, delimited file. The file created is in the same format as a file created with the COPY TO TYPE DELIMITED command; that is, fields are separated by commas, and character fields are enclosed in quotation marks. The following example assumes that the database is named &quot;mydata&quot;, and that the memo field is to be treated as a character field: handle=FCREATE('c:\mytext.txt') IF handle < 0 WAIT WINDOW &quot;Unable to create file&quot; RETURN ENDIF USE mydata SCAN *Numeric values must be converted to characters before *writing them to a text file. *The following line converts the number to a string =FWRITE(handle,ALLTRIM(STR(numfield))+&quot;,&quot;) *The following sends open quotes for the memo field =FWRITE(handle,CHR(34)) x=MEMLINES(memo1) FOR i = 1 TO x      =FWRITE(handle,MLINE(memo1,i)) *The following line inserts a space before writing the next *line from the memo field =FWRITE(handle,&quot; &quot;) ENDFOR *the following line adds close quotes and a delimiter *after the memo field =FWRITE(handle,CHR(34)+&quot;,&quot;) *the following line uses FPUTS to end a record with a    *carriage return and linefeed =FPUTS(handle,CHR(34)+ALLTRIM(charfield)+CHR(34)) ENDSCAN =FCLOSE(handle)

<div class="references_section">