I now this is simple but how do you make the timer countdown from... 5 minutes and show how much time is left in label1? Also, is there command that will exit the application (for ex.) when the count = 0?
TIA
Printable View
I now this is simple but how do you make the timer countdown from... 5 minutes and show how much time is left in label1? Also, is there command that will exit the application (for ex.) when the count = 0?
TIA
For exiting your application use this code .
VB Code:
Application.Exit()
No, i mean when the clock is at 0
Hmm , you've just said :Quote:
Originally posted by james14
No, i mean when the clock is at 0
anyways , when the clock is at 0 what do you want to do ? exit the timer ? or the application ? or if you have loop and you want to terminate that loop ?:rolleyes:Quote:
Also, is there command that will exit the application (for ex.) when the count = 0?
heh sorry, what i want it to do is when the clock hits 0 (time runs out) the application will exit itself because it ran out of time.
Ok . This counts 10 sec before it exits itself .
VB Code:
Dim sec As Integer = 10 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick sec -= 1 If sec > 0 Then Label1.Text = sec Else Timer1.Enabled = False Application.Exit() End If End Sub
Note , Leave the timer set to 1000 for interval and enabled property to false .
How often do you want the timer to tick down? Every second? Every Minute?
Nevermind Pirate's got your back.
Thanks guys!
This is good. but how can i got problem using my method.Quote:
Originally posted by Pirate
Ok . This counts 10 sec before it exits itself .
VB Code:
Dim sec As Integer = 10 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick sec -= 1 If sec > 0 Then Label1.Text = sec Else Timer1.Enabled = False Application.Exit() End If End Sub
I tried Dim sec As Integer = NumericUpDown1.Text but it seems to have problem and prompt me
An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication2.exe
Additional information: Object reference not set to an instance of an object.
but all those are in the NumericUpDown box are numbers? Why?? Please help :)
This is old thread so I'm not gonna read it over , with Numeric controls use
NumericUpDown1.Value (not text) .
This would save you the hastle of casting . I don't see a problem here though .
It give me the same error too. Why? Or should I use a differnent method but not numericupdown box?Quote:
Originally posted by Pirate
This is old thread so I'm not gonna read it over , with Numeric controls use
NumericUpDown1.Value (not text) .
This would save you the hastle of casting . I don't see a problem here though .
Please help me? This maybe simple but I just can't understand both method it doesn't work for me? Or no one understand my question?
Look carefully at where you are getting that error message. Have you declared Sec with too narrow a scope?Quote:
Originally posted by private1337
This is good. but how can i got problem using my method.
I tried Dim sec As Integer = NumericUpDown1.Text but it seems to have problem and prompt me
An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication2.exe
Additional information: Object reference not set to an instance of an object.
but all those are in the NumericUpDown box are numbers? Why?? Please help :)
What u mean? I tried put Dim sec As Integer = NumericUpDown1.Text or Dim sec As Integer = NumericUpDown1.Value on top of the form codings andQuote:
Originally posted by taxes
Look carefully at where you are getting that error message. Have you declared Sec with too narrow a scope?
Dim secs As Integer = NumericUpDown4.Value
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer10.Tick
secs -= 1
If secs > 0 Then
lbl.Text = secs
Else
Timer1.Enabled = False
End If
End Sub
I just don't understand why there is an error? Or I put at the wrong place?
Hi,
Right. Your scope is OK but you have to assign the values after the NumericUpDown value has been selected. Presumably the NumericUpDown is contained in the same form so you need
VB Code:
Private Sub NumericUpDown4_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged secs =CInt(NumericUpDown4.Value) End Sub
However, as you are using several NumericUpDown controls, you probably need to include that code in the click event of a Proceed button.
So sad to say it give me the same error too? Got other way?
Post a sample of your proj .
Hi,
I hope you are not confusing "sec" with "secs". If you are using both make sure botah are correctly instanced. Exactly which line gives you the error?
Hi, I have not mistake the sec and secs. I tried try in new form but it also doesn't work.. My code is
Dim sec As Integer = NumericUpDown1.Value
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
sec -= 1
If sec > 0 Then
Label1.Text = sec
Else
Timer1.Enabled = False
Application.Exit()
End If
End Sub
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
sec = CInt(NumericUpDown1.Value)
End Sub
End Class
The error is Dim sec As Integer = NumericUpDown1.Value
Hi,
Please read the responses you get carefully.
You have already been told that
Dim sec As Integer =NumericUpDown1.Value
is not acceptable for two reasons;
1. It should be simply Dim Sec As Integer
2. Even if you do try to set it a value at that time it should be
Dim sec As Integer = CInt(NumericUpDown1.Value)
The intellisense tries to tell you just that!
It solve the problem.. How stupid can I be :( Thanks anyway..Quote:
Originally posted by taxes
Hi,
Please read the responses you get carefully.
You have already been told that
Dim sec As Integer =NumericUpDown1.Value
is not acceptable for two reasons;
1. It should be simply Dim Sec As Integer
2. Even if you do try to set it a value at that time it should be
Dim sec As Integer = CInt(NumericUpDown1.Value)
The intellisense tries to tell you just that!
Hi,
We got there in the end. Best of luck.
Thanks taxes.. u r the Timer pro :thumb: