How to show only one messagebox under timer event

Ok i have a textbox a timer.
If textbox.text = My.Computer.Clock.LocalTime.Date

then a message box should pop up "today is your day"

After the first messagebox has been shown it should stop
but it repeats itself coz i put it under timer_tick event
I want it under timer event but i want the message box to show only 1 time

this the code i input but couldnt work:

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick

        If TextBox1.Text = My.Computer.Clock.LocalTime.Date Then
            MessageBox.Show("today is your day")
            Timer2.Stop()
        End If

    End Sub

Any way to make it work




Answer this question

How to show only one messagebox under timer event

  • Perry Bynum

    Move the Timer.Stop() command to before your message box command.
  • Ravi Nidhonkar

    On the old vb6 you should set the Interval property to 0 , but I'm unsure if this is correct in vb.net. Try and good luck!

    Timer2.Interval=0



  • AndyHopcraft

    Try to invoke the Stop method of the Timer, here is the example:


    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If TextBox1.Text = My.Computer.Clock.LocalTime.Date Then
            MessageBox.Show("today is your day")
        
            Dim mi As MethodInvoker = New MethodInvoker(AddressOf Timer2.Stop)
            Me.Invoke( mi )
        End If
    End Sub

     



  • How to show only one messagebox under timer event