954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to create a stopwatch? Not using labels.

Hi, I was just wondering if there was anyway to create some sort of stopwatch, that doesnt include labels signifing, milli seconds etc?

Thanks

BleepyE
Junior Poster in Training
87 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

Welcome BleepyE.

Read the forum rules. You need to show effort, and what better way than posting the code that you have tried so far?

Homework policy

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 
private void frmCustomerDetails_Load(object sender, EventArgs e)
{

 lblTime.Text = DateTime.Now.ToLongTimeString();
            btnStopWatch.Enabled = false;
}



private void btnStopWatch_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            btnEnterRecords.Enabled = true;
            btnStopWatch.Enabled = false;
        }
Santyfurtado
Newbie Poster
1 post since Dec 2010
Reputation Points: 10
Solved Threads: 1
 

Welcmoe @Santyfurtado

Please read my previous post and Daniweb member rules .

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Sorry was on my phone when I created this thread.

Current code consists of adding 1 to a value of a label ever timer tick.
Pritty basic stuff.

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        timer1.start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Label1.Text = 10 Then
            Label2.Text += 1
            Label1.Text = 0
        Else
            Label1.Text += 1
        End If
    End Sub

  
End Class


Id really prefer a method of accuratly timing something, like a stopwatch, but not using labels.

Something that I would develop into a application that recorded times.

Thanks

BleepyE
Junior Poster in Training
87 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

@Santyfurtado

I do believe that code is C not VB.net

Thanks anyway

BleepyE
Junior Poster in Training
87 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

Surely if you don't want to use labels you could use a public variable;

Public Class Form1

	Public TimerValue as Integer
	
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		timer1.start()
	End Sub
	
	Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
		'Runs every 1 miliseconds, 1000 times a second dependant on CPU lapse time
		TimerValue = TimerValue + 1
	End Sub
	
	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
		timer1.stop()
		ShowSeconds()
	End Sub
	
	Public function ShowSeconds()
		label1.text = (TimerValue / 1000)
	end function
End Class
anqe_tb
Newbie Poster
7 posts since Dec 2010
Reputation Points: 10
Solved Threads: 3
 

@ange_tb

Thanks, im getting there.


I found this on the web which is closer to what im after.

Public Class Form1
    Dim Time As New DateTime 'This will just create a DateTime Element

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Timer1.Enabled = True Then
            Timer1.Stop() 'Yea....Stops if it was started
        Else
            Time = DateTime.Now 'This will change 'Time' to the current time
            Timer1.Start() 'Starts the Timer.

        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim Difference As TimeSpan = DateTime.Now.Subtract(Time) 'This is really what the entire application runs off of. It will take 'Time' Witch is set to the time that the button was clicked at and subtract it from the current time
        Label1.Text = Difference.Days.ToString & ":" & Difference.Hours.ToString & ":" & Difference.Minutes.ToString & ":" & Difference.Seconds.ToString & "." & Difference.Milliseconds.ToString 'This line...Will just make it so we can read it. Days:Hours:Minutes:Seconds.Milliseconds 
    End Sub
End Class


Its quite nice

Thanks to reconrey1292

BleepyE
Junior Poster in Training
87 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You