home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


VBScript supplies three other math operators:

  \—The backslash operator divides its first operand by its second, after first rounding floating point operands to the nearest integer, and returns the integer part of the result. For example, 19 \ 6.7 returns 2 (6.7 rounds to 7, 19 divided by 7 is a little over 2.71, the integer part of which is 2).
  Mod—This operator is similar to \ in that it divides the first operand by its second, again after rounding floating point operands to the nearest integer, and returns the integer remainder. Therefore, 19 Mod 6.7 returns 5.
  ^—This exponent operator returns the first operand raised to the power of the second. The first operand can be negative only if the second, the exponent, is an integer.

Comparison Operators Comparing the value of two expressions to see whether one is larger, smaller, or equal to another is often necessary. VBScript supplies several comparison operators that take two operands and return true if the comparison is true and false if it is not. Table 33.2 shows the VBScript comparison operators:

Table 33.2 VBScript Comparison Operators

Operator Read It As Returns true When:

= equals The two operands are equal.
<> does not equal The two operands are unequal.
< less than The left operand is less than the right operand.
<= less than or The left operand is less than or equal to equal to the right operand.
> greater than The left operand is greater than the right operand.
>= greater than or The left operand is greater than equal to or equal to the right operand.


You can also use the comparison operators on strings; the results depend on standard lexicographic ordering (ordering by the ASCII values of the string characters).

Thinking of the comparison operators as questions may be helpful. When you write

(x >= 10)

you are really saying, “Is the value of variable x greater than or equal to 10?” The return value answers the question true or false.

Logical Operators Comparison operators compare quantity or content for numeric and string expressions, but sometimes you need to test a logical value—whether a comparison operator returns true or false, for example. VBScript’s logical operators enable you to compare expressions that return logical values. The following are VBScript’s logical operators:

  And—The And operator returns true if both its input expressions are true. If the first operand evaluates to false, And returns false immediately, without evaluating the second operand. The following is an example:
x = TRUE And TRUE      ‘ x is TRUE
x = TRUE And FALSE     ‘ x is FALSE
x = FALSE And TRUE     ‘ x is FALSE
x = FALSE And FALSE    ‘ x is FALSE
  Or—This operator returns true if either of its operands is true. If the first operand is true, || returns true without evaluating the second operand. The following is an example:
x = TRUE Or TRUE       ‘ x is TRUE
x = TRUE Or FALSE      ‘ x is TRUE
x = FALSE Or TRUE      ‘ x is TRUE
x = FALSE Or FALSE     ‘ x is FALSE
  Not—This operator takes only one expression and it returns the opposite of that expression. Thus Not true returns false, and Not false returns true.
  Xor—This operator, which stands for “exclusive or,” returns true if either, but not both, of its input expressions is true, as in the following:
x = TRUE Xor TRUE      ‘ x is FALSE
x = TRUE Xor FALSE     ‘ x is TRUE
x = FALSE Xor TRUE     ‘ x is TRUE
x = FALSE Xor FALSE    ‘ x is FALSE
  Eqv—This operator, which stands for “equivalent,” returns true if its two input expressions are the same—either both true or both false. The statement x Eqv y is equivalent to Not (x Xor y).
  Imp—This operator, which stands for “implication,” returns true according to the following:
x = TRUE Imp TRUE      ‘ x is TRUE
x = FALSE Imp TRUE     ‘ x is TRUE
x = TRUE Imp FALSE     ‘ x is FALSE
x = FALSE Imp FALSE    ‘ x is TRUE


NOTE:  Note that the logical implication operator Imp is the only logical operator for which the order of the operands is important.

Note that the And and Or operators don’t evaluate the second operand if the first operand provides enough information for the operator to return a value. This process, called short-circuit evaluation, can be significant when the second operand is a function call.


NOTE:  Note that all six of the logical operators can also operate on non-Boolean expressions. In this case, the logical operations described previously are performed bitwise, on each bit of the two operands. For the two integers 19 (00010011 in binary) and 6 (00000110), for example:
19 And 6=   2 (00000010 in binary)
19 Or 6 =  23 (00010111 in binary)
Not 19  = -20 (11101100 in binary)

String Concatenation The final VBScript operator is the string concatenation operator &. Although you can also use the addition operator + to concatenate strings (returning a string made up of the original strings joined together), using & proves better because it is less ambiguous.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.