Connection Examples: Using the Lookup Object
This example shows you how to check to see if an object is connected to a data source, then lets you build a Lookup object that overwrites an existing color table.
Example: Using Range Comparison
In this example, the picture contains a rectangle named Rect1.
Private Sub BtnLookup_Click()
Dim blnIsConnected As Boolean
Dim lngIndex As Long
Dim lngStatus As Long
Dim strPropName As String
Dim strSource As String
Dim strFQSource As String
Dim vtSourceObjects
Dim LookupObject As Object
Dim strFullname As String
Dim blnIsEmpty As Boolean
'Check to see if the rectangle's ForegroundColor
'property is already connected to a data source
Rect1.IsConnected "ForegroundColor", blnIsConnected, _
lngIndex, lngStatus
'If it is, use the Disconnect method to remove the
'existing property connection
If blnIsConnected Then
Rect1.Disconnect "ForegroundColor"
End If
'If a ForegroundColor animation does not exist, build an
'empty lookup animation object off of the rectangle
If (TypeName(LookupObject) = "Nothing") Then
Set LookupObject = Rect1.BuildObject("lookup")
End If
'Add levels to your lookup animation object with a range
'comparison using the AddLevel method. The following
'table will have inputs between 10 and 20 displaying the
'color with the RGB value of 255 (red), 21 through 40
'would display RGB 65535 and so on
LookupObject.AddLevel 10, 255, 20
LookupObject.AddLevel 20, 65535, 40
LookupObject.AddLevel 40, 65280, 60
LookupObject.AddLevel 60, 16711680, 80
LookupObject.AddLevel 80, 8388736, 100
'Use the SetSource method to connect the lookup animation
'object to the data source object. This connection
'overwrites any existing color table set up
LookupObject.SetSource "AI1.F_CV", True
'We have connected the InputValue property of the lookup
'animation object to the data source. Now, we will
'connect the animation object's OutputValue property to
'the shape. Its output is connected to the object it is
'animating.
strFullname = LookupObject.FullyQualifiedName & _
".OutputValue"
Rect1.Connect "ForegroundColor", strFullname, lngStatus
End Sub
Similarly, you can create an Exact Match color table using the LookupExact method and the ExactMatch property of an object. The following example shows you how.
Notice that, again, the example first checks that the object is connected in the first place, then proceeds to manipulate the object's property based on that connection.
Example: Using Exact Match Lookup
In this example, the picture contains a rectangle named Rect2.
Private Sub BtnLookupExact_Click()
Dim blnIsConnected As Boolean
Dim lngIndex As Long
Dim lngStatus As Long
Dim strPropName As String
Dim strSource As String
Dim strFQSource As String
Dim vtSourceObjects
Dim LookupObject As Object
Dim strFullname As String
Dim blnIsEmpty As Boolean
'Check to see if the rectangle's ForegroundColor property
'is already connected to a data source
Rect2.IsConnected "ForegroundColor", blnIsConnected, _
lngIndex, lngStatus
'If it is, use the Disconnect method to remove the
'property connection
If blnIsConnected Then
Rect2.Disconnect "ForegroundColor"
End If
'If a ForegroundColor animation does not exist, build an
'empty lookup animation object off of the rectangle
If (TypeName(LookupObject) = "Nothing") Then
Set LookupObject = Rect2.BuildObject("lookup")
End If
'To create an exact match color table, the user can do
'two things: (1) Call AddLevel with the same parameters
'as a range comparison and set the ExactMatch property to
'true OR (2) Call AddLevel without the second input
'parameter. The following table will have inputs 10
'displaying the color with an RGB value of 255
'(red), 21 would display RGB 65535 and so on.
LookupObject.AddLevel 10, 255, 20
LookupObject.AddLevel 21, 65535, 40
LookupObject.AddLevel 41, 65280, 60
LookupObject.AddLevel 61, 16711680, 80
LookupObject.AddLevel 81, 8388736, 100
LookupObject.ExactMatch = True
'Use the SetSource method to connect the lookup animation
'object to the data source object. This connection
'overwrites any existing ColorTable set up.
LookupObject.SetSource "AI1.F_CV", True
'We have connected the InputValue property of the lookup
'animation object to the data source. Now, we will
'connect the animation object's OutputValue property to
'the shape. Its output is connected to the object it is
'animating.
strFullname = LookupObject.FullyQualifiedName & _
".OutputValue"
Rect2.Connect "ForegroundColor", strFullname, lngStatus
End Sub
For more information on data sources, refer to the Creating Pictures manual. For information on changing data sources at run-time, refer to the Changing Data Sources section.