Share this Page URL

Debugging: Your Key to Successful Development Sub Assertion() Dim intAge As Integer intAge = InputBox("Please Enter Your Age") Debug.Assert (intAge >= 0) MsgBox "You are " & intAge End Sub 611 This example sets the value of a variable called intAge equal to the value entered into an Input Box. The Debug.Assert statement "asserts" that the value entered is greater than or equal to zero. If it is, code execution proceeds as expected. If the assertion is incorrect, the code invokes the debugger. It is a good idea to include a comment as to why an assertion might fail. By doing this, you will facilitate the process of responding to the situation when it occurs. Also, it is important to realize that, if you deploy your application with Debug.Assert statements intact, you will receive a tech- nical support call when an assertion fails, and your code places the user in the debugger without warning! Debugging Tips The following tips will make your life much easier when debugging: · Before starting to debug, be clear about what the problem is. Make sure that you get all of the necessary information from the user as to what he did to generate the problem. Without this vital information, you can spend countless hours trying to reproduce the problem rather than solve it. · Make changes one line of code at a time. I have seen many hot-shot developers attempt to change multiple lines of code simultaneously. Instead of correcting the problem they initially set out to solve, they generate a multitude of additional problems.