Detecting if program is in Design mode or running mode from inside a Add-In
Hi guys! I need to determine if my program is in design mode or in running mode, from inside my Add-In.
From Inside a user control you can check for Ambient.UserMode, but I cannot find the way to do it from a running Add-In.
I checked all the structure from VBInstance.ActiveVBProject and seems there is no direct property.
Any clues?
Re: Detecting if program is in Design mode or running mode from inside a Add-In
If your add-in is for the IDE, then wouldn't the loaded project always be in design-mode since it's in the IDE?
Re: Detecting if program is in Design mode or running mode from inside a Add-In
Quote:
Originally Posted by
LaVolpe
If your add-in is for the IDE, then wouldn't the loaded project always be in design-mode since it's in the IDE?
The Add-In opens a form wich interact with the project... You can only open it when the project is in desing mode, but after that you can run the proyect and the form of the Add-In will not know it changed stated and cause problems
Re: Detecting if program is in Design mode or running mode from inside a Add-In
You could use VBBuildEvents, which are hidden events in "Microsoft Visual Basic 6.0 Extensibility". Open Object Browser(F2), right-click anywhere, then enable "Show Hidden Members", then search for "VBBuildEvents". You will find these 3 events:
BeginCompile(VBProject As VBProject)
EnterDesignMode()
EnterRunMode()
Re: Detecting if program is in Design mode or running mode from inside a Add-In
This is the one place where a call to EbMode works like we would want it to:
Code:
Private Declare Function EbMode Lib "vba6" () As Long ' 0=Design, 1=Run, 2=Break.
The comment out on the end explains everything. Now, note that you can't use this in regular code as it will always return 1 because, to call it, you're running. However, when in an Add-In, it works as you would want it to.
Also, I think you confused LaVolpe by not distinguishing between three different conditions: 1) running compiled, 2) running in IDE, 3) designing in IDE. If I understand correctly, you're trying to distinguish between #2 and #3, which the EbMode call can do (from an Add-In).
Good Luck,
Elroy
EDIT1: I just use it like: If EbMode <> 0& Then [we're not in design mode]
EDIT2: As an aside, there's one of those funny "EB" prefixes. Also notice that it's the vba6.dll, although we're clearly in VB6. Just some hang-overs from VB6's development having deep roots in Excel Basic (EB) and the VBA.
Re: Detecting if program is in Design mode or running mode from inside a Add-In
Thanks Qvb6 and Elroy! That's exactly what I want to check. But seems I'm not getting something right. I'm trying the events approach first.
I coded this inside a form in the AddIn :
Code:
Public WithEvents sIDE As VBIDE.VBBuildEvents
Public Sub sIDE_EnterRunMode()
MsgBox "Entering run mode"
End Sub
but is not triggering anything. Any clue?
Re: Detecting if program is in Design mode or running mode from inside a Add-In
That's not enough. You need to set the reference to the object. I learned about VBBuildEvents from a simple Add-in called ImmClear(and the Readme mentions Addin newsgroups). This Add-in clears the Immediate window when you start a project. You can find the Add-in source code here, which explains how to use VBBuildEvents.
Re: Detecting if program is in Design mode or running mode from inside a Add-In
Re: Detecting if program is in Design mode or running mode from inside a Add-In
Quote:
Originally Posted by
qvb6
That's not enough. You need to set the reference to the object. I learned about VBBuildEvents from a simple Add-in called ImmClear(and the Readme mentions Addin newsgroups). This Add-in clears the Immediate window when you start a project. You can find the Add-in
here, along with the source code, which explains how to use VBBuildEvents.
Thanks Again! I will look at that source code and learn how to implement it.
Re: Detecting if program is in Design mode or running mode from inside a Add-In
Quote:
Originally Posted by
TysonLPrice
Not exactly the same, but thanks. Thats to detect if your current program is running, not the vb ide itselft.
Re: Detecting if program is in Design mode or running mode from inside a Add-In
Hi shagratt,
The EbMode pretty much answers the question you asked. However, you seem to be now asking a slightly different question. You're wanting events that fire when you change from design-mode to run-mode (and vice-versa). That project that qvb6 pointed you to does precisely that.
Good Luck,
Elroy
EDIT1: I took out the link since shagratt got what he needed. For others, dig your way to it from qvb6's link above.
Re: Detecting if program is in Design mode or running mode from inside a Add-In
Quote:
Originally Posted by
Elroy
Download it quickly because that zip file also contains the compiled add-in DLL, which the VBForums moderators don't like. In fact, I wouldn't trust that DLL for anything. I'd examine the source and recompile before I did anything.
That's exactly what I did Elroy! :) Checked the source. Implemented in my own code, and now I got it working!
BTW there is a bug when the "Enter Design Mode" dont trigger after "Compiling" , but for me its not that important as the running-desing cicle detection.
Thanks everyone for the help!