Visual Basic Code of the Week (COTW)
http://www.codeoftheweek.com
Issue #36
All content and source code is Copyright (c) 1998 by C&D Programming Corp. No part of this issue can be reprinted or distributed in any manner without express written permission of C&D Programming Corp.

Requirements for this Issue

The source code in this issue is designed for Visual Basic 5.0 and above. It can be used with some small modifications in VB 3 and 4.

In this Issue

This issue shows how to implement a machine independent delay function.

Wait Function

Description

This routine is useful in your applications where you want to wait a certain number of seconds for input. Some good examples are during communications programs or waiting for input. The Wait function allows you to abort it and determine how many seconds it has already been waiting for.

An interesting aspect of this routine you should notice is that the last two parameters are passed by reference. This means that if the values of these variables change anyplace in your program (in this routine or outside of this routine) they will always reflect the current value. This is how we are able to abort the Wait routine from outside of the actual routine. See the sample below for an implementation of this feature.

Declaration

Public Function Wait(ByVal lSeconds As Long, _
                     Optional ByRef bAbortFlag As Boolean = False, _
                     Optional ByRef lElapsed As Long) As Boolean

Parameters