Thanks in Advance.
I need to create files in a Sub and immediately write from StreamWriter. I can't figure out how to release the newly created files so StreamWriter can work. I get an error that file is in use by another process. This works if I create the files outside of
VB and just run the StreamWriter.
Code:
Imports System.IO
Public Class Form1
Public a_HoldArray(60) As String 'a_HoldArray is populated in another Sub.
Public filenamevariable As String
'CREATE AND WRITE FILE
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' GET A VARIABLE INTO THE FILE NAME
filenamevariable = "DataTime"
File.Create("C:\Documents and Settings\xxxxxx_" & filenamevariable & "_xxxxxx.txt")
Dim FileWriter As StreamWriter
FileWriter = New StreamWriter("C:\Documents and Settings\xxxxxx_DateTime_xxxxxx.txt", False)
For i = 1 To UBound(a_HoldArray)
FileWriter.WriteLine(a_HoldArray(i))
Next
FileWriter.Close()
End Sub
End Class