We help IT Professionals succeed at work.

Why Declare local variables as statics?

In the attached dialog box, there's an option to declare local variables as statics.  
1.  What's a static?
2.  Why declare local variables as statics?
Watch Question

Martin Liss"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018

A variable that is defined in a procedure is normally initialized every time the procedure is executed. If the variable is Static it retains its value until change by code.

Static MyVar As String
Top Expert 2012
So that you can keep control of each variable, it is best practice to declare variables a local as possible. Global (Public) variables can be modified by any process in the project, and in complex applications it is possible to lose track of what it was that unexpectedly changed the value of a particular variable.

However you may want to use a procedure many times and to remember the previous value of a particular variable. Rather than declare it as Global, it can be declared as Static. Thus it can only be modified by the procedure in which it is declared, but the value is still remembered whenever that procedure is executed.