About the Calculations Developer Sample Form [InfoPath 2003 SDK Documentation]

Applies to:

Microsoft Office InfoPath 2003

For information on Service Pack 1 features for working with calculations, see the "Calculating Data" section in the InfoPath 2003 Help.

The Calculations developer sample form uses events and custom functions to demonstrate how to programmatically perform calculations and update fields in a Microsoft Office InfoPath form. In InfoPath, event handlers are used to implement client-side business logic, which may include controlling the behavior of a form, responding to form events, validating user input, or submitting a form. This sample form highlights the use of a field's OnAfterChange event to update other values in the form that depend on a value entered or changed by a user.

The Calculations developer sample form is based on a product list and order form scenario. It contains two views:

  • Products view  The default view in which the user can create a list of product categories and products in the Products section, and then enter order items for these products in the Items section.
  • Summary view  A simple view containing two fields that display a sales summary figure for a selected product.

In both views, scripting code in the form responds to the OnAfterChange events of various fields by updating product information and recalculating values whenever necessary.

To test the features of the sample form, open the form in the default Products view and enter a list of product categories and products in the Products section. Then enter some order items for these products in the Items section. Observe that the scripting code in the form not only fills in the item name and price based on the Product ID entered, but calculates the line item totals, order total, and aggregate values, including the average, minimum, and maximum line item cost. You can then switch to Summary view and select a product in the drop-down list box to see the calculated total of order line items for a selected product.

Warning  For the sake of brevity, the scripting code used in the Calculations developer sample form does not include extensive data validation. In a real-world scenario, you would need to add stronger validation code to ensure that your fields contain the appropriate data.

Note   To see all of the files that make up the Calculations developer sample form, open the form and click Extract Form Files on the File menu while in design mode. This extracts all of the form files from the form template file and saves them to a specified folder on your hard disk.

To learn how the calculation features are implemented in the Calculations developer sample form, see the following topics:

Product View Calculations in the Calculations Developer Sample Form

Summary View Calculations in the Calculations Developer Sample Form

Products Secondary Data Source in the Calculations Developer Sample Form

See Also | About the SDK Developer Sample Forms