Discussion created by yjf731222 on Apr 16, 2014
Latest reply on Apr 21, 2014 by yjf731222





Private Sub Display_Click(ByVal lvarX As Long, ByVal lvarY As Long)
'Option Explicit




Dim PIServername As String
Dim PITagname As String
Dim Description As String * 26
Dim PIPtNo As Long
Dim TrendStartTime As String
Dim TrendEndTime As String
Dim Status As Long
Dim Success As Boolean




Dim MySymbols As SelectedSymbols
Dim MySymbol As Symbol
Dim MySymbolType As Long
Dim N As Integer




Dim pbSymbols As SelectedSymbols
Dim pbSymbol As Symbol
Dim pbBar As PBCommandBar
Dim pbButton As PBCommandBarButton
Dim I As Integer
Dim A As Integer
        On Error GoTo ErrorHandler
Set MySymbols = ThisDisplay.SelectedSymbols




'Check to see how many are selected.
If MySymbols.Count = 0 Then
'If the count is zero, user clicked display background, do nothing.
Exit Sub
End If
For N = 1 To MySymbols.Count
'Attach to each individual symbol object.
Set MySymbol = MySymbols.Item(N)
'Get the symbols type, ie. Trend, Line, Value, etc..
MySymbolType = MySymbol.Type




'If symbol object is type 7, by definition its a value object.
If MySymbolType = 7 Then




'Get the tagname and trend it.
PITagname = MySymbol.GetTagName(1)
'Pick up the current trend time range.
TrendStartTime = Trend1.StartTime
TrendEndTime = Trend1.EndTime
For I = 1 To Trend1.TraceCount




'If selected tag is not the current one in trend, put it there.
If Not (Trend1.GetTagName(I) = PITagname) Then
    A = 0
   A = 1
   Trend1.RemoveTrace (I)
   Exit For
End If
Next I
If A = 0 Then
Trend1.AddTrace (PITagname)
'Removes old point trace from trend, ( ProcessBook 2.1 trends can
'   contain no traces ).
 Exit Sub
'Trend1.RemoveTrace (I)
End If




'Add trace for this tag to trend




'Refresh time range, setting
Trend1.SetStartAndEndTime TrendStartTime, TrendEndTime




'Trend1.TrendTitle = "趋势图"
Success = Trend1.SetTraceScale("Autorange", "Autorange")
Exit Sub
End If
Next N
'Trend1.RemoveTrace (I)
End Sub