Importing a file with a Codeunit.

CDLSA
Member Posts: 4
Is their anyone who has an example of a codeunit for importing a text-file (ASCII) in navision. Just to know how to find the first record of the txt-file and how to find the next record.
Without using a dataport so I would be able to call the CU with NAS to import the file.
Thanks.
Without using a dataport so I would be able to call the CU with NAS to import the file.
Thanks.
0
Comments
-
file.TEXTMODE(TRUE);
file.WRITEMODE(FALSE);
file.OPEN(file path and name);
REPEAT
file.READ(vstring);
// do something with vstring
UNTIL
file.POS = file.LEN;
This code reads 1 line of text at a time.
Remember, vstring can only be a max of 1000 characters so each line cannot be more than 1000 characters.
A dataport is much better to use because of this. You can also do the same thing with a dataport, some coding and the common dialog ocx.0 -
wonmo wrote:file.TEXTMODE(TRUE);
file.WRITEMODE(FALSE);
file.OPEN(file path and name);
REPEAT
file.READ(vstring);
// do something with vstring
UNTIL
file.POS = file.LEN;
This code reads 1 line of text at a time.
Remember, vstring can only be a max of 1000 characters so each line cannot be more than 1000 characters.
A dataport is much better to use because of this. You can also do the same thing with a dataport, some coding and the common dialog ocx.
isn't it?0 -
wonmo wrote:file.TEXTMODE(TRUE);
file.WRITEMODE(FALSE);
file.OPEN(file path and name);
REPEAT
file.READ(vstring);
// do something with vstring
UNTIL
file.POS = file.LEN;
This code reads 1 line of text at a time.
Remember, vstring can only be a max of 1000 characters so each line cannot be more than 1000 characters.
A dataport is much better to use because of this. You can also do the same thing with a dataport, some coding and the common dialog ocx.
for example my data is --> no,name,address
how to segregate ","
so no goes to field no, name goes to field name, and address goes to field address
thanks0 -
After you read the line in .txt file, use STRPOS to determine delimiter of field, and COPYSTR to copy the string.0
-
bekio wrote:After you read the line in .txt file, use STRPOS to determine delimiter of field, and COPYSTR to copy the string.
here is my code and sample data
i want to segregate no,name and address
anyone can help?
thanksOnRun() SFile.TEXTMODE(TRUE); SFile.WRITEMODE(FALSE); SFile.OPEN('D:\TestImport\Test.txt'); REPEAT SFile.READ(vString); vStringCode := STRPOS(vstring,';'); TestImport.No := UPPERCASE(vStringCode); TestImport.INSERT; UNTIL SFile.POS = SFile.LEN; MESSAGE('Import Done');
code2;Nama 2;Address 2
code3;Nama 3;Address 3
code4;Nama 4;Address 4
code5;Nama 5;Address 50 -
Search the forum on COPYSTR + STRPOS and you'll find some postings with sample code. For example:
viewtopic.php?f=32&t=44776
viewtopic.php?f=23&t=15461No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0 -
Luc Van Dyck wrote:Search the forum on COPYSTR + STRPOS and you'll find some postings with sample code. For example:
viewtopic.php?f=32&t=44776
viewtopic.php?f=23&t=15461
thanks a lot for your help Luc0 -
anyone how to import txt file without delimeter?
we use fixed length0 -
What is your problem exactly, splitting file lines in several variables?* Daniele Rebussi * | * Rebu NAV Diary *0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions