Results 1 to 12 of 12

Thread: Detecting if program is in Design mode or running mode from inside a Add-In

  1. #1

    Thread Starter
    Addicted Member shagratt's Avatar
    Join Date
    Jul 2019
    Location
    Argentina
    Posts
    203

    Question 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?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Addicted Member shagratt's Avatar
    Join Date
    Jul 2019
    Location
    Argentina
    Posts
    203

    Re: Detecting if program is in Design mode or running mode from inside a Add-In

    Quote Originally Posted by LaVolpe View Post
    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

  4. #4
    Fanatic Member
    Join Date
    Feb 2019
    Posts
    924

    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()

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    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.
    Last edited by Elroy; Jul 21st, 2019 at 01:47 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  6. #6

    Thread Starter
    Addicted Member shagratt's Avatar
    Join Date
    Jul 2019
    Location
    Argentina
    Posts
    203

    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?

  7. #7
    Fanatic Member
    Join Date
    Feb 2019
    Posts
    924

    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.
    Last edited by qvb6; Jul 24th, 2019 at 12:25 PM.

  8. #8
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Detecting if program is in Design mode or running mode from inside a Add-In

    Here is a similar post you can check:

    http://www.vbforums.com/showthread.p...ing-in-the-IDE
    Please remember next time...elections matter!

  9. #9

    Thread Starter
    Addicted Member shagratt's Avatar
    Join Date
    Jul 2019
    Location
    Argentina
    Posts
    203

    Re: Detecting if program is in Design mode or running mode from inside a Add-In

    Quote Originally Posted by qvb6 View Post
    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.

  10. #10

    Thread Starter
    Addicted Member shagratt's Avatar
    Join Date
    Jul 2019
    Location
    Argentina
    Posts
    203

    Re: Detecting if program is in Design mode or running mode from inside a Add-In

    Quote Originally Posted by TysonLPrice View Post
    Here is a similar post you can check:

    http://www.vbforums.com/showthread.p...ing-in-the-IDE
    Not exactly the same, but thanks. Thats to detect if your current program is running, not the vb ide itselft.

  11. #11
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    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.
    Last edited by Elroy; Jul 23rd, 2019 at 01:03 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  12. #12

    Thread Starter
    Addicted Member shagratt's Avatar
    Join Date
    Jul 2019
    Location
    Argentina
    Posts
    203

    Thumbs up Re: Detecting if program is in Design mode or running mode from inside a Add-In

    Quote Originally Posted by Elroy View Post
    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!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width