INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Debugging and Tuning

How do I use ASSERTS to test for errors? by foxdev
Posted: 7 Jun 00

If you're like most of us, you're used to putting in numerous WAIT WINDOW and ? MYVAR statements throughout your code to try to track down problems.

Now that we have a decent debug/trace ability in VFP, you can set breakpoints and SET STEP ON in various places.  But sometimes the problem occurs infrequently, and you hate stepping through hundreds of lines of code.

Enter ASSERT.  An ASSERT allows you to test an expression at runtime, and only notify you if the expression evaluates to false.  As a bonus, it not only notifies you, but allows you to invoke the debugger at that point.

And as an extra special bonus:  raise your hand if you've ever accidently left debugging code (like a WAIT WINDOW) in an application that went into production.  I've done it dozens of times, and its darn embarrassing.  Fortunately, if you issue the command SET ASSERTS OFF then ASSERT statements aren't executed at runtime.

Note that ASSERTS are OFF by default, so you'll have to turn them on by issuing the command SET ASSERTS ON.

Some examples of using Asserts:

nConnHandle = sqlconnect('myconnection')
assert nConnHandle>0 message "connection failed"

select * from users where userid='FRED' into cursor curUsers
assert reccount('curUsers') > 0 message "no users found"


The message clause is optional, but is suggested because the default message is assert failed, which is not terribly descriptive.

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close