Microsoft KB Archive/214743

= How To Determine the IDE Mode From an Add-In =

Article ID: 214743

Article Last Modified on 7/1/2004

-

APPLIES TO


 * 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

-



This article was previously published under Q214743



SUMMARY
The Visual Basic Extensibility Object Model (VBE) does not provide a direct method of determining if the integrated development environment (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.  Start Visual Basic and create a new Add-in project (MyAddIn.vbp). A form named frmAddIn is generated by default.  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  Copy the code for the IDEMode function above and paste it in frmAddIn's code module. Click the Start button or press the F5 key to run the add-in. 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. From the Add-ins menu, select MyAddIn. Note that the Immediate window for MyAddIn will show the IDE state. Put some code in the standard EXE and run it to see the state change.</li></ol>

<div class="references_section">