Assert Command

Purpose

Debugging command that halts program execution if an expression is not true.

Syntax

[Debug].Assert boolexp

boolexp:Any valid Boolean expression that evaluates to true (nonzero) or false (0).

Description

The Assert command is intended for use in debugging and by default works only in the IDE and it stops the program execution if the expression evaluates to 0.
Its normal use is to check the correct value of the variables during debugging.

When the expression evaluates to False (0) a message box is displayed showing the entire line of code.

Assert x! <> 0              ' 0 not allowed for x!

Assert i >= 9 && i <= 27    ' i can not be between 9 and 27 inclusive

Assert DllVersion("") = 2.2 ' Wrong GfaWin23.OCX runtime

The title of the message box is 'Assert:<ProgName>'.
The message box text is the entire Assert code line, including the comments, and the name of the procedure.

Remarks

Assert can not be used to display the contents of a variable.

Assert is a shortcut for Debug.Assert, a method of the Debug object like Trace and Print. By default the Debug object is disabled for final executables, but it can be enabled through the Compiler tab in the Properties dialog.

See Also

Debug, Trace

{Created by Sjouke Hamstra; Last updated: 23/09/2014 by James Gaite}