Visio Guy

Visio Discussions => Visio Bugs (er...Issues) => Topic started by: Hey Ken on June 26, 2013, 07:38:17 PM

Title: Visio automation engine gets confused or stops altogether
Post by: Hey Ken on June 26, 2013, 07:38:17 PM

Hey, gurus:

   Well, it's happened again, and it gets soooo frustrating whenever it does.  I sometimes spend hours tracking down a bug in my code that just isn't there.

   What happened to me just now was that static variables suddenly weren't retaining their values across successive invocations.  Closing and re-opening Visio cleared up the problem this time (once I finally realized what the problem actually was), but there have been other times where re-booting was required before things cleaned themselves up.

   Sometimes it's not so subtle—in more-common, less-extreme circumstances events simply stop firing; in fact, that's happened to me so often that long ago I added a right-click page action to "nudge" the automation engine to re-initialize events (i.e., set application, document, window, and page event variables to Nothing, then to the proper value).

   My sense of pride tells me it must be a bug in Visio, but if it is, it's been there across ten years and three versions (2003, 2007, 2010).  Seems unlikely, especially since I can find no mention on the web of others having similar troubles. 

   The problem always seems to arise later in a session, after I've closed and re-opened multiple documents or stencils multiple times, which is why I suspect it's some sort of bug.  However, as you may know, I have a history of getting esoteric in my use of macros (http://visguy.com/vgforum/index.php?topic=4710.msg19190#msg19190), which is why I suspect it may be a problem of my own doing.  But I certainly do NOT know how to make static variables turn dynamic.

   Any idea what's going on? 

   - Ken

Title: Re: Visio automation engine gets confused or stops altogether
Post by: vojo on June 27, 2013, 12:53:59 AM
you may want to set autosave on so when it happens you can recall last known good.   From there you can determine if its something
that "builds up over time" or the last few things you did.  I assume you have sufficient DRAM and such (so that automation isnt waiting on
OS to swap out/in file pages in order to continue to execute).

Visio is typically real stable  (other tools crash more times in a month for me than visio crashed in 10 years).

If the automation is home grown...contact the author or start a VBA window and do some tasking/probing yourself.
Title: Re: Visio automation engine gets confused or stops altogether
Post by: Jumpy on June 27, 2013, 06:11:09 AM
You didn't mention it, so I guess it's not part of your problem, but if the automatition / a macro crashes, the VBA-project can be resetted and all variables loose their values. So maybe an error in your code occured and after that the variables don't work anymore?

Title: Re: Visio automation engine gets confused or stops altogether
Post by: Hey Ken on August 01, 2013, 03:26:09 PM

   Thanks for the advice, guys.

   I do keep autosave on, and it's autosaved me many a time.  The problems I've been seeing span many machines, so I don't believe DRAM is an issue.  Contacting the author is the only path I can take, seeing how I'm the author.  But I've looked at it so much without finding an answer that I finally gave up and implemented the "nudge" fudge to restart the automation engine.  End of story.

   Until now.  A few weeks back I stumbled across the actual solution when I was researching a completely different issue.  I had added a userform to my stencil-based macros to allow the user to set various options, but every time I exited the userform, all events stopped firing.  Couldn't figure it out.  I googled around looking at other userform solutions, all of which worked fine for me and retained their event-firing abilities.  So I compared their code to mine, and by process of elimination I found the critical difference: my WithEvents variables were all Private; theirs were Public.  I changed mine to Public, and that was that.  Events fired as expected.  And not only did it solve my userform event problem, since then I have not yet come across the situation where the automation engine stops working.  I haven't needed my nudge fudge at all, and my static variables are remaining static (so far).  New end of story.

   Before you ask, I made the variables Private in the first place because that was the example I started with when I first learned Visio macro coding over a decade ago.  It worked, so it sat unchanged all these years.  Never thought to look at it again.

   So it wasn't a bug after all.  "Probable user error...", as all the old mainframe error manuals used to say.

   - Ken

Title: Re: Visio automation engine gets confused or stops altogether
Post by: Yacine on August 01, 2013, 07:11:32 PM
Hi Ken,
I just read about your "nudge" and was wondering whether your problem is similar to mine.
I work with a visio file that I open from MS ACCESS. Unfortunately, I lose the handle to the visio App everytime one of my routines crashes (sloppy programmer  :-\ ). Do you, or one of the other members know how to get the handle of an application that you started from VBA, so I can retrieve the application and the file after a crash?

PS: Just re-opening the file does not help, as the "orphaned" file is still open.
PPS: I could have opened a new thread, but I'm not only sloppy, but also lazy. (which goes together, I guess)

Y.
Title: Re: Visio automation engine gets confused or stops altogether
Post by: Jumpy on August 02, 2013, 06:04:57 AM
I don't now how you start the first instance of the Visio application. With CreateOpbject("Visio.Application") ?
Maybe you can use GetObject(...) which returns an Visio App if it can find one and an error otherwise.
If you get an valid Visio app returned you could look at its open documents and see if it's the one you wanted (in theory there could be more than one instance of Visio open at the time).
Title: Re: Visio automation engine gets confused or stops altogether
Post by: Hey Ken on August 02, 2013, 02:33:18 PM
Yacine:

   I'm not sure our problems are similar; mine was a loss of events firing, yours is the loss of an app.  Still, let me offer a suggestion.

   Rather than figuring out how to clean up after a crash, why not prepare for the crash then capitalize on that preparation?  Specifically, when you start Visio, the first thing you do is write the handle info to a local file.  When you exit normally, erase the file.  But if you crash, you can access your stored info to rebuild your environment.  That also avoids the problem of multiple instances of Visio.

   Just a thought,

   - Ken
Title: Re: Visio automation engine gets confused or stops altogether
Post by: Yacine on August 02, 2013, 08:29:01 PM
Thank you guys for the replies.

@Ken,
that's exactly what I wanted to do. But I could not find a way to get a proper value of a handle that I could store somewhere.

@Jumpy,
unless I get a hint to solve the problem as Ken describes it, I'll probably go for your pragmatic advice.

Cheers,
Y.