FIX: Problems Calling DoEvents from a Scroll Bar Change Event
ID: Q95498
|
The information in this article applies to:
-
Microsoft Visual Basic programming system for Windows, version 2.0
SYMPTOMS
There are two parts to this bug, a paint problem and a stack problem. These
two problems can occur when DoEvents is called from the Change event of a
scroll bar.
- Clicking either the up or down directional arrows of a scroll bar causes
the change event to fire repeatedly and generate an "Out of Stack Space"
error.
- Moving the scroll bar's thumb after clicking either of the directional
arrows leads to painting problems with the scroll bar.
WORKAROUND
To work around the problem, move code containing DoEvents calls from the
change event to a timer event. Then from the scroll bar change event,
enable the timer. For example, add the following steps to those listed in
the "More Information" section to implement this workaround:
- Add a Timer control (Timer1) to Form1.
- Place the following code in the Timer1_Timer event procedure:
Sub Timer1_Timer ()
s! = Timer
Do
x% = DoEvents ()
Loop While Timer - s! <= .25
timer1.Enabled = 0
End Sub
- Place the following code in the HScroll1 Change event procedure to
replace the code added in step 3.
Sub HScroll1_Change ()
Print "We are in the Change Event"
timer1.Interval = 2000
timer1.Enabled = -1
End Sub
- From the Run menu, choose Start (ALT, R, S) or press the F5 key to run
the program.
Now you should be able to click the directional arrows of the scroll bar
and move the scroll thumb without encountering either of the two problems.
STATUS
Microsoft has confirmed this to be a bug in Microsoft Visual Basic version
2.0. The stack problem was corrected in Microsoft Visual Basic version 3.0.
However, the paint problem still exists.
MORE INFORMATION
Steps to Reproduce Problem
- Start Visual Basic, or from the File menu, choose New Project if Visual
Basic is already running. Form1 is created by default.
- Add a horizontal scroll bar (HScroll1) to Form1.
- Add the following code in the HScroll1_Change event procedure of Form1:
Sub HScroll1_Change ()
Print "We are in the Change Event"
s! = Timer
Do
x% = DoEvents ()
Loop While Timer - s! <= .25
End Sub
- From the Run menu, choose Start (ALT, R, S) or press the F5 key to run
the program.
To demonstrate the problem of Change events being fired repeatedly, click
either of the scroll bar's directional arrow buttons and leave the mouse
cursor over the directional arrow. This will eventually lead to an "Out of
stack space" error message.
To demonstrate the painting problems, click either of the arrows. Then move
the scroll thumb of the scroll bar in any direction. The scroll bar will be
painted incorrectly. This will also lead to an "Out of stack space" error
message.
Additional query words:
buglist2.00 fixlist3.00 2.00 3.00
Keywords :
Version :
Platform :
Issue type :