Apex OR programming

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
985
Reaction score
1,325
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
 
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:
 
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. :)
 

IF YOU HAD TO TAKE A REEFING EXAM, WOULD YOU PASS?

  • Yes!

    Votes: 32 45.7%
  • Not yet, but I have one that I want to buy in mind!

    Votes: 9 12.9%
  • No.

    Votes: 26 37.1%
  • Other (please explain).

    Votes: 3 4.3%

New Posts

Back
Top