mibuso.com

Microsoft Business Solutions online community
It is currently Fri May 24, 2013 6:04 pm

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Import dataport and skipping the header line
PostPosted: Thu Mar 16, 2006 6:34 pm 
Online
Moderator
MVP Microsoft Dynamics NAV
NAV TechDays 2013 attendee

Joined: Wed Jul 02, 2003 10:13 am
Posts: 7504
Location: Milan
Country: Italy (it)
Problem:you have a textfile with headers and you must import it with a dataport, but you want to skip the header line, because otherwise you get an error. How to do that?

Put some code in trigger "OnPreDataItem()":
(variable "cha" is CHAR)
Code: Select all
IF CurrDataport.IMPORT THEN BEGIN
  REPEAT
    CurrFile.READ(cha);
  UNTIL cha = 10; // of course in case the RecordSeparator is "<<NewLine>>"
END;

_________________
Regards,Alain Krikilion
Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title! || Read Forum Rules before making a posting


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 1:15 pm 
Online
Moderator
MVP Microsoft Dynamics NAV
NAV TechDays 2013 attendee

Joined: Wed Jul 02, 2003 10:13 am
Posts: 7504
Location: Milan
Country: Italy (it)
And for more than 1 line:
Code: Select all
IF CurrDataport.IMPORT THEN BEGIN
  LintLinesToRead := 2; // lines that must be read (this is an integer)
  REPEAT
    CurrFile.READ(cha);
    IF cha = 10 THEN
      LintLinesToRead -= 1;
  UNTIL LintLinesToRead = 0;
END;

_________________
Regards,Alain Krikilion
Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title! || Read Forum Rules before making a posting


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 20, 2008 5:23 am 
Offline

Joined: Thu Jul 27, 2006 6:08 pm
Posts: 319
Location: Sydney
Country: Australia (au)
I get an error "File is not open" at Currfile.Read(cha) part of the code.

i dont want to hardocode the filepath but when the "user" slects the "csv"file from the options tab

iam using 4.0(SP3)

Thanks

_________________
Regards,

GD


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 20, 2008 6:27 am 
Offline
MVP Microsoft Dynamics NAV
Site Supporter

Joined: Fri Jun 06, 2003 9:01 pm
Posts: 6979
Location: L.I., New York
Country: United States (us)
are you sure the code is on PreDataItem not PreDataPort?

(variable "cha" is TYPE CHAR)

_________________
Harry Ruiz
http://www.cosmeticsolutions.com
http://www.autismspeaks.org


Top
 Profile E-mail WWW  
 
 Post subject:
PostPosted: Fri Jun 20, 2008 7:18 am 
Offline

Joined: Thu Jul 27, 2006 6:08 pm
Posts: 319
Location: Sydney
Country: Australia (au)
thanks savatage #-o

_________________
Regards,

GD


Top
 Profile  
 
 Post subject: Re: Import dataport and skipping the header line
PostPosted: Mon May 30, 2011 10:06 am 
Offline

Joined: Fri Oct 28, 2005 1:46 pm
Posts: 127
Location: London
Country: United Kingdom (uk)
I am missing the logic for the Until cha = 10;
Is 10 the expected number of records?

_________________
Experience is what you get when you hoped to get money


Top
 Profile E-mail WWW  
 
 Post subject: Re: Import dataport and skipping the header line
PostPosted: Tue May 31, 2011 5:36 pm 
Online
Moderator
MVP Microsoft Dynamics NAV
NAV TechDays 2013 attendee

Joined: Wed Jul 02, 2003 10:13 am
Posts: 7504
Location: Milan
Country: Italy (it)
No, the 10 is the ASCII value of the line feed.

A newline in a textfile is defined by 2 chars : CR/LF = Carriage Return + Line Feed = ASCII 13 + ASCII 10.

So I am reading char per char until I find ASCII value = 10. When I have found it, I know I am at the end-of-line.

_________________
Regards,Alain Krikilion
Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title! || Read Forum Rules before making a posting


Top
 Profile  
 
 Post subject: Re: Import dataport and skipping the header line
PostPosted: Tue May 31, 2011 10:33 pm 
Offline

Joined: Fri Oct 28, 2005 1:46 pm
Posts: 127
Location: London
Country: United Kingdom (uk)
Thanks, it is a long time since I had to think about ASCII.
I have used your code and it works perfectly, many thanks.

_________________
Experience is what you get when you hoped to get money


Top
 Profile E-mail WWW  
 
 Post subject: Re: Import dataport and skipping the header line
PostPosted: Mon Apr 16, 2012 10:38 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Tue Aug 14, 2001 7:01 am
Posts: 5315
Location: Prague
Country: Czech Republic (cz)
Simple and Brilliant.

Thanks. :thumbsup:

_________________
David Singleton
Dynamics NAV Freelancer
Dynamics Book
Go-Live International


Top
 Profile E-mail WWW  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: