VB.NET Language in a Nutshell

   
With Statement

Syntax

With object [ statements ] End With

object (required; Object)

A previously declared object variable or user -defined type

statements (optional)

Program code to execute against object

Description

This statement is used to execute a series of statements on an object without having to qualify each statement with the object name .

Rules at a Glance

Example

Public Structure Point Dim x As Integer Dim y As Integer End Structure Public Sub Main Dim udtPt As POINT With udtPt .x = 10 .y = 100 End With Console.Writeline(udtpt.x) End Sub

Programming Tips and Gotchas

It is important that you do not include code within the With statement block that forces execution to branch out of the block. Similarly, do not write code that forces program flow to jump into a With block. Both the With and its associated End With statement must be executed, or you will generate unpredictable results.

   

Категории