Hello Mike
In answer to the e-mail you send ( i like to keep it in the group so anyone
can benefit and / or join in the discussion )
here are 2 simple examples
Raiseevent option :
Public Class Form1
Private WithEvents account As New Account
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
account.DosomeC alcOnAccount()
End Sub
Private Sub account_eAccoun tLow(ByVal Amount As Decimal) Handles
account.eAccoun tLow
MsgBox("eAccoun tLow :Amount:" & Amount.ToString )
End Sub
Private Sub account_eAccoun tGotLowAmount(B yVal Amount As Decimal)
Handles account.eAccoun tGotLowAmount
MsgBox("eAccoun tGotLowAmount :Amount:" & Amount.ToString )
End Sub
End Class
Public Class Account
'option 1
Public Event eAccountLow(ByV al Amount As Decimal) 'ofcourse the event
arguments could be anything you like
Public Event eAccountGotLowA mount(ByVal Amount As Decimal)
Public Sub New()
'nothing needed here
End Sub
Public Sub DosomeCalcOnAcc ount()
'do some stuff in a sub routine
'dummy routine
Dim amount As Decimal = 1000
Do Until amount = 100
amount -= 1
Loop
'hey the account got low :-)
'simplest solution ( although i like the next example more as it
binds both events )
RaiseEvent eAccountLow(amo unt)
RaiseEvent eAccountGotLowA mount(amount)
End Sub
End Class
Private handler option :
Public Class Form1
Private WithEvents account As New Account
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
account.DosomeC alcOnAccount()
End Sub
Private Sub account_eAccoun tLow(ByVal Amount As Decimal) Handles
account.eAccoun tLow
MsgBox("eAccoun tLow :Amount:" & Amount.ToString )
End Sub
Private Sub account_eAccoun tGotLowAmount(B yVal Amount As Decimal)
Handles account.eAccoun tGotLowAmount
MsgBox("eAccoun tGotLowAmount notice that i am raised through the
clas`s handler :Amount:" & Amount.ToString )
End Sub
End Class
Public Class Account
'option 1
Public Event eAccountLow(ByV al Amount As Decimal) 'ofcourse the event
arguments could be anything you like
Public Event eAccountGotLowA mount(ByVal Amount As Decimal)
Public Sub New()
AddHandler eAccountLow, AddressOf sAccountGotLowA mount
End Sub
Private Sub sAccountGotLowA mount(ByVal Amount As Decimal)
RaiseEvent eAccountGotLowA mount(Amount)
End Sub
Public Sub DosomeCalcOnAcc ount()
'do some stuff in a sub routine
'dummy routine
Dim amount As Decimal = 1000
Do Until amount = 100
amount -= 1
Loop
'hey the account got low :-)
RaiseEvent eAccountLow(amo unt)
End Sub
End Class
when i tested this code it turned out that i was wrong in a previous
asumption
cause in the second example eAccountGotLowA mount is externally raised before
the event eAccountLow.
hth
Michel
"Mike" wrote:
Hi group;
Let say I have an object called Account, that raises an event called
AccountLow with its owns EventArgs, and when this event gets raised, I
will like to raise another custom event called AccountGotLowAm ount and
passes AccountLow’s EventArgs along with the new event.
How do I do this?