你的位置:首页 > 新闻动态 > 行业新闻

wincc利用脚本访问压缩归档

2014-5-6 9:14:39      点击:
其实这是一个很简单的demo,但是当执行到oCom.Execute的时候总是提示“未指定的错误”
有点晕!今晚开党支部会         也开不下去了!逃!
我来到了实验室 一点一点地改,一点一点地试
当我把要读的目的归档数据banciArchive/banci改为chanwuArchive/chanwu的时候
突然,结果出来了!
为什么同样是归档数据,有的可以有的不可以呢 ? 我仔细检查了两者的区别,当把前者的组态改的和后者一模一样的时候,两者就都可以了!(注意:1.过程变量属性 里边的 提供变量 选择 系统 还是 手动输入 2.新定义了归档后 重启一下项目工程)
嘿嘿,这种兴奋感久违了!以下是这段代码:
Sub X6309X94AE1X0000S_X6309X94AE1X0000X5F0F_X6309X94AE1X00009_OnClick(ByVal Item)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''定义变量                              
Dim sPro
Dim sDsn
Dim sSer
Dim sCon
Dim sSql
Dim oRs
Dim conn
Dim oCom
Dim oItem
Dim m,n,s
Dim hourdate
Dim secdate
Dim k
Dim oList
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''连接并读取数据库
sPro = "Provider=WinCCOLEDBProvider.1;"
sDsn = "Catalog=CC_myprj_07_04_01_09_11_32R;"
sSer = "Data Source=.\WinCC"
sCon = sPro + sDsn + sSer
sSql = "TAG:R,'banciArchive\banci','2007-4-1 00:00:00','2007-4-5 00:00:00'"
Set conn = CreateObject("ADODB.Connection")
conn.Connecti*****tring = sCon
conn.CursorLocation = 3
conn.Open
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
oCom.CommandType = 1
Set oCom.ActiveConnection = conn
oCom.CommandText = sSql
Set oRs = oCom.Execute
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''显示到listview中
Set oList = ScreenItems("listview1")
oList.View =3
oList.ListItems.Clear
m = oRs.Fields.Count
oList.ColumnHeaders.Clear
For n = 0 To m - 1
           oList.ColumnHeaders.Add , , CStr(oRs.Fields(n).Name), 100 
Next
If (m > 0) Then
         oRs.MoveFirst
         n = 0
         Do While Not oRs.EOF And n < 80
          Set oItem = oList.ListItems.Add()
          oItem.Text = FormatNumber(oRs.Fields(0).value,0)  
          s = CDate(oRs.Fields(1).value)
          k = DateAdd("h", 8, s)
          oItem.SubItems(1) = k
          oItem.SubItems(2) = FormatNumber(oRs.Fields(2).value,0)
          oItem.SubItems(3) = FormatNumber(oRs.Fields(3).value,0)
          'oItem.SubItems(2) = Hex(oRs.Fields(3).value)
          oItem.SubItems(4) = FormatNumber(oRs.Fields(4).value,0)
          n = n + 1
          oRs.MoveNext
         Loop
         MsgBox n
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''关闭记录集,数据库连接
oRs.Close
Set oRs = Nothing
conn.Close
Set conn = Nothing
End Sub