IF Statement in InfoPath & Help with formula

S

spence

Hi All

I am an EXTREME newbie to InfoPath so please forgive me if I am asking
a stupid question!

I have five fields called SHAPE, LENGTH, WIDTH, DIAMETER and RESULT.
The SHAPE field is a drop down list box with two options - 1. Square,
2. Circle. I want the user to be able to select Square, then fill in
the LENGTH and WIDTH fields and then the result of a formula based on
these two fields to be outputted to the RESULT field.

If the user selects Circle, then fills in the DIAMETER field I want to
use a different formula to get the results to the RESULT field.

In short, selecting one option from a drop down list uses one formula
and selecting the other option uses a different formula.

The way it's working in my head is this:

If SHAPE = Square, then RESULT = formula using numbers in LENGTH and
WIDTH fields
If SHAPE = Circle, then RESULT = formula using number in DIAMETER field

Many thanks in advance

Ben
 
S

spence

Do you mean the sample called 'calc.xsn'? Because I can't find any
calculations on the form template at all!
 
O

olivier

Yes, you have to open the code script.
Tools/Design this form (message upgrade to SP1, click No)
Tools/Script/Microsoft Script Editor (MSE)
have a look to "function CalcItemTotal(itemNode)" it shows how to get
several fields, apply a calculation and store it.

In your case, you can select your shape field and then right click,
properties/data validation/event/On after change/Edit. This open MSE on the
function which will be fired. Store the code there. each time the field is
modified your script is called. The shape value is given by eventObj.NewValue
that you can test

If (eventObj.Newvalue=="Square")
{
// put here the formula for Square
}
else
{
// put here the formula for circle
}

Use SelectSingleNode to get each value just like written in the example, of
course after replacing the xpath with yours. Be careful, case sensitive !
 
S

spence

Thank you olivier for your help. Much appreciated. I'm sure I'll be
able to work things out from here
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top