cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Using IF statement to change the value of a property

JamesP
1-Newbie

Using IF statement to change the value of a property

I am trying to change the value of a property depending on the value of another property. I have used the code below within a subscription. 

 

if(me.Amplitude = 1) {
me.Condition = "Normal Operation"
}

else if(me.Amplitude = 2) {
me.Condition = "Bearing Fault"
}
else {
me.Condition="Error"
}

 

When I test the code my Condition property changes to 'Normal Operation' but remains on 'Normal Operation' regardless of the value I assign to Amplitude. 

 

Hope you can help.

 

Thanks, James

1 ACCEPTED SOLUTION

Accepted Solutions

The single equals sign = is an assignment operation which evaluates to True. The double equals == is an equality test.

 

One technique to avoid getting burned by this type of error is to put the constant on the left:

if( 1 = me.Amplitude ) {...

That would have thrown an error until you fixed it with the double equals sign

View solution in original post

1 REPLY 1

The single equals sign = is an assignment operation which evaluates to True. The double equals == is an equality test.

 

One technique to avoid getting burned by this type of error is to put the constant on the left:

if( 1 = me.Amplitude ) {...

That would have thrown an error until you fixed it with the double equals sign

Top Tags