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

Wait for Window to Activate

550 views
Skip to first unread message

Billy Vick

unread,
Jun 14, 2000, 3:00:00 AM6/14/00
to
How do I wait for a windows to activate. I have an application that I can
strart running in VB Script but I need to wait for the output so I can
export the data to a file. The problem is that if the network is running
fine, I can wait 5000 milliseconds and everthing is fine. If the network is
slow, I could have to wait much longer. I was wondering if there was just a
way to "wait" until that report window appears.

Thanks,
Billy Vick


Walter Zackery

unread,
Jun 14, 2000, 3:00:00 AM6/14/00
to

You can do something like this with any WSH version that has the Sleep
method.

Do Until Shell.AppActivate("MyWindow")
WScript.Sleep 100
Loop

"Billy Vick" <bv...@yahoo.com> wrote in message
news:uARucSh1$GA.196@cppssbbsa04...
: How do I wait for a windows to activate. I have an application that

:
:
:

Tom Lavedas

unread,
Jun 14, 2000, 3:00:00 AM6/14/00
to
That's not in the documentation (grouse, grouse).

While poking around with the VBA Object viewer, I saw that AppActivate
returned a value (like a function, though the documentation says its a
method and makes no mention of a return value), but I couldn't figure
out how to use it. Thanks for illuminating that for us, Walter.
(Where'd you come by that info?)

I might make a tiny suggestion though. Wouldn't be better to use a long
For loop - so that it eventually times out when something untoward
occurs. For example, ...

bActive = False
For I = 100 to 10000 Step 100
if Shell.AppActivate("MyWindow") Then
bActive = True
Exit For
End if
WScript.Sleep 100
Next
if not bActive Then
WSH.Echo "Timeout"
WSH.Quit(1001)
End if

BTW, Sleep and AppActivate first appeared (together) in WSH version 2.0.

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/

jim_w

unread,
Jun 14, 2000, 3:00:00 AM6/14/00
to
I think Mike Harris was the first one to come up with the notion of using
appactivate as a function.

But, beware of using undocumented "features". If it's not documented, then
it just might be working as a result of some "inadvertant accident", (like,
the S_OK constant accidently being left in the return register), rather than
any overt intention on microsoft's part to make the life of a scripter any
easier. And then microsoft may step up and "correct" that accident at any
time...

(signed) Joe Gloomster

Tom Lavedas <lav...@pressroom.com> wrote in message
news:3947B7E3...@pressroom.com...

art...@gmail.com

unread,
Oct 9, 2013, 9:01:06 AM10/9/13
to
El miércoles, 14 de junio de 2000 09:00:00 UTC+2, Billy Vick escribió:
> How do I wait for a windows to activate. I have an application that I can
> strart running in VB Script but I need to wait for the output so I can
> export the data to a file. The problem is that if the network is running
> fine, I can wait 5000 milliseconds and everthing is fine. If the network is
> slow, I could have to wait much longer. I was wondering if there was just a
> way to "wait" until that report window appears.
>
> Thanks,
> Billy Vick

Hi

This code can be usefull for you..

https://gist.github.com/anebot/6899746


Function WaitForAppActivate(oShell,AppName,TimeOutInSec)

Dim start_time
Dim exit_by_timeout
exit_by_timeout = False
start_time = Now()
While Not oShell.AppActivate(AppName) And not exit_by_timeout
exit_by_timeout = ( DateDiff("s",start_time,Now()) > TimeOutInSec)
if not exit_by_timeout then
WScript.Sleep 10
end if
Wend
WaitForAppActivate = Not exit_by_timeout

End Function

Todd Vargo

unread,
Oct 10, 2013, 5:38:16 PM10/10/13
to
OP may have found your response helpful 13 years ago. There seems to be
a lot of helpful GoogleGroups users responding to dead threads from
years ago simply because they do not pay attention to the "posted" date.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
0 new messages