PRB: Events Occur in EXE While a Message Box Is Displayed

This article was previously published under Q178078
This article has been archived. It is offered "as is" and will no longer be updated.
Running a project in the IDE that displays a message box prevents eventsfrom occurring. However, when you compile and run the same project as anexecutable file (EXE), the events occur while the message box is displayed.
The behavior in the EXE has changed with Microsoft Visual Basic 5.0 and 6.0 so that it is different from earlier versions of Microsoft Visual Basic.
This behavior is by design.

Steps to Reproduce Behavior

  1. Start a new Standard EXE project in Visual Basic. Form1 is created by default.
  2. Add two Command Buttons and one Timer control to Form1.
  3. Copy the following code to the Code window of Form1:
          Option Explicit      Private Sub Form_Load()         Timer1.Interval = 1000         Command1.Caption = "Show Message Box"         Command2.Caption = "Show Modal Form"      End Sub      Private Sub Command1_Click()         MsgBox "Events Do Not Occur"      End Sub      Private Sub Command2_Click()        Form2.Show vbModal      End Sub      Private Sub Timer1_Timer()        Static intCount         intCount = intCount + 1         Form1.Print "Event # " & intCount      End Sub
  4. Add a second form to the Project by completing the following steps:

    1. From the Project menu, click Add Form. The Add Form dialog box appears.
    2. From the New Tab, click Form.
    3. Click OK to close the Add Form dialog box. Form2 is added to the project.
  5. On the Run menu, click Start or press the F5 key to start the program.
  6. Click Show Message Box after two events occur. Note that the Timer event is no longer triggered.
  7. Click Show Modal Form to display a modal form. Note that the events still occur even while the modal form is displayed.
  8. Compile the project and run the executable file as shown in step 6. Note that the events still occur despite displaying the message box or form.
RaiseEvent trigger fire

Article ID: 178078 - Last Review: 02/24/2014 08:31:26 - Revision: 2.1

  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition
  • kbnosurvey kbarchive kbprb KB178078