Name
Set Statement
Syntax
Get( ) [statements] [variable= Value ] End Get
-
statements Use: Optional
Program code to be executed when the Property Set procedure is called
-
variable Use: Optional
Data Type: Any (the data type of the property)
Typically, a Private variable to hold the property value
-
Value Use: Optional
Type: Keyword
A keyword representing the value to be assigned to the property
Description
Defines a Property Set procedure that sets a property value
Rules at a Glance
The
Setstatement can only be used within aProperty...EndPropertyconstruct.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 Get procedure.
The
Valuekeyword 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) = ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access