How to Export Memo Fields to an ASCII FileLast reviewed: April 29, 1996Article ID: Q95722 |
The information in this article applies to:
SUMMARYThe COPY TO <filename> 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 INFORMATIONThe 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:
COPY TO <filename> FIELDS numfield, charfield, newchar ; TYPE DELIMITEDThe 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:
COPY TO <filename> FIELDS numfield, charfield, newchar ; TYPE DELIMITEDThe 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 2This 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 <filename> 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 "mydata", and that the memo field is to be treated as a character field:
handle=FCREATE('c:\mytext.txt') IF handle < 0 WAIT WINDOW "Unable to create file" 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))+",") *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," ") ENDFOR *the following line adds close quotes and a delimiter *after the memo field =FWRITE(handle,CHR(34)+",") *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) REFERENCESFoxPro version 2.0 for MS-DOS "Interface Guide," "Modifying Database Structure" FoxPro version 2.0 for MS-DOS "Developer's Guide," "Low-Level File I/O"
|
Additional reference words: VFoxWin 3.00 FoxDos FoxWin FoxMac 2.00 2.50
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |