Operators in VBScript. Logical Operators


© Maxim Karetnikov
Articles in this Topic    Discussions in this Topic

VBScript provides a variety of operators that you can use when performing logical operations. For example, if you want to use an If statement that is TRUE if two statements are TRUE, you can use the And operator to combine the statements (If (A = B) And (C > D) Then ). The logical operators available in VBScript are discussed below.

Negation Not Operator

This operator has the following syntax:

result = Not expression 

The result variable in relation to expression is given in table 1.

Table 1. Not Operator

If expression

then result
True False
False True

If you enter the code

b=False 
a = Not b

the result stored in variable True. Typically, Not operator is often used when working with if-then conditional statements. Consider, for instance, the following code segment:

if expression1=False then
msgbox "Enter the correct value"

You could use the Not operator to make code easier to read:

if Not expression1 then
msgbox "Enter the correct value"

Conjunction And Operator

The conjunction operator compares two or more variables in some type of test. The syntax for the conjunction operator is

result = expression1 And expression2

The table 2 displays the result variable in relation to expression1 and expression2. In order to obtain True in the result variable, both expression1 and expression2 must be true.

Table 2. And Operator

If expression1

and expression2 then result
True True True
False True False
True False False
False False False

For instance, if you want to make your page available only for user of the age above 16 and male sex, you might use the statement like this

if YourAge>16 And YourSex=Male then
msgbox "You are welcome" 
else 
msgbox "The page is forbidden for you" 

Disjunction Or Operator

The syntax and usage of Or operator is similar to And operator:

result = expression1 Or expression2

The result variable in relation to expression1 and expression2

Go To Page: 1 2


Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo