PRB: Report Variables Calculated Incorrectly

ID: Q97051

The information in this article applies to:

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

Last Reviewed: June 27, 1995