Copy link to clipboard
Copied
Is it possible for me to replicate excel formula (D31)/SIN(RADIANS(D29)) using Simplified Field Notation? I have been playing around with Math.sin(x) but cannot seem to get it to work. Let's just say that D31 is field "Intended Load in lbs." and D29 is field "Angle in degrees". Should it be intendedloadinlbs/Math.sin(angleindegrees)?
Any help would be greatly appreciated.
I'm going to help you out a bit with this... Try this code:
var v1 = Number(this.getField("slingsintendedload").valueAsString);
var v2 = Number(this.getField("Slingangleindegrees").valueAsString);
var v3 = Math.sin(degToRad(v2));
if (v3==0) event.value = "";
else event.value = v1 / v3;
function degToRad(v) {
return v * (Math.PI/180);
}
Copy link to clipboard
Copied
Math.sin takes radians too, so you have to convert those degrees to radians. There's no function to do this, so just multiply by 0.0174533
Copy link to clipboard
Copied
Thank you Test Screen Name! Just to make sure I am understanding correctly, would the text in Simplified Field Notation be (intendedloadinlbs/Math.sin(0.0174533(angleindegrees))
Copy link to clipboard
Copied
You can't use the Simplified Field Notation to do it. It requires writing a custom calculation script.
Copy link to clipboard
Copied
Thank you try67. I will have to research further and learn how to write a custom calculation script. I have been tasked with creating a Critical Lift (Cranes and Rigging) PDF, which autofills certain fields based on the preset calculations, and I only have this last one left. It's definitely a show stopper!
Copy link to clipboard
Copied
A good place to start: https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations
Copy link to clipboard
Copied
Thank you for your help!
Copy link to clipboard
Copied
It wouldn't be 0.0174533(angleindegrees) it would be 0.0174533*angleindegrees to multiply.
Copy link to clipboard
Copied
I greatly appreciate it! Between your advice and the self help link provided by try67, I have a better shot of getting this figured out than before I posted my question on the forum.
Copy link to clipboard
Copied
Does this look more like it? intendedloadinlbs/Math.sin0.0174533*angleindegrees
Copy link to clipboard
Copied
I suggest you study this page quite carefully: JavaScript Math Reference
Copy link to clipboard
Copied
As try67 mentioned earlier, you cannot use the simplified field notation option for this, you need to use JavaScript. The tutorial linked to earlier has more information in the "Custom calculation script" section at the end. The best thing you can do now is read those first three paragraphs.
Copy link to clipboard
Copied
Thank you for the help. I am certainly no expert, which is why I am hoping someone can throw me a lifeline on this forum. I have taken all suggestions and came back with this custom validation script. I pray I am close to where I need to be. Any suggestions would be greatly appreciated.
event.value = ( this.getField("slingsintendedload").value / Math.sin * 0.0174533 * this.getField("Slingangleindegrees").value
Copy link to clipboard
Copied
First of all, move the code to be the field's custom calculation script.
Then, when you apply it, you should get this error message:
SyntaxError: missing ) in parenthetical
Fix that and then move on to the next problem, namely that you're not using Math.sin correctly, as it's a function and you need to provide it with a parameter within parentheses, for example:
Math.sin(90)
Copy link to clipboard
Copied
I'm going to help you out a bit with this... Try this code:
var v1 = Number(this.getField("slingsintendedload").valueAsString);
var v2 = Number(this.getField("Slingangleindegrees").valueAsString);
var v3 = Math.sin(degToRad(v2));
if (v3==0) event.value = "";
else event.value = v1 / v3;
function degToRad(v) {
return v * (Math.PI/180);
}
Copy link to clipboard
Copied
I cannot thank you enough try67. I will eventually become more fluent with the coding, but again, this is my first time ever having a need to create such a code. I am grateful for the experts on this forum, such as yourself, who is willing to take time out of their day and help the amateurs like me.