Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Lamberta Schmidt   on Nov 02 In MS Office Category.

  
Question Answered By: Brock Smith   on Nov 02

From what I have experienced, NT prevents DoEvents from "Doing" so to
speak. It as if NT doesn't want to let you have the ability to trap
events __when a Sub is running__. Like "You have a Sub executing and
I don't want another one started until it finishes due to its own
code."
I have a sheet which does serial I/O and I had problems
recognizing events with DoEvents. I would be running  a Sub which was
polling the serial port and collecting data, if it was present. This
Sub was entered from a CheckBox on the sheet.
When the data stopped (or I just wanted to stop polling) I needed
to halt this Sub with an 'abort' button push on the sheet...let it
collect data, then stop when the user wanted to. The 'abort button'
fired a Sub which reset  the value of the CheckBox that started the
polling Sub and I think I had a WHILE LOOP watching the condition of
the CheckBox once the Sub was running.
With a DoEvents in the polling loop in that sub, I couldn't
recognize my 'abort' button push except by continuing to click the
button, then after MANY ckicks, it would jump out of the polling
Sub. The 'abort' button reset the value of the CheckBox which
entered that Sub.
This same sheet on an XP machine worked flawlesly. Come to think
of it, trying to "Un-Check" the CheckBox to exit the polling Sub
operated the same (Except, if you kept clicking, you'd overshoot and
re-start the polling...high argggg factor). I sprinkled DoEvents
all over the polling Sub to little avail and it looked pretty silly,
but I was desperate.

On the NT machine I wound up putting this to get out of the Sub with
only ocassionally needing to push more than once.
For ii= 1 to 300
DoEvents
NEXT
The bigger I made the 300, the better. I may be imagining, but it
sometimes seems to capture the abort button better if I hold it down
for a little before releasing... ya get punchy after a while, ya
know.
It also doesn't seem to slow things down with large values for the
300 implying that NT inhibits the "Do" in DoEvents!.

It's as if NT inhibits the event trapping ability of DoEvents. Kind
of a DontDoEvents override... DoEventsEnable = False.

Share: 

 

This Question has 6 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Interesting problem when I run a vba process Or get search suggestion and latest updates.


Tagged: