Skip to main content
Known Participant
April 5, 2022
Question

Hi - Help needed please?

  • April 5, 2022
  • 2 replies
  • 1494 views

As a complete javascript novice I've been trying to duplicate the formulae in an operating Excel file, in an Acrobat 'form'. Below is an example of the typical Excel formula (of which there are x40), with reference to calculations performed on various cell data :

=D14-(D22*1000*0.02)/($T$20*35.6)-$M$5

I have attempted to use Acrobat 'custom calculation script' to perform the same process and arrived at this:

event.value = (this.getField("22_AWG01").value)-(0.326*1000*0.02)/(this.getField("Total_current").value*35.6)-(this.getField("Metres").value)

In many cases this does return the answer/s I was expecting - but not in every case. No doubt my method or syntax is probably inappropriate

I do have some extra functions/conditions to apply if possible, should I manage to get this fixed

MTIA
Steve


This topic has been closed for replies.

2 replies

Legend
April 5, 2022

I think you need to break it down and look at the exact detail. The formula looks plausible, but of course we don't know what's in your fields or what you see. Take one case where it doesn't do what you expect.

-Tell us the value Excel gives and the value found in D14, D22, T20 and M5.

-Tell us the value Acrobat gives.

-And tell us the value of 22_AWG01, Total_current and Metres

(As well, of course, as telling us why you've replaced the reference to D22 by the constant 0.326)

Known Participant
April 6, 2022

Hi Test Screen Name
I've been through the figures, and the calculations do appear to be correct. The main issue I now think is that the x80 fields containing calculations don't all update simultaneously when the custom user data is inserted. As I've been working on this project I found the first & second rows (2x8=16 fields at the top of the page) were calculating instantly - as I scrolled down the page, what I thought were incorrect calculations (eg my errors) were fields that hadn't yet re-calculated. If I retun to the pdf 15 seconds later all the calculations have updated correctly. I have been through and checked the field calculation order which luckily, for the most part, followed my construction of the field layout.

Is there a way I can speed up the calculations, or add a button to click to 'Update all fields'?
As there are a few more issues to resolve on this project I'm happy to reimburse for time spent helping.
Attached is the 'bare bones' design of the form showing the fields which I intend to copy into a designed layout.
Steve

Legend
April 6, 2022

Hi Bernd
I have looked into this. Would you suggest performing all the 'add/multiply/subtract/division' calculations before performing the conversion (metres to feet) calculations? 


Don't try and follow rules about what kind of calculation. It really is the order of calculation, and only you can know this information. (Ironically, Excel can know this without you tell it!)

 

In a simple case consider a form like this

 

Item 1 price ...  A

Item  2 price ...  B

Subtotal  ...     C     C=A+B

Tax ....    D     D=C*0.2

Total to pay .... E   E=C+D

 

You can see you cannot calcuate E until you have calculated C and D. You cannot calculate D until you have calculated C. And so on. We know this insinctively as humans, and we also tend to go from top to bottom. Acrobat is not smart, and does not automatically go from top to bottom, so we have to tell it the right order. If not sure, just work through on piece of paper without making any assumptions.

 

Bernd Alheit
Community Expert
Community Expert
April 5, 2022

(0.326*1000*0.02)

Why does you use 0.326 here?

Known Participant
April 5, 2022

Hi Bernd - thanks for looking.

Sorry,  I confused the issue.
In the Excel file there are some referenced cells "D12, D22, D32, D42, D52" - that all have a set value 0.326.
I thought that it would be easier for me to 'read what was going on' if I substituted the Cell ref for its set value.

 

the sum I get from the above calc has to be converted from metres to feet

event.value = (this.getField("22_AWG01").value)/0.3048

 

Is my javascript fit for purpose?

Steve