FIX: VB Debug.Print in MouseMove Event Causes MouseMove Event

Last reviewed: October 30, 1997
Article ID: Q72679
1.00 WINDOWS kbenv

The information in this article applies to:

  • Microsoft Visual Basic programming system for Windows, version 1.0

SYMPTOMS

Debug.Print used within the MouseMove event procedure of a form or control causes a MouseMove event. If the mouse cursor is located within the form or control, an endless stream of output to the Immediate Window will occur. This behavior occurs for a program run in the Visual Basic development environment. An .EXE program does not utilize the Immediate Window and the Debug object so this behavior does not apply to a .EXE program. The problem does not occur if a Print method is issued to any other form or control in the program.

STATUS

This is not a problem with Visual Basic, but rather the nature of the Microsoft Windows operating environment. This problem does not occur in Visual Basic version 2.0 or 3.0.

MORE INFORMATION

If Debug.Print is used within the MouseMove event procedure of a form or control, an endless stream of output is sent to the Immediate Window. This occurs whenever the mouse cursor is within the form or control. This behavior occurs because the Debug.Print statement causes the focus to change briefly to the Immediate Window. When the focus returns to the form or control, Windows generates a MouseMove event that is processed by Visual Basic. There is no way for Visual Basic to suppress MouseMove events that are generated by Windows. The easiest way to overcome this behavior is to send debug output to another form or control.

To duplicate this behavior, create a picture control (Picture1) within the default form (Form1). Add the following code segment to the MouseMove event procedure of Picture1:

     Sub Picture1_MouseMove (Button As Integer, Shift As Integer,
                             X As Single, Y As Single)
     ' You must write the above Sub statement on just one line.
         Static i%
         i% = i% + 1
         Debug.Print i%
     End Sub

If you want output to be sent only when the mouse is moved, then all Debug.Print statements within the MouseMove event procedure should be changed to Print methods to other forms or controls. Below is a description of how to modify the example above such that output is produced only when the mouse is moved.

Add another form (Form2) to the project by selecting New Form from the File menu (ALT F+F). Change the Debug.Print statement in the MouseMove event procedure for Picture1 to Form2.Print. Below is a copy of the above sample modified to send output to another form.

     Sub Picture1_MouseMove (Button As Integer, Shift As Integer,
                             X As Single, Y As Single)
     ' You must write the above Sub statement on just one line.
         Static i%
         i% = i% + 1
         Form2.Print i%
     End Sub

In the example above, all output that scrolls off the form will be lost. A more sophisticated routine will be required to keep track of all output to the form. Such a routine is beyond the scope of this article.


Additional reference words: fixlist2.00 fixlist3.00 1.00 2.00 3.00
KBCategory: kbenv
KBSubcategory: EnvtDes PrgCtrlsStd
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.