BUG: GotFocus Event Not Executed in Sub Main and SetFocus

Last reviewed: October 14, 1996
Article ID: Q149489
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

SYMPTOMS

The GotFocus Event fails to execute when the form is displayed through a

Sub Main event and the SetFocus event is executed.

WORKAROUND

Execute the DoEvents method after the SetFocus event.

STATUS

Microsoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article. Microsoft is researching this issue and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start 16-bit or 32-bit Visual Basic 4.0, or if it is already running, click New Project on the File menu.

  2. Add a TextBox control to the Form1 form.

  3. On the Insert menu, click Module to create a module. Copy the following code to the Module1 Code window:

          Option Explicit
    

          Sub Main()
             Load Form1
             Stop
          End Sub
    
    

  4. Copy the following code to the Code window of the Form1 form:

          Option Explicit
    

          Private Sub Form_Load()
    
             Me.Show
             Text1.SetFocus
             'Uncomment the next line for Workaround
             'DoEvents
          End Sub
    
          Private Sub Text1_GotFocus()
             Text1.Text = "GotFocus"
          End Sub
    
    

  5. On the Tools menu, click Options to display the Options dialog box. Click the Project tab and set Sub Main as the Startup Form.

  6. Step through the application by pressing F8. Note that after the SetFocus event, the GotFocus event is skipped. If the DoEvents statement is uncommented, the GotFocus event will be fired if the application is not run in debug mode. If F8 is used to step through each line of code, the GotFocus event will still not be fired.


Additional reference words: 4.00 vb4win vb4all SetFocus GotFocus Module
KBCategory: kbprg kbbuglist
KBSubcategory: PrgOther




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 14, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.