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