New Line in a Text File

HanenHanen Member Posts: 281
Hello,



How can I write a new line in a textfile knowing that I'm using a dataport to create textfile. I tried this code but id didn't work
:cry:
Dataport - OnPostDataport()
CurrFile.TEXTMODE(TRUE);
Regards

Hanen TALBI

Comments

  • krikikriki Member, Moderator Posts: 9,110
    Try this:
    Dataport - OnPostDataport()
    CurrFile.TEXTMODE(FALSE);
    
    txtCRLF := 'XX';  // define it as Text with size 2
    txtCRLF[1] := 13;
    txtCRLF[2] := 10;
    CurrFile.WRITE(txtCRLF);
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • HanenHanen Member Posts: 281
    It works but it's a new line with an additional blank #-o I only need a new line (cursor at first position without blanks)... :-k

    THANKS FOR HELP
    Regards

    Hanen TALBI
  • krikikriki Member, Moderator Posts: 9,110
    My fault, it should have been the COPYSTR and not the text with size 2 (it may be of any length).
    Dataport - OnPostDataport()
    CurrFile.TEXTMODE(FALSE);
    
    txtCRLF := 'XX';  // define it as Text with size 2
    txtCRLF[1] := 13;
    txtCRLF[2] := 10;
    CurrFile.WRITE(COPYSTR(txtCRLF,1,2));
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • HanenHanen Member Posts: 281
    No, it's the same problem :oops:
    Regards

    Hanen TALBI
  • Big_DBig_D Member Posts: 207
    Hi Hanen

    I have had similar issues with created BACS files, a trick I used was to trim the file by two characters at the end - presuming that these final two characters are CR + LF...

    Length := BACSFile.POS;
    //Length of Type Integer
    //BACSFile of Type File
    BACSFile.CLOSE;
    //Need to close and reopen the said file first.
    BACSFile.OPEN(Filename);
    // Filename used previously to open the file.
    BACSFile.SEEK (gLength - 2);
    BACSFile.TRUNC;
    BACSFile.CLOSE;

    Hope this helps :D
    Big D signing off!
  • krikikriki Member, Moderator Posts: 9,110
    Before trying Big D's trick, you can try this:
    Dataport - OnPostDataport()
    CurrFile.TEXTMODE(FALSE);
    
    txtCRLF := 'XX';  // define it as Text with size 2
    txtCRLF[1] := 13;
    txtCRLF[2] := 10;
    CurrFile.WRITE(COPYSTR(txtCRLF,1,2));
    CurrFile.SEEK(CurrFile.POS - 1); // if it doesn't work try with  "- 2"
    CurrFile.TRUNC; // try first without this command
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • -matrix--matrix- Member Posts: 103
    You Can Try to Create Integer DataItem In the Dataport with CONST(1) Then:
    > Insert the DataportFields with variables
    > In OnBeforeExport Trigger Insert Code for populate the variable
  • vaprogvaprog Member Posts: 1,139
    kriki wrote:
    Try this:
    Dataport - OnPostDataport()
    CurrFile.TEXTMODE(FALSE);
    
    txtCRLF := 'XX';  // define it as Text with size 2
    txtCRLF[1] := 13;
    txtCRLF[2] := 10;
    CurrFile.WRITE(txtCRLF);
    
    kriki's first attempt was almost right. It accurately defines the newline string. His later addition of COPYSTR was not necessary (though not wrong; it produced the same result as the first attempt).
    The problem with both these attempts is, though, that it is written in binary (non-text mode) in which a string is written with a trailing NUL character. The character on the last line in your screenshot is not a blank, but this NUL character (hex 00).

    So, what you should do is
    Dataport - OnPostDataport()
    CurrFile.TEXTMODE(TRUE);
    CurrFile.WRITE('');
    

    Big D's suggestion, on it's own, will not do you any good. kriki's latest suggestion, not regarding the comments, would probably correct the wrongly written byte, but why write it in the first place?
Sign In or Register to comment.