RSS

HTA Scripting: displaying output

02 Jan

One of the most frustrating issue facing vbscripters who is moving over to HTA scripting must be the seemingly lack of ability for the form to display its output as you code runs.

The first attempt most scripter will do is to define a spanID and try to write the output to it. For example:

thisText = “Starting script now…”
Do loop
Do something….
thisText = thisText & <BR> & “doing something now… ”
SpanID.InnerHTML = thisText
if done then Exit do
Loop

One would reasonably expect the dialog window to continuously update itself with the output text. However, we would quickly realise that the output come appears only after the entire loop has completed and the subprocedure ended or you may a call to a msgbox or other output functions. From the UI, it appears that the form hangs (as it process the loop) and then outputs the entire output after the delay.

One of the MS Article, Updating the Display During Lengthy Operations, has this to say:

Let’s imagine that the script above did execute as the author intended, and the user saw the count value on the display rise from 0 to 500. In this hypothetical situation, every time the display updated, events such as onresize and onchange would be generated. Should these events be handled in script immediately? Probably not as that could have effects on the script that was running in the original function—if a global variable’s value was changed, for example. An alternative would be to queue up all the events to be processed when the original function finally executed, but this too has a number of problems and seems far from efficient. It is useful for script to be able to execute and decide how things should be on the screen and then have all updates occur simultaneously when the function completes, rather than having a gradual display change on different parts of the screen.

Found a solution which uses a hidden cmd window to force the form to update:

Set WSHShell = CreateObject(“WScript.Shell”)
thisText = “Starting script now…”
Do loop
Do something….
thisText = thisText & <BR> & “doing something now… ”
SpanID.InnerHTML = thisText
WSHShell.run “%comspec% /c “, 0, true
if done then Exit do
Loop

Tested the solution and viola! the output comes alive!

Advertisements
 
Leave a comment

Posted by on January 2, 2008 in Scripts, VBScripts, Windows

 

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: