If you have a real-time pen defined, and attempt to pass external (SQL) data to the pen using the SetPenDataArray method, the time and legend values keep updating with the real-time value.
To avoid this problem, disconnect from the real-time data source before calling the SetPenDataArray method, as show in the following sample code:
Pen1.SetSource "ChartData", True
res=Pen1.SetPenDataArray (count, vtVal, vtDate, vtQual)
where ChartData can be any string.
The SetPenDataArray Method takes arrays of parameters. One of these parameters is quality. This parameter holds the OPC Quality of the data as a numeric constant. When creating your own data in a relational database, you need to specify a value of 192 for this field in order for your data to plot on the chart object.
Keep in mind that the data you pass to a pen does not have to be from a SQL query - it can consist of any external data. To bring this data into a pen, use the call Pen.SetPenDataArray. You can also use GetPenDataArray to extract the data from the pen. Refer to the following example:
Example: Using GetPenDataArray to Extract Data from Pen
Dim lNumPts As Long
Dim vVal As Variant
Dim vPsa As Variant
Dim vQual As Variant
Pen1.GetPenDataArray lNumPts, vVal, vPsa, vQual
Example: SetPenDataArray Method with Hardcoded Values
The following is sample code for the SetPenDataArray method with hardcoded values. You can use this code to test or show the functionality of this method. For this example to complete, the Quality(x) must be equal to 192.
Private Sub Rect2_Click()
Dim iWrkSpace As Workspace
Dim db_var_name As Database
Dim record_var As Recordset
Dim iCount As Integer
Dim dVal As Variant
Dim dtDate As Variant
Dim lQual As Variant
Dim iResult As Integer
Dim iRow As Integer
Dim iCol As Integer
Dim i As Integer
'Please note that this example can handle a maximum of 500 points.
'If you need more points, increase the size of the
'following declarations.
Dim Value(500) As Double
Dim Times(500) As Date
Dim Quality(500) As Long
'Create an object on the iFIX WorkSpace and the
'Specified SQL database
Set iWrkSpace = CreateWorkspace("", "admin", "", dbUseJet)
Set db_var_name = iWrkSpace.OpenDatabase("Chart.mdb")
Set record_var = db_var_name.OpenRecordSet("Data Query", dbOpenDynaset)
record_var.MoveLast
iCount = record_var.RecordCount
record_var.MoveFirst
'Load the array with the Recordset values
For i = 0 To iCount - 1
Value(i) = record_var.Fields("Value").Value
Times(i) = record_var.Fields("Time").Value
'If the Quality(x) is not equal to 192 the Point
'will be ignored by the chart
Quality(i) = record_var.Fields("Quality").Value
record_var.MoveNext
Next i
'Close the connection with the SQL database
db_var_name.Close
'Set up the correct array types
dVal = Value
dtDate = Times
lQual = Quality
iResult = Pen1.SetPenDataArray(iCount, dVal, dtDate, lQual)
End Sub