Freetutes.com - Free Visual basic Tutorial website on the web

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering

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

Tutorial Main Page | Previous Page | Contents | Next Page

Sponsored Links

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()
    Beep
    Call Delay(2#)
    Beep
    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)
    Loop
    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 | Link to Us | Partner Links | About Us | Contact Us
Copyright © 2007-2008 Freetutes.com | All Rights Reserved