IPIValues2 Example

 

An example of using the various methods of the IPIValues2 interface.

 



' This rouinte examines the data in the passed pivalues collection using the methods in the

' IPIvalues2 interface


Private Sub TestIPIValues2(pvs as PIValues)
On Error GoTo errhandler

    dim Ipvs2 as IPIValues2

    dim dataAry() As Variant, timeAry() As Double, attrAry() As Long

    dim idx as long, lUpBound as long

    dim bIsGood as boolean, bQuestionable as boolean, bAnnotated as boolean

    dim bSubstituted as boolean, vtAnnotation as variant

    dim pv as PIValue, errmsg as string, lTemp as long, bEmptyAn as boolean

 

' Get secondary interface from the pivalues

    set Ipvs2 = pvs

' Get arrays

    Ipvs2.GetValueArrays dataAry, timeAry, attrAry

   

' Check the array bounds

    lUpBound = pvs.count - 1

    if (UBound(dataAry) <> lUpBound) then

        msgbox("value array bound not correct")

        exit sub

    endif

    if (UBound(timeAry) <> lUpBound) then

        msgbox("time array bound not correct")

        exit sub

    endif

    if (UBound(attrAry) <> lUpBound) then

        msgbox("flags array bound not correct")

        exit sub

    endif
 

' Examine data in the arrays

    for idx = 0 to lUpBound

        set pv = pvs(idx + 1)

' compare timestamp from arrays call with PIValue timestamps

        if (abs(timeary(idx) - pv.timestamp.utcseconds) > 0.001) then

            errmsg = "Time does not match at idx " & cstr(idx)

            msgbox(errmsg)

        endif

' Check data quality

        if (attrAry(idx) < 0) then

            bIsGood = false

' remove the sign bit

            lTemp = attrAry(idx) xor -2147483648#

        else

            bIsGood = true

            lTemp = attrAry(idx)

        endif

        ' Compare isgood indicator from flag with the pivalue IsGood method

        If (bIsGood Xor pv.IsGood) Then
            errmsg = "Sign bit from flag does not match pv.IsGood at idx " & CStr(idx)
            MsgBox (errmsg)
        End If
' Parse the Flag attribute

        if (lTemp >= 4) then

            bSubstituted = true

            lTemp = lTemp - 4

        else

            bSubstituted = false

        endif

        if (lTemp >= 2) then

            bQuestionable = true

            lTemp = lTemp - 2

        else

            bQuestionable = false

        endif

        if (lTemp = 1) then

            bAnnotated = true

        else

            bAnnotated = false

        endif

' Check annotation

        vtAnnotation = Ipvs2.GetItemAnnotation(idx + 1)

' GetItemAnnotation will return empty variant if there is no annotation in the pivalue

        bEmptyAn = IsEmpty(vtAnnotation)          

        if (not (bAnnotated xor bEmptyAn)) then    ' they should not have the same value

            errmsg = "Annotated flag not match GetItemAnnotation result at idx " & cstr(idx)

            msgbox(errmsg)

        endif

    next idx


    Exit Sub

errhandler:
    MsgBox (Err.Description)
    Exit Sub
End Sub
 

Enabling Operational Intelligence