Differentiating Debug or Release

ayozzhero

Well-known member
Joined
Apr 6, 2005
Messages
186
Location
Malaysia
Programming Experience
1-3
Is there anyway to detect during runtime whether the app is running under Debug mode or Release mode?

My actual problem is, I create one or two test button on a form. I want the buttons to appear when I run the app in Debug mode (on other words, when I click Run/Play button in VB .Net) and dissappear (hidden & disabled) in Release mode.

Thank you for helping
 
VB.NET has a C-style preprocessor that can execute conditional compilation:
VB.NET:
	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
#If DEBUG Then
		Me.Button1.Visible = True
#Else
		Me.Button1.Visible = False
#End If
	End Sub
Default constants are CONFIG, DEBUG and TRACE but you can also define your own. Go to the project properties and select Configuration Properties -> Build.

Edit:
Notice that in the properties for the Debug configuration the "Define DEBUG constant" option is checked, while it is not for the Release configuration.
 
Sometimes things are so simple and easy, yet we need some knowledge to accomplish it, otherwise it is still far beyond reach.

Thanks a lot for your help jmcilhinney :)
 
I'm sure that a great many VB.NET developers, and the vast majority of inexperienced ones, know nothing about conditional compilation. I don't think I've ever heard it mentioned on a forum anywhere. My background is C/C++ so when I saw #region in VB.NET I just thought I'd try #somethingelse and see what happened. You'll notice that typing a # automatically moves to the far left-hand side, where preprocessor directives (as they are called in C) are usually written.
 
I knew that .NET had conditional preprocessors in them, but I didn't know that DEBUG was auto created when in Debug setting. Pretty cool. Most VB developers in general don't know any thing about preprocessors. With a C (ANSI) and Pascal background, not having preprocessors realy drove me mad when moving to VB (back in the VB3 days).

Tg
 
Back
Top