This documentation is archived and is not being maintained.

Property Changes in Visual Basic

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

Visual Basic 6.0

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

Passing a variable the ByRef property argument allows a procedure to change that variable in the calling code.

Visual Basic .NET

Visual Basic .NET 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 arguments:

Private MonthNum As Integer = 1  ' Internal storage for property value. 
Property Month( ) As Integer 
   Get 
      Return MonthNum 
   End Get 
   Set(ByVal Value As Integer) 
      If Value < 1 Or Value > 12 Then 
         ' Error processing for invalid value. 
      Else 
         MonthNum = Value 
      End If 
   End Set 
End Property   ' Month 

You can use any name you want for the argument to 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 .NET does not allow default properties without arguments, 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 .NET does not support ByRef property arguments. If a property procedure has a ByRef argument and changes the variable underlying that argument, the property can behave in an unexpected manner. Therefore, all declarations of parameterized properties must specify ByVal for the arguments.

See Also

Default Property Changes in Visual Basic | ByVal | Programming Element Support Changes Summary

Show: