VBScript is very flexible when it comes to storing data in variables. You can add variables that
contain numbers together, or even concatenate strings. In ASP, we can group operators into four
major categories: Arithmetic, Comparisons, Logic and Concatenation.
Arithmetic
The arithmetic operators used in ASP coding are very similar to other programming languages.
Operator | Description | Example | Results |
+ | Addition | x = 5 + 1 | 6 |
- | Subtraction | x = 5 - 1 | 4 |
* | Multiplication | x = 5 * 1 | 5 |
/ | Division | x = 6 / 3.5 | 1.17428571428571 |
^ | Exponential | x = 3 ^ 3 | 27 |
Mod | Modulus | x = 10 Mod 3 | 1 |
- | Negate | x = -5 | -5 |
\ | Integer Division | x = 6 \ 3.5 | 1 |
Comparisons
Comparison operators are often used within If..Then blocks of code (conditional statements). They are helpful when
you need to compare two variables and make a decision based on the outcome. The result of a
comparison operator is either TRUE or FALSE.
Operator | Description | Example | Results |
= | Equal To | 5 = 1 | FALSE |
< | Less Than | 5 < 1 | FALSE |
> | Greater Than | 5 > 1 | TRUE |
<= | Less Than Or Equal To | 5 <= 1 | FALSE |
>= | Greater Than Or Equal To | 5 >= 1 | TRUE |
<> | Not Equal To | 5 <> 1 | TRUE |
Logic
A logical operator is used in conditional statements that require more than one set of
comparisons.
Operator | Description | Example | Results |
And | All Must be TRUE | True and False | FALSE |
Or | One Must be TRUE | True or False | TRUE |
Not | Reverse of True | Not True | FALSE |
Concatenation
When working with strings, the "&" operator is used to merge strings together to form a
new string.
Operator | Description | Example | Results |
& | String Concatenation | myString = "John" & "Smith" | John Smith |
Example
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<%
Dim x,y
x = 5 + 1
y = 1
Response.Write (x & "<br />")
If x > 1 Then
Response.Write("x is greater than 1!<br />")
Else
Response.Write("x is not greater than 1!<br />")
End If
If (x > 1) And (y > 1) Then
Response.Write("Both x and y are greater than 1!<br />")
Else
Response.Write("Either x or y is not greater than 1!<br />")
End If
Dim firstName
Dim lastName
Dim fullName
firstName = "John"
lastName = "Smith"
fullName = firstName & " " & lastName
Response.write(fullName)
%>
</body>
</html>
Please help us spread the word by socializing it today!
Did you find something wrong with the information on this page? Please take a moment to report it to us
so that we can continue to improve the quality of the information on this site. Click here to
report an issue with this page.
Recommended Books & Training Resources