本文主要是介绍WinCC7.5 将归档数据打印到MSHGrid(不是MSFlexGrid控件),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
参考网址:https://www.cnblogs.com/fishingsriver/p/14397431.html
新建变量
MSHGrid控件
查询按钮
Sub OnClick(ByVal Item) Dim myCatalog,myDS,PCName,cnstr,sqlstr1,sqlstr2
Dim grid,BTime,ETime,utcbtime,utcetime,utcbtstr,utcetstr
Dim conobj,rsobj1,comobj1
Dim rsobj2,comobj2
Dim rscount,i,curRow
myCatalog=HMIRuntime.Tags("@DatasourceNameRT").Read
PCName=HMIRuntime.Tags("@LocalMachineName").Read
myDS=PCName & "\WinCC"
Set BTime=HMIRuntime.Tags("btime")
Set ETime=HMIRuntime.Tags("etime")
utcbtime=Dateadd("h",-8,BTime.Read)
utcetime=Dateadd("h",-8,ETime.Read)
utcbtstr = Year(utcbtime) & "-" & Month(utcbtime) & "-" & Day(utcbtime) & " " & Hour(utcbtime) & ":" & Minute(utcbtime) & ":" & Second(utcbtime)
utcetstr = Year(utcetime) & "-" & Month(utcetime) & "-" & Day(utcetime) & " " & Hour(utcetime) & ":" & Minute(utcetime) & ":" & Second(utcetime)
cnstr="Provider=WinCCOLEDBProvider.1; Catalog=" & myCatalog & "; Data Source=" & myDS'Msgbox cnstrSet conobj=CreateObject("ADODB.Connection")
conobj.connectionstring=cnstr
conobj.CursorLocation = 3
conobj.Open
'TimeStep=2,1 表示间隔2秒。
'sqlstr = "Tag:R,('ProcessValueArchive\OFP';'ProcessValueArchive\OMP'),'" & utcbtstr & "','" & utcetstr & "'," & "'order by Timestamp ASC','TimeStep=1,1'"
sqlstr1 = "Tag:R,('ProcessValueArchive\OFP'),'" & utcbtstr & "','" & utcetstr & "'," & "'order by Timestamp ASC','TimeStep=1,1'"
sqlstr2 = "Tag:R,('ProcessValueArchive\OMP'),'" & utcbtstr & "','" & utcetstr & "'," & "'order by Timestamp ASC','TimeStep=1,1'"Set rsobj1 = CreateObject("ADODB.Recordset")
Set comobj1 = CreateObject("ADODB.Command")
comobj1.CommandType = 1
Set comobj1.ActiveConnection = conobj
comobj1.CommandText = sqlstr1
Set rsobj1 = comobj1.ExecuteSet rsobj2 = CreateObject("ADODB.Recordset")
Set comobj2 = CreateObject("ADODB.Command")
comobj2.CommandType = 1
Set comobj2.ActiveConnection = conobj
comobj2.CommandText = sqlstr2
Set rsobj2 = comobj2.ExecuteSet grid=ScreenItems("grid")
rscount=rsobj1.RecordCount
If rscount=0 ThenMsgbox "无记录"Exit Sub
End If
rsobj1.movefirst
rsobj2.movefirstgrid.Cols=4
grid.Rows=rscount+1grid.TextMatrix(0,1)="日期时间"
grid.TextMatrix(0,2)="空气总压"
grid.TextMatrix(0,3)="煤气总压"For i=1 To rscountcurRow=igrid.TextMatrix(curRow,1)=Dateadd("h",+8,rsobj1.fields(1).value)grid.CellWidth(1)=2500grid.TextMatrix(curRow,2)=rsobj1.fields(2).valuegrid.TextMatrix(curRow,3)=rsobj2.fields(2).valuersobj1.movenextrsobj2.movenext
NextSet rsobj1 = Nothing
Set rsobj2 = Nothing
conobj.Close
Set conobj = NothingEnd Sub
这篇关于WinCC7.5 将归档数据打印到MSHGrid(不是MSFlexGrid控件)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!