Learning examples of using AddAdvise and QUEUEMARKEREVENT in VBA

Started by Visisthebest, August 26, 2020, 11:13:00 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visisthebest

Are there any learning examples that demonstrate the use of AddAdvise and/or QUEUEMARKEREVENTs in VBA? These are not easy topics (at least for me) so examples that one can tinker with are really useful for learning how to use these for Visio event handling.


Based on this excellent advice from John Goldsmith on how to write a VBA-based Visio solution that can be ported to a VSTO add-in later with fewer changes:

Events - if you might be targeting C# later on then you should avoid declaring events using the WithEvents keyword, which is a VB only construct.  The ideal is to go for AddAdvise with and event sink class which is more work but also more efficient.  Another consideration for events is what changes will be need to be made to calls from the ShapeSheet to your code.  With VBA you might want to use the CALLTHIS function but this won't work for addins.  An alternative to consider might be the use of the QUEUEMARKEREVENT function to raise....QueueMarker events.  Here you would raise an event from the ShapeSheet that could be interpreted by both VBA and an addin.  It would have the benefit of potentially later being able to  swap in a new non-code stencil and existing legacy  documents would continue to function as before (at least in terms of event firing).  MarkerEvents aren't the solution to everything so you'd want to weigh the benefits or otherwise of using them against the task of 'converting' existing documents later on.

Visio 2021 Professional

Croc

Microsoft Visio 2013 SDK contains Microsoft Visio 2013 SDK Samples including Microsoft Visio Code Samples Library for Visual Basic. You can see all the necessary examples in the Event Handling section.

Nikolay

I think if you plan to rewrite VBA code to C# then event syntax is the least of your problems.
It's such a tiny piece that you well may forget about it. It's just one line change.

Basically, instead of "WithEvents" you just use "+=", and that's it.

If you want to run C# code from ShapeSheet directly (why?), then yes, you are right, the QUEUEMARKEREVENT is the way to go.

I think it's pretty much documented in the official manual:
https://docs.microsoft.com/en-us/office/vba/api/visio.application.markerevent

Visisthebest

Probably convert to VB.NET writing the code so minimal changes are needed, so no variants and following John Goldsmith's tips here:

http://visguy.com/vgforum/index.php?topic=8612.msg37746#msg37746

Will need to change the Type label of UDT's to Structure and I keep in mind Integers in VB.NET are 4 bytes etc.

Any additional tips much appreciated!
Visio 2021 Professional

Nikolay

I would simply re-write everything from scratch. To my experience, this is the fastest way ;D