CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2001
    Posts
    19

    Run from devellopement environment

    hi there

    Is there a way to check if the program i'm writing runs from the devellopement environment or as exe? this would be great for debugging.

    thanks, daniel


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Run from devellopement environment

    There are various ways to check so. You could use the name of the executable executing the program. In the IDE, it should be VB5 or VB6.exe, in runtime, this should be the name of your program.
    Another way, much easier, is the following.

    public Function IsInDebug() as Boolean

    on error goto ErrHandler
    debug.print 1 / 0
    IsInDebug = false
    Exit Function

    ErrHandler:
    IsInDebug = true

    End Function

    'somewhere else
    If IsDebugging then
    Msgbox "Running in IDE"
    else
    Msgbox "Running compiled"
    End If



    What it does is it does a division by zero, so an error is raised and the function returns true. However, when compiled, all refferences to Debug are ignored, so the statement isn't executed, no error is raised, and the function returns false.

    Source: www.vbcodelibrary.co.uk

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Run from devellopement environment


    In a module bas, write a sub main() and make it the starting point of your app
    option Explicit
    private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (byval lpModuleName as string) as Long
    public RunningInIde as Boolean

    Sub Main()
    Dim RunningInIde as Boolean
    If App.StartMode = vbSModeAutomation then '=1=Activex component
    Exit Sub
    ElseIf App.StartMode = vbSModeStandalone then '=0= as standalone or within IDE
    #If Win32 then
    If GetModuleHandle("VB32.EXE") Or GetModuleHandle("VB6.EXE") then
    RunningInIde = true
    End If
    #else
    If GetModuleHandle("VB.EXE") then RunningInIde = true
    #End If
    If RunningInIde then
    'your code for running from VB ambient
    else
    'your code for running as standalone
    End If
    End If
    End Sub




    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Feb 2001
    Posts
    19

    Re: Run from devellopement environment

    wow, cool idea! thanks!

    daniel


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

Featured