Microsoft KB Archive/111872

From BetaArchive Wiki

Character Field Transferred to Microsoft Excel as Numeric

ID: Q111872

The information in this article applies to:

  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b

SYMPTOMS

A FoxPro character type field that contains numbers is converted to a numeric field in Microsoft Excel when the FoxPro dynamic data exchange (DDE) functions are used.

RESOLUTION

To avoid this situation, do one of the following:

  • Add a single quotation mark to the beginning of the field; for example:

          =DDEPOKE(mchan,"R1C1","'"+fld1)

    NOTE: This method will transfer the FLD1 field as character but will add an additional single quotation mark toward the beginning of the field. This extra quotation mark can be removed manually or with the help of a Microsoft Excel macro.

    -or-

  • Add '="' to the beginning of the field and '"' to the end; for example:

          =DDEPOKE(CHAN,"R1C1",'="'+fld1+'"')

    With this method, Microsoft Excel will treat the contents of FLD1 as an expression.

MORE INFORMATION

Steps to Reproduce Problem

1. Open Microsoft Excel with Sheet1 as the active worksheet.

2. Open FoxPro for Windows and issue the following commands from the

   Command window:

      CREATE TABLE xddetst.dbf (fld1 C(8))
      APPEND BLANK
      REPLACE fld1 WITH "12345678"
      mchan = DDEINITIATE("EXCEL","SHEET1")
      =DDEPOKE(mchan,"R1C1",fld1)

   With the above DDEPOKE() command FoxPro will send the FLD1 field
   contents to cell A1 in Sheet1 of Microsoft Excel.

3. Press ALT+TAB to switch to Microsoft Excel. Here you will see that the

   contents of FLD1 were transferred to cell A1 in Sheet1 as a numeric
   field.

In Microsoft Excel, to enter a number, string, or formula as text, you have to prefix the data with a single quotation mark. If you select cell A1, you will see that the Formula Bar does not display a single quotation mark before the cell's contents. Additional reference words: FoxWin 2.50 2.50a 2.50b number format

KBCategory: kbinterop kbprg KBSubcategory: FxinteropDde


Last Reviewed: June 26, 1995
© 1999 Microsoft Corporation. All rights reserved. Terms of Use.