LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default unwanted reinitialization of global variables

You're right. I work so much in the IDE that I got tired of finding my
variables reset by my debugging and I got in the habit of initializing them
as necessary.

"Dave Peterson" wrote:

You don't need the Call keyword, but it doesn't hurt. I like it.

I'd also add a check to see if re-initializing the variables was required (as
you saw).

But I don't understand your point about why/how the variables are reset. Those
public and static variables don't get reset just because the code isn't running.

Charlie wrote:

It's not about "No code is running", it's "code is NOT running" that resets
the variables. I learned the hard way: I don't bother with initializing much
in the Workbook_Open event anymore. I put my initializations at the
beginning of every event as necessary (and you don't need the "Call"
keyword), e.g.

Private Sub Worksheet_Activate()

InitializeVars
...Do Stuff

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

InitializeVars
...Do Stuff

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

InitializeVars
...etc.

End Sub

" wrote:

But then again... No code is running between the execution of the
Workbook_Open event and the execution of Routine2. Maybe that was not
the answer after all.




--

Dave Peterson

 
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 variables Ed Excel Programming 6 November 19th 06 10:55 PM
global variables Nicolas Roth Excel Programming 3 September 25th 06 04:40 PM
Global Variables [email protected] Excel Programming 0 July 7th 06 10:53 AM
Global Variables mattsvai[_11_] Excel Programming 4 February 3rd 06 05:02 PM
Global Variables Francis Brown Excel Programming 9 November 27th 05 06:14 PM


All times are GMT +1. The time now is 01:20 PM.

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"