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

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,.

Initial values


Executable statements

An executable statement causes changes. It can move to different parts of the code, execute other statements again and again, or calculate a result.

Assignment statements

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.

Eligible elements


Data types and conversions


Compound assignment

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.

Chained assignment

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 & _

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 (,)
Method ChangePassword(user_id As String,
        password_to_change As String,
        password_to_be As String) As Boolean
    ' ...
End Method
After a left parenthesis (()
@Abstract Method Read_in_list [Type] (
    ByRef List[Type] #user_data )
After a left brace ({) or between two right braces (})
Dim numbers() As Int32 = {
    { 1, 2, 3, 4, 5 },
    { 6, 7, 8, 9, 10 }
After a modifier that starts with the at-sign (@)
@Deprecated "Use foobar as an alternative"
Method foo(a As Int32, b As String)

For information about using comments after a line continuation sequence, see the section below.

Adding comments


comments and divided statements


See also