News:

  • June 11, 2026, 11:22:07 PM

Login with username, password and session length

Author Topic: IF Statement  (Read 9372 times)

PLCGuy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 677
IF Statement
« on: August 29, 2016, 06:36:46 AM »
Can someone help me write an IF Statement, or something that would work for what I am trying to do in the DO-More?

If V0, V1, and V2 are equal to "0" then output a bit to show this. I do not to run a device if there are no values in those locations.

I was looking at the example but I do not understand the example, IF(C7,D0,D1) means.

Or if there is a better way, that would be great too.

PLCGuy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 677
Re: IF Statement
« Reply #1 on: August 29, 2016, 07:34:21 AM »
I think I got it.
If(V0,0 + V1,0 + V2,0) result c300

I had to click on the IF column and there it was. Nice examples. I was only looking at the last column where it says examples

Is there a better way to write it?

PLCGuy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 677
Re: IF Statement
« Reply #2 on: August 29, 2016, 07:49:59 AM »
whoops, that is incorrrect.
I need if v0 or v1 or v2 equals zero, result bit C?

Not in example

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: IF Statement
« Reply #3 on: August 29, 2016, 08:24:31 AM »
You could do it in ladder logic or in MATH.  Here's the MATH expression

MATH C300 "IF(((V0 == 0) || (V1 == 0) || (V2 == 0)), 1, 0)"

or simpler (no IF needed)
MATH C300 "(V0 == 0) || (V1 == 0) || (V2 == 0)"

or in LADDER
Code: [Select]
V0   0                       C300
-] = [-+-------------------( OUT )
       |
V1   0 |
-] = [-+
       |
V2   0 |
-] = [-+


franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: IF Statement
« Reply #4 on: August 29, 2016, 08:26:40 AM »
If you need all 3 to be zero to have C300 be ON, change the logical-OR operators || to logical-AND operators &&

In ladder logic, place the equal-to contacts in series instead of parallel.

PLCGuy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 677
Re: IF Statement
« Reply #5 on: August 29, 2016, 09:09:37 AM »
Thank you franji 1. I just like to do it in the math box. Just to be cool.

Maybe you could add that example to the help!