Add subtract multiply and divide values in a control InfoPath 2007
Author: mety Labels:: Add subtract multiply and divide values in a control InfoPath 2007You can help your users fill out forms based on your form template by using formulas to calculate the value for a control, based on data that the user enters into other controls. The calculations can include adding, subtracting, multiplying, and dividing values. For example, if you are designing a form template that electrical contractors will use to apply for permits, you can add a formula to a control that automatically calculates the total price that the contractor has to pay for the application by multiplying the number of permits in the application by the price of each permit. A formula is an XPath expression made up of values, fields or groups, functions, and operators used to calculate and display other values. Formulas can be used to do the following tasks:
Each XPath expression that is used in a formula is a combination of values, functions, and operators that evaluates to a single value. A formula can contain several expressions. You can think of a formula as a sentence made up of one or more phrases, with each phrase representing one expression in the formula. The following illustration shows the relationship between a formula and an expression. A function is an expression that returns a value based on the results of a calculation. The values used in the functions are called arguments. You can use the standard XPath 1.0 functions that are included in InfoPath, as well as some InfoPath-specific functions. Find links to more information about InfoPath functions in the See also section. Using two or more operators in a formulaWhen a formula contains two or more mathematical operators, InfoPath performs the calculation according to the precedence of the operator. The following list shows the order in which operations are performed:
For example, imagine that you are creating a permit application form template that has a text box that displays the total cost of all of the permits submitted in an application. The values required by this formula come from other text boxes in the form. The text box that shows the total cost contains the following formula: txtPermit1Qty * txtPermitCost1 + txtPermit2Qty * txtPermitCost2 /txtNumberOfPermits This formula includes addition (+), multiplication (*), and division (/) operators. According to the precedence of operators, the multiplication and division calculations are performed before the addition calculation. Since the multiplication and division operators have the same precedence, the multiplication calculation is done before the division operator because the multiplication operator is located to the left of the division operator. The formula is calculated in this way:
For example, consider the following formula: ((txtPermit1Qty * txtPermitCost1) + (txtPermit2Qty * txtPermitCost2))/txtNumberOfPermits In this calculation, the value that results from multiplying the values in txtPermit1Qty and txtPermitCost1 is added to the value that results from multiplying the values in txtPermit2Qty and txtPermitCost2. The sum of that calculation is then divided by the value in txtNumberOfPermits. Insert a mathematical formula into a control
|