8 Replies Latest reply on Dec 17, 2012 10:45 AM by RJKSolutions

    add cursor to newly created trend

      Hi I have made a code in VBA to take any data following, non-trend symbol that is double-clicked and build a trend of it, maximize that trend, and then drop cursors onto the minimum and maximum values in the trend's display range.  The code is working now, but before it was getting an error in which the cursors would give me an error when I tried to move them to a specific time in the trend.  This occurred no matter what I set their times too.  I then realized that the trend was not building before the cursors were added to it, so setting their times always resulted in an error because the trend itself did not have a time range yet.  I solved this issue with the rather clumsy fix of adding a message box (MsgBox ("wait")) between the add trend and add cursor/set cursor time statements.  Adding delay between the two portions of the code did not resolve this issue.  I was wondering if anyone else had come across this and had come up with a better solution.  Thanks in advance for the help.

       

       

       
      Private Sub Display_BeforeDoubleClick(bCancelDefault As Boolean, ByVal lvarX As Long, ByVal lvarY As Long)
      
      If ThisDisplay.Application.RunMode = True Then
      
      bCancelDefault = True
      
      If SelectedSymbols.Count > 0 Then
      
      If SelectedSymbols.Item(1).Name <> "value_trend" Then
      
       
      
      Dim valtag As String
      
      Dim valtrend As PBSymLib.Trend
      
      Dim maxval As Double
      
      Dim minval As Double
      
      Dim timemax As Variant
      
      Dim timemin As Variant
      
      Dim i As Long
      
       
      
      valtag = SelectedSymbols.Item(1).GetTagName(1)
      
      If SelectedSymbols.Item(1).Type = PBObjLib.pbSymbolTrend Then
      
          valtag = Mid(valtag, InStr(3, valtag, "\"))
      
      End If
      
       
      
      Set valtrend = ThisDisplay.Symbols.Add(pbSymbolTrend)
      
      With valtrend
      
       
      
          .AddTrace (valtag)
      
          .Maximize (True)
      
          .CurrentTrace = .TraceCount
      
          maxval = .GetTraceValue(2, timemax, retstat)
      
          minval = .GetTraceValue(2, timemin, retstat)
      
          For i = 3 To .TraceValuesCount - 1
      
          If .GetTraceValue(i, timer, retstat) > maxval Then
      
              maxval = .GetTraceValue(i, timemax, retstat)
      
          End If
      
          If .GetTraceValue(i, timer, retstat) < minval Then
      
              minval = .GetTraceValue(i, timemin, retstat)
      
          End If
      
          Next i
      
       
      
      End With
      
       
      
      MsgBox ("wait")
      
       
      
      With valtrend
      
       
      
          .Name = "value_trend"
      
          .AddCursor
      
          .CurrentCursor = .CursorCount
      
          .CursorTime = timemax
      
       
      
          .AddCursor
      
          .CurrentCursor = .CursorCount
      
          .CursorTime = timemin
      
       
      
      End With
      
       
      
       
      
      Else
      
          Symbols.Remove ("value_trend")
      
      End If
      
      End If
      
      End If
      
      End Sub