Results 1 to 4 of 4

Thread: [RESOLVED] Detect whether in debug mode

  1. #1

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Resolved [RESOLVED] Detect whether in debug mode

    Hi all,

    how could I detect in code whether I'm running the executable or whether I'm running my project from the .NET IDE? Does someone have a coding example for me?

    Thanx in advance,

    Marco

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Detect whether in debug mode

    You use conditional compilation to compile different code depending on whether you are in Debug or Release:
    VB Code:
    1. #If DEBUG Then
    2.         MessageBox.Show("Debug")
    3. #Else
    4.         MessageBox.Show("Release")
    5. #End If
    Note that this If statement is NOT executed at run time. Depending on whether you are compiling a Debug or Release build, only one of the MessageBox lines will be compiled into your executable.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Re: Detect whether in debug mode

    Quote Originally Posted by jmcilhinney
    You use conditional compilation to compile different code depending on whether you are in Debug or Release:
    VB Code:
    1. #If DEBUG Then
    2.         MessageBox.Show("Debug")
    3. #Else
    4.         MessageBox.Show("Release")
    5. #End If
    Note that this If statement is NOT executed at run time. Depending on whether you are compiling a Debug or Release build, only one of the MessageBox lines will be compiled into your executable.
    So 'DEBUG' is a keyword, and not a private declared variable, according to your code? In that case, solved and many thanx...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Detect whether in debug mode

    No, DEBUG is not a keyword. It is a conditional compilation constant. Open the Property Pages for your project and take a look at the Configuration Properties -> Build section. If you change the configuration between Release and Debug you will see that by default DEBUG and TRACE are defined for the Debug configuration but only TRACE is defined for the Release configuration. You can also define your own constants. I have an application that I have customised for one particular customer. I defined a conditional compilation constant to control which code gets compiled. When the constant is defined the custom code is compiled into the build. If the constant is not defined then the normal code gets compiled. You can create addtional configurations for your project other than just Release and Debug that include different settings, including these constants. You then just change the configuration on the toolbar and voila.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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