Default Property Changes in Visual Basic
Visual Basic 6.0
In Visual Basic 6.0, default properties are supported on objects. On a Label control, for example, Caption is the default property, and the two assignments in the following example are equivalent:
Dim L As Label
L = "Important"
L.Caption = "Important"
While default properties enable a certain amount of shorthand in writing Visual Basic code, they have several drawbacks:
-
They can make code more difficult to read. In the preceding example, if you are not familiar with the Label control, you cannot tell from the first assignment whether the string
"Important"is being stored directly in the variableLor in a default property. -
Given an object that you plan to use in your code, it is not always easy to discover whether it has a default property, and if so, which property that is.
-
Default properties make the Set statement necessary in the Visual Basic language. The following example shows how Set is needed to indicate that an object reference, rather than a default property, is to be assigned:
Dim L1 As Label, L2 As Label
L1 = "Saving" ' Assign a value to L1's Caption property.
L2 = L1 ' Replace L2's Caption property with L1's.
L2 = L1 ' Replace L2 with an object reference to L1. End Sub

Join the conversation! Your thoughts help the community grow.