• “Pause” in code

    Author
    Topic
    #461111

    Hi All,
    I am working with some VB script (5.5) on a piece of equipment and would like to pause, or delay, execution of the script for a couple of seconds. Does anyone know if this is possible? I am looking through the VB Script 5.5 help file and nothing sticks out to me.

    Thanks,
    Mark

    Viewing 4 reply threads
    Author
    Replies
    • #1168454

      I am working with some VB script (5.5) on a piece of equipment and would like to pause, or delay, execution of the script for a couple of seconds.

      Not sure what you mean by “a piece of equipment,” but if it runs the Windows Script Host, check out the WScript.Sleep Method. (This method is not part of native VBS.)

      • #1168456

        Hi,
        The equipment is a machine that acts like a printer with programmable input. There is an option to run VBScript 5.5 compliant commands with the job file when it runs. Looking at the VBS 5.5 help file I have, that Wscript method is not there, so I am not sure it will work. Any other ideas?

        Thanks,
        Mark

        Not sure what you mean by “a piece of equipment,” but if it runs the Windows Script Host, check out the WScript.Sleep Method. (This method is not part of native VBS.)

        • #1168458

          The equipment is a machine that acts like a printer with programmable input. There is an option to run VBScript 5.5 compliant commands with the job file when it runs. Looking at the VBS 5.5 help file I have, that Wscript method is not there, so I am not sure it will work. Any other ideas?

          Perhaps you can write a Do loop that simply burns up time doing something useless and monitoring the clock. However, if the goal is to let another process proceed in the background, you may need to find a method similar to Sleep (assuming the equipment is capable of multi-tasking different processes).

          • #1168627

            That sounds like it may work. Any idea how you would monitor the clock?

            Thanks,
            Mark

            Perhaps you can write a Do loop that simply burns up time doing something useless and monitoring the clock. However, if the goal is to let another process proceed in the background, you may need to find a method similar to Sleep (assuming the equipment is capable of multi-tasking different processes).

        • #1168486

          I can use WScript.Sleep in a .vbs file without problems – see attached sample.

          • #1168524

            Hi Hans,
            I will try but I am not seeing that in the VBS 5.5 command reference.

            Thanks,
            Mark

            I can use WScript.Sleep in a .vbs file without problems – see attached sample.

          • #1168626

            Hi,
            WScript will not work with VBS 5.5. Do you have any ideas of another way to waste a second or two?

            Thanks,
            Mark

            I can use WScript.Sleep in a .vbs file without problems – see attached sample.

            • #1168628

              Does VBScript – sleep command help? (See the replies near the bottom of the thread)

            • #1168635

              Hi Hans,
              I can try this but “Sleep” is also not in the keyword list. I am now wondering if some sort of “Timer” DO/LOOP would work.

              Thanks,
              Mark

              Does VBScript – sleep command help? (See the replies near the bottom of the thread)

            • #1168638

              I meant the Window.setTimeOut mentioned near the end – this will only work for web pages.

              I use VBScript very rarely, and then for very simple things only, so I can’t offer much help.

            • #1168668

              Hi Hans,
              OK, no problem. I will keep trying things and if I come across something that works, I will post back.

              Take care,
              Mark

              I meant the Window.setTimeOut mentioned near the end – this will only work for web pages.

              I use VBScript very rarely, and then for very simple things only, so I can’t offer much help.

            • #1168684

              Have you tried something like this which was found here – http://www.experts-exchange.com/Web_Develo…Q_11973538.html
              dim startTimer, currentTimer
              dim duration ‘in seconds
              duration=30

              startTimer=timer
              do while currentTimer<(startTimer+duration)
              currentTimer=timer
              Loop

            • #1168689

              Hi Andrew,
              That looks good. I will give it a try.

              Thanks,
              Mark

              Have you tried something like this which was found here – http://www.experts-exchange.com/Web_Develo…Q_11973538.html
              dim startTimer, currentTimer
              dim duration ‘in seconds
              duration=30

              startTimer=timer
              do while currentTimer<(startTimer+duration)
              currentTimer=timer
              Loop

    • #1182902

      Just stumbled onto this thread while looking for something else. It’s old, yet I may have an input of some use.

      A couple of years ago I faced the same problem and after stubborn searching on the net I found this (My apoligies to who and wherever this was posted – I can’t remember):

      This item comes just before the macro itself, a bit like an ‘option explicit’

      Private Declare Sub Sleep Lib “kernel32” (ByVal nMilliseconds As Long)

      In the code itself you can then write:

      Sleep 750

      Adjust the number to get as much delay as you need.

      I don’t know how this works in Word 07. Also, the reference to 32 makes me think it’s tied to the 32-bit OS. It is, then I don’t know if this will work with a 64-bit OS.

    • #1183098

      You can’t use the Windows API in VBScript, unfortunately, so that wouldn’t work for this particular situation.

    • #1183105

      1) Homer Simpson: “D’Oh!”

      2) Note to self: Must READ postings before replying

    • #1183290

      I’m really rusty on this, and it may not fit your situation, but FWIW, I have a .vbs file called SleepSeconds.vbs that I created just to be called by other scripts that, for one reason or other, couldn’t directly use the .Sleep method of the WScript object. The SleepSeconds.vbs file looks like this:

      Code:
      Option Explicit
      'This procedure exists because you can't directly
      ' call WScript's methods (e.g., WScript.Sleep) in
      ' certain contexts (e.g., in an HTA).
      
      Dim wshArgs, seconds
      
      Set wshArgs = wscript.arguments
      
      If wshArgs.named.exists("seconds") = True Then
      	seconds = wshArgs.named.item("seconds")
       Else
      	seconds = 10
      End If
      
      WScript.Sleep 1000 * seconds
      
      Set wshArgs = Nothing

      And here’s an example (from an HTA) of a script calling SleepSeconds.vbs:

      Code:
      	Dim oShell
      	Set oShell = CreateObject("WScript.Shell")
      	oShell.Run "wscript.exe C:BINVBSProcsSleepSeconds.vbs /seconds:3", , True
      	Set oShell = Nothing
    Viewing 4 reply threads
    Reply To: “Pause” in code

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: