Moving a dynamic connector and calling a subroutine

Started by beejay, April 27, 2017, 07:34:15 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

beejay

Hi all,

First post, so be gentle  ;)

I've searched this forum, and Google generally, but no luck so far.

Visio 2013, Windows 7 Enterprise (and yes, the Enterprise bit means I cannot load any extra tools to assist me - what is on the PC is what I get)

I'm trying to update some user data fields in a dynamic connector, based on the shape connected to the end (but not the beginning) of the connector.

I have some VBA that is called when the EndTrigger cell on the connector changes. the connector has the following User defined cells

User.Row_1 =EndTrigger+CALLTHIS("UpdateConn")
User.Row_2 =BegTrigger

I have reduced the VBA to the absolute minimum to show my problem
Option Explicit

Public Sub UpdateConn(vsoShape As Visio.Shape)

Debug.Print Now & " " & vsoShape.Name

Debug.Print Now & " Start trigger value: " & vsoShape.Cells("User.Row_2")
Debug.Print Now & " End trigger value: " & vsoShape.Cells("User.Row_1")

End Sub


I expected (wrongly) that if I move the beginning of the connector the routine would not run, if I move the end of the connector it should run once.
In fact it always runs at least once, and up to three times for a single move. the results appear quite consistent.

Rather than list every combination of movements, I will give a couple of examples.

  • connector not connected to other shape at either end, move the whole connector but do not glue either end to anything. Debug output shows:

    27/04/2017 16:41:23 Dynamic connector
    27/04/2017 16:41:23 Start trigger value: 1
    27/04/2017 16:41:23 End trigger value: 1
    27/04/2017 16:41:23 Dynamic connector
    27/04/2017 16:41:23 Start trigger value: 1
    27/04/2017 16:41:23 End trigger value: 1
    Didn't expect it to run at all, but it ran twice?

  • Connector beginning not connected to anything. Connector end not glued to shape, move it so it is now glued to a shape. Debug output shows:

    27/04/2017 16:49:51 Dynamic connector
    27/04/2017 16:49:51 Start trigger value: 1
    27/04/2017 16:49:51 End trigger value: 2
    That was what I expected

  • Connector beginning not connected to anything. Connector end glued to shape, move it so it is no longer glued. Debug output shows:

    27/04/2017 16:50:28 Dynamic connector
    27/04/2017 16:50:28 Start trigger value: 1
    27/04/2017 16:50:28 End trigger value: 1
    27/04/2017 16:50:28 Dynamic connector
    27/04/2017 16:50:28 Start trigger value: 1
    27/04/2017 16:50:28 End trigger value: 1
    27/04/2017 16:50:28 Dynamic connector
    27/04/2017 16:50:28 Start trigger value: 1
    27/04/2017 16:50:28 End trigger value: 1
    Ran 3 times, I expected once??


This simplistic example seems to give consistent (but wrong?) results. My original code did a lot more, and occasionally ran repeatedly (as in never stopped, had to kill Visio).

I hope someone can shed some light on this (to me) weirdness.

Thanks in advance for any suggestions
BrianJ

wapperdude

Visio 2019 Pro

beejay

Hi Wapperdude,

That article was partly the inspiration that pushed me to try this technique. But given that David is setting some data associated with the shapes, I don't believe that you would notice if the code was triggered multiple times.

In my case I was also showing a message box describing the changes that were made to the shape data when the connector was glued to another shape - and this box appears one or more times, indicating the routine is being triggered one or more times. On a couple of occasions, it descended into the pathologically bad case of continually retriggering - giving me an endless set of message boxes to acknowledge - all without changing the code  ???

That prompted me to simplify my code down to the few lines I originally posted - which show the issue.

I am completely puzzled

Thanks
BrianJ

wapperdude

QuoteUser.Row_1 =EndTrigger+CALLTHIS("UpdateConn")

This construct is not conditional nor is it tied to a specific event.  "EndTrigger" is a value, not an event.  I would suspect the add-in connector code updates the EndTrigger value multiple times as the end is dragged about. You might try using an "IF" statement if all you're interested in is when gluing occurs.  Something like =If( EndTrigger=2, Callthis(whatever),""). Whatever being out subroutine.

Perhaps if you outlined what your trying to do, the Forum can offer some suggestions.

Wapperdude
Visio 2019 Pro