Chapter: Internet & World Wide Web HOW TO PROGRAM - VBScript

| Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail |

Operators - VBScript

VBScript is a case-insensitive language that provides arithmetic operators, logical opera-tors, concatenation operators, comparison operators and relational operators.

Operators

 

VBScript is a case-insensitive language that provides arithmetic operators, logical opera-tors, concatenation operators, comparison operators and relational operators. VBScript’s arithmetic operators (Fig. 24.1) are similar to the JavaScript arithmetic operators. Two ma-jor differences are the division operator, \, which returns an integer result and the expo-nentiation operator, ^, which raises a value to a power. [Note: the precedence of operators is different in JavaScript. See Section 24.9 for a list of VBScript operators and their prece-dences.]


Figure 24.2 lists VBScript’s comparison operators. Only the symbols for the equality operator and the inequality operator are different in JavaScript. In VBScript, these compar-ison operators may also be used to compare strings.

 

The VBScript logical operators are And (logical AND), Or (logical OR), Not (logical negation), Imp (logical implication), Xor (exclusive OR) and Eqv (logical equivalence). Figure 24.3 shows truth tables for these logical operators. Note: Despite the mixture of case in keywords, functions, etc., VBScript is not case-sensitive—uppercase and lowercase let-ters are treated the same, except, as we will see, in character string constants (also called character string literals).




VBScript provides the plus sign, +, and ampersand, &, operators for string concatena-tion as follows:

s1 = "Pro"

s2 = "gram"

s3 = s1 & s2

 

or

 

s3 = s1 + s2

 

The ampersand is more formally called the string concatenation operator. The above state-ments would concatenate (or append) s2 to the right of s1 to create an entirely new string, s3, containing "Program".

 

If both operands of the concatenation operator are strings, these two operators can be used interchangeably; however, if the + operator is used in an expression consisting of varying data types, there can be a problem. For example, consider the statement

 

s1 = "hello" + 22

 

VBScript first tries to convert the string "hello" to a number, then add 22 to it. The string "hello" cannot be converted to a number, so a type mismatch error occurs at run time. For this reason, the & operator should be used for string concatenation.


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail


Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.