Option Explicit
Function action
Dim sPro
Dim sDsn
Dim sSer
Dim sCon
Dim sSql
Dim oRs
Dim conn
Dim oCom
Dim oItem
Dim oPercent
Dim TagStartTime, TagAimTemp, Num, LogSum, LogID, n
'Connet SQL
sPro = "Provider=WinCCOLEDBProvider.1;"
sDsn = "Catalog=CC_TEST__07_03_29_10_50_43R;"
sSEr = "DAta Source=.\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
For Num = 1 To 6
TagStartTime = HMIRuntime.Tags("StartTime_" + CStr(Num)).Read
n = DateDiff("h",TagStartTime, Now)
If n < 6 Then
Select Case Num
Case 1
LogID = "27"
Case 2
LogID = "30"
Case 3
LogID = "33"
Case 4
LogID = "37"
Case 5
LogID = "40"
Case 6
LogID = "43"
End Select
sSql = "TAG:R," + LogID + ",'" + CStr(DateAdd("h", -8, TagStartTime)) + ".000','" + CStr(DateAdd("h", -8, Now)) + ".000'"
oCom.CommandText = sSql
Set oRs = oCom.EXecute
If (oRs.RecordCount > 0) Then
oRs.MoveFirst
LogSum = 0
Do While Not oRs.EOF
LogSum = LogSum + oRs.Fields(2).value
oRs.MoveNext
Loop
TagAimTemp = HMIRuntime.Tags("AimTemp_" + CStr(Num)).Read
Set oPercent = HMIRuntime.Screens("Pic_Main").ScreenItems("Log_Percent_" + CStr(Num))
oPercent.OutPutValue = FormatPercent(LogSum/(TagAimTemp*5*60),1,-1)
End If
Else
Set oPercent = HMIRuntime.Screens("Pic_Main").ScreenItems("Log_Percent_" + CStr(Num))
oPercent.OutPutValue = "请设置新的数据"
End If
Next
oRs.Close
Set oRs = Nothing
conn.Close
Set conn = Nothing
问题补充:
想请问大家:以下的LogID="27",27,30,33,37,40,43这些数据是根据什么而设的?可以告诉我吗?谢谢
Case 1
LogID = "27"
Case 2
LogID = "30"
Case 3
LogID = "33"
Case 4
LogID = "37"
Case 5
LogID = "40"
Case 6
LogID = "43
最佳答案
变量归档所对应的ID号,可从SQL SERVER MANAGER中查到。
提问者对于答案的评价:
谢谢
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc272936.html