countdown timervb,net timer
Page 1 of 1
12 Replies - 4068 Views - Last Post: 18 February 2010 - 10:23 AM
#1
countdown timer
Posted 18 February 2010 - 06:11 AM
The application simply has one button on it, when that button is selected a timer in the back ground will be triggered (for example 30 mins). After the timer is up I would like it to display a message.
Thank you in advance for your help.
Mary
Replies To: countdown timer
#2
Re: countdown timer
Posted 18 February 2010 - 06:20 AM
[rules][/rules]
Secondly I recommend that you do a quick search.
I will give you no code but I will walk you through what you have to do...
- Firstly you need a timer that is set to a ceartin time to tick on
- then everytime it ticks it needs to subtract that value from
- a publicly declared integer
- when that integer reaches 0 it...
- tells you that it has reached 0
#3
Re: countdown timer
Posted 18 February 2010 - 07:30 AM
'Start' is not a member of 'System.Windows.Forms.Timer'.
Public Class HomePage
Dim sec As Integer
Private Sub Form1_Load()
Timer.Start()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Startbut.Click
MsgBox("zero")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
lblClock.Text = TimeOfDay
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
Private Sub Message_ParentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Message.ParentChanged
End Sub
Private Sub lblClock_ParentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblClock.ParentChanged
End Sub
Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Startbut.Text = Startbut.Text - 1
If Startbut.Text = 0 Then
Timer1.Stop()
Startbut.Text = "you have been out for 1 hour"
Startbut.Enabled = True
End If
End Sub
End Class
#4
Re: countdown timer
Posted 18 February 2010 - 07:56 AM
I think you should name it:
Private Sub Form1_Load() Timer1.Start() ' ore you set it also as [b]Timer1.Enabled=true[/b] End Sub
This post has been edited by Luc001: 18 February 2010 - 08:24 AM
#5
Re: countdown timer
Posted 18 February 2010 - 08:01 AM
timer.start()
Since start is not a shared member of the Timer class you should reference your object
timer1.start()
Also it is good practice to have Option Explicit and Strict ON and Option Infer OFF. I'm at work and can't explain what they do. It's worth a google though.
#6 Guest_mary4321*
Re: countdown timer
Posted 18 February 2010 - 08:20 AM
Mary
#7
Re: countdown timer
Posted 18 February 2010 - 08:32 AM
#8
Re: countdown timer
Posted 18 February 2010 - 09:03 AM
After a closer look at your code found that they're several problems.
Here's an explanation:
Public Class Form1
Dim sec As Integer
Dim timer As New System.Windows.Forms.Timer ' declare your timer like this
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click
MsgBox("zero")
End Sub
Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
lblClock.Text = TimeOfDay
stbutt.Text = stbutt.Text - 1
If stbutt.Text = 0 Then
timer.Stop()
stbutt.Text = "you have been out for 1 hour"
' it doesn't need to enable a button to do something
' you need a performclick for that
stbutt.PerformClick()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' you need also that the timer gets activated
' Addhandler and adressof
AddHandler timer.Tick, AddressOf timer_Tick
timer.Enabled = True ' to start your timer
timer.Interval = 1000 ' to set the interval
stbutt.Text = "60"
lblClock.Text = TimeOfDay
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click
MsgBox("zero")
End Sub
End Class
It should work now.
This post has been edited by Luc001: 18 February 2010 - 09:04 AM
#9
Re: countdown timer
Posted 18 February 2010 - 09:18 AM
#10
Re: countdown timer
Posted 18 February 2010 - 09:25 AM
That's true and the more easy way, but the goal was do work with the system.windows.Forms Timer.
#11
Re: countdown timer
Posted 18 February 2010 - 09:31 AM
#12 Guest_mary4321*
Re: countdown timer
Posted 18 February 2010 - 09:36 AM
Luc001, on 18 February 2010 - 08:03 AM, said:
After a closer look at your code found that they're several problems.
Here's an explanation:
Public Class Form1
Dim sec As Integer
Dim timer As New System.Windows.Forms.Timer ' declare your timer like this
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click
MsgBox("zero")
End Sub
Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
lblClock.Text = TimeOfDay
stbutt.Text = stbutt.Text - 1
If stbutt.Text = 0 Then
timer.Stop()
stbutt.Text = "you have been out for 1 hour"
' it doesn't need to enable a button to do something
' you need a performclick for that
stbutt.PerformClick()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' you need also that the timer gets activated
' Addhandler and adressof
AddHandler timer.Tick, AddressOf timer_Tick
timer.Enabled = True ' to start your timer
timer.Interval = 1000 ' to set the interval
stbutt.Text = "60"
lblClock.Text = TimeOfDay
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click
MsgBox("zero")
End Sub
End Class
It should work now.
Hi there, thanks a million for havin a look at my code. I am now getting an error message saying that "performclick" is not a member.
Mary
#13
Re: countdown timer
Posted 18 February 2010 - 10:23 AM
mary4321, on 18 February 2010 - 08:36 AM, said:
Luc001, on 18 February 2010 - 08:03 AM, said:
After a closer look at your code found that they're several problems.
Here's an explanation:
Public Class Form1
Dim sec As Integer
Dim timer As New System.Windows.Forms.Timer ' declare your timer like this
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click
MsgBox("zero")
End Sub
Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
lblClock.Text = TimeOfDay
stbutt.Text = stbutt.Text - 1
If stbutt.Text = 0 Then
timer.Stop()
stbutt.Text = "you have been out for 1 hour"
' it doesn't need to enable a button to do something
' you need a performclick for that
stbutt.PerformClick()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' you need also that the timer gets activated
' Addhandler and adressof
AddHandler timer.Tick, AddressOf timer_Tick
timer.Enabled = True ' to start your timer
timer.Interval = 1000 ' to set the interval
stbutt.Text = "60"
lblClock.Text = TimeOfDay
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click
MsgBox("zero")
End Sub
End Class
It should work now.
Hi there, thanks a million for havin a look at my code. I am now getting an error message saying that "performclick" is not a member.
Mary
Hi Mary,
I tested my code before posting and everything worked.
What did you do?
This post has been edited by Luc001: 18 February 2010 - 10:30 AM
|
|

New Topic/Question
Reply




MultiQuote




|