Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))

Chapter 16 Quick Reference

To

Do this

Inherit an existing form's interface and functionality

Click the Add New Item command on the Project menu, click the Inherited Form template, specify a name for the inherited form, and then click Add. Use the Inheritance Picker to select the form you want to inherit, and then click OK. Note that to be eligible for inheritance, base forms must be compiled as .exe or .dll files. If you want to inherit a form that isn't a component in the current project, the form must be compiled as a .dll file.

Customize an inherited form

Add Toolbox controls to the form, and set property settings. Note that you won't be able to set the properties of inherited objects on the form. These objects are identified by small icons and are inactive.

Create your own base classes

Click the Add Class command on the Project menu, specify the class name, and then click Open. Define the class in a class module by using program code.

Hide declared variables in a class

Use the Private keyword to hide class variables from other programmers that examine your class. For example:

Private Name1 As String

Create a new property in the class

Define a public property procedure in the class. For example:

Public Property FirstName() As String Get Return Name1 End Get Set(ByVal value As String) Name1 = value End Set End Property

Create a new method in the class

Define a Sub or Function procedure in the class. For example:

Public Function Age(ByVal Birthday As Date) _ As Integer Return Int(Now.Subtract(Birthday).Days _ / 365.25) End Function

Declare an object variable to use the class

Use the Dim and New keywords, a variable name, and the user-defined class in a program statement. For example:

Dim Employee As New Person

Set properties for an object variable

Use the regular syntax for setting object properties. For example:

Employee.FirstName = TextBox1.Text

Inherit a base class in a new class

Create a new class, and use the Inherits keyword to incorporate the base class's class definitions. For example:

Public Class Teacher Inherits Person Private Level As Short Public Property Grade() As Short Get Return Level End Get Set(ByVal value As Short) Level = value End Set End Property End Class

Категории