-
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=
(
人机界面运行时间
标签
Set wendu= (
Set
liuliang= (
Set zhongliang=
(
Set dianya= (
Set sudu= (
strcn=
Security=SSPI;Persist
Security
Info=False;Initial
Catalog=baobiao1;Data Source=.wincc
Set
cn=CreateObject(
tionString=strcn
is_SQL=
into
ribao(riqi,yali,wendu,liuliang,zhongliang,d
ianya,sudu)
Values('
riqi
&
&
&
&
e is_SQL
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(
Set Date1 =
ScreenItems(
Set Date2 =
ScreenItems(
Set MSFlexGrid1 = ScreenIte
ms(
【
ScreenItems
为画
面对象集合,把定义的函数与画面中的控件进行映射
】
By
= Year()
Bm = Month()
Bd =
Day()
【
BY BM BD
为
date1
的年月日定义
,B
p>
为
begin
开始时间】
< br>
Ny =
Year()
Nm = Month()
Nd =
Day()
【
NY NM ND
为
date2
的年月日定义,
N<
/p>
的
end
结束时间】
BeginDate = By &
EndDate
= Ny &
e = By &
f = Ny &
If By > Ny Or By = Ny And Bm > Nm Or By
= Ny And Bm = Nm And Bd > Nd Then
MsgBox
输入的时间不正确
p>
错误的起始时间
【
MsgBox
为弹出的对话框控件】
End If
'
以上程序为日期查询
2.1 '
建立连接
Sql
=
CONVERT(char(19),
riqi,
20)
AS
riqi,
yali,
wendu,
liuliang,
zhongliang, dianya, sudu FROM ribao
WHERE riqi BETWEEN '
& EndDate &
【
CONVERT
在
SQL
(结构化语言)中的一个系统函数
一般用法
convert
函数
用来转换数据类型
例子:
SELECT CONVERT
(VARCHAR(5),12345)
返回:字符串
'12345'
/sql/sql_
】
sql1
=
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 '
p>
【
/sql/sql_func_
】
strcn
=
Security=SSPI;Persist
SecurityInfo=False;Initial
Catalog=baobiao1;Data Source=.wincc
Set conn = CreateObject(
tionString
= strcn
Location = 3
'
使用命令文本查询
Set oRs = CreateObject(
Set oCom =
CreateObject(
dType = 1
Set Connection = conn
dText = Sql
Set oRs = e
n = Count
【
RecordCount
指示
Recordset
对象中记录的当前数目】
=
n
【
Text2
为日报表中静态文本的
查询到的记录数的文本内容为
n
】
Set oCom1 = CreateObject(
dType = 1
Set Connection = conn
dText = sql1
Set oRs1
= e
n1 = Count
ylp =
oRs1(
oRs1(
llx
=
oRs1(
yld
=
oRs1(
wdd
=
oRs1(
lld
=
oRs1(
zlp =
oRs1(
oRs1(
sdx
=
oRs1(
zld
=
oRs1(
dyd
=
oRs1(
sdd
=
oRs1(
If n = 0 Then
【查询的结果数为
0
时显示内容】
p>
MsgBox
对不起
< br>,
没有找到符合条件的数据
没有
相关数据
End If
y
【
使用
FlexGrid
ActiveX
控件可以在
Microsoft Visual
Basic
的窗体中创建一个电
子数据表格,也可称之为网格,
/link?url=gdGZm1tyQhFpO4MlK
lEiFPvRS990aO0n5y9PFHPR1a
edWB4XLJL05K68
bL84l6aa
】
=
Count + 6
th(0) = 800
th(1)
= 2100
th(2) = 1000
th(3) =
1000
th(4) = 1000
th(5) =
1000
th(6) = 1000
th(7) =
1000
'
合并单元格,并把单元格的内容写为
R980
履带式布料机日报表
= 0
For z = 0 To 7
= z
=
履带式布料机日报表
Next
ells = 4
【
Merge
合并】
< br>
ow(0) = True
'
合并单元格
trix(1, 0) =
编号<
/p>
【
Matrix
矩阵,
(行,列)
】
trix(1, 1) =
日期
trix(1, 2) =
压力
trix(1, 3)
=
温度
trix(1,
4) =
流量
trix(1, 5) =
重量
trix(1, 6) =
电压
trix(1, 7) =
速度
'trix(Count+2, 0) =
总和
trix(Count + 3, 0) =
最大值
trix(Count + 4, 0) =
最小值
trix(Count + 5, 0) =
平均值
gnment(0) = 4
gnment(1) = 4
gnment(2) = 4
gnment(3) = 4
gnment(4) = 4
gnment(5) = 4
gnment(6) = 4
gnment(7) = 4
【对其方式