Skip to Content
VB.NET Language in a Nutshell, Second Edition
book

VB.NET Language in a Nutshell, Second Edition

by Steven Roman PhD, Ron Petrusha, Paul Lomax
April 2002
Intermediate to advanced
688 pages
19h 51m
English
O'Reilly Media, Inc.
Content preview from VB.NET Language in a Nutshell, Second Edition

Name

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

  • The single object referred to in the With statement remains the same throughout the code contained within the With...End With block. Therefore, only properties and methods of object can be used within the code block without explicitly referencing the object. All other object references within the With...End With statement must start with a fully qualified object reference.

  • With statements can be nested, as long as the inner With statement refers to a subobject or a dependent object of the outer With statement.

  • A member of object is referenced within a With block by omitting the object name and simply including a period and the member name.

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

VB .NET Language in a Nutshell

VB .NET Language in a Nutshell

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596003080Supplemental ContentCatalog PageErrata