I have an adobe form in which I need to calculate a value's variance from a range. For example, if the range is $1,000.00 to $2,500.00, and the value is $3,000.00, I need it to return a variance of $500.00. If the value was $1,500.00, I need it to return a variance of $0.00 since it falls in the range. There may be occasions in which the range is $0.00 to $0.00, in which case any value would be a variance.
I have a built an adobe form with the following form fields:
1.) Low End of Range (Set to $ Format)
2.) High End of Range (Set to $ Format)
3.) Actual (Set to $ Format)
4.) Average (Set to $ Format, automatically generates the average based on the entry to "Actual" field)
5.) $ Variance (Set to $ Format, automatically calculates the $ variance of the average to the ranges defined in 1 and 2 above)
6.) % Variance (Set to % Format, to automatically valculate the % variance of the average to the ranges defined in 1 and 2 above)
The problem I am having is when the user enters the high range they recieve an error saying "The valued entered does not match the format of the field [% Variance]". It does not seem to be causing an error with the calculation; however, I would like to find a way to avoid the error from displaying.
var Average = this.getField("Avg").value var Low = this.getField("Low").value var High = this.getField("High").value var Variance = this.getField("Variance$").value if (High== 0) event.value = ""; else if(Average <= Low) event.value = Variance / Low; else if (Average >= High) event.value = Variance / High;
When the divisor is zero the result of your calculation is Infinity, which is not a valid value for a field with the Number format. You need to first check for that, and only if the divisor is not zero proceed with the calculation.
I thought that is what I was doing with the
if (High== 0) event.value = "";
part of my formula?
Thank you in advance for your assistance!
What about the Low value?
When I tried using the same formula for the low value it wouldn't calculate anything.
In some instances, if I have a range of lets say $0.00 to $1,000.00, and the average is $1,500.00. I need a percentage variance for the $500.00.
Copy link to clipboard
var Average = Number(this.getField("Avg").valueAsString); var Low = Number(this.getField("Low").valueAsString); var High = Number(this.getField("High").valueAsString); var Variance = Number(this.getField("Variance$").valueAsString); if (Average <= Low && Low!=0) event.value = Variance / Low; else if (Average >= High && High!=0) event.value = Variance / High; else event.value = "";
I think that worked! Thank you!