MS at it again
-
Hi all. Sorry for the frustration here, but I always dread going to MS for any kind of help anymore, regarding what this-or-that does. For years now, they are extremely spotty in their ability to describe something simply and unambiguously. Below is a perfect example; a paragraph which talks in circles: "The WithEvents statement and the Handles clause provide a declarative way of specifying event handlers. An event raised by an object declared with the WithEvents keyword can be handled by any procedure with a Handles statement for that event, as shown in the following example:" Sounds like lawyer talk, so whenever I run into lawyer talk, I try to reword it into an explicit example. So here goes. "A button's mouse click event raised by a button, declared with the WithEvents keyword can be handled by any procedure with a Handles statement for the button mouse click event..." That's like saying "A box with a lid, has a lid on it." It seems to be saying that if I use the WithEvents keyword, I can attach, for example, the statement, "Handles Button3.Click" on to ANY procedure and the procedure will respond to the Button3.Click event. Well...Duh! I can do that withOUT the WithEvents keyword! So what is the difference? Or did they MEAN to say, "A user can declare a custom event with the WithEvents keyword. Then, any procedure can use that event just like any other event, by attaching it at the end of a procedure's declaration, with the "Handles" clause." If so, why use the keyword "WithEvents at all? Why not just,
Public Event MyCustomEvent
'Description of event goes here.
End EventOR, are they trying to say this, 'Using the WithEvents keyword, a class is declared that can contain multiple events, any of which can be used at the end of a procedure's declaration with the "Handles" clause. For example,
'Declare a new collection of events:
Dim WithEvents MyEventsCollection As New EventsCollection1'Create the class, declared above:
Class EventsCollection1
Public Event My1stEvent()
Public Event My2ndEvent()
End Class'Then, any procedure can have a Handles clause at the end of it, which assigns any of the events in the collection,
Private Sub ThisProcedure() Handles EventsCollection1.My1stEvent
'...Do stuff.
End SubIf THAT is what they mean, why put all of those events in a collection (a Class), instead of just calling them all out in
-
Hi all. Sorry for the frustration here, but I always dread going to MS for any kind of help anymore, regarding what this-or-that does. For years now, they are extremely spotty in their ability to describe something simply and unambiguously. Below is a perfect example; a paragraph which talks in circles: "The WithEvents statement and the Handles clause provide a declarative way of specifying event handlers. An event raised by an object declared with the WithEvents keyword can be handled by any procedure with a Handles statement for that event, as shown in the following example:" Sounds like lawyer talk, so whenever I run into lawyer talk, I try to reword it into an explicit example. So here goes. "A button's mouse click event raised by a button, declared with the WithEvents keyword can be handled by any procedure with a Handles statement for the button mouse click event..." That's like saying "A box with a lid, has a lid on it." It seems to be saying that if I use the WithEvents keyword, I can attach, for example, the statement, "Handles Button3.Click" on to ANY procedure and the procedure will respond to the Button3.Click event. Well...Duh! I can do that withOUT the WithEvents keyword! So what is the difference? Or did they MEAN to say, "A user can declare a custom event with the WithEvents keyword. Then, any procedure can use that event just like any other event, by attaching it at the end of a procedure's declaration, with the "Handles" clause." If so, why use the keyword "WithEvents at all? Why not just,
Public Event MyCustomEvent
'Description of event goes here.
End EventOR, are they trying to say this, 'Using the WithEvents keyword, a class is declared that can contain multiple events, any of which can be used at the end of a procedure's declaration with the "Handles" clause. For example,
'Declare a new collection of events:
Dim WithEvents MyEventsCollection As New EventsCollection1'Create the class, declared above:
Class EventsCollection1
Public Event My1stEvent()
Public Event My2ndEvent()
End Class'Then, any procedure can have a Handles clause at the end of it, which assigns any of the events in the collection,
Private Sub ThisProcedure() Handles EventsCollection1.My1stEvent
'...Do stuff.
End SubIf THAT is what they mean, why put all of those events in a collection (a Class), instead of just calling them all out in
-
Hi all. Sorry for the frustration here, but I always dread going to MS for any kind of help anymore, regarding what this-or-that does. For years now, they are extremely spotty in their ability to describe something simply and unambiguously. Below is a perfect example; a paragraph which talks in circles: "The WithEvents statement and the Handles clause provide a declarative way of specifying event handlers. An event raised by an object declared with the WithEvents keyword can be handled by any procedure with a Handles statement for that event, as shown in the following example:" Sounds like lawyer talk, so whenever I run into lawyer talk, I try to reword it into an explicit example. So here goes. "A button's mouse click event raised by a button, declared with the WithEvents keyword can be handled by any procedure with a Handles statement for the button mouse click event..." That's like saying "A box with a lid, has a lid on it." It seems to be saying that if I use the WithEvents keyword, I can attach, for example, the statement, "Handles Button3.Click" on to ANY procedure and the procedure will respond to the Button3.Click event. Well...Duh! I can do that withOUT the WithEvents keyword! So what is the difference? Or did they MEAN to say, "A user can declare a custom event with the WithEvents keyword. Then, any procedure can use that event just like any other event, by attaching it at the end of a procedure's declaration, with the "Handles" clause." If so, why use the keyword "WithEvents at all? Why not just,
Public Event MyCustomEvent
'Description of event goes here.
End EventOR, are they trying to say this, 'Using the WithEvents keyword, a class is declared that can contain multiple events, any of which can be used at the end of a procedure's declaration with the "Handles" clause. For example,
'Declare a new collection of events:
Dim WithEvents MyEventsCollection As New EventsCollection1'Create the class, declared above:
Class EventsCollection1
Public Event My1stEvent()
Public Event My2ndEvent()
End Class'Then, any procedure can have a Handles clause at the end of it, which assigns any of the events in the collection,
Private Sub ThisProcedure() Handles EventsCollection1.My1stEvent
'...Do stuff.
End SubIf THAT is what they mean, why put all of those events in a collection (a Class), instead of just calling them all out in
Try reading this old article on MSDN.[^] Truthfully, I haven't used WithEvents for anything in about 10 years. I found that I prefer to wire up the events I need myself instead of relying on Handles.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
-
Try reading this old article on MSDN.[^] Truthfully, I haven't used WithEvents for anything in about 10 years. I found that I prefer to wire up the events I need myself instead of relying on Handles.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak