Outstream and Carriage Returns

Alex_Chow
Member Posts: 5,063
I'm using Outstream to write to a file. The problem is when I use Outstream, it does not put Carriage return at the end of the line. I'm going to be writing multiple lines using Outstream.
I can't use the regular write, because it crashes if you write a very long string.
I've tried this:
I also tried:
I also tried:
But nothing seem to work. Can anyone help? Thanks!
I can't use the regular write, because it crashes if you write a very long string.
I've tried this:
ExportFileName.TEXTMODE(FALSE); OutputText.ADDTEXT(sometext); ExportFileName.CREATEOUTSTREAM(OutStr); OutputText.WRITE(OutStr); ExportFileName.write(LF); ExportFileName.write(CR); ExportFileName.CLOSE;
I also tried:
ExportFileName.TEXTMODE(FALSE); OutputText.ADDTEXT(sometext); ExportFileName.CREATEOUTSTREAM(OutStr); OutputText.WRITE(OutStr); ExportFileName.CLOSE; ExportFileName.OPEN(NameofExportFile); ExportFileName.TEXTMODE(FALSE); ExportFileName.SEEK(ExportFileName.LEN); ExportFileName.WRITE(LF); ExportFileName.WRITE(CR); ExportFileName.CLOSE;
I also tried:
ExportFileName.TEXTMODE(TRUE); OutputText.ADDTEXT(sometext); ExportFileName.CREATEOUTSTREAM(OutStr); OutputText.WRITE(OutStr); OutputText.WRITE('');
But nothing seem to work. Can anyone help? Thanks!
Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
0
Answers
-
Hello Alex,
strange thing this... I looked it up. For writing overlong lines I am using code which writes 1024char-chunks (maximum text variable), and reposition the file position before the trailing CR/LF for the next chunk. The outfile is written in textmode, no OUTSTREAM. This way you always get a CR/LF on the line's end.
with best regards
Jens0 -
I'm using bigtext and Outstream to write the lines to the file. Again, if you're exporting over (I think) 5000 character in a single line using File.WRITE, it crashes saying something about memory. For my case, using TEXTMODE and FILE.WRITE is not an option.
Anyone have any experience using Outstream and added the carriage return?Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book0 -
What you can do is:
after OutStream.Write(), do aOutFile.textmode(true); OutFile.write(''); OutFile.textmode(false);
You can also write the CR/LF as bytes from a string (in binary mode). The catch is to not use the OutStream for it.
with best regards
Jens0 -
jglathe wrote:What you can do is:
after OutStream.Write(), do aOutFile.textmode(true); OutFile.write(''); OutFile.textmode(false);
You can also write the CR/LF as bytes from a string (in binary mode). The catch is to not use the OutStream for it.
with best regards
Jens
Hi Jens,
Thanks for the reply. But as you can see from the sample I provided above, I tried these codes, but it didn't work.Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book0 -
Hi Alex,
you're right, I just tried it out - only works once at the end of the file. However, it works directly with BigText when you ADDTEXT the CR/LF into the BigText:CRLFString[1] := 13; CRLFString[2] := 10; TargetFile.CREATE('C:\Compress\CRLFTest.txt'); TargetFile.CREATEOUTSTREAM(TargetStream); //create a longer than 4k text FOR i := 1 TO 500 DO BEGIN TargetText.ADDTEXT('0123456789'); END; //add the cr/lf TargetText.ADDTEXT(CRLFString); //repeat to rule out that it works only once FOR k:=1 TO 10 DO BEGIN TargetText.WRITE(TargetStream); END; TargetFile.CLOSE; MESSAGE('done');
with best regards
Jens1 -
Jens, you are AWESOME!!!
Your next round of drinks is on me whenenver I meet you. :thumbsup:Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book0
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