Knowledge Base

How to use a user-defined function to calculate percentages in a report group footer in Visual FoxPro

Article ID: 132727

Article Last Modified on 2/17/2005


APPLIES TO


This article was previously published under Q132727

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 public 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 ""  
   
Put this UDF in the group header. Add a text box to the group footer to display the results of the Msum variable.

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

113754 "Syntax Error" When Verifying UDF() in Report Writer


Additional query words: VFoxWin

Keywords: KB132727