how to put a time counter in my vb.net project?
-
i am making a software "IQ TEST" for my thesis project... but my problem is i dont know how to put a timer in my module? can you pls tell me the codes for it??? thanks
Hi, Please try the following code snippet which uses a Timer Control (Timer1), one label (lblLogin) and two button (btnLogin and btnBreak). Drag and drop above mention .Net control and give name accordingly (as mentioned in the parenthesis) and paste the following code snippet: ------------------------------------------------------------------------- BEGIN CODE Public Class Form1 Dim tmr1 As Integer Dim timerString As String Dim seconds, minutes, hours As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.lbldate.Text = Format(Now(), "dddd, MMM dd yyyy") 'Me.btnLogin.Enabled = False Me.AcceptButton = btnLogin Me.Timer1.Start() ' End Sub Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick 'Me.lblLogin.Text = Format(Now(), "hh:mm:ss") 'tmr1 = tmr1 + 1 'timerString = tmr1 seconds += 1 If seconds = 60 Then minutes += 1 seconds = 0 End If If minutes = 60 Then hours += 1 minutes = 0 End If timerString = hours & ":" timerString = timerString & minutes & ":" timerString = timerString & seconds Me.lblLogin.Text = timerString End Sub Private Sub btnBreak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBreak.Click Me.Timer1.Stop() End Sub Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click Me.Timer1.Start() End Sub END CODE ------------------------------------------------------------------------- I hope this helps :).
Regards, John Adams ComponentOne LLC
-
Hi, Please try the following code snippet which uses a Timer Control (Timer1), one label (lblLogin) and two button (btnLogin and btnBreak). Drag and drop above mention .Net control and give name accordingly (as mentioned in the parenthesis) and paste the following code snippet: ------------------------------------------------------------------------- BEGIN CODE Public Class Form1 Dim tmr1 As Integer Dim timerString As String Dim seconds, minutes, hours As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.lbldate.Text = Format(Now(), "dddd, MMM dd yyyy") 'Me.btnLogin.Enabled = False Me.AcceptButton = btnLogin Me.Timer1.Start() ' End Sub Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick 'Me.lblLogin.Text = Format(Now(), "hh:mm:ss") 'tmr1 = tmr1 + 1 'timerString = tmr1 seconds += 1 If seconds = 60 Then minutes += 1 seconds = 0 End If If minutes = 60 Then hours += 1 minutes = 0 End If timerString = hours & ":" timerString = timerString & minutes & ":" timerString = timerString & seconds Me.lblLogin.Text = timerString End Sub Private Sub btnBreak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBreak.Click Me.Timer1.Stop() End Sub Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click Me.Timer1.Start() End Sub END CODE ------------------------------------------------------------------------- I hope this helps :).
Regards, John Adams ComponentOne LLC
thanks, but can this timer can stop in another form? for example, your timer starts at form1, the timer is only set in 60 minutes. When 60 min. is over and you are in the form3 already.. it will go automatically to the last form (form10 for example). is it possible?
-
thanks, but can this timer can stop in another form? for example, your timer starts at form1, the timer is only set in 60 minutes. When 60 min. is over and you are in the form3 already.. it will go automatically to the last form (form10 for example). is it possible?
-
Yes, of course. How it's done depends however very much on how you move from one form to another.
Despite everything, the person most likely to be fooling you next is yourself.