⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmadditem.frm

📁 VB6.0 复杂的OPC CLIENT 自动化接口源程序
💻 FRM
📖 第 1 页 / 共 3 页
字号:
                End If
            End If
        Loop
    End If

End Sub

' This function will go an get the current tags available at this
' branch of the server's browse tree. This is done using the
' ShowLeafs function of the browser interface.  Unlike the
' browsing for branches using the ShowBranches function, we now
' want to use the three methods available to filter tags(leafs) from
' the lsit returned  by the server.  By default these filters are
' all disabled or in a show everything state.
'
Private Sub tvBranchView_Click()

    Dim SelectedNode As Node
    
    Set SelectedNode = tvBranchView.SelectedItem
    
    If Not SelectedNode Is Nothing Then
         Dim i As Integer
         Dim ItemName As String
         Dim DataTypeSelected As Integer
         Dim AccessSelected As Long
         
         ' Move to the current position of the treeview.  We need to do
         ' this each time since the use could move from one branch in
         ' the tree to a completely different branch not simple down one
         ' or up one.
         SetBrowsePosition SelectedNode.Key
        
         ' Clear any items that may currently be in the list view control.
         lvItemView.ListItems.Clear
         
         ' Set the Item name filter using the string found in the
         ' ItemNameFilter cotnrol.  By default this is "*" which
         ' most server take to mean everything.  You can use
         ' other wildcards such as ? in addition to *.  Using these
         ' Wildcard you can do some fairly fancy filtering. An example
         ' might be "Pressure_???_T*"  In this case and items with the
         ' the name "Pressure_" then three fields of anything then
         ' "_T" anything would be return when we call ShowLeafs.
         '
         OPCBrowserClassObj.SetFilter ItemNameFilter.Text
         
         ' Set the datatype filter.  Like the item name filter this
         ' filter allows you to reduce the number of items returned
         ' in the ShowLeafs function call based on the data type of the
         ' item.  In this case we need to test the index of the DataTypeFilter
         ' combo box control since the user may not have selected anything
         ' yet in which case we will use the "Native" data type which tells
         ' the server to return all datatypes.
         If DataTypeFilter.ListIndex = -1 Then
             DataTypeSelected = 0
         Else
             DataTypeSelected = DataTypeFilter.ItemData(DataTypeFilter.ListIndex)
         End If
         OPCBrowserClassObj.SetDataTypeFilter DataTypeSelected
         
         ' Set the access type filter.  Like the item name filter this
         ' filter allows you to reduce the number of items returned
         ' in the ShowLeafs function call based on the read write access
         ' of the item.  In this case we need to test the index of the
         ' AccessFilter combo box control since the user may not have
         ' selected anything yet in which case we will use the
         ' access type of "0" which tells the server to return all
         ' items regardless of access type.
         If AccessFilter.ListIndex = -1 Then
             AccessSelected = 0
         Else
             AccessSelected = AccessFilter.ItemData(AccessFilter.ListIndex)
         End If
         OPCBrowserClassObj.SetAccessFilter AccessSelected
         
         ' Finally show the new items based on the filters set above.
         OPCBrowserClassObj.ShowLeafs
         ' Add the new item if anny to the listview control.
         For i = 1 To OPCBrowserClassObj.GetItemCount
             OPCBrowserClassObj.GetItemName ItemName, i
             lvItemView.ListItems.Add , "Item" + Str(i), ItemName
         Next i
    End If
        
End Sub

' When the branch of the treeview control is collapsed we must remove
' all the childreen under that branch and replace them with a single
' dummy node to allow the branch to be reexpanded if the user desires.
Private Sub tvBranchView_Collapse(ByVal Node As Node)
    If Node.Children > 0 Then
        RemoveChildren Node, True
    End If
    DummyNodeNum = DummyNodeNum + 1
    ' Add the dummy node back into the treeview control under the parent
    ' node that has just been collapsed.
    tvBranchView.Nodes.Add Node.Key, tvwChild, "DummyNode" + Str(DummyNodeNum), ""
End Sub

' The RemoveChildren function removes all of the nodes/branches under a
' supplied parent node.  This function is used recusively to remove
' other node below each branch.  The Root paramter is set to true
' by the main caller to signify that the top most node is not to be
' deleted.  Once this function is called recursively the Root flag is
' set false allowing the parent of each subsequent level to be deleted
' as the children are removed.
Function RemoveChildren(ByVal Node As Node, ByVal Root As Boolean)
    Dim i As Integer
    Dim nodecnt As Integer
    Dim test As String
    
    test = Node.Key
    nodecnt = Node.Children
    If nodecnt > 0 Then
        For i = 1 To nodecnt
            test = Node.Child.Key
            RemoveChildren Node.Child, False
        Next i
        
        If Not Root Then
            tvBranchView.Nodes.Remove Node.Key
        End If
    Else
        tvBranchView.Nodes.Remove Node.Key
    End If
End Function

' Once a list of tags is dislpayed in the ListView control they can be loaded
' into the ItemID text control by double clicking on the tag name.
' Once in the ItemID control you can add to the tag to the current group
' by clicking the Add button on the form.  This does not close
' the dialog however allowing you to continue to add more tags as needed.
'
Private Sub lvItemView_DblClick()
    ItemID.Text = OPCBrowserClassObj.GetItemID(lvItemView.SelectedItem.Text)
End Sub

' The follwing function deal with the manipulation of the three
' methods of filter the the items names(tags) available from the server
' for a given branch.

' The DataTypeFilter allows you to reduce the number of tags displayed
' based on the data type.  The other two fitler mehtods must also be applied
' here before the ShowLeafs function is called to reload the tags
' in the lsitview control.  This operation occurs everytime you change the
' the data type filter on the dialog.
'
Private Sub DataTypeFilter_Click()
    Dim i As Integer
    Dim ItemName As String
    Dim DataTypeSelected As Integer
    Dim AccessSelected As Long
    
    ' Remove all of the current items from the lsit view.
    lvItemView.ListItems.Clear
    
    ' Set the Item name filter using the string found in the
    ' ItemNameFilter cotnrol.  By default this is "*" which
    ' most server take to mean everything.  You can use
    ' other wildcards such as ? in addition to *.  Using these
    ' Wildcard you can do some fairly fancy filtering. An example
    ' might be "Pressure_???_T*"  In this case and items with the
    ' the name "Pressure_" then three fields of anything then
    ' "_T" anything would be return when we call ShowLeafs.
    '
    OPCBrowserClassObj.SetFilter ItemNameFilter.Text
    
    ' Set the datatype filter.  Like the item name filter this
    ' filter allows you to reduce the number of items returned
    ' in the ShowLeafs function call based on the data type of the
    ' item.  In this case we need to test the index of the DataTypeFilter
    ' combo box control since the user may not have selected anything
    ' yet in which case we will use the "Native" data type which tells
    ' the server to return all datatypes.
    If DataTypeFilter.ListIndex = -1 Then
        DataTypeSelected = 0
    Else
        DataTypeSelected = DataTypeFilter.ItemData(DataTypeFilter.ListIndex)
    End If
    OPCBrowserClassObj.SetDataTypeFilter DataTypeSelected
    
    ' Set the access type filter.  Like the item name filter this
    ' filter allows you to reduce the number of items returned
    ' in the ShowLeafs function call based on the read write access
    ' of the item.  In this case we need to test the index of the
    ' AccessFilter combo box control since the user may not have
    ' selected anything yet in which case we will use the
    ' access type of "0" which tells the server to return all
    ' items regardless of access type.
    If AccessFilter.ListIndex = -1 Then
        AccessSelected = 0
    Else
        AccessSelected = AccessFilter.ItemData(AccessFilter.ListIndex)
    End If
    OPCBrowserClassObj.SetAccessFilter AccessSelected
    
    ' Finally show the new items based on the filters set above.
    OPCBrowserClassObj.ShowLeafs
    ' Add the new item if anny to the listview control.
    For i = 1 To OPCBrowserClassObj.GetItemCount
        OPCBrowserClassObj.GetItemName ItemName, i
        lvItemView.ListItems.Add , "Item" + Str(i), ItemName
    Next i
End Sub

' The ItemNameFilter_Change allows you to reduce the number of tags displayed
' based on the name of the item.  The other two fitler mehtods must also be applied
' here before the ShowLeafs function is called to reload the tags
' in the lsitview control.  This operation occurs everytime you change the
' the item name filter on the dialog.
'
Private Sub ItemNameFilter_Change()
    Dim i As Integer
    Dim ItemName As String
    Dim DataTypeSelected As Integer
    Dim AccessSelected As Long
    
    ' Remove all of the current items from the lsit view.
    lvItemView.ListItems.Clear
    
    ' Set the Item name filter using the string found in the
    ' ItemNameFilter cotnrol.  By default this is "*" which
    ' most server take to mean everything.  You can use
    ' other wildcards such as ? in addition to *.  Using these
    ' Wildcard you can do some fairly fancy filtering. An example
    ' might be "Pressure_???_T*"  In this case and items with the
    ' the name "Pressure_" then three fields of anything then
    ' "_T" anything would be return when we call ShowLeafs.
    '
    OPCBrowserClassObj.SetFilter ItemNameFilter.Text
    
    ' Set the datatype filter.  Like the item name filter this
    ' filter allows you to reduce the number of items returned
    ' in the ShowLeafs function call based on the data type of the
    ' item.  In this case we need to test the index of the DataTypeFilter
    ' combo box control since the user may not have selected anything
    ' yet in which case we will use the "Native" data type which tells
    ' the server to return all datatypes.
    If DataTypeFilter.ListIndex = -1 Then
        DataTypeSelected = 0
    Else
        DataTypeSelected = DataTypeFilter.ItemData(DataTypeFilter.ListIndex)
    End If
    OPCBrowserClassObj.SetDataTypeFilter DataTypeSelected
    
    ' Set the access type filter.  Like the item name filter this
    ' filter allows you to reduce the number of items returned
    ' in the ShowLeafs function call based on the read write access
    ' of the item.  In this case we need to test the index of the
    ' AccessFilter combo box control since the user may not have
    ' selected anything yet in which case we will use the
    ' access type of "0" which tells the server to return all
    ' items regardless of access type.
    If AccessFilter.ListIndex = -1 Then
        AccessSelected = 0
    Else
        AccessSelected = AccessFilter.ItemData(AccessFilter.ListIndex)
    End If
    OPCBrowserClassObj.SetAccessFilter AccessSelected
    
    ' Finally show the new items based on the filters set above.
    OPCBrowserClassObj.ShowLeafs
    ' Add the new items if any to the listview control.
    For i = 1 To OPCBrowserClassObj.GetItemCount
        OPCBrowserClassObj.GetItemName ItemName, i
        lvItemView.ListItems.Add , "Item" + Str(i), ItemName
    Next i
End Sub


Private Sub AccessFilter_Click()
    Dim i As Integer
    Dim ItemName As String
    Dim DataTypeSelected As Integer
    Dim AccessSelected As Long
    
    lvItemView.ListItems.Clear
    
    ' Set the Item name filter using the string found in the
    ' ItemNameFilter cotnrol.  By default this is "*" which
    ' most server take to mean everything.  You can use
    ' other wildcards such as ? in addition to *.  Using these
    ' Wildcard you can do some fairly fancy filtering. An example
    ' might be "Pressure_???_T*"  In this case and items with the
    ' the name "Pressure_" then three fields of anything then
    ' "_T" anything would be return when we call ShowLeafs.
    '
    OPCBrowserClassObj.SetFilter ItemNameFilter.Text
    
    ' Set the datatype filter.  Like the item name filter this
    ' filter allows you to reduce the number of items returned
    ' in the ShowLeafs function call based on the data type of the
    ' item.  In this case we need to test the index of the DataTypeFilter
    ' combo box control since the user may not have selected anything
    ' yet in which case we will use the "Native" data type which tells
    ' the server to return all datatypes.
    If DataTypeFilter.ListIndex = -1 Then
        DataTypeSelected = 0
    Else
        DataTypeSelected = DataTypeFilter.ItemData(DataTypeFilter.ListIndex)
    End If
    OPCBrowserClassObj.SetDataTypeFilter DataTypeSelected
    
    ' Set the access type filter.  Like the item name filter this
    ' filter allows you to reduce the number of items returned
    ' in the ShowLeafs function call based on the read write access
    ' of the item.  In this case we need to test the index of the
    ' AccessFilter combo box control since the user may not have
    ' selected anything yet in which case we will use the
    ' access type of "0" which tells the server to return all
    ' items regardless of access type.
    If AccessFilter.ListIndex = -1 Then
        AccessSelected = 0
    Else
        AccessSelected = AccessFilter.ItemData(AccessFilter.ListIndex)
    End If
    OPCBrowserClassObj.SetAccessFilter AccessSelected
    
    ' Finally show the new items based on the filters set above.
    OPCBrowserClassObj.ShowLeafs
    ' Add the new items if any to the listview control.
    For i = 1 To OPCBrowserClassObj.GetItemCount
        OPCBrowserClassObj.GetItemName ItemName, i
        lvItemView.ListItems.Add , "Item" + Str(i), ItemName
    Next i

End Sub





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -