PRB: Shell Statement May Not Return Task Handle Immediately

Last reviewed: March 29, 1996
Article ID: Q147671
The information in this article applies to:
  • Professional and Enterprise Editions of Microsoft Visual Basic, 16-bit only, for Windows, version 4.0

SYMPTOMS

The Shell function returns a task handle to the application it starts. On slow machines, it has been reported that the task handle may not be returned immediately. This can cause problems if the code immediately after the call to the Shell function assumes that the variable used to hold the return value will be valid. The code will work fine when it is stepped through in the design environment if the pause between steps is of sufficient length to allow the handle to be returned and the value of the variable to be valid.

WORKAROUND

To work around this problem, simply wait until the task handle is returned to the variable used to hold the Shell function's return value. This can be accomplished with a few lines of code, like this:

   x = 0
   x = Shell("MY.exe")
   Do While x = 0
      DoEvents
   Loop


Additional reference words: 4.00 vb4win vb416
KBCategory: kbprg
KBSubcategory: PrgOther


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.