FIX: Problems Calling DoEvents from a Scroll Bar Change Event (95498)



The information in this article applies to:

  • Microsoft Visual Basic Standard Edition for Windows 2.0

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

Modification Type:MinorLast Reviewed:1/8/2003
Keywords:kbbug KB95498