I will show you how to create a simple stopwatch for visual basic 6 beginners. This stopwatch consists of 3 labels called Label1, Label2, Label3 and 2 buttons called btnSart and btnExit.
1. Create 3 labels named Label1, Label2 and Label3.
2. Change the text of these labels to the number 0.
3. Create a Start/Stop button called btnStart.
4. Create an Exit button called btnExit.
5. Finally, create a timer called tmrTime. Make sure you change the timer interval to 1000 to represent 1 second. This can be placed anywhere in the form as it does not interfere with the design/object.
Then we start our coding. As long as you have labelled everything correctly, you can simple just type all this in without going back and referring to each component.
We will first code the button Start/Stop. This code means if the timer doesnt start automatically, this starts it
Code:
Private Sub btnStart_Click()
If tmrTime.Enabled = False Then
tmrTime.Enabled = True
Else
tmrTime.Enabled = False
End If
End Sub
Next we will code the timer tmrTime. This basically means the timer will gradually add on 1 second and when it reaches 60 secs, the minute label will start. This is the same for the hour label.
Code:
Private Sub tmrTime_timer()
Label3.Caption = Val(Label3.Caption) + Val(1)
If Label3.Caption = 60 Then
Label2.Caption = Val(Label2.Caption) + Val(1)
Label3.Caption = 0
ElseIf Label2.Caption = 60 Then
Label1.Caption = Val(Label1.Caption) + Val(1)
Label2.Caption = 0
End If
End Sub
Now we will address the issue of the form. This means when the form loads, the timer will not start yet until you click the start/stop button.
Code:
Private Sub Form_Load()
tmrTime.Enabled = False
End Sub
Finally we code the Exit button. This just exits the program.
Code:
Private Sub btnExit_Click()
Unload Me
End Sub
Now the form should look similar to the attached image. You can also change the name of the form and give the hours, minutes and second a name label.center]
1. Create 3 labels named Label1, Label2 and Label3.
2. Change the text of these labels to the number 0.
3. Create a Start/Stop button called btnStart.
4. Create an Exit button called btnExit.
5. Finally, create a timer called tmrTime. Make sure you change the timer interval to 1000 to represent 1 second. This can be placed anywhere in the form as it does not interfere with the design/object.
Then we start our coding. As long as you have labelled everything correctly, you can simple just type all this in without going back and referring to each component.
We will first code the button Start/Stop. This code means if the timer doesnt start automatically, this starts it
Code:
Private Sub btnStart_Click()
If tmrTime.Enabled = False Then
tmrTime.Enabled = True
Else
tmrTime.Enabled = False
End If
End Sub
Next we will code the timer tmrTime. This basically means the timer will gradually add on 1 second and when it reaches 60 secs, the minute label will start. This is the same for the hour label.
Code:
Private Sub tmrTime_timer()
Label3.Caption = Val(Label3.Caption) + Val(1)
If Label3.Caption = 60 Then
Label2.Caption = Val(Label2.Caption) + Val(1)
Label3.Caption = 0
ElseIf Label2.Caption = 60 Then
Label1.Caption = Val(Label1.Caption) + Val(1)
Label2.Caption = 0
End If
End Sub
Now we will address the issue of the form. This means when the form loads, the timer will not start yet until you click the start/stop button.
Code:
Private Sub Form_Load()
tmrTime.Enabled = False
End Sub
Finally we code the Exit button. This just exits the program.
Code:
Private Sub btnExit_Click()
Unload Me
End Sub
Now the form should look similar to the attached image. You can also change the name of the form and give the hours, minutes and second a name label.center]
Thu May 06, 2010 3:39 pm by faseeh2006
» TOP 20 TRICKS TO SPEED UP YOUR PC
Fri Apr 16, 2010 10:14 am by JianWei-Jw
» Upload your files
Mon Apr 12, 2010 4:29 pm by faseeh2006
» Basic Skills!
Fri Apr 09, 2010 10:19 pm by faseeh2006
» How to Download, Decompress and Burn Playstation 2 Games
Fri Apr 09, 2010 10:17 pm by iyenboy
» Beginner's Guide to BitTorrent/UTorrent or any Torrent Client
Fri Apr 09, 2010 10:14 pm by iyenboy
» How To Use PCSX2 - The Playstation 2 Emulator !
Fri Apr 09, 2010 10:11 pm by iyenboy
» how to use kaspersky for lifetime !!
Fri Apr 09, 2010 10:09 pm by iyenboy
» How to Crack CD protection
Fri Apr 09, 2010 10:06 pm by iyenboy