Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

string write to txt file

sarunas
2023-08-01
2023-08-09
  • sarunas - 2023-08-01

    Hello, I have variable code:

    FOR n:=1 TO 255 DO
    CONCAT2(pSrcString1:=ADR(GlobalPersistent.ReadAllEvents[n].sDate),pSrcString2:=ADR(GlobalPersistent.ReadAllEvents[n].STime),pDstString:=ADR(GVariable.WriteToFileString[n]),nDstSize:=255);
    formatStrg:='%s,%s,%s,%s';
    FBFormatString(sFormat:=FormatStrg, arg1:=FSTRING(GlobalPersistent.ReadAllEvents[n].sDate),
    arg2:=FSTRING(GlobalPersistent.ReadAllEvents[n].STime),
    arg3:=FSTRING(GlobalPersistent.ReadAllEvents[n].sSource),
    arg4:=FSTRING(GlobalPersistent.ReadAllEvents[n].sMessageText),
    sOut=>GVariable.WriteToFileString[n]);
    ENDFOR
    I string write to array, when this Array I write to txt file
    fbFileWrite( bExecute := FALSE );
    fbFileWrite( sNetId:=sDestNetId, hFile:=hDestFile,
    pWriteBuff:= ADR(GVariable.WriteToFileString), cbWriteLen:= SIZEOF(GVariable.WriteToFileString),
    bExecute:=TRUE, tTimeout:=tTimeOut );

    I open create file and see this. I attached picture

     
  • TimvH

    TimvH - 2023-08-09

    Maybe you should not use SIZEOF, but LEN. Because SIZEOF means you will get the memory size of your string variable (e.g. maximum 80 characters), but LEN will give the actual length of the string.

     
  • alrcastro

    alrcastro - 2023-08-09

    In addition to the above tip, your program is overlooking error codes for formatting and file access functions; it is always good practice to read these parameters.

     

Log in to post a comment.