You are currently offline, waiting for your internet to reconnect

How To Use the Assert Method for Debugging

This article was previously published under Q161153
This article has been archived. It is offered "as is" and will no longer be updated.
The Assert method of the Debug object allows monitoring of an expressionfor 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:
      Part            Description      ----            -----------      Debug           Required. The Assert method only applies to the                      Debug object.      expression      Required. Any logical expression.				
The Assert method forces a design-time break at the Assert statement whenthe expression evaluates to False. If the expression evaluates as True,program operation continues. For example:
      Function myFunction (x as Long,y as Long, z as Long) as Long          Debug.Assert (x<>0 And y<>0 And z<>0)          myFunction = 1/x + 1/y + 1/z      End Function				
If you call myFunction as:
      q = myFunction (1,2,3)				
the program continues as normal. However, passing a zero as any one of theparameters forces a break. The following example breaks at the Assertstatement:
      q = myFunction (1,0,3)				
The above example allows testing for inappropriate parameters to protectagainst a division by zero error. If a break occurs at the Assertstatement, you can check the locals window to determine which value isinappropriate. This is especially useful when the argument values come fromother functions:
     q = myFunction ( calcX(), calcY(), calcZ() )				
The Assert method is only used for debugging. During compiling, MicrosoftVisual Basic always removes Assert statements from the final code. There isno workaround for this behavior.
kbVBp500 kbVBp600 kbVBp kbdsd kbDSupport kbNoKeyWord

Article ID: 161153 - Last Review: 12/04/2015 15:56:37 - Revision: 3.1

Microsoft Visual Basic 6.0 Learning Edition, Microsoft Visual Basic 6.0 Professional Edition, Microsoft Visual Basic 6.0 Enterprise Edition, Microsoft Visual Basic 5.0 Control Creation Edition, Microsoft Visual Basic 5.0 Enterprise Edition

  • kbnosurvey kbarchive kbhowto KB161153