8.1.4 Compound Statements

A compound statement includes a two or more expressions, each of which returns an object. Compound statements are useful when you have to traverse the object hierarchy to reference an object. For example, the following compound statement returns a reference to a Screen object.

Set SessionScreen = InfoConnect.Sessions(1).Screen.Area(1,1,10,80)

This statement is evaluated as follows:

Expression

Object Returned

InfoConnect.Sessions

Sessions collection object.

Sessions(1) (equivalent to Sessions.Item(1) )

The first session in the collection.

Screen property of the first session

Screen object.

The Area method of the returned Screen object

An Area object that defines a screen segment from row 1, column 1 to row 10, column 80.

Because only the Screen object has to be referenced, the use of the compound statement is far more efficient than assigning multiple object references to multiple object variables. Compare the compound statement to the equivalent set of statements below.

Dim SessionsObj As Object
Dim SessionObj As Object
Dim ScreenObj As Object
Dim AreaObj As Object
Set SessionsObj = infoconnect.Sessions
Set SessionObj = SessionsObj(1)
Set ScreenObj = SessionObj.Screen
Set AreaObj = ScreenObj.Area(1,1,10,80)