5
« on: August 06, 2013, 01:10:01 PM »
I'm sure there is a much better way to do this, but it served my purpose. I have a form that displays a textbox for the user to provide information about why it was neccessary for the schedule to be overridden. When the send button is press this routine runs which logs the information to a text file on a server. tb_SystemSnapshot is a textbox that is loaded with information about the current system state upon Form load.
Private Sub OverrideReason_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SystemSnapshotTextBox.Text += "System Override: " & User & " " & Date.Now & vbCrLf
SystemSnapshotTextBox.Text += "Mixer Formula: " & MainForm.MixerFormula.Text & vbCrLf
SystemSnapshotTextBox.Text += "Filling: " & MainForm.Batch_Filling.Text & vbCrLf
SystemSnapshotTextBox.Text += "Formula list:" & vbCrLf
SystemSnapshotTextBox.Text += "[1] " & MainForm.Formula_List_0.Text & vbCrLf
SystemSnapshotTextBox.Text += "[2] " & MainForm.Formula_List_1.Text & vbCrLf
SystemSnapshotTextBox.Text += "[3] " & MainForm.Formula_List_2.Text & vbCrLf
SystemSnapshotTextBox.Text += "[4] " & MainForm.Formula_List_3.Text & vbCrLf
SystemSnapshotTextBox.Text += "[5] " & MainForm.Formula_List_4.Text & vbCrLf
SystemSnapshotTextBox.Text += "[6] " & MainForm.Formula_List_5.Text & vbCrLf
SystemSnapshotTextBox.Text += "[7] " & MainForm.Formula_List_6.Text & vbCrLf
SystemSnapshotTextBox.Text += "[8] " & MainForm.Formula_List_7.Text & vbCrLf
SystemSnapshotTextBox.Text += "[9] " & MainForm.Formula_List_8.Text & vbCrLf
SystemSnapshotTextBox.Text += "[10] " & MainForm.Formula_List_9.Text & vbCrLf
SystemSnapshotTextBox.Text += "[11] " & MainForm.Formula_List_10.Text & vbCrLf
SystemSnapshotTextBox.Text += "================================================================================================" & vbCrLf
Private Sub Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Send.Click
If UsrReason.Text.Length < 5 Then
MessageBox.Show("Please enter a description and resend")
UsrReason.Text = ""
Exit Sub
End If
Dim Datehash As String = Date.Now.ToString.Replace("/", "-")
Datehash = Datehash.Replace(" ", "")
Datehash = Datehash.Replace(":", "")
Dim LogFile As String = "S:\Compound Scheduling\Logs\" + Datehash + ".txt"
Try
My.Computer.FileSystem.WriteAllText(System.IO.Path.GetFullPath(LogFile), SystemSnapshotTextBox.Text & UsrReason.Text, True)
Catch ex As Exception
MsgBox("An Error occured Saving message")
End Try
Me.Close()
End Sub
I hope this helps.