remember values from the execution of one procedure to the
next.
In some cases, a public variable can accomplish exactly
what a static variable can, but good programming dictates that
you use the most restrictive scope available. The following
code demonstrates the differences:
'at the module level
Public iState As Integer
Sub PublicVariable()
iState = iState + 1
MsgBox iState
End Sub
Sub StaticVariable()
Static iVar As Integer
iVar + 1
MsgBox iVar
End Sub
Note:Make sure you follow consistent variable naming conven-
tions. The most common convention calls for the first one to three
characters to describe the type of variable, followed by a meaning-
ful variable ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.