用vb+access作了个数据采集系统
需要3秒往数据库中放一组数据
使用了timer控件但是总是提示错误,使用需用户触发的时间就没有错误
timer空间命名为tmMain,data控件命名为data1
代码如下:
Private Sub MDIForm_Load()
tmMain.Enabled = False
tmMain.Interval = 3000
tmMain.Enabled = True
data1.DatabaseName = App.Path & "\data.mdb"
data1.RecordSource = "event"
writeDB = False
End Sub
Private Sub tmMain_timer()
data1.Recordset.AddNew
data1.Recordset.Fields("time") = mytime
data1.Recordset.Fields("date") = mydate
data1.Recordset.Fields("sector") = 0
data1.Recordset.Update
End Sub
麻烦大家帮忙看看,在非mdi的窗体中使用就没有问题,不知道为什么
嗯,谢谢你,不知有没有用data空间的示例呢?
在vb中定时记录数据的问题
答案:2 悬赏:40
解决时间 2021-02-20 03:29
- 提问者网友:騷女、無惡不作
- 2021-02-19 04:03
最佳答案
- 二级知识专家网友:错过的是遗憾
- 2021-02-19 04:53
提供一段在MDI中应用的写数据代码,TIMER的属性Interval设为500:
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\HXMdi.mdb;Persist Security Info=False"
Adodc1.RecordSource = "Select * from jilu_sj"
Adodc1.Refresh
End Sub
Private Sub Timer1_Timer()
If Label1.Caption <> CStr(Time$) Then
Label1.Caption = Time$
sum_zj = sum_zj + 1
'校准
If sum_zj >= 3 Then
sum_zj = sum_zj - 3 '每3秒记录一组数据
Adodc1.Recordset.AddNew
Adodc1.Recordset(0) = shiyan_sj(0)
Adodc1.Recordset(1) = Mid(Date$, 3, 2) & Mid(Date$, 6, 2) & Mid(Date$, 9, 2) & "-" & Time$ 'Mid(Time$, 1, 2) & Mid(Time$, 4, 2) & Mid(Time$, 7, 2) '记录time
Adodc1.Recordset(2) = Val(Label3(0).Caption) '记录数据
Adodc1.Recordset(3) = Val(Label3(1).Caption) '记录数据
Adodc1.Recordset.Update
End If
End If
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\HXMdi.mdb;Persist Security Info=False"
Adodc1.RecordSource = "Select * from jilu_sj"
Adodc1.Refresh
End Sub
Private Sub Timer1_Timer()
If Label1.Caption <> CStr(Time$) Then
Label1.Caption = Time$
sum_zj = sum_zj + 1
'校准
If sum_zj >= 3 Then
sum_zj = sum_zj - 3 '每3秒记录一组数据
Adodc1.Recordset.AddNew
Adodc1.Recordset(0) = shiyan_sj(0)
Adodc1.Recordset(1) = Mid(Date$, 3, 2) & Mid(Date$, 6, 2) & Mid(Date$, 9, 2) & "-" & Time$ 'Mid(Time$, 1, 2) & Mid(Time$, 4, 2) & Mid(Time$, 7, 2) '记录time
Adodc1.Recordset(2) = Val(Label3(0).Caption) '记录数据
Adodc1.Recordset(3) = Val(Label3(1).Caption) '记录数据
Adodc1.Recordset.Update
End If
End If
End Sub
全部回答
- 1楼网友:晨与橙与城
- 2021-02-19 05:36
在窗体上添加一个timer控件。把它的inteval设为6000,再添加代码如下:
private sub timer1_timer()
static i as long
i = i + 1
if i mod 300 = 0 then
'todo 这里添加你的过程名
end if
end sub
因为timer控件时间间隔最大值只有6.5秒,所以用一个变量i,每隔6秒递增。每达到30分钟执行特定代码
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯