Q214743: HOWTO: Determine the IDE Mode From an Add-In
Article: Q214743
Product(s): Microsoft Visual Basic for Windows
Version(s): WINDOWS:5.0,6.0
Operating System(s):
Keyword(s): kbVBp kbVBp500 kbVBp600 kbGrpDSVB
Last Modified: 11-JAN-2001
-------------------------------------------------------------------------------
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows, versions 5.0, 6.0
- Microsoft Visual Basic Professional Edition for Windows, versions 5.0, 6.0
- Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0, 6.0
-------------------------------------------------------------------------------
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.
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
(c) 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 kbGrpDSVB
Technology : kbVBSearch kbAudDeveloper kbZNotKeyword6 kbZNotKeyword2 kbVB500Search kbVB600Search kbVBA500 kbVBA600 kbVB500 kbVB600
Version : WINDOWS:5.0,6.0
Issue type : kbhowto
=============================================================================
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.
Copyright Microsoft Corporation 1986-2002.