Declare Variable Statement
The Declare Variable statement declares a variable. It does not return a value. For more information about the format and arguments you can use this statement, see Declaring Variables.
Dim is an abbreviation for Declare in Memory. You must begin the value in the VariableName argument with a letter. It must contain only letters, numbers, and underscores. You can use square brackets to separate a name. You can use any character between the square brackets except for more square brackets. For example:
Dim my_1st_variable As String
Dim [one long and strange! variable name] As String
Format
Dim [Shared] variableName [As[ New] type] [, variableName [As[ New] type]] ...
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
variableName |
The name of the variable to declare. |
type |
The data type of the variable. |
Example
The following example includes a Dim statement for each of the possible data types:
' Must define a record type before you can declare a record
' variable
Type Testrecord
Custno As Integer
Custname As String
End Type
Sub Button_Click
Dim counter As Integer
Dim fixedstring As String * 25
Dim varstring As String
Dim myrecord As Testrecord
Dim ole2var As Object
Dim F(1 to 10), A()
'...(code here)...
End Sub