Sub OnClick(ByVal Item)
Dim sPro, sDsn, sSer,sCon, sSql
Dim sVid, sStart, sStop, sVal,lRet,dVal, dGT
Dim conn, oRs, oCom, oList, oItem
Dim m,n,s, DSNName
Dim objIOMinuten, objIOWert
Set DSNName = HMIRuntime.Tags("ProjectDSN")
' 0.0 Get parameters from picture
DSNName.Read
HMIRuntime.Trace "Value DSNName: " & DSNName.Read & vbCrLf
sDsn = DSNName.Value
HMIRuntime.Trace "Value DSNName.Value: " & sDsn & vbCrLf
'sVid = CStr(13)
sVid = CStr(106)'104 = ID of Archive\Achive variable "T01"
Set objIOMinuten = ScreenItems("Minuten")
sStart=objIOMinuten.OutputValue
sStop = "0000-00-00 00:00:00.000"
Set objIOWert = ScreenItems("Wert")
sVal = objIOWert.OutputValue
'"Provider=WinCCOLEDBProvider.1;Catalog=CC_V6_Demo3_03_02_04_16_19_15R;Data Source=.\WinCC"
sPro = "Provider=WinCCOLEDBProvider.1;"
sDsn = "Catalog=" & sDsn & ";"
sSer = "Data Source=.\WinCC"
sCon = sPro & sDsn & sSer
'Trace mit Ausgabe in GlobalSkriptDiagnose-Fenster
HMIRuntime.Trace "sCon: " & sCon & vbCrLf
sSql = "Tag:R," & sVid & ",'0000-00-00 00:" & sStart & ":00.000','" & sStop & "'"
lRet = MsgBox("Opened with " & vbCr & sCon & vbCr & sSql & vbCr & sVal, vbOKCancel)
' If lRet <> 1 Then Exit Sub
'Trace mit Ausgabe in GlobalSkriptDiagnose-Fenster
HMIRuntime.Trace "sSql: " & sSql & vbCrLf
' 2.1 Make connection
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = sCon
'Trace mit Ausgabe in GlobalSkriptDiagnose-Fenster
HMIRuntime.Trace "conn.ConnectionString: " & conn.ConnectionString & vbCrLf
conn.CursorLocation = 3 'adUseClient original'
conn.Open
' 2.2 Use command text for query
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
' adCmdText = 1
oCom.CommandType = 1
Set oCom.ActiveConnection = conn
oCom.CommandText = sSql
' 2.3 Fill the recordset
Set oRs = oCom.Execute
m = oRs.Fields.Count
' 3.0 Fill standard listview object with recordset
Set oList = ScreenItems("ListTable")
oList.ListItems.Clear
If(m>0) Then
oRs.MoveFirst
n = 0
dGT = CDbl(sVal)
Do While Not oRs.EOF
n = n + 1
dVal = oRs.Fields(2).Value
If dVal > dGT Then
s = Left(CStr(oRs.Fields(1).Value), 23)
Set oItem = oList.ListItems.Add()
oItem.Text = Left(CStr(oRs.Fields(1).Value), 23)
oItem.SubItems(1) = FormatNumber(dVal, 4)
oItem.SubItems(2) = Hex(oRs.Fields(4).Value)
End If
If (n > 100) Then Exit Do
oRs.MoveNext
Loop
oRs.Close
Else
End If
Set oRs = Nothing
Set conn = Nothing
End Sub
这是一段连接查询数据库到listview控件中的脚本,请问其中 Tags("ProjectDSN")是什么参数?要查询的变量不是T01吗? 另外想问下如何判断归档中的变量的ID号,例如:CStr(106)'104 = ID of Archive\Achive variable "T01"
106从哪里读出的?
希望高手帮帮忙
最佳答案
ProjectDSN应该是一个文本型的变量,保存的是本项目的运行数据库DSN名称,就是类似CC_V6_Demo3_03_02_04_16_19_15R的东西。
归档变量的ID号需要通过SQL SERVER来获得。打开SQL Server Enterprise Manager,找到项目运行数据库(类似CC_V6_Demo3_03_02_04_16_19_15R),找到表格Archive,并通过Open Table->Return All Rows打开表格,找到对应的VALUE ID既是。
提问者对于答案的评价:
谢谢
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc276664.html