How to Specify a Default Property in Visual Basic
- 1). Declare the property as a part of your class definition as you normally would. The property must have Public accessibility, so you must not use the Shared or Private keyword in the declaration. As an example, the property XXXX is declared as follows:
Property myMessageString As String - 2). Add the Default keyword to the declaration, preceding the Property keyword. The example statement is modified to read:
Default Property myMessageString As String - 3). Add a minimum of one parameter to the property declaration. A Default property must have at least one argument. Add an argument list to the example as follows:
Default Property myMessageString( ByVal index As Integer) As String - 4). Write Get and Set property procedures to enable access to the stored data values. The procedures are written between the Property signature and the End Property statement. The Get procedure is called when the Property's value is retrieved. The Set procedure stores the values received by the Property. The Get procedure for the example is very simple, reading:
Get
Return myTextStrings(index)
End Get
The Set is equally simple as it stores the values to a class array:
Set
myTextStrings(index) = Value
End Set