2 Replies - 1797 Views - Last Post: 10 August 2009 - 11:07 PM Rate Topic: -----

#1 core2kid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-August 09

Timer program in VB Express 2008

Posted 05 August 2009 - 03:09 PM

I created a countdown timer for a entered time. I wanted, once the timer is completed, a messagebox to pop up stating that the timer has completed (bolded below) How do I do this properly? Right now the message box keeps popping up and doesn't stop.

Private Sub tmrwait_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrwait.Tick
		Dim remaining As TimeSpan = m_StopTime.Subtract(Now)
		remaining = New TimeSpan(remaining.Hours, remaining.Minutes, remaining.Seconds)
		If remaining.TotalSeconds < 0 Then remaining = TimeSpan.Zero
		lblRemaining.Text = remaining.ToString
		If remaining.TotalSeconds <= 0 Then
			[b]MsgBox("Times Up!")[/b]
			tmrwait.Enabled = False
		End If
	End Sub


This post has been edited by AdamSpeight2008: 05 August 2009 - 03:36 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Timer program in VB Express 2008

#2 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Timer program in VB Express 2008

Posted 05 August 2009 - 03:28 PM

I would suggest not using legacy functions from VB6, like MsgBox, use the VB.NET equivalent...MessageBox.Show("Time's up!")

This post has been edited by Locke: 05 August 2009 - 03:28 PM

Was This Post Helpful? 0
  • +
  • -

#3 piman314  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 169
  • Joined: 07-August 09

Re: Timer program in VB Express 2008

Posted 10 August 2009 - 11:07 PM

i would suggest switching the two lines inside the if statement.
tmrwait.Enabled = false
MessageBox.Show("Time's Up!")


creating a messagebox halts the program execution until it is closed.
because the tmrwait.Tick event is handled during the message loop for the main window, it will exit the event handler if it takes too long and will continue to the next loop, so the line to disable the timer is never called.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1