Problems with writing to txt file

C

chauc3r

I'm having problems writing to a text file. Basically it refuses to
write anything. The file is created. At the appropiate times it goes
into the correct if statements (I have verified this using msgboxes).
Any idea why it wouldnt be writing anything?

Do Until (objFacilitySht.Cells(row, cboAPName.Text).Value = "")
Dim fsStream As New FileStream(txtSaveto.Text & "\" &
objFacilitySht.Cells(row, cboAPName.Text).Value & ".txt",
FileMode.Create, FileAccess.Write)
Dim swWriter As New StreamWriter(fsStream)

' Start Writing Config files
Try
' Do until the end of the config sheet
counter = 1
Do Until (objConfigSht.Cells(counter, 1).Value = "")
If (InStr(objConfigSht.Cells(counter, 1).Value, "###")) Then
pound = objConfigSht.Cells(counter, 1).value.replace("#", "")

If pound = "1" Then
swWriter.WriteLine("!Revision " & Rev_date)

End If
Else
swWriter.WriteLine(objConfigSht.Cells(counter, 1).Value)

End If
counter += 1
Loop

swWriter.Close()

Catch ex As IOException

MsgBox(ex.Message)

End Try
row += 1
Loop
 
Z

Zoury

Hi !
swWriter.Close()

Catch ex As IOException

MsgBox(ex.Message)

End Try

Is there an exception thrown.. ? if so then you didn't call the Close()
method, which should drop all the changes made to the file content.

try to call Close() in the Catch too :
'***
Try

' code code code...

swWriter.Close()

Catch ex As IOException

swWriter.Close()
MsgBox(ex.Message)

End Try
'***
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top