Article ID: 161153 - View products that this article applies to.
This article was previously published under Q161153
The Assert method of the Debug object allows monitoring of an expression for failure conditions.
The following syntax is used for the Assert method:
Debug.Assert (expression)The Assert method syntax has the following object qualifier and part:
The Assert method forces a design-time break at the Assert statement when the expression evaluates to False. If the expression evaluates as True, program operation continues. For example:
Part Description ---- ----------- Debug Required. The Assert method only applies to the Debug object. expression Required. Any logical expression.
If you call myFunction as:
the program continues as normal. However, passing a zero as any one of the parameters forces a break. The following example breaks at the Assert statement:
The above example allows testing for inappropriate parameters to protect against a division by zero error. If a break occurs at the Assert statement, you can check the locals window to determine which value is inappropriate. This is especially useful when the argument values come from other functions:
The Assert method is only used for debugging. During compiling, Microsoft Visual Basic always removes Assert statements from the final code. There is no workaround for this behavior.
Article ID: 161153 - Last Review: July 13, 2004 - Revision: 3.1
Contact us for more help
Connect with Answer Desk for expert help.