Asle Frantzen

ContextHandler event happens too quick

Discussion created by Asle Frantzen Champion on Mar 13, 2012
Latest reply on Mar 14, 2012 by Asle Frantzen



According to this thread ([DEAD LINK] it seems that the ContextHandler event is early in the context changing process.


I have 3 values which get their values based on the context, and whenever the context handler event kicks in I want to update the traces on a trend. Now the problem seems to be that these value-symbols haven't been updated with their new context-sensitive information, OR that I can't see any changes in the trend after inserting/updating the traces.


Any tips 'n tricks for doing what I want?


It all seems to work if I input a breakpoint or just show a message box with some random stuff early in my UpdateTrend-method.




Simplified code:



Private WithEvents myCtxtHndlr As ContextHandler

Private Sub Display_Open()
    Set myCtxtHndlr = Application.ContextHandlers("E")
End Sub

Private Sub myCtxtHndlr_ContextChanged(FromDisplay As Display, FromContextHandler As ContextHandler)
    UpdateTrend thisTrend:=Trend1
End Sub

Private Sub UpdateTrend(ByRef thisTrend As Trend)
    Dim vIndex As Integer
    Dim status As Boolean
    Dim restatus As Variant
    Dim trafo1 As String    
    Dim trace1 As String
    'Remove all trend traces
    For vIndex = thisTrend.TraceCount To 1 Step -1
        status = thisTrend.RemoveTrace(vIndex)
    Next vIndex
    'Check and set trace
    trafo1 = value_transformer1.GetValue(Now, restatus)
    If (trafo1 <> "n" And trafo1 <> "") Then
        trace1 = "E.\Equipment repository\Transformers\" & trafo1 & "|HV Active power"
        status = thisTrend.AddTrace(trace1)
    End If

End Sub