Late problem with Enums

During development everything was fine, early binding was processed, but now I have switched to late binding for production and I am having problems with Visio Enums. As shown below:

 Set AppVisio = CreateObject("visio.application")
 Set vsoSelection = AppVisio.ActiveWindow.Selection
 Call vsoSelection.GetIDs(lngShapeIDs)

 With .Shapes.ItemFromID(lngShapeIDs(0))
    .CellsSRC(visSectionObject, visRowXFormOut, visXFormPinX).FormulaU = sngShapeHCenter
    .CellsSRC(visSectionObject, visRowXFormOut, visXFormPinY).FormulaU = sngShapeVCenter
    .CellsSRC(visSectionObject, visRowXFormOut, visXFormWidth).FormulaU = sngShapeWidth
    .CellsSRC(visSectionObject, visRowXFormOut, visXFormHeight).FormulaU = sngShapeHeight
 End With

      

In early binding

visSectionObject, visRowXFormOut, visXFormPinX etc.

      

everyone is allowed, but I can't get them to resolve in Late Binding.

I tried to add AppVisio. to no avail for prefixing parameters, can anyone help and tell me the correct way to reference Enums?

I've tried using the Visio VBA recorder to see what it gives, but it's not as much as I was hoping for (yes, I know, it's so verbose, but not in this case).

This is required for Visio 2010 and 2013, etc.

+2


source to share


2 answers


This is one of the tradeoffs of late binding, rather than specifying an explicit link in Tools> Links. The predefined enums are then not available.

You will need to replace the enums with their numeric value ( see this list for example ).

For example, a numeric value visRowXFormOut

is equal 1

, which you can check for yourself in the Immediate window:

?visRowXFormOut
1

      



So, you can either replace all instances visRowXFormOut

with 1

s or declare visRowXFormOut

as a constant:

Const visRowXFormOut As Integer = 1

      

and keep the rest of your code as it is.

+4


source


Determining all the counters yourself or replacing the code in primes can be overwhelming in some cases. There is also another way.

If you are using scripts on Windows (the language looks like .vbs), you can still use these constants by wrapping your file in .WSF ( Windows Script ).

In your .wsf file, you have a "reference" element that allows you to use constants from a type library.

<job id='my script'>

    <!-- this imports enumerators from Visio typelib -->
    <reference guid="{00021A98-0000-0000-C000-000000000046}" version="4.14" />

    <script language="vbscript">
        ... 
        your code here which uses constants from Visio type library here, like:
        ...
        WScript.Echo visRowXFormOut ' prints 1
        ...
    </script>

</job>

      



Not 100% sure if you have to explicitly specify the version in an item, but in any case, Visio 2010 is 4.14, Visio 2013 is 4.15. It can work without an explicit BOM (see wsf docs)

You might also consider migrating the entire .vbs file unchanged:

<job id='my script>

    <reference guid="{00021A98-0000-0000-C000-000000000046}" version="4.14"/>

    <!-- you can use enumerators in that script -->
    <script language="vbscript" src="code.vbs" />

</job>

      

0


source







All Articles