Not Reading the first line while importing

bobnavisionbobnavision Member Posts: 159
Hi,

I am using a dataport to import CSV file. The first line of the CSV file is having heading which I do not want to import .
How can we ignore the first line so that dataport does not give any error while importing because of the headings?

Regards,

Comments

  • jorgitojorgito Member Posts: 115
    Two ways:

    1. Remove the heading from the csv file and import

    2. Use a variable iCount that increases in the OnAfterImportRecord. When the iCount = 1 (first line) do CurrDataport.SKIP;
  • bobnavisionbobnavision Member Posts: 159
    I cannot use the first way because it will on client site,

    The second way I tried but it didn't worked. I declared an integer variable
    wrote the code CurrDataport.skip on OnBeforeImport but it wont work.
    It never reaches to the code.

    rgds
  • krikikriki Member, Moderator Posts: 9,118
    In the "OnPreDataItem()", put this code:
    IF CurrDataport.IMPORT THEN BEGIN
      CurrFile.TEXTMODE(TRUE);
      CurrFile.READ(txt);
      CurrFile.TEXTMODE(false);
    END;
    
    And txt is a text1024-variable.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • krikikriki Member, Moderator Posts: 9,118
    Just created a Tips&Tricks. This will also help if the headerline is more then 1024 chars: http://www.mibuso.com/forum/viewtopic.php?p=43344#43344
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DenSterDenSter Member Posts: 8,307
  • bobnavisionbobnavision Member Posts: 159
    Hi Kriki,

    That amazingly works. I appreciate that.
    what is this code doing and how CHAR works.
    How we will make it to work for 2 lines ?

    Regards
  • ara3nara3n Member Posts: 9,257
    to run it for two lines, just add put the code twice
    IF CurrDataport.IMPORT THEN BEGIN
      CurrFile.TEXTMODE(TRUE);
      CurrFile.READ(txt);
      CurrFile.READ(txt);
      CurrFile.TEXTMODE(false);
    END;
    
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • krikikriki Member, Moderator Posts: 9,118
    Hi Kriki,

    That amazingly works. I appreciate that.

    what is this code doing and how CHAR works.
    How we will make it to work for 2 lines ?

    Regards
    CHAR is 1 character of a string, so I start to read 1 character per time.
    In DOS/Windows, each end of line is finished with a CR/LF (carriage return/line feed) in ascii 13/10. So If I find the 10, I know that next char is a char of line 2 and stop reading.

    And for 2 lines, you can just put an extra repeat-until. Otherwise you can use a counter.I'll put this code in the tip&tricks.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.