ucooper
級別: *
|
之前做項目的時候,查閱了大量資料,終于解決了將歸檔數據寫入listviews控件的功能,這里將我的代碼發出來以供參考。注意,里面的一些參數需要根據你的具體需要進行修改。 本人還總結了一份技術文檔,由于這里不能上傳上傳文檔,請到我的個人博客里下載吧: http://www.ucooper.com/wincc-summary.html Sub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y) Dim sPro,sDsn,sSer,sCon,sSql,oRs,conn,oCom,oItem,m, n, s,i,oList sPro = "Provider=WinCCOLEDBProvider.1;" sDsn = "Catalog=CC_tanks_09_07_14_10_38_56R;" sSer = "Data Source=.\WinCC" sCon = sPro + sDsn + sSer sSql = "TAG:R,'tanks\aa','2009-07-16 00:00:00','2009-07-17 00:00:00'" MsgBox "Open with:" & vbCr & sCon & vbCr & sSql & vbCr 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 oCom.CommandText = sSql Set oRs = oCom.Execute n=oRs.RecordCount MsgBox(n) Set oList = ScreenItems("控件1") oList.ListItems.Clear olist.ColumnHeaders.clear oList.View =3 //顯示樣式,3為報表樣式 oList.GridLines =True //顯示網格 olist.ColumnHeaders.Add, , CStr(oRs.Fields(0).Name),150 oList.ColumnHeaders.Add, , CStr(oRs.Fields(1).Name),150 oList.ColumnHeaders.Add, , CStr(oRs.Fields(2).Name),150 oList.ColumnHeaders.Add, , CStr(oRs.Fields(3).Name),150 oList.ColumnHeaders.Add, , CStr(oRs.Fields(4).Name),150 'ListView1.ColumnHeaders.Add, , CStr(oRs.Fields(3).Name),150 If(n>0) Then oRs.MoveFirst End If m = 0 Do While Not oRs.EOF m = m + 1 Set oItem = oList.ListItems.Add() oItem.text=CStr(oRs.Fields(0).value) ' oItem.SubItems(1)="bb" ' oItem.SubItems(2)="cc" oItem.SubItems(1) = CStr(DateAdd("h", -8,oRs.Fields(1).value)) oItem.SubItems(2) = CStr(oRs.Fields(2).value) oItem.SubItems(3) = CStr(oRs.Fields(3).value) oItem.SubItems(4) = CStr(oRs.Fields(4).value) ' oItem.Text = Left(CStr(oRs.Fields(1).Value), 23) ' oItem.SubItems(1) = FormatNumber(oRs.Fields(2).Value, 4) ' oItem.SubItems(2) = Hex(oRs.Fields(4).Value) If m > 100 Then Exit Do Else End If oRs.MoveNext Loop MsgBox("wwwww") oRs.Close Set oRs = Nothing conn.Close Set conn = Nothing End Sub |
---|---|
|