With (statement)

<< Click to Display Table of Contents >>

With (statement)

With Object

 [Statements]

End With

Executes a group of statements for the given object.

The With statement allows accessing the elements of an object without having to repeat the object name over and over again.

Note: With statements may be nested.

See also: While Wend, Do Loop, section Hints for simplifying notations

Example:

Type type1

 a As Integer

 d As Double

 s As String

End Type

Type type2

 a As String

 o As type1

End Type

Dim var1a As type1

Dim var2a As type2

Sub Main

 With var1a

         .a = 65

         .d = 3.14

 End With

 With var2a

 .a = "Hello"

         With .o

                 .s = "Bye!"

         End With

 End With

 var1a.s = "TEST"

 MsgBox var1a.a

 MsgBox var1a.d

 MsgBox var1a.s

 MsgBox var2a.a

 MsgBox var2a.o.s

End Sub