Name

Set Statement

Syntax

Set
   [ statements ]
   [ variable = Value ]
End Set
statements (optional)

Program code to be executed when the Property Set procedure is called

variable (optional; any (the data type of the property)

Typically, a Private variable to hold the property value

Value (optional; Keyword)

A keyword representing the value to be assigned to the property

Description

Defines a Set property procedure that sets a property value

Rules at a Glance

  • The Set statement can only be used within a Property...End Property construct.

  • The value assigned to the property is usually stored to a variable that’s Private to the class. This protects the property value from modification other than by calling the Property Set procedure.

  • The Value keyword represents the value to be assigned to the property. This value must be of the same data type as the property.

Example

The example code illustrates a class that has a simple property and a property array. The syntax documented above, rather than the “official” syntax (see the note in Section ), is used, since in our opinion it is much clearer and intuitive.

Public Enum WageConstants Rate = 0 Overtime = 1 Differential = 2 End Enum Public Class CEmployee Dim strName As String Dim decWage(2) As Decimal Public Property Name( ) As String Set(sName As String) strName = sName End Set Get Return strName End Get End Property Public Property Wage(iType As WageConstants) As Decimal Get Wage = decWage(iType) End Get Set decWage(iType) = Value End Set End Property ...

Get VB.NET Language in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.