データ型を調べてそのデータ型を示す文字列を返す(TypeName 関数)
2015/08/26
TypeName 関数 の使い方
TypeName 関数は、引数に、データ型を調べたい値や変数を指定するとそのデータ型を示す文字列を返します。
result = TypeName ( varname )
引数・戻り値
- varname ・・・ 調べたい値や変数を指定します。
- result ・・・ 引数 varname のデータ型を表す文字列
(戻り値は、以下「TypeName 関数の戻り値一覧」を参照)。
TypeName 関数の戻り値一覧
| 戻り値 | 内容 |
| Byte | バイト型(Byte) |
| Integer | 整数型(Integer) |
| Long | 長整数型(Long) |
| Single | 単精度浮動小数点数型(Single) |
| Double | 倍精度浮動小数点数型(Double) |
| Currency | 通貨型(Currency) |
| Decimal | 10 進数型 |
| Date | 日付型(Date) |
| String | 文字列型(String) |
| Boolean | ブール型(Boolean) |
| Error | エラー値 |
| Empty | 未初期化 |
| Null | 無効な値 |
| Object | オブジェクト |
| Unknown | オブジェクトの種類が不明なオブジェクト |
| Nothing | オブジェクトを参照していないオブジェクト変数 |
引数 varname が、バリアント型変数の場合は、内部処理形式を識別する文字列を返します。
引数 varname が配列の場合は、上記の文字列の中の該当する文字列またはバリアント型(Variant)の値に、空のかっこ “()” を付けて返します。
(例)引数 varname が整数の配列のとき、TypeName 関数は “Integer()” を返します。
TypeName 関数 の使用例
サンプルVBAソース
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Sub Sample_typename() Dim myStr As String, myInt As Integer, myLng As Long Dim myDbl As Double, mySgl As Single, myBol As Boolean Dim myObj As Object, myDat As Date, myCur As Currency Dim myByt As Byte, myWks As Worksheet Dim myVal1, myVal2, myEmp, myNull Set myWks = ActiveSheet myVal1 = 123 myVal2 = CDec(12500) myNull = Null Debug.Print TypeName(myStr) Debug.Print TypeName(myInt) Debug.Print TypeName(myLng) Debug.Print TypeName(myDbl) Debug.Print TypeName(mySgl) Debug.Print TypeName(myBol) Debug.Print TypeName(myObj) Debug.Print TypeName(myDat) Debug.Print TypeName(myCur) Debug.Print TypeName(myByt) Debug.Print TypeName(myWks) Debug.Print TypeName(myVal1) Debug.Print TypeName(myVal2) Debug.Print TypeName(myEmp) Debug.Print TypeName(myNull) End Sub |
実行結果
関連記事
-
-
文字列:文字列を検索してその最初の文字位置を返す(InStr 関数,InStrB 関数)
InStr 関数・InStrB 関数の使い方 【書式】 result = { I …
-
-
変数がNull 値かどうかをチェックする( IsNull 関数 )
IsNull 関数の使い方 【書式】 result = IsNull ( exp …
-
-
オブジェクトの書式をクリアする(ClearFormats メソッド)
ClearFormats メソッド 対象となるオブジェクトの書式(スタイル)を初 …
-
-
エラー(CVErr 関数・IsError 関数・Error 関数)
CVErr 関数(エラー番号をエラー値に変換する)の使い方 【書式】 retur …
-
-
日付時刻:年・月・日を取得(Year、Month、Day 関数)
日付から年・月・日を取得する関数 【書式】 date_year = Year ( …
-
-
連想配列(Dictionary オブジェクト)
連想配列 連想配列とは、添字(キー)に文字列を使用することができる配列です。 V …
-
-
文字列:文字列の指定した位置から指定文字数取得(Mid 関数,MidB 関数)
Mid 関数・MidB 関数 の使い方 【書式】 result_mid = Mi …
-
-
コレクション(Collection)オブジェクト「連想配列」
コレクション(Collection)オブジェクトの使い方 【書式】 Dim my …
-
-
色の設定(ColorIndex プロパティ・Colors プロパティ)
ColorIndex プロパティ ColorIndex プロパティは、指定したオ …
-
-
カレントフォルダ(CurDir 関数、ChDir ステートメント、ChDrive ステートメント)
カレントフォルダ カレントフォルダとは、ブックを開いたり保存するときに既定で参照 …
