Importing a txt file

raven44raven44 Member Posts: 85
Hi,
I have a a txt file that I wish to bring into some customized tables into Navision.
Is there a way to read through the file line by line and then populate the appropriate tables? As the file is formatted into sections, which need modification before importation into Navision.
Eg.

** Transaction ID 16367864 Date - 2006-12-01 01:40:00
** Base[9835]:Region 15 [Processing Department] Financial

- USER1 placed in section 1 with $50.00
- USER2 placed in section 2 with $150.00
- USER3 placed in section 3 with $135.00 [Initiated]

USER1 pays small fee - $5.00
USER2 pays big fee - $10.00
USER3 - no fee

End of transaction 16367864



** Transaction ID 16367852 Date - 2006-12-01 01:32:12
** Base[9835]:Region 15 [Processing Department] Financial

...and continues with a similar format.
With the example above, it would be transferred into 3 Navision tables.
I'm hoping that I will be able to use a Dataport. Is this possible?
Any ideas would be greatly appreciated.
Thanks in Advance.

Answers

  • JohnieGJohnieG Member Posts: 56
    Just an idea.... :-k
    It seems that your problem would be much simpler if you had an xml file (or if you could create an xml file from your txt) for the kind of information that you want to insert.
    In that case I believe that the dataport would be much more easier to create...
    Always Look On The Bright Side Of Life...
  • krikikriki Member, Moderator Posts: 9,110
    You can also create a codeunit to import your textfile line-by-line.

    Something like:
    filRead.WRITEMODE(FALSE);
    filRead.TEXTMODE(TRUE);
    filRead.OPEN('The File');
    intLen := filRead.LEN;
    WHILE filRead.POS < intLen DO BEGIN
      filRead.READ(txtOneLine);
      ...
      do something with the line
      ...
    END;
    filRead.CLOSE
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • raven44raven44 Member Posts: 85
    Thanks, thats exactly what I'm looking for.
    Sometimes it seems so simple.

    Just an additional note for users that may go this route.
    When pushing the txtOneLine into a table that has a different datatype, use EVALUATE.
    An example can be found at:
    http://www.mibuso.com/forum/viewtopic.p ... xt+integer

    Thanks to all.
  • SpyrootSpyroot Member Posts: 45
    Thank you for the code. I was able to import txt from an email. Here is the code


    filRead.WRITEMODE(FALSE);
    filRead.TEXTMODE(TRUE);
    filRead.OPEN('C:\test.txt'); \\ File Location
    intLen := filRead.LEN;
    WHILE filRead.POS < intLen DO BEGIN
    filRead.READ(txtOneLine);
    FieldExist := STRPOS(txtOneLine,'Invoice'); \\ String to search
    IF (FieldExist > 0) THEN
    InvoiceTxt := COPYSTR(txtOneLine,FieldExist+10,9);
    END;
    filRead.CLOSE
  • bhalpinbhalpin Member Posts: 309
    Unbelievable!

    It's been a while since I opened and read a text file in C/Side - long enough that I can't remember exactly what to do.

    So, off into ADG and C/Side Developers Help.

    @#$%^&amp;*+_)*&^%$#$%^&*)_!!!

    Everything is there EXCEPT how to specify the file name. I keep going back to the page on File.OPEN thinking it's just GOT TO BE THERE ... but this is the syntax they show:

    [Ok := ] File.OPEN

    :-k

    Thank <whomever> for Mibuso though - in about 90 seconds I find this thread and see:

    filRead.OPEN('C:\test.txt'); \\ File Location

    Well DUH - There's a secret parameter to the open command! \:D/

    Sometimes ....
Sign In or Register to comment.