Results 1 to 15 of 15

Thread: Timer needed

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Timer needed

    Any ideas on how to make a function wait on another function before it begins? I have a function that runs a batch file; the file takes around 5 minutes to run. The next function has to apply a filter on the resulting text file of the batch file. The filter applies too soon and sees that there is nothing to apply the filter to so the program ends. Here's some code:

    VB Code:
    1. Private Sub runBatch()
    2.      Shell ("INVENTORY_FTP.bat")
    3.      'Need to wait 5 minutes here
    4. End Sub

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Timer needed

    Why not just do a shellandwait until the batch file is done? You can do a search in the forum for that.

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Timer needed

    Or, you could use this:

    VB Code:
    1. Shell ("Start /wait INVENTORY_FTP.bat")

    which will wait until the batch file finishes.
    you might need a cmd in there

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Timer needed

    dglienna: It says File Not Found

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Timer needed

    Not sure if it's the command, or that you don't have the path to the batch file.
    Try adding the path to the batch file, and if that doesn't work, then this should

    VB Code:
    1. Shell ("C:\Windows\System32\cmd.exe /c  " & _
    2.      "Start /wait INVENTORY_FTP.bat"), vbNormalFocus

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Timer needed

    Actually I was wondering if shellandwait would work, but my program doesn't recognize the shellandwait command

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Timer needed

    There is no command. It combines the same API's that start does.

    http://vbforums.com/attachment.php?attachmentid=41200

    Here is an example of shell and wait, though.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Timer needed

    That was a little too complex for me to understand.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Timer needed

    I've seen some other people using the shellandwait command in VB6. Is there something I need to add before my program recognizes that command?

    Here's one of those threads:
    http://www.vbforums.com/showthread.php?t=373660

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Timer needed

    I posted what everybody was using. That's why I suggested Start /Wait. It's a lot simpler.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Timer needed

    True, let me try that again

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Timer needed

    This code works:
    VB Code:
    1. Shell ("C:\Windows\System32\cmd.exe /c  " & _
    2.      "Start /wait INVENTORY_FTP.bat"), vbNormalFocus

    However, it opens two command windows. And doesn't close them.

    But this code doesn't:
    VB Code:
    1. Shell ("Start /wait INVENTORY_FTP.bat"), vbNormalFocus

    I'd like to have only one command window open and the window close after running the command

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Timer needed

    Use the /B flag. Try start /? from a command prompt.
    VB Code:
    1. start /wait /b myfile.bat

    and take off the last command to show focus. that was only for testing.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Timer needed

    Anyone know how to get around the fact that the file path contains a space when trying to run a batch file? It says "File NOT FOUND: G:\Finance\Inventory" If anyone can help me out I'd be most appreciative. Thanks. As always here's the code:

    VB Code:
    1. Shell ("Start /wait /b G:\Finance\Inventory Control\CycleCount\DB\deleteCycleCount.bat")

  15. #15
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Timer needed

    Put your path and filename in quotes.
    VB Code:
    1. Shell ("Start /wait /b " & chr(34) & "G:\Finance\Inventory Control\CycleCount\DB\deleteCycleCount.bat" & chr(34))

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