<< Click to Display Table of Contents >> Hints for simplifying notations |
If you are beginning to wonder whether so much typing is really necessary to address a single document, we can reassure you that it's not! There are several ways to reduce the amount of typing required.
Using the With statement
The first shortcut is to use the With statement when addressing multiple members of the same object.
First, the conventional style:
pm.Application.Left = 100
pm.Application.Top = 50
pm.Application.Width = 500
pm.Application.Height = 300
MsgBox pm.Application.Options.CreateBackup
This code looks much clearer through use of the With statement:
With pm.Application
.Left = 100
.Top = 50
.Width = 500
.Height = 300
MsgBox .Options.CreateBackup
End With
Save time by omitting default properties
There is yet another way to reduce the amount of typing required: Each object (for example, Application or Application.Workbooks) has one of its properties marked as its default property. Conveniently enough, you can always leave out default properties.
The default property of Application, for example, is Name. Therefore, the two following instructions are equivalent:
MsgBox pm.Application.Name ' displays the application name of PlanMaker
MsgBox pm.Application ' does exactly the same
Typically, the property that is used most often in an object has been designated its default property. For example, the most used property of a collection surely is the Item property, as the most common use of collections is to return one of their members. The following statements therefore are equivalent:
MsgBox pm.Application.Workbooks.Item(1).Name
MsgBox pm.Application.Workbooks(1).Name
Finally things are getting easier again! But it gets even better: Name is the default property of a single Workbook object (note: "Workbook", not "Workbooks"!). Each Item of the Workbook collection is of the Workbook type. As Name is the default property of Document, it can be omitted:
MsgBox pm.Application.Workbooks(1)
Not easy enough yet? OK... Application is the default property of PlanMaker. So, let's just leave out Application as well! The result:
MsgBox pm.Workbooks(1)
This basic knowledge should have prepared you to understand PlanMaker's object model. You can now continue with the next section that contains a detailed list of all objects that PlanMaker provides.