One of the more unique Structured Text instructions is the CASE instruction. How does it work? What is it good for? What is the syntax? How do you use it? Why would you use it? We’ll answer these questions all while providing a number of real-world examples. If you are an IEC user, or even if you are just thinking about switching to IEC – you won’t want to miss this session.




0:21

Hi everyone, good morning and thank you for joining us today.

0:25

Today we are going to talk about using the case instruction in IEC structured Text and the presentation will last only five minutes.

0:35

As always if you have any questions please add in the question panel and we will go through them at the end of the presentation. That said, let’s get started. Hello and welcome to today’s webinar.

0:48

Today we will look at using the case instruction in IEC structure text.

0:54

Let’s look at our agenda for today.

0:57

We are going to start by answering the question, what is the case statement?

1:02

How it is used?

1:04

And then we will give you an application example and there will be demonstrations throughout and we will finish with a Q &A session.

1:11

What is the case statement?

1:13

It is a structured text statement which executes a block of statements based on a selector value.

1:20

Now if all you need to do is execute statements based on one or another value, the if then else is probably the way to go.

1:27

It is a statement we are all familiar with and we use very regularly.

1:32

And for handling a couple different statements, however if your decision tree is a little more complicated than that, if there are more cases, then the case statement is something you should evaluate.

1:42

that is what we’re going to do today. Let’s look at how the case statement is used.

1:48

In other words, we are going to look at the syntax so at the top line there you can see case and then a selector variable followed by of now that selector variable if it is a variable it has to be a double integer but it can also be a double integer expression so keep that in mind as well and then in the lines followed by a colon.

2:13

If it is just a single selected value you know the value of that double integer then you just put that number followed by the colon and then to the right there you can see the list of statements that will be executed for that case.

2:27

Now it also supports a list of values separated by a comma and then a colon after the last value.

2:34

It also supports a range of values where you have got the first value in the range and the final value in the range.

2:41

In between of those you have got a couple of periods and then you can also combine the list and the range for another case.

2:48

If none of those values are met in the list at the top there then you have got your else condition which takes care of everything else. It ends there with an underscore case and do not forget your semicolons.

3:01

Those are always important.

3:03

Now an important note if you are using the range of values you have got those two periods between your first and last value.

3:11

Make sure you have space before and a space after those periods for the proper syntax.

3:17

For our demonstration we are going to start by being in Cscape 10 but if you have been using an earlier version of Cscape everything we are showing you here is going to apply to that as well.

3:29

Here we have our case statement starting at the top here and our selector value is from a variable called product and it is a double integer value and then down here we have a series of different cases and when each of these cases are true we are going to execute these statements.

3:47

The list that is also shown here.

3:50

Now all these happen to be just simple assignment statements but they can be much more complex than that. This is just a simple example.

3:58

Now here have got a single value option here at the top.

4:02

We have a list of values here and here we have a combination of a range of values between 2 and 7 as well as a list of values including 15 and 16. We are going to go ahead and go into debug mode and then check out the bench.

4:18

So here is our example screen and our product number, it is just selected as 0 right now.

4:24

So let’s go ahead and change that to number one and if our product has a number of one that means we should be blue with that mix. Let’s head back to seascape and check that out.

4:35

The product variable has a value of one which means that the first case is being executed here and that is giving us the values that we see on the screen.

4:45

Let’s change to a different product value this time.

4:48

Let’s say six and you may possibly notice that we are using the spinner option on the Stata field in this particular case and that is an option that is available with Seascape 10 and Canvas.

5:00

So when we select product number 6 that gives us a green color with its mix of pigments and if we head back to Seascape we can see that the product of 6 falls within the range of 27 so that is why we end up with our color of green. Let’s do one more example.

5:17

Let’s change to a colour of 14.

5:19

So let us go up here and select colour number 14 and that means amber.

5:24

And if we go back and look at our logic here we can see a value of 14 falls within this case which gives us our colour of 4 and the mixed pigments of amber.

5:35

That concludes our webinar for today. Thank you so much for listening and the Q &A session will begin shortly.

5:56

Let me see if we have any questions.

6:01

Okay, since we don’t have any questions so far, let me jump into the agenda.

6:15

I hope you can see it now.

6:17

So the next webinar is going to be on connecting AC inputs to Horner OCS and if you want to participate, please register on our website.

6:33

I believe that’s all for today.

6:35

Thank you all for your time and I hope to see you in the next webinar.

6:39

Have a nice day, everyone.

6:56Thank you.