Microsoft KB Archive/161052

= How To Create a Default Value for Custom Controls and Classes =

Article ID: 161052

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q161052



SUMMARY
Microsoft Visual Basic 5.0 and 6.0 allow you to create custom controls and Classes that have a default property. This behavior is similar to the intrinsic TextBox control. The TextBox control has a default value that corresponds to the string value of its Text property. This allows the following code to behave identically: MsgBox Text1.Text -and- MsgBox Text1 Both will display a dialog box containing the Text shown within the TextBox.



MORE INFORMATION
To set an existing property as the default value for a custom control or Class, do the following:


 * 1) Load your custom control project into Microsoft Visual Basic.
 * 2) In the Project window, right-click your custom control or Class. Click View Code.
 * 3) On the Tools menu, click Procedure Attributes.
 * 4) In the Name field, select the property you wish to set as the default.
 * 5) Click Advanced.
 * 6) In the Procedure ID field, select Default. Click OK.

The selected property is now automatically returned when you reference an instance of your control: Msgbox UserControl1.MyProperty -and- Msgbox UserControl1 are equivalent statements.

