Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-07-2020, 06:30 AM
John 4 John 4 is offline Make Watch list variables available to all procedures? Windows 10 Make Watch list variables available to all procedures? Office 2013
Advanced Beginner
Make Watch list variables available to all procedures?
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default Make Watch list variables available to all procedures?

I often use the same variable names in more than one procedure (especially when I have a macro broken up into different subs/procedures for debugging before adding them all together). So for example, I might be using "Rng1" and "Rng2" in 3 or 4 different subs.

The Watches list appears to give me the option of having them all available for whatever sub I happen to be running at any given time. i.e. if I right-click on the variable name in the watch list and click 'Edit Watch' a window opens where I can select "Context - All Procedures".

However, when I do so and step through the sub with the F8 key, the Watch list window says (beside the variable name) "Expression not defined in context". This happens regardless of whether the "Module" section of the Edit Watch window has the module name selected (in which are the various subs), or whether "All Modules" is selected.

What am I doing wrong?
Reply With Quote
  #2  
Old 12-07-2020, 11:18 AM
Charles Kenyon Charles Kenyon is offline Make Watch list variables available to all procedures? Windows 10 Make Watch list variables available to all procedures? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,116
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
What am I doing wrong?
Nothing, but the variable you place in the watch list is, I believe, the one from the procedure in which it was originally found. That is, it is the variable itself, not a variable of that name in the current procedure.

If your variable is declared as public and persistent outside the procedure in which you are using it, that may be a different situation. (like you, I am an advanced beginner when it comes to coding)

Last edited by Charles Kenyon; 12-08-2020 at 08:35 PM.
Reply With Quote
  #3  
Old 12-07-2020, 02:20 PM
John 4 John 4 is offline Make Watch list variables available to all procedures? Windows 10 Make Watch list variables available to all procedures? Office 2013
Advanced Beginner
Make Watch list variables available to all procedures?
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default

Thanks Charles,
I think I get it. The context options of 'Procedure' and 'Module' in the Edit Watch window seem to be more for restricting than expanding the visibility/signification of variable names.

I'm sure Andrew's rolling his eyes after he already helped me on my understanding of variables

But I'm getting there. Thanks again.
Reply With Quote
  #4  
Old 12-07-2020, 07:52 PM
Guessed's Avatar
Guessed Guessed is online now Make Watch list variables available to all procedures? Windows 10 Make Watch list variables available to all procedures? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

No eye rolling from me today. I don't usually use Watch as it is rarely useful to me and I tend to add Debug.Print statements or hover over things if I need to see what their values are.

I do use them for arrays though when my usual methods are too clunky.

If you have defined the same name in multiple subs/functions then the context will be super important and I would be using global variables if that was the case.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 12-09-2020, 03:20 AM
John 4 John 4 is offline Make Watch list variables available to all procedures? Windows 10 Make Watch list variables available to all procedures? Office 2013
Advanced Beginner
Make Watch list variables available to all procedures?
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default

Hi Andrew.
Yes, it's arrays I'm working with at the minute, so the Watch window is very useful. And using either global variables or private module-level variables has taken care of the problem.

It beats repeatedly deleting Rng1, Rng2, and Rng 3 (or Str1, Str2, and Str3) from the Watch list for Sub 1, and adding them again to the list for Sub 2, etc. A laptop screen doesn't leave a huge amount of space for the Watch window.

Thanks for your advice
Reply With Quote
  #6  
Old 12-09-2020, 04:55 PM
Charles Kenyon Charles Kenyon is offline Make Watch list variables available to all procedures? Windows 10 Make Watch list variables available to all procedures? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,116
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Once you have this done, you may want to change those from public variables.
Reply With Quote
  #7  
Old 12-09-2020, 07:26 PM
John 4 John 4 is offline Make Watch list variables available to all procedures? Windows 10 Make Watch list variables available to all procedures? Office 2013
Advanced Beginner
Make Watch list variables available to all procedures?
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
Once you have this done, you may want to change those from public variables.
Yeah, I'll cut and paste them from the top of the module to the top of the sub when everything's done and all the subs are added together. Thanks Charles
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Make Watch list variables available to all procedures? Best way to make variables in one sub available to a called sub Jennifer Murphy Word VBA 2 02-29-2020 12:18 AM
Why isn't watch list sorted? Jennifer Murphy Word VBA 0 02-23-2020 08:20 PM
Onenote and Apple watch Powell64 OneNote 0 06-04-2017 03:00 PM
Array to iterate through variables and trap blank variables Marrick13 Word VBA 5 08-04-2015 06:19 AM
can word: make variables, find appropriate pages, fill out pages with variables, print only those 20GT Word VBA 1 10-15-2014 09:48 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:27 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft