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:

  1. Add a Timer control (Timer1) to Form1.


  2. 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 


  3. 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 


  4. 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

  1. Start Visual Basic, or from the File menu, choose New Project if Visual Basic is already running. Form1 is created by default.


  2. Add a horizontal scroll bar (HScroll1) to Form1.


  3. 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 


  4. 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 :


Last Reviewed: September 2, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.