HOWTO: Determine the IDE Mode From an Add-In

ID: Q214743


The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0


SUMMARY

The Visual Basic Extensibility Model (VBEIDE, or Add-In model) does not provide a direct method of determining if the IDE is in design, run, or break mode. Performing certain actions, such as trying to add a control to a form during the wrong mode, such as run mode, could cause errors in the Add-in.

Most of the time this is not a problem. Occasionally, however, a long process or a process that is started via a timer event could cause a problem when trying to do something when the IDE is in the run or break modes.


MORE INFORMATION

To determine the state of the IDE, the run menus for the IDE can be checked for their enabled states.

The following reusable function can determine the state of the IDE:


Public Function IDEMode(vbInst As VBIDE.VBE) As Long
    '==================================
    'Returns the mode the IDE is in:
    '   vbext_vm_Run = "Run mode"
    '   vbext_vm_Break = "Break Mode"
    '   vbext_vm_Design = "Design Mode"
    '==================================
    Dim lMode As Long
    lMode = vbext_vm_Design
    If vbInst.CommandBars("Run").Controls("End").Enabled = True Then
        ' The IDE is at least in run mode
        lMode = vbext_vm_Run
        If vbInst.CommandBars("Run").Controls("Break").Enabled = False Then
            ' The IDE is in Break mode
            lMode = vbext_vm_Break
        End If
    End If
    IDEMode = lMode
End Function 

The following step-by-step instructions demonstrate the functionality of the IDEMode function above.
  1. Start Visual Basic and create a new Add-in project (MyAddIn.vbp). A form named frmAddIn is generated by default.


  2. Place a Timer Control (Timer1) on frmAddIn. Set its Interval property to 1000 and place the following code in frmAddIn's code module:
    
    Private Sub Timer1_Timer()
        Select Case IDEMode(VBInstance)
            Case vbext_vm_Run
                Debug.Print "Run Mode"
            Case vbext_vm_Break
                Debug.Print "Break Mode"
            Case vbext_vm_Design
                Debug.Print "Design Mode"
        End Select
    End Sub 


  3. Copy the code for the IDEMode function above and paste it in frmAddIn's code module.


  4. Click the Start button or press the F5 key to run the add-in.


  5. Start another instance of Visual Basic and create a new Standard EXE project. Form1 is created by default. Under Add-Ins menu, select Add-In Manager. In Visual Basic 5.0, select the check box next to MyAddin. In Visual Basic 6.0, select MyAdd-in, and select the "Loaded/Unloaded" check box. Click OK.


  6. From the Add-ins menu, select MyAddIn. Note that the Immediate window for MyAddIn will show the IDE state.


  7. Put some code in the standard EXE and run it to see the state change.



REFERENCES

For additional information about how to create an add-in using Visual Basic 5.0 and Visual Basic 6.0, please see the following article in the Microsoft Knowledge Base:

Q189468 HOWTO: Create a Basic Add-in Using VB5 or VB6

© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Mike Dixon, Microsoft Corporation

Additional query words: Addin Add-In Add-on Addon

Keywords : kbVBp kbVBp500 kbVBp600 kbGrpVB
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: March 11, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.