How to get information if an event is handled???

Christian B

Member
Joined
Aug 5, 2005
Messages
9
Programming Experience
3-5
Hi,

i am writing a class that is raising an event wich notifies about Alarms and Errors. The Problem is for Example:
VB.NET:
public event ErrorMessageAvailable(code as errorcode)

sub NotifyError()
     error = getError()
     if error then
          raiseevent ErrorMessageAvailable(error.Code)
[COLOR=Red]          'If ErrorMessageAvailable Event is not handled then
          'StoreError(Error)[/COLOR]
     end if
end sub

Has someone an idea how i can find the information (is the event handled)
that i need to complete the red-marked code fragment?

Thank you for reading

Christian B
 

To check whether an event has been handled, you can create an another argument in the ErrorMessageAvailable with a ByRef , e.g.
VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Event[/COLOR][/SIZE][SIZE=2] ErrorMessageAvailable([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] code [/SIZE][SIZE=2][COLOR=#0000ff]As er[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]rorcode[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByRef[/COLOR][/SIZE][SIZE=2] handled [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Boolean[/COLOR][/SIZE][SIZE=2])
[/SIZE]
and pass in a boolean variable:
VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] handled [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Boolean[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]RaiseEvent[/COLOR][/SIZE][SIZE=2] ErrorMessageAvailable(error.code, handled)
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Not[/COLOR][/SIZE][SIZE=2] handled [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'Do not handled stuff here
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE]
ByRef makes it so that if you alter the variable within the event handler, it remains altered after the event is called.
 
Thanks, this seems to be a good Idea!

I permanetly thought about solutions that the handling method will not recongize, but i didn't found something! Your idea will be a good alternative...

Christian B
 
Back
Top