定时检测vb程序

来源:百度知道 编辑:UC知道 时间:2024/06/01 18:20:22
想要每十分钟对数据进行评价,然后将评价结果存入数据库,代码如下
Private Sub Timer1_Timer()
Text7.Text = Date$ '获得时间日期
Text8.Text = Time$
On Error Resume Next
Dim tmChk As Date
tmChk = Time
If (Minute(tmChk) = 10 Or Minute(tmChk) = 20 Or Minute(tmChk) = 30 Or Minute(tmChk) = 40 Or Minute(tmChk) = 50 Or Minute(tmChk) = 0) And Second(tmChk) = 0 Then
sum1 = Val(Text1.Text) * 0.4587 + Val(Text2.Text) * 0.1665 + Val(Text3.Text) * 0.1609 + Val(Text4.Text) * 0.0433 + Val(Text5.Text) * 0.0427 + Val(Text9.Text) * 0.0428 + Val(Text11.Text) * 0.0425 + Val(Text12.Text) * 0.0426
If sum1 <= 3 Then
Text6.Text = "贫营养化"
ElseIf (sum1 > 3 And sum1 <= 4) Then
Text6.Text = "贫中营养化"
ElseIf (sum1 > 4 And sum1 <= 5) Then
Text6.Text = "中营养化"
ElseIf (sum1 > 5 And sum1 <= 6) Then

首先,你的SQL语句引用的所有文本框中的数据时都缺少了.Text属性,应该如写法:

Set Rs = Con.Execute("insert into sheet2 (ID,PH,溶解氧,氨氮,温度,叶绿素,高锰酸钾,总磷,总氮,日期,时间,评价) values('" + Text10.text + "','" + Text1.text + "','" + Text2.text + "','" + Text3.text + "','" + Text4.text + "','" + Text5.text + "','" + Text9.text + "','" + Text11.text + "','" + Text12.text + "','" + Text7.text + "','" + Text8.text + "','" + Text6.text + "')")

其次:
1 如果你的数据库字段ID是自动编号的,则在SQL语句中就不要写插入ID字段的数据,如
Set Rs = Con.Execute("insert into sheet2 (PH,溶解氧,氨氮,温度,叶绿素,高锰酸钾,总磷,总氮,日期,时间,评价) values('" + Text1.text + "','" + Text2.text + "','" + Text3.text + "','" + Text4.text + "','" + Text5.text + "