5 Replies Latest reply on Jan 25, 2011 2:34 PM by Kenneth.Rice

    Using PI-SDk call .Summaries2 in Processbook via VBA

    Kenneth.Rice

      Hi Folks,

       

      Not sure if I should have posted this in PI-SDK or here.

       

      I have a colleague trying to use the following

       

      Set nvsSum = ipid2.Summaries2(StartTime, EndTime, duration, asTotal, cbTimeWeighted)

       

      and the help files say duration can be set as VT_EMPTY or VT_NULL, when he tries to execute that code he gets an error

      VB error Invalid Function Argument "Duration"

      I would appreciate any help thanks

        • Re: Using PI-SDk call .Summaries2 in Processbook via VBA
          Ahmad Fattahi

          Can you copy here the part where you define "duration"? Is it a variant?

            • Re: Using PI-SDk call .Summaries2 in Processbook via VBA
              Kenneth.Rice

              Ahmad,

               

                 Hi thanks for the reply. As you can see below the answer to your question is no he has defined it as a String. Should it be a Variant?

               

              Also he is gonna need to have a conversion factor of 1.44 to convert from KGPM to MG, where and how does that get added

               
              Public Function CalcTotalFlowMG(Tag As String, StartTime As String, EndTime As String) As Double
              
                 Dim Ttl As Double
              
              Dim pt As PIPoint
              
              Dim pdata As PIData
              
              Dim ipid2 As IPIData2, ipiCalc As IPICalculation
              
              Dim nvsSum As NamedValues, nvsFilSum As NamedValues
              
              Dim valsum As PIValues, valfilsum As PIValues, valfiltime As PIValues, valtimetrue As PIValues
              
              Dim filexpr As String, duration As String
              
              Dim nv As NamedValue, msg As String
              
              Dim filtime As Double, stime As PITime, etime As PITime, maxtime As PITime
              
              Dim stime2 As PITime, etime2 As PITime
              
                 duration = "1 Y" ' <<<-- works but should be set to "VT_EMPTY"or "VT_NULL" per PI-SDK help I think?
              
                 ' duration = "VT_EMPTY"
              
                 Set ipiCalc = PIServer                         ' get pointer to IPICalculation Interface
              
                 Set pt = PIServer.PIPoints(Tag)  ' perform summary calls on tag sinusoid
              
                 Set pdata = pt.Data
              
                 Set ipid2 = pdata                        ' get pointer to IPIData2 Interface
              
                 Set nvsSum = ipid2.Summaries2(StartTime, EndTime, duration, asTotal, cbTimeWeighted)
              
              ' extract the pivalues for total from the result
              
                 Set valsum = nvsSum("Total").Value
              
                 Ttl = CDbl(valsum.Item(1))
              
                 CalcTotalFlowMG = Ttl / 1000# ' Converting to MG don't know if it works, haven't gotten to this point yet
              
              End Function