Enforce a Timeout Using the Timer Function

Category:
Miscellaneous
Type:
Snippets
Difficulty:
Beginning
Author:
Intelligent Solutions Inc.

Version Compatibility:

More information:
This code uses the Timer function, which returns seconds from midnight, to enforce a timeout value. It takes into account the fact that midnight may occur within the time span in question. It is useful in applications when you attempt to make a connection to a remote machine and there is no guarantee that the machine will be available, such as in a winsock application.

The snippet is a simpler and more robust implementation of the delay routine on this site. In the other example, you pass a timeout value and a boolean value by reference and return after the boolean value is true or timeout span is exceeded; therefore, the boolean value must be available at the module or global level. In this example, you just pass the time to wait before timing out.

See the comments within the code for more information and an example.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: