This documentation is archived and is not being maintained.

Property Procedure Changes for Visual Basic 6.0 Users

Visual Studio 2008

Visual Basic 2008 updates the declaration of property procedures and parameters for simplification and interoperability with other programming languages.

In Visual Basic 6.0, you use the Property Get, Property Let, and Property Set statements to get and set property values.

You can declare a property parameter to be ByRef. Passing a variable to such a parameter allows a procedure to change that variable in the calling code.

Visual Basic 2008 introduces a unified property declaration syntax that includes the procedures for getting and setting the property's value. This guarantees consistency of property attributes such as access level and overloading. The following example shows the declaration of a property that does not take parameters.

Private monthNum As Integer = 1
Property month() As Integer
        Return monthNum
    End Get
    Set(ByVal Value As Integer)
        If Value < 1 Or Value > 12 Then
            ' Error processing for invalid value. 
            monthNum = Value
        End If
    End Set
End Property

You can use any name you want for the parameter for Set. If you do not supply an argument, Value is automatically generated.

This syntax change makes the Property Get and Property Set statements unnecessary, and they are not supported. Because Visual Basic 2008 does not allow default properties without parameters, Property Let and Property Set are not needed to distinguish whether an object reference or a default property is to be assigned. Therefore, the Property Let statement also is not supported.

Visual Basic 2008 does not support ByRef property parameters. If a property procedure had a ByRef parameter and changed the variable underlying the corresponding argument, the property could behave in an unexpected manner. Therefore, all declarations of parameterized properties must specify ByVal for the parameters.