Default Properties

Default properties are supported in Visual Basic 2005 only if the properties take arguments. For example, the Label control in VBA has a property called Caption that is the default property; this means that you can assign a value to this control directly, without specifying the property name. In Visual Basic 2005, you must specify the property when assigning values to properties. For example, you would have to type Labell.Text = "OK" to assign the OK string to the label. Typing Labell = "OK" would cause an error.

An example of a default property that takes an argument is the Item property. You do not need to explicitly specify the Item property because it takes an index as a parameter. For example, you can reference a bookmark using Me.Bookmarks(l) instead of specifying the Item property using Me.Bookmarks.Item(l).

Because of this change, you no longer need to use the Set keyword when assigning an object to a variable. The Set keyword was used to differentiate between the assignment of an object and the assignment of a value to a default property of the object. Removing the support for default properties removes the ambiguity of assignment.

0 0

Post a comment