Assert Method
Conditionally suspends execution at the line on which the method appears.
Syntax
object.Assert booleanexpression
The Assert method syntax has the following object qualifier and argument:
| Part | Description |
|---|---|
| object | Required. Always the Debug object. |
| booleanexpression | Required. An expression that evaluates to either True or False. |
Remarks
Assert invocations work only within the development environment. When the module is compiled into an executable, the method calls on the Debug object are omitted.
All of booleanexpression is always evaluated. For example, even if the first part of an And expression evaluates False, the entire expression is evaluated.
Example
The following example shows how to use the Assert method. The example requires a form with two button controls on it. The default button names are Command1 and Command2.
When the example runs, clicking the Command1 button toggles the text on the button between 0 and 1. Clicking Command2 either does nothing or causes an assertion, depending on the value displayed on Command1. The assertion stops execution with the last statement executed, the Debug.Assert line, highlighted.
|