Add method (EventList collection)

Microsoft Visio Developer Reference

Add method (EventList collection)

   Example   

Adds an Event object that runs an add-on when an event occurs. The Event object is added to the EventList collection of the source object whose events you want to receive.

Version added

4.1

Syntax

eventObj = object.Add (eventCode, visActCodeRunAddon, target, targetArgs)

eventObj

The new Event object added to the EventList collection.

object

Required. An expression that returns an EventList collection.

eventCode

Required Integer. The event(s) to capture.

target

Required String. The name of your add-on.

targetArgs

Required String. The string that is passed to your add-on.

Remarks

The source object whose EventList collection contains the Event object establishes the scope in which the events are reported. Events are reported for the source object and objects lower in the object model hierarchy. For example, to run an add-on when a particular document is opened, add an Event object for the DocumentOpened event to the EventList collection of that document. To run an add-on when any document is opened in an instance of the application, add the Event object to the EventList collection of the Application object.

Creating Event objects is a common way to handle events from C++ or other non–Microsoft Visual Basic solutions. Unlike events handled using the Visual Basic WithEvents keyword (all the events in a source object's event set fire), your program will only be notified of the events you select. Depending on your solution, this may result in improved performance.

Event objects that run add-ons can be persistent, that is, they can be stored with a Visio document. To be persistent, an Event object's Persistent and Persistable properties must both be True.

The arguments passed to the Add method set the initial values of the Event object's Event, Action (visCodeRunAddon), Target, and TargetArgs properties.

Event codes are declared by the Visio type library and have the prefix visEvt. Event codes are often a combination of constants. For example, visEvtAdd+visEvtDoc is the event code for the DocumentAdded event. To find an event code for the event you want to create, see Event codes.

To create an Event object that advises the caller's sink object about an event, see the AddAdvise method.