Statements

TODO

Declaration statements

You use declaration statements to name and define procedures, variables, constants, and more. When you declare a programming construct, you can also define its data type, access level, and scope. See Declared Element Characteristics for more information,.

Initial values

TODO

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

TODO

Data types and conversions

TODO

Compound assignment

TODO

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

ElementExample
After a comma (,)
Method ChangePassword(user_id As String,
        old_password As String,
        new_password 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 instead"
Method foo(a As Int32, b As String)

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

Adding comments

TODO

comments and divided statements

TODO

See also