Expressions

Expressions are the pieces of code that produce values. They are used in assignments, conditions, function arguments, and return statements.

Back to Language Reference


Supported Expression Forms

Primary Expressions

Calls, Members, and Indexes

<expression>([<arg>[, <arg>...]]) <expression>.<identifier> <expression>\<identifier> <expression>[<indexExpr>[, <indexExpr>...]]

Postfix operations can be chained, such as foo.bar[1].baz(2). Both . and \ are recognized for member access. . is the preferred modern style.

Enum members are accessed with EnumName.MemberName. The bare enum name (for example Direction) is a type name and cannot be used by itself as a value expression.

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

Binary Operators

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.

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.

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:

Parentheses let you force a different order when needed.