Handling OLE Errors and Timeouts


Applications that use OLE objects need to anticipate that errors and delays can occur in the applications that provide the objects. Because these events occur outside of the application that contains the OLE object, Visual Basic needs a special mechanism for communicating these errors and timeouts. Fortunately, version 5.0 adds a set of App object properties that lets you control how OLE objects deal with problems as described in Table 19.5.

Table 19.5 - App Object Properties that Control VB's Response to OLE Timeouts.

App Object Property Determines
OleRequestPendingMsgText The error message displayed to users when an OLE server times out while processing a request
OleRequestPendingMsgTitle The title on the pending request timeout dialog box.
OleRequestPendingTimeout The number of milliseconds to wait before the pending message is displayed
OleServerBusyMsgText The error message displayed to users when an OLE server fails to respond to a request
OleServerBusyMsgTitle The title on the server busy dialog box
OleServerBusyRaiseError Whether or not a trappable error is generated after a busy error occurs
OleServerBusyTimeout The number of milliseconds to wait before the busy message is displayed

The difference between a pending error and a busy error is how far the OLE request got before encountering a problem.

With pending errors, the OLE server has received and acknowledged the request - it's just taking longer than you might expect. Perhaps the server is in an infinite loop or merely retrieving a very large chunk of data.

With busy errors, the OLE server has rejected the request - usually because the server is doing some modal task for another user. In Excel, you get a busy error any time you request OLE data while Excel is displaying a dialog box.

In either case, the default timeout interval is 5 seconds. You might want to change the default OleServerPendingTimeout property before performing tasks you know will take a long time for the server to handle. Because busy errors generally occur because of user actions with the OLE server, the standard OleServerBusyTimeout value is generally okay.

Turning off busy errors by setting OleServerBusyRaiseError to False is often useful because Visual Basic will still display the server busy dialog box. Turning the busy error off prevents OLE from halting your application unexpectedly - the user can still correct the problem using the OLE dialog box to switch to the application or cancel the request.