See Also Example
Returns a value that indicates how a Variant
Syntax
VarType(variant)
Remarks
The argument variant is a variable of the Variant data type The VarType function returns a value that provides information about the type of data stored in the Variant.
The value returned by VarType is one of the following:
Symbolic constant | Value | Meaning |
V_EMPTY | | Empty |
V_NULL | | Null |
V_INTEGER | | Integer |
V_LONG | | Long |
V_SINGLE | | Single |
V_DOUBLE | | Double |
V_CURRENCY | | Currency |
V_DATE | | Date |
V_STRING | | String |
Note Symbolic constants for file Variant definitions can be found in the Visual Basic file CONSTANT.TXT. When placed in any module in a project, the symbolic names can be used in all your form and code modules.
Data Types
IsDate Function
IsEmpty Function
IsNull Function
IsNumeric Function
The example uses VarType to determine whether a Variant argument passed to the function is either a Single or a Double. True is returned if the argument is one of these types of data, False if it is not. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim Num ' Declare variable.
Num = InputBox("Enter a number.") ' Get number from user.
If IsNumeric(Num) Then
Num = CDbl(Num)
Else
MsgBox "You did not enter a number."
Exit Sub
End If
If IsReal(Num) Then
MsgBox "What you entered is a real number."
Else
MsgBox "What you entered is not a real number."
End If
End Sub
Function IsReal(VarArg)
If VarType(VarArg) = 4 Or VarType(VarArg) = 5 Then
IsReal = True ' If Single or Double.
Else
IsReal = False ' If not.
End If
End Function