3 Replies Latest reply on Mar 14, 2012 7:19 AM by dohanlon

    FormCalc syntax and scripting issues

    cniethe1997

      Hi, I'm a total beginner at LiveCycle and FormCalc. I have been trying to create a simple form for a school assignment in which the user enters numeric data into a table and the last coloum then is calculated via FormCalc scripting. The equation which I have been attempting to express using FormCalc is  simple, (Cell1-Cell2)/Cell3*Cell4. I skimmed through a few tutorials but obviously my understanding of FormCalc and LiveCycle in general is insuffecient. I am hoping someone who could easily do this will help save me from having to learn FormCalc, any help or advice will be very much appreciated.

        • 1. Re: FormCalc syntax and scripting issues
          dohanlon Level 3

          You just need to select the field you want the calculation to appear in and go to the calculate event in the script window and use the following in formcalc

           

          $ = ( Cell1 - Cell2 ) / ( Cell3 * Cell4 )
          

           

          or whatever the corresponding field names are.

           

          Also, you need to cater for empty fields, either set the cells to be numeric with a default value or extend the script to test if a value has been entered yet. Something like

           

          if ( HasValue( TextField3 ) and HasValue( TextField4 ) ) then
              $ = ( TextField1 - TextField2 ) / ( TextField3 * TextField4 )
          else
               < some other calc here / or nothing>
          endif
          
          1 person found this helpful
          • 2. Re: FormCalc syntax and scripting issues
            cniethe1997 Level 1

            I appreciate the help but I actually wanted to know how to do,

            (Cell1 - Cell2) / Cell3 * Cell4,

            not

            (Cell1 - Cell2) / (Cell3 * Cell4).

            As, (8 - 4) / 4 * 5 = 5 but (8 - 4) / (4 * 5) = 0.2  it is evident that these are not the same. I apologize for not explaining clearly enough to begin with. I have spent a while trying to figure out the appropriate script but I continue to receive an arithmatic over/underflow error message. Also I was wondering which setting for 'Show:' on the script window will make the feild update when the feilds that are used in the calculation of its value are inputted. Any help is appreciated.

            • 3. Re: FormCalc syntax and scripting issues
              dohanlon Level 3

              You get the arithmetic over/underflow error because one of your fields is empty or 0. You still need to test for these cases before you do the calculation. So if Cell 3 is 0 or empty (i.e. null) then you need to decide what happens. No calculation?

               

              The correct calculation when all fields are entered is

               

              $ = ( Cell1 - Cell2 ) / Cell3 * Cell4

               

              but you really must test for Cell3 first to trap the error. Once all fields are entered, the error disappears. Something like

               

              if ( HasValue( Cell3 ) )

              {

                   $ = ( Cell1 - Cell2 ) / Cell3 * Cell4

              }