yuantao0615
级别: 探索解密
精华主题: 0
发帖数量: 73 个
工控威望: 186 点
下载积分: 696 分
在线时间: 45(小时)
注册时间: 2010-01-04
最后登录: 2015-12-14
查看yuantao0615的 主题 / 回贴
楼主  发表于: 2013-10-15 17:21
这段代码在WINCC6.2中可以读出归档数据,在WINCC7.0中为什么却完全读不出来归档数据呢?
求高手指导啊!!!急急!!!!!!

Dim sPro, sDsn, sSer, sCon, sSql
    Dim conn, oRs, oCom
    Dim DSNName
    Dim i As Integer
    Dim sStart, sStop As String
    
Sub get_wincc_data()

    '--Get Database DSN name-----------------------------------
    Set DSNName = CreateObject("CCHMIRuntime.HMIRuntime")
    sDsn = DSNName.Tags("@DatasourceNameRT").Read
    
    '--build connection string-----------------------------------
    sPro = "Provider=WinCCOLEDBProvider.1;"
    sDsn = "Catalog=" & sDsn & ";"
    sSer = "Data Source=ZHANG\WinCC"
    sCon = sPro & sDsn & sSer
    Set conn = CreateObject("ADODB.Connection")
    conn.ConnectionString = sCon
    conn.CursorLocation = 3
    conn.Open
    Set oRs = CreateObject("ADODB.Recordset")
    Set oCom = CreateObject("ADODB.Command")
    oCom.CommandType = 1
    Set oCom.ActiveConnection = conn
    
  
    sStart = Year(DTPicker1.Value) & "-" & Month(DTPicker1.Value) & "-" & Day(DTPicker1.Value) & " 00:00:00"
    sStop = Year(DTPicker1.Value) & "-" & Month(DTPicker1.Value) & "-" & Day(DTPicker1.Value) & " 23:00:00"
    
  
     sStart = DateAdd("h", -8, CDate(sStart))
     sStop = DateAdd("h", -8, CDate(sStop))
    
  
     sSql = "Tag:R,('ProcessValueArchive\Fan1_T1'),'" & sStart & "','" & sStop & "' order by datetime"
     oCom.CommandText = sSql
    Set oRs = oCom.Execute
    If (oRs.EOF) Then
       oRs.Close
    Else
        oRs.MoveFirst
        i = 0
        Do While Not oRs.EOF
        Sheet1.Cells(i + 4, 2) = oRs.Fields("RealValue").Value
        oRs.MoveNext
        i = i + 1
        Loop
        oRs.Close
    End If
  

    sSql = "Tag:R,('ProcessValueArchive\Fan1_T2'),'" & sStart & "','" & sStop & "' order by datetime"
    oCom.CommandText = sSql
    Set oRs = oCom.Execute
    If (oRs.EOF) Then
       oRs.Close
    Else
        oRs.MoveFirst
        i = 0
        Do While Not oRs.EOF
        Sheet1.Cells(i + 4, 3) = oRs.Fields("RealValue").Value
        oRs.MoveNext
        i = i + 1
        Loop
        oRs.Close
    End If

    sSql = "Tag:R,('ProcessValueArchive\Fan1_P1'),'" & sStart & "','" & sStop & "' order by datetime"
    oCom.CommandText = sSql
    Set oRs = oCom.Execute
    If (oRs.EOF) Then
        oRs.Close
    Else
        oRs.MoveFirst
        i = 0
        Do While Not oRs.EOF
        Sheet1.Cells(i + 4, 4) = oRs.Fields("RealValue").Value
        oRs.MoveNext
        i = i + 1
        Loop
        oRs.Close
    End If
    
  
    sSql = "Tag:R,('ProcessValueArchive\Fan1_P2 '),'" & sStart & "','" & sStop & "' order by datetime"
    oCom.CommandText = sSql
    Set oRs = oCom.Execute
  
    If (oRs.EOF) Then
       oRs.Close
    Else
        oRs.MoveFirst
        i = 0
        Do While Not oRs.EOF
        Sheet1.Cells(i + 4, 5) = oRs.Fields("RealValue").Value
        oRs.MoveNext
        i = i + 1
        Loop
        oRs.Close
    End If
    
Set oRs = Nothing
Set conn = Nothing
End Sub


Private Sub DTPicker1_Change()
clear_cell get_wincc_data
End Sub

Sub clear_cell()
For i = 4 To 27
  For j = 2 To 5
  Cells(i, j) = ""
  Next j
Next i
End Sub
yuantao0615
级别: 探索解密
精华主题: 0
发帖数量: 73 个
工控威望: 186 点
下载积分: 696 分
在线时间: 45(小时)
注册时间: 2010-01-04
最后登录: 2015-12-14
查看yuantao0615的 主题 / 回贴
1楼  发表于: 2013-10-15 23:08
是不是因为ConnectivityPack没有授权的缘故呢?