Hey everyone, I guess a few of my colleagues in here knows that I really dont like timers!
I am trying to create a timer for a Chat Room that allowes users to Chat for a Certain Minutes. But I wanna create a simple timer that can be easy to use and to Calculate the time, using the CALCULATION Option in VBNET. Such as (* = / + -) ! And tell users how long time they have LEFT to chat. But with the StopWatch its almost impossible to use the Calculating Method because of the "Colon" : used between the values for separation. And its making it harder for me to Calculate how long TIME IS LEFT or TIME PASSED.. The (StopWatch) I am using is (12:00:00 and 000) 9 Characters Long! And comes with 2 Labels for it.
Example:
Label1 = 12:00:00 (Hours / Minutes / Seconds)
Label2 = 000 for (MiliSeconds)
But I need it more simple without the "HOURS" and "MILISECONDS", No Colon: between. A single POINT between is OK like "60.30" for 60 minutes and 30 Seconds.. And it should only count upto 999 Minutes, so it will be 999.99 and 5 Chars Long.
I need some help starting up with this, and hope I can get some help on here! Thanks a lot in advance!
Here is the Code I am using for the 9 Characters STOPWATCH:
I am trying to create a timer for a Chat Room that allowes users to Chat for a Certain Minutes. But I wanna create a simple timer that can be easy to use and to Calculate the time, using the CALCULATION Option in VBNET. Such as (* = / + -) ! And tell users how long time they have LEFT to chat. But with the StopWatch its almost impossible to use the Calculating Method because of the "Colon" : used between the values for separation. And its making it harder for me to Calculate how long TIME IS LEFT or TIME PASSED.. The (StopWatch) I am using is (12:00:00 and 000) 9 Characters Long! And comes with 2 Labels for it.
Example:
Label1 = 12:00:00 (Hours / Minutes / Seconds)
Label2 = 000 for (MiliSeconds)
But I need it more simple without the "HOURS" and "MILISECONDS", No Colon: between. A single POINT between is OK like "60.30" for 60 minutes and 30 Seconds.. And it should only count upto 999 Minutes, so it will be 999.99 and 5 Chars Long.
I need some help starting up with this, and hope I can get some help on here! Thanks a lot in advance!
Here is the Code I am using for the 9 Characters STOPWATCH:
Code:
Dim startTime As DateTime
Function extZero(ByVal binNum As String)
Dim ext As String = "0"
Dim HexToBin As String = ""
If binNum.Length < 2 Then
Dim k As Integer = 1
Dim len As Integer = 2 - (binNum.Length + 1)
For k = 1 To len
ext = ext & "0"
Next k
HexToBin = ext + binNum
ElseIf binNum.Length = 2 Then
HexToBin = binNum
End If
Return HexToBin
End Function
Private Sub Timer3_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Dim span As TimeSpan = DateTime.Now.Subtract(startTime)
LabelTime.Text = extZero(span.Hours.ToString) & ":" & extZero(span.Minutes.ToString) & ":" & _
extZero(span.Seconds.ToString)
LabelMilisecond.Text = span.Milliseconds
End Sub
Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Click
If (Timer3.Enabled) Then
Button24.Text = "Start"
Timer3.Stop()
Else
Button30.PerformClick()
startTime = DateTime.Now()
Button24.Text = "Stop"
Timer3.Start()
End If
End Sub