AnsweredAssumed Answered

Problems Converting old VBA PISDK Function to VB.NET PI AF SDK Equivalent

Question asked by DeepSkyMan on Nov 18, 2019
Latest reply on Nov 18, 2019 by Dan Fishman

I am having difficulty converting an old VBA Function to a VB.NET Equivalent using the PI ADF SDK - Can you provide some asistance as to the changes needed to the code Please:


 

Private Function GetPiCalculatedData(ByVal piTag As String, ByVal startTime As String, ByVal endTime As String, _
                                    Optional ByVal duration As String = "30m", _
                                    Optional ByVal calcType As ArchiveSummariesTypeConstants = asAverage, _
                                    Optional ByVal calcBasis As CalculationBasisConstants = cbTimeWeighted, _
                                    Optional ByRef bError As Boolean = False) As PIValues

' Essentially replicates the functionality of =PIAdvCalcDat() in Excel
' Error handling
On Error GoTo dataerror
Dim srv As Server
Dim pData As IPIData2
Dim nVal As NamedValues
Dim piVals As PIValues
' Basic process: connect to server, ask for data for the tag, do the calculation, extract to a PIValues object in order to process later
Set srv = Servers.DefaultServer
Set pData = srv.PIPoints(piTag).Data
Set nVal = pData.Summaries2(startTime, endTime, duration, calcType, calcBasis)
Set piVals = nVal.Item(1).Value
' Return values
Set GetPiCalculatedData = piVals
' Tidy up
Set piVals = Nothing
Set nVal = Nothing
Set pData = Nothing
Set srv = Nothing
Exit Function
dataerror:
bError = True
End Function
Kind Regards
paul J.

Outcomes