jxharding
asked on
timer displayed on label must count backwards
hi, i have a form with a timer and a label
the idea is that the text of the table is set to 00:15:00
and then it counts backwards to 0, and each second , it counts down.
the problem is with the string manipulation
i use vb6's left function, and i get the string to not display AM at the end because it would have displayed
12:14:59AM
now i need to remove the first 3 char's as well so that it only shows 14:59 and counts from there
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
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
Label1.Text = Microsoft.VisualBasic.Left (DateAdd(" s", -1, Label1.Text), 8)
Label1.Text = Microsoft.VisualBasic.Righ t(Label1.T ext, 5)
End Sub
this current setup does not give a error but does not display it right because first i strip the last charaters off,
and then i still need the original value to calculate what the next value will be.
should i use a second timer? is there a way to use ms.vb.left & ms.vb.right right in one command?
thanks!
the idea is that the text of the table is set to 00:15:00
and then it counts backwards to 0, and each second , it counts down.
the problem is with the string manipulation
i use vb6's left function, and i get the string to not display AM at the end because it would have displayed
12:14:59AM
now i need to remove the first 3 char's as well so that it only shows 14:59 and counts from there
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
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
Label1.Text = Microsoft.VisualBasic.Left
Label1.Text = Microsoft.VisualBasic.Righ
End Sub
this current setup does not give a error but does not display it right because first i strip the last charaters off,
and then i still need the original value to calculate what the next value will be.
should i use a second timer? is there a way to use ms.vb.left & ms.vb.right right in one command?
thanks!
this should fix the problem
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = Convert.ToDateTime(textBox 1.Text).Ad dSeconds(- 1).ToLongT imeString( )
End Sub
assuming Label1 has some valid time string before running this code
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = Convert.ToDateTime(textBox
End Sub
assuming Label1 has some valid time string before running this code
ASKER
hi desp,
i tried both fixes ,and although they make perfect sense, i still get
12:14:59AM
on both
did your's display correctly?
i tried having the text on the label as
00:15:00
and 00:15
thanks!
i tried both fixes ,and although they make perfect sense, i still get
12:14:59AM
on both
did your's display correctly?
i tried having the text on the label as
00:15:00
and 00:15
thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
replace textbox1 by label1 ... in the previous comment
dim dt as DateTime = DateTime.Now
dt.AddSeconds(-1)
I think you will get rid of the string manipulation