Arithmetic Operators
Operator | Description | Example |
---|---|---|
+ | Addition | Dim sum = a + b |
- | Subtraction | Dim diff = a - b |
* | Multiplication | Dim prod = a * b |
/ | Division (floating‑point) | Dim quot = a / b |
\ | Integer division | Dim intQuot = a \ b |
Mod | Modulus (remainder) | Dim r = a Mod b |
^ | Exponentiation | Dim p = a ^ b |
Comparison Operators
Operator | Description | Example |
---|---|---|
= | Equality | If a = b Then ... |
<> | Inequality | If a <> b Then ... |
< | Less than | If a < b Then ... |
> | Greater than | If a > b Then ... |
<= | Less than or equal | If a <= b Then ... |
>= | Greater than or equal | If a >= b Then ... |
Is | Reference comparison | If obj1 Is obj2 Then ... |
IsNot | Reference inequality | If obj1 IsNot obj2 Then ... |
Logical (Boolean) Operators
Operator | Description | Example |
---|---|---|
And | Logical AND (no short‑circuit) | If A And B Then ... |
AndAlso | Logical AND with short‑circuit | If A AndAlso B Then ... |
Or | Logical OR (no short‑circuit) | If A Or B Then ... |
OrElse | Logical OR with short‑circuit | If A OrElse B Then ... |
Not | Logical negation | If Not A Then ... |
Xor | Exclusive OR |
String Concatenation Operator
Operator | Description | Example |
---|---|---|
& | String concatenation | Dim full = firstName & " " & lastName |
Assignment Operators
Operator | Description | Example |
---|---|---|
= | Simple assignment | Dim x = 5 |
+= | Add and assign | x += 3 ' x = x + 3 |
-= | Subtract and assign | x -= 2 ' x = x - 2 |
*= | Multiply and assign | x *= 4 ' x = x * 4 |
/= | Divide and assign | x /= 2 ' x = x / 2 |
\= | Integer divide and assign | x \= 3 ' x = x \ 3 |
Mod= | Modulus and assign | x Mod= 5 ' x = x Mod 5 |
^= | Exponentiate and assign | x ^= 2 ' x = x ^ 2 |
&= | Concatenate and assign | str &= "World" |
Type‑Conversion Operators
Operator | Description | Example |
---|---|---|
CType(..., Type) | Runtime conversion | Dim s As String = CType(i, String) |
DirectCast(..., Type) | Compile‑time cast (no conversion) | Dim obj As Object = DirectCast(str, Object) |
TryCast(..., Type) | Safe cast returning Nothing on failure | Dim btn As Button = TryCast(ctrl, Button) |