Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there an 'if in Debug mode...' ?

Status
Not open for further replies.

Brawn

Programmer
Jul 5, 2001
73
0
0
CA
I want to raise an error if in debug mode but do something else if not.

I know theres a way, I just don't know what it is.

I DON'T want to set a global variable and have all my code check to see whether it is true or not becuase I want my objects as reusable as possible.

Any thoughts, [smile] Brawn

- The difference between genius and stupidity is that genius has its limits -
 
I am not sure if this is what you are looking for but I use a global variable (g_bDebug As Boolean) and set the value to true if I want to debug and false if I do not. Then I use the variable when I need to do what ever debug function I would like. Hope this helps. Anything is possible, the problem is I only have one lifetime.
[cheers]
 
I don't think that VB supports a compiler directive for Debug like you will find in C. I am in agreement with foada, the use of a global variable, or global constant, works quite well.

For example, I have at the beginning of every routine the following statment.

If (gBol_UseErrorHandler) Then
On Error GoTo HandleError
End If

During development gBol_UseErrorHandler is usually false, but its turned on when the app goes into production.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
You can use compiler predirectives to conditionally decide what code is included in the final compiled version-- depending on the state of the DEBUG_MODE, only one of the code segments is included in the executable:

' set the DEBUG_MODE in a module
#Const DEBUG_MODE = true

#If DEBUG_MODE Then
'Show error to user
#Else
'Log error and exit gracefully
#End If


Mark

The law, in its majestic equality, forbids the rich, as well as the poor, to sleep under the bridges, to beg in the streets, and to steal bread.

Anatole France
 
Here is such a simple way that you will kick yourself...but I'm a simple guy.

Private Function IsDesignTime() As Boolean
Dim blnDesignTime As Boolean
' If not debug then blnDesignTime will be false
Debug.Assert (SetDesignTime(blnDesignTime) = True)
IsDesignTime = blnDesignTime
End Function

Private Function SetDesignTime(ByRef blnDesignTime As Boolean) As Boolean
blnDesignTime = True
SetDesignTime = True
End Function Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Also, to cut down on RELEASE code. Do not use #Const. Use Global Conditional Compile i.e. entire project, not just module level.


#If blnDebug then
For I = 0 To .....
...
Next
#End if

Go to Project Properties / Make and enter Conditional Compilation Arguments.
blnDebug = -1: blnWhatever = -1

-1 = true, 0 = false.

Be sure to set the debug arguments = 0 for RELEASE compile. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top