Set Statement
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Set Statement

Declares a Set property procedure used to assign a value to a property.

[ <attrlist> ] Set(ByVal value [ As datatype ])
   [ block ]
End Set


Optional. List of attributes that apply to this Set block. Multiple attributes are separated by commas.
Required. This parameter contains the new value for the property.
Required if Option Strict is On. Declares the data type of the value parameter. The data type specified must be the same as the data type of the property where this Set statement is declared.
Optional. The body of the Set procedure contains code to set the property value.
End Set
Terminates a Set property procedure.

Each attribute in the attrlist part has the following syntax and parts:

attrname [({ attrargs | attrinit })]

attrlist Parts

Required. Name of the attribute. Must be a valid Visual Basic identifier.
Optional. List of positional arguments for this attribute. Multiple arguments are separated by commas.
Optional. List of field or property initializers for this attribute. Multiple initializers are separated by commas.


Visual Basic .NET calls the Set property procedure when the value of a property is changed in an assignment operation.


This example uses the Set statement to set the value of a property.

Class PropClass
   Private PropVal As Integer
   Property Prop1() As Integer
         Return PropVal ' Same As Prop1 = PropVal
      End Get
      Set(ByVal Value As Integer)
         PropVal = Value
      End Set
   End Property
End Class

See Also

Get Statement | Property Statement | Adding Fields and Properties to a Class

© 2015 Microsoft