My code SCL don´t work

jara

Member
Join Date
Jul 2010
Location
Cordoba
Posts
100
Hello everybody!

I have made a FC with SCL, the problem is that don´t work. I have been testing the same code with VBScript and it´s work fine.
I don´t find where is the fault, if someone can help me to find it.
Thanks
Code:
FUNCTION FC200: VOID

VAR_INPUT
    Cod_Barras : STRING;
    Num_Cod : INT;
END_VAR
VAR_OUTPUT
    Cod_BarrasOK: STRING;
    Cod_BarrasNoK: BOOL;
    Message : STRING;
END_VAR
VAR_TEMP
    lenCod : INT;
    Barcod: STRING;
    index: INT;
    c:STRING[1];
END_VAR
BEGIN 
//Barcod:=''; lenCod:=0; index:=1;
c:='';
Barcod:=Cod_Barras;
lenCod:= LEN(S:=Barcod);
Cod_BarrasNoK :=0; 
Message:='';
    IF (lenCod <> Num_Cod) THEN
        Cod_BarrasNoK :=1;        
    ELSE        
         FOR index := 1 TO lenCod BY 1 DO
            c:= MID(IN := Barcod , L:= index, P:=1); // STRING    
                IF NOT EQ_STRNG(S1 := c ,S2 :='0' ) THEN //OR NE_STRNG(S1 := c ,S2 :='1' )// IF (c<>'0') OR (c<>'1') OR (c<>'2') OR (c<>'3') OR (c<>'4') OR (c<>'5') OR (c<>'6') OR (c<>'7') OR (c<>'8') OR (c<>'9') THEN
                    Message := 'The code isn´t valid';
                    Cod_BarrasNoK :=1;
                    EXIT;
                END_IF;          
         END_FOR;
        //Cod_BarrasNoK := 0;
    END_IF;

    IF Cod_BarrasNoK=0 THEN
        Cod_BarrasOK:=Barcod;
        Message:='';
    END_IF;
    
END_FUNCTION
 
Sorry, I don´t find how I can edit the thread.
I want to do, if there is some character 'a','b',.... in Barcod then the code is wrong, only is possible numbers.
I think that the problem is with the bucle for and the next sentence.
 
The L and P parameters for the MID function are the wrong way round.

Here's your function modified:

Code:
FUNCTION FC200: VOID

VAR_INPUT
    Cod_Barras : STRING;
    Num_Cod : INT;
END_VAR
VAR_OUTPUT
    Cod_BarrasOK: STRING;
    Cod_BarrasNoK: BOOL;
    Message : STRING;
END_VAR
VAR_TEMP
    lenCod : INT;
    Barcod: STRING;
    index: INT;
    c:STRING[1];
    cb AT c:ARRAY[1..3] OF CHAR;
    x,y:INT;
    byx AT x:ARRAY[1..2] OF CHAR;
    byy AT y:ARRAY[1..2] OF CHAR;
    charZero:INT;
    charNine:INT;
    byZ AT charZero:ARRAY[1..2] OF CHAR;
    byN AT charNine:ARRAY[1..2] OF CHAR;
END_VAR
BEGIN 
//Barcod:=''; lenCod:=0; index:=1;
c:='';
x:=0;
charZero:=0;
charNine:=0;
byz[2]:='0';
byN[2]:='9';
Barcod:=Cod_Barras;
lenCod:= LEN(S:=Barcod);
Cod_BarrasNoK :=0; 
Message:='';
    IF (lenCod <> Num_Cod) THEN
        Cod_BarrasNoK :=1;        
    ELSE        
         FOR index := 1 TO lenCod BY 1 DO
            c:= MID(IN := Barcod , L:=1 , P:=index); // STRING    
            byx[2]:=cb[3];           
                IF x < charZero OR x > charNine THEN 
                    Message := 'The code isn´t valid';
                    Cod_BarrasNoK :=1;
                    EXIT;
                END_IF;          
         END_FOR;
        //Cod_BarrasNoK := 0;
    END_IF;

    IF Cod_BarrasNoK=0 THEN
        Cod_BarrasOK:=Barcod;
        Message:='';
    END_IF;
    
END_FUNCTION
 
Last edited:

Similar Topics

Dear Experts, Need help understanding this SCL code . IF (#SimOn = 0) THEN IF (#DI_In <> #Mem) AND (#Mem1 = 0) THEN #RemTime := #Tf...
Replies
4
Views
1,566
Hi, I have something like this in S7 Classic in a FB200 that I wanna use in TIA Portal: #FIRST_BEAM:= PIB[#HW_ADDR]; HW_ADDR is a integer...
Replies
8
Views
3,329
Hi there, we have situation a compressor unit PLC faulted, the cause is unknown as it lost coms before it was taken offline by unknown reason...
Replies
3
Views
1,953
Hello, How can I generate SCL code of CFC library block in Step7
Replies
0
Views
1,638
Could anybody please tell me what algorithm use following S7-SCL code. I understand it is a value as input then making output. But i want to know...
Replies
4
Views
2,580
Back
Top Bottom