Dim
In Microsoft Visual Basic, the Dim keyword is used to declare a local variable. It allocates enough space in the computer's memory for data of a specific type. In Visual Basic, these types are Integer, Long, Double, Boolean, Currency, Date, String, Byte, Object, or Variant. A variable declared using the Dim keyword lasts only as long as a particular sub or function lasts.
The syntax is: Dim varName As varType
The statement might be used in a program such as this:
Private Sub cmdVariables_Click()
Dim intResult As Integer
intResult = 5
lblResult.Caption = intResult
End Sub
An alternative to using As is to use a Type Suffix to declare the type of your variable. These type suffixes are:
_____________________________
|Variable Type | Suffix |
|Integer | % |
|Double | # |
|String | $ |
|Long | & |
|Single | ! |
|Currency | @ |
______________________________
The other variable types don't have one, and you must use
As.
If you want another type of variable (such as a global variable), you can use Private, Public, or Const (for a constant).