Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HTA - Refresh

2,395 views
Skip to first unread message

JHP

unread,
Apr 30, 2008, 9:33:10 AM4/30/08
to
No sure if this is the right forum. but I hope someone can help - I've been
searching for an answer for days - and I bet it's something simple I have
over looked.

That said:

I have written a simple HTA script that iterates through parsing a text file
by line, incrementing a Progress Bar. But because of the long process the
background disappears if anything overlaps it, and a text <div> is not
updated.

How do I refresh (repaint) the HTA.

NB: The ProgressBar is "of Object" - and not affected:
<object classid="clsid:35053A22-8589-11D1-B16A-00C0F0283628"
id="ProgressBar1" height="20" width="400">

Thank you for any help, and reading through a long winded request.

mr_unreliable

unread,
Apr 30, 2008, 11:07:41 AM4/30/08
to
JHP wrote:
> How do I refresh (repaint) the HTA.
>

hi JHP,

Try this:

document.execCommand("Refresh")

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)

Tom Lavedas

unread,
Apr 30, 2008, 11:06:45 AM4/30/08
to

This pausing your processing for a period of time to give the system
time to update the browser display. This is commonly done through the
setTimeout (or to a lesser extent the setInterval) functions provided
as part of the browser Document Object Model (DOM). The main feature
needed to make this work is that you process MUST take a break at each
point you want the display to be updated. Then the setTimeout kicks
in after the appropriate timeout and restarts the process. This is
pretty tricky to do and somewhat difficult for some people to
comprehend (it took me more than one try ;o).

Anyway, here is a sample I had laying around that illustrates on way
to do it ...

<html>
<head>
<script language=VBScript>
Sub StepWise(nStage)
Dim nPause

document.body.innerHTML = "Step " & nStage
nPause = 500 ' milliseconds
Select Case nStage
Case 1
setTimeout "StepWise " & nStage + 1, nPause, "VBScript"
Case 2
setTimeout "StepWise " & nStage + 1, nPause, "VBScript"
Case 3
setTimeout "StepWise " & nStage + 1, nPause, "VBScript"
Case 4
setTimeout "StepWise " & nStage + 1, nPause, "VBScript"
Case 5
document.body.innerHTML = "Done"
End Select

End Sub

</script>
</head>
<body onload="StepWise 1">
</body>
</html>

This is structured by stages, which by nature do different things. It
could also be a simple IF block around your whole loop process
instead, sometyhing like this ...

Sub Steps(nStep, nLimit)
Dim nPause

nPause = 50 ' milliseconds for example
if nStep <= nLimit then
' do process
' update progress
document.body.innerHTML = "Step " & nStep
else
GoToNextPartofProcess(Arguments, if, needed)
End Select

End Sub

HTH

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

JHP

unread,
Apr 30, 2008, 12:14:07 PM4/30/08
to
I thought about that, but I wont be able to use it with this situation as
I'm parsing over 100,000 lines (a second per line adds over 27 hours).

Thank you for replying.

"Tom Lavedas" <tglb...@cox.net> wrote in message
news:23fcad21-b73c-483d...@z72g2000hsb.googlegroups.com...

JHP

unread,
Apr 30, 2008, 12:40:15 PM4/30/08
to
How do I embed this into vbScript - with a quick net lookup I see that it's
java. I added it to my code but nothing happends... here is a snippet:

Sub CreateTMP()
Const forWriting = 2
Const createFile = True

Set objRegExp = CreateObject("VBScript.RegExp")
objRegExp.Global = True
objRegExp.IgnoreCase = True
objRegExp.Pattern =
"[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]"
Set objMatch = objRegExp.Execute(strACHText)
lngRowCount = objMatch.Count

If lngRowCount > 0 Then
strProgress = "<object

classid='clsid:35053A22-8589-11D1-B16A-00C0F0283628' id='ProgressBar1'

height='20' width='400'>"
strProgress = strProgress & "<param name='Min' value='0'>"
strProgress = strProgress & "<param name='Max' value='" & lngRowCount &
"'>"
strProgress = strProgress & "<param name='Orientation' value='0'>"
strProgress = strProgress & "<param name='Scrolling' value='1'>"
strProgress = strProgress & "</object>"
document.getElementById("progress").innerHTML = strProgress
Sleep(1)

For Each rtnMatch In objMatch
strContract = rtnMatch.Value
document.getElementById("contract").innerHTML = "<span>Parsing
Contract: " & strContract & "</span>"

If ProgressBar1.Value < ProgressBar1.Max Then ProgressBar1.Value =
ProgressBar1.Value + 1

document.execCommand("Refresh")
lngStart = rtnMatch.FirstIndex
lngFinish1 = InStr(lngStart, strACHText, vbCrLf)
lngFinish2 = InStr(lngFinish1 + 2, strACHText, vbCrLf) - (lngFinish1 +
2)
strLine1 = Mid(strACHText, lngStart, lngFinish1 - lngStart)
strLine2 = Mid(strACHText, lngFinish1 + 2, lngFinish2)
strTemp = strTemp & Trim(strLine1) & " " & Trim(strLine2) & vbCrLf
Next
strACHFile = Mid(strFolderFile, InStrRev(strFolderFile, "\") + 1)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strRoot & Left(strACHFile,
Len(strACHFile) - 3) & "tmp", forWriting, createFile)
objFile.Write strTemp
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
Call createExcel()
End If
Set objMatch = Nothing
Set objRegExp = Nothing
End Sub

"mr_unreliable" <kindlyReply...@notmail.com> wrote in message
news:OtspsLtq...@TK2MSFTNGP04.phx.gbl...

Tom Lavedas

unread,
Apr 30, 2008, 1:50:24 PM4/30/08
to
On Apr 30, 12:14 pm, "JHP" <goaways...@GFY.com> wrote:
> I thought about that, but I wont be able to use it with this situation as
> I'm parsing over 100,000 lines (a second per line adds over 27 hours).
>
> Thank you for replying.
>
> "Tom Lavedas" <tglba...@cox.net> wrote in message

Why do you say it will add one second per line. It can be set to an
interval large enough to let the display update, but small enough to
minimize its impact.

In addition, you don't have to update the screen after every iteration
through the loop. Set it to happen every 100th time, instead.

Finally, as much as I admire mr unreliable's work, in general, I think
he's wrong about the Refresh. The issue is that your underlying
process is hogging all of the time available, such that the Refresh
can't take effect. Beside that, I think that a refresh should result
in the HTA returning to it's initialized state, that is like it was
just reloaded, not to the state at the time of the refresh. At least,
that's what would happen if you were to press the refresh key (F5) or
select the Refresh menu item in a browser window.

JHP

unread,
Apr 30, 2008, 3:05:42 PM4/30/08
to
I see your point - I don't want it to reload the hta just refresh the
page...

Thank you for following up - I'm going to implement your idea - I may be
able to get away with little to no impact... Thanks!

"Tom Lavedas" <tglb...@cox.net> wrote in message

news:f7e88ed3-15db-48c4...@a23g2000hsc.googlegroups.com...

Joe Fawcett

unread,
May 1, 2008, 6:14:29 AM5/1/08
to
"JHP" <goawa...@GFY.com> wrote in message
news:OWjpfDuq...@TK2MSFTNGP03.phx.gbl...
Not sure why you think that's in java, or JavaScript. Looks like VB(Script)
to me.

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name


mayayana

unread,
May 1, 2008, 9:06:55 AM5/1/08
to

Another option is to provide some kind of
feedback to let people know the HTA is busy.
In VB there's a DoEvents method that passes
control to Windows just long enough to catch
up with pending system messages, then continues.
It slows things down but works well to keep
screen painting up to date. That's really what
you want, but there's no good way to do it in
script or in IE.

A method I use is to show a small clock icon
and change the cursor while working. It's a bit
clunky, but it serves to inform people of what's
happening and stop them from trying to click
buttons. (After all, no one can do anything
while your function is running anyway, so keeping
the painting refreshed isn't of much value.)

The way this method works is that I put the clock
picture in a table with an ID set to not display:

TABLE.clock {display: none;}

Then I can toggle the display from code.
When I want to show the clock I use:

document.body.style.cursor = "wait"
ShowClock

The ShowClock sub just handles the CSS code to
make the clock visible center-screen, with a high
z-index to put it on top of everything else. Then I
also call a hack version of DoEvents, which is needed
for IE to paint the clock before starting the long
operation that's going to freeze it:

Sub DoEvents()
SH.run "%comspec% /c exit", 0, True
End Sub

(SH is WScript.Shell.)

When the operation is done the HideClock sub just
changes the style display property of the table, to
hide the clock, and returns the cursor to normal.

I don't remember whether I tested this method
successfully on all systems.

JHP

unread,
May 1, 2008, 2:25:01 PM5/1/08
to
Not saying your wrong, but everywhere I search: document.execCommand - runs
Client-Side, and it's always associated to JavaScript:

http://www.google.com/search?complete=1&hl=en&q=document.execCommand+vbscript&aq=f

My response was more to the fact that: document.execCommand("Refresh") did
not work in the context I was using it, and maybe mr_unreliable had a fix :)

"Joe Fawcett" <joefa...@newsgroup.nospam> wrote in message
news:epdnlQ3q...@TK2MSFTNGP06.phx.gbl...

JHP

unread,
May 1, 2008, 2:28:15 PM5/1/08
to
Thanks for the post... I was using the progress bar as the feedback
solution, it's just that if anything overlaps the window while the long
process was running - the background would loose it's color for the
duration; also screen text would not update until it completed.

"mayayana" <mayaXX...@mindXXspring.com> wrote in message
news:%23hrxxw4...@TK2MSFTNGP05.phx.gbl...

Tom Lavedas

unread,
May 1, 2008, 2:48:49 PM5/1/08
to
On May 1, 2:25 pm, "JHP" <goaways...@GFY.com> wrote:
> Not saying your wrong, but everywhere I search: document.execCommand - runs
> Client-Side, and it's always associated to JavaScript:
>
> http://www.google.com/search?complete=1&hl=en&q=document.execCommand+...

>
> My response was more to the fact that: document.execCommand("Refresh") did
> not work in the context I was using it, and maybe mr_unreliable had a fix :)
>
> "Joe Fawcett" <joefawc...@newsgroup.nospam> wrote in message
>
> news:epdnlQ3q...@TK2MSFTNGP06.phx.gbl...
{snip}

>
> > Not sure why you think that's in java, or JavaScript. Looks like
> > VB(Script) to me.
>
> > --
>
> > Joe Fawcett (MVP - XML)
>
> >http://joe.fawcett.name

Strictly speaking it is not Java (JScript), but rather a part of the
browser's document object model (DOM) which is language independent.
That is it can be used in JScript or VBS, if the browser supports
those - only IE does both, AFAIK. Plus, I believe IE's DOM is the
only one that supplies the execCommand() method but it's still not
Java. Your observation is probably an artifact of the fact that most
posts are from people using the more universal JScript to better
support a wider set of browsers.

JHP

unread,
May 1, 2008, 3:06:04 PM5/1/08
to
Thanks very much - knowledge is power... and it helps to know what I'm
talking about :)

"Tom Lavedas" <tglb...@cox.net> wrote in message

news:ab7b57a1-1628-4f42...@f63g2000hsf.googlegroups.com...

mayayana

unread,
May 1, 2008, 8:09:44 PM5/1/08
to
> Thanks for the post... I was using the progress bar as the feedback
> solution,

Woops. I didn't notice that part of your initial post.

mr_unreliable

unread,
May 2, 2008, 12:00:28 PM5/2/08
to
JHP wrote:
> How do I refresh (repaint) the HTA.
>

hi JHP,

Many, if not most, professional scripters will advise you to
use IE (or an HTA) for a graphical user interface (gui), in
situations where a vbs msgbox or askbox is not good enough.
That is because IE (or an HTA) is Microsoft code which is
guaranteed to be 100 percent reliable and trustworthy. No
professional in his/her right mind would use anything but
Microsoft code.

However, there are a few scripters out there, who may indulge
in risky behavior and deviate from the microsoft "security
blanket". For those courageous and/or foolhardy folks, there
are other possibilities, and by using those other possibilities
you may avoid some of the shortcomings of IE (and/or HTA), like
the lack of "repaint" or even "doEvents".

For one, you could use a third-party control with vbs, which
will offer you an (almost) full gui capability (equivalent to
vb, because these 3rd-party controls are frequently written
in vb). Here are two that I have used successfully:

kixForms: http://www.kixforms.org/assets/index.htm
(written by: Shawn Tassie of CGI Canada)
wshDialog: http://home.hccnet.nl/p.vd.klugt/,
(written by: Peter J.C. van der Klugt)

For another, you could use a scripting language, (or a programming
language which is relatively uncomplicated so that is may almost
be regarded as a scripting language). There are a number of
languages which meet that criteria. All of these languages have
a more-or-less complete gui capability, and most have a COM
capability, although in some cases not as fully-developed as vbs.

FBSL: http://www.fbsl.net/phpbb2/index.php
o'Basic http://obasic.com/
Emergence BASIC: http://www.ionicwind.com/
FreeBASIC: http://www.freebasic.net/

In situations like this, I used to also recommend:
AutoIt3: http://www.autoitscript.com/autoit3/
but since autoit has dropped support of win98 (my os of choice),
I have dropped them.

There is also the "free" microsoft visual basic express edition,
which is an almost-full vb compiler. However, this is a vast step
into a much higher level of complexity, compared with vbs, and is
not recommended unless you wish to set aside a considerable amount
of time to learn it (or re-learn if you know vbClassic).

Joe Fawcett

unread,
May 6, 2008, 4:02:17 AM5/6/08
to
"mr_unreliable" <kindlyReply...@notmail.com> wrote in message
news:ubflgyGr...@TK2MSFTNGP02.phx.gbl...
Another option I have used is HTA with ScriptX from meadroid. You then get
the repainting and the ability to hook events etc.
Very suitable for corporate use when you can put the ScriptX stuff on an
intranet server.

JHP

unread,
May 7, 2008, 1:27:02 PM5/7/08
to
Sorry for just getting back to you now...

Thanks very much mr_unreliable and Joe Fawcett... fantastic - This is not a
Microsoft World (almost but not quite)

I was listening to Live - The Beauty Of Gray while writing this... you guys
have a good one!

"mr_unreliable" <kindlyReply...@notmail.com> wrote in message
news:ubflgyGr...@TK2MSFTNGP02.phx.gbl...

mr_unreliable

unread,
May 8, 2008, 5:09:49 PM5/8/08
to
JHP wrote:
> I was listening to Live - The Beauty Of Gray while writing this...

This is new. Most newsgroupies don't bother to update us
on their music of choice while posting techie stuff.

For the curious, here is T.B.O.G. in video:

http://www.youtube.com/watch?v=p5WIexiYeQg

cheers, jw

0 new messages