「VB.net」VarTypeで変数のデータ型をInteger値を返す
書式
Public Function VarType (VarName As Object) As VariantType
変数のデータ型の分類を含む Integer 値を返します。
使用例
Module Module1 Sub Main() 'String型 Dim str As String = "test" 'Integer型 Dim intA As Integer = 250 'Double型 Dim dbD As Double = 12.34 'Boolean型 Dim bf As Boolean = False 'Object型 Dim cftObj As New Object ' Integer 3 Console.WriteLine(VarType(intA)) 'Double 5 Console.WriteLine(VarType(dbD)) ' String 8 Console.WriteLine(VarType(str)) ' Boolean 11 Console.WriteLine(VarType(bf)) ' Object 9 Console.WriteLine(VarType(cftObj)) Console.ReadKey() End Sub End Module
結果
3
5
8
11
9