By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,847 Members | 2,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,847 IT Pros & Developers. It's quick & easy.

Problems with writing to txt file

P: n/a
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

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
'***

--
Best Regards
Yanick
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.