I have written a program that functions similarly to a stopwatch.
When the user clicks the button, a label on the form starts counting. The
program, however, does not tick once a second. How can I fix this?
The following is the program. It assumes that the forms has a Button named
Button1, a Label named Label1 and a Timer named Timer1.
Dim sec, min As Double
Private Sub InitializeTimer()
' Run this procedure in an appropriate event.
' Set to 1 second.
Timer1.Interval = 1000
' Enable timer.
Timer1.Enabled = True
Button1.Text = "Enabled"
End Sub
Private Sub Timer1_Tick(ByVal Sender As Object, ByVal e As EventArgs)
Handles Timer1.Tick
' Set the caption to display the current value of sec
Label1.Text = min & ":" & sec
sec += 1
If sec = 60 Then
min += 1
sec = 0
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Button1.Text = "Stop" Then
Button1.Text = "Start"
Timer1.Enabled = False
Else
Button1.Text = "Stop"
Timer1.Enabled = True
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
sec = 0
min = 0
End Sub
Thanks in advance.
--
Xero http://www.chezjeff.net
My personal web portal 5 1527
add label1.refresh
Private Sub Timer1_Tick(ByVal Sender As Object, ByVal e As EventArgs)
Handles Timer1.Tick
' Set the caption to display the current value of sec
Label1.Text = min & ":" & sec
sec += 1
If sec = 60 Then
min += 1
sec = 0
End If
label1.refresh
End Sub
hth Peter
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> wrote in message
news:8C**********************************@microsof t.com... I have written a program that functions similarly to a stopwatch. When the user clicks the button, a label on the form starts counting. The program, however, does not tick once a second. How can I fix this?
The following is the program. It assumes that the forms has a Button named Button1, a Label named Label1 and a Timer named Timer1.
Dim sec, min As Double Private Sub InitializeTimer() ' Run this procedure in an appropriate event. ' Set to 1 second. Timer1.Interval = 1000 ' Enable timer. Timer1.Enabled = True Button1.Text = "Enabled" End Sub
Private Sub Timer1_Tick(ByVal Sender As Object, ByVal e As EventArgs) Handles Timer1.Tick ' Set the caption to display the current value of sec Label1.Text = min & ":" & sec sec += 1 If sec = 60 Then min += 1 sec = 0 End If End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Button1.Text = "Stop" Then Button1.Text = "Start" Timer1.Enabled = False Else Button1.Text = "Stop" Timer1.Enabled = True End If End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load sec = 0 min = 0 End Sub Thanks in advance. -- Xero
http://www.chezjeff.net My personal web portal
Jeff,
Did I not give you an example for this.
In that answer I said that a "timer" is not to measure time, however is an
alarm clock.
I gave you an example with the tickcount and gave you extra a link to the
timespan class because you have than a probably better showable span time.
I had a short discussion in that thread with Herfried, where he told how
you could use a timer. I asked him if they measure in Austria the time at
sport events (not setting the game time) with an alarm clock, and on that he
did not answer anymore.
Therefore why are you asking the same question again and are you using the
timer (an alarm clock) as a stopwatch?
Cor
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> I have written a program that functions similarly to a stopwatch. When the user clicks the button, a label on the form starts counting. The program, however, does not tick once a second. How can I fix this?
The following is the program. It assumes that the forms has a Button named Button1, a Label named Label1 and a Timer named Timer1.
Dim sec, min As Double Private Sub InitializeTimer() ' Run this procedure in an appropriate event. ' Set to 1 second. Timer1.Interval = 1000 ' Enable timer. Timer1.Enabled = True Button1.Text = "Enabled" End Sub
Private Sub Timer1_Tick(ByVal Sender As Object, ByVal e As EventArgs) Handles Timer1.Tick ' Set the caption to display the current value of sec Label1.Text = min & ":" & sec sec += 1 If sec = 60 Then min += 1 sec = 0 End If End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Button1.Text = "Stop" Then Button1.Text = "Start" Timer1.Enabled = False Else Button1.Text = "Stop" Timer1.Enabled = True End If End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load sec = 0 min = 0 End Sub Thanks in advance. -- Xero
http://www.chezjeff.net My personal web portal
Cor,
I have read the discussion between you and Herfried as well.
Herfried said that a Timer raises an event periodically. Therefore I thought
if I set the time interval to 1000 milliseconds (i.e. 1 second) and increase
the value of a label by 1, the program will function just like a stopwatch.
Perhaps I did not make myself clear enough. Actually I want that label
refreshes itself once a second. The code you sent to me seemed to be
displaying the total time elapsed only when the user does something (clicks a
button, type something or whatever) rather than refreshing itself
automatically.
Anyway I have achieved what I want. Thanks for discussing this problem with
me! :)
Jeff
"Cor Ligthert" wrote: Jeff,
Did I not give you an example for this.
In that answer I said that a "timer" is not to measure time, however is an alarm clock.
I gave you an example with the tickcount and gave you extra a link to the timespan class because you have than a probably better showable span time.
I had a short discussion in that thread with Herfried, where he told how you could use a timer. I asked him if they measure in Austria the time at sport events (not setting the game time) with an alarm clock, and on that he did not answer anymore.
Therefore why are you asking the same question again and are you using the timer (an alarm clock) as a stopwatch?
Cor
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )>
I have written a program that functions similarly to a stopwatch. When the user clicks the button, a label on the form starts counting. The program, however, does not tick once a second. How can I fix this?
The following is the program. It assumes that the forms has a Button named Button1, a Label named Label1 and a Timer named Timer1.
Dim sec, min As Double Private Sub InitializeTimer() ' Run this procedure in an appropriate event. ' Set to 1 second. Timer1.Interval = 1000 ' Enable timer. Timer1.Enabled = True Button1.Text = "Enabled" End Sub
Private Sub Timer1_Tick(ByVal Sender As Object, ByVal e As EventArgs) Handles Timer1.Tick ' Set the caption to display the current value of sec Label1.Text = min & ":" & sec sec += 1 If sec = 60 Then min += 1 sec = 0 End If End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Button1.Text = "Stop" Then Button1.Text = "Start" Timer1.Enabled = False Else Button1.Text = "Stop" Timer1.Enabled = True End If End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load sec = 0 min = 0 End Sub Thanks in advance. -- Xero
http://www.chezjeff.net My personal web portal
Cor,
I have read the discussion between you and Herfried as well.
Herfried said that a Timer raises an event periodically. Therefore I thought
if I set the time interval to 1000 milliseconds (i.e. 1 second) and increase
the value of a label by 1, the program will function just like a stopwatch.
Perhaps I did not make myself clear enough. Actually I want that label
refreshes itself once a second. The code you sent to me seemed to be
displaying the total time elapsed only when the user does something (clicks a
button, type something or whatever) rather than refreshing itself
automatically.
Anyway I have achieved what I want. Thanks for discussing this problem with
me! :)
Jeff
"Cor Ligthert" wrote: Jeff,
Did I not give you an example for this.
In that answer I said that a "timer" is not to measure time, however is an alarm clock.
I gave you an example with the tickcount and gave you extra a link to the timespan class because you have than a probably better showable span time.
I had a short discussion in that thread with Herfried, where he told how you could use a timer. I asked him if they measure in Austria the time at sport events (not setting the game time) with an alarm clock, and on that he did not answer anymore.
Therefore why are you asking the same question again and are you using the timer (an alarm clock) as a stopwatch?
Cor
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )>
I have written a program that functions similarly to a stopwatch. When the user clicks the button, a label on the form starts counting. The program, however, does not tick once a second. How can I fix this?
The following is the program. It assumes that the forms has a Button named Button1, a Label named Label1 and a Timer named Timer1.
Dim sec, min As Double Private Sub InitializeTimer() ' Run this procedure in an appropriate event. ' Set to 1 second. Timer1.Interval = 1000 ' Enable timer. Timer1.Enabled = True Button1.Text = "Enabled" End Sub
Private Sub Timer1_Tick(ByVal Sender As Object, ByVal e As EventArgs) Handles Timer1.Tick ' Set the caption to display the current value of sec Label1.Text = min & ":" & sec sec += 1 If sec = 60 Then min += 1 sec = 0 End If End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Button1.Text = "Stop" Then Button1.Text = "Start" Timer1.Enabled = False Else Button1.Text = "Stop" Timer1.Enabled = True End If End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load sec = 0 min = 0 End Sub Thanks in advance. -- Xero
http://www.chezjeff.net My personal web portal
Xero, I have read the discussion between you and Herfried as well.
Herfried said that a Timer raises an event periodically. Therefore I thought if I set the time interval to 1000 milliseconds (i.e. 1 second) and increase the value of a label by 1, the program will function just like a stopwatch.
Perhaps I did not make myself clear enough. Actually I want that label refreshes itself once a second. The code you sent to me seemed to be displaying the total time elapsed only when the user does something (clicks a button, type something or whatever) rather than refreshing itself automatically.
In my opinion is the difference between a clock and a stopwatch that a
stopwatch starts and stops with a buttonclick.
However have a lot of success with your alarmclock used as stopwatch, I am
glad you took this Herfried solution to measure the time.
I advised you to take the timespan or the environment tickcount. (While
there is an even more precise one however that takes API's.)
When you say that when Herfried find my advise not right and than take
automatic the method from Herfried without even to give a reaction, than I
keep that in mind of course for your next question.
When it was about to show a going clock *meanwhile* there are even samples
to show an analog clock. However that has nothing to do with measure time,
that is just showing.
Have a lot of success with your method advised by Herfried.
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bruce D |
last post by:
My program in connecting to a web site and I want to know how long it takes
to connect to this site. I'm assuming I need to use some sort of timer.
This is a console application. Here are the...
|
by: not_a_commie |
last post by:
So I have a motherboard with multiple CPU sockets. It seems that if I
create a StopWatch on one thread and then call the Elapsed member from
a different thread that sometimes I get a tick count...
|
by: =?Utf-8?B?UmFqYQ==?= |
last post by:
I am running a sample application that gives me performance time for each
action. I am using Stopwatch class (found in System.Diagnostics namespace in
..Net 2.0)
to get the Elapsed time. If I run...
|
by: PlusNet |
last post by:
Why doesn't the following work?
Dim MyStopwatch() as Stopwatch
...Later in the code
redim preserve MyStopwatch(10)
...Later in the code
MyStopwatch(1).start
|
by: phreaker |
last post by:
Hi,
I'm interested in the alternatives to debugging C# other than Visual
Studio .NET
I have a large multi-threaded application, and I find that the
debugger that comes with Visual Studio...
|
by: Firecore |
last post by:
Hello.
I am making a Stopwatch program in C.
Can anyone help?
Is it possible to make a timer(stopwatch) function in C?
|
by: reinhart |
last post by:
hi! Please somebody help me
I'm really a newbie for C++
I have a task to create stopwatch program using C++
What should I write at C++??
please help me !!!
|
by: kerplunkwhoops |
last post by:
Hello
I am wanting to use the high accuracy of System.Diagnostics.Stopwatch
to get the current time using GetTimeSpan.
Underneath, System.Diagnostics.Stopwatch.GetTimeStamp uses the win32
API...
|
by: stimpy_cm |
last post by:
Hi everyone, I’m not a programmer but have a little notion about how
things work. I recently downloaded an emulator for my calculator (Texas
Instruments Voyage 200), the program uses a library...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |