Dim Statement


[Overrides] [Shadows] Dim [WithEvents]varname[([subscripts])] _
             [As [New] type] [= initexpr]

Use: Optional

Type: Keyword

In a derived class definition, indicates that a variable overrides a similar variable in a base class


Use: Optional

Type: Keyword

In a derived class definition, indicates that calls to derived class members that are made through a base class ignore the shadowed implementation


Use: Optional

Type: Keyword

In an object variable definition, indicates that the object will receive event notification


Use: Required

Your chosen name for the variable


Use: Optional

Dimensions of an array variable


Use: Optional

Type: Keyword

Keyword that creates an instance of an object


Use: Optional

The data type of varname


Use: Optional

Any expression that provides the initial value to assign to the variable; cannot be used if an As New clause is used


Declares and allocates storage space in memory for variables. The Dim statement is used either at the start of a procedure or the start of a module to declare a variable of a particular data type.

Rules at a Glance

  • Object is the default data type created when no data type is explicitly declared.

  • The declaration of a nonobject variable actually creates the variable. For an object variable, the variable is not created unless the optional New statement is used. If not, then the object variable is set to Nothing and must be assigned a reference to an ...

Get VB .NET Language in a Nutshell 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.