VBScript の真偽比較表

実行結果
  IsEmpty IsObject IsNull TypeName VarType ASC() Len if Value then
初期状態 Empty not Object not Null Empty 0 Error 0 False
Set Value = Nothing not Empty Object not Null Nothing 9 Error Error Error
Value = "" not Empty not Object not Null String 8 Error 0 Error
Value = vbNullString not Empty not Object not Null String 8 Error 0 Error
Value = vbNullChar not Empty not Object not Null String 8 0 1 Error
Value = Null not Empty not Object Null Null 1 Error False
Value = Empty Empty not Object not Null Empty 0 Error 0 False
Value = Array() not Empty not Object not Null Variant() 8204 Error Error Error
Value = False not Empty not Object not Null Boolean 11 70 5 False
Value = True not Empty not Object not Null Boolean 11 84 4 True
Value = "False" not Empty not Object not Null String 8 70 5 False
Value = "True" not Empty not Object not Null String 8 84 4 True
Value = 0 not Empty not Object not Null Integer 2 48 1 False
Value = 1 not Empty not Object not Null Integer 2 49 1 True
Value = "0" not Empty not Object not Null String 8 48 1 False
Value = "1" not Empty not Object not Null String 8 49 1 True
Value = -1 not Empty not Object not Null Integer 2 45 2 True
Value = "-1" not Empty not Object not Null String 8 45 2 True
Value = 17 not Empty not Object not Null Integer 2 49 2 True
Value = "ABC" not Empty not Object not Null String 8 65 3 Error
  • これは以下のプログラムで出力
    したものです
  • 出力用コード
    
    <SCRIPT language=VBScript>
    ' **********************************************************
    ' グローバル
    ' **********************************************************
    Dim Value
    Dim MyDisp
     
    ' **********************************************************
    ' クラス
    ' **********************************************************
    Class Disp
     
    	Public DispArray()		' 動的配列
    	Public Counter		' 添え字カウンター
     
    ' ************************************************
    ' コンストラクタ
    ' ************************************************
    	Public Default Function InitSetting()
     
    		ReDim Preserve DispArray(0)
    		Counter = -1
     
    	end function
     
    ' ************************************************
    ' メソッド ( データセット )
    ' ************************************************
    	Function SetData( strValue )
     
    		Counter = Counter + 1
    		ReDim Preserve DispArray( Counter )
    		DispArray( Counter ) = strValue
     
    	end function
     
    ' ************************************************
    ' メソッド ( データ取得 )
    ' ************************************************
    	Function GetData()
     
    		GetData = Join( DispArray, vbCrLf )
     
    	end function
     
    ' ************************************************
    ' メソッド ( タイプセット )
    ' ************************************************
    	Function SetType( Target, Title )
     
    		SetData( "<TR>" )
     
    		SetData( "<TD style='font-weight:bold'>" & Title & "</TD>" )
     
    		if IsEmpty( Target ) then
    			SetData( "<TD>Empty</TD>" )
    		else
    			SetData( "<TD>not Empty</TD>" )
    		end if
     
    		if IsObject( Target ) then
    			SetData( "<TD>Object</TD>" )
    		else
    			SetData( "<TD>not Object</TD>" )
    		end if
     
    		if IsNull( Target ) then
    			SetData( "<TD>Null</TD>" )
    		else
    			SetData( "<TD>not Null</TD>" )
    		end if
     
    		SetData( "<TD>" & TypeName( Target ) & "</TD>" )
     
     
    		SetData( "<TD>" & VarType( Target ) & "</TD>" )
     
    		on error resume next
    		SetData( "<TD>" & Asc( Target ) & "</TD>" )
    		if Err.Number <> 0 then
    			SetData( "<TD>Error</TD>" )
    		end if
    		on error goto 0
     
    		on error resume next
    		SetData( "<TD>" & Len( Target ) & "</TD>" )
    		if Err.Number <> 0 then
    			SetData( "<TD>Error</TD>" )
    		end if
    		on error goto 0
     
    		on error resume next
    		if Target then
    			if Err.Number = 0 then
    				SetData( "<TD>True</TD>" )
    			else
    				SetData( "<TD>Error</TD>" )
    			end if
    		else
    			if Err.Number = 0 then
    				SetData( "<TD>False</TD>" )
    			else
    				SetData( "<TD>Error</TD>" )
    			end if
    		end if
    		on error goto 0
     
    		SetData( "</TR>" )
     
    	end function
     
    End Class
     
    '***********************************************************
    ' 変数内容のテスト
    '***********************************************************
    function ValueTest()
     
    	Set MyDisp = new Disp
     
    	Call MyDisp()
     
    	With ( MyDisp )
     
    		.SetData( "<TABLE border=1 cellpadding=5>" )
    		.SetData( "<TH>&nbsp;</TH>" )
    		.SetData( "<TH>IsEmpty</TH>" )
    		.SetData( "<TH>IsObject</TH>" )
    		.SetData( "<TH>IsNull</TH>" )
    		.SetData( "<TH>TypeName</TH>" )
    		.SetData( "<TH>VarType</TH>" )
    		.SetData( "<TH>ASC()</TH>" )
    		.SetData( "<TH>Len</TH>" )
    		.SetData( "<TH>if Value then</TH>" )
     
    		'*****************************************
    		' 初期状態
    		'*****************************************
    		Call .SetType( Value, "初期状態" )
     
    		'*****************************************
    		' Nothing
    		'*****************************************
    		Set Value = Nothing
    		Call .SetType( Value, "Set Value = Nothing" )
     
    		'*****************************************
    		' zero-length string
    		'*****************************************
    		Value = ""
    		Call .SetType( Value, "Value = """"" )
     
    		'*****************************************
    		' vbNullString
    		'*****************************************
    		Value = vbNullString
    		Call .SetType( Value, "Value = vbNullString" )
     
    		'*****************************************
    		' vbNullChar
    		'*****************************************
    		Value = vbNullChar
    		Call .SetType( Value, "Value = vbNullChar" )
     
    		'*****************************************
    		' Null
    		'*****************************************
    		Value = Null
    		Call .SetType( Value, "Value = Null" )
     
    		'*****************************************
    		' Empty
    		'*****************************************
    		Value = Empty
    		Call .SetType( Value, "Value = Empty" )
     
    		'*****************************************
    		' Array
    		'*****************************************
    		Value = Array()
    		Call .SetType( Value, "Value = Array()" )
     
    		'*****************************************
    		' False & True
    		'*****************************************
    		Value = False
    		Call .SetType( Value, "Value = False" )
     
    		Value = True
    		Call .SetType( Value, "Value = True" )
     
    		Value = "False"
    		Call .SetType( Value, "Value = ""False""" )
     
    		Value = "True"
    		Call .SetType( Value, "Value = ""True""" )
     
    		Value = 0
    		Call .SetType( Value, "Value = 0" )
     
    		Value = 1
    		Call .SetType( Value, "Value = 1" )
     
    		Value = "0"
    		Call .SetType( Value, "Value = ""0""" )
     
    		Value = "1"
    		Call .SetType( Value, "Value = ""1""" )
     
    		Value = -1
    		Call .SetType( Value, "Value = -1" )
     
    		Value = "-1"
    		Call .SetType( Value, "Value = ""-1""" )
     
    		Value = 17
    		Call .SetType( Value, "Value = 17" )
     
    		'*****************************************
    		' 文字列
    		'*****************************************
    		Value = "ABC"
    		Call .SetType( Value, "Value = ""ABC""" )
     
     
    		.SetData( "</TABLE>" )
     
    		document.write MyDisp.GetData
     
    	End With
     
    end function
     
    </SCRIPT>
     
    <HTML>
    <HEAD>
    	<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=Shift_JIS">
    </HEAD>
    <BODY>
    	<INPUT type=button value="テスト" onClick='Call ValueTest()'>
     
    	<DIV id=DispArea>
    	</DIV>
    </BODY>
    </HTML>
    



    プラバシーポリシー