1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| Sub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y)
Dim sPro, sDsn, sSer,sCon, sSql
Dim sVid, sVal, lRet, sRel
Dim V,Sum,Avg,Std
Dim conn, oRs, oCom, oList, oItem
Dim m,n,s,nRec
Dim strDateTime, iMs
// 0.0 Get parameters from picture
sDsn = ScreenItems("laDSN").Text
sSer = ScreenItems("laServer").Text
sSql = ScreenItems("laSql").Text
//1.1 Make connection string for ADODB as indicated below
//Provider=WinCCOLEDBProvider.1;Catalog=CC_V6_Demo3_03_02_04_16_19_15R;Data Source=.\WinCC"
// 1.2 Define command text in sSql for WinCC compressed archives, relative time
sPro = "Provider=WinCCOLEDBProvider.1;"
sDsn = "Catalog=" + sDsn + ";"
sSer = "Data Source=" + sSer + "\WinCC"
sCon = sPro + sDsn + sSer
nRec = NMAX
// "TAG:R,1,'0000-00-00 00:05:00.000','0000-00-00 00:00:00.000'"
lRet = MsgBox("Opened with " & vbCr & sCon & vbCr & sSql & vbCr, vbOKCancel)
If lRet <> 1 Then Exit Sub
// 2.1 Make connection
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = sCon
conn.CursorLocation = adUseClient //3
conn.Open
// 2.2 Use command text for query
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
oCom.CommandType = 1 //adCmdText = 1
Set oCom.ActiveConnection = conn
//***** ma ligne Sql est TAG:R,1,'0000-00-00 00:05:00.000','0000-00-00 00:00:00.000'
//***** J'ai un peu de mal à comprendre cette ligne
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
Sum = 0
Avg = 0
Std=0
Do While Not oRs.EOF
n = n + 1
V = oRs.Fields(2).Value
Sum = Sum +V
Std = Std + V ^ 2
If( n < nRec ) Then
SplitDateTimeAndMs oRS.Fields(1).Value, strDateTime, iMs
s = FormatDateTime(strDateTime,2) & " " & FormatDateTime(strDateTime,3)
Set oItem = oList.ListItems.Add()
oItem.Text = s
oItem.SubItems(1) = iMs
oItem.SubItems(2) = FormatNumber(V, 4)
oItem.SubItems(3) = Hex(oRs.Fields(4).Value) // vrati
End If
oRs.MoveNext
Loop
oRs.Close
If( n>1) Then Avg = Sum / n
If (n>2) Then Std = Sqr((Std - n * Avg ^ 2) / (n - 1))
HMIRuntime.Tags("Count").Write n
HMIRuntime.Tags("Sum").Write Sum
HMIRuntime.Tags("Avg").Write Avg
HMIRuntime.Tags("Std").Write Std
Else
End If
Set oRs = Nothing
conn.Close
Set conn = Nothing
End Sub |
Partager