PRB: Report Variables Calculated Incorrectly

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

SYMPTOMS

Variables defined in the Report Writer appear to be calculated incorrectly.

CAUSE

The variable that appears to be calculated incorrectly is making reference to another, as yet undefined, variable. This is because variables are defined and calculated in the order they are listed in the variable list.

RESOLUTION

In the variable list, change the order of the variables so that if a variable (mvarA) makes reference to another variable (mvarB) in the Value To Store box, the referenced variable (mvarB) appears earlier in the variable list. See below for a detailed explanation of the problem and its resolution.

MORE INFORMATION

Steps to Reproduce Problem

  1. In the Command window, type the following:

          USE \FOXPRO2\TUTORIAL\CUSTOMER.DBF
    

    (The directory specified will depend on the version of FoxPro and where it is stored on the system.)

  2. In the Command window, type:

          CREATE REPORT VARTEST.FRX
    

  3. Create three variables as follows:

    a. From the Report menu, choose Variables. b. Choose the Add button. c. In the Variable Name box, type "maverage" (without the quotation

          marks).
    
    d. In the Value To Store box, type "msum/mcount" (without the

          quotation marks).
    
    e. Choose the OK button. f. Choose the Add button. g. In the Variable Name box, type "msum" (without the quotation

          marks).
    
    h. In the Value To Store box, type "customer.ytdpurch" (without the

          quotation marks).
    
    i. Under Calculate, select the Sum option button. j. Choose the OK button. k. Choose the Add button. l. In the Variable Name box, type "mcount" (without the quotation

          marks).
    
    m. In the Value To Store box, type "customer.ytdpurch" (without the

          quotation marks).
    
    n. Under Calculate, select the Count option button. o. Choose the OK button. p. In the Report Variables dialog box, choose the OK button.

  4. Move to a Detail line and add the following fields:

        - customer.ytdpurch (from database field list)
        - msum (from variable list)
        - mcount (from variable list)
        - maverage (from variable list)
    

  5. From the Report menu, choose Page Preview.

    Note that the first "Average" is ******** (it should be equal to the sum). Also note that the second average uses the sum and count from the first record instead of the second record.

To correct the problem in this case:

  1. From the Report menu, choose Variables.

  2. In the Variables list, highlight maverage.

  3. Drag maverage to the end of the list (or hold down the CTRL key while pressing the DOWN ARROW key).

  4. Choose the OK button.

  5. From the Report menu, choose Page Preview.


Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a RWriter
KBCategory: kbprg kbprb
KBSubcategory: FxtoolRwriter


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.