Hi, I have used the code snippet from DRabinowitz (http://community.osisoft.com/index.php?/topic/1376-lets-share-useful-code-snippets/?p=3869) to allow me to build trends on a page by double clicking the values on the page. The code is the same except I have removed the " Trend1.RemoveTrace 1" statement as I want to add multpile points to the trend (and some auto-scaling code).
It works great however I would like to add some further smarts to it such as matching the scale of points if they are associated with the same variable (eg. controller.PV & controller.SP should have the same scale). So far I haven't been able to figure out how to search through the list of points in a trend by name and determine if a point is already in the trend. My trend object is always the same name "TrendX" so all I want to do is iterate through the list of points and return the index if I find a match.
If anyone has an example on how I could do this it would be great. I've looked at the code sample under "GetTraceIndex" but I cant see how to apply it to searching through my trend object?
Thanks
Jason
Below is my modified version of DRabinowitz's code sample.
Private Sub Display_BeforeDoubleClick(bCancelDefault As Boolean, ByVal lvarX As Long, ByVal lvarY As Long)
On Error Resume Next
Dim vT, vDT As Variant
Dim lstatus As Long
Dim rng, delta As Variant
rng = 5 ' scale +- this %
If ThisDisplay.Application.RunMode = True Then
If SelectedSymbols.Count > 0 Then 'make sure we have actually double-clicked a symbol'
If SelectedSymbols.Item(1).Type = pbSYMBOLTYPE.pbSymbolBar Or SelectedSymbols.Item(1).Type = pbSYMBOLTYPE.pbSymbolValue Then 'update trend for a bar or value symbol'
bCancelDefault = True
TrendX.AddTrace SelectedSymbols.Item(1).GetTagName(1) 'add a trace using the tag or dataset from the selected symbol'
vT = Abs(SelectedSymbols.Item(1).GetValue(vDT, lstatus))
delta = rng / 100 * vT
TrendX.CurrentTrace = TrendX.TraceCount
Call TrendX.SetTraceScale(Round(vT - delta), Round(vT + delta))
End If
End If
End If
End Sub