ASSERT Command

Displays a message box when a logical expression evaluates to False (.F.).

When the condition stipulated in the ASSERT command evaluates to False (.F.), an assert message box displays and echoes to the Debug Output window in the Debugger.

Note

ASSERT is disregarded in applications you distribute.

ASSERT lExpression [MESSAGE cMessageText]

Parameters

  • lExpression
    Specifies the logical expression to evaluate. If lExpression  evaluates to a logical False (.F.), a debugging dialog box displays. If lExpression  evaluates to a logical True (.T.), the dialog box does not display.

  • cMessageText
    Specifies the text to display in the debugging dialog box. If you omit cMessageText, the default text displays and indicates the line number on which the assertion failed and the procedure containing the assertion.

Remarks

You can specify whether assert messages display by setting the SET ASSERTS command. For more information, see SET ASSERTS Command.

The message box that displays contains Debug, Cancel, Ignore, and Ignore All buttons. The following table describes the action performed when choosing each button.

Button

Description

Debug

Suspends program execution and displays the Debugger window with the Trace window active.

Cancel

Ends program execution.

Ignore

Continues program execution with the line following the ASSERT command.

Ignore All

Continues program execution with the line following the ASSERT command and sets SET ASSERTS to OFF. Disregards subsequent ASSERT commands until SET ASSERTS is set to ON.

Example

Suppose you create a function that expects a nonzero parameter value. The following line of code in the function alerts you if the value of the parameter is 0:

ASSERT nParm != 0 MESSAGE "Received a parameter of 0"

See Also

Concepts

Debugging Before Bugs Exist

Reference

Debugger Window

Other Resources

Commands (Visual FoxPro)

Language Reference (Visual FoxPro)