J
Jeffrey Spoon
Hello. I have been working on the program below. However I'm not sure
how to get my own event working properly. I created my ThresholdNormal
class and put a condition in the sub CheckThreshold. It then raises the
ThresholdOK event. My event handler Private Sub Threshold_Normal should
then run the EnterState7() sub. But the event is never raised and
judging from the fact that the label4 test I included doesn't update the
CheckThreshold() sub is never called. And I've no idea why. Any help
appreciated (sorry about the reams of code).
Code:
Form1:
Private StateVariableA As Integer 'A Main State
Private StateVariableB As Integer 'B Alarm substate
Private StateVariableBHistory As Integer 'B alarm substate
history
Protected Reading As Integer 'getReading variable
Protected LowerThreshold = 60 'thresholds
Protected UpperThreshold = 80
Protected count = -1 'debug
Private WithEvents Threshold As ThresholdNormal
Private Sub EnterState1()
'This is the Bed Empty (Default) State
'No patient in bed
StateVariableA = 1
StateAlbl.Text = StateVariableA
'
HeartRatelbl.Text = "Bed empty"
DataLogger.SetThresholds(LowerThreshold, UpperThreshold)
DataLogger.FastSpeed()
End Sub
Private Sub EnterState2()
'This is the Disable Alarm State
'Patient in bed
StateVariableB = 2
StateBlbl.Text = StateVariableB
'
DataLogger.SetDisableAlarm(True)
AlarmEnablebtn.Text = "Enable Alarm"
End Sub
Private Sub EnterState3()
'This is the Update Heart Rate State
'Responds to getReading event
StateVariableA = 3
StateAlbl.Text = StateVariableA
'
Reading = DataLogger.GetReading
' If Reading <= UpperThreshold And Reading >= LowerThreshold
Then
'Alarmlbl.Text = "Should be normal"
'End If
HeartRatelbl.Text = Reading
'
count = count + 1
countlbl.Text = count
Threshold.CheckThreshold()
End Sub
Private Sub EnterState4()
'This is the Alarm Enabled State
'Responds to Alarm Enabled event
StateVariableB = 4
StateBlbl.Text = StateVariableB
'
DataLogger.SetDisableAlarm(False)
AlarmEnablebtn.Text = "Disable Alarm"
End Sub
Private Sub EnterState5()
'This is the Alarm Substate
'This deals with State 5B
StateVariableA = 5
StateAlbl.Text = StateVariableA
EnterState2()
End Sub
Private Sub EnterState6()
'This is the Alarm activated state
'
StateVariableA = 6
StateAlbl.Text = StateVariableA
Alarmlbl.Text = "Threshold Exceeded"
End Sub
Private Sub EnterState7()
'This is the alarm reset (de-activate) state
'
StateVariableA = 7
StateAlbl.Text = StateVariableA
Alarmlbl.Text = "Threshold Normal" 'reset alarm
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Form load event
Threshold = New ThresholdNormal
EnterState1()
End Sub
Private Sub Patient_Bed_toggle(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles PatientInbtn.Click
If StateVariableA = 1 Then
EnterState5()
End If
End Sub
Private Sub Reading_Ready_get(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles DataLogger.NextReadingReady
'NextReadingReady() event handler
If StateVariableA = 5 Then
EnterState3()
ElseIf StateVariableA = 3 Then
EnterState3()
ElseIf StateVariableA = 6 Then
EnterState3()
ElseIf StateVariableA = 7 Then
EnterState3()
End If
End Sub
Private Sub Alarm_Toggle_click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles AlarmEnablebtn.Click
'Alarm Enabled/Disabled event handler
If StateVariableB = 2 Then
StateVariableBHistory = 2
StateBHlbl.Text = StateVariableBHistory
EnterState4()
ElseIf StateVariableB = 4 Then
StateVariableBHistory = 4
StateBHlbl.Text = StateVariableBHistory
EnterState2()
ElseIf StateVariableA = 6 Then
EnterState5()
ElseIf StateVariableA = 7 Then
EnterState5()
ElseIf StateVariableA = 3 Then
If StateVariableBHistory = 2 Then
EnterState2()
ElseIf StateVariableBHistory = 4 Then
EnterState4()
End If
End If
End Sub
Private Sub Upper_Threshold_exceed(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DataLogger.UpperThresholdExceeded
'Upper threshold exceeded event handler
If StateVariableA = 7 Then
EnterState6()
ElseIf StateVariableB = 4 Then
EnterState6()
ElseIf StateVariableA = 3 Then
EnterState6()
End If
End Sub
Private Sub Lower_Threshold_exceed(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DataLogger.LowerThresholdExceeded
'Lower threshold exceeded event handler
If StateVariableA = 7 Then
EnterState6()
ElseIf StateVariableB = 4 Then
EnterState6()
ElseIf StateVariableA = 3 Then
EnterState6()
End If
End Sub
Private Sub Threshold_Normal() Handles Threshold.ThresholdOK
If StateVariableA = 6 Then
EnterState7()
If StateVariableA = 3 Then
EnterState7()
End If
End If
End Sub
End Class
Class ThresholdNormal
Inherits Screen1
Public Event ThresholdOK()
Public Sub CheckThreshold()
If Reading <= UpperThreshold And Reading >= LowerThreshold Then
RaiseEvent ThresholdOK()
End If
Label4.Text = Reading
Label4.Text = "hello"
End Sub
End Class
how to get my own event working properly. I created my ThresholdNormal
class and put a condition in the sub CheckThreshold. It then raises the
ThresholdOK event. My event handler Private Sub Threshold_Normal should
then run the EnterState7() sub. But the event is never raised and
judging from the fact that the label4 test I included doesn't update the
CheckThreshold() sub is never called. And I've no idea why. Any help
appreciated (sorry about the reams of code).
Code:
Form1:
Private StateVariableA As Integer 'A Main State
Private StateVariableB As Integer 'B Alarm substate
Private StateVariableBHistory As Integer 'B alarm substate
history
Protected Reading As Integer 'getReading variable
Protected LowerThreshold = 60 'thresholds
Protected UpperThreshold = 80
Protected count = -1 'debug
Private WithEvents Threshold As ThresholdNormal
Private Sub EnterState1()
'This is the Bed Empty (Default) State
'No patient in bed
StateVariableA = 1
StateAlbl.Text = StateVariableA
'
HeartRatelbl.Text = "Bed empty"
DataLogger.SetThresholds(LowerThreshold, UpperThreshold)
DataLogger.FastSpeed()
End Sub
Private Sub EnterState2()
'This is the Disable Alarm State
'Patient in bed
StateVariableB = 2
StateBlbl.Text = StateVariableB
'
DataLogger.SetDisableAlarm(True)
AlarmEnablebtn.Text = "Enable Alarm"
End Sub
Private Sub EnterState3()
'This is the Update Heart Rate State
'Responds to getReading event
StateVariableA = 3
StateAlbl.Text = StateVariableA
'
Reading = DataLogger.GetReading
' If Reading <= UpperThreshold And Reading >= LowerThreshold
Then
'Alarmlbl.Text = "Should be normal"
'End If
HeartRatelbl.Text = Reading
'
count = count + 1
countlbl.Text = count
Threshold.CheckThreshold()
End Sub
Private Sub EnterState4()
'This is the Alarm Enabled State
'Responds to Alarm Enabled event
StateVariableB = 4
StateBlbl.Text = StateVariableB
'
DataLogger.SetDisableAlarm(False)
AlarmEnablebtn.Text = "Disable Alarm"
End Sub
Private Sub EnterState5()
'This is the Alarm Substate
'This deals with State 5B
StateVariableA = 5
StateAlbl.Text = StateVariableA
EnterState2()
End Sub
Private Sub EnterState6()
'This is the Alarm activated state
'
StateVariableA = 6
StateAlbl.Text = StateVariableA
Alarmlbl.Text = "Threshold Exceeded"
End Sub
Private Sub EnterState7()
'This is the alarm reset (de-activate) state
'
StateVariableA = 7
StateAlbl.Text = StateVariableA
Alarmlbl.Text = "Threshold Normal" 'reset alarm
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Form load event
Threshold = New ThresholdNormal
EnterState1()
End Sub
Private Sub Patient_Bed_toggle(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles PatientInbtn.Click
If StateVariableA = 1 Then
EnterState5()
End If
End Sub
Private Sub Reading_Ready_get(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles DataLogger.NextReadingReady
'NextReadingReady() event handler
If StateVariableA = 5 Then
EnterState3()
ElseIf StateVariableA = 3 Then
EnterState3()
ElseIf StateVariableA = 6 Then
EnterState3()
ElseIf StateVariableA = 7 Then
EnterState3()
End If
End Sub
Private Sub Alarm_Toggle_click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles AlarmEnablebtn.Click
'Alarm Enabled/Disabled event handler
If StateVariableB = 2 Then
StateVariableBHistory = 2
StateBHlbl.Text = StateVariableBHistory
EnterState4()
ElseIf StateVariableB = 4 Then
StateVariableBHistory = 4
StateBHlbl.Text = StateVariableBHistory
EnterState2()
ElseIf StateVariableA = 6 Then
EnterState5()
ElseIf StateVariableA = 7 Then
EnterState5()
ElseIf StateVariableA = 3 Then
If StateVariableBHistory = 2 Then
EnterState2()
ElseIf StateVariableBHistory = 4 Then
EnterState4()
End If
End If
End Sub
Private Sub Upper_Threshold_exceed(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DataLogger.UpperThresholdExceeded
'Upper threshold exceeded event handler
If StateVariableA = 7 Then
EnterState6()
ElseIf StateVariableB = 4 Then
EnterState6()
ElseIf StateVariableA = 3 Then
EnterState6()
End If
End Sub
Private Sub Lower_Threshold_exceed(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DataLogger.LowerThresholdExceeded
'Lower threshold exceeded event handler
If StateVariableA = 7 Then
EnterState6()
ElseIf StateVariableB = 4 Then
EnterState6()
ElseIf StateVariableA = 3 Then
EnterState6()
End If
End Sub
Private Sub Threshold_Normal() Handles Threshold.ThresholdOK
If StateVariableA = 6 Then
EnterState7()
If StateVariableA = 3 Then
EnterState7()
End If
End If
End Sub
End Class
Class ThresholdNormal
Inherits Screen1
Public Event ThresholdOK()
Public Sub CheckThreshold()
If Reading <= UpperThreshold And Reading >= LowerThreshold Then
RaiseEvent ThresholdOK()
End If
Label4.Text = Reading
Label4.Text = "hello"
End Sub
End Class