HOWTO write text files with long lines

Shenpen
Member Posts: 386
What if you have to write a banking interface for Navision, where a line in the text file can easily more than 1024 chars long?
1) You cannot write one variable for a line, as a text var can only be 1024 chars long.
2) You cannot write in binary mode, as Navision will insert zero bytes after strings.
3) You could try to concatenate two or more text variables when writing, but even if it works, that's an ugly hack and it is hard to build a general "interface framework" on top of it.
The right solution is OUTSTREAM.
variables:
CR: char
LF: char
CRLF : text(2)
ThisFile: file
Stream: OutStream
1) You cannot write one variable for a line, as a text var can only be 1024 chars long.
2) You cannot write in binary mode, as Navision will insert zero bytes after strings.
3) You could try to concatenate two or more text variables when writing, but even if it works, that's an ugly hack and it is hard to build a general "interface framework" on top of it.
The right solution is OUTSTREAM.
variables:
CR: char
LF: char
CRLF : text(2)
ThisFile: file
Stream: OutStream
CR:=13; LF:=10; CRLF:=format(CR)+format(LF); ThisFIle.TEXTMODE(FALSE); ThisFile.CREATE('c:\dammit.txt'); ThisFile.CREATEOUTSTREAM(Stream); Stream.WRITETEXT('Ha!'); Stream.WRITETEXT('No zeroes, no spaces, no newlines, no problem!'); Stream.WRITETEXT(CRLF); Stream.WRITETEXT('See?'); ThisFile.CLOSE;
Do It Yourself is they key. Standard code might work - your code surely works.
0
Comments
-
You just might want to 'optimize' your code by skipping variables CR and LF. Instead initialize variable CRLF like this:
CRLF[1] := 13; CRLF[2] := 10;
0 -
A file in Binary mode works,but with some tricks.
Fil.WRITE(COPYSTR(txtMyString,1,STRLEN(txtMyString)); // the COPYSTR is needed, because otherwise the full length of txtMyString is written.
fil.SEEK(fil.POS - 1); // this repositions on the zero-byte and will be overwritten by the next WRITE.
Also the CRLF you made, I used.
So, now also the poor guys that are still working with older Navision-versions can write longer strings.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
And what happens with the zero byte of the last write in a file?
Do It Yourself is they key. Standard code might work - your code surely works.0 -
Shenpen wrote:And what happens with the zero byte of the last write in a file?
I did something like this when no streams existed and it worked.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!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