This documentation is archived and is not being maintained.

10.3 With Statement

Visual Studio .NET 2003

A With statement allows multiple references to an expression's members without specifying the expression multiple times. The expression must be classified as a value and is evaluated once, upon entry into the block. Within the With statement block, a member access expression or dictionary access expression starting with a period or an exclamation point is evaluated as if the With expression preceded it. For example:

Structure Test
    Public x As Integer

    Function F() As Integer
        Return 10
    End Sub
End Structure

Module TestModule
    Sub Main()
        Dim y As Test

        With y
            .x = 10
            .x = .F()
        End With
    End Sub
End Module

It is invalid to branch into a With statement block from outside of the block.

WithStatement ::=
   With Expression StatementTerminator
   [ Block ]
   End With StatementTerminator

See Also

10.1 Blocks | 10.1.1 Local Variables and Parameters | 10.2 Local Declaration Statements | 10.4 SyncLock Statement | 10.5 Event Statements | 10.6 Assignment Statements | 10.7 Invocation Statements | 10.8 Conditional Statements | 10.9 Loop Statements | 10.10 Exception-Handling Statements | 10.11 Branch Statements | 10.12 Array-Handling Statements | With...End With Statements (Visual Basic Language Reference) | With...End With Statements (Visual Basic Language Concepts)