FIX: COPY TO DELIMITED Creates File with No Carriage Returns

Last reviewed: October 20, 1997
Article ID: Q110539
2.50b MACINTOSH kbusage kbfixlist kbbuglist kbtshoot kbcode

 The information in this article applies to:

  - Microsoft FoxPro for Macintosh, version 2.5b

SYMPTOMS

In FoxPro for Windows and FoxPro for MS-DOS, the following commands create a delimited ASCII file, with each record terminated by a carriage return and linefeed (CR/LF) combination. In FoxPro for Macintosh, the same commands create a delimited ASCII file, with each record terminated by a linefeed only.

   USE customer
   COPY TO newfile TYPE DELIMITED

Many programs, such as Microsoft Word for Macintosh, require that delimited records be terminated by a carriage return at the end of each record. This problem occurs regardless of the delimiter used; for example, the problem occurs whether the DELIMITED or DELIMITED WITH TAB clause is used.

RESOLUTION

There are two possible workarounds for this problem:

  • Load the text file into an editor that recognizes the linefeed characters, and then use the editor's search and replace feature to replace each linefeed with a carriage return.

    To do this using the FoxPro file editor, perform the following:

    1. In the Command window, type "MODIFY FILE <filename>" (without

          the quotation marks).
    

    2. From the Edit menu, choose Find.

    3. In the Look For text box, type "\n" (without the quotation

          marks) to search for the linefeed.
    

    4. In the Replace With text box, type "\r\n" (without the quotation

          marks) to replace the linefeed with a carriage return and a linefeed.
    

    5. Choose Replace All.

    NOTE: For more information on searching for special characters, see the following sections of the online Help file:

        - FoxPro FOXHELP.HLP online Help file, "Find Dialog" jump text,
          under the "Interface A-Z" topic
    

        - FoxPro FOXHELP.DBF online Help file, "Find" topic, under "The
          FoxPro Interface" section
    

    -or-

  • Write a program that performs low-level file I/O and adds a carriage return to each line, as shown in the following sample program.

    USE SYS(2004)+"\tutorial\customer.dbf" COPY TO test.txt TYPE DELIMITED FOR RECNO() < 5

       infile=FOPEN("test.txt",10)         && read-only, unbuffered
       IF infile > 0       && file opened?
          SET SAFETY OFF   && no warnings
          outfile=FCREATE("test2.txt",0)  && create read/write file
          IF outfile > 0
             FOR F=1 TO FCOUNT()       && loop through fields +
                =FSEEK(outfile,0,2)     && go to end of file
                =FWRITE(outfile,CHR(34)+FIELD(F)+CHR(34)+ ;
                   IIF(F=FCOUNT(),[],[,])) && write field names
             ENDFOR
             =FWRITE(outfile,CHR(13))    && carriage return (CR) +
             DO WHILE NOT FEOF(infile)   && now get data from
                linein=FGETS(infile)      && the input file
                =FSEEK(outfile,0,2)      && point to end of file
                =FWRITE(outfile,linein+CHR(13))&& write data with CR terminator
             ENDDO
             =FCLOSE(outfile)   && close output file
          ENDIF
          =FCLOSE(infile)       && close input file
       ENDIF
    
       USE                      && close the database
    
       NOTE: The plus sign ("+") at the end of a line denotes a code block that
       is necessary only if saving the field names is necessary, such as when
       you are creating a Word Merge list.
    
    

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. This problem was corrected in FoxPro 2.6a for Macintosh.


Additional reference words: FoxMac 2.50b fixlist2.60a buglist2.50b line
feed hard return soft return tshoot trouble-shoot
KBCategory: kbusage kbfixlist kbbuglist kbtshoot kbcode
KBSubcategory:
Keywords : kbbuglist kbcode kbfixlist kbtshoot kbusage
Version : 2.50b
Platform : MACINTOSH
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 20, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.