Name

Dim Statement

Syntax

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

Use: Optional

Type: Keyword

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

Shadows

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

WithEvents

Use: Optional

Type: Keyword

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

varname

Use: Required

Your chosen name for the variable

subscripts

Use: Optional

Dimensions of an array variable

New

Use: Optional

Type: Keyword

Keyword that creates an instance of an object

type

Use: Optional

The data type of varname

initexpr

Use: Optional

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

Description

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.