none
Static Variables RRS feed

  • Question

  • Other than the theory of "STATIC VARIABLES" I am looking a pritical example of Static Varible which can explain in which scnerio we can use a STATIC VARIABLE and why.
    Thursday, March 10, 2016 7:14 PM

All replies

  • Hi, Kahn-Cann
     
    Static Variable:
     
    Variables do have a lifetime.

    Indicates that the local variable is preserved between calls.
    A static variable can be thought of as a local variable with memory.

    A static variable is a local variable whose lifetime is the lifetime of the entire module and not the procedure where it is declared.

    In fact static variables retain their values as long as the code module is active. There does not have to be any code running all the time.
    Therefore a static variable has the scope of a local variable but the lifetime of a module level variable. Makes a variable persistent even after the procedure has completed.
    The next execution of the routine can access the previous value. It is the lifetime of a variable that determines its existence, the scope determines its visibility.

    This is the forum to discuss questions and feedback for Excel for Developers, I'll move your question to the MSDN forum for Visual Basic for Applications (VBA)

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=isvvba

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, 
    and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. 

    Thanks for your understanding.
    Friday, March 11, 2016 2:39 AM