![]() |
#1
|
|||
|
|||
![]() 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? |
#2
|
|||
|
|||
![]() Quote:
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. |
#3
|
|||
|
|||
![]()
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. |
#4
|
||||
|
||||
![]()
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 |
#5
|
|||
|
|||
![]()
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 |
#6
|
|||
|
|||
![]()
Once you have this done, you may want to change those from public variables.
|
#7
|
|||
|
|||
![]() Quote:
![]() |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
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 |