S7-300 Array of strings and SCL

JOLTRON

Lifetime Supporting Member
Join Date
Aug 2006
Location
MI
Posts
692
Looking for some help with an array of strings in SCL.

I have an array of 99 string[98]
I also have an array of 99 INT

My first 4 chars of the strings are a character representation of an INT value e.g. 0001

I want to convert these to INTs.

My issues is when I try to compile I get an 'Illegal parameter assignment' when I try using the 'LEFT' function.

I am calling it as described in my Hans Berger book but it just isn't happy.

Any ideas?

Code:
(*##############################################################################
Inputs 
##############################################################################*)
VAR_INPUT
    Count:INT;
END_VAR


(*##############################################################################
Outputs
##############################################################################*)
VAR_OUTPUT
     TaskId:ARRAY[0..99] OF INT;
END_VAR


(*##############################################################################
Inouts
##############################################################################*)
VAR_IN_OUT
     TaskList:ARRAY[0..99] OF STRING[98];
END_VAR

(*##############################################################################
Variables
##############################################################################*)
VAR
    
    i : INT ;             // iterator
    tmpStr  : STRING;

END_VAR




BEGIN


    FOR i := 0 TO Count DO    
            
       tmpStr := LEFT (IN:=TaskList[i],L:=4);  //  HERE IS THE PROBLEM  
       TaskId[i]:= STRNG_I(S := tmpStr);
              
    END_FOR;  
     
     strLeftToINT:=0;

END_FUNCTION
 
Cannot pass FC IN_OUT of type string to another FC, use a temp string instead.

Code:
VAR
    
    i : INT ;             // iterator
    tmpStr  : STRING;
    tmpStr1 :STRING;
END_VAR
BEGIN


    FOR i := 0 TO Count DO    
       tmpstr1:=TaskList[i];     
       tmpStr := LEFT (IN:=tmpstr1,L:=4);  //  HERE IS THE PROBLEM  
       TaskId[i]:= STRNG_I(S := tmpStr);
              
    END_FOR;
 
Your array definition specifies 100 entries, not 99 as you posted, and your for loop contruction means that you will process count+1 strings - is this what you meant to happen?
 
Damnit! I always forget about the temp string when passing to another FC :(

Thanks I will look at the shortly.

My arrays is defined as 100. But in the actual process I am only using 99. I use 100 so I get a nice easy number to deal with. That is also why I defined my strings as 98 (using 100 bytes when the 2 byte header is included).

I didn't catch my count number issue in the For loop. I will have to address that as well.

Thanks as always for the help LD!
 
It compiles for me now and it executes but I don't seem to be getting any results.

My goal is to pass in an array of strings and get an array of INTs back from it based on the first 4 characters of the string.

Seems simple enough but I am still struggling. Definitely do not feel at home in SCL.

I have tried making both arrays INOUTs so I have full read / write access to each of them

I have tried directly writing to an external DB and monitoring it in a VAT table but I am not seeing any changes.

From inside SCL am I allowed to access DB's symbolically? e.g. strings.string1 := 'test';

I'm going to read through my SCL / STL book some more but any help would be appreciated.

Code:
(*##############################################################################
Inputs 
##############################################################################*)
VAR_INPUT
    Count:INT;
END_VAR


(*##############################################################################
Outputs
##############################################################################*)
VAR_OUTPUT
     
END_VAR


(*##############################################################################
Inouts
##############################################################################*)
VAR_IN_OUT
     TaskList:ARRAY[0..99] OF STRING[98];
     TaskId:ARRAY[0..99] OF INT;

END_VAR

(*##############################################################################
Variables
##############################################################################*)
VAR
    
    i : INT ;             // iterator
    tmpStrFull  : STRING;
    tmpStrFourChar :STRING;

END_VAR




BEGIN


    FOR i := 0 TO Count - 1 DO    
            
       strings.int1 := i;
            
       tmpStrFull := TaskList[i];
       strings.str2 := tmpStrFull;
       
       tmpStrFourChar := LEFT (IN:=tmpStrFull,L:=4);    
       strings.str1 := tmpStrFourChar;
       
       TaskId[i]:= STRNG_I(S := tmpStrFourChar);
       strings.int1 := TaskId[i];

    END_FOR;  
     
     strLeftToINT:=0;

END_FUNCTION
 
Kabang....

Code:
    FOR i := 0 TO Count - 1 DO    
                 
       tmpStrFull := TaskList[i];

       [COLOR=Red]tmpstrFourchar:='a'; //must initialise a temp string before being used as value from a library string block[/COLOR]
       tmpStrFourChar := LEFT (IN:=tmpStrFull,L:=4);    
       
       TaskId[i]:= STRNG_I(S := tmpStrFourChar);
   END_FOR;
 
Wow, I've never seen that either. Good catch! I assume this discussion was in reference to S7-300, is that true for the newer families as well?
 
Wow, I've never seen that either. Good catch! I assume this discussion was in reference to S7-300, is that true for the newer families as well?

Yes mk I was dealing with an S7-300 plc. I haven't worked with strings much on the 1200/1500 series but I will try to test it out when I have a minute.

Anyways here is the final code I ended up with.

Code:
(*##############################################################################
Inputs 
##############################################################################*)
VAR_INPUT
    
    TaskList:ARRAY[0..99] OF STRING[98];
    Count:INT;
    
END_VAR


(*##############################################################################
Outputs
##############################################################################*)
VAR_OUTPUT
     
     TaskId:ARRAY[0..99] OF INT;
     
END_VAR


(*##############################################################################
Inouts
##############################################################################*)
VAR_IN_OUT
    
END_VAR

(*##############################################################################
Variables
##############################################################################*)
VAR
    
    i : INT ; // iterator
    tmpStrFull  : STRING;
    tmpStrFourChar :STRING;

END_VAR



(*##############################################################################
Begin logic
##############################################################################*)
BEGIN
    
    FOR i := 0 TO Count - 1 DO    
           
       //Initialise strings or the will not work in SCL     
       tmpStrFull := '';
       tmpStrFourChar := '';

       //Set tmpStrFull to full string of task            
       tmpStrFull := TaskList[i];
       
       //Set tmpStrFourChar to the first four characters which contains the unique ID
       //in character format
       tmpStrFourChar := LEFT (IN:=tmpStrFull,L:=4);    
       
       //conver the four character string to an INT
       TaskId[i]:= STRNG_I(S := tmpStrFourChar);


    END_FOR;  
     
     //RetVal currently not used so set it to zero
     SetTaskIDs:=0;

END_FUNCTION
 

Similar Topics

Dear All , I have written a small program in SCL as below . ///////////////////////////////////////////////////////////// FUNCTION FC1:VOID...
Replies
6
Views
2,407
Hi, I am useless at STL and not fortunate enough to have SCL. I am trying to do the following; MW1 := 6 MW2 := 400 DB100.DBW[MW1] := MW2 So store...
Replies
3
Views
1,658
Hi Guys: See attached figure. This is my UDT. Is there any way to populate my array using excel and then copying it to my program, instead of...
Replies
8
Views
2,714
Hello, Using LAD, how can I generate an array of 50 numbers and then calculate an average of them? I don't know how to define an array as a...
Replies
29
Views
11,426
As a relative newcomer to the S7-300 its driving me crazy. Can anyone tell me how I simply address an array item in the form: Array[index] where...
Replies
4
Views
8,894
Back
Top Bottom