7 Replies Latest reply on Mar 27, 2017 1:55 PM by lambo99

    Multiple Line if statements

    lambo99

      I am trying to run a multiple variable statement.  When i run the statement individually it works, but one I combine multiple lines it only reads the last line.  could someone tell me where I am going wrong?

       

      this.getField("Capacity").value ="";

      if (this.getField("Media").value == "Liquid" && this.getField("Orifice").value == ("D")&& this.getField("Series").value == ("740")){this.getField("Capacity").value = ((this.getField("Area")).value *4.814)*.791*Math.sqrt(62.37*(this.getField("PSI")).value*1.1)}

      ;

       

       

      this.getField("Capacity").value ="";

      if (this.getField("Media").value == "Liquid" && this.getField("Orifice").value == ("D")&& this.getField("Series").value == ("741")){this.getField("Capacity").value = ((this.getField("Area")).value *4.814)*.791*Math.sqrt(62.37*(this.getField("PSI")).value*1.1)}

      ;

        • 1. Re: Multiple Line if statements
          Karl Heinz Kremer Adobe Community Professional

          You have extra "()" around the string constants, but that should not cause any problems. Just to make things more readable, you may want to change things like this

           

          this.getField("Orifice").value == ("D")

           

          to this:

           

           

          this.getField("Orifice").value == "D"

           

           

           

          I don't see anything that is obviously wrong.

           

          Can you tell me what exactly is not working? Are you getting syntax errors? Are the results not what you would expect?

          • 2. Re: Multiple Line if statements
            lambo99 Level 1

            The issue I am having is if I have the  "741" value selected the "capacity" value shows.  But if I change the "741" value to "740" like the line above, the "capacity" value does not show.  If i delete out the second statement with the "741" value and just have the "740" value it does work.  So what i am figuring is the program is only reading the last statement I put in.

            • 3. Re: Multiple Line if statements
              lambo99 Level 1

              Maybe I need an Else if statement?

              • 4. Re: Multiple Line if statements
                Karl Heinz Kremer Adobe Community Professional

                Ah, now I see, there was a one character difference between the two lines. I assumed that somehow the second one was an accidental copy of the first one. You need to change your logic a little bit if you want to test for both "740" and "741" (I've reformatted the script a bit to make it easier to understand):

                 

                this.getField("Capacity").value = "";
                if (this.getField("Media").value == "Liquid" &&
                  this.getField("Orifice").value == "D" &&
                  (this.getField("Series").value == "740" || this.getField("Series").value == "741")) 
                {
                  this.getField("Capacity").value = ((this.getField("Area")).value * 4.814) * .791 * Math.sqrt(62.37 * (this.getField("PSI")).value * 1.1)
                };
                
                • 5. Re: Multiple Line if statements
                  lambo99 Level 1

                  That worked, thank you very much.  I have one other question if you dont mind.

                  under the "Media" there are multiple options as well.  it can be air/gas, liquid, or steam.  depending on that a different formula is used.  for example

                  this.getField("Capacity").value = ""; 

                  if (this.getField("Media").value == "Liquid" && 

                    this.getField("Orifice").value == "D" && 

                    (this.getField("Series").value == "740" || this.getField("Series").value == "741"|| this.getField("Series").value == "742"|| this.getField("Series").value == "743"  ))  

                    this.getField("Capacity").value = ((this.getField("Area")).value * 4.814) * .791 * Math.sqrt(62.37 * (this.getField("PSI")).value * 1.1) 

                  };  

                   

                   

                  this.getField("Capacity").value = ""; 

                  if (this.getField("Media").value == "Air/Gas" && 

                    this.getField("Orifice").value == "D" && 

                    (this.getField("Series").value == "740" || this.getField("Series").value == "741"|| this.getField("Series").value == "742"|| this.getField("Series").value == "743"  ))  

                   

                  {

                  this.getField("Capacity").value = ((this.getField("Area")).value *18.331)*((this.getField("PSI").value*1.1 + 14.7)*.878)};

                  • 6. Re: Multiple Line if statements
                    Karl Heinz Kremer Adobe Community Professional

                    You may want to learn more about JavaScript and how it's conditional statements work. If you need a head start, take a look here: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC

                     

                    Without knowing more about how many different cases there are, and how similar (or different) they are, it's hard to give you generic advice.

                     

                    In general, an if/else/else if statement could work:

                     

                    if (this.getField("Media").value == "Liquid" &&
                      this.getField("Orifice").value == "D" &&
                      (this.getField("Series").value == "740" || this.getField("Series").value == "741" || this.getField("Series").value == "742" || this.getField("Series").value == "743")) {
                      this.getField("Capacity").value = ((this.getField("Area")).value * 4.814) * .791 * Math.sqrt(62.37 * (this.getField("PSI")).value * 1.1)
                    }
                    else if (this.getField("Media").value == "Air/Gas" &&
                      this.getField("Orifice").value == "D" &&
                      (this.getField("Series").value == "740" || this.getField("Series").value == "741" || this.getField("Series").value == "742" || this.getField("Series").value == "743"))
                    {
                      this.getField("Capacity").value = ((this.getField("Area")).value * 18.331) * ((this.getField("PSI").value * 1.1 + 14.7) * .878)
                    }
                    else if (something else) {
                    }
                    else {
                      // this is the case when none of the other statements were OK
                    }
                    
                    • 7. Re: Multiple Line if statements
                      lambo99 Level 1

                      That worked perfectly, Thank you so much for you help.  As you can tell I am very new to this.  I will check out that site.

                       

                      Thanks again