共用方式為


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 傳回的值

Nothing (Visual Basic)

VariantType.Object

DBNull

VariantType.Null

列舉型別

基礎資料型別 (SByte、Byte、Short、UShort、Integer、UInteger、Long 或 ULong)

陣列

陣列元素型別和 VariantType.Array 的位元運算 OR

陣列的陣列

VariantType.Object 和 VariantType.Array 的位元運算 OR

結構 (System.ValueType)

VariantType.UserDefinedType

Exception

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.

智慧型裝置開發人員注意事項

不支援這個函式。

需求

命名空間:Microsoft.VisualBasic

**模組:**Information

組件:Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

請參閱

參考

資料型別摘要 (Visual Basic)

Object 資料型別

VariantType 列舉型別