Public Class EventLogger
' Eventuality - Version 1.0
' This program is designed to read keyboard inputs and output the corresponding patient events to a plain text file
' Development commenced: December 15 2011
' Program Release: December 19 2011
Dim StopWatch As New Diagnostics.Stopwatch
Dim EventFile As System.IO.StreamWriter
Dim KeyPressed As Boolean = False
Private Sub EventLogger_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Timer1.Enabled = False ' Runs on load and disables Timer till Start is clicked
Label1.Text = "0" ' Sets Stopwatch counter on screen to 0 at the Start
TextBox1.Text = vbNewLine & vbNewLine & vbNewLine & vbNewLine & vbNewLine & vbNewLine & vbNewLine & _
" Eventuality Ver: 1.0"
TextBox1.Enabled = False ' Temporarily disables input to Textbox
If My.Computer.FileSystem.DirectoryExists("C:\Eventuality\") = False Then ' Checks if Eventuality directory does not exist
My.Computer.FileSystem.CreateDirectory("C:\Eventuality\") ' If it does not, create it
End If
SaveFileDialog1.InitialDirectory = "C:\Eventuality\" ' Sets default directory
SaveFileDialog1.DefaultExt = "states" ' Sets default file extension
If SaveFileDialog1.ShowDialog() = DialogResult.OK Then ' Get user defined filename and create file
Dim NameString As String = System.IO.Path.GetFileNameWithoutExtension(SaveFileDialog1.FileName)
EventFile = My.Computer.FileSystem.OpenTextFileWriter("C:\Eventuality\" & NameString & ".states", True)
Else
End ' If user hits Cancel or does not enter a filename, program terminates
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = Me.StopWatch.Elapsed.TotalSeconds.ToString("0") ' Formats the text string in Label to display the elapsed time in seconds
End Sub
Private Sub BtnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStart.Click
If Timer1.Enabled = False Then ' If the Timer isn't running
TextBox1.Enabled = True ' Enables Textbox for input
TextBox1.Text = "" ' Resets Textbox contents
Timer1.Enabled = True ' Turn the Timer on
Me.StopWatch.Start() ' Inits Stopwatch
EventFile.WriteLine(Label1.Text & vbTab & "Start Acquisition") ' Writes event type to text file
TextBox1.AppendText(Label1.Text & vbTab & "Start Acquisition" & vbNewLine) ' Inputs event type and hit return
BtnStart.Text = "Stop" ' Button text now says Stop
TextBox1.Focus() ' Restore focus to textbox after button press
Else ' If Timer is running
Me.StopWatch.Reset() ' Resets Stopwatch
BtnStart.Enabled = False ' Disables Start button
Timer1.Enabled = False ' Turn the Timer off
EventFile.WriteLine(Label1.Text & vbTab & "Stop Acquisition") ' Writes event type to text file
TextBox1.AppendText(Label1.Text & vbTab & "Stop Acquisition" & vbNewLine) ' Inputs event type and hit return
Label1.Text = "0" ' Resets Stopwatch counter on screen
BtnStart.Text = "Start" ' Button text reverts to Start
EventFile.Close() ' Closes Text File
TextBox1.Focus() ' Restores focus to textbox after button press
End If
End Sub
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles TextBox1.KeyDown
If KeyPressed = False Then
KeyPressed = True
If e.KeyData = Keys.D1 Then ' If keystroke is "1"
e.SuppressKeyPress = True ' Prevents actual keypress appearing
EventFile.WriteLine(Label1.Text & vbTab & "Sigh") ' Writes timestamp and event type to text file
TextBox1.AppendText(Label1.Text & vbTab & "Sigh" & vbNewLine) ' Displays timestamp and event type on program textbox and hit return
ElseIf e.KeyData = Keys.D2 Then
e.SuppressKeyPress = True
EventFile.WriteLine(Label1.Text & vbTab & "Cry")
TextBox1.AppendText(Label1.Text & vbTab & "Cry" & vbNewLine)
ElseIf e.KeyData = Keys.D3 Then
e.SuppressKeyPress = True
EventFile.WriteLine(Label1.Text & vbTab & "Whimper")
TextBox1.AppendText(Label1.Text & vbTab & "Whimper" & vbNewLine)
ElseIf e.KeyData = Keys.D4 Then
e.SuppressKeyPress = True
EventFile.WriteLine(Label1.Text & vbTab & "Pant")
TextBox1.AppendText(Label1.Text & vbTab & "Pant" & vbNewLine)
ElseIf e.KeyData = Keys.D5 Then
e.SuppressKeyPress = True
EventFile.WriteLine(Label1.Text & vbTab & "Gag")
TextBox1.AppendText(Label1.Text & vbTab & "Gag" & vbNewLine)
ElseIf e.KeyData = Keys.D6 Then
e.SuppressKeyPress = True
EventFile.WriteLine(Label1.Text & vbTab & "Congested Breathing")
TextBox1.AppendText(Label1.Text & vbTab & "Congested Breathing" & vbNewLine)
ElseIf e.KeyData = Keys.D7 Then
e.SuppressKeyPress = True
EventFile.WriteLine(Label1.Text & vbTab & "Cough")
TextBox1.AppendText(Label1.Text & vbTab & "Cough" & vbNewLine)
ElseIf e.KeyData = Keys.D8 Then
e.SuppressKeyPress = True
EventFile.WriteLine(Label1.Text & vbTab & "Hiccup")
TextBox1.AppendText(Label1.Text & vbTab & "Hiccup" & vbNewLine)
ElseIf e.KeyData = Keys.D9 Then
e.SuppressKeyPress = True
EventFile.WriteLine(Label1.Text & vbTab & "Sneeze")
TextBox1.AppendText(Label1.Text & vbTab & "Sneeze" & vbNewLine)
ElseIf e.KeyData = Keys.D0 Then
e.SuppressKeyPress = True
EventFile.WriteLine(Label1.Text & vbTab & "Grunt")
TextBox1.AppendText(Label1.Text & vbTab & "Grunt" & vbNewLine)
Else
e.SuppressKeyPress = True ' Supresses keystroke entry when invalid key is pressed
End If
Else
e.SuppressKeyPress = True ' Supresses repeated keystroke entries when a valid key is held down
End If
End Sub
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
KeyPressed = False ' Resets KeyPressed variable to False when key is released
End Sub
End Class