Author Topic: Visio automation engine gets confused or stops altogether  (Read 5868 times)

0 Members and 1 Guest are viewing this topic.

Hey Ken

  • Full Member
  • ***
  • Posts: 190
  • Just This Guy
    • The Pennsylvania Project, with Ken Krawchuk
Visio automation engine gets confused or stops altogether
« on: June 26, 2013, 02: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, 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

Ken V. Krawchuk
'caster

The Pennsylvania Project
Radio Podcast

10 to 11 AM Saturdays on WWDB 860 AM in Philadelphia
On demand at http://PennsylvaniaProject.com

vojo

  • Hero Member
  • *****
  • Posts: 1228
Re: Visio automation engine gets confused or stops altogether
« Reply #1 on: June 26, 2013, 07:53:59 PM »
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.

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Visio automation engine gets confused or stops altogether
« Reply #2 on: June 27, 2013, 01: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?


Hey Ken

  • Full Member
  • ***
  • Posts: 190
  • Just This Guy
    • The Pennsylvania Project, with Ken Krawchuk
Re: Visio automation engine gets confused or stops altogether
« Reply #3 on: August 01, 2013, 10:26:09 AM »

   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

Ken V. Krawchuk
'caster

The Pennsylvania Project
Radio Podcast

10 to 11 AM Saturdays on WWDB 860 AM in Philadelphia
On demand at http://PennsylvaniaProject.com

Yacine

  • Hero Member
  • *****
  • Posts: 2574
Re: Visio automation engine gets confused or stops altogether
« Reply #4 on: August 01, 2013, 02: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.
« Last Edit: August 01, 2013, 02:13:25 PM by Yacine »
Yacine

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Visio automation engine gets confused or stops altogether
« Reply #5 on: August 02, 2013, 01: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).

Hey Ken

  • Full Member
  • ***
  • Posts: 190
  • Just This Guy
    • The Pennsylvania Project, with Ken Krawchuk
Re: Visio automation engine gets confused or stops altogether
« Reply #6 on: August 02, 2013, 09:33:18 AM »
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
Ken V. Krawchuk
'caster

The Pennsylvania Project
Radio Podcast

10 to 11 AM Saturdays on WWDB 860 AM in Philadelphia
On demand at http://PennsylvaniaProject.com

Yacine

  • Hero Member
  • *****
  • Posts: 2574
Re: Visio automation engine gets confused or stops altogether
« Reply #7 on: August 02, 2013, 03: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.
« Last Edit: August 02, 2013, 03:30:45 PM by Yacine »
Yacine