VB 2005 supports the various operators shown in Table 2-2.
Table 2-2. Operators supported in VB 2005
Type | Language element | Description |
|---|
Arithmetic | ^ | Raises to the power of |
| | | Subtraction |
| | * | Multiplication |
| | / | Division |
| | \ | Integer Division |
| | Mod | Modulus (remainder) |
| | + | Addition |
Assignment | = | Assigns a value to a variable or property |
| | ^= | Raises the value of a variable to the power of an expression and assigns the result back to the variable (new in VB 2005) |
| | *= | Multiplies the value of a variable by the value of an expression and assigns the result to the variable (new in VB 2005) |
| | /= | Divides the value of a variable by the value of an expression and assigns the result to the variable (new in VB 2005) |
| | \= | Divides the value of a variable by the value of an expression and assigns the integer result to the variable (new in VB 2005) |
| | += | Adds the value of an expression to the value of a variable and assigns the result to the variable (works for strings as well) (new in VB 2005) |
| | -= | Subtracts the value of an expression from the value of a variable and assigns the result to the variable (new in VB 2005) |
| | &= | Concatenates a String expression to a String variable and assigns the result to the variable (new in VB 2005) |
Comparison | = | Equal |
| | <> | Not equal to |
| | < | Less than |
| | > | Greater than |
| | <= | Less than or equal to |
| | >= | Greater than or equal to |
| | Like | Compares a string against a pattern |
| | Is | Compares two object reference variables |
| | IsNot | Compares two object reference variables |
Concatenation | & | Concatenates two strings |
| | + | Concatenates two strings |
Logical/bitwise operations | Not | Logical negation on a Boolean expression |
| | And | Logical conjunction on two Boolean expressions, or bitwise conjunction on two numeric expressions |
| | Or | Logical disjunction on two Boolean expressions, or bitwise disjunction on two numeric values |
| | Xor | Logical exclusion operation on two Boolean expressions, or bitwise exclusion on two numeric expressions |
| | AndAlso | Short-circuiting logical conjunction on two expressions (new in VB 2005) |
| | OrElse | Short-circuiting logical disjunction on two expressions (new in VB 2005) |
Miscellaneous operations | AddressOf | Creates a procedure delegate instance that references the specific procedure (new in VB 2005) |
| | GetType | Returns a Type object for the specified type (new in VB 2005) |
When testing for the equality of numeric values, use the = operator. Use the Is operator to test the equality of objects. Chapter 3 will discuss the use of the Is operator in greater detail.