AddAdvise & Shape Added to Page detection

I

Irshad Ahmed

Hi
I am struggling with solving the AddAdvise method and
getting it to work for me to detect when a shape is added
to a page in Visio.
I need for the application to be a seprate program not VB
in Visio. Hance need to use the AddAdvise.
I need to detect this any time a shape is added.
I have ready referanced
Developing Microsoft Visio Solutions
Professional Delvelopment with Visio 2002
Visio 2002 Delveloper's Survival Pack
I think I am close but am still not getting the code to
work correctly.

The project is an Active X exe

The form (frmVisioMenu) which runs includes

Set g_Sink = New EventSink
Set eventsObj = visDoc.EventList

eventsObj.AddAdvise (visEvtShape + visEvtAdd),
g_Sink, "", "Shape Added.."

Their is a class module also which includes

Public Sub VisEventProc(eventCode As Integer, sourceObj As
Object, eventID As Long, _
seqNum As Long, subjectObj As
Object, moreInfo As Variant)

Dim strDumpMsg As String

Select Case eventCode

Case (visEvtAdd + visEvtShape)
strDumpMsg = "Shape Add(" & eventCode & ")"

Case Else
strDumpMsg = "Other(" & eventCode & ")"
End Select

frmVisioMenu.TextBox1.Text = strDumpMsg
------------------------------------------------
The program start off without problem, it creates an
instance of Visio and also loads a stecil (code not
shown), but when I add shapes I do not see those shapes
reported at all?

Will be very Thankful for insight.
 
C

Chris Roth [ Visio MVP ]

A common problem has to do with VB not handling the built in visEvtAdd
constant very well. Something to do with integer limits, I've never bothered
to learn it very well. In the help file, the sample code shows this:

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

make sure you have visEvtAdd re-defined somewhere that can be accessed by
all your modules.

But if this is your problem, you should be getting an overflow error
somewhere. Are you? Or do you have error trapping that is making this error
go unnoticed?

Also, are you missing the interface declarations? The example in the help
file shows the following, which is a bit different than what you have:

------------------------------------------------------
Implements Visio.IVisEventProc

'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 Else
strMessage = "Other (" & nEventCode & ")"
End Select

'Display the event name and the event code
Debug.Print strMessage

End Function

------------------------------------------------------
--

Hope this helps,

Chris Roth
Visio MVP
 
A

Al Edlund

Chris,
I've also been burned in this area with the &H8000 (the twit who chose that
as pointer should be shot). The reason for the problem is that adding to it
does not come up with a positive integer, but rather a negative integer
(since it is a negative value in vb). I found it was best to just code the
value directly (which is what you see in the vb.net examples).
Al
 
I

Irshad Ahmed

Thanks Chris,
With your input I now have the ability to know when a
shape is added.
Yep was not seeing error due to error trapping.
Regards Irshad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top