Options

Writing a ASCII-File

KromozoneKromozone Member Posts: 47
Hi Board,

I want to write an ASCII-File with some Parameters, separated by ";".
Is there a way to write this File by the piece and not as one big string?

If I write my Parameters with "file.write", Navision everytime writes an CRLF after it, but I want it as one long text without any Linefeeds :cry:

How can I prevent this?

Thank you
Rainy greetings from South-Germany!

Andy

Comments

  • Options
    Tommy_SchouTommy_Schou Member Posts: 117
    Kromozone wrote:
    Hi Board,

    I want to write an ASCII-File with some Parameters, separated by ";".
    Is there a way to write this File by the piece and not as one big string?

    If I write my Parameters with "file.write", Navision everytime writes an CRLF after it, but I want it as one long text without any Linefeeds :cry:

    How can I prevent this?

    Thank you
    Rainy greetings from South-Germany!

    Andy

    I haven't really tested this. But there are a few ways to do it I should think. If you set textmode to false you will not get the CRLF appended. Another way would be to seek - -2 on the file everytime you have made a file.write.
    Best regards
    Tommy
  • Options
    KromozoneKromozone Member Posts: 47
    If you set textmode to false you will not get the CRLF appended.

    But if Textmode is false, Navision writes an binary file, not an ASCII I thought.
    Another way would be to seek - -2 on the file everytime you have made a file.write.

    Can you explain how to? :oops:
  • Options
    Tommy_SchouTommy_Schou Member Posts: 117
    TestFile.CREATE('c:\tmp\test2.txt');
    TestFile.OPEN('c:\tmp\test2.txt');
    TestFile.TEXTMODE(TRUE);
    TestFile.WRITE('This is a test');
    TestFile.SEEK(TestFile.POS-2); // Go back 2 positions in the file thus overwriting CRLF
    TestFile.WRITE('Line 2. CRLF should not exist');
    TestFile.CLOSE;
    

    The above should create a file with 2 lines in it.. where there is no CRLF between the lines.

    There is however a CRLF at the very end... I tried getting rid of it by writing
    TestFile.SEEK(TestFile.POS-2); // Go back 2 positions in the file thus overwriting CRLF
    TestFile.TRUNC
    

    before TestFile.Close. But though it should work. It apparently doesn't. Maybe you will have better luck! :)
    Best regards
    Tommy
  • Options
    KromozoneKromozone Member Posts: 47
    Thank you :) Will test it afterward...

    Andy
  • Options
    fbfb Member Posts: 246
    This problem is often solved by writing the file one Char at a time...

    (CrLf is defined as Text with a length of 2...)
    ...
    
      TestFile.TEXTMODE(FALSE);
      TestFile.CREATE('c:\tmp\TestFile.txt');
      CrLf[1] := 13;
      CrLf[2] := 10;
    
      WriteString(Param1 + ';');  // first parameter...
      WriteString(Param2 + ';');  // second parameter...
      WriteString(Param3 + CrLf); // last parameter, add linefeed...
    
      TestFile.CLOSE;
      ...
    
    PROCEDURE WriteString(NewString : Text[250])
    VAR
      i : Integer;
    BEGIN
      FOR i := 1 TO STRLEN(NewString)
        TestFile.WRITE(NewString[i]);
    END;
    
Sign In or Register to comment.