Expressions
Expressions are the pieces of code that produce values. They are used in assignments, conditions, function arguments, and return statements.
Supported Expression Forms
- Number literals
- String literals
- Boolean literals
- Identifiers
- New expressions
- System function references
- Parenthesized expressions
- Invocation
- Member access
- Index access
- Unary operators
- Binary operators
Primary Expressions
- 123
- "hello"
- True
- name
- New Player
- Graphics
- (x + 1)
Calls, Members, and Indexes
<expression>([<arg>[, <arg>...]])
<expression>.<identifier>
<expression>\<identifier>
<expression>[<indexExpr>[, <indexExpr>...]]
- Foo()
- DoSomething(1, 2)
- Graphics(800, 600)
- foo.bar
- foo\bar
- arr[0]
- matrix[i, j]
Postfix operations can be chained, such as foo.bar[1].baz(2). Both . and \ are recognized for member access. . is the preferred modern style.
If you are learning arrays for the first time, read Arrays for a step-by-step explanation of declarations, indexes, and common mistakes.
New Expressions
New <TypeName> allocates a new object for a user-defined Type.
Type Player
Field Name As String
Field Score As Integer
End Type
Dim currentPlayer As Player
currentPlayer = New Player
Unary Operators
- +
- -
- Not
- +1
- -value
- Not False
Binary Operators
- Logical: Or, And
- Comparison: =, <>, <, <=, >, >=
- Arithmetic: +, -, *, /, Mod, ^
Comparisons for Beginners
A comparison checks whether one value matches or relates to another value. The result of a comparison is always True or False.
=means equal to<>means not equal to<means less than<=means less than or equal to>means greater than>=means greater than or equal to
You can compare variables to variables, variables to constants, or more complex expressions.
score = 10
health <= 0
playerX > enemyX
lives <> maxLives
(coins + bonus) > targetScore
Logical Conditions for Beginners
Use logical operators when a condition depends on more than one test.
Andmeans both sides must beTrueOrmeans either side can beTrueNotflipsTruetoFalseandFalsetoTrue
score >= 100 And lives > 0
health <= 0 Or timeLeft = 0
Not finished
(x > 0 And y > 0) Or debugMode
When a condition starts to look complicated, add parentheses to make the grouping clear.
Operator Precedence
From lowest to highest:
- 1. Or
- 2. And
- 3. =, <>, <, <=, >, >=
- 4. +, -
- 5. *, /, Mod
- 6. ^
- 7. Unary +, unary -, Not
Parentheses let you force a different order when needed.
- (X + (7 * DoSomething() / MyVar))