Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this sub in a class:
VB
Private Sub TimerTick(ByVal sender As Object, ByVal e As EventArgs) Handles myTimer.Tick
            If alarmTime < Date.Now Then
            myTimer.Stop()
            RaiseEvent TimerComplete(&quot;Your time is up&quot;)
        Else
            RemainingTime = alarmTime.Subtract(Date.Now)

            RaiseEvent Elapsed(RemainingTime)
        End If
        If RemainingTime.Minutes <  1 Then
            RaiseEvent OnAlert("1 minute left")
        End If
    End Sub

Problem is when I raise the last event OnAlertEvent in the form with messagebox, at evey timer tick a new messagebox is shown tick filling up screen.Can anyone help
Posted
Updated 29-May-13 22:35pm
v3
Comments
CHill60 30-May-13 4:38am    
How about If RemainingTime.Minutes < 1 And RemaningTime.Minutes > 0 Then
Akinmade Bond 30-May-13 8:13am    
The problem is that If RemainingTime.Minutes < 1 will always evaluate to true when the time is less than a minute and hence, a the function RaiseEvent OnAlert("1 minute left"); will run.

To stop that from happening, change that line to If RemainingTime.Minutes = 1

1 solution

VB
Private Sub TimerTick(ByVal sender As Object, ByVal e As EventArgs) Handles myTimer.Tick
            If alarmTime < Date.Now Then
            myTimer.Stop()
            RaiseEvent TimerComplete(&quot;Your time is up&quot;)
        Else
            RemainingTime = alarmTime.Subtract(Date.Now)

            RaiseEvent Elapsed(RemainingTime)
        End If
        If RemainingTime.Minutes = 1 Then
            RaiseEvent OnAlert("1 minute left")
        End If
    End Sub

set timer control's Interval for 60000, so it will fire tick event on every one minute

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900