发表于:2006-04-20 12:27:00
楼主
我是在做毕业设计的学生,要在treeview控件里添加标签,但是我的子程序只能添加最顶层的标签,下面带颜色的语句还显示‘自动化错误’请指点迷津,不胜感激!!!!
Dim AnOPCBrowser As OPCBrowser
Public AnOPCServer As OPCServer
Public ProgID As String
Public AllOPCItemCounts As Long '首先用browser方法得出这个变量的值,才能对全体数据进行加项以及读取
Public Const AllOPCItemNUMS = 500
Public ReturnBranches(1 To AllOPCItemNUMS) As String
Public AllOPCItemIDS(1 To AllOPCItemNUMS) As String
Public ClientHandles(1 To AllOPCItemNUMS) As Long
********************************************************************
'通过浏览器对服务器的标签进行读取,并用treeview控件进行显示,因为是通用客户端,所以还不知道服务器中的标签是
'多少级的,必须进行判断。
Sub BrowserOPCItem()
Dim i As Integer
Dim j As Integer
Dim ItemName() As String
Dim TreeStr As String
Dim SubTreeStr As String
Dim ReturnBranches(1 To 500)
'初始化opcbrowser
Set AnOPCBrowser = Nothing
Set AnOPCBrowser = AnOPCServer.CreateBrowser
AnOPCBrowser.MoveToRoot
AnOPCBrowser.ShowBranches
AllOPCItemCounts = AnOPCBrowser.Count
Form1.TreeView1.LineStyle = tvwRootLines '在兄弟接点和父接点之间显示线
'对treeview控件进行节点的添加
Form1.TreeView1.Nodes.Add , , "NO.1", ProgID
For i = 1 To AllOPCItemCounts
ReturnBranches(i) = AnOPCBrowser.Item(i) '因为不允许对showbranches方法进行循环,必须先保存好服务器
'里面的枝
Next i
'把服务器里面所有的标签都添加到treeview1里面,每个标签是一个节点,因为每个标签里面还有子标签,所以要进行
'多个循环
For i = 1 To AllOPCItemCounts
TreeStr = "NO." & (i + 1)
Form1.TreeView1.Nodes.Add "NO.1", tvwChild, TreeStr, ReturnBranches(i)
AnOPCBrowser.MoveDown (ReturnBranches(i))
[color=#FF0000]AnOPCBrowser.ShowLeafs[/color]
'内循环是用来对子节点的添加
For j = 1 To AnOPCBrowser.Count
SubTreeStr = "NONO." & i & (j + 1)
Form1.TreeView1.Nodes.Add TreeStr, tvwChild, SubTreeStr, AnOPCBrowser.Ite