•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 456,507 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,663 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 1227 | Replies: 2
![]() |
•
•
Join Date: Sep 2007
Posts: 35
Reputation:
Rep Power: 2
Solved Threads: 1
Hi, I'm getting quite good with vb.net now and have created quite a few good programs but I'm having trouble with something that seems simple but i cant figure out whats wrong, if anybody can help me with the following code it would be very appreciated.
What I'm trying to do is create a timer where you put in the time (in seconds) into textbox1 and when you click button2, label2.Text keeps decreasing by 1 each time timer2 has an interval, but for some reason, when i click start, it only goes down 1 and then just stops on that number.
Please help me solve this, thanks.
What I'm trying to do is create a timer where you put in the time (in seconds) into textbox1 and when you click button2, label2.Text keeps decreasing by 1 each time timer2 has an interval, but for some reason, when i click start, it only goes down 1 and then just stops on that number.
Dim myTime As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "Start" Then
myTime = TextBox1.Text
Label2.Text = myTime
Timer2.Start()
Button1.Text = "Stop"
Else
If Button1.Text = "Stop" Then
Timer2.Stop()
Button1.Text = "Start"
End If
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Label2.Text = myTime - 1
End Sub
Private Sub Form8_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer2.Enabled = True
Timer2.Stop()
End SubPlease help me solve this, thanks.
•
•
Join Date: Sep 2007
Posts: 35
Reputation:
Rep Power: 2
Solved Threads: 1
I changed
To
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick Label2.Text = myTime - 1 End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick Label2.Text = myTime - 1 myTime = Label2.Text End Sub
•
•
Join Date: Sep 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
Since you want something to continue operating, i would switch from an if statement to some kind of while loop, so that as long as Stop isn't pressed, it will continue to operate. Also, you are consistently subtracting 1 from a fixed value (mytime) when in fact one of the numbers should be updating with the timer.
Summary:
Use a while loop so your countdown timer continues to operate until a given condition is met, say, when it reaches zero or something.
Check the math so that you aren't subtracting 1 from an unchanging value.
Hope this helps!
Halbo
Summary:
Use a while loop so your countdown timer continues to operate until a given condition is met, say, when it reaches zero or something.
Check the math so that you aren't subtracting 1 from an unchanging value.
Hope this helps!
Halbo
![]() |
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- timer in VB6 (Visual Basic 4 / 5 / 6)
- Tkinter Countdown Timer problems. (Python)
- Pause/Restart Countdown Timer Question (VB.NET)
- Countdown Timer (VB.NET)
- timer countdown help (Visual Basic 4 / 5 / 6)
- Timer Countdown (C++)
- Countdown (Java)
Other Threads in the VB.NET Forum
- Previous Thread: textbox.text not showing up
- Next Thread: auto send


Linear Mode