Share via


Other Control Structures 

Visual Basic provides control structures that help you dispose of a resource or reduce the number of times you have to repeat an object reference.

Using...End Using Construction

The Using...End Using construction establishes a statement block within which you make use of a resource such as a SQL connection. You can optionally acquire the resource with the Using statement. When you exit the Using block, Visual Basic automatically disposes of the resource so that it is available for other code to use. The resource must be local and disposable. For more information, see Using Statement (Visual Basic).

With...End With Construction

The With...End With construction allows you to specify an object reference once and then run a series of statements that access its members. This can simplify your code and improve performance because Visual Basic does not have to re-establish the reference for each statement that accesses it. For more information, see With...End With Statement (Visual Basic).

See Also

Tasks

How to: Transfer Control Out of a Control Structure

Reference

Using Statement (Visual Basic)
With...End With Statement (Visual Basic)

Concepts

Decision Structures
Loop Structures
Nested Control Structures

Other Resources

Control Flow in Visual Basic