
Automation 2-15
2-15
necessary to subtract one in order to access all the objects in
the collection.
The example below, is identical to the first example except that
a For Each loop is used instead of the standard For loop in order
to enumerate through the Streams collection.
Variants
A property can return a variety of variable types. Values such as
temperature and pressure are returned as doubles or 32-bit
floating-point values. The stream name property returns a string
value. Visual Basic provides an additional variable called a
variant. A variant is a variable that can take on the form of any
type of variable including, Integers, Double, String, Array, and
Objects.
If the property of an object returns an array whose size can vary
depending upon the case, then a variant is used to access that
value. For example, the ComponentMassFractionValue property
of a ProcessStream returns an array of doubles sized to the
number of components associated with that stream.
In Visual Basic, if a variable is not explicitly declared then it is
Example 1: Accessing Collection Objects
Dim hyStreams As Streams
Dim hyStream As ProcessStream
Set hyStreams = hyCase.Flowsheet.MaterialStreams
For j = 0 To hyStreams.Count - 1
MsgBox hyStreams.Item(j).name
Next j
Example 2: Accessing Collection Objects
Dim hyStreams As Streams
Dim hyStream As ProcessStream
Set hyStreams = hyCase.Flowsheet.MaterialStreams
For Each hyStream In hyStreams
MsgBox hyStream.name
Next hyStream
Komentáře k této Příručce