Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Using formCalc or JavaScript

Avatar

Level 5

Good Day All;

I am now getting into forms that require some calculations. In doing some reading I have seen where both JavaScript and FormCalc are being used. Can anyone tell me which is the better to use?

For the form I am currently designing I have tried formCalc but I have hit a wee bump. I have ued the following “if(cost_p_h ne 0) thenSum(60/file_p_h) endif” and received the following error

Script failed (language is formcalc; context is xfa[0].form[0].form1[0].#subform[0].#subform[1].Table1[0].Row1[0].dur[0])

script=if(cost_p_h ne 0) thenSum(60/file_p_h) endif

   Error: syntax error near token 'thenSum' on line 1, column 25.

I am currently running Acrobat Pro 8 and the version of LiveCycle Designer is 8.05

Thanks All.

Chomp

1 Accepted Solution

Avatar

Correct answer by
Level 7

It is becuase if files in blank it counts that as not equal to 0 so does the calculation. try:

if (files > 0) then

     Sum(60/files)

else $ = ""

endif

View solution in original post

6 Replies

Avatar

Level 4

Hello Chomp,

In your script you should give a space between then and Sum as follows:

if(cost_p_h ne 0) then Sum(60/file_p_h) endif”

Hope,this will help you.

Thanks,

Debadas.

Avatar

Level 5

Thanks Debadas;

I made the change to "  if (cost_p_h ne 0) then Sum(60/file_p_h) endif

Then I get the following error

Script failed (language is formcalc; context is xfa[0].form[0].form1[0].#subform[0].#subform[1].Table1[0].Row1[0].dur[0])

script=if(cost_p_h ne 0) then Sum(60/file_p_h) endif

   Error: arithmetic over/underflow.

Any thoughts?

Thanks

Chomp

Avatar

Level 4

Hello Chomp,

You can not divide by zero, so you need to add code to only allow the division when you have a non-zero divisor.

So for  this script Sum(60/file_p_h), you have check wheather file_p_h is non-zero.


if(file_p_h ne 0) then Sum(60/file_p_h) endif

Thanks,

Debadas.

Avatar

Level 5

Sorry for taking so long to respond to your post Debadas.

I have used if(file_p_h ne 0) then Sum(60/file_p_h) endif and I am still getting the arithmetic over/underflow error.

I created a new simple form with 4 fields

position = dropdown with 3 entries

wage = numeric field

files= numeric field

cost = numeric field

As soon as I open the form I get the arithmetric over/underflow error (divide by 0)

I put the code in the "cost" field using show = calculate*   if(files ne 0) then Sum(60/files) endif and the language = formCalc.

When I clear the error and enter a number in the "files" field, the calculation works.

I know I am missing something.. It is just the what.

Thanks again Debadas

Avatar

Correct answer by
Level 7

It is becuase if files in blank it counts that as not equal to 0 so does the calculation. try:

if (files > 0) then

     Sum(60/files)

else $ = ""

endif

Avatar

Level 5

Thank you very much. worked like a charm.... Not toooo sure why the "ne 0" did not work.

Chomp