VarType 函数 (Visual Basic)
更新:2007 年 11 月
返回一个 Integer 值,其中包含变量的数据类型分类。
Public Function VarType(ByVal VarName As Object) As VariantType
参数
- VarName
必选。Object 变量。如果 Option Strict 为 Off,则可以传递除结构之外的任何数据类型的变量。
备注
由 VarType 返回的整数值是 VariantType 枚举 的成员。
下表显示了由 VarType 针对特殊的 VarName 所返回的值。
VarName 表示的数据类型 |
VarType 返回的值 |
---|---|
VariantType.Object |
|
VariantType.Null |
|
枚举 |
基础数据类型(SByte、Byte、Short、UShort、Integer、UInteger、Long 或 ULong) |
数组 |
数组元素类型和 VariantType.Array 的按位 OR |
数组的数组 |
VariantType.Object 和 VariantType.Array 的按位 OR |
结构 (System.ValueType) |
VariantType.UserDefinedType |
VariantType.Error |
|
未知 |
VariantType.Object |
示例
下面的示例使用 VarType 函数来返回几个变量的数据类型分类信息。
Dim testString As String = "String for testing"
Dim testObject As New Object
Dim testNumber, testArray(5) As Integer
Dim testVarType As VariantType
testVarType = VarType(testVarType)
' Returns VariantType.Integer.
testVarType = VarType(testString)
' Returns VariantType.String.
testVarType = VarType(testObject)
' Returns VariantType.Object.
testVarType = VarType(testNumber)
' Returns VariantType.Integer.
testVarType = VarType(testArray)
' Returns the bitwise OR of VariantType.Array and VariantType.Integer.
智能设备开发人员说明
不支持此函数。
要求
**模块:**Information
**程序集:**Visual Basic 运行库(在 Microsoft.VisualBasic.dll 中)