Can anyone tell me what the major difference is between creating a Event -vs- a Sub? I'm kinda confused on custom events and when to use them?
Printable View
Can anyone tell me what the major difference is between creating a Event -vs- a Sub? I'm kinda confused on custom events and when to use them?
Events are used when objects need to notify a client that something of importance is happening. For instance, with a car object, you would want to raise an event when the car is overheating, thus you would create a 'Overheating' event, and raise this when appropriate.
Subs (methods in oop terms) are routines that perform some type of action (behavior) and can either return a value or not. For instance, the car object would have a TurnLeft() method that would handle the action associated with the car turning left.
I think the biggest difference is who initiates them. An event is initiated by the object itself whereas a method (sub) is initiated outside of the object.
Using the car example the car is the one that calls the overheating event, where as another object is the one that would call the FillGas method.
Well said...:D
Hmm, Ok thanks, still a bit of confusion but I'll figure it out :)