Placing checks inside the code
A Diagnostic Message Generator!
──────────────────────────────────────────────────────────────────────────────

Another powerful command that you can use is the ASSERT command. The ASSERT
command will enable you to test for an expression. If the expression fails,
then the ASSERT command sends a diagnostic message to the Assert/Trace
Window and halts the execution of the program and hands control over to
MrDebug.

As long as the expression evaluates to a true (.T.) then no action is taken
and the program continues happily on it's way, unaware that any low-level
checking routines have taken place.

ASSERT may be used to cure a multitude of sins. Perhaps an obvious usage for
it can be ensure that something in your code is as it should be.

ASSERT nTax == 0.175

With this line of code before an important set of calculations, you could
rely on the fact that the tax rate multiplier will be .175 when the
calculations start because if they are not, then this ASSERT line will flag
the problem, and signal MrDebug that the assertion failed.

Please note that if you use an expression that does not equate to a logical,
such as:

ASSERT lAddTax

where, in this case, lAddTax has not been initialized then you will get a
run-time error when this is executed - because the code is gibberish.

If however, you had already initialized lAddTax to .T. then this would sail
through perfectly well - evaluating lAddTax would return .T..

You could take this one step further by first making sure that the variable
was a logical value with:

ASSERT lAddTax AS LOGICAL

followed by:

ASSERT lAddTax

which would make sure that lAddTax was .T. at this point.

However please note that sometimes you may want lAddTax to be .F., so you
may not want to place an Assertion here unless you wanted to know when
lAddTax was .F. - this could come in handy as a debugging tool to work out
why a variable was not a particular value.

The following example demonstrates how to check that a calculation is
correct:

nGross := (nTax * nNett)
nTaxAmount := nGross - nNett

ASSERT nTaxAmount + nNett == nGross

The above line can be seen to be a double check to ensure that the
calculation is correct.