Expand my Community achievements bar.

Repeatable subforms script calculation syntax

Avatar

Level 2
My form contains a subform (row) with 5 radio buttons, with values (scores) of 5,4,3,2, and 1. The user may add another of these subforms by clicking a button.



My intention is to set a field with the average score -- that is, obviously, the total scores, divided by the number of rows. Here is my FormCalc for the calculate event of the Average field -- complete with error message:



b Script failed (language is formcalc; context is

b xfa[0].form[0].form1[0].Pg1[0].#subform[2].EssentialAv[0])



b script=



b var totPts =



b Sum(form1.Pg1.EssentialJobRow[*].RadioButtonList.#field[3])+

b Sum(form1.Pg1.EssentialJobRow[*].RadioButtonList.#field[2])+

b Sum(form1.Pg1.EssentialJobRow[*].RadioButtonList.#field[1])+

b Sum(form1.Pg1.EssentialJobRow[*].RadioButtonList.#field[0])+

b Sum(form1.Pg1.EssentialJobRow[*].RadioButtonList.#field[4])



b var numRows =

b Count(form1.Pg1.EssentialJobRow[*].RadioButtonList.#field[4])



b //$.rawValue=totPts



b //$.rawValue=numRows



b $.rawValue = totPts/numRows



b Error: arithmetic over/underflow.



I have used the commented lines in debugging, to prove that the total score and the number of rows are being calculated correctly. There is always at least one instance of the subform, so numRows is always greater or equal to 1 -- never 0.



This is such a simple thing, I know the answer must be staring me in the face, but I do not see it.



Thanks for any suggestions you may have.
4 Replies

Avatar

Former Community Member
Hi Darrell,



You said you tested and verified the total wasn't 0. Is your total a negative number? This error message could be for both scenarios.



Here is a link below to a form sample that may help validating for negative numbers in a field.



http://partners.adobe.com/public/developer/en/livecycle/lc_designer_validation_tutorial.pdf



Have a great day!

Pam

Avatar

Level 2
Thanks, Pam. No, no negative numbers (unless it is happening somewhere behind stage). I have used both message boxes, and the commented lines to try to find the problem, but the values always look OK until I do the division.

Avatar

Level 2
I was mistaken. The number of rows *does* go to 0.



To test, I displayed the total points and number of rows variables with two message boxes.



When I click the button to add a row, the point count and the row count increment properly.



However, when I click one of the unselected radio buttons in a row, the point total increments correctly, but the row count sometimes is 0.



I suspect it relates to the sequence of events related to my use of the Count function to try to determine how many instances of the row exist.



Back to the drawing board to find a more appropriate way to determine the number of subforms I have created . . .

Avatar

Level 2
This works:



var numRows = _EssentialJobRow.count