How to Add Information to Existing Data in a Field

Last reviewed: June 27, 1995
Article ID: Q111312
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, and 2.5b
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, and 2.5b
  • Microsoft FoxPro for Macintosh, version 2.5b

SUMMARY

In order to use the REPLACE command to replace a field with the existing field contents plus more information, you must use the TRIM() function as part of the REPLACE statement. If the TRIM() function is not used, FoxPro seems to execute the replacements; however, the table is not updated.

MORE INFORMATION

The contents of a field include any trailing blank spaces. When you attempt to replace a field with its existing contents plus additional data, the additional data will be concatenated to the end of the entire field including the trailing blanks. Since this is longer than the defined length of the field, the additional data will not be included when the field is updated. In order to add data to the existing contents of a field, you must remove the trailing blank spaces prior to adding the new data. You can accomplish this with the TRIM() function.

The following program example is based on the assumption that C:\FOXPRO25 is the main FoxPro directory and that the TUTORIAL subdirectory and its contents are installed as one of the subdirectories under FOXPRO25. In this example, we will use CUSTOMER.DBF in the C:\FOXPRO25\TUTORIAL subdirectory and will update all records that have "1st" in the COMPANY field to add "Inc." to the end of this field.

NOTE: Before making any changes to the original database, use the COPY TO command to make a backup copy of the existing database. Also, to find the CUSTOMER database for this example, make sure that the default directory is the main FoxPro directory.

Example

  1. Type the following in the Command window:

          USE C:\FOXPRO25\TUTORIAL\customer
          COPY TO cust2.dbf
    

  2. Type the following commands in the Command window:

          SELECT CUSTOMER
          BROWSE
    

    Note that the first four records have COMPANY fields with "1st" in them.

    The COMPANY fields should be:

          1st Computers
          1st Data Reductions
          1st Software Systems Ltd.
          1st Survey
    

  3. Press ESC to close the Browse window on the CUSTOMER database.

  4. Type the following REPLACE command in the Command window:

         REPLACE company with TRIM(company)+" Inc." for "1st" $ company
    

    FoxPro will display the "4 replacements" message to indicate that the replacements were successful.

  5. In the Command window, type the following:

          GO TOP
          BROWSE
    

Note that the four records have changed.


Additional reference words: FoxMac FoxDos FoxWin 2.0 2.50 2.50a 2.50b
KBCategory: kbprg
KBSubcategory: FxprgBrowse


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: June 27, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.