Hi,
I was unable to use FILL fonction the return string is always empty
in the source code there is the declaration sx and Sx in the code ia it a probleme ?
can anybody explain the code ?? please why 2 loop in this code ??
thanks
I post here the code which works for me with step 7 scl 5.3
FUNCTION FILL : STRING
TITLE = 'FILL'
//version 1.1 17. dec. 2008
//programmer hugo
//tested by
//
//the function fill creates a string at length L of characters C.
//
//uses: oscat/String/CHR_TO_STRING (FC227)
// oscat/Constants/CONSTANTS (DB6)
// S7/Standard Library/IEC Function Blocks/CONCAT (FC2)
//
VERSION : '1.1'
AUTHOR : hugo
NAME : FILL
FAMILY : STRINGS
VAR_INPUT
C : BYTE;
L : INT;
END_VAR
VAR
tFILL : STRING[254]; <--- 256 byte in L Stack !!!!!!!!!!!!!
tL : WORD;
_L AT tL : ARRAY[0..15] OF BOOL;
i: INT;
sx: STRING[1];
END_VAR
BEGIN
sx := CHR_TO_STRING(C);
tFILL:=''; <---- add this line
(* limit L to maximum 80 characters the length of a standard string *)
tL := INT_TO_WORD(LIMIT(MN:=0,IN:=L,MX:=Constants.STRING_LENGTH));
(* create a string of characters to be connected to str *)
FOR i := 1 TO 8 DO
tFILL := CONCAT(IN1:=tFILL,IN2:=tFILL);
IF _L[0] THEN tFILL := CONCAT(IN1:=tFILL,IN2:=sx); END_IF;
tL := SHL(IN:=tL,N:=1);
END_FOR;
FILL := tFILL;
(* revision histroy
hm 29. mar. 2008 rev 1.0
original release
hm 17. dec. 2008 rev 1.1
changed function chr to chr_to_string
*)
END_FUNCTION
this code work on but use more than 256 byte in L stack which is dangerous for most of CPU by default there is 256 byte in L stack
any idea for an other method ??