Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Freshen your debugging with ASSERTS (FAQ candidate)

Status
Not open for further replies.

foxdev

Programmer
Feb 11, 2000
1,995
US
If you're like most of us, you're used to putting in numerous <FONT FACE=monospace>WAIT WINDOW</font> and <FONT FACE=monospace>? MYVAR</font> statements throughout your code to try to track down problems.<br><br>Now that we have a decent debug/trace ability in VFP, you can set breakpoints and <FONT FACE=monospace>SET STEP ON</font> in various places.&nbsp;&nbsp;But sometimes the problem occurs infrequently, and you hate stepping through hundreds of lines of code.<br><br>Enter ASSERT.&nbsp;&nbsp;An ASSERT allows you to test an expression at runtime, and only notify you if the expression evaluates to false.&nbsp;&nbsp;As a bonus, it not only notifies you, but allows you to invoke the debugger at that point.<br><br>And as an extra special bonus:&nbsp;&nbsp;raise your hand if you've ever accidently left debugging code (like a <FONT FACE=monospace>WAIT WINDOW</font>) in an application that went into production.&nbsp;&nbsp;I've done it dozens of times, and its darn embarrassing.&nbsp;&nbsp;Fortunately, if you issue the command <FONT FACE=monospace>SET ASSERTS OFF</font> then ASSERT statements aren't executed at runtime.<br><br>Note that ASSERTS are OFF by default, so you'll have to turn them on by issuing the command <FONT FACE=monospace>SET ASSERTS ON</font>.<br><br>Some examples of using Asserts:<br><br><FONT FACE=monospace>nConnHandle = sqlconnect('myconnection')<br>assert nConnHandle&gt;0 message &quot;connection failed&quot;<br><br>select * from users where userid='FRED' into cursor curUsers<br>assert reccount('curUsers') &gt; 0 message &quot;no users found&quot;<br></font> <p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br>
 
On the SQL SELECT a frequent expression used is _TALLY.&nbsp;&nbsp;i suppose ASSERT is good here when it should and must return a cursor set?&nbsp;&nbsp;Robert, do you have any good info on the various aspects of the debug environment?&nbsp;&nbsp;watch, locals, event viewer, etc?&nbsp;&nbsp;I for one am way under speed on what all it provides.&nbsp;&nbsp;Do you use a DEFINE in your code or config file like #DEFINE DEBUGMODE .T.&nbsp;&nbsp;&& switch .T.¦.F.?<br>Thanks <p>John Durbin<br><a href=mailto: > </a><br><a href= Certified Professional VFP Programmer</a><br>ICQ VFP ActiveList #73897253
 
<FONT FACE=monospace>ASSERT _TALLY &gt; 0</font><br>would certainly be valid and often useful.<br><br>John, many of the tips-and-tricks of using the various debugging tools are visual in nature, so it is much easier to show someone than to explain it (&quot;click on the little bar to the right&quot;).&nbsp;&nbsp;Oh, if only we had some way of recording screen activity... <p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br>
 
Yes I've been searching for one.&nbsp;&nbsp;Found HyperCam but it like doubles my screen when played.&nbsp;&nbsp;Check it out at download.com.&nbsp;&nbsp;I just today downloaded Camtasia and SnagIt!&nbsp;&nbsp;Camtasia works!&nbsp;&nbsp;I'll try SnagIt next.&nbsp;&nbsp;Of course the co$t factor is an issue too&nbsp;&nbsp;:(&nbsp;&nbsp;&nbsp;I'm looking <p>John Durbin<br><a href=mailto: > </a><br><a href= Certified Professional VFP Programmer</a><br>ICQ VFP ActiveList #73897253
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top