1

I am writing a VBScript for an application that runs on an industrial controller which does not support WScript. The controller has a single thread for processing VBScript and I need to pause my script for only a few program scans to allow another event handler to process. VBScript is processed in a WSH shell. If I run a MsgBox and popup a message it frees the script to do what it needs to and everything works fine but I cannot have a message box popping up.

Everything I have read suggests using WScript.Sleep but that is not available to me.

This does not run in a web browser so the window.timeout object is not available. I cannot access WScript.Sleep so that is not an option.

ChrisE
  • 53
  • 9
  • 1
    Can you not replace your code which I suppose contains a neverending loop into code that is triggered by a timer (setInterval), instead? – NineBerry Feb 01 '19 at 21:25
  • This is not a never ending loop. I have an activex object that moves files between controllers. I call one of its methods to move a file. It returns true or false saying it completed. At the same time it formulates a string message that it sends back via event handler. Once I run this method, the next line of code needs to wait until this string is populated but if I use a loop to monitor the length of that string it holds up the processing of the event handler. I found that if I pop a message box it will allow it to run so that when I close the box my code executes properly. – ChrisE Feb 01 '19 at 21:36
  • 1
    What is the environment that executes the script? Browser, Windows Scripting Host or something else? If something else, please name the software. – NineBerry Feb 01 '19 at 22:04
  • 1
    If you check the API of the environment that runs your script, you will perhaps find that it offers some function that is equivalent to sleep() or doEvents() – NineBerry Feb 01 '19 at 23:06
  • The software is Indusoft and the application is running on Windows 7 embedded pro. The software runs the vbscript inside a WSH shell but they dont provide access to WScript. – ChrisE Feb 04 '19 at 19:42

1 Answers1

1

If the granularity of seconds is fine enough for you and your operating system is Windows Vista or higher, you can take this script as a sample of how to wait for three seconds:

MsgBox (Now()), , "1"
WScript.CreateObject("WSCript.shell").Run "timeout.exe /T 3", 0, True
MsgBox (Now()), , "2"
AHeyne
  • 3,377
  • 2
  • 11
  • 16