Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default How to display value of global variable?

I have a global variable in a module, outside any procedure, declared as:

Private cnt as Long

In the Immediate Window, I tried the command:

print cnt

to no avail. If I change Private to Public, the print command works. But I
want it to be Private.

FYI, the variable cnt is incremented by some procedures.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default How to display value of global variable?

PS....

I wrote:
I have a global variable in a module, outside
any procedure, declared as:
Private cnt as Long


Hmm, forgot to ask my question, which is....

How can I display its value while I am in the VBA editor, notably when I am
not at a breakpoint in a procedure that uses the variable?

Hovering the cursor over the global declaration did not work.


----- original message -----

"JoeU2004" wrote in message
...
I have a global variable in a module, outside any procedure, declared as:

Private cnt as Long

In the Immediate Window, I tried the command:

print cnt

to no avail. If I change Private to Public, the print command works. But
I want it to be Private.

FYI, the variable cnt is incremented by some procedures.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default How to display value of global variable?

HiJoe,

I believe that the reason it des not work is that Private restricts the
variable to the module in which it is declared. The Immediate window becomes
like another module. If you place a sub in the module in which it is declared
then you can print it to the immediate window.

Examples:-

Private cnt As Long

Sub test1()
cnt = 8
End Sub

Sub test2()
Debug.Print cnt
End Sub

--
Regards,

OssieMac


"JoeU2004" wrote:

PS....

I wrote:
I have a global variable in a module, outside
any procedure, declared as:
Private cnt as Long


Hmm, forgot to ask my question, which is....

How can I display its value while I am in the VBA editor, notably when I am
not at a breakpoint in a procedure that uses the variable?

Hovering the cursor over the global declaration did not work.


----- original message -----

"JoeU2004" wrote in message
...
I have a global variable in a module, outside any procedure, declared as:

Private cnt as Long

In the Immediate Window, I tried the command:

print cnt

to no avail. If I change Private to Public, the print command works. But
I want it to be Private.

FYI, the variable cnt is incremented by some procedures.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default How to display value of global variable?

"OssieMac" wrote:
If you place a sub in the module in which it is declared
then you can print it to the immediate window.


Well, duh! Shoulda thought of that myself. Thanks.


----- original message -----

"OssieMac" wrote in message
...
HiJoe,

I believe that the reason it des not work is that Private restricts the
variable to the module in which it is declared. The Immediate window
becomes
like another module. If you place a sub in the module in which it is
declared
then you can print it to the immediate window.

Examples:-

Private cnt As Long

Sub test1()
cnt = 8
End Sub

Sub test2()
Debug.Print cnt
End Sub

--
Regards,

OssieMac


"JoeU2004" wrote:

PS....

I wrote:
I have a global variable in a module, outside
any procedure, declared as:
Private cnt as Long


Hmm, forgot to ask my question, which is....

How can I display its value while I am in the VBA editor, notably when I
am
not at a breakpoint in a procedure that uses the variable?

Hovering the cursor over the global declaration did not work.


----- original message -----

"JoeU2004" wrote in message
...
I have a global variable in a module, outside any procedure, declared
as:

Private cnt as Long

In the Immediate Window, I tried the command:

print cnt

to no avail. If I change Private to Public, the print command works.
But
I want it to be Private.

FYI, the variable cnt is incremented by some procedures.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default How to display value of global variable?

Errata....

I wrote:
"OssieMac" wrote:
If you place a sub in the module in which it is declared
then you can print it to the immediate window.


Well, duh! Shoulda thought of that myself.


Oh yeah, I did eventually. I discovered y'hafta have forethought to do it
that way.

If you add a procedure to the module later, all variables are reinitialized
to zero (!), even Static variables in another procedure in the module.

I guess it's a good idea ;-) to always have a dummy Sub and Function whose
contents you can change.

I'm surprised that hovering the cursor over the declaration does not work.

Aha! I just stumbled on a way to get hovering to work; well, sorta. If I
set a breakpoint at the beginning of any procedure in the module, then
execute it and stop at the breakpoint, hovering over the Private module
variable shows its value.

Unfortunately, Reset'g to abort the stopped procedure also resets all
variables again. Sigh.

Anyway, thanks for your explanation of the root cause of the problem. I
guess there is no way to display Private module variables without
forethought.


----- original message -----

"JoeU2004" wrote in message
...
"OssieMac" wrote:
If you place a sub in the module in which it is declared
then you can print it to the immediate window.


Well, duh! Shoulda thought of that myself. Thanks.


----- original message -----

"OssieMac" wrote in message
...
HiJoe,

I believe that the reason it des not work is that Private restricts the
variable to the module in which it is declared. The Immediate window
becomes
like another module. If you place a sub in the module in which it is
declared
then you can print it to the immediate window.

Examples:-

Private cnt As Long

Sub test1()
cnt = 8
End Sub

Sub test2()
Debug.Print cnt
End Sub

--
Regards,

OssieMac


"JoeU2004" wrote:

PS....

I wrote:
I have a global variable in a module, outside
any procedure, declared as:
Private cnt as Long

Hmm, forgot to ask my question, which is....

How can I display its value while I am in the VBA editor, notably when I
am
not at a breakpoint in a procedure that uses the variable?

Hovering the cursor over the global declaration did not work.


----- original message -----

"JoeU2004" wrote in message
...
I have a global variable in a module, outside any procedure, declared
as:

Private cnt as Long

In the Immediate Window, I tried the command:

print cnt

to no avail. If I change Private to Public, the print command works.
But
I want it to be Private.

FYI, the variable cnt is incremented by some procedures.






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default How to display value of global variable?

at the start of the module put
OPTION PRIVATE MODULE

from HELP:
When a module contains Option Private Module, the public parts, for example,
variables, objects, and user-defined types declared at module level, are
still available within the project containing the module, but they are not
available to other applications or projects.

"JoeU2004" wrote:

I have a global variable in a module, outside any procedure, declared as:

Private cnt as Long

In the Immediate Window, I tried the command:

print cnt

to no avail. If I change Private to Public, the print command works. But I
want it to be Private.

FYI, the variable cnt is incremented by some procedures.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Global Variable dhstein Excel Discussion (Misc queries) 4 July 26th 09 05:10 PM
global variable not seen Scott Excel Programming 1 July 4th 07 04:11 PM
Global Variable Francis Brown Excel Programming 4 November 27th 05 06:38 PM
Global Variable Patrick Simonds Excel Programming 8 October 6th 05 12:39 AM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM


All times are GMT +1. The time now is 01:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"