I am using some helpful code found here: http://codingresolved.com/discussion...y-log-files/p1
I have built a simple form based on his sample and wanted to simply log a button press. I am not seeing a clear variable to actually write to the file created daily.... some help would be appreciated since I am intermediate at best and ask a lot of obvious questions....
Here is my sample form:
Code:Imports System.IO Public Class Form1 Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label1.Text = DateTime.Now.ToShortDateString Try Dim LogFileName As String LogFileName = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString() LogFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Sessions " + LogFileName + " .txt" Dim fs As New FileStream(LogFileName, FileMode.OpenOrCreate, FileAccess.Write) 'Dim fs As New FileStream("C:\Sessions + '" + LogFileName + "' + .txt", FileMode.OpenOrCreate, FileAccess.Write) Dim m_streamWriter As New StreamWriter(fs) Catch ex As Exception End Try Timer1.Start() End Sub '- See more at: http://codingresolved.com/discussion/722/how-to-create-daily-log-files/p1#sthash.N9wLM9zc.dpuf Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick Dim day As Integer = DateDiff(DateInterval.Day, CDate(Label1.Text), CDate(DateTime.Now.ToShortDateString)) Dim a As Integer = day If day >= 1 Then Dim LogFileName As String LogFileName = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString() LogFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Sessions " + LogFileName + " .txt" Dim fs As New FileStream(LogFileName, FileMode.OpenOrCreate, FileAccess.Write) Dim m_streamWriter As New StreamWriter(fs) Label1.Text = DateTime.Now.ToShortDateString End If '- See more at: http://codingresolved.com/discussion/722/how-to-create-daily-log-files/p1#sthash.N9wLM9zc.dpuf End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim logtext As String = Date.Now & "Macro Created:" & "--" & " " & "Subject:" & " " & "--" & " " & vbCrLf My.Computer.FileSystem.WriteAllText(HOW DO I POINT THIS TO THE FILE CREATED DAILY?, logtext, True) End Sub End Class




Reply With Quote
