Q132727: How to Use a UDF to Calculate Percentages in a Report
Article: Q132727
Product(s): Microsoft FoxPro
Version(s): WINDOWS:2.6a,3.0
Operating System(s):
Keyword(s):
Last Modified: 15-FEB-2000
-------------------------------------------------------------------------------
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:
Q113754 "Syntax Error" When Verifying UDF() in Report Writer
Additional query words: VFoxWin
======================================================================
Keywords :
Technology : kbVFPsearch kbAudDeveloper kbFoxproSearch kbFoxPro260a kbVFP300
Version : WINDOWS:2.6a,3.0
=============================================================================
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.
Copyright Microsoft Corporation 1986-2002.