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
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