Scroll Bar Change Event Can't Call Modal Form or Modal MsgBox

ID Number: Q76631

1.00

WINDOWS

Summary:

You should not use the scroll bar Change event to bring up message

boxes or modal forms in Visual Basic.

If a scroll bar Change event brings up a modal form or message box,

unexpected behavior in the scroll bar may follow. The modal dialog box

may pop up repeatedly, and the scroll bar arrows may appear large and

distorted.

This information applies to Microsoft Visual Basic programming system

version 1.0 for Windows.

More Information:

Clicking with the mouse somewhere on the scroll bar will trigger the

Change event, which will call up the message box that then gets the

focus. Because it is modal, it will retain the focus while the mouse

Up event occurs. Hence, the scroll bar is still waiting for a mouse Up

event. A Change event will occur again once the message box is

canceled and the scroll bar regains the focus. At this point, the

program enters an infinite loop; the message box gets called again and

again. The scroll bar either blinks or has unusual arrows that are

oversized.

Steps to Reproduce Problem

--------------------------

1. Place a scroll bar on a a blank form.

2. Double-click on the scroll bar to bring up the ScrollBar_change

event procedure.

3. Type the following code:

MsgBox "This is a test"

4. From the Run menu, choose Start.

5. Click anywhere on the scroll bar.

6. When the dialog box is displayed, choose the OK button.

Note that the scroll bar is blinking when the dialog box is displayed.

The dialog box will most likely pop up again and again. Other unusual

graphical distortions may occur, such as large cursor arrows appearing

on the scroll bar. This also is true if you call up a modal form

instead of a MsgBox.

Additional reference words: 1.00