Retrieving Annotations fails - sometimes...

Discussion created by Steve.Buckley on Mar 13, 2014
Latest reply on Mar 14, 2014 by Marcos Vainer Loeff
For a VBA/Excel app, I have the following function (adapted from the SDK manual), to write comments to a Lab tag: Function MostRecentAnnotation(ByRef piVal As piValue)     Dim retValAttr As NamedValues     Dim nvAnn As NamedValue     Dim retAnns As PIAnnotations     Dim curAnn As PIAnnotation     On Error Resume Next     Set retValAttr = piVal.ValueAttributes     Set nvAnn = retValAttr.Item("annotations")     Set retAnns = nvAnn.value     Set curAnn = retAnns.Item(retAnns.Count)     If Not curAnn Is Nothing Then         MostRecentAnnotation = curAnn.value     Else         MostRecentAnnotation = ""     End If End Function The above code ONLY successfully retrieves the tag's annotations AFTER the Excel app has been used to write an annotation to the tag, using code that includes the following snippet:     Set myData = svr.PIPoints(PITag).Data     On Error Resume Next     myData.RetrievalAttributes.Add "Annotations", 1     On Error GoTo Handler1     Set myAnn = myAnns.Add(PITag, "Comment", AnnotationText, False)     myValAttr.Add "annotations", myAnns     Set myVal.ValueAttributes = myValAttr     myData.UpdateValue myVal, 0, ReplacementOption I cannot see how this second piece of code affects the first, as they are separate procedures, not globally scoped. Can anyone help me see what I'm missing?