IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesASP ClassicOperators  Print This     

Cross Ref > Operators

By Mike Prestwood

ASP Classic versus VB Classic: A side by side comparison between ASP Classic and VB Classic.

 
Operators
 

A language symbol used for assignment, comparison, computational, or as a logical.

Assignment

[Other Languages] 

Languages Focus

Common assignment operators for languages include =, ==, and :=. An assignment operator allows you to assign a value to a variable. The value can be a literal value like "Mike" or 42 or the value stored in another variable or returned by a function.

ASP Classic:   =

ASP Classic uses = for it's assignment operator.

Syntax Example:
FullName = "Randy Spitz"
Age = 38
VB Classic:   =

VB Classic uses = for it's assignment operator.

Syntax Example:
Dim Age As Integer
Dim FullName As String
   
FullName = "Randy Spitz"
Age = 38




Comparison Operators

[Other Languages] 

General Info: Round Floating Point Numbers

When comparing floating point numbers, make sure you round to an acceptable level of rounding for the type of application you are using.

Languages Focus

A comparison operator compares two values either literals as in "Hello" and 3 or variables as in X and Counter. Most languages use the same operators for comparing both numbers and strings. Perl, for example, uses separate sets of comparison operators for numbers and strings.

ASP Classic:   =, <>

Save as VB Classic. Common comparison operators:

= equal
<> not equal
< less than
> greater than
<= less than or equal
>= greater than or equal
Syntax Example:
//Does ASP evaluate the math correctly? No!
If .1 + .1 + .1 = .3 Then
Response.Write "correct"
Else
Response.Write "not correct"
End If
VB Classic:   =, <>

Common comparison operators:

= equal
<> not equal
< less than
> greater than
<= less than or equal
>= greater than or equal
Syntax Example:
//Does VB evaluate the math correctly? No!
If 0.1 + 0.1 + 0.1 = 0.3 Then
MsgBox "correct"
Else
MsgBox "not correct"
End If




Empty String Check

[Other Languages] 

Languages Focus

An empty string is a zero length string, a string that is equal to null (""), or not assigned. In some languages, you can check if a string is empty by comparing it to an empty string (""). Some languages distinguish between nil and null ("") so checking if the length is 0 is easier.

ASP Classic:   Len(s&vbNullString)

In ASP Classic, you have to add an empty string to the value being compared in order to get consistent results. For example, add &"" to your string varilable or it's code equivalent &vbNullString. Then compare to an empty string or verify it's length to 0 with Len.

Syntax Example:

All these will work for variables unassigned, set to "", or set to Null:

If s&"" = "" Then
  Response.Write("<br>Quotes with &'' say null is empty")
End If
 
If Len(s&"") = 0 Then
  Response.Write("<br>Len with &'' says null is empty")
End If
 
If Len(s&vbNullString) = 0 Then
  Response.Write("<br>Using vbNullString also works!")
End If
VB Classic:   Len(s&vbNullString)

In VB Classic, you have to add an empty string to the value being compared in order to get consistent results. For example, add &"" to your string varilable or it's code equivalent &vbNullString. Then compare to an empty string or verify it's length to 0 with Len.

Syntax Example:

All these will work for variables unassigned, set to "", or set to Null:

If s&"" = "" Then
MsgBox ("Quotes with &'' say null is empty")
End If
 
If Len(s&"") = 0 Then
MsgBox ("Len with &'' says null is empty")
End If
 
If Len(s&vbNullString) = 0 Then
MsgBox ("Using vbNullString also works!")
End If




Logical Operators

[Other Languages] 

Languages Focus

Logical operators perform conditional and, or, and not operations. Some languages support both binary logical operators that link two and unary logical operators negate (make opposite) the truth value of its argument. Finally, some languages short circuit logic. For example, with this or that, if this is an expression returning true, then that is never executed.

ASP Classic:   and, or, not

Same as VB. ASP Classic logical operators:

and and, as in this and that
or or, as in this or that
Not Not, as in Not This

ASP Classic never short circuits. Given the expression this or that as well as this and that, if this evaluates to false, then that is still executed.

Syntax Example:
'Given expressions a, b, c, and d:
If Not (a and b) and (c or d) Then
  'Do something.
End If
VB Classic:   and, or, not

VB Classic logical operators:

and and, as in this and that
or or, as in this or that
Not Not, as in Not This

VB Classic never short circuits. Given the expression this or that as well as this and that, if this evaluates to false, then that is still executed.

Syntax Example:
'Given expressions a, b, c, and d:
If Not (a and b) and (c or d) Then
  'Do something.
End If




String Concatenation

[Other Languages] 
ASP Classic:  "String Concatenation" & or +

Although you can use either a & or a + to concatenate values, my preference is to use a + because more languages use it. However, if you use & then some type conversions are done for you. If you use + you will sometimes have to cast a value to concatenate it. For example, you will have to use CStr to cast a number to a string if you use the + operator as a concatenation operator.

Syntax Example:
Dim FirstName
Dim LastName
 
FirstName  = "Mike"
LastName  = "Prestwood"
 
Response.Write "Full name: " & FirstName & " " + LastName
 
Response.Write "2+2=" + CStr(2+2)
VB Classic:  "String Concatenation" & or +

Although you can use either a & or a + to concatenate values, my preference is to use a + because more languages use it. However, if you use & then some type conversions are done for you. If you use + you will sometimes have to cast a value to concatenate it. For example, you will have to use CStr to cast a number to a string if you use the + operator as a concatenation operator.

Syntax Example:
Dim FirstName As String
Dim LastName As String
 
FirstName = "Mike"
LastName = "Prestwood"
 
MsgBox "Full name: " & FirstName & " " + LastName
 
MsgBox "2+2=" + CStr(2+2)




Unary Operators

[Other Languages] 

General Info: Unary Operator

An operation with only one operand (a single input). Common unary operators include + plus, - minus, and bitwise not. Some operators can function as both unary and binary operators. For example, + and - operators can serve as either.

Languages Focus

What unary operators are supported in additoin to the standard plus, minus, and bitwise not.

ASP Classic: 

An operation with only one operand (a single input) such as +, -, and Not.

VB Classic: 

An operation with only one operand (a single input) such as +, -, and Not.





Sales Website: www.prestwood.com Or visit our legacy sales site: 
legacy.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]