Apex OR programming

robsworld78

Valuable Member
View Badges
Joined
Feb 14, 2020
Messages
1,029
Reaction score
1,293
Location
Edmonton, Canada
Rating - 0%
0   0   0
Is an OR condition possible using Apex programming?

Example:

if Temp1 > 76 turn on outlet 7
OR
if Temp2 > 76 turn on outlet 7
 

SuncrestReef

That Apex guy
View Badges
Joined
Jan 18, 2018
Messages
4,214
Reaction score
8,688
Location
Oregon
Rating - 0%
0   0   0
Yes, you can do OR and AND logic with the Apex:

[Outlet7]
Set OFF
If Temp1 > 76.0 Then ON
If Temp2 > 76.0 Then ON

The Apex evaluates each line of code from top to bottom, and the last line that's True will set the state. In this example, if both temperature probes and below 76, the output will be Off due to the Set OFF line being the only True condition. But if Temp1 or Temp2 is above 76, then the output will turn On, resulting in an OR operation.

---

For AND conditions, you need to use a little reverse logic:

[Outlet7]
Set OFF
If Temp1 > 76.0 Then ON
If Temp2 < 76.1 Then OFF

In this example, the output is normally off. If Temp1 is above 76, it will try to turn on the output, but if Temp2 is below 76.1 (in other words not greater than 76.0) then the output remains off. Both temperature probes would need to agree it's above 76.0, resulting in an AND operation.

See my series of Apex tutorials for example code on a variety of topics:
 
OP
OP
robsworld78

robsworld78

Valuable Member
View Badges
Joined
Feb 14, 2020
Messages
1,029
Reaction score
1,293
Location
Edmonton, Canada
Rating - 0%
0   0   0
Thanks for details, was hoping you were going to say NO lol...

I'm making my own controller but having trouble getting OR logic to work, it's a lot more complicated then AND. Then I thought, lets see if Apex can do it, couldn't find anything about OR only AND so thought I would ask pros here, now I have to get it working. :)
 

TOP 10 Trending Threads

Back
Top