Lost Password?


  #1 (permalink)  
Old 09-16-2007, 03:05 AM
travy92's Avatar   
travy92 travy92 is offline
Learning Programmer
 
Join Date: Sep 2007
Location: Australia
Age: 15
Posts: 72
Credits: 14
Rep Power: 5
travy92 is on a distinguished road
Send a message via MSN to travy92
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:

Quote:
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:

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

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

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

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

Quote:
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.

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

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

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

Quote:
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 To view attachments in this forum your post count must be 1 or greater. You currently have 0 posts.
__________________
C:\Users\Travis\Desktop\Image Converter\Knight1.bmp

Last edited by Jordan; 09-18-2007 at 08:33 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-22-2007, 01:58 PM
khaabas khaabas is offline
Newbie
 
Join Date: Sep 2007
Posts: 4
Credits: 0
Rep Power: 0
khaabas is on a distinguished road
Default

code timer not correct
appear message run time error 424
how i can fix this problem
thanx man
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-22-2007, 02:51 PM
TcM's Avatar   
TcM TcM is offline
Code Warrior
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,332
Credits: 0
Rep Power: 68
TcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of light
Default

That is because you made the Label name as Label1, instead of Label2! Rename Label to Label2 and it should work
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-01-2008, 09:17 AM
duffbuffvick duffbuffvick is offline
Newbie
 
Join Date: Feb 2008
Posts: 1
Credits: 0
Rep Power: 0
duffbuffvick is on a distinguished road
Default

Thank you for posting. Amazing tutorial.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 08:05 AM
wazofski wazofski is offline
Programmer
 
Join Date: Feb 2008
Posts: 126
Credits: 3
Rep Power: 3
wazofski is on a distinguished road
Default

Doesn't work, it only adds +0,01 once and then it does nothing, think you gotta remake your code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 03-02-2008, 03:47 AM
travy92's Avatar   
travy92 travy92 is offline
Learning Programmer
 
Join Date: Sep 2007
Location: Australia
Age: 15
Posts: 72
Credits: 14
Rep Power: 5
travy92 is on a distinguished road
Send a message via MSN to travy92
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-03-2008, 09:55 AM
wazofski wazofski is offline
Programmer
 
Join Date: Feb 2008
Posts: 126
Credits: 3
Rep Power: 3
wazofski is on a distinguished road
Default

No i did use a label
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-04-2008, 03:41 AM
obliviongoty obliviongoty is offline
Newbie
 
Join Date: Jun 2008
Posts: 1
Credits: 0
Rep Power: 0
obliviongoty is on a distinguished road
Default 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 08:47 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 06-04-2008, 08:48 AM
TcM's Avatar   
TcM TcM is offline
Code Warrior
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,332
Credits: 0
Rep Power: 68
TcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of light
Default Re: Tutorial - A Simple Stropwatch!

Added code tags.

Thanks for the improvement.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 08-31-2008, 04:56 PM
ViRuSS's Avatar   
ViRuSS ViRuSS is offline
Learning Programmer
 
Join Date: Aug 2008
Location: London, England
Age: 14
Posts: 70
Credits: 1
Rep Power: 2
ViRuSS will become famous soon enoughViRuSS will become famous soon enough
Default Re: Tutorial - A Simple Stropwatch!

nice, this is helpful
thank you
__________________
I didn't write here anything this is Illusion
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Hex-Editing TcM Tutorials 31 11-01-2008 10:51 AM
Tutorial: C# Hello World Jordan CSharp Tutorials 15 10-16-2008 11:44 PM
John's Java Tutorial Index John Java Tutorials 0 01-11-2007 04:05 PM
JSP Tutorial encoder JavaScript and CSS 0 05-26-2006 06:31 AM


All times are GMT -5. The time now is 04:53 AM.

Contest Stats

WingedPanther ........ 2630.54
Xav ........ 2576.41
Brandon W ........ 1697.27
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 959.05
dcs ........ 646.09
Steve.L ........ 475.59
orjan ........ 407.96
chili5 ........ 378.6

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads