
Deleting Last Carriage Return from Text File
<<
<<Hi All,
<<
<<I have a module which exports a load of text from my
<<tables and sticks them into a text file - I want the last
<<entry to end without a carriage return, but no matter what
<<I've tried I always end up with the unwanted carriage
<<return (which has adverse effects on what I do with the
<<text file afterwards). Anybody got any suggestions as to
<<how I could get the module to open the text file, go to
<<the end of the text and delete the last carriage return?
<<
Someone else may have a better way, but here's one way you can do it. Essentially open the file for binary access
afterwards and change the last two bytes (carriage return and linefeed) to spaces. So you won't get an extra line at the
bottom, but you will have two extra spaces at the end of the last record.
intFile = FreeFile
strFileOut = "C:\Output.txt"
Open strFileOut For Output As #intFile
For Each objEntry In colEntries
Debug.Print objEntry.getAll
Print #intFile, objEntry.getAll
Next
Close #intFile
intFile = FreeFile
Open strFileOut For Binary As #intFile
varFileSize = LOF(intFile)
'Change the next to last byte from Chr(13) to a space
Put intFile, varFileSize - 1, " "
'Change the last byte from Chr(10) to a space
Put intFile, varFileSize, " "
Close #intFile
Hope this helps!
Sincerely,
Keith Fink
Microsoft Developer Support