5 Replies Latest reply on Nov 20, 2012 11:47 AM by andreas

    Sampled Data Function in VBA


      I need to pull sampled data into a worksheet after passing the start time, end time, and time interval.  Any suggestions?

        • Re: Sampled Data Function in VBA

          Hi Jonathan,


          Can't you just use PI DataLink for it?


          In case not, for whatever reason, here's an example of how you can retrieve sampled data programmatically using the PI-SDK in VBA:

          Dim myServer As Server
          Dim myPoint As PIPoint
          Dim ipid2 As IPIData2
          Dim myValues As PIValues
          Dim val As PIValue
          Dim msg As String
          Set myServer = Servers.DefaultServer
          Set myPoint = myServer.PIPoints("cdt158")
          Set ipid2 = myPoint.Data
          Set myValues = ipid2.InterpolatedValues2("26-jul-2011 10:00", "26-jul-2011 17:00", "30m")
          msg = "timestamps and values" & vbCrLf
          For Each val In myValues
              msg = msg & "ts: " & val.TimeStamp.LocalDate & " - value: " & val.Value & vbCrLf
          Next val
          MsgBox msg



          Of course you can change this sample code, so that the query parameters (tag name, start time, end time, time interval) are taken from cells in a Excel spreadsheet and the results are output to the spreadsheet.


          I hope this helps.