PointAttributes / PointAttribute Example

picture

This example, during the Form_Load, connects to the default server, and displays the server name. When Command1 is hit it reads the tag name from Text1, retrieves its PointAttributes collection and displays each point attribute in a list box (List1). Clicking on an attribute from the list box displays the name and value of the Point Attribute in Label 3 and Text 2. Changing a value displayed in Text 2 and hitting Command2 will update the attribute on the server.

 

Build the PointAttributes 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
Dim pt As PIPoint

Private Sub Command1_Click()
On Error GoTo handler
    If Text1.Text = "" Then
        MsgBox "Please enter a tag name."
        Exit Sub
    End If
    Set pt = srv.PIPoints(Text1.Text)
    Dim ptattr As PointAttribute
    List1.Clear
    For Each ptattr In pt.PointAttributes
        List1.AddItem ptattr.Name
    Next
Exit Sub
handler:
    MsgBox Err.Description
End Sub

Private Sub Command2_Click()
On Error GoTo handler
    If pt Is Nothing Then
        MsgBox "Please retrieve a tag's attributes first."
        Exit Sub
    End If
    Dim ptatr As PointAttribute
    Set ptatr = pt.PointAttributes(List1.Text)
    pt.PointAttributes.ReadOnly = False
    ptatr.Value = Text2.Text
    pt.PointAttributes.ReadOnly = True
    MsgBox "Attribute successfully modified"
Exit Sub
handler:
    MsgBox Err.Description
End Sub

Private Sub Form_Load()
Set srv = Servers.DefaultServer
Label6.Caption = srv.Name
Text1.Text = ""
Text2.Text = ""
End Sub

Private Sub List1_Click()
On Error GoTo handler
    
    Dim ptatr As PointAttribute
    Set ptatr = pt.PointAttributes(List1.Text)
    Label3.Caption = ptatr.Name
    Text2.Text = CStr(ptatr.Value)
Exit Sub
handler:
    MsgBox Err.Description
End Sub
Enabling Operational Intelligence