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!

Reuseing an ObjWriter made with System.IO.StreamWriter()... Help!

Status
Not open for further replies.

Timalaugh

Programmer
Aug 10, 2011
31
US
Hi everyone,

I created an output stream object and all i want to do is be able to use the same object to write to different files:

Dim objWriter As New System.IO.StreamWriter(OutFileName)
... and writing to the file using:
objWriter.WriteLine(WriteThisText)

...it works fine but anyone know if I can reuse the object to write to another file?
I tried just changing the OutFileName... and the .Close, .Flush and .Dispose and then changing the OutFileName but the only thing that works is creating another output object for the second file.

Is this just the way it is? ... or am i missing something?
 

You can use the same variable:

Dim objWriter As New System.IO.StreamWriter(OutFileName)

'do some stuff

objWriter.Close()
objWriter.Dispose()

objWriter = New System.IO.StreamWriter(DifferentFileName)

That's just the way it is.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top