Different Effects App/App with IDE visible???

J

Julian

I've been annoyed by this for years, but now to try and do something about
it...

Word 2002, currently under Vista HP (but it was the same behaviour under
XP...)

Sometimes code does one thing (the wrong thing/nothing) when it runs
automatically, and does exactly the right thing when single-stepped - or is
otherwise odd in its execution! - making debugging impossible!

Current problem: I have a self re-starting on-time loop to handle idle
actions... to let me know that it is running in the background I have
created two alternate buttons on a custom toolbar and toggle their .visible
state.

I can see the code setting the visible properties to the correct value, but
the buttons themselves often do not change visibility (they *do* seem to
change if I am watching in Word, but only at the point that I switch to the
VBA IDE... but this is not consistent behaviour: I *have* seen the icons
toggling away happily for hours...)

Buttons inited with e.g.
Set extrasBar = CommandBars("Extras")
Set idleLoopAButton = extrasBar.Controls("idleLoopA")

where idleLoopAButton is a module global.

The idle loop looks like this

Static Sub idleLoopActions()
Dim callCounter As Long

callCounter = callCounter + 1
On Error Resume Next
If idleLoopAButton.Visible = False And idleLoopAButton.Visible =
True Then ' dummy impossible test - only execute within if there is an
error accessing properties
initIdleLoopRunIndicator
End If
On Error GoTo 0
If callCounter Mod 2 = 0 Then
idleLoopAButton.Visible = True ' just toggle the visibility
of two buttons
idleLoopBButton.Visible = False
Else
idleLoopAButton.Visible = False
idleLoopBButton.Visible = True
End If
DoEvents
' do other stuff omitted from post...
end sub

I have "cleaned" the code (with "VBA Code Cleaner", deleted the toolbars and
reimported them from a backup file... and restarted Word (NOT restarting the
VBA IDE) but all to no effect - buttons not toggling!

Does anyone have any ideas?

TIA

PS Code has lots of userforms, and some other ActiveX (a spreadsheet as OWC
for example)
 
J

Julian

Extra info...

It's something to do with events... if absolutely nothing happens then the
buttons don't change... but if I type Left-Arrow/Right-Arrow continuously it
happens every time...

Have tried turning ScreenUpdating on and off, using ScreenRefresh, resetting
parent toolbar visibility to TRUE, adding multiple DoEvents after each step
(1 gets an event posted, 2nd causes it to be handled... I think) - none of
which work...

I need to post some sort of null event - Word only seems to update the
screen on some sort of "appropriate" trigger

<sigh>

Ideas?
 

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