Dataport - delete space in a file

Hi. I’m producing a file with a standard dataport. When I open the file in notepad, and go to the end of the file, the cursor is just behind the last letter. This is expected. However, because the file will be procced by another system, I need the cursor to be at the start of the next line (don’t ask me why, the other system is old and rigid). I can press enter in Notepad, and make that happen. But how do I do this in Navision? I have tried the following code in the onPostDataport: tt[1] := 13; tt[2] := 10; CurrFile.WRITE(tt); This works in a way, but I get an extra space in the file (why?). The space can’t be there either. So, either the code is wrong, and thats why it produces the extra space, (how do I write CR/LF then?) or I need to write some code to remove the space, and how would you expert minds do that (-: With regards, Thomas Jensen Norway.

You may try to add a new dataitem to the end of the dataport what does not have any records to export (filter everything out). If you have default crlf as dataitem separators, it should create a crlf in the end of the file. Haven’t tried it myself though - just an idea.

Hi. Yes, thats what I did first. I can’t get it to work. At the end of the file, there is some strange letters, and a space… Please help [?] Regards, Thomas Jensen Norway.

Let’s start with a few postulates:


  1. When a dataport runs, ‘CurrFile’ is set to TEXTMODE(FALSE) – let’s call it ‘binary’ mode. 2) When you write a text variable to a file in ‘binary’ mode, the text characters are written, followed by a ‘null’ char… this is the ‘extra space’ that you see… (You may need a file editor that has a ‘binary’ or ‘hex’ mode to see the actual characters. I used UltraEdit – open the file, switch to hex mode – aha, there’s an 0x00 char at the end…) 3) For the greatest control of what gets into a file in binary mode, write one Char at a time. 4) If the file were in ‘text’ mode, you could simply write an empty string…

So, there are two available solutions: a) change ‘tt’ to a Char and code it as follows:tt := 13; CurrFile.WRITE(tt); tt := 10; CurrFile.WRITE(tt); Or b) switch the file to text mode, and write an empty string:CurrFile.TEXTMODE(TRUE); CurrFile.WRITE(''); Hope this helps.