cjrancur

Sharing ACE functions among executables

Discussion created by cjrancur on Mar 31, 2010
Latest reply on Apr 1, 2010 by spilon

I've built a handy function that is helpful for use in many different ACE executables.  This one checks to see if the annotations named value has been set for a passed pidata object.  The code is shown below for function checkForAnnotationnamedValue.  I try to run this check before writing to annotations, so that a try/catch doesn't have to be used.  Am I right in thinking that checking this is more efficient than using the windows try/catch utility around a call like the following:

Try
   objPIData.RetrievalAttributes.Add("annotations", 1)
Catch ex As Exception
   ' Collection Already Exists, No Problem, Keep going
End Try

Is there a way to use the function checkForAnnotationNamedValue in many different ACE executables, without simply copying the private function into the ACE class module for the various ACE modules?

 

 

Private Function checkForAnnotationNamedValue(ByRef objPIData As PIData) As Boolean
        Dim myReturn As Boolean = False 'assume the named value does not exist, unless proven otherwise
        'objPIData.RetrievalAttributes.Add("annotations", 1)
        Dim myNamedValue As PISDKCommon.NamedValue

        Try
            If objPIData Is Nothing OrElse objPIData.RetrievalAttributes.Count < 1 Then
                Return (False) 'No named value present
                Exit Function
            End If
            For Each myNamedValue In objPIData.RetrievalAttributes
                If myNamedValue.Name = "annotations" Or myNamedValue.Name = "Annotations" Then
                    myReturn = True
                    Return myReturn
                    Exit Function
                End If
            Next

            Return myReturn
        Catch ex As Exception
            SendMessageToPI(ex.Message, "CheckForAnnotationNamedValue")
            Return myReturn
        End Try
    End Function
   

End Class

Outcomes