Skip to main content
lambo99
Participating Frequently
March 27, 2017
Answered

Multiple Line if statements

  • March 27, 2017
  • 1 reply
  • 983 views

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

;

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

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)

};

1 reply

Karl Heinz  Kremer
Community Expert
Community Expert
March 27, 2017

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?

lambo99
lambo99Author
Participating Frequently
March 27, 2017

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.

Karl Heinz  Kremer
Community Expert
Karl Heinz KremerCommunity ExpertCorrect answer
Community Expert
March 27, 2017

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)

};