VB.NET,如何利用Timer控件在某个时间点触发事件?
比如,点击窗体的button,然后要求它在未到来的某个时间点比如11:59:45,执行某个sub过程;或者,从11:55:00开始,到11:59:45,每隔10秒钟执行一...
比如,点击窗体的button,然后要求它在未到来的某个时间点比如11:59:45,执行某个sub过程;
或者,从11:55:00开始,到11:59:45,每隔10秒钟执行一次sub过程~
谢谢~
请帮忙写下代码,追加30~ 展开
或者,从11:55:00开始,到11:59:45,每隔10秒钟执行一次sub过程~
谢谢~
请帮忙写下代码,追加30~ 展开
1个回答
展开全部
我待会私信给你,因为这里写代码可能会被判定内容不规范~~
当然你可以追问下, 我在下面回答下试试~~
程序不难!可以自己写一下哦~~
私信里面查收哦~~
代码已经写好了,你追问下~~
呃,我试下代码能不能直接写进来吧~~
建立一个按钮,两个timer,我这里用的是默认名称~~
-----
By 110schoolx
纯手工,问题解决请采纳,问题未解决请继续追问,请勿人间蒸发,谢谢!
——————————
vb.net原代码:
Public Class Form1
Dim time As String
Dim time2 As String
Dim timeofhour As Integer
Dim timeofminute As Integer
Dim timeofsecond As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = False
Timer2.Enabled = False
Timer1.Interval = 500
Timer2.Interval = 10000
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'11:59:45,执行某个sub过程
Dim CurrentTime As String
CurrentTime = Format(TimeOfDay, "yyMMdd-HHmmss")
time = "20130508-115945"
If CurrentTime = time Then
Call Process()
End If
'从11:55:00开始,到11:59:45,每隔10秒钟执行一次sub过程
Dim CurrentTime2 As String
CurrentTime2 = Format(TimeOfDay.Date, "yyMMdd")
time2 = "20130508"
If CurrentTime2 = time2 Then
If TimeOfDay.Hour = 11 Then
If TimeOfDay.Minute > 54 And TimeOfDay.Minute < 59 Then
Timer2.Enabled = True
ElseIf TimeOfDay.Minute = 59 And TimeOfDay.Second < 46 Then
Timer2.Enabled = True
Else
Timer2.Enabled = False
End If
End If
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
Private Sub Process()
'Enter your code
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Call Process()
End Sub
End Class
当然你可以追问下, 我在下面回答下试试~~
程序不难!可以自己写一下哦~~
私信里面查收哦~~
代码已经写好了,你追问下~~
呃,我试下代码能不能直接写进来吧~~
建立一个按钮,两个timer,我这里用的是默认名称~~
-----
By 110schoolx
纯手工,问题解决请采纳,问题未解决请继续追问,请勿人间蒸发,谢谢!
——————————
vb.net原代码:
Public Class Form1
Dim time As String
Dim time2 As String
Dim timeofhour As Integer
Dim timeofminute As Integer
Dim timeofsecond As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = False
Timer2.Enabled = False
Timer1.Interval = 500
Timer2.Interval = 10000
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'11:59:45,执行某个sub过程
Dim CurrentTime As String
CurrentTime = Format(TimeOfDay, "yyMMdd-HHmmss")
time = "20130508-115945"
If CurrentTime = time Then
Call Process()
End If
'从11:55:00开始,到11:59:45,每隔10秒钟执行一次sub过程
Dim CurrentTime2 As String
CurrentTime2 = Format(TimeOfDay.Date, "yyMMdd")
time2 = "20130508"
If CurrentTime2 = time2 Then
If TimeOfDay.Hour = 11 Then
If TimeOfDay.Minute > 54 And TimeOfDay.Minute < 59 Then
Timer2.Enabled = True
ElseIf TimeOfDay.Minute = 59 And TimeOfDay.Second < 46 Then
Timer2.Enabled = True
Else
Timer2.Enabled = False
End If
End If
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
Private Sub Process()
'Enter your code
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Call Process()
End Sub
End Class
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询