|
-
Apr 21st, 2003, 07:26 PM
#1
Thread Starter
Addicted Member
Timer
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
-
Apr 21st, 2003, 07:47 PM
#2
Sleep mode
For exiting your application use this code .
-
Apr 21st, 2003, 07:56 PM
#3
Thread Starter
Addicted Member
No, i mean when the clock is at 0
-
Apr 21st, 2003, 08:03 PM
#4
Sleep mode
Originally posted by james14
No, i mean when the clock is at 0
Hmm , you've just said :
Also, is there command that will exit the application (for ex.) when the count = 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 ?
-
Apr 21st, 2003, 08:11 PM
#5
Thread Starter
Addicted Member
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.
-
Apr 21st, 2003, 08:16 PM
#6
Sleep mode
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
-
Apr 21st, 2003, 08:18 PM
#7
Sleep mode
Note , Leave the timer set to 1000 for interval and enabled property to false .
-
Apr 21st, 2003, 08:21 PM
#8
How often do you want the timer to tick down? Every second? Every Minute?
Nevermind Pirate's got your back.
-
Apr 21st, 2003, 10:10 PM
#9
Thread Starter
Addicted Member
-
Nov 15th, 2004, 09:48 AM
#10
Lively Member
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
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
The Power Of Sharing Knowledge!
-
Nov 15th, 2004, 11:22 AM
#11
Sleep mode
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 .
-
Nov 15th, 2004, 12:22 PM
#12
Lively Member
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 .
It give me the same error too. Why? Or should I use a differnent method but not numericupdown box?
The Power Of Sharing Knowledge!
-
Nov 17th, 2004, 09:57 AM
#13
Lively Member
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?
The Power Of Sharing Knowledge!
-
Nov 17th, 2004, 12:35 PM
#14
PowerPoster
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
Look carefully at where you are getting that error message. Have you declared Sec with too narrow a scope?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 18th, 2004, 03:22 AM
#15
Lively Member
Originally posted by taxes
Look carefully at where you are getting that error message. Have you declared Sec with too narrow a scope?
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 and
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?
The Power Of Sharing Knowledge!
-
Nov 18th, 2004, 06:37 AM
#16
PowerPoster
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.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 18th, 2004, 11:29 AM
#17
Lively Member
So sad to say it give me the same error too? Got other way?
The Power Of Sharing Knowledge!
-
Nov 18th, 2004, 12:26 PM
#18
Sleep mode
Post a sample of your proj .
-
Nov 18th, 2004, 12:33 PM
#19
PowerPoster
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?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 19th, 2004, 01:38 AM
#20
Lively Member
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
The Power Of Sharing Knowledge!
-
Nov 19th, 2004, 05:43 AM
#21
PowerPoster
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!
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 19th, 2004, 10:49 AM
#22
Lively Member
[ResolveD]
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!
It solve the problem.. How stupid can I be Thanks anyway..
The Power Of Sharing Knowledge!
-
Nov 19th, 2004, 12:52 PM
#23
PowerPoster
Hi,
We got there in the end. Best of luck.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 20th, 2004, 02:42 AM
#24
Lively Member
Thanks taxes.. u r the Timer pro
The Power Of Sharing Knowledge!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|