Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Now.TimeOfDay.Minutes = 47 Then
MessageBox.Show("47")
End If
End Sub
Dim moment As New System.DateTime(1999, 1, 13, 3, 57, 32, 11)
' Year gets 1999.
Dim year As Integer = moment.Year
' Month gets 1 (January).
Dim month As Integer = moment.Month
' Day gets 13.
Dim day As Integer = moment.Day
' Hour gets 3.
Dim hour As Integer = moment.Hour
' Minute gets 57.
Dim minute As Integer = moment.Minute
' Second gets 32.
Dim second As Integer = moment.Second
' Millisecond gets 11.
Dim millisecond As Integer = moment.Millisecond
Dim twoOclockToday As Date = Date.Today.AddHours(14)
Dim interval As Integer = CInt(Math.Round((twoOclockToday - Date.Now).TotalMilliseconds))
myTimer.Interval = interval
myTimer.Start()
I think this code will be more suitable for my case. But does it work only on the moment it hits the minute or hour i set? I'm afraid it might miss the time and will not go into the function. Can a range be used?VB.NET:Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If Now.TimeOfDay.Minutes = 47 Then MessageBox.Show("47") End If End Sub
Private alarmTime As New TimeSpan(2, 3, 1)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim alarmTime As Date = Date.Today + Me.alarmTime
If alarmTime > Date.Now Then
alarmTime.AddDays(1)
End If
Dim interval As TimeSpan = alarmTime - Date.Now
'Set the Timer's Interval to the time until the next alarm.
Me.Timer1.Interval = CInt(Math.Round(interval.TotalMilliseconds))
Me.Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim alarmTime As Date = Date.Today.AddDays(1) + Me.alarmTime
Dim interval As TimeSpan = alarmTime - Date.Now
'Set the Timer's Interval to the time until the next alarm.
Me.Timer1.Interval = CInt(Math.Round(interval.TotalMilliseconds))
'Do something here.
End Sub