×

Subscribe to newsletter

subscribe to our weekly newsletter to get notified with latest story and article Subscribe now!




PLC BLOG | Structured Text CASE OF Statement
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


Structured Text CASE OF Statement

CASE_OF is a control flow statement that used for execute different statement of code based on the value of the selector or expression. CASE_OF is an alternative of multiple if-else-if statements. CASE_OF easy to understand. Basic syntax of CASE_OF statement is a selector or expression to be evaluated based on result label select. In Structured Text Language, CASE_OF is a variable selector or Selection statement that allows a program to choose among multiple alternatives based on the value of a variable. Use CASE_OF to select what to do based on a numerical value. CASE_OF selects one variable at single scan and execute statement. The CASE_OF statement is used to perform different actions based on different conditions. The CASE construct is similar to a switch statement in the C or C++ programming languages.


What is a CASE_OF statement in Structured Text

CASE_OF is control flow statement which match selector value with numeric_expression if numeric_expression and selector value matched than statement of select selector value is executed otherwise else statement executed. Following is representation of working Case_Of statement.

What is a CASE_OF statement in Structured Text

Syntax of CASE_OF Statement in Structured Text

Below is the Syntax of CASE_OF Statement in Structured Text
  • CASE numeric_expression OF
  •      selector1:
  •             statement;
  •      selector2:
  •             statement;
  • .....
  • .....
  •      selectorN:
  •             statement;
  •       ELSE
  •             statement;
  •       END_CASE;
  • numerical_Expression: is integer type based on numerical expression case statement select statement.
  • selector: select value match with numeric_expression. If the numeric_expression matches the specified selector value(any value) than statement of selector selected and executed.
  • if the numeric_expression not match with any selector value than else statement executed.


Example Of Case_Of statement

below is the first example of Case_Of statement in rslogix 5000, in this example we check which limit switch is operated so we use case statement and expression for this statement is a limit_switch when first limit switch is operated than limit_switch_1 set to 1 and other limit switch set to 0 simiilarly for all three limit switch. if no limit switch is operated so status for all limit switch is set to zero. this example demonstrated only for one value selection.

Example Of Case_Of statement

Example Of Case_Of statement for A range of values

in this example of Case_Of statement for A range of values we evaluated case of statement for rang of value. in structured text if you want to use range value so Use two periods (..) to identify the range. for example 1..4 so it so 1 to 4 value. In below example we evaluate temperature at different level. we set alarm at different level so when temperature in between 1 to 40 than low alarm set to 1 and all other alarm is set to 0. If the temp_lvl is 46,47 to 89 than warning alarm is set to 1 if temp_lvl in between 95 to 189 than error alarm is set to 1. If alarm is not in any range than else statement is executed. you make your own program if find any difficulty than comment below or you can send a mail.

Example Of Case_Of statement for A range of values

Example Of Case_Of statement for Real Values

Example Of Case_Of statement for Real Values

in this example we evaluate numeric_expression with a real values here we use a tank water level according to our process when water level of tank between 110 to 156 than first pump start, if tank water level between 156.01 to 190 than second pump and first pump start similarly at last all pump start when level reached between 190.01 to 210.00. in this example i not use else statement so please tell me what happened if i not use else statement in comment.


Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


Suggested Post


 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

comment