11 Replies Latest reply on Jan 18, 2012 1:53 PM by dv27

# How can one object perform different calculations in a repeatable subform?

I posted my question under a previous post, but am afraid it will be overlooked, so i'm posting it again in hopes of getting some much needed help.

I’m trying to apply a calculation to a numeric object. My calculations are dependent on:
1.      If a checkbox is checked
2.      The number of days entered
3.      The number of rows that are added (i'm using a repeatable subform)

Basically, if the first row is the ONLY row, then it can contain three possible calculations

1. if a checkbox is checked and the total number of days entered is <= 2, then the calculation is.... partial.rawValue  * Days.rawValue
2. if a checkbox is checked and the total number of days entered is > 2, then the calculation is....perDiem.rawValue * (Days.rawValue - 2 ) + (partial.rawValue * 2)
3. otherwise, the calcuation is....perDiem.rawValue * Days.rawValue

However, if more than one row is selected, then the first and the last row would contain the following possible calculations:

1. If a checkbox is checked, then the calculation is…perDiem.rawValue * (Days.rawValue - 1 ) + partial.rawValue
2. Otherwise, the calculation is…perDiem.rawValue * Days.rawValue

The middle rows are always going to contain one possible calculation of…perDiem.rawValue * Days.rawValue

I have NO idea how to setup my script... i'm assuming that i need to create multiple variable (first row and last row), but have failed so far.

• ###### 1. Re: How can one object perform different calculations in a repeatable subform?

Can you please share your form? It's hard to determine how your form is designed and I don't have the time to rebuild it by myself.

• ###### 2. Re: How can one object perform different calculations in a repeatable subform?

Sure, I can share it, but i'm not sure how. I dont see an option to upload a file to this message. Please let me know how to share and I'll do so. Thanks for your help!

• ###### 3. Re: How can one object perform different calculations in a repeatable subform?

Use a file sharing service in the web such as Acrobat.com.

• ###### 4. Re: How can one object perform different calculations in a repeatable subform?

Thanks! I just uploaded it to https://acrobat.com/#d=PwnUtMIB5OwKlPRnagr*UA

The object that I'm referring to is located at MIEexpSection.MIEexp.gsaTotal.

MIEexp is a repeatable subform.

Please let me know if you need anything else.

• ###### 6. Re: How can one object perform different calculations in a repeatable subform?

Try accessing it now: https://acrobat.com/#d=PwnUtMIB5OwKlPRnagr*UA

• ###### 7. Re: How can one object perform different calculations in a repeatable subform?

In what field the calculated result should be shown?

• ###### 8. Re: How can one object perform different calculations in a repeatable subform?

It should be shown in the gsaTotal field.

• ###### 9. Re: How can one object perform different calculations in a repeatable subform?

Ok, so far I could follow your instruction the formula (FormCalc) for the field gsaTotal look like:

var row = \$.parent.index

var rowCount = _MIEexp.count - 1

if (rowCount gt 0) then

if (row eq 0 or row eq rowCount) then

if (domestic eq 1) then

perDiem * (Days - 1) + partial

else

perDiem * Days

endif

else

perDiem * Days

endif

else

if (domestic eq 1 and Days le 2) then

partial * Days

elseif (domestic eq 1 and Days gt 2) then

perDiem * (Days - 2) + (partial * 2)

else

perDiem * Days

endif

endif

• ###### 10. Re: How can one object perform different calculations in a repeatable subform?

it's perfect!!! almost..

the last row displays a negative number, until a value is entered into the Days field. How can I avoid displaying the negative number? I assume I need to add an "If Days gt 0" somewhere in the code, but am not sure where. Can you please help?

• ###### 11. Re: How can one object perform different calculations in a repeatable subform?

Ok, try

var row = \$.parent.index

var rowCount = _MIEexp.count - 1

if (rowCount gt 0) then

if (row eq 0 or row eq rowCount) then

if (domestic eq 1 and Days gt 0) then

perDiem * (Days - 1) + partial

else

perDiem * Days

endif

else

perDiem * Days

endif

else

if (domestic eq 1 and Days le 2 and Days ne null) then

partial * Days

elseif (domestic eq 1 and Days gt 2) then

perDiem * (Days - 2) + (partial * 2)

else

perDiem * Days

endif

endif

• ###### 12. Re: How can one object perform different calculations in a repeatable subform?

Perfect!!!! thank you so much for your help!