Declaration of Variable Types in VB.net

There are 5 types of variable declaration types in VB.net, they are Dim, Redim, Static, Public or Private. Although VB.net allows these declarations to appear just anywhere within the body of the codes, it is best to declare all the variables at the beginning (best practices). Below briefly describes the 5 types of variable declaration and what they are used for:


Dim
Used to declare variables. Whenever the procedure is called, the variable value is reset to default value. For instance, an integer declaration will become zero, and a string declaration will be reset to empty string.

ReDim

The ReDim keyword is only used to redimension an array.

Static
Used to declare and hold the values in the variables. For instance, each time the procedured is called, the data stored in the variable is retained.

Public
Used to declare variables within a module. The variable can be accessed and called anywhere in the project.

Private
Used to declare variables within a module. The variable is only accessible and called within the same module.

0 comments