Question Open two files at once...?

ianr900

Member
Joined
Jul 13, 2006
Messages
18
Location
UK
Programming Experience
3-5
Can I have two files open at the same time to write text into, in VB .net?
I have this code:
VB.NET:
 Dim fsStream As New FileStream(EVENT_LOG_PATH & EVENT_LOG_FILENAME & DateString & ".ip", FileMode.Append, FileAccess.Write, FileShare.Read)
    Dim swWriter As New StreamWriter(fsStream)

    ' Open log file for use by VLOG
    Dim fsVLOGStream As New FileStream(EVENT_LOG_PATH & VOLTS_LOG_FILENAME & DateString & ".ip", FileMode.Append, FileAccess.Write, FileShare.Read)
    Dim swVLOGWriter As New StreamWriter(fsStream)

Then I use this to write lines of text to each file:
VB.NET:
swWriter.WriteLine(str)
swVLOGWriter.WriteLine(str)

If I open a file, write to it, then close it, everything works fine. But if I try to have both open at the same time all the text ends up in the first file and nothing gets written to the second! There are no build errors.
What am I doing wrong?
Thx.
 
OK - I see my mistake now (a typo in my second dim statement)! Should have been this:

Dim swVLOGWriter As New StreamWriter(fsVLOGStream)

Now it works. Sorry to bother you guys.
 
Back
Top