Connections.Count Bug??? Visio 2000

C

Corey McCord

When counting a shapes connections it seems to give me conflicting numbers.

If I connect just plain connectors to a shape the count seems to be correct.
But if I connect a "Shape" with a connector it seem to count each "Shape"
twice???

This makes the Connections.Count function kinda useless without writing it's
own function to remove duplicates.

The thing that really makes it strange is the actual "ID" of the shapes
collected from the count are matching so I'm having a hard time figuring out
what exactly it's doing that's what leads me to believe that this is a bug.

Any help would be great.

Corey
 
H

Hadriel

I'm not clear what your doing differently in the case it counts once vs.
twice (your description sounds the same to me), but I use VBA to glue shapes
and use the count function a lot in Visio 2000 and it works fine for me. I
assume the count you're referring to is of the shape's connects collection,
which counts the number of connect objects in the collection.
Maybe if you paste some of the code it would clear it up.
 
C

Corey McCord

Nothing fancy about the code to show what I mean.

First make a Box, this is my first shape. Place and "Inward" connector on
each side.

Now make a couple smaller boxes with an "Outward" connector on it.

ThisDocument Code;

Dim VisEvent As New VisioEvents
Option Explicit
Sub InitializeDrawing()
Set VisEvent.ConnectorsPage = Visio.ActivePage
End Sub
Private Sub Document_DesignModeEntered(ByVal doc As Visio.IVDocument)
Set VisEvent = Nothing
End Sub
Private Sub Document_RunModeEntered(ByVal doc As Visio.IVDocument)
Call InitializeDrawing
End Sub

VisioEvents Code;

Public WithEvents ConnectorsPage As Visio.Page
Public tmpVal As Variant

Private Sub ConnectorsPage_ConnectionsAdded(ByVal Connects As
Visio.IVConnects)


MsgBox Connects.ToSheet.FromConnects.Count

For Each tmpVal In Connects.ToSheet.FromConnects

MsgBox tmpVal

Next tmpVal

End Sub

Now drag one of the smaller boxes to a connection point on the larger shape.

First msgbox will be 2.

Then the For Each will msgbox the smaller box twice.

Again, this might be what it's supposed to do but it dosen't make sense to
me.

Corey
 
H

Hadriel

For me it shows just one connection when the page has only one connection
(when the first small box is added to the big one) and 2 connections when the
second small box is added as well. But that makes sense since the connects
collection passed by the event is the collection of all the connect objects
of the page. Maybe you're expecting the connects collection to only contain
the ones just added? But that wouldn't explain why you got the same shape
names twice. Hmm. weird.
Maybe you should try just getting the connects collection of the page
directly in the procedure for the connectionsadded event, instead of using
the passed IVConnects collection, and msgbox that - just to verify the page
really has two connect objects for the shapes. Another debug thing to try is
getting the connects collection for the shape (instead of page) and see what
that count reports. I tried this in Visio 2000 SR-1 (build 2072), by the way.
-hadriel
 
C

Corey McCord

You get these results using the exact code that I just used?

Now I'm really confused.

Because the code I used does get the collection from the shape
(FromConnects).

Corey
 
H

Hadriel

Oops - sorry, yes the same exact code - wasn't paying attention to which
object's connect object you were referencing. Right, so I only get a count
of 1 and only one shape name shows up once. (and it does appear that the
connects collection passed back is only the added ones, so disregard that
comment)
Maybe another debug idea is to just write a very simple separate module
procedure for checking the connect objects of a selected shape, so you can
just call it as a macro after selecting the shape that's causing you problems
to verify there really are 2 connect objects for that shape. Below is a
procedure I use to check connections, which I copied from someone else
(Microsoft probably) - it shows both from and to connections, it only checks
it for the first selected shape, and may not be the fastest/cleanest method
but for debug purposes its fine i think:

Public Sub ListConnections()

Dim shpsObj As Visio.Shapes
Dim shpObj As Visio.Shape
Dim fromObj As Visio.Shape
Dim fromData As Integer
Dim fromStr As String
Dim toObj As Visio.Shape
Dim toData As Integer
Dim toStr As String
Dim consObj As Visio.Connects
Dim frmconsObj As Visio.Connects
Dim conObj As Visio.Connect
Dim frmconObj As Visio.Connect
Dim curShapeIX As Integer
Dim I As Integer
Dim selectObj As Visio.Selection

Set selectObj = ActiveWindow.Selection
Set shpObj = selectObj.Item(1)
Set shpsObj = shpObj.Shapes

For curShapeIX = 0 To shpsObj.Count
If curShapeIX > 0 Then
Set shpObj = shpsObj.Item(curShapeIX)
End If
Set consObj = shpObj.Connects

'get info for connects to shapes
For I = 1 To consObj.Count
Set conObj = consObj(I)
Set fromObj = conObj.FromSheet
fromData = conObj.FromPart
Set toObj = conObj.ToSheet
toData = conObj.ToPart

'FromPart property values
If fromData = visConnectError Then
fromStr = "error"
ElseIf fromData = visNone Then
fromStr = "none"
ElseIf fromData = visLeftEdge Then
fromStr = "left"
ElseIf fromData = visCenterEdge Then
fromStr = "center"
ElseIf fromData = visRightEdge Then
fromStr = "right"
ElseIf fromData = visBottomEdge Then
fromStr = "bottom"
ElseIf fromData = visMiddleEdge Then
fromStr = "middle"
ElseIf fromData = visTopEdge Then
fromStr = "top"
ElseIf fromData = visBeginX Then
fromStr = "beginX"
ElseIf fromData = visBeginY Then
fromStr = "beginY"
ElseIf fromData = visBegin Then
fromStr = "begin"
ElseIf fromData = visEndX Then
fromStr = "endX"
ElseIf fromData = visEndY Then
fromStr = "endY"
ElseIf fromData = visEnd Then
fromStr = "end"
ElseIf fromData >= visControlPoint Then
fromStr = "controlPt_" & _
Str(fromData - visControlPoint + 1)
Else
fromStr = fromData
End If

If toData = visConnectError Then
toStr = "error"
ElseIf toData = visNone Then
toStr = "none"
ElseIf toData = visGuideX Then
toStr = "guideX"
ElseIf toData = visGuideY Then
toStr = "guideY"
ElseIf toData >= visConnectionPoint Then
toStr = "connectPt_" & _
CStr(toData - visConnectionPoint + 1)
Else
toStr = toData
End If

MsgBox (shpObj.Name & ": Connected to another shape from " & _
fromObj.Name & " " & fromStr & " to " & toObj.Name & " " &
toStr & ".")
Next I

'get info for connects from shapes
Set frmconsObj = shpObj.FromConnects
For I = 1 To frmconsObj.Count
Set frmconObj = frmconsObj(I)
Set fromObj = frmconObj.FromSheet
fromData = frmconObj.FromPart
Set toObj = frmconObj.ToSheet
toData = frmconObj.ToPart

'FromPart property values
If fromData = visConnectError Then
fromStr = "error"
ElseIf fromData = visNone Then
fromStr = "none"
ElseIf fromData = visLeftEdge Then
fromStr = "left"
ElseIf fromData = visCenterEdge Then
fromStr = "center"
ElseIf fromData = visRightEdge Then
fromStr = "right"
ElseIf fromData = visBottomEdge Then
fromStr = "bottom"
ElseIf fromData = visMiddleEdge Then
fromStr = "middle"
ElseIf fromData = visTopEdge Then
fromStr = "top"
ElseIf fromData = visBeginX Then
fromStr = "beginX"
ElseIf fromData = visBeginY Then
fromStr = "beginY"
ElseIf fromData = visBegin Then
fromStr = "begin"
ElseIf fromData = visEndX Then
fromStr = "endX"
ElseIf fromData = visEndY Then
fromStr = "endY"
ElseIf fromData = visEnd Then
fromStr = "end"
ElseIf fromData >= visControlPoint Then
fromStr = "controlPt_" & _
Str(fromData - visControlPoint + 1)
Else
fromStr = fromData
End If

If toData = visConnectError Then
toStr = "error"
ElseIf toData = visNone Then
toStr = "none"
ElseIf toData = visGuideX Then
toStr = "guideX"
ElseIf toData = visGuideY Then
toStr = "guideY"
ElseIf toData >= visConnectionPoint Then
toStr = "connectPt_" & _
CStr(toData - visConnectionPoint + 1)
Else
toStr = toData
End If

MsgBox (shpObj.Name & ": Connected from another shape from " & _
fromObj.Name & " " & fromStr & " to " & toObj.Name & " " &
toStr & ".")
Next I

Next curShapeIX
End Sub



-hadriel
 
C

Corey McCord

I'm not connecting the shapes with a connector line...

I'm talking about connecting the shape to the shape directly. You get the
same results?

I think I know what it's doing... I just don't get why they did it this way.
Looks like they never thouht you would connect a shape directly to a shape.
It looks like it counts the connector on the base shape along with the
connector on the attaching shape.

Corey
 
H

Hadriel

Ahh, reproduced it. I wasn't using a connector either, but I was using a
master shape (the rectangle from the basic shapes stencli) as the one being
connected to, and that worked fine. But then I tried using a hand-drawn
rectangle with connection points I got the double instance. Also I noticed
when connecting the smaller boxes to it that it calls the connection event
twice. (which makes sense i guess, since there really are two connections
being made) I assume this is because the hand-drawn shapes are connecting
both the pinx/piny and the angle cells to the shape, vs. when they connect to
the stencil's shape only the pinx/piny cells connect? A connector only
connects begin or end cells as well (not angle). I bet Graham Wideman's book
covers this but I don't have it with me right now.
Another thing I noticed is that only one of the duplicate connect objects is
to a connection point (the toPart is higher than 100), as is the case for
when it's not duplicated, so you could just check for that to find a singular
connect object you want and get around this.
-hadriel
 
H

Hadriel

By the way it's not a bug - it's by design. The 2002 SDK says about gluing:
"From an outward or inward/outward connection point cell of a 2-D shape to…
An inward or inward/outward type connection point cell that is not a cell of
a guide or guide point: If the outward connection point has a direction, then
two connection points are created—one from the Angle cell to the
Connections.Xi cell and the other from the PinX cell to the Connections.Yi
cell."
That also explained why it didn't happen for the rectangle stencil shape I
dropped, because it doesn't have a direction for its connection points by
default. Once I set their direction it, too, made two connections. And when
I removed the hand-drawn shapes connection directions, it only created a
single connection.
-hadriel
 

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