how to create a codeunit for a text file
Christ
Member Posts: 24
Hello, i created a dataport to import a text file. Problem is that this process has to be automated through NAS. Nas doesn't support dataport so i have to create a codeunit to import the text file. This is rather new for me. Can anyone give me some info/code how to read in a text file through codeunit. Kind regards
0
Comments
-
I would go for a report or a XMLport, but you could also use codeunit. Maybe DataType File fits for you, but it depends on the structure of the file you want to import."Money is likewise the greatest chance and the greatest scourge of mankind."0
-
what is the advantage of using a report instead of a codeunit? I'm new in this stuff so i would choose the most easy way to go with. It's just a file with a komma separator per record line.0
-
If 1 line is less than 1024 chars, you can read line per line and analyse it to separate the different fields.
A report has no advantages. Best use a codeunit.
Best use tab separated. It is safer than ","-separated.
The code is something like this:txtTab := 'x'; // txtTab is text of len 1 txtTab[1] := 9; fil.TEXTMODE(true); fil.WRITEMODE(false); IF NOT fil.OPEN('c:\subdir\file.txt') then error('Could not open'); intLen := fil.LEN; WHILE intlen > fil.POS do begin // do not use always fin.LEN. It slows down a lot clear(txtString); fil.READ(txtString); // analyse the txtString blnStop := FALSE; REPEAT intTabPos := STRPOS(txtString,txtTab); IF intTabPos <> 0 THEN BEGIN txtValue := COPYSTR(txtString,1,intTabPos - 1); txtString := COPYSTR(txtString,intTabPos + 1); END ELSE BEGIN txtValue := txtString; blnStop := TRUE; END; // do something with your field ... UNTIL blnStop; END; fil.CLOSE;Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
I find the ; the best seperator (together with the [] fieldstart/end delimiter)kriki wrote:If 1 line is less than 1024 chars, you can read line per line and analyse it to separate the different fields.
A report has no advantages. Best use a codeunit.
But a report has an advantage, it can be run from the "start-search" (or run depending on version) to run a link like [url=navision://.....]navision://.....[/url], a codeunit does not have that option. (for the rest indeed no advantages)0 -
The possibility that in a description there is a ; or a , is too high. I have had that a lot of times. The TAB is less likely (only happens if users copy info from Excel).Sog wrote:
I find the ; the best seperator (together with the [] fieldstart/end delimiter)kriki wrote:If 1 line is less than 1024 chars, you can read line per line and analyse it to separate the different fields.
A report has no advantages. Best use a codeunit.
But a report has an advantage, it can be run from the "start-search" (or run depending on version) to run a link like [url=navision://.....]navision://.....[/url], a codeunit does not have that option. (for the rest indeed no advantages)
An even better separator is "MAHABHARATA" in the hope no one stores info from Hindu religion in NAV.
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
I tried it out and everything works fine but for me the problem is how to cut to the next line. So the first line works fine but the secon doesn't. The text file is like this: 1;1;1;1:1
2;2;2;2;2
so the field delimiter is ; and record delimiter is newline but how to solve the new line so that is is been seen as a new record?0 -
Set TEXTMODE of your file variable to TRUE then READ will return one line to you."Money is likewise the greatest chance and the greatest scourge of mankind."0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions