Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering

Browse Topics

- Getting started
- Data Types
- Modules
- Operators in VB6
- VB6 Variable
- VB6 Procedures
- VB6 Control Structures
- Loops in VB6
- VB6 Exit Do & With End With
- Arrays in VB6
- User-Defined Data Types
- VB6 Constants
-
VB6 Built-in Functions
- Date and Time in VB6
- VB6 Controls
- TextBox Control
- ComboBox & OptionButton
- Label & Frame
- PictureBox & ImageBox
- Timer Control
- ListBox & ComboBox
- VB6 ScrollBar
- Control Arrays in VB6
- Files controls in VB6
- VB6 CheckBox
- Forms in VB6
- Menus in VB6
- MDI Form in VB6
- InputBox
- MessageBox
- Mouse events
- Mouse Move
- Error Handling
-
Error Handling (2)
-
VB6 Database

You are here: Visual Basic > VB6 (Beginners Tutorial)

Tutorial Main Page | Previous Page | Contents | Next Page

Quick Example 1: Using GetTickCount to Build a Stopwatch

1. Use the API Text Viewer to obtain the Declare statement for the GetTickCount function. Choose Private scope. Copy and paste it into the applications General Declarations area (new code is italicized).

Option Explicit
Dim StartTime As Variant
Dim EndTime As Variant
Dim ElapsedTime As Variant
Private Declare Function GetTickCount Lib "kernel32" () As Long


2 . Modify the cmdStart_Click procedure as highlighted:

Private Sub cmdStart_Click()
'Establish and print starting time
StartTime = GetTickCount() / 1000
lblStart.Caption = Format(StartTime, "#########0.000")
lblEnd.Caption = ""
lblElapsed.Caption = ""
End Sub


3 . Modify the cmdEnd_Click procedure as highlighted:

Private Sub cmdEnd_Click()
'Find the ending time, compute the elapsed time
'Put both values in label boxes
EndTime = GetTickCount() / 1000
ElapsedTime = EndTime - StartTime
lblEnd.Caption = Format(EndTime, "#########0.000")
lblElapsed.Caption = Format(ElapsedTime, "#########0.000")
End Sub


4. Run the application. Note we now have timing with millisecond (as opposed to one second) accuracy.


  

Tutorial Main Page | Previous Page | Contents | Next Page

   

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved