How to Use a UDF to Calculate Percentages in a Report

Last reviewed: July 31, 1995
Article ID: Q132727
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxPro for Windows, version 2.6a

SUMMARY

To calculate percentages of a group total in report using the Report Writer, you must create a UDF (user defined function).

MORE INFORMATION

The FoxPro Report Writer calculates totals in a top down manner. To get a detail item's percentage of a total that resides in the group footer band, the total must first be calculated in the group header. This can be accomplished by using the following code in a UDF:

   SET TALK OFF
   PUBLIC msum     && initialize variable for sum total
   msum=0
   y=RECNO()       && store record number to variable so total from
   * previous group is not added on
   x=<field name>  && store field which is grouped to variable
   SUM <numeric field name> FOR  x=<field name> TO msum
   GO y
   RETURN msum     && this will simply display the total in the group
   * header that appears in the group footer

For more information about UDFs, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q113754
   TITLE     : "Syntax Error" When Verifying UDF() in Report Writer


Additional reference words: 3.00 VFoxWin
KBCategory: kbtool kbcode
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: July 31, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.