VBScript Logical Operators
The logical operators are And Operator, Not Operator, Or Operator, and Xor Operator.
Truth Table of VBScript Logical Operators
Truth Table of VBScript Logical Operators
abNot aa And ba Or ba Xor ba Eqv ba Imp b00100011011011011000110011011011
And Operator
last updated 18 Nov 2017And logic operator is used to create a value by performing a logical conjunction on two logic expressions or bitwise logical conjunction on two numeric digit expressions.
Syntax
expression1 And expression2
Argument
expression1Any expression.expression2Any expression.Return
Returns of And operation
expression1expression2ReturnTrueTrueTrueTrueFalseFalseTrueNullNullFalseTrueFalseFalseFalseFalseFalseNullFalseNullTrueNullNullFalseFalseNullNullNull
Returns of bitwise And operation
expression1expression2Return000010100111
Remark
- If, and only if, both expressions evaluate to True, result is True.
- If either expression evaluates to False, result is False.
- The logical operation is not short-circuited. All expressions are evaluated.
- The And operator also performs a bitwise comparison of identically positioned bits in two numeric digit expressions and sets the corresponding bit.
Version
1
Not Operator
last updated 18 Nov 2017Not logic operator is used to create a value by performing a logical negation on a logic expression or bitwise logical negation on an expression.
Syntax
Not expression
Argument
expressionAny expressionReturn
Returns of Not operation
expressionReturnTrueFalseFalseTrueNullNull
Returns of bitwise Not operation
expressionReturn0110
Remark
- The Not operator inverts the logical status of an expressions.
- The Not operator also inverts the bit values of an expressions and sets the corresponding bit.
Version
1
Or Operator
last updated 18 Nov 2017Or logic operator is used to create a value by performing a logical disjunction on two logic expressions or bitwise logical disjunction on two numeric digit expressions.
Syntax
expression1 And expression2
Argument
expression1Any expression.expression2Any expression.Return
Returns of Or operation
expression1expression2ReturnTrueTrueTrueTrueFalseTrueTrueNullTrueFalseTrueTrueFalseFalseFalseFalseNullNullNullTrueTrueNullFalseNullNullNullNull
Returns of bitwise Or operation
expression1expression2Return000011101111
Remark
- If, either or, both expressions evaluate to True, result is True.
- If either expression evaluates to False, result is False.
- The logical operation is not short-circuited. All expressions are evaluated.
- The Or operator also performs a bitwise comparison of identically positioned bits in two numeric digit expressions and sets the corresponding bit.
Version
1
Xor Operator
last updated 18 Nov 2017Xor logic operator is used to create a value by performing a logical exclusion on two logic expressions or bitwise logical exclusion on two numeric digit expressions.
Syntax
expression1 Xor expression2
Argument
expression1Any expression.expression2Any expression.Return
Returns of Xor operation
expression1expression2ReturnTrueTrueFalseTrueFalseTrueFalseTrueTrueFalseFalseFalse
Returns of bitwise Xor operation
expression1expression2Return000011101110
Remark
- If one, and only one, of the expressions evaluates to True, result is True. However, if either expression is Null, result is also Null.
- The Xor operator also performs a bitwise comparison of identically positioned bits in two numeric digit expressions and sets the corresponding bit.
Version
1
Eqv Operator
last updated 18 Nov 2017Eqv logic operator is used to create a value by performing a logical equivalence or XorNot on two logic expressions or bitwise logical exclusion on two numeric digit expressions.
Syntax
expression1 Eqv expression2
Argument
expression1Any expression.expression2Any expression.Return
Returns of Eqv operation
expression1expression2ReturnTrueTrueTrueTrueFalseFalseFalseTrueFalseFalseFalseTrueNullTrueNullNullFalseNullTrueNullNullFalseNullNullNullNullNull
Returns of bitwise Eqv operation
expression1expression2Return001010100111
Remark
- If either expression is Null, result is also Null.
- The Eqv operator also performs a bitwise comparison of identically positioned bits in two numeric digit expressions and sets the corresponding bit.
Version
1
Imp Operator
last updated 18 Nov 2017Imp logic operator is used to create a value by performing a logical implication on two logic expressions or bitwise logical exclusion on two numeric digit expressions.
Syntax
expression1 Imp expression2
Argument
expression1Any expression.expression2Any expression.Return
Returns of Imp operation
expression1expression2ReturnTrueTrueTrueTrueFalseFalseTrueNullNullFalseTrueTrueFalseFalseTrueFalseNullTrueNullTrueTrueNullFalseNullNullNullNull
Returns of bitwise Imp operation
expression1expression2Return001011100111
Remark
- The Imp operator also performs a bitwise comparison of identically positioned bits in two numeric digit expressions and sets the corresponding bit.
Version
1
Examples
Examples of logical And, Not, Or, Xor, Eqv, and Imp operators
ASP VbScript Command:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script runat="server" language="VBScript">
Function printdata
cmda=array("a","b","a And b","a Or b","a Xor b","a Eqv b","a Imp b","Hex(a)","Hex(b)","Hex(a And b)","Hex(a Or b)","Hex(a Xor b)","Hex(a Eqv b)","Hex(a Imp b)","Not b","Hex(Not b)"):ucnt=UBound(cmda):call heading
vars="a=Null:b=Null":dsp_x
vars="a=Null:b=Empty":dsp_x
vars="a=Null:b=""""":dsp_x
vars="a=Null:b=""a""":dsp_x
vars="a=Null:b=""5""":dsp_x
vars="a=Null:b=5":dsp_x
vars="a=Null:b=True":dsp_x
vars="a=Null:b=False":dsp_x
vars="a=Empty:b=Null":dsp_x
vars="a=Empty:b=Empty":dsp_x
vars="a=Empty:b=""""":dsp_x
vars="a=Empty:b=""a""":dsp_x
vars="a=Empty:b=""5""":dsp_x
vars="a=Empty:b=5":dsp_x
vars="a=Empty:b=True":dsp_x
vars="a=Empty:b=False":dsp_x
vars="a="""":b=Null":dsp_x
vars="a="""":b=Empty":dsp_x
vars="a="""":b=""""":dsp_x
vars="a="""":b=""a""":dsp_x
vars="a="""":b=""5""":dsp_x
vars="a="""":b=5":dsp_x
vars="a="""":b=True":dsp_x
vars="a="""":b=False":dsp_x
vars="a=Null:b=Null":dsp_x
vars="a=Empty:b=Null":dsp_x
vars="a="""":b=Null":dsp_x
vars="a=""a"":b=Null":dsp_x
vars="a=""5"":b=Null":dsp_x
vars="a=5:b=Null":dsp_x
vars="a=True:b=Null":dsp_x
vars="a=False:b=Null":dsp_x
vars="a=Null:b=Empty":dsp_x
vars="a=Empty:b=Empty":dsp_x
vars="a="""":b=Empty":dsp_x
vars="a=""a"":b=Empty":dsp_x
vars="a=""5"":b=Empty":dsp_x
vars="a=5:b=Empty":dsp_x
vars="a=True:b=Empty":dsp_x
vars="a=False:b=Empty":dsp_x
vars="a=Null:b=""""":dsp_x
vars="a=Empty:b=""""":dsp_x
vars="a="""":b=""""":dsp_x
vars="a=""a"":b=""""":dsp_x
vars="a=""5"":b=""""":dsp_x
vars="a=5:b=""""":dsp_x
vars="a=True:b=""""":dsp_x
vars="a=False:b=""""":dsp_x
vars="a=True:b=True":dsp_x
vars="a=True:b=False":dsp_x
vars="a=False:b=True":dsp_x
vars="a=False:b=False":dsp_x
vars="a=True:b=1":dsp_x
vars="a=True:b=0":dsp_x
vars="a=False:b=1":dsp_x
vars="a=False:b=0":dsp_x
vars="a=1:b=True":dsp_x
vars="a=1:b=False":dsp_x
vars="a=0:b=True":dsp_x
vars="a=0:b=False":dsp_x
vars="a=True:b=""1""":dsp_x
vars="a=True:b=""0""":dsp_x
vars="a=False:b=""1""":dsp_x
vars="a=False:b=""0""":dsp_x
vars="a=""1"":b=True":dsp_x
vars="a=""1"":b=False":dsp_x
vars="a=""0"":b=True":dsp_x
vars="a=""0"":b=False":dsp_x
vars="a=""a"":b=""A""":dsp_x
vars="a=""2"":b=""9""":dsp_x
vars="a=&h1A:b=&hBF":dsp_x
vars="a=&h1A1A1A:b=&hBFBFBF":dsp_x
vars="a=&h1A1A1A1A:b=&hBFBFBFBF":dsp_x
vars="a=10000000000:b=99999999":dsp_x
vars="a=99999999:b=10000000000":dsp_x
vars="a=9.9:b=1.1":dsp_x
vars="a=10:b=1":dsp_x
vars="a=1:b=1":dsp_x
vars="a=1.4:b=1":dsp_x
vars="a=1.5:b=1":dsp_x
vars="a=1.6:b=1":dsp_x
vars="a=2:b=1":dsp_x
vars="a=2.4:b=1":dsp_x
vars="a=2.5:b=1":dsp_x
vars="a=2.6:b=1":dsp_x
vars="a=3:b=1":dsp_x
End Function
Dim abb,cnt,cmda,cmp,dai,dlt,dte,dad,e,fnd,flg,fir,f_dw,gbd,hor,i,ild,k,mth,min,num,pnn,pi,sec,str1,str2,str,strs,tme,tmp,ucnt,var,vars,varx,wkd,x,z:varx=0
Function heading:If var=1 Then:tmp="":Else:tmp="<b>vars</b>":End If:For i=0 to ucnt:tmp=tmp&"<b>"&rmv_ctrl(cmda(i))&", TypeName</b>":Next:Response.Write "Results on Microsoft Windows Server 2008 R2 Standard x64, Microsoft-IIS/7.5, VB Version 14.0<br />"&"<i>"&tmp&"</i>":End Function
Function dsp_x:Dim tmp_a,tmp_b,i:If varx=0 Then:Execute vars:End If:If var=1 Then:tmp_a="":Else:tmp_a=rmv_ctrl(vars):End If:For i=0 to ucnt:tmp_b=cmd_b(cmda(i)):if i/2=fix(i/2) Then:tmp_b="<b>"&tmp_b&"</b>":End If:tmp_a=tmp_a&tmp_b:Next:Response.Write "<i>"&tmp_a&"</i>":End Function
Function rmv_ctrl(blk_str):Select Case blk_str:Case chr(0):blk_str="NUL":Case chr(1):blk_str="SOH":Case chr(2):blk_str="STX":Case chr(3):blk_str="ETX":Case chr(4):blk_str="EOT":Case chr(5):blk_str="ENQ":Case chr(6):blk_str="ACK":Case chr(7):blk_str="BEL":Case chr(8):blk_str="BS":Case chr(9):blk_str="HT":Case chr(10):blk_str="LF":Case chr(11):blk_str="VT":Case chr(12):blk_str="FF":Case chr(13):blk_str="CR":Case chr(14):blk_str="SO":Case chr(15):blk_str="SI":Case chr(16):blk_str="DLE":Case chr(17):blk_str="DC1":Case chr(18):blk_str="DC2":Case chr(19):blk_str="DC3":Case chr(20):blk_str="DC4":Case chr(21):blk_str="NAK":Case chr(22):blk_str="SYN":Case chr(23):blk_str="ETB":Case chr(24):blk_str="CAN":Case chr(25):blk_str="EM":Case chr(26):blk_str="SUB":Case chr(27):blk_str="ESC":Case chr(28):blk_str="FS":Case chr(29):blk_str="GS":Case chr(30):blk_str="RS":Case chr(31):blk_str="US":Case chr(127):blk_str="DEL":End Select:rmv_ctrl=blk_str:If IsNull(blk_str) OR IsEmpty(Blk_str) OR blk_str="" OR IsNumeric(Blk_str) Then:Else:rmv_ctrl=Replace(Replace(Replace(Replace(Replace(blk_str,"&","&")," "," "),"""","""),"<","<"),">",">"): End If :End Function
Function cmd_b(blk_str):cmd_b="["&cmd_x(blk_str)&"], "&cmd_x("TypeName("&blk_str&")"):End Function
Function cmd_x(blk_str):On Error Resume Next:Dim xans, tmp:xans="":tmp="":execute "xans="&blk_str:If Err.Number <> 0 Then:xans=cmd_x("TypeName("&blk_str&")"):Select Case xans:Case 9::Case Else:xans="error":End Select:End If:If IsArray(xans)=False Then:cmd_x=rmv_ctrl(xans): Else:tmp=lst_arry(xans):cmd_x=trim(tmp):End If:End Function
Function lst_arry(blk_str):Dim tmp,i,q:q="""":tmp="":For i=0 to UBound(blk_str):if VarType(blk_str(i))>1 And VarType(blk_str(i))<6 Then:q="'":End If:tmp=tmp&" "&q&rmv_ctrl(blk_str(i))&q:Next:lst_arry=trim(tmp):End Function
</script>
<title>Sample Page</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<style type="text/css">
i {display:table-row}
u,b {display:table-cell}
</style>
</head>
<body>
<%call printdata %>
</body>
</html>
HTML Web Page Embedded Output: