473,388 Members | 1,207 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

stopwatch function with button

for this start and stop should there on a button. but i don't want start and stop text on the button. let the button text bi button1 only when we press the button the timer should start on a lable and when we again press the button the timer should stop and the lable time should bi zero. and when we again press it should start .
does anybody know ......the function what we have to use for it..............
Dec 18 '12 #1
14 2688
Rabbit
12,516 Expert Mod 8TB
This is not a code writing service but if you post what you have along with a description of the problem and any error messages you get, we can help guide you to a solution.
Dec 18 '12 #2
Expand|Select|Wrap|Line Numbers
  1. If Button1.Text = "start" Then
  2.             Button1.Text = "start"
  3.             'startTime = DateTime.Now()
  4.             Timer1.Start()
  5.         ElseIf Button1.Text = "start" Then
  6.             Button1.Text = "start"
  7.             Timer1.Stop()
  8.             'endtime = DateTime.Now()
  9.             Timer1.Start()
  10.         End If

by this when i m cliking the button one more time the timer is not stoping and not going to zero position
Dec 19 '12 #3
Expand|Select|Wrap|Line Numbers
  1.  If j = 0 Then
  2.             Timer1.Enabled = True
  3.             Timer1.Start()
  4.             j = 1
  5.         Else
  6.             Timer1.Enabled = False
  7.             Timer1.Stop()
  8.             Label1.Text = "00:00:00"
  9.             j = 0
i got it but not exact
Dec 19 '12 #4
but it not starting from zero its starting from where it stopped.
anybody know how the time start from zero with the same button.
Dec 19 '12 #5
zmbd
5,501 Expert Mod 4TB
Your logic fails: Look at line 2 and line 5 of the code block in post #3.
Dec 19 '12 #6
Rabbit
12,516 Expert Mod 8TB
How you reset it will depend on which class you're using. There are many timer classes.
Dec 19 '12 #7
clases means you are talking aboout the time intervel period....... and also i want a message box to displayed in a particular time. like for every ten min message box should be displayed but it not comming on every then ten min as the min come to ten the message box is getting started may for every second mesage box is displaying am a freshier.... so plaease guide me ......
Dec 20 '12 #8
zmbd
5,501 Expert Mod 4TB
Doesn't matter what you do until you fix the logic block as I've indicated.
Dec 20 '12 #9
Rabbit
12,516 Expert Mod 8TB
@z, I believe their next code block fixes the original issue, albeit in an odd way.

@syed, I can't answer any of your questions until you answer my question in post #7 because a time interval period is not a class I've heard of nor can I find any such class for VB on the web. You must be using some other class that you need to tell us about.

Even if you answer that question, I have no idea what you said in the rest of your post. It is confusing and unclear.
Dec 20 '12 #10
Expand|Select|Wrap|Line Numbers
  1. 'Imports System.DateTime
  2.  
  3. Public Class Form1
  4.     'Dim startTime As DateTime
  5.     'Dim endtime As DateTime
  6.     Dim seconds, minutes, hours As Integer
  7.     Dim j As Integer = 0
  8.  
  9.     Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
  10.         'If (Timer1.Enabled) Then
  11.         '    Me.Text = "Click to Re-start"
  12.         '    Timer1.Stop()
  13.         'Else
  14.         '    startTime = DateTime.Now()
  15.         '    Me.Text = "Click to Stop"
  16.         '    Timer1.Start()
  17.         '   End If
  18.     End Sub
  19.  
  20.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  21.  
  22.         j = 0 'Then
  23.         'startTime = DateTime.Now()
  24.         'Timer1.Enabled = True
  25.         seconds = 0
  26.         minutes = 0
  27.         hours = 0
  28.  
  29.         Timer1.Start()
  30.         '    j = 1
  31.         'ElseIf j = 1 Then
  32.         '    Timer1.Stop()
  33.         '    Timer1.Enabled = False
  34.         '    j = 0
  35.         '    Label1.Text = "00:00:00"
  36.         'End If
  37.     End Sub
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  46.         'Dim span As TimeSpan = DateTime.Now.Subtract(startTime)
  47.         'Label1.Text = span.Minutes.ToString & ":" & _
  48.         'span.Seconds.ToString & "." & _
  49.         'span.Milliseconds.ToString & " "
  50.         If seconds = 60 Then
  51.             seconds = 0
  52.             minutes = minutes + 1
  53.         End If
  54.         If minutes = 3 Then
  55.             minutes = 0
  56.             hours = hours + 1
  57.         End If
  58.         If minutes = 1 Then
  59.             MessageBox.Show("hi")
  60.         Else
  61.             minutes = minutes + 1
  62.         End If
  63.  
  64.         seconds = seconds + 1
  65.         Label1.Text = Format(hours, "00") & "." & Format(minutes, "00") & "." & Format(seconds, "00")
  66.     End Sub
  67.  
  68. End Class
  69.  

see sir this is my all coding
Dec 20 '12 #11
LOL you guys are fighting a lost cause. Not much you can do without the correct info and you are right fix the logic try again post the next error. LOL
Dec 20 '12 #12
Rabbit
12,516 Expert Mod 8TB
I can't make heads or tails of your code. You've commented out almost everything. I don't think your code will do anything at all much less the behaviour you described.
Dec 20 '12 #13
zmbd
5,501 Expert Mod 4TB
Syed Hadi:
If Rabbit had not replied, I would have deleted this as a homework question.

As your postings have progressed, the entire thread continues to give me the impression that this is a homework question and as such we should stop here until you can provide an example that actually works without basic logical errors or jumbled up half code.

Your initial code had a fundamental logic error.
The second code doesn't handle that logic error.
The third code does little if anything as Rabbit has pointed out.

Therefore, I respectfully ask that you take a few deep breaths, regroup, and then take a very hard close look at your project.

1) Write out in a single paragraph the major goals that you want the program to accomplish. This should be in "plain English." Not that you have to use English, just that you should not use any pseudo code, jargon, or other short cuts.

2) In a single paragraph, for each of the major goals, detail the steps. These also should be in "plain English."

3) You need to do a logic chart for your program. I prefer the NS style ( nassi shneiderman diagram Google Search ) however any programing flow-charting method will work. This should flow naturally from your work in (1) and (2)

4) Using the flowchart write the major blocks of code and then fill in with your support code as needed.

5) Compile and fix compiler-time errors.

6) Execute the program

7) Then come back here with any further issues.
Dec 20 '12 #14
k
from next time ill
Dec 27 '12 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Patrick Marti | last post by:
Is it possible to call a function from a ImageButton wich I create at runtime? That would be really interesting Many thanks for any suggest. Greetings Patrick Marti
1
by: Nithya Venkatachalam | last post by:
Hi, onclicking a button, iam calling a function which loads some other page. so, it is calling onUnloadhandler. In this onunloadhandler, is there any way to find the name of that button?
8
by: dakman | last post by:
Recently, I have been needing to do this alot and I can never find a way around it, the main reason I want to do this is because for example in the application I am making right now, it creates a...
1
by: yaya coco | last post by:
I want to use button. My question is that How can use server side and client site event at the same time. That is: I want to use button : when The user click the button first of all, client...
5
by: Xero | last post by:
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...
3
by: eladla | last post by:
Hi all, I have a function in C++/CLI that calls a native C++ function. I want the C++/CLI function to measure the time between the call to the unmanaged function and the return to the managed...
5
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...
3
by: Jeff Jarrell | last post by:
I am unable to add up two timespans as created by the System.Diagnostics.Stopwatch class. Each stopwatch should be about two seconds and is appears ok, but when I try and add them up it goes to...
8
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?
4
by: TwoBit | last post by:
Hello Bytes, I am very new at using Microsoft Access and have just recently implicated it in recording productivity on outbound calls for my team. My team is in charge of making outbound calls...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.