VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

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

Using GetTickCount to Implement a Delay

Many times, you want some delay in a program. We can use GetTickCount to form a user routine to implement such a delay. We’ll write a quick example that delays two seconds between beeps.

  1. Start a new project. Put a command button on the form. Copy and paste the proper Declare statement.

  2. Use this for the Command1_Click event:

    Private Sub Command1_Click()
    Call Delay(2#)
    End Sub

  3. Add the routine to implement the delay. The routine I use is:

    Private Sub Delay(DelaySeconds As Single)
    Dim T1 As Long
    T1 = GetTickCount()
    Do While GetTickCount() - T1 < CLng(DelaySeconds * 1000)
    End Sub

    To use this routine, note you simply call it with the desired delay (in seconds) as the argument. This example delays two seconds. One drawback to this routine is that the application cannot be interrupted and no other events can be processed while in the Do loop. So, keep delays to small values.

  4. Run the example. Click on the command button. Note the delay between beeps.


Tutorial Main Page | Previous Page | Contents | Next Page


Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved