A statement is a full instruction. It can contain keywords, operators, variables, constants, and expressions. Each statement goes into one of the categories that follow:
- Declaration statements give names to variables, constants, and procedures. They can also supply a data type.
- Executable statements cause something to occur. They can call a procedure, or move execution through loops and branches in code. They can also change a variable with an assignment statement.
You use declaration statements to identify and make procedures, variables, constants, and more. When you declare a programming construct, you can also identify its data type, access level, and scope. See Declared Element Qualities for more information,.
An executable statement causes changes. It can move to different parts of the code, execute other statements again and again, or calculate a result.
An assignment statement is a special type of executable statement.
It gets the value on the right side of the assignment operator (
=), then stores that in the element on the left side.
An example follows.
x = 42
Here the assignment statement stores the literal value 42 in the variable x.
Data types and conversions
A compound assignment statement first does an operation on an expression, then assigns the result to a variable.
The example below uses the operator
It adds the value of the expression on the right to the value of the variable on the left.
x += 1
This is the same as the statement that follows.
x = x + 1
For a list of such operators, see Assignment Operators.
You can give many variables the same value with one statement.
Chained assignment uses a special operator (
You put this operator after each of the variables, then put an expression last.
You cannot use other assignment operators with this statement.
An example follows.
' Reset the coordinates. x := y := z := 0.0
Note: You also can use the operator
:= in arguments passed to procedures.
See Parameter List for more information.
Statements divided into many lines
Most statements are short, but can become too long to read easily.
You can divide a long statement into two or more lines of code.
You write a space and an underscore (
_) before the end-of-line.
In the example that follows, a name and address returned from a database table are printed to a label.
#address_label.Text = _ #row!Name & $N & _ #row!Address
Divided statements without the underscore
Some conditions let you continue a statement on a different line without the underscore character (
In the table that follows are the elements of a statement and conditions in which the compiler ignores an end-of-line.
|After a comma (
|After a left parenthesis (
|After a left brace (
|After a modifier that starts with the at-sign (
For information about using comments after a line continuation sequence, see the section below.
comments and divided statements