テクパー2020 テクニカルヘルパー |
VisualBasic アプリ開発入門 |
◆ 変数と型変換(キャスト) |
1.データを格納する変数とデータの型(タイプ) | ||
分類 | 型 (タイプ) | 内容 |
数値 |
Byte
|
符号なし整数 (1byte) [ 0 〜 255 ]
Dim Var As Byte '
|
---|---|---|
Short
|
符号あり整数 (2byte) [ -32768 〜 32767 ]
Dim Var As Short = 110S '
|
|
Integer
|
符号あり整数 (4byte) [ -2147483648 〜 2147483647 ]
Dim Var As Integer = 210000I '
Dim Var As Integer = 210000% '
|
|
Long
|
符号あり整数 (8byte) [ -9223372036854775808 〜 9223372036854775807 ]
Dim Var As Long = 81110000L '
Dim Var As Long = 81110000& '
|
|
Single
|
浮動小数点 (4byte) [ +1.5-45 〜 +3.438 ]
Dim Var As Single = 1100.56F '
Dim Var As Single = 1100.56! '
|
|
Double
|
浮動小数点 (8byte) [ +5.0-324 〜 +1.7308 ]
Dim Var As Double = 22100.551R '
Dim Var As Double = 22100.551# '
|
|
Decimal
|
十進数 [ +1.0-28 〜 +7.928 ]
Dim Var As Decimal = 5200.312D '
Dim Var As Decimal = 5200.312@ '
|
|
文字 |
Char
|
1文字 (Unicode,2byte)
Dim Var As Char = "A"C '
|
String
|
文字列 (Unicode)
Dim Var As String = "XYZ"C '
|
|
その他 |
Boolean
|
論理型 (True / False)
Dim Var As Boolean = True '
Dim Var As Boolean = False '
|
Date
|
日付・時間 (8byte)
Dim Var As Date = #2009/01/01 10:10:10:00# '
|
|
Object
|
汎用オブジェクト
Dim Var As Object '
|
|
【 変数宣言 】
|
Dim 変数名 As データ型 '
Dim 変数名 As データ型 = 初期値 '
Dim 変数名 As データ型 = 初期値, 変数名 As データ型 = 初期値, ... '
Dim 変数名, 変数名, 変数名, ... As データ型 '
|
2.データの型が異なる変数の「代入」、「比較」、「演算」で明示的に型変換をする記述 | ||
関数 | 変換後の型 | 記述例 |
CByte |
Byte
|
Dim Var As Byte = CByte("10")'
|
---|---|---|
CShort |
Short
|
Dim Var As Short = CShort("110")'
|
CInt |
Integer
|
Dim Var As Integer = CInt(210000L)'
|
CLng |
Long
|
Dim Var As Long = CLng(110S)'
|
CSng |
Single
|
Dim Var As Single = CSng("1100.56")'
|
CDbl |
Double
|
Dim Var As Double = CDbl(1100.56F)'
|
CDec |
Decimal
|
Dim Var As Decimal = CDec("5200.312")'
|
CChar |
Char
|
Dim Var As Char = CChar(4S)'
|
CStr |
String
|
Dim Var As String = CStr(5200.312D)'
|
CBool |
Boolean
|
Dim Var As Boolean = CBool(-1)'
|
CDate |
Date
|
Dim Var As Date = CDate("5200.312")'
|
CObject |
Object
|
Dim Var As Object = CObject("ABC")'
|
Copyright (C) 2010 プログラミングのテクニックをあなたに!!(リトル・ヘルパー) All Rights Reserved. |