EVENT Using ADDADVISE

Started by mmulvenna, January 25, 2009, 12:40:19 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

mmulvenna

I am probably being really dense here and i suspect i am missing someting pretty simple but....I have the following code in my application. It is copied from the SDK but the one event I added does not even compile.
I get a runtime error   ...exception occured" when it gets to this line  Set vsoScopeEnteredEvent = vsoDocumentEvents.AddAdvise( _
     visEvtCodeEnterScope, mEventSink, "", "Enter Scope...")


I want to trap when an item is added to a group so i thought i could use the scope entered event to do this.The above line is the only one I added. Are there additional parameters that i need to provide to visevtcodeenterscope

This code is in a class module.
Implements Visio.IVisEventProc


Thanks in advance for any help
Mike

'Declare visEvtAdd as a 2-byte value
'to avoid a run-time overflow error
Private Const visEvtAdd% = &H8000

Private Function IVisEventProc_VisEventProc( _
        ByVal nEventCode As Integer, _
        ByVal pSourceObj As Object, _
        ByVal nEventID As Long, _
        ByVal nEventSeqNum As Long, _
        ByVal pSubjectObj As Object, _
        ByVal vMoreInfo As Variant) As Variant

    Dim strMessage As String


    'Find out which event fired
    Select Case nEventCode
        Case visEvtCodeDocSave
            strMessage = "DocumentSaved (" & nEventCode & ")"
        Case (visEvtPage + visEvtAdd)
            strMessage = "PageAdded (" & nEventCode & ")"
        Case visEvtCodeShapeDelete
            strMessage = "ShapesDeleted(" & nEventCode & ")"
         Case visEvtCodeEnterScope
         strMessage = "enterscope(" & nEventCode & ")"
        Case Else
            strMessage = "Other (" & nEventCode & ")"
    End Select


    'Display the event name and the event code
    MsgBox strMessage

End Function


This code is in a module.
Option Explicit

Private mEventSink As clsEventSink

Dim vsoDocumentEvents As Visio.EventList
Dim vsoDocumentSavedEvent As Visio.Event
Dim vsoPageAddedEvent As Visio.Event
Dim vsoShapesDeletedEvent As Visio.Event
Dim vsoScopeEnteredEvent As Visio.Event

   
'Declare visEvtAdd as a 2-byte value
'to avoid a run-time overflow error
Private Const visEvtAdd% = &H8000

Public Sub CreateEventObjects()
    'Create an instance of the clsEventSink class
    'to pass to the AddAdvise method.
    Set mEventSink = New clsEventSink

    'Get the EventList collection of the active document.
    Set vsoDocumentEvents = ActiveDocument.EventList

    'Add Event objects that will send notifications.
    'Add an Event object for the DocumentSaved event.
    Set vsoDocumentSavedEvent = vsoDocumentEvents.AddAdvise( _
     visEvtCodeDocSave, mEventSink, "", "Document saved...")

    'Add an Event object for the PageAdded event.
    Set vsoPageAddedEvent = vsoDocumentEvents.AddAdvise( _
     visEvtAdd + visEvtPage, mEventSink, "", "Page added...")
     'Add an Event object for the ShapesDeleted event.
    Set vsoShapesDeletedEvent = vsoDocumentEvents.AddAdvise( _
     visEvtCodeShapeDelete, mEventSink, "", "Shapes deleted...")
   Set vsoScopeEnteredEvent = vsoDocumentEvents.AddAdvise( _
     visEvtCodeEnterScope, mEventSink, "", "Enter Scope...")
End Sub