CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: VB and Delays

  1. #1
    Join Date
    Jul 1999
    Posts
    6

    VB and Delays

    Does any know of the best way to put a delay in a VB APP.

    I'm using the Shell command to mount a network drive using the 'NET USE' statement. I have noticed that it can take from between 1 second to 20 seconds to successfully mount the drive. However, my VB App has continued to the next statements that rely on the mounted drive being there.

    I need to delay my app for about 30 seconds before continuing. I can of course put a loop in there but this takes up CPU.
    Any other way of doing this?



  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: VB and Delays

    you can use the Sleep API (Sleep( 30 * 1000)).
    But, be aware that this stops your app from responding to any events.
    You could work around this by sleeping in portions of half a second or so.
    Happy sleeping :-)


  3. #3
    Join Date
    Jul 1999
    Posts
    6

    Re: VB and Delays

    Thanks for this.

    I'm pretty new to VB, but where do I get the Sleep command from. Its not in Standard VB.


  4. #4
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Re: VB and Delays

    There is a way to make CPU not to halt:
    You put inside the loop or before the line that Lothar posted this command:

    DoEvents



    So the PC can respond to any event during the delay :-)

    Michael Vlastos
    Company MODUS SA
    Development Department
    Athens, Greece
    Tel: +3-01-9414900

  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: VB and Delays

    put the following declaration in your code

    public Declare Sub Sleep Lib "kernel32" (byval dwMilliseconds as Long)



    then call it like that.

    call sleep(30000)



    to sleep for 30 seconds.


  6. #6
    Guest

    Re: VB and Delays

    Another possibilty worth investigating is to use the Windows API version of Shell called ShellExecute.This returns a handle to the application instance which can then be used in conjuction with another API called WaitForSingleObject to wait for the exact time that the operation takes and then continue.MSDN should have articles relating to the use of both in VB.
    http://msdn.microsoft.com


  7. #7
    Join Date
    Oct 1998
    Posts
    6

    Re: VB and Delays

    What I would do ... other than using Create Process and Wait for single Object ... is to create a timer object that will check to see if the network drive is ready ... after the point in your code where you use the shell function ... enable your timer, then end the subroutine. Set your timer interval ... every 10 seconds or so ... then in the timer code you can check to see if the drive is ready ... If the drive is available ... you disable the timer ... and call the appropriate subroutine to continue with your app.

    Gordito Supreme


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured