Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Scripting
VBScript
 With Statement (VBScript)
This page is specific to
.NET Framework 3.0

Other versions are also available for the following:
Visual Basic Scripting Edition
With Statement (VBScript)

Updated: November 2007

Executes a series of statements on a single object.

With object
      statements
End With
object

Required. Name of an object or a function that returns an object.

statements

Required. One or more statements to be executed on object.

The With statement allows you to perform a series of statements on a specified object without requalifying the name of the object. For example, to change a number of different properties on a single object, place the property assignment statements within the With control structure, referring to the object once instead of referring to it with each property assignment. The following example illustrates use of the With statement to assign values to several properties of the same object.

With MyLabel
   .Height = 2000
   .Width = 2000
   .Caption = "This is MyLabel"
End With

While property manipulation is an important aspect of With functionality, it is not the only use. Any legal code can be used within a With block.

Note:

Once a With block is entered, object can't be changed. As a result, you can't use a single With statement to affect a number of different objects.

You can nest With statements by placing one With block within another. However, because members of outer With blocks are masked within the inner With blocks, you must provide a fully qualified object reference in an inner With block to any member of an object in an outer With block.

Important Do not jump into or out of With blocks. If statements in a With block are executed, but either the With or End With statement is not executed, you may get errors or unpredictable behavior.

Reference

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker