How to make a stopwatch aplication:
Open Visual Basic 6. Select Standard EXE. Make 3 command buttons and 6
labels, and place them like on video. To 3 labels on right side, on
border style, select 1 - Fixed Single.
Put
caption on first button: Start Timing, on second: End Timing, and on
third Exit. To 3 labels on left side, put these captions: On first:
Start Time, on second End time and on third Elapsed time. On labels on
right side, put these names: For first label: lblStart, for Second
lblEnd and for third lbElapsed. For first button, but these names: For
first button: cmdStart, for second cmdEnd and for third cmdExit. Also,
remove everything from caption in 3 labels of right side.
Now, we need program codes. Double click on form, find combo where says
Form. Click it and select General. Type in this:
Option ExplicitDim StartTime As Variant
Dim EndTime As Variant
Dim ElapsedTime As Variant
Double click on Start Timing button and type in this:
Private Sub cmdStart_Click()
'Establish and print starting time
StartTime = Now
lblStart.Caption = Format(StartTime, "hh:mm:ss")
lblEnd.Caption = ""
lblElapsed.Caption = ""
End SubDouble click on End Timing button and write this:
Private Sub cmdEnd_Click()
'Find the ending time, compute the elapsed time
'Put both values in label boxes
EndTime = Now
ElapsedTime = EndTime - StartTime
lblEnd.Caption = Format(EndTime, "hh:mm:ss")
lblElapsed.Caption = Format(ElapsedTime, "hh:mm:ss")
End Sub
Double click on Exit button and write this:
Private Sub cmdExit_Click()
End
End Sub
That's all! Now, your program is ready for testing.
No comments:
Post a Comment