With...End With Statement


With...End With Statement

Syntax

     With object        [statements]     End With 


object (required; Object)

A previously declared object variable or instance


statements (optional)

Program code to execute against object

Description

The With...End With block construct is used to execute a series of statements on an object without having to qualify each use with the object name itself.

Usage at a Glance

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

  • With statements can be nested, but only the object referenced in the inner block's With clause can be used without qualification by the code in the inner block.

  • You cannot jump into or out of a With block using the GoTo statement. If you need to exit a block early, you can place a label on the End With line and use a GoTo statement to jump to that line.

  • object cannot be assigned a new instance while in the With block.

Example

     Public Structure Point        Public x As Integer        Public y As Integer     End Structure     Public Sub TestPoint(  )        Dim samplePoint As Point        With samplePoint           .x = 10     ' Refers to samplePoint.x           .y = 100    ' Refers to samplePoint.y        End With        MsgBox(samplePoint.x)     End Sub 

See Also

Using...End Using Statement




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net