Search This Blog

2010/01/17

EVENT CREATION AND EVENT HANDLING:

Public Class WaterTank
Public Event WaterTank_OverFlowing(ByVal TankName As String)
Private size As Integer
Private MaxSize As Integer
Private TankName As String
Public Count As Integer

Public Sub OverFlowMessage(ByVal TankName As String)
MessageBox.Show("Tank is OverFlowing")
End Sub

Public Sub AddWater(ByVal x As Integer)
size = size + x
If (size > MaxSize) Then
'raise an event tank is overflowing
RaiseEvent WaterTank_OverFlowing(TankName)
End If
End Sub

Public Sub New()
size = 10000
Count = Count + 1
TankName = "WaterTank" & Count.ToString
AddHandler WaterTank_OverFlowing, AddressOf OverFlowMessage
End Sub

Public Sub New(ByVal name As String, ByVal Mxsize As Integer)
Count = Count + 1
TankName = name
MaxSize = Mxsize
AddHandler WaterTank_OverFlowing, AddressOf OverFlowMessage
End Sub


End Class

No comments:

Post a Comment