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.
This operator has the following syntax:
result = Not expression
The result variable in relation to expression is given in table 1.
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"
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.
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"
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