Navigation:  ThinBASIC language > Data types and variables > TYPE >

WITH / END WITH

Previous pageReturn to chapter overviewNext page

 

Description

 

With...End With allows you to perform a series of statements on a specified UDT variable without the need to type the name of the UDT variable.

 

Syntax

 

WITH UDTVariable[(index)]

 

 [statements]

 

END WITH

 

Returns

 

None

 

Parameters

 

Remarks

 

You can nest With...End With structures by placing one structure within another up to 25 levels.

However, because members of outer statements are masked inside the inner statements, you must provide a fully qualified UDT reference in an inner With block to any member of an object in an outer With block.

 

Restrictions

 

If the UDT Variable is an array of UDT, variable must be specified with the array index to be accessed.

 

See also

 

Examples

 

Type MyType

    a As Long

    b As Long

    s As String * 100

End Type

 

Dim x As MyType

Dim y As MyType

 

'---Up to 25 nested WITH levels

With x

    .a = 10

    With y

        .a = 1

        .b = 2

        .s = "This is Y"

    End With

 

    .b = 20

    .s = "This is X"

End With

 

With x

    .a += .a * .b

    .s = trim$(.s) + "-Added later"

End With

 

MSGBOX 0, _

            "---The following is X---" & $crlf & _

                $Tab & x.a & $crlf & _

                $Tab & x.b & $crlf & _

                $Tab & x.s & $crlf & _

            "---The following is Y---" & $crlf & _

                $Tab & y.a & $crlf & _

                $Tab & y.b & $crlf & _

                $Tab & y.s & $crlf & _

            ""

 

Dim ax(10) As MyType

 

With ax(5)

  .a = 25

End With

 

MSGBOX 0, "Used with array of UDT: " & ax(5).a