f.READ

mickukmickuk Member Posts: 47
edited 2006-02-15 in Navision Financials
Hi All,

Probably a really simple question but does anyone know of any method that is built into Navision that deals with reading lines froma file in an easy way. I'm not a seasoned Navision programmer and I'm a little lost.

I'm looking for a method that will allow me to read separate lines from a file. I've tried f.READ however that appears only to return the entire contents of the file.

For example my test file consists of the following...

1,4556667,56
3,4787678,65
3,5564333,67

If I output the "line" that I've read in from this file I get the entire contents. I've looked at f.TEXTMODE which I presume should be set to true (based on my past experience of file output with Navision to avoid binary type files/no end of line).

This is my test code...
  IF EXISTS('filename.txt') THEN BEGIN

     importFile.OPEN('filename.txt');

         WHILE importFile.POS < importFile.LEN DO BEGIN

            importFile.READ(in_line);
              MESSAGE(in_line);

         END;
  END
  ELSE
     MESSAGE('The import file does not exist');    


The output from this simply relays the entire contents of the file back through a message box; however what I am aiming for is for each line to be read separately. Any help would be appreciated.

Comments

  • KowaKowa Member Posts: 923
    If TEXTMODE it set to TRUE, READ should return just one line instead of the whole text. If it is a unix generated text file, this will not work (only LF = LineFeed at the end of the line without a CR = CarriageReturn as used in Windows) without converting the file to the windows text file type.
    http://kb.iu.edu/data/acux.html
    Kai Kowalewski
  • mickukmickuk Member Posts: 47
    edited 2006-02-15
    Thanks for the information. This is however quite strange as the file that I'm using has been produced on a windows based machine using notepad. One would assume that this should have the correct EOL characters.

    Is there any other reason why this would fail? When I use
    Length := STRLEN(in_line);
    

    I get the total number of characters in the file. I assume that this should report back the number of characters that is within the line that has been read (in_line). If this was the case then that would be a lot less than what is currently being returned.

    Thanks in advance

    EDIT
    =============================
    Solved....

    I had been messing with the code when i had a free moment and realised that I has set textmode on my output file but not on my input #-o


    =============================
  • krikikriki Member, Moderator Posts: 9,112
    Try this:
    IF EXISTS('filename.txt') THEN BEGIN
      importFile.WRITEMODE(FALSE);
      importFile.TEXTMODE(TRUE);
      importFile.OPEN('filename.txt');
      WHILE importFile.READ(txtLine) > 0 DO BEGIN
        MESSAGE('%1',txtLine);
      END;
      importFile.CLOSE;
    END
    ELSE
       MESSAGE('The import file does not exist');
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • mickukmickuk Member Posts: 47
    Thanks kriki that worked fine. Missed the most obvious thing on there.....the TEXTMODE :whistle:
Sign In or Register to comment.