Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove trailing newline vbcrlf from file output 1

Status
Not open for further replies.

garybIT

IS-IT--Management
Jan 15, 2008
4
US
I have a program that simply opens a file and prints a string to the file and closes it. I need this file to not have a CR/LF after the string (which does not contain the CR/LF). The print statement seems to put the CR/LF there when it writes to the file.
Example:
Open strFile For Output As #1 Len = Len(strOutput)
Print #1, strOutput
Close #1

_________________________________________________________
Same variable, below demonstrates string has no trailing vbcrlf:
Clipboard.Clear
Clipboard.SetText strOutput
_________________________________________________________
If I paste into a notepad window, there is no newline character at the end of the file. I've tried different modes and everything I could find online regarding the ending newline character, but could not find a solution.

Any help would be greatly appreciated!
 
Nevermind, that won't probably work, depending on what you want, as it replaces the data at the beginning with the strOutput.
 
Hi Gary!

Try this instead:
Code:
Dim fso As FileSystemObject, ts As TextStream
...
Set fso = New FileSystemObject
Set ts = fso.CreateTextFile(strFile, Overwrite:=True)
ts.Write strOutput
ts.Close
Set ts = Nothing
Set fso = Nothing

Needs reference to MS Scripting Runtime.
:)

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Thanks everyone for your quick replies! I appreciate all of your help! dilettante's solution did work. I'm not sure why I didn't already know this, but thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top