RecordedValuesByCount Example

 

This example, during the Form_Load, connects to the default server, clears and initializes the display with reasonable defaults. When Command1 is hit it validates the user's input and retrieves the requested recorded values and displays them. 

 

Build the RecordedValuesByCount example as follows:

1. Create a new project and add a reference to the PISDK library.

2. Add the visual elements as shown in the picture. Make sure the numbered element names (label1, list1, etc.) match those shown. The radio buttons are created inside the frame and are named Option1 and Option2. 

3. Cut and paste the code below into the project.

 

Option Explicit
Dim srv As Server
Dim piconst As PIConstant
Private Sub Command1_Click()
On Error GoTo handler
   ' validate the input
   If Len(Text1.Text) = 0 Then
      MsgBox "Please enter a tag name"
      Exit Sub
   End If
   Dim dt As Date
   dt = CDate(Text2.Text)
   If dt < 25568.5 Then
      MsgBox "Invalid start time."
      Exit Sub
   End If
   Dim btType As BoundaryTypeConstants
   btType = piconst.Item(List1.Text).Value
   Dim pt As PIPoint
   Set pt = srv.PIPoints(Text1.Text)
   ' clear the results
   List2.Clear
   ' Get the recorded values
   Dim pvs As PIValues
   Dim count As Long
   count = CLng(Text3.Text)
   Dim direction As DirectionConstants
   If Option1.Value = True Then
      direction = dForward
   Else
      direction = dReverse
   End If
   
   Set pvs = pt.Data.RecordedValuesByCount(dt, count, direction, btType)
   Label8.Caption = CStr(pvs.count)
   Dim pv As PIValue
   For Each pv In pvs
      List2.AddItem CStr(pv.TimeStamp.LocalDate) + vbTab + CStr(pv.Value)
   Next
Exit Sub
handler:
   MsgBox Err.Description
End Sub

Private Sub Form_Load()
On Error GoTo handler
   Set srv = Servers.DefaultServer
   ClearForm
Exit Sub
handler:
   MsgBox Err.Description
End Sub
Private Sub ClearForm()
   Text1.Text = "cdm158"
   Dim dt As Date, dt2 As Date
   dt = Now() - 8# / 24#
   Text2.Text = CStr(dt)
   Text3.Text = CStr(10)
   List1.Clear
   Label8.Caption = ""
   List2.Clear
   On Error GoTo handler
   Set piconst = PIConstants.Item("BoundaryTypeConstants")
   Dim nv As NamedValue
   For Each nv In piconst
      List1.AddItem nv.Name
   Next
   List1.ListIndex = 0
   Option1.Value = True
   Exit Sub
handler:
   MsgBox Err.Description
End Sub

Enabling Operational Intelligence