1
votes

With the recent deprecation of VBScript in IE11, I need to convert all my code that I have as an external script in Macro Express Pro. I've tried using JScript, but the macro runs for about a second and does nothing. I decided to switch to HTA/HTML and have the code print within a window. I've converted all the VBScript to the JavaScript equivalents, but I'm stuck with WScript.Echo. Is there a JavaScript equivalent for this?

I have a variable named %Variables% in the "Save console output to:" box. With WScript.Echo, if I need to exit out of the script and go back to VBScript, I can use the code below:

If Opt = "" Then
   Wscript.Echo "EXIT"
   Wscript.Quit
End If

This will send "EXIT" to %Variables% so that it can be used by Macro Express Pro to terminate the macro completely.

Is there a JavaScript way of doing the exact same thing?

1

1 Answers

1
votes

If you need to stop JavaScript execution you can always use return to exit the current function naturally, but that obviously won't work if you have nested functions.

Probably the next-best alternative would be to throw an exception to stop execution.

As for "echo" you can use the global console object. For example:

console.log("hello world");

Edit:

For a 500 milisecond "sleep" use setTimeout:

setTimeout(function() {
    console.log('hello');
}, 500);

Note that setTimeout will not block the process however like sleep does on some other platforms.