Static Variables






Static Variables

Normally, the lifetime of a local procedure-level variable ends when the procedure ends. But sometimes you might want a variable to retain its value between each call into the procedure. Sometimes you might also want a million dollars, but you can't always have it. But you can have variables that keep their values if you want. They're called static variables. To declare a static variable, use the Static keyword in place of the Dim keyword.

Static keepingTrack As Integer = 0

The assignment of zero to keepingTrack is done only once, when creating the instance of the type that contains this statement. Thereafter, it keeps whatever value is assigned to it until the instance is destroyed. Static variables can be created only within procedures.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows