Counting all connections leading to a shape

Started by o4sythe, February 19, 2015, 12:35:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wapperdude

The macro checks the color of both the connectors and the shapes.  It does this to avoid entering a shape more than once into the shape array, and to avoid multiple counting of any connector.  As such, closed loops will create an error,  some or every (???) time. 

The way the macro works is
  1. Start with selected shape, look at every connector
  2. Only examine connectors that meet the direction requirement, i.e., "m".
  3. Check the connector to see if it's been used before, if so, skip.
  4. Check the opposite end of the connector.
       A. If shape is the originating shape, ignore.  The connects connection always includes the originating shape.
       B. Check to see if the shape has already been used, i.e., its color, if so, ignore
       C. Everything OK, increment "j", the shape array index,redim the array, add new shape.
       D. Increment the connector count by one

Macro loops thru every connector, counts each new connector, adds shape to shape array, then loops thru the shape array until all shapes in the array, "k", have been checked.  It terminates when "k" exceeds "j".  A closed loop throws off the, "j", "k" relationship.

It's a simple macro, not anticipating existence of loops.  Some special conditional requirements are needed...
   1. Allow original shape, possibly
   2. Allow double counting of shape, but not re-add to the array, otherwise, end up with endless, repeating loop.

I would recommend making a simple, 3 shape loop, step thru program, see where/why it breaks, then establish some conditional test to allow that scenario.

Since I'm not in front of my computer, the order of the steps may not be quite right....disclaimer!!! 
Visio 2019 Pro

wapperdude

Well, the closed loop condition turned out to be simple change. So, the code should run, it did for my quick test, attached.  Also, doesn't fail for connectors with less than 2 connections.

Sheet.7 is the shape that would initiate closed loop response.

Wapperdude
Visio 2019 Pro

o4sythe

Perfect. Enough said!

Thank you very much wapperdude, you're such a great help :-)

wapperdude

Probably a closed topic, but, there was one feature I didn't like...having to edit the macro to change the connection type from incoming or outgoing.  So, here's an update that pops up a non-modal UserForm.  The form reminds you to select a shape, which can be done without having to close the form.  It also gives you 3 direction options:  incoming, outgoing, or both.  The direct connects are in one color and the indirect connects are in a 2nd color.

If nothing else, it's easier and more fun to use!   :o

Wapperdude
Visio 2019 Pro