How to check for debug mode in VB2010?

JumpyNET

Centurion
Joined
Apr 4, 2005
Messages
196
How can check for debug mode in VB2010?

In VB2008 Express I could determine whether I was running the app from the debugger or the release version like this:
[Vb]
#If Debug Then
'My code here...
#Else
'Alternative code here...
#End If
[/Vb]
But in VB2010 Express this no longer works and when running my app from the VS IDE (F5) it always jumps to the else part.
 
The #If Debug Then statement will equal true at compile time if it is a debug build, this won't be effected by a debugger being attached or not.
But it seems like it never equals true.

The problem is that using the code below never shows the message box on my computer when using VB2010.
[Vb]
#If Debug Then
MsgBox("TESTING")
#End If
[/Vb]
 
I tried the same with a brand new project and there it seems to work. The problem must be related to converting the original VB2008 project to VB2010.
 
If you look under the "Compile" tab in the project properties, there is an "Advanced Compile Options..." button. In the window that comes up, there is a check box marked "Define DEBUG constant". As long as this is checked, I don't see why things shouldn't work as expected.
 
Back
Top