Reading Text files

RuubenRuuben Member Posts: 41
Hello, i'm trying to read a text file line by line, but readtext function is reading character by character. This is the code i'm using:

VarFile.OPEN('C:\FILE.TXT');
VarFile.CREATEINSTREAM(VarInStream);

WHILE NOT VarInStream.EOS() DO
BEGIN
VarInStream.READTEXT(VarText1024);
END;

Answers

  • DaveTDaveT Member Posts: 1,039
    Hi Ruuben,

    The code looks fine to me - have you tried to use VarFile.TEXTMODE
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • RuubenRuuben Member Posts: 41
    Yes, i've tried it but it's the same.. it reads an only character
  • DaveTDaveT Member Posts: 1,039
    Hi Ruuben,

    :-k Strange indeed - I have tested the code on a Cronus database and it is working fine. Try specifing the Lenght in the Readtxt command or use the Varfile.Read command.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • nunomaianunomaia Member Posts: 1,153
    Did you tried to enforce string length by defining a length parameter?
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • RuubenRuuben Member Posts: 41
    Hi again, first thanks for helping me.. i think i've found one reason why it doesn't work. I'm trying to open a xml file like a text file, in this case readtext function reads character by character. When i've changed the file selected by a normal text file it works correctly.

    What i want to do is to change the first line (which is version of xml file) by another different line.

    Maybe i could solve this problem by another way.
  • nunomaianunomaia Member Posts: 1,153
    If are reading an XML file you are probally reading a unicode file. Navision and unicode .... [-o<
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • DaveTDaveT Member Posts: 1,039
    Hi Ruuben,

    have a look at this post

    viewtopic.php?f=23&t=29313&hilit=replace+string
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • RuubenRuuben Member Posts: 41
    Hi! i've solved it by changing version of xml file in XmlPort from UTF-16 to UTF-8, i don't understand it by it worksss xDDD

    thanks!!!!
  • nunomaianunomaia Member Posts: 1,153
    Because the format of UFT8 it’s different of UTF-16. UTF-8 without any special chars it’s similar to ASCII format so NAV can read it more or less well. Working with UTF18 files it’s double byte so for Navision it’s like a binary file.
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
Sign In or Register to comment.