[RESOLVED] Trouble writing to a .txt file
I am trying to write to a .txt file here is my code:
VB Code:
Dim oFile As System.IO.File
Dim oWrite As System.IO.StreamWriter
oWrite = oFile.CreateText("C:\New.txt")
oWrite.WriteLine("This is just a test.")
oWrite.WriteLine()
The code will create a new txt file, but it will not write the text to the file.
thanks
Re: Trouble writing to a .txt file
Add these 2 lines at the end:
oWrite.Flush()
oWrite.Close()
Re: Trouble writing to a .txt file
First off, CreateText is a Shared method so you should just qualify it with the class name rather than a variable name, i.e.
VB Code:
oWrite = IO.File.CreateText("C:\New.txt")
Secondly, you have call Close on the StreamWriter to flush the data to the file and close it.