Main Menu

Recent posts

#1
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - Today at 06:08:42 PM
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:
> named:         vsoShp.AddRow visSectionConnectionPts, iRow, visTagCnnctPt
> unnamed:       vsoShp.AddNamedRow visSectionConnectionPts, "P" & iRow + 1, visTagCnnctNamed

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
    Next

End Sub

QED
#2
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - Today at 05:34:41 AM
Yes.  I ran steps 1 - 3, both files.  The difference is that I ran from Program window not the Immediate window.  Re-ran just a bit ago.  I get different results.
I run code with 1st line active.  It runs fine for both CP1 and CP2 files.  Close Visio, no saving.
Re-run code with just 2nd line active.  Runs fine in both CP1 and CP2 files.  No errors.  For me, the difference is that 1st line works now.  Perhaps I had a typo?.  For you, difference is both lines work, both files.

The other difference is that I had to save the CP files as vsdm in order to run code.

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


#3
Programming & Code / Re: Testing row type, before t...
Last post by Nikolay - May 17, 2024, 05:35:02 PM
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
#4
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - May 17, 2024, 01:54:40 PM
@Nikolay:
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.
#5
Programming & Code / Re: Testing row type, before t...
Last post by Nikolay - May 17, 2024, 05:52:00 AM
@wapperdude
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:

#6
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - May 16, 2024, 03:39:48 PM
@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.
#7
Programming & Code / Re: Testing row type, before t...
Last post by Nikolay - May 16, 2024, 02:56:36 PM
I've updated the post above with an easier example that should help to understand the issue.

The topicstarter is looking for a code that would work for both CP1 and CP2 file above.
#8
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - May 16, 2024, 02:54:24 PM
@Nikolay:  Wrong.  It does both. 

First row added as normal, deleted, replaced with "named" row.  Here's the steps:
QuotevsoShp.AddRow visSectionConnectionPts, iRow, 0
        vsoShp.DeleteRow visSectionConnectionPts, iRow
        vsoShp.AddNamedRow visSectionConnectionPts, "P" & iRow, visTagCnnctNamedABCD

Second row, similar, except 1st add is named, then deleted, replaced with normal.  I watched the process as I stepped thru the code using <F8> to verify that is what is going on.

So we're all on same page, at least from Forum perspective, here's my latest test case, attached.

The file has two shapes.  Yellow square that has a master, on Document Stencil.  Master has Connection Pts section.  That section has been deleted from the shape on drawing page.  The green circle has no master and no connection pts.

Code has been modified to step thru both shapes.  No error observed.
#9
Programming & Code / Re: Testing row type, before t...
Last post by Nikolay - May 16, 2024, 02:48:02 PM
@wapperdude
The issue happens when you try to add an "unnamed" type connection point to a section that already contains "named" connection points.

Your code does not mix them; to hit the issue, it should.

Better example (attached). You have 2 files, they look exactly the same (ShapeSheet is also the same).
They have a single rectangle inside. The "connection points" section is empty (has no rows).

Now try executing this line for each of them (adds one row to connection points section):

ActivePage.Shapes(1).AddRow visSectionConnectionPts, 0, visTagCnnctPt
If you try to execute this for the first file, it succeeds.
If you try to execute the same line for the second file, it fails.

#10
Programming & Code / Re: Testing row type, before t...
Last post by wapperdude - May 16, 2024, 02:15:45 PM
@Croc, @Nikolay:  Interesting thoughts.  I tried each of your suggestions thinking that I missed something.  I have not encountered the OP's problem, nor the issue that Nikolay's code produces.

Here is my updated code to mimic Nikolay's code.  It does both cases that he shows.  It would be easy enough to copy my code and run it.

I'm running V2019 Pro on laptop with Win11 64B.

Sub ConnPts()
    Dim vsoShp As Visio.Shape
    Dim iRow As Integer

    iRow = 0
       
    Set vsoShp = ActiveWindow.Selection(1)
    vsoShp.AddRow visSectionConnectionPts, iRow, 0
    vsoShp.DeleteRow visSectionConnectionPts, iRow
    vsoShp.AddNamedRow visSectionConnectionPts, "P" & iRow, visTagCnnctNamedABCD 'Row index starts at "0", but want names to start at "1"
    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, visTagCnnctNamedABCD 'Row index starts at "0", but want names to start at "1"
    vsoShp.DeleteRow visSectionConnectionPts, iRow + 1
    vsoShp.AddRow visSectionConnectionPts, iRow + 1, 0
    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, 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