Dear John, How Do I... Set a Default Property for My Object?

I prefer to always set all properties explicitly rather than by using the shortcut for an object's default property, but some people prefer to do it the other way. For example, the Text property is the default property for the TextBox control, which means that you can set the Text property explicitly or by default. Both of these lines have exactly the same effect:

Text1.Text = "This string is assigned to the Text property."
Text1 = "This string is assigned to the Text property."

It's not well documented, but Visual Basic now lets you assign a default property to your own objects, if you like to use this technique. Let's see how this is done by setting the Loan object's Principal property as its default property. Bring up the code for the Loan class, and from the Tools menu choose Procedure Attributes to display the Procedure Attributes dialog box. From the Name drop-down list, select the Principal property. Click the Advanced button, select the (Default) option from the Procedure ID drop-down list, and click OK. The Principal property is now the default for the Loan object.

To verify the correct operation of this default property, bring up the code for the form you created to test the Loan object. Find the line on which the Principal property is set to 1000, and edit the line to remove the .Principal part, as shown here:

loanTest = 1000

Run the test application, and verify that it still calculates the loan values correctly.