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

Debugging Watch Window 2

Status
Not open for further replies.

Cowper

Programmer
Sep 18, 2002
29
AU
Hi, I am preparing for VB certification exam and have a question about debugging Watch window. I hope someone can me some input. The following is the code I tried to use Watch window to monitor. However, every time, I add variables counter and intNum into Watch window. The value column shows <Out of Context>. I know I should redefine the scope for these variables but how? Where have I done wrong?

*******************************
Private Sub Command1_Click()

Dim counter As Integer
Dim intNum(100) As Integer

For counter = 1 To 100
intNum(counter) = counter * 5
Me.ProgressBar1.Value = counter
Debug.Print counter
Next counter

Me.ProgressBar1.Value = Me.ProgressBar1.Min

End Sub


Thank you
Cowper
 
The code looks and works fine, I get 1 to 100 printed in the Immediate window(what you call watch)

> The value column shows <Out of Context>.

Are you referring to the printout in the Immediate Window?
 

To be able to use the watch window in this manner you have to place a break point some where in the loop or create a watch that will break when it becomes true.

Add a new watch (counter = 10, break when true) run and click on the command button. You will now see that the watches you have added are in context when it breaks.

Reason being that the program is running!, and you are in the sub where they are declared.

You can also get this information by using the locals window. Then watch window is great for only breaking on those hard to find errors.

Good Luck

??? 0 out of 20 and only 8 replies in the threads that you have started ??? Please read FAQ222-2244 item 15.


 
Ok, obviously I am confused. Whats the major advantages/use of the Watch window? (Now I have found it)
 
Hi, thank you both LPlates and vb5prgrmr. :)! I've found out where I did wrong -- I didn't place a break point in the loop. What an idiot I am!

As for LPlates' question about the major advantages/use of the Watch window, I can probably asnwer it by copying some words from the VB Certification book I am reading now -- The Watch Window &quot;allows you to specify which expressions to watch and returns information about their values as your program runs&quot;. For example, vb5prgrmr suggested me to set (counter = 10, break when true). By doing so, I can watch how variable Counter behaves when it reaches 10.

Cowper



 
I give you both a star, I didnt know it existed, excuse my ignorance :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top