+ Reply to Thread
Results 1 to 6 of 6

Globals are cleared by ending code ("run/reset"); what else happens?

  1. #1
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Globals are cleared by ending code ("run/reset"); what else happens?

    I just put a breakpoint on End Sub, went alt-R,R, and now MyGlobalString is "" whereas had I instead gone F5 or F8 it would be "foo" as assigned earlier. (The variable was defined atop the module, public MyGlobalString as string) Also, a form control's value that normally would persist when I .Show'd the form again is lost by breaking and ending code.

    Are there other implications of terminating code? I always thought that all I had to worry about was restoring states like Calculation mode and closing things that obviously need to be closed. What else happens?

    ( And while I'm thinking about it, I wonder which "state" variables do I really need to worry about restoring anyway? I seem to observe that some always return to normal regardless of how code ends (.ScreenUpdating) and some don't (.Calculation). )

    I do note on https://msdn.microsoft.com/en-us/vba...tart-execution
    "You can restart execution from break mode. Restarting returns the code to a newly initialized state, resetting all variables and removing any suspendedprocedures from memory." (By "restarting" it means to restart code by alt-R, R and then running code again)
    Chip, if you can read this, you're STILL making the world a better place with your immeasurably valuable gifts. Every week, you continue to help me (and untold numbers of others) tremendously. Practically no alternative outlets can match your effectiveness, even over the vast number of topics you demystify and empower usage of. You were, and still are, amazing.

  2. #2
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: Globals are cleared by ending code ("run/reset"); what else happens?

    I've reset code a million times in my life. Another million times I've effectively done so by hitting alt-F4 when in break mode (thus asking to close the VBA window) and "OK" to the messagebox warning me that code will end. Now I'm thinking - after religiously doing it one way for 2 million times - if I should just go to the immediate window and type end and hit enter instead?!

  3. #3
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: Globals are cleared by ending code ("run/reset"); what else happens?

    Errrr, no, executing End does the same thing. And you can't go Exit Sub in the immediate window. Looks like I have to awkwardly highlight "End Sub" and set as next statement and run. Is that really what is required to preserve static variables?

  4. #4
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: Globals are cleared by ending code ("run/reset"); what else happens?

    So I end up with 3 questions:
    1. What else happens besides static variable clearing when you reset code?
    2. What "state" variables persist on normal termination, yet change on code reset?
    (bonus: what state variables don't persist anyway, e.g. .ScreenUpdating ?)
    3. Is there a better way to "normally" terminate code, preserving statics, than the cumbersome "setting next statement" ?

  5. #5
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: Globals are cleared by ending code ("run/reset"); what else happens?

    Bump .

  6. #6
    Registered User
    Join Date
    05-20-2017
    Location
    Saint Louis, USA
    MS-Off Ver
    2016 PC, 2016 Mac
    Posts
    6

    Re: Globals are cleared by ending code ("run/reset"); what else happens?

    I've run into this same problem before in both Excel and Access.

    The best way I've been able to get around it is putting a label one line above End Sub, and then dragging around a "Goto GetOut" statement to wherever I am debugging.

    It's annoying to do. I'd love to know if there's a better way.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 02-05-2019, 12:03 AM
  2. [SOLVED] Replace all values with "0" ending to the value with "5" ending
    By mgecelov in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-04-2017, 02:39 PM
  3. VBA code doing the same as manually pressing the "Reset" Button
    By excel_drives_crazy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-20-2015, 05:58 PM
  4. Macro to search a string ending with vowel "AEIOUY"
    By kitunga in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-02-2014, 02:37 PM
  5. [SOLVED] help with retaining formats in a range that is "cleared"
    By jmac1947 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2014, 11:07 PM
  6. SUMIFS Function To Reset SUM if "x" is placed to "0" ??
    By Exceldummy101 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-15-2013, 04:45 PM
  7. Replies: 3
    Last Post: 04-24-2006, 01:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1