SCL Siemens array question

vib

Member
Join Date
May 2022
Location
spain
Posts
7
Hello,
When you want compare values of an array to a range of numbers is it a right way to do that?

Code:
FUNCTION ADD
  VAR_IN_OUT
     A:ARRAY[1..50] OF INT;
  END_VAR
  VAR_TEMP
    I:INT;
  END_VAR
  BEGIN
    I:=0;
  WHILE I<50  DO
    IF(A[I]:=1, 3, 7, 9, 12, 15, 20, 21, 14, 17, 30, 33, 36, 39, 42, 49 )THEN
       A[I]:=A[I]+12.5;
    END_IF
   I:=I+1
   END_WHILE
   ADD:=A[I];
END_FUNCTION

Or I have to check 1 per 1 value? I wanna know if you can check it like that
 
Oh dear .... anyway..

I dont have my programming pc at hand, but I think you can do it like this:
Code:
FOR i:=1 TO 50 
  CASE A[i] OF
    1,3,7,9,12,14,15,17,20,21,33,36,39,42,49: // match found
  ELSE
    // match not found 
  END_CASE ;
END_FOR ;
 
Oh dear .... anyway..

I dont have my programming pc at hand, but I think you can do it like this:
Code:
FOR i:=1 TO 50 
  CASE A[i] OF
    1,3,7,9,12,14,15,17,20,21,33,36,39,42,49: // match found
  ELSE
    // match not found 
  END_CASE ;
END_FOR ;

Oh can you use CASE like that? using ELSE inside?
 
Oh can you use CASE like that? using ELSE inside?

Sure, you can omit the ELSE part, but using it results in cleaner (more readable) code.

To make sure that you understood, it works so, that if any of the cases was not there then the else part is executed.
 

Similar Topics

Hi All, I am currently writing a new function in SCL, And I have a array at 300 bytes (tmpArray[0..299] OF Bytes) to this function. Questions...
Replies
3
Views
3,427
Hi All, I need to try and convert some code from Siemens SCL (TIA16) over to Allen Bradley RS5000. I have attached an image of the SCL and what...
Replies
10
Views
4,047
in the scl code written in screenshot Line 1 condition is false but still the program checking the line 2 condition and says it is true i had...
Replies
3
Views
1,750
I am new to PLC programming. Is there a standard way to incorporate alarms / warnings / events such as the exceptions in C++ or Java where you can...
Replies
5
Views
1,955
Hello All, I am new to programming with Tia Portal and I am having difficulty with something that we have found "easy" in other programming...
Replies
3
Views
2,368
Back
Top Bottom