Читать книгу Excel 2019 Power Programming with VBA - Michael Alexander, Dick Kusleika - Страница 152
NOTE
ОглавлениеDim
is a shortened form of Dimension. In old versions of BASIC, this statement was used exclusively to declare the dimensions for an array. In VBA, the Dim
keyword is used to declare any variable, not just arrays.
The following procedure uses six local variables declared by using Dim
statements:
Sub MySub() Dim x As Integer Dim First As Long Dim InterestRate As Single Dim TodaysDate As Date Dim UserName As String Dim MyValue ' - [The procedure's code goes here] - End Sub
Notice that the last Dim
statement in the preceding example doesn't declare a data type; it simply names the variable. As a result, that variable becomes a variant.
You also can declare several variables with a single Dim
statement. Here's an example:
Dim x As Integer, y As Integer, z As Integer Dim First As Long, Last As Double