Writing newline to a text file

Cem_KaraerCem_Karaer Member Posts: 281
How can I write newline to a text file by using the WRITE function of a FILE variable? Or is there any other way to do it?
Cem Karaer @ Pargesoft
Dynamics NAV Developer since 2005

Comments

  • ara3nara3n Member Posts: 9,256
    A line ends with 10 and 13 characters.
    Create a txt variable

    MyEndLine[1] := 10;
    MyEndLine[2] := 13;

    in your code MyFile.write('your text'+MyEndLine);


    If you set the MyFile.TEXTMODE(true);

    Navision will add this so you don't have to.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Cem_KaraerCem_Karaer Member Posts: 281
    MyEndLine[1] := 10;
    MyEndLine[2] := 13;
    If MyEndLine is a text array, it is impossible to assign 10 or 13 values to this array.
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
  • dlebechdlebech Member Posts: 7
    cemkaraer wrote:
    MyEndLine[1] := 10;
    MyEndLine[2] := 13;
    If MyEndLine is a text array, it is impossible to assign 10 or 13 values to this array.

    They need to be of the type "char" instead. And you probably need to do like this instead:
    MyFile.write('your text'+MyEndLine[1] + MyEndLine[2]);

    David

    PS. By the way, the 10 and 13 are the ASCII numbers for carriage return and line feed. That's why they change line for you :-)
  • Cem_KaraerCem_Karaer Member Posts: 281
    MyFile.write('your text'+MyEndLine[1] + MyEndLine[2]);
    The code above creates the following message:

    Microsoft Business Solutions-Navision
    Type conversion is not possible because 1 of the operators contains an invalid type.

    Text + Char

    OK
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
  • wonmowonmo Member Posts: 139
    MyFile.write('your text'+FORMAT(MyEndLine[1]) + FORMAT(MyEndLine[2]));
  • dlebechdlebech Member Posts: 7
    wonmo wrote:
    MyFile.write('your text'+FORMAT(MyEndLine[1]) + FORMAT(MyEndLine[2]));

    Thank you for the correction :-)

    For cemkaraer: In general when you need to convert something to text, you can almost always use the FORMAT command. Works with chars, integers, decimals, dates and so forth.

    -David
  • ara3nara3n Member Posts: 9,256
    cemkaraer wrote:
    MyEndLine[1] := 10;
    MyEndLine[2] := 13;
    If MyEndLine is a text array, it is impossible to assign 10 or 13 values to this array.

    MyEndLine is not an array. It's text type. And text is an array of characters.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.