日报表解释说明
- 格式:doc
- 大小:110.00 KB
- 文档页数:10
1全局脚本
在全局脚本里建立起与数据库的连接,通过定时整点触发脚本,把变量写到数据库。WINCC里全局脚本触发定时器设定是每小时整点触发。
Option Explicit 变量声明
Function action 功能操作
Dim database 定义数据库
Dim strcn,cn
Dim is_SQL
Dim riqi
Dim yali,wendu,liuliang,zhongliang,dianya,sudu 定义压力、温度、、、、
Dim DateTime 定义日期时间
riqi=Now
Set yali= HMIRuntime.Tags("yali") 人机界面运行时间标签
yali.Read
Set wendu= HMIRuntime.Tags("wendu")
wendu.Read
Set liuliang= HMIRuntime.Tags("liuliang")
liuliang.Read
Set zhongliang= HMIRuntime.Tags("zhongliang")
zhongliang.Read
Set dianya= HMIRuntime.Tags("dianya")
dianya.Read
Set sudu= HMIRuntime.Tags("sudu")
sudu.Read
strcn="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=baobiao1;Data Source=.\wincc"
Set cn=CreateObject("ADODB.connection")
cn.connectionString=strcn
cn.Open
is_SQL="insert into ribao(riqi,yali,wendu,liuliang,zhongliang,dianya,sudu) Values('"& riqi &"','"&yali.Value &"','"&wendu.Value &"','"&liuliang.Value &"','"&zhongliang.Value &"','"&dianya.Value &"','"&sudu.Value &"')"
cn.Execute is_SQL
cn.Close
End Functi
2查询按钮
Sub OnClick(ByVal Item)
Dim i, n, k, n1, a1, b1, c1, d1, e1, f1
Dim MSFlexGrid1
Dim Sql, oCom, conn, sql1, oCom1
Dim j, b, z
Dim ylp, wdp, llp, ylx, wdx, llx, yld, wdd, lld
Dim zlp, dyp, sdp, zlx, dyx, sdx, zld, dyd, sdd
【压力、温度、流量、重力、电压、速度的平均值、最小值、最大值】
Dim strcn, cn
Dim a, shi, t, x
Dim oRs, oRs1
Dim Text2
Dim BeginDate 开始日期
Dim EndDate 结束日期
Dim By, Bm, Bd 定义开始年月日
Dim Ny, Nm, Nd, c, e, f 定义结束年月日
Dim Date1,Date2
【定义函数命令:
】
Set Text2 = ScreenItems("Text2")
Set Date1 = ScreenItems("Date1")
Set Date2 = ScreenItems("Date2")
Set MSFlexGrid1 = ScreenItems("MSFlexGrid1")
【ScreenItems为画面对象集合,把定义的函数与画面中的控件进行映射
】
By = Year(Date1.Value)
Bm = Month(Date1.Value)
Bd = Day(Date1.Value) 【BY BM BD 为date1的年月日定义,B为begin开始时间】
Ny = Year(Date2.Value)
Nm = Month(Date2.Value)
Nd = Day(Date2.Value) 【NY NM ND 为date2的年月日定义,N的end结束时间】BeginDate = By & "-" & Bm & "-" & Bd & " " & "00:00:00"
EndDate = Ny & "-" & Nm & "-" & Nd & " " & "23:59:59"
e = By & "-" & Bm & "-" & Bd
f = Ny & "-" & Nm & "-" & Nd
If By > Ny Or By = Ny And Bm > Nm Or By = Ny And Bm = Nm And Bd > Nd Then MsgBox "输入的时间不正确", vbOK, "错误的起始时间" 【MsgBox为弹出的对话框控件】End If
'以上程序为日期查询
2.1 '建立连接
Sql = "SELECT CONVERT(char(19), riqi, 20) AS riqi, yali, wendu, liuliang, zhongliang, dianya, sudu FROM ribao WHERE riqi BETWEEN '" & BeginDate & "' and'" & EndDate & "'ORDER BY riqi"
【CONVERT 在SQL(结构化语言)中的一个系统函数
一般用法
convert 函数用来转换数据类型
例子:SELECT CONVERT (VARCHAR(5),12345)
返回:字符串 '12345'
/sql/sql_orderby.asp】
sql1 = "select avg(yali)as ylp,avg(wendu)as wdp,avg(liuliang)as llp,avg(zhongliang)as zlp,avg(dianya)as dyp,avg(sudu)as sdp,min(yali)as ylx,min(wendu)as wdx,min(liuliang)As llx,min(zhongliang)As zlx,min(dianya)As dyx,min(sudu)As sdx,max(yali)As yld,max(wendu)As wdd,max(liuliang)As lld,max(zhongliang)As zld,max(dianya)As dyd,max(sudu)As sdd from ribao where riqi between '" & BeginDate & "' and'" & EndDate & "'"
【/sql/sql_func_avg.asp】
strcn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist SecurityInfo=False;Initial Catalog=baobiao1;Data Source=.\wincc"
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = strcn
conn.CursorLocation = 3
conn.Open
'使用命令文本查询
Set oRs = CreateObject("ADODB.Recordset")