Space-Saving Variables

Exception to the code-entry rule: If you plan to use an object model path repeatedly, define it as a variable, to save space and create a compact script.

Example—What not to type:

ActiveDocument.Sections["Query"].DataModel.Connection.Username = "hyperion"
ActiveDocument.Sections["Query"].DataModel.Connection.SetPassword("hyperion")ActiveDocument.Sections["Query"].DataModel.Connection.Connect

Example—What to type:

DMPath = ActiveDocument.Sections["Query"].DataModel.Connection
DMPath.Username = "hyperion"
DMPath.SetPassword("hyperion")
DMPath.Connect

Treat space-saving variables as object model paths. That is, insert periods between object model segments, and do not add unnecessary spaces.

Also, include only objects in the path; that is, do not include methods or property segments for the objects:

Example—Incorrect script, because ActiveDocument.Sections["Query"].Limits does not have an Activate() method:

LPath = ActiveDocument.Sections["Query"].Limits
LPath.Activate()

Example—Correct script:

LPath = ActiveDocument.Sections["Query"]
LPath.Activate()