Variable values into a string

rgumara
2010-02-05
2010-02-08
  • rgumara - 2010-02-05

    Hi!

    I have to set the content of several numeric variables (basically INT) into a text file as I want to do a kind of backup of the data get from the PLC inputs.

    I need to build a long string by transforming the data of all the Integers (in oder to make this text file easily analysable) and enter this string as an input of the function "SysFileWrite" of the library SysLibFile.lib.

    Is there any command or function (INT_TO_STRING() ) which allow me to do this conversion, equivalent to these C examples: (char)int_variable or printf("%d", int_variable)?

    Thanks to all!

     
  • unknown - 2010-02-08

    rgumara hat geschrieben:
    I need to build a long string by transforming the data of all the Integers (in oder to make this text file easily analysable) and enter this string as an input of the function "SysFileWrite" of the library SysLibFile.lib.

    See example:

    PROGRAM PLC_PRG
    VAR
       iVar: ARRAY [0..10] OF INT := 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
       strString: STRING;
       i: INT;
    END_VAR
    IF i <> 11 THEN
       strString := CONCAT(strString, INT_TO_STRING(iVar[i]));      (*insert a variable into the line*)
       strString := CONCAT(strString, ' ');                         (*insert space between variables*)
       i := i + 1;
    END_IF;
    

    You may not use an array of variables. In this way your program will be a little bit bigger:

    PROGRAM PLC_PRG
    VAR
       iVar1, iVar2, iVar3: INT;
       strString: STRING;
       i: INT;
    END_VAR
    IF i <> 4 THEN
       strString := CONCAT(strString, INT_TO_STRING(iVar1));
       strString := CONCAT(strString, ' ');
       strString := CONCAT(strString, INT_TO_STRING(iVar2));
       strString := CONCAT(strString, ' ');
       strString := CONCAT(strString, INT_TO_STRING(iVar3));
       i := i + 1;
    END_IF;
    
     
  • shooter - 2010-02-08

    use INT_TO_STRING and to make it a nice line begin with a "and use "," in between and end with a "and a CRLF (13).

    please also add the time so you know when it happens.

     

Log in to post a comment.