+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Tutorial - A Simple Stropwatch!

  1. #1
    travy92's Avatar
    travy92 is offline Learning Programmer
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    76
    Rep Power
    17

    Post Tutorial - A Simple Stopwatch!

    INTRO:

    In this tutorial we'll be learning how to make a simple stopwatch.

    -------------------------------------------------------------------

    GUI (LAYOUT):

    Here is my GUI:



    ------------------------------------------------------------------

    WHAT YOU NEED:

    2 Labels with:

    #1 Label:
    Name: Label1
    Caption: SIMPLE STOPWATCH

    #2 Label:
    Name: Label2
    Caption: 0.00

    4 Command Buttons with:

    #1 Command Button:
    Name: Command1
    Caption: START

    #2 Command Button:
    Name: Command2
    Caption: STOP

    #3 Command Button:
    Name: Command3
    Caption: RESET

    #4 Command Button:
    Name: Command4
    Caption: QUIT

    1 Timer with:
    Name: Timer1
    Caption: (None)
    Interval: 1

    ----------------------------------------------------------------

    CODE:

    Private Sub Command1_Click()
    Timer1.Enabled = True
    End Sub

    Private Sub Command2_Click()
    Timer1.Enabled = False
    End Sub

    Private Sub Command3_Click()
    Label2.Caption = "0.00"
    End Sub

    Private Sub Command4_Click()
    End
    End Sub

    Private Sub Timer1_Timer()
    Label2.Caption = Format(Val(Label2.Caption) + 0.01, _
    "fixed")
    End Sub
    The code explanation follows.

    ----------------------------------------------------------------

    CODE EXPLANATION:

    Private Sub Command1_Click()
    Timer1.Enabled = True
    End Sub
    Enables the timer (Makes it start).

    ----------------------------------------------------------------

    Private Sub Command2_Click()
    Timer1.Enabled = False
    End Sub
    Disables the timer (Stops it).

    ----------------------------------------------------------------

    Private Sub Command3_Click()
    Label2.Caption = "0.00"
    End Sub
    This code tells VB that when Command3 (RESET) is clicked, change the caption of Label2 to 0.00.

    ----------------------------------------------------------------

    Private Sub Command4_Click()
    End
    End Sub
    Ends (Closes) the program.

    ----------------------------------------------------------------

    Private Sub Timer1_Timer()
    Label2.Caption = Format(Val(Label2.Caption) + 0.01, _
    "fixed")
    End Sub
    This means make Label2's caption change by adding +0.01 to it every millisecond.

    ----------------------------------------------------------------

    Thank you for reading this tutorial.

    Thanks to Tcm9669/TheComputerMaster for the Screenshot program.

    Made by me, Travy92.

    SAMPLES:
    Attached Files Attached Files
    Last edited by Jordan; 09-18-2007 at 05:33 AM.
    C:\Users\Travis\Desktop\Image Converter\Knight1.bmp

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    khaabas is offline Newbie
    Join Date
    Sep 2007
    Posts
    4
    Rep Power
    0
    code timer not correct
    appear message run time error 424
    how i can fix this problem
    thanx man

  4. #3
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    That is because you made the Label name as Label1, instead of Label2! Rename Label to Label2 and it should work

  5. #4
    duffbuffvick is offline Newbie
    Join Date
    Feb 2008
    Posts
    1
    Rep Power
    0
    Thank you for posting. Amazing tutorial.

  6. #5
    wazofski is offline Programmer
    Join Date
    Feb 2008
    Posts
    126
    Rep Power
    0
    Doesn't work, it only adds +0,01 once and then it does nothing, think you gotta remake your code.

  7. #6
    travy92's Avatar
    travy92 is offline Learning Programmer
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    76
    Rep Power
    17
    Quote Originally Posted by wazofski View Post
    Doesn't work, it only adds +0,01 once and then it does nothing, think you gotta remake your code.
    Umm, i think you've used a TextBox.. Not a Label.
    C:\Users\Travis\Desktop\Image Converter\Knight1.bmp

  8. #7
    wazofski is offline Programmer
    Join Date
    Feb 2008
    Posts
    126
    Rep Power
    0
    No i did use a label

  9. #8
    obliviongoty is offline Newbie
    Join Date
    Jun 2008
    Posts
    1
    Rep Power
    0

    Re: Tutorial - A Simple Stropwatch!

    I made some improvements to the code and renamed the objects, all credit to travy92 though. Now there is one button for start and stop and a minutes label too, the seconds reset to 0.00 when a minute ticks over. The reset button will also not be a problem if it is used while the counter is still going.

    To make this work you will need to rename the objects to the appropriate names used in this code and add a Label called lblTimeMins

    Code:
    Private Sub cmdExit_Click()
        End
    End Sub
    
    
    
    Private Sub cmdReset_Click()
        If tmrStopWatch.Enabled = True Then
            tmrStopWatch.Enabled = False
            lblTimeMS.Caption = "0.00"
            lblTimeMins.Caption = "0"
        Else
            lblTimeMS.Caption = "0.00"
            lblTimeMins.Caption = "0"
        End If
    End Sub
    
    
    
    Private Sub cmdStopStart_Click()
        If tmrStopWatch.Enabled = False Then
            tmrStopWatch.Enabled = True
        Else
            tmrStopWatch.Enabled = False
        End If
    End Sub
    
    
    
    Private Sub Form_Load()
        tmrStopWatch.Enabled = False
    End Sub
    
    
    
    Private Sub tmrStopWatch_Timer()
        lblTimeMS.Caption = Format(Val(lblTimeMS.Caption) + 0.01, "fixed")
        If lblTimeMS.Caption = "60.00" Then
            lblTimeMins.Caption = lblTimeMins + 1
            lblTimeMS.Caption = "0.00"
        End If
    End Sub
    Last edited by TcM; 06-04-2008 at 05:47 AM.

  10. #9
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101

    Re: Tutorial - A Simple Stropwatch!

    Added code tags.

    Thanks for the improvement.

  11. #10
    ViRuSS's Avatar
    ViRuSS is offline Learning Programmer
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    77
    Rep Power
    13

    Re: Tutorial - A Simple Stropwatch!

    nice, this is helpful
    thank you
    I didn't write here anything this is Illusion

+ Reply to Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Tutorial simple dice game
    By Turk4n in forum Java Tutorials
    Replies: 26
    Last Post: 05-31-2011, 12:33 PM
  2. Beginner Tutorial: Creating a simple class with methods
    By mr mike in forum Ruby on RailsTutorials
    Replies: 0
    Last Post: 01-03-2011, 08:52 PM
  3. Simple Blog System - Tutorial - Upcoming
    By webcodez in forum PHP Development
    Replies: 2
    Last Post: 02-25-2010, 10:25 PM
  4. Tutorial: Simple digital watch...
    By Turk4n in forum Java Tutorials
    Replies: 2
    Last Post: 06-28-2008, 01:31 PM
  5. Tutorial paint dots(simple version)
    By Turk4n in forum Java Tutorials
    Replies: 6
    Last Post: 06-25-2008, 11:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts