Case Function - Multiple Conditions, Is it possible?

pistola
2024-11-03
2024-11-05
  • pistola - 2024-11-03

    Looking at the help (https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_st_instruction_case.html).

    I don't think it is possible but I figured I'd ask.

    I'm looking at have a case that evaluates two variables, instead of having multiple If Else statements I was hoping I could just use a case.

    Example

    *
    

    Case Var1 & Var 2 of
    10 & 10:
    Instruction Code
    10 & 20:
    Instruction Code
    20 & 20:
    Instruction Code
    End_Case

    Obviously I tried typing as noted above and Codesys threw an error. But I was wondering if there was a different way of programming to make something like this work?

    If not I'll just use a bunch of If Else Statements, Thanks.

     
  • TimvH

    TimvH - 2024-11-05

    This is not possible.
    Possible solution could be:
    CASE var1 OF
    10:
    CASE var2 OF
    10:;
    20:;
    END_CASE
    20:
    CASE var2 OF
    10:;
    20:;
    END_CASE
    ELSE
    ;
    END_CASE

     
  • pistola - 2024-11-05

    Thanks for the information, I ended up just making a long if else statement as each variable had 3 possible options, I figured at least this way it would still work.

     

Log in to post a comment.