100% found this document useful (1 vote)
60 views1 page

VBSyntax WithStatement

This document discusses the WITH statement in VB.NET, which allows programmers to abbreviate a group of statements by avoiding repetition of an object reference. The WITH statement uses the object as a prefix for subsequent statements, equivalent to writing out the full object reference each time but more concise. An example is provided showing how the WITH statement can clean up code by removing repeated references to objDS.Tables(0) in a series of statements operating on that object.

Uploaded by

sedmondsbrown
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
60 views1 page

VBSyntax WithStatement

This document discusses the WITH statement in VB.NET, which allows programmers to abbreviate a group of statements by avoiding repetition of an object reference. The WITH statement uses the object as a prefix for subsequent statements, equivalent to writing out the full object reference each time but more concise. An example is provided showing how the WITH statement can clean up code by removing repeated references to objDS.Tables(0) in a series of statements operating on that object.

Uploaded by

sedmondsbrown
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

SEB’s VB.

NET Guide

Useful Statements

The WITH Statement:


The WITH statement is used to abbreviate a group of statements.

EG:
With objDS.Tables(0)
objRow = .NewRow
objRow (“UserName”) = txtName.Text
objRow (“HighScore”) = txtScore.Text
.Rows.Add(objRow)
End With

This will perform exactly the same as the longer statements:

objRow = objDS.Tables(0).NewRow
objRow(“UserName”) = txtName.Text
objRow(“HighScore”) = txtScore.Text
objDS.Tables(0).Rows.Add(objRow)

As can be seen, the WITH statement avoids repetition of objDS.Tables(0) as a full stop
indicates that it is to be used as a prefix.

Page 1 of 1

You might also like