| | |
Countdown Timer
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 3
Reputation:
Solved Threads: 0
I am currently making a timer for a school project. Im a little new to VB.net and having a few problems getting the timer to work.
When the countdown timer gets to 0 the "-" sign appears in the wrong place. As in i get 0:-1
I would also like the text in the timer to turn red when it enters negative numbers. (Maybe Flash, but i guess that is very complicated).
Anyway here is my current code:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim TargetTime As System.DateTime
Dim willy As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
willy = TextBox1.Text
If Timer1.Enabled Then
Timer1.Stop()
Else
TargetTime = Now.AddMinutes(willy)
Timer1.Start()
End If
Catch ex As Exception
MsgBox("No Time Set")
End Try
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim Diff As TimeSpan = TargetTime.Subtract(Now)
Label1.Text = Diff.Minutes & ":" & Diff.Seconds
End Sub
When the countdown timer gets to 0 the "-" sign appears in the wrong place. As in i get 0:-1
I would also like the text in the timer to turn red when it enters negative numbers. (Maybe Flash, but i guess that is very complicated).
Anyway here is my current code:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim TargetTime As System.DateTime
Dim willy As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
willy = TextBox1.Text
If Timer1.Enabled Then
Timer1.Stop()
Else
TargetTime = Now.AddMinutes(willy)
Timer1.Start()
End If
Catch ex As Exception
MsgBox("No Time Set")
End Try
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim Diff As TimeSpan = TargetTime.Subtract(Now)
Label1.Text = Diff.Minutes & ":" & Diff.Seconds
End Sub
•
•
Join Date: Dec 2002
Posts: 461
Reputation:
Solved Threads: 56
Try this:
VB.NET Syntax (Toggle Plain Text)
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim Diff As TimeSpan = TargetTime.Subtract(Now) If Diff.Seconds < 0 Then Label1.Text = "-" & Format(Diff.Minutes, "#0") & ":" & Format(System.Math.Abs(Diff.Seconds), "00") Else Label1.Text = Format(Diff.Minutes, "#0") & ":" & Format(System.Math.Abs(Diff.Seconds), "00") End If End Sub
•
•
Join Date: Dec 2002
Posts: 461
Reputation:
Solved Threads: 56
Try this:
Sorry it took so long in replying.
VB.NET Syntax (Toggle Plain Text)
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim Diff As TimeSpan = TargetTime.Subtract(Now) If Diff.Seconds < 0 And Diff.Minutes >= 0 Then Label1.Text = "-" & Format(Diff.Minutes, "#0") & ":" & Format(System.Math.Abs(Diff.Seconds), "00") Else Label1.Text = Format(Diff.Minutes, "#0") & ":" & Format(System.Math.Abs(Diff.Seconds), "00") End If End Sub
![]() |
Similar Threads
- timer in VB6 (Visual Basic 4 / 5 / 6)
- Tkinter Countdown Timer problems. (Python)
- Pause/Restart Countdown Timer Question (VB.NET)
- timer countdown help (Visual Basic 4 / 5 / 6)
- Timer Countdown (C++)
- Countdown (Java)
Other Threads in the VB.NET Forum
- Previous Thread: Migrate VB6 codes to VB2005
- Next Thread: VB.Net
| Thread Tools | Search this Thread |
"crystal .net .net2005 .net2008 2008 access add advanced application array assignment basic beginner box browser button buttons click code combo convert cpu cuesent data database datagrid datagridview datetimepicker designer dissertation dissertations dissertationthesis dissertationtopic dosconsolevb.net editvb.net employees excel exists firewall forms html image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity open pdf picturebox2 port print printpreview record regex reports" reuse right-to-left save savedialog search serial settings socket sqldatbase sqlserver storedprocedure string temp textbox timer transparency txttoxmlconverter useraccounts usercontol usercontrol vb vb.net vb.nettoolboxvisualbasic2008sidebar vba vbnet vista visual visualbasic.net visualstudio.net web wpf wrapingcode xml





