共用方式為


Information.VarType 方法

傳回 Integer 值,其中包含某個變數的資料型別分類。

命名空間: Microsoft.VisualBasic
組件: Microsoft.VisualBasic (在 microsoft.visualbasic.dll 中)

語法

'宣告
Public Shared Function VarType ( _
    VarName As Object _
) As VariantType
'用途
Dim VarName As Object
Dim returnValue As VariantType

returnValue = Information.VarType(VarName)
public static VariantType VarType (
    Object VarName
)
public:
static VariantType VarType (
    Object^ VarName
)
public static VariantType VarType (
    Object VarName
)
public static function VarType (
    VarName : Object
) : VariantType

參數

  • VarName
    必要項。Object 變數。如果 Option StrictOff,您可以傳遞任何資料型別的變數,但是結構除外。

傳回值

傳回 Integer 值,其中包含某個變數的資料型別分類。

備註

如需詳細資訊,請參閱 Visual Basic 的主題 VarType 函式 (Visual Basic)

VarType 傳回的整數值為 VariantType 列舉型別 的成員。

下表將顯示在 VarName 的特殊案例中,由 VarType 所傳回的值。

VarName 表示的資料型別

VarType 傳回的值

Nothing (Visual Basic)

VariantType.Object

DBNull

VariantType.Null

列舉型別

基礎資料型別 (SByteByteShortUShortIntegerUIntegerLongULong)

陣列

陣列元素型別及 VariantType.Array 的位元 OR

陣列的陣列

VariantType.ObjectVariantType.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.

平台

Windows 98、 Windows 2000 SP4、 Windows CE、 Windows Millennium Edition、 Windows Mobile for Pocket PC、 Windows Mobile for Smartphone、 Windows Server 2003、 Windows XP Media Center Edition、 Windows XP Professional x64 Edition、 Windows XP SP2、 Windows XP Starter Edition

.NET Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。

版本資訊

.NET Framework

支援版本:2.0、1.1、1.0

.NET Compact Framework

支援版本:2.0

請參閱

參考

Information 類別
Information 成員
Microsoft.VisualBasic 命名空間

其他資源

VarType 函式 (Visual Basic)
資料型別摘要 (Visual Basic)
Object 資料型別
VariantType 列舉型別