Simple question about case's

stu1980
2012-09-19
2012-09-22
  • stu1980 - 2012-09-19

    Hi, very simple question. if i have code in a case and no jump address. Will the code keep executing over and over again?

     
  • shooter - 2012-09-20

    When the CASE is done the program jumps to END_CASE

     
  • stu1980 - 2012-09-20

    Will this be the case with multiple cases? e.g.
    CASE Example OF
    1.case1();
    2.case2();
    3.case3();

    END_CASE;

    Say if case1 executes its code, will it automatically jump to the next or as you said jump to end case.

     
  • shooter - 2012-09-21

    If example is 1 case1 will be executed
    It will not even test if example is 2 but will move to the end_case instruction just because the example is not correct for any other.
    This is also not allowed so
    1:
    and 1..3: is not allowed.
    btw it must be a colon and not a comma.
    see example i gave you
    CASE INT1 OF
    1, 5: BOOL1 := TRUE;
    BOOL3 := FALSE;
    2: BOOL2 := FALSE;
    BOOL3 := TRUE;
    10..20: BOOL1 := TRUE;
    BOOL3:= TRUE;
    ELSE
    BOOL1 := NOT BOOL1;
    BOOL2 := BOOL1 OR BOOL2;
    END_CASE;

    if int1 is not 1,2,5,10,11,12,13,14,15,16,17,18,19,20 else will be done
    otherwise
    when it is 1 or 5 bool1 will be true
    when int1 is 2 bool2 will be false
    if int1 is from 10 to 20 bool3 will be true
    etc.

     
  • stu1980 - 2012-09-21

    Thanks Shooter

    One thing, how do you determin which case is used. How can you choose case 1. or 2. or 3. I presume if you declare your variable "example" as an interger you can feed values in that variable, then choose each case you want.

     
  • shooter - 2012-09-21

    yes that why example is declared in the VAR list
    VAR
    example:INT;
    END_VAR

    but this will be done automatic when you type in the program.

     
  • stu1980 - 2012-09-22

    Thanks

     

Log in to post a comment.