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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extend Debug Knowledge

Status
Not open for further replies.

ftook

Programmer
Dec 4, 2006
80
GB
I am in the throws of developing a couple of small access solutions for 2 companies and am thoroughly enjoying the programming and learning stages (with the help of this forum aswell), but i beleive that i am not best utilising the debug facilities to assist me. Is there any tutorial / tips on how best to debug the code (ie have trouble seeing where immediate window can best be used).

 
I use the immediate window for the following purposes?

1. Viewing variables not in the watch window with
? VariableName

2. Setting variables to values to check unexpected values cases to trigger error handlers where they would not ordinarily run. Eg
Variable = "Value"
This can also be used with assignment statements and function calls, eg:

dblResult = FunctionCall (Var1, Var2, Var3)
Debug.Print dblResult

3. Using Debug.Print messages within your VBA code to show additional error messages or values of variables or code evaluation over and above that you would display to the users. This can help you work out exactly what is going wrong/

eg:
Debug.Print "MyVar=" & MyVar

John
 
ftook,

jrbarnett gives some excellent examples. I will amplify on one:
Debug.Print "MyVar=" & MyVar
This can be extremely useful when you are concatenating pieces of a SQL statement. To print the entire string in the immediate window can often reveal a syntax error, or why the SQL is not returning what you expected.

HTH,

Ken S.
 
I always make sure I have the statement Option Explicit in my code declarations bit. That soon throws up when there is a variable undeclared. I also use the Debug/Compile New function when I have the code window open, that also throws up some problems for me. Hope its of help.
 
How are ya ftook . . .

One of the biggest help secnarios available to you is setting [blue]break points[/blue] and stepping thru code (line by line) there after! Running code stops at a break point and you can continue (line by line) tracing your code.

Then there's [blue]watches[/blue]. Using a break point to stop code execution [blue]you can see the values of variables and expressions as you traverse thru code[/blue] (single step).

These are the main two tools used by programmers when they have a problem.

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top