An Introduction
Why would you want to use Assertion Checking?
──────────────────────────────────────────────────────────────────────────────

The simple reason is so that you can make sure that your variables are being
delivered to where they should go. Assertion checking does this by allowing
you to check that you are at least passing the correct number of variables
around your system without any silly errors creeping in such as
typographical errors, incorrect variable types or possibly even commas
missing in a list of parameters being passed down.

Think of Assertion checking as another layer of added protection for your
program.

Assertion checking is not going to catch every single error that could
possibly occur, but it will help you to cut down on those odd errors that
normally creep in during the development cycle.

The easiest form of Assertion checking is with the variable list in the
FUNCTION declaration statement. For Example, let us suppose that we start of
with a function:

FUNCTION DrawBox( nTop, nLeft, nBottom, nRight )

@ nTop, nLeft, nBottom, nRight BOX B_DOUBLE

RETURN( NIL )

This looks fine as long as you pass the correct parameters then this will
draw a box on the screen. Now let's just say that you'd accidently mis-typed
something and instead called the function as:

DrawBox( 1, 1,,10, 10 )

Please note the extra comma between the 1 and the 10 - a common enough
typing mistake that can cost time trying to track down. When this runs,
nothing will happen, the program will not fall over, there will be no screen
output - so how are you supposed to know if something has gone wrong?

There is an easier way than tracing through each line of code watching for
something not happening!

Take a look at the following function, an enhancement on the previous one:

FUNCTION DrawBox( nTop AS INT, nLeft AS INT, nBottom AS INT, nRight AS INT )

@ nTop, nLeft, nBottom, nRight BOX B_DOUBLE

RETURN( NIL )

Notice that each variable in the function declaration parameter list has the
words AS INT after them. These signify that if any parameters that are
passed down to this function are not integers then flag them as an error.

Now, when this function is called using the following function call:

DrawBox( 1, 1,,10,10)

Instead of nothing happening, the program will halt with an Assertion
Break warning message in the MrDebug's command window and an entry in the
Assert/ Trace Window with the Time the function was called, the filename the
function is in, the name of the function that was called, the line number
and a message, such as Param 2 is not type INT.

From this we can see precisely what has happened i.e., why the assertion
occurred. At this point your options are open - you could quit out, load
your editor correct the mistake, re-compile, re-link and re-run the program
- NOT!

You could instead, press <Shift><Alt><N>, make a note of the problem, make
the necessary changes to the variables within the variable and continue on
with the program - the easy life!

And much later when you have finished running your program, with the use of
the notes that you made earlier go into your source code and make the
necessary changes to correct the source code all in one go.