Server Example 2

 

This example, during the Form_Load, connects to the default server and clears the display controls. The user enters criteria for 3 predefined attributes and clicks Command1 to perform the Server.GetPointsSQL call. The code in the click event builds the query, handling specifically the case of no criteria specified to avoid mistaken costly searches for all the points. On successful return, a list box is filled with the returned points and a label is updated with the count of returned points. Clicking on any of the points in the list box displays the three attributes used as criteria so the correctness of the query can be confirmed.

Build this Server 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, &ldots;) match those shown.

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

 

  Option Explicit
Dim srv As Server

Private Sub Command1_Click()
On Error GoTo handler
  ' Don't let user ask for everything by default
  If Text1.Text = "" And Text2.Text = "" _
      And Text3.Text = "" Then
    MsgBox "Please enter some limiting search criteria."
    Exit Sub
  End If
  
  Dim strQuery As String
  If Text1.Text = "" Then
    strQuery = "Tag = '*'"
  Else
    strQuery = "Tag = '" & Text1.Text & "' "
  End If
  If Text2.Text <> "" Then
    strQuery = strQuery & "AND " & _
      "Descriptor = '" & Text2.Text & "' "
  End If
  If Text3.Text <> "" Then
    strQuery = strQuery & "AND " & _
      "ExDesc = '" & Text3.Text & "' "
  End If
  Dim ptList As PointList
  Me.MousePointer = vbHourglass
  ClearAttrDisplay
  Set ptList = srv.GetPointsSQL(strQuery)
  Me.MousePointer = vbDefault
  List1.Clear
  Label6.Caption = ptList.Count
  Dim pt As PIPoint
  For Each pt In ptList
    List1.AddItem pt.Name
  Next
Exit Sub
handler:
  Me.MousePointer = vbDefault
  List1.Clear
  Label6.Caption = ""
  MsgBox Err.Description
End Sub

Private Sub Form_Load()
On Error GoTo handler
  Set srv = Servers.DefaultServer
  srv.Open
  Text1.Text = ""
  Text2.Text = ""
  Text3.Text = ""
  Label6.Caption = ""
  ClearAttrDisplay
  Exit Sub
handler:
  MsgBox Err.Description
End Sub

Private Sub List1_Click()
On Error GoTo handler
  Dim pt As PIPoint
  Set pt = srv.PIPoints(List1.Text)
  Label10.Caption = pt.PointAttributes("tag").Value
  Label11.Caption = pt.PointAttributes("descriptor").Value
  Label12.Caption = pt.PointAttributes("exdesc").Value
Exit Sub
handler:
  MsgBox Err.Description
End Sub
Private Sub ClearAttrDisplay()
  Label10.Caption = ""
  Label11.Caption = ""
  Label12.Caption = ""
End Sub
Enabling Operational Intelligence