Microsoft KB Archive/95498

= FIX: Problems Calling DoEvents from a Scroll Bar Change Event =

Article ID: 95498

Article Last Modified on 1/8/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition

-



This article was previously published under Q95498



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 &quot;Out of Stack Space&quot; 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 &quot;More Information&quot; 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 &quot;We are in the Change Event&quot; 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.



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.</li> Add a horizontal scroll bar (HScroll1) to Form1.</li>  Add the following code in the HScroll1_Change event procedure of Form1: Sub HScroll1_Change

Print &quot;We are in the Change Event&quot;

s! = Timer Do     x% = DoEvents Loop While Timer - s! <= .25

End Sub </li> From the Run menu, choose Start (ALT, R, S) or press the F5 key to run the program.</li></ol>

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 &quot;Out of stack space&quot; 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 &quot;Out of stack space&quot; error message.

Additional query words: buglist2.00 fixlist3.00 2.00 3.00

Keywords: kbbug kbfix KB95498

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.