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



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 3.0
  • Microsoft Visual FoxPro for Windows 7.0
  • Microsoft Visual FoxPro 8.0

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


Modification Type:MajorLast Reviewed:2/17/2005
Keywords:KB132727 kbAudDeveloper