CSV Utility write file problems

dagi89
2023-02-27
2023-03-07
  • dagi89 - 2023-02-27

    Dear all,

    I am using csv utility yo write a file

    the functions that I use are:

    init:
    VAR
    csvWriterTemp_2Init : CSV.Init;
    AddProductFamily : CSV.AddSTRING;
    CSVFileWrite : CSV.WriteFile;

    END_VAR

    1st csvWriterTemp_2Init(xExecute :=FALSE,sFileName:=_StringWipWrite,sDirectoryPath:=_szDir_OrdersInProduction,sRowSeparator:='$N',sColumnSeparator:=',',rCSVWriter:=CSVWriter);

    2nd csvWriterTemp_2Init(xExecute :=TRUE,sFileName:=_StringWipWrite,sDirectoryPath:=_szDir_OrdersInProduction,sRowSeparator:='$N',sColumnSeparator:=',',rCSVWriter:=CSVWriter);

    3rd AddProductFamily(xExecute:= TRUE,xAbort:=FALSE, sInput:=_0ProductFamily,rCSVWriter:=CSVWriter);
    4th AddProductFamily(xExecute:= FALSE,xAbort:=FALSE, sInput:=_0ProductFamily,rCSVWriter:=CSVWriter);

    Others Add functions to add additionals elements

    5th CSVFileWrite(xExecute:=TRUE,xAbort:=FALSE,rCSVWriter:=CSVWriter);
    6th CSVFileWrite(xExecute:=FALSE,xAbort:=FALSE,rCSVWriter:=CSVWriter);

    7th csvReaderTemp_0Init(xExecute :=FALSE,szFileName:=_StringWipWrite,sLineSeparator:='$N',sColumnSeparator:=',',xCloseFile:=TRUE);
    8th csvReaderTemp_0Init(xExecute :=TRUE,szFileName:=_StringWipWrite,sLineSeparator:='$N',sColumnSeparator:=',',xCloseFile:=TRUE);

    the problem is:
    - at the first execution the file is well created as expected.
    text into file:(P01,M00001,PENNA 01,KitB.csv,RICETTA PERNNA 10,D,DT#2023-02-24-18:51:23,DT#2023-02-24-18:51:43,OK,NO ERROR
    P01,M00002,PENNA 01,KitB.csv,RICETTA PERNNA 10,D,DT#2023-02-24-18:51:23,DT#2023-02-24-18:51:43,OK,NO ERROR
    P01,M00003,PENNA 01,KitB.csv,RICETTA PERNNA 10,D,DT#2023-02-24-18:51:23,DT#2023-02-24-18:51:43,OK,NO ERROR)
    - after that the file is renamed
    - at the second execution the file is written wrong and the system at the beginning of the file writes ','.
    text into file:(,P01,M00001,PENNA 01,KitB.csv,RICETTA PERNNA 10,D,DT#2023-02-24-18:51:23,DT#2023-02-24-18:51:43,OK,NO ERROR
    P01,M00002,PENNA 01,KitB.csv,RICETTA PERNNA

    I do not know how to overcome this problem.

    is there any solution or suggestion that can help me to find a solution?

     
  • snhatton - 2023-03-01

    Good morning @Dagi89,

    I've attached an example for your consideration. The attached example saves a formatted csv file every 5 seconds and is based on the CSV Utility example located in: C:\Users\<user name="">\CSV Utility SL\1.0.2.0. </user>

    The csv file is limited by number of lines that can be written and file size. The program Sequential_Add_Values is where the CSV fields are defined. The program Sequential_Save will save the csv, or create a new csv if the file size is exceeded. I hope this helps!

    Regards,

    Shawn

     
    πŸ‘
    1
  • dagi89 - 2023-03-07

    THANKS.. fixed.

    i had to use the function New File of CSV Utility Package.

    Regards,

    Dagi89

     
  • snhatton - 2023-03-07

    Wonderful! Glad you got it working!

     

Log in to post a comment.