Courtesy from Archie:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
EthernetIPforCLXCom1.IPAddress = TextBox1.Text
EthernetIPforCLXCom1.ProcessorSlot = TextBox2.Text
'* Retreive the tags from the PLC
Dim AllTags() As AdvancedHMI.Drivers.CLXTag = EthernetIPforCLXCom1.GetTagList
'* Clear anything in the TreeView
TreeView1.Nodes.Clear()
'* Add all tags to the tree view
For i = 0 To AllTags.Length - 1
Dim Node As New TreeNode(AllTags(i).TagName)
If AllTags(i).ArrayElements1 > 0 And AllTags(i).ArrayElements2 <= 0 Then
Node.Text &= " [" & AllTags(i).ArrayElements1 & "]"
ElseIf AllTags(i).ArrayElements2 > 0 And AllTags(i).ArrayElements2 <= 0 Then
Node.Text &= " [" & AllTags(i).ArrayElements1 & "," & AllTags(i).ArrayElements1 & "]"
ElseIf AllTags(i).ArrayElements3 > 0 Then
Node.Text &= " [" & AllTags(i).ArrayElements1 & "," & AllTags(i).ArrayElements1 & "," & AllTags(i).ArrayElements3 & "]"
End If
'* If the Tag is a UDT, then add the structure name in parentheses
If (AllTags(i).IsStructure) Then
Node.Text &= " (" & AllTags(i).UDTStructure.Name & ")"
End If
TreeView1.Nodes.Add(Node)
'* If the Tag is a UDT, then add the structure definition as a tree node
AddSubNode(Node, AllTags(i).UDTStructure)
Next
End Sub
Private Sub AddSubNode(node As TreeNode, UDTstructure As AdvancedHMI.Drivers.CIP.CLXTemplateObject)
If UDTstructure IsNot Nothing Then
For i = 0 To UDTstructure.Members.Count - 1
Dim SubNode As New TreeNode(UDTstructure.Members(i).Name)
node.Nodes.Add(SubNode)
'* If the member is a UDT, then recursively add the UDT structure as a sub node
AddSubNode(SubNode, UDTstructure.Members(i).SubTemplate)
'* If the member is an array, then add the element count in brackets
If UDTstructure.Members(i).ArrayElements > 0 Then
SubNode.Text &= " [" & UDTstructure.Members(i).ArrayElements & "]"
End If
'* If the member is another UDT, then add the name in parentheses
If UDTstructure.Members(i).SubTemplate IsNot Nothing Then
SubNode.Text &= " (" & UDTstructure.Members(i).SubTemplate.Name & ")"
End If
Next
End If
End Sub