Static Variables: A Special Type of Local Variable : Static variable « Language Basics « VBA / Excel / Access / Word





Static Variables: A Special Type of Local Variable

 
Private Sub cmdLocalAge_Click()
  Dim intAge As Integer
  intAge = intAge + 1
  Debug.Print intAge
End Sub
Private Sub cmdStaticAge_Click()
  Static sintAge As Integer
  sintAge = sintAge + 1
  Debug.Print sintAge
End Sub

 










Related examples in the same category

1.If you need a procedural level variable to retain its value between calls to the procedure, declare the variable using the Static keyword
2.Static variable lifetime
3.Redefine static variable