Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Set Statement

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

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

Parts

attrlist
Optional. List of attributes that apply to this Set block. Multiple attributes are separated by commas.
value
Required. This parameter contains the new value for the property.
datatype
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.
block
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

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

Remarks

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

Example

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

Class PropClass
   Private PropVal As Integer
   Property Prop1() As Integer
      Get
         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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft