Testing row type, before their are any rows (ConnectionPts)

Started by dbramblett, May 15, 2024, 02:10:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


@Nikolay:  you're only half wrong  ??? , and I'm only half right  :o

Your last example reminded me of the problem.  My code came from an older post, and I forgot about this issue.  You are using "visTagCnnctPt".  This does indeed replicate the problem.  I am using "visTagCnnctNamedABCD" and has no issue.

Note, using "visTagCnnctNamed" without the ABCD is also fine.
Note 2, using zero, 0, instead of visTag..., also works.  Interestingly, you get named rows, but the D-cell remains inactive.

Conclusion:  the issue is associated with using "visTagConntPt".  There are other options that work fine.
Visio 2019 Pro


The situation is symmetrical. Meaning, the problem happens when the "type" of the "connection points" section is mismatching the type of the "row" you are adding to it. This is the issue the topic starter is trying to solve, as far as I understand (in his first post). Meaning (as an example):

Adding "visTagCnnctNamedABCD" or "visTagCnnctNamed" will not work if you try to add that to the "CP1.vsd" file from the post above (but will work for CP2.vsd)

Adding "visTagCnnctPt" or "visTagCnnctPtABCD" will not work if you try to add that to the "CP2.vsd" file from the post above (but will work for CP1.vsd)

Here is a table that clarifies it:

          visTagCnnctPt,      visTagCnnctNamed,
File      visTagCnnctPtABCD    visTagCnnctNamedABCD
CP1.vsd    YES                  NO
CP2.vsd    NO                  YES

The steps to try to do that are simple:

1. Download files CP1.vsd, CP2.vsd
2. Open the file CP1.vsd (or CP2.vsd)
3. Open VBA IDE, and in the "Immediate" window, type:
ActivePage.Shapes(1).AddRow visSectionConnectionPts, 0, visTagCnnctPtthen hit enter.

You can vary the "visTagCnnctPt" with the other options (visTagCnnctNamed, visTagCnnctPtABCD, visTagCnnctNamedABCD) to see if you get an error message or not.

Here is a video to clarify:


Clearly we're not on same page.  I tried to follow the video, but couldn't quite understand it.

I took the CP1 and CP2 files, copied my code from reply #11.  Code ran fine for both files.  Added 3 connPts both files.  No errors.   Note, the code syntax "shape.addrow" does NOT like any visTagCnnct entry.  Only a "0".  It is the "shape.addnamedrow" that accepts the visTag entries, except not the visTagCnnctPt.

I'm not seeing your objection.  I don't understand why you haven't tried the code.  I don't understand why you haven't tried the sample file that I provided.  The one caveat is that you start with a shape that has no connection points...like your 2 CP files do.  So, if you run the code once, you need to go back into shapesheet and delete the connection points before running the code again.  If you don't, you get extra connection point added to shape.  But, code kinda runs => produces exception error.

While not necessary, I would tile the drawing window and shapesheet window as your files do, plus the code window so that all 3 are easily visible.  Then, step thru the code using <F8> to execute code 1 line at a time.  You will see that for row1, it is 1st unnamed.  Then deleted.  Then named, as progression thru code continues.  Row2 starts by setting it to named.  Deleted.  Then unnamed.  As it always appears to be a named row, due to row1, the point of the 2nd row is to show that the code does execute in reverse order.  Row3 is a simple addition that takes place after the above 2.

It is then easy enough to modify the code, specifically, change the visTagCnncts entry.  visTagCnnctsPt fails.  Replacing the entry with "0" (no quotes) works too.

It is a simple test.  Do me the courtesy to try it.  I tried yours.  The visTagCnnctPt produced an error everytime.  On that we agree.
Visio 2019 Pro


The first step to solve the problem is to understand it :D
Meaning, to reproduce the issue. That's what I was trying to show - to explain the issue, not to solve it.

Did you try to follow the steps form the above post?
I mean, 1, 2, 3


Yes.  I ran steps 1 - 3, both files.  Re-ran again, just a bit ago.  I get different results from those posted in response #16 posted by Nikolay.
I ran code below, with only 1st line active.  It runs fine for both CP1 and CP2 files.  Then, close Visio, no saving.  Reload each CP file.
Re-run code with just 2nd line active.  Runs fine in both CP1 and CP2 files.  No errors.  Two configuration differences:  1st, I'm running from code window, not immediate window.  The other difference is that I had to save the CP files as vsdm in order to run code.  So, not using vsd files directly.

Here's the code:
Sub Nik()
    ActivePage.Shapes(1).AddRow visSectionConnectionPts, 0, visTagCnnctPt
'    ActivePage.Shapes(1).AddNamedRow visSectionConnectionPts, "P0", visTagCnnctNamed
End Sub
Visio 2019 Pro


Follow-up to last above entry, I decided to simplify my code that adds multiple connection points. The code adds 3 rows in this order:  unnamed, named, unnamed.  It was run on both CP1 and CP2 files.  The addrow syntax used is as follows:
> Unnamed:        vsoShp.AddRow visSectionConnectionPts, iRow, visTagCnnctPt
> Named:            vsoShp.AddNamedRow visSectionConnectionPts, "P" & iRow + 1, visTagCnnctNamed
        where iRow is the row index counter

The anticipated result would be error after 1st row attempted addition as indicated by OP.
More likely scenarios would be error after 2nd or 3rd attempts as each would have a preceding, existing different row type.

What was observed, 1st and 2nd row additions always worked for either CP file.  The 3rd row addition generated the error both files.  This was easily corrected with simple change.  In the 3rd row, syntax change to replace visTagCnnctPt with the number 0.  With that change, the code runs with no errors and all 3 connection points are successfully added.

Background:  VisioPro 2019, Win11 64B, CP1.vsdm, CP2.vsdm

The revised code:
Sub ConnPts()
' This macro explores adding connection points to a shape programmitically.
' It is not necessary to add the Connection Point section prior to adding rows.
' This code presumes there are no pre-existing connection points.

' Using visTagCnnctPt seems to cause grief.

    Dim vsoShp As Visio.Shape
    Dim iRow As Integer
    Dim vsoRow As Visio.Row

    iRow = 0
    For Each vsoShp In ActivePage.Shapes
        vsoShp.AddRow visSectionConnectionPts, iRow, visTagCnnctPt
        Set vsoRow = vsoShp.Section(visSectionConnectionPts).Row(iRow)
        With vsoRow
            .Cell(visCnnctX).FormulaU = "Width*0"
            .Cell(visCnnctY).FormulaU = "Height*0.5"
        End With
        vsoShp.AddNamedRow visSectionConnectionPts, "P" & iRow + 1, visTagCnnctNamed
        Set vsoRow = vsoShp.Section(visSectionConnectionPts).Row(iRow + 1)
        With vsoRow
            .Cell(visCnnctX).FormulaU = "Width*1"
            .Cell(visCnnctY).FormulaU = "Height*0.5"
        End With
'        vsoShp.AddRow visSectionConnectionPts, iRow + 2, visTagCnnctPt
        vsoShp.AddRow visSectionConnectionPts, iRow + 2, 0
        Set vsoRow = vsoShp.Section(visSectionConnectionPts).Row(iRow + 2)
        With vsoRow
            .Cell(visCnnctX).FormulaU = "Width*0.5"
            .Cell(visCnnctY).FormulaU = "Height*1"
        End With

End Sub


Add note:  each CP file was downloaded and immediately saved as vsdm.  Each vsdm file was re-loaded, code was pasted in and run.  Eventually, file resaved with code.  Original vsd files remain unedited.
Visio 2019 Pro


Hey thanks everyone for jumping on this one. Also my bad all, I assumed the question was a simple thing to answer and didn't think about adding code to demonstrate.

1. @Croc: About Masters: Negative. I actually got started down this road because I wanted to make a stencil of a network switch with connection points for each port and didn't want to manually add all the ports with exact spacing. There are no masters on the sheet at present. Just a rectangle shape I drew. So no masters at all under Document Stencils.

2. @Croc: About the code something like this: Well your not wrong, except that code only works if the row indice is present. If there are no rows, there is nothing to test.

3. @Nikolay: About Just to clarify: Precisely my issue.  Additionally, it never occured to me the section might disappear on save. But I disagree that there is no practical use for knowing what the section will allow in terms of a row type. I think it would allow me to provide better feed back in terms of errors and possibly simplify some code.  Otherwise, I'd have to write a bunch of extra code to check various conditions and derive the correct answer to what kind of addrow method is called for.

4. @wapperdude and @Nikolay: Thanks for the extra effort. What I'm getting out of this is that I can only test for row type, if there is already a row to test. If there isn't I basically just have to try and add the row then see if I get an error, then try the other. Not great, but if that's the only way, I guess that's that.


Actually, my point is that there's no need to test!  Just don't use visTagCnnctPt.  Period. Use 0 instead.  Then, if you want a named row, see syntax given above, in reply #20.  You do not need to test.  Just define the rows as you like.   Add all unnamed, or all named, or any mixture.

Functionally, the only differences between named and unnamed are, well, being able to reference a row by name.  Yeah, I know, Duh!  and having access to the D-cell.  If you don't use either of these features, just use default unnamed.  Visio does not require you to maintain rowtype.  In fact, that was demonstrated in my reply #11 code. 

I guess, one question is,  using multiple copies of this shape?  Again, if you don't use the features of named row, then it's who cares.  Use the "0" and add to your hearts content.

The other question would be, type of connection point:  inward, outward, both.  That has nothing to do with rowtype.
Visio 2019 Pro


I mean, you could use this logic:
- if there is at least one row, use it to find out the section "kind"
- if there are no rows at all, just re-create the section (the re-created section will allow any row "kind")

Overall, the issue looks like a Visio bug:
the section "kind" is not cleared when the last row is deleted from it.

But I'm 99.999% sure nobody will ever bother to fix that.


Quote from: Nikolay on May 21, 2024, 11:15:11 PMI mean, you could use this logic:
- if there is at least one row, use it to find out the section "kind"
- if there are no rows at all, just re-create the section (the re-created section will allow any row "kind")


Quote from: Nikolay on May 21, 2024, 11:15:11 PMBut I'm 99.999% sure nobody will ever bother to fix that
I am sure for 119%! Because 99% of all Visio users dont use Named connection points. 
The rarest users add/remove rows line by line in that section


Quote from: Surrogate on May 22, 2024, 09:52:35 AMI am sure for 119%! Because 99% of all Visio users dont use Named connection points.
The rarest users add/remove rows line by line in that section

...And even more rare are users that use shape.RowType to change the "kind" of row.

What I found is using visTagCnnctPt rarely works, but rather, it almost always produces an error.  Fortunately, substituting "0" for that seems to always work. 

Most incredibly, why did Visio even bother to differentiate between named and unnamed row types in the Connection Points section?  Merely to make the D-cell accessible?!?  Seems unnecessary.  Make them always nameable.  Just allow D-cell to be 100% accessible.  Especially, considering that once any one row is named, then that ability is always available for all existing and newly added rows...whether or not the User chooses to do so.  (After all, that's how other sections work.).

Finally,  the only real point to this named row stuff is to traumatize. The User!   To that end, I say... Name them!   Name them all!!!

Yeah. How UN-likely that M$ will ever change this???  ..."to infinity and beyond!"
Visio 2019 Pro


In the paper book Visio 2003 Developer's Survival Pack by Graham Wideman, I found table 36-8. There I found that visTagCnnctPt and other rows were added in the Visio 06 version.

The Visio History table indicates that version 06 was released in August 1999, before MS acquired Visio!