With structure

When we declare a variable as an object or custom data type we can access its members in many ways. In the opinion of many, the easier way is to individually “frame” the object fields by the With structure. Instead of dividing the variable and field name by the „points“, it allows us to define a block of commands, enter values by specifying field names, and then closing a block that completes the value assignment process.

Syntax of With the structure is:

With <object>
  <field 1>=<value 1>
  <field n>=<value n>
End With

In the following program you can see how to assign values to a variable without and by using the With structure:

Option Base 1
Type Person
  firstname As String
  lastname As String
  salary As Single
End Type

Sub DW()

Dim Employee(100) As Person
Employee(1).firstname = “Robert”
Employee(1).lastname = “Plant”
Employee(1).salary = 100000

With Employee(2)
  .firstname = “Jimmy”
  .lastname = “Page”
  .salary = 120000
End With

MsgBox Employee(1).salary
MsgBox Employee(2).salary

End Sub