Static Statement

Syntax

Static varname[([subscripts])] [As [New] type] _
       [,varname[([subscripts])] [As [New] type]] . . .

varname

Use: Required

Data Type: Any

The name of the variable, following Visual Basic naming conventions.

subscripts

Use: Optional

Data Type: Long Integer

Denotes varname as an array, and specifies the number and extents of dimensions of the array.

New

Use: Optional

Type: Keyword

Used to automatically create an instance of the object referred to by the object variable varname.

type

Use: Optional

Type: Keyword

Data type of the variable varname.

Description

Used at procedure level to declare a static variable and allocate the relevant storage space in memory. Static variables retain their value between calls to the procedure in which they are declared.

Rules at a Glance

  • A static variable's scope is limited to the procedure in which it's created.

  • The subscripts argument has the following syntax:

    [lowerbound To] upperbound [, _
    [lowerbound To] upperbound]
  • Using the subscripts argument, you can declare up to 60 multiple dimensions for the array.

  • The lowerbound argument of the subscripts argument is optional. When not used, the lower bound of the array is specified by the Option Base statement. If Option Base has not been used, the lower bound of the array is zero.

  • If the subscripts argument isn't used (i.e., the variable name is followed by empty parentheses), the array is declared as dynamic. You can change both the number of dimensions and number of elements of ...

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.