The Object ClassObjects not only bring encapsulation to your programming fingertips, but they are also part of an object hierarchy called an object class. The benefit of a class is that all objects in the class share the same features. (A single object is said to be an instance of the class.)
When you test an object with If TypeOf, Visual Basic returns the object's class. Therefore, the following line of code returns True or False, depending on whether the object named myObj is a part of the CommandButton class: If TypeOf myObj Is CommandButton ' Check the class
Classes make programming with objects more flexible than would be possible without the class structure. For example, the With...End With statement lets you easily assign multiple properties for a single object. Notice the following code's redundancy: chkMaster.Caption = "Primary Source" chkMaster.Alignment = vbLeftJustify chkMaster.Enabled = True chkMaster.Font.Bold = False chkMaster.Left = 1000 chkMaster.RightToLeft = False chkMaster.Top = 400 When you enclose an object inside a With...End With block, you can eliminate the repetition of the object name. The following code is identical to the previous code: With chkMaster .Caption = "Primary Source" .Alignment = vbLeftJustify .Enabled = True .Font.Bold = False .Left = 1000 .RightToLeft = False .Top = 400 End With
|
|
![]() |
![]() |
|||