A variable is the amount of values that can be changed during the program running. A variable is usually used to represent the intermediate and final results of the stored program. Variables must be declared before use.
Variable declaration Syntax:
Dim variable name [As [New] data type] [= expression]
[As [New] data type] indicates the type of the variable. If it is omitted, the variable is of the Object type. [= Expression] returns the initial value of a variable, which can be omitted. For example, declare two variables intVar and strVar:
Dim intVar As Integer = 10' declares an Integer variable intVar and assigns the initial value 10.
Dim strVar As string' declares a String variable strVar
Multiple variables can be defined in a Dim statement. For example, declare that X is a long integer variable, Y is a single precision Floating Point variable, and Name is a string variable:
Dim X As Long, Y As Single, Name As String
The New keyword is used to create an object instance while declaring object variables. For details, see section 3.7.
BibliographyPrevious sectionNext section |