473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Creating events in VB.net



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
--
Jeffrey Spoon

Nov 21 '05 #1
4 1341
The class that generates the events is based upon inheriting Screen1, but
it's not clear from the listing what this is, if it over rides anything etc.

Can I suggest you stick a break points in on the line Public Sub
CheckThreshold()
and add a simple try catch block. Then step through the code to see if it
gets as far as RaiseEvent ThresholdOK()


"Jeffrey Spoon" <Je**********@hotmail.com> wrote in message
news:Tg**************@nowhere.nnn...


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
--
Jeffrey Spoon

Nov 21 '05 #2
In message <e4******************@newsfe5-win.ntli.net>, JohnFol
<Ou************@WibbleObbble.Com> writes
The class that generates the events is based upon inheriting Screen1, but
it's not clear from the listing what this is, if it over rides anything etc.

Can I suggest you stick a break points in on the line Public Sub
CheckThreshold()
and add a simple try catch block. Then step through the code to see if it
gets as far as RaiseEvent ThresholdOK()


Sorry, I chopped off the very top of the code:

Public Class Screen1
Inherits System.Windows.Forms.Form

It's just a default form, but I have another form which is empty at the
moment, which will be used eventually. All I have done for now is made
Screen1 the start-up object in project properties.

I will try what you suggested also. Thanks for the response.

--
Jeffrey Spoon

Nov 21 '05 #3
In message <e4******************@newsfe5-win.ntli.net>, JohnFol
<Ou************@WibbleObbble.Com> writes
The class that generates the events is based upon inheriting Screen1, but
it's not clear from the listing what this is, if it over rides anything etc.

Can I suggest you stick a break points in on the line Public Sub
CheckThreshold()
and add a simple try catch block. Then step through the code to see if it
gets as far as RaiseEvent ThresholdOK()

Ok I've done this. It is calling CheckThreshold each time but the event
is never raised because the Reading value is always 0 for some reason. I
have inherited Screen1 (where Reading resides) and it is protected so I
thought that would've worked. Also, the reading is displayed properly on
the form. Something else I don't understand is that the label4 variable
is being updated according to the debugger but it is not being updated
on the actual form.


--
Jeffrey Spoon

Nov 21 '05 #4
In message <e4******************@newsfe5-win.ntli.net>, JohnFol
<Ou************@WibbleObbble.Com> writes
The class that generates the events is based upon inheriting Screen1, but
it's not clear from the listing what this is, if it over rides anything etc.

Can I suggest you stick a break points in on the line Public Sub
CheckThreshold()
and add a simple try catch block. Then step through the code to see if it
gets as far as RaiseEvent ThresholdOK()


Ok, it must have been since Reading was updated within a sub procedure
when the ThresholdNormal class was inheriting the attributes it was just
using the default declaration as it wouldn't see the local assignment.
So now I pass the reading as a parameter to the CheckThreshold(Reading)
sub and it worked fine.

The only thing I'm not sure about is why label4 is not updated. I assume
this is because it is not set on the form Screen1 but in a separate
class. Is some sort of access required in the properties somewhere or
should it just be done within the associated form?

Thanks John (I'll probably be back here shortly with more problems,
you'll be happy to know...)


--
Jeffrey Spoon

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ben | last post by:
My current project requires me to create part of a form that is created on the fly. The project consists a list of entries to an event. The name and address and such is easy. The design is detup so...
16
by: tshad | last post by:
This is a little complicated to explain but I have some web services on a machine that work great. The problem is that I have run into a situation where I need to set up my program to access one...
1
by: skyson2ye | last post by:
Hi, guys: I have written a piece of code which utilizes Javascript in PHP to create a three level dynamic list box(Country, States/Province, Market). However, I have encountered a strange problem,...
1
by: Tony Johansson | last post by:
Hello! I'm reading in a book and here they says. "Now it is time to begin thinking about which events the control should provide. Because the control is derived from userControl class, it has...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.