Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

I need to replicate excel formula (D31)/SIN(RADIANS(D29)), using Simplified Field Notation

Community Beginner ,
Aug 28, 2018 Aug 28, 2018

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. 

TOPICS
Acrobat SDK and JavaScript , Windows
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 29, 2018 Aug 29, 2018

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);

}

Translate
LEGEND ,
Aug 28, 2018 Aug 28, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 28, 2018 Aug 28, 2018

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))

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 28, 2018 Aug 28, 2018

You can't use the Simplified Field Notation to do it. It requires writing a custom calculation script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 28, 2018 Aug 28, 2018

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!    

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 28, 2018 Aug 28, 2018
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 28, 2018 Aug 28, 2018

Thank you for your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 28, 2018 Aug 28, 2018

It wouldn't be   0.0174533(angleindegrees)  it would be  0.0174533*angleindegrees  to multiply.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 28, 2018 Aug 28, 2018

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 28, 2018 Aug 28, 2018

Does this look more like it?  intendedloadinlbs/Math.sin0.0174533*angleindegrees

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 28, 2018 Aug 28, 2018

I suggest you study this page quite carefully: JavaScript Math Reference

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 28, 2018 Aug 28, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 29, 2018 Aug 29, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2018 Aug 29, 2018

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2018 Aug 29, 2018

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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 29, 2018 Aug 29, 2018
LATEST

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines