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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write text file without skipping a line between records

Status
Not open for further replies.

alexisb

Programmer
Apr 5, 2001
100
US
I am exporting data to a text file in a loop. The output file skips a line after each loop. I want the data to be in one line or to export 10 or 20 times before skipping a line. Is there a way for me to say "don't skip a line" or to control when to skip a line?
Thanks for your help.
Here's an example similar to my code:
Code:
i = 0
 Open "myfile.txt" For Output As #1
 Do While i <> 3
 i = i + 1
 Print #1, i & &quot;,&quot;
 Loop
 Close #1
My output is:
1,
2,
3
I want: 1,2,3
 
after the loop you could try removing your carriage returns like so&quot;

Code:
____________________________

Dim replacestr as String
Dim strfiledata as String


Open &quot;myfile.txt&quot; For Input as #1
strFileData = Input(LOF(1), #1)

replacestr = Replace(strFileData, vbCr, &quot;&quot;)

Close #1

Dim fso As New FileSystemObject, fil As File, ts As TextStream
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
fso.CreateTextFile (&quot;c:\ParsedData.csv&quot;)
Set fil = fso.GetFile(&quot;c:\ParsedData.csv&quot;)
Set ts = fil.OpenAsTextStream(ForWriting)

ts.Write replacestr
ts.Close
_______________________________________

GTLoco
 
alexisb,

i = 0
Open &quot;myfile.txt&quot; For Output As #1
Do While i <> 3
i = i + 1
Print #1, i & &quot;,&quot;;
Loop
Print #1, &quot;&quot;
Close #1

Wayne
 
Thank you so much! Wayne, your code worked perfectly!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top