Using Visio 2003 or Visio 2007 from VB.net ActiveX drawing control

G

Gshell

I, and several others here, have been struggling with how to create a VB.NET
application that can run on machines where there may be a mix of Visio 2005
or Visio 2007 users. (The information below pertains to a VB.NET application
that utilizes the ActiveX control. All other modes of interacting with Visio
are untested by me.)

Despite claims to the contrary, code written against Visio 2003 will NOT run
if the end user has Visio 2007. You wind up with various COM exceptions.
However things are not as bad as they might seem. Read on...

I am still developing in Visual Studio 2003. I had Visio 2003 installed and
had done all of my development using those two. I installed Visio 2007 in a
separate directory so I could switch between Visio versions at will. (To
switch all you need to do is run the version you want to be "active". It
will run a "mini install" cycle as it updates the registry. After that
VB.Net will instantiate the "active" version of Visio inside the ActiveX
Drawing tool.)

Right after installing VISIO 2007, I ran my VB.NET code inside the VB IDE
and things blew up left and right. Lots of COM exception errors. Even
viewing VISIO objects in a "Watch" window showed COM exceptions on various
properties of the object. Clearly something was amiss. After scouring the
internet for clues I turned up NOTHING, NADA, ZILCH. I implored for help in
the Microsoft Private Partner newsgroups, etc. all to no avail.

Digging my heels in I decided to play around and see if I could figure this
out. First, I thought I'd add the "new" Visio 2007 ActiveX drawing control
to the VB IDE tool palette. But when I tried I got a surprise. It was
already there! The old Visio 2003 ActiveX drawing control WHILE still named
as if it were from Visio 11 (aka Visio 2003) was actually the Visio 12 (aka
Visio 2007) version. I realized this when I clicked "Add/Remove items" in
the tool palette and then went to the COM tab, scrolled down and found a
check mark next to the "Microsoft Visio 12.0 Drawing tool"!

Not sure if this meant that my VB.net form had the new ActiveX control on it
or not I dragged a new copy onto my form, so now I had TWO controls. I did a
global search and replace of all my code to point it to the NEW control and
deleted the old one. Ran the code and still got a ton of COM exceptions.
Sigh.

I looked at the three References in my project. One was labeled "Visio",
another "VisOcx" and a third the "AxMicrosoft.Office.Interop.VisOCX". The
properties of the "Visio" and "VisioOCX" references revealed they were still
pointing to Visio 11 (aka Visio 2003). The "AX" pointed to a file inside my
project because I believe it is actually generated when you drag the Active
X control onto the form. But it gave no indication as to it's version. So,
I deleted the "Visio" and "VisOCX" references and added them back pointing to
Visio 12 (aka Visio 2007) Versions. This had the side effect of changing
their name in the references in my project. Now they show up as
"Microsoft.Office. Interop.Visio" and "Microsoft.Office.Interop.Visocx". And
indeed their properties show them as Visio 12 versions. To be safe, I added
another instance of the Active X drawing control to my form. Again did a
global search and replace to point my code to the NEW control and deleted the
old one.

Holding my breath I complied my code and it RAN. No COM exceptions! I did
have some other anomalies which I'll explain latter. But it ran! Now for
the acid test! I shut down the VB IDE and ran Visio 2003. This made it the
"active" version. I fired up VB IDE and ran my code again and it ran just
fine!!! Hurrah!

I shut down the VB IDE, switched back to Visio 2007 as the active version
and fired up my code again. Once again it ran, with a couple of issues, but
it ran! I then created an installer for my app (remember I am still using
the Visio 12... aka Visio 2007... references). I sent it off to my business
partner who has ONLY Visio 2003 installed and it ran fine there. (The ONLY
test I have not done is on a machine that has only had Visio 2007 installed,
but I feel confident it will work.)

Now as to the issues I found. First, I am instantiating the
"Cross-functional Flowchart.vst" template. When running against Visio 2003,
this always brings up a dialog box asking for the number of "swimlanes" and
horizontal or vertical orientation. (This was regardless of the state of the
AppVisio.AlertResponse property.) My VB.NET code would stay suspended until
the user hit the OK button and the template finished initializing. With
Visio 2007 two differences appeared. The AlertResponse property if set to 1,
now dispenses with the dialog box for the number of lanes AND the underlying
VB.net code continues to run immediately. This caused some issues because my
code always made the assumption that the template had finished initializing
and referenced some objects it expected to be ready for use. With Visio
2007, the template had not initialized when my code referenced some objects
and my code failed because those objects were not yet instantiated. I
changed the AlertResponse property to zero, hoping that the dialog box would
hold my code up long enough for the template to finish. But apparently that
ALSO held up the template initialization as well. By commenting out these
references to not yet existing objects, I found out that my code was running
up to the point where I was dropping a new "Function Band" (one of the
templates stencil items) onto the drawing surface. It would wait there until
the template was initialized. So, I added some code to IMMEDIATELY drop a
new "function band" onto the form right after I set the SRC property of the
Active X control to the "Cross-functional Flowchart.vst" template. This
allowed the template to complete its initialization (which also by the way
ALSO deleted the "function band" I had just added) and THEN my VB.net code
got control and all of the objects I expected to be instantiated actually
were there and ready for use! I was even able to set the AlertResponse
property back to 1 so I no longer see the dialog box about the number of
swimlanes.

Two other items of note that are different under Visio 2007. When setting a
formula to a string containing a GUARD function, Visio 2003 did not care if
there was already a GUARD function there or not. Visio 2007 does, it
refuses to set the formula unless you use a FomulaForce to do so. And when
you right click on a completed drawing in the Active X control under Visio
2003 you get a popup menu that includes an item which allows you to set the
zoom level. Under Visio 2007 that item is gone and you have to make you own
menu.

WHEW! Long winded, huh? But hopefully this will help some of the other
folks who are obviously struggling with this here. ("ASIF" are you out there
still???? You were the first user here who posted about this and I tried to
reach you. Hopefully you will see this!)

Gary
 
J

JuneTheSecond

One of ideas is put Drawing Control in the program,
I am not sure iti is possible.
or,
stop or shift program by the version of installed Visio.
Visio Application has Version property.
for example,
myapp = AxDrawingControl1.Document.Application
If myapp.Version <> "12.0" Then
MessageBox.Show("Version not correct")
End
End If
 
F

faraz

One of ideas is put Drawing Control in the program,
I am not sure iti is possible.
or,
stop or shift program by the version of installed Visio.
Visio Application has Version property.
for example,
myapp = AxDrawingControl1.Document.Application
If myapp.Version <> "12.0" Then
MessageBox.Show("Version not correct")
End
End If


The problem here is drawing control 11.0 and 12.0 both have different
namespaces, it breaks as you run the application. So theres no point
for checking the version. Once the application is run without any
exception it means it supports the visio version (whatever.. 2003 or
2007).
 
J

JuneTheSecond

I am sorry for my mistake, then my another idea is check Visio version,
for example, In the Form_Lord,
Dim visapp As New Visio.InvisibleApp
If visapp.Version = "12.0" Then
MessageBox.Show("Version is correct")
Else
MessageBox.Show("Version not correct")
End
End If
 
G

Gshell

Did you even read the long note I wrote??? I have figured out HOW to do make
a VB.Net application work with either the 2003 or 2007 version of Visio. I
am not asking how to do it. I have made it work and am trying to help other
folks here who have the same problem. I am not trying to be rude, but your
"answer" has NOTHING to do with the message I sent. Please read the message I
wrote.

Gary
 
G

Gshell

Yes, BUT if you use the drawing control from Visio 12 it's namespace is
backwards compatible with instances of Visio 2003. That was the crux of my
long winded message. I was able to create a single version of my VB.NET
application that now works with either Visio 2003 or Visio2007. There were
some minor differences in how the two behaved but the namespace issue, as it
turns out, is NOT an issue afterall. Where the two versions of Visio behave
differently I tested the "VisioVersion" property to make minor tweaks in my
code.

Gary
 
F

faraz

If you say Visio 12 is backward compatible with instances of visio
2003, you should try this.
in you application, handle the shapeAdded event with pop up message of
ShapeName. Now run your application in both versions of active visio.
You may be surprised to know the events are only working with 2007 but
not with 2003.

I have checkd the application events are not working with 2003 with
the control 12.0.
 
G

Gshell

My particular app does not use events at all, but when I was playing with the
issue of the "Cross Functional Flowchart. VST" not initalizing in the same
way as it had before, I did try using the "No Events Pending" event to
resolve the problem I had. I cannot say with 100% certainty, but I think
that WAS firing when I ran it under Visio 2003. But again I am nit certain
and subsequently, I have removed the need for the events handling from my
code. So you may be right.

Gary
 

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