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

AppActivate Return Value

2,727 views
Skip to first unread message

Michael Bürgi

unread,
Feb 28, 2000, 3:00:00 AM2/28/00
to
AppActivate Return ValueI have done some testing upon your posting and I
discovered some really weird behaviour:

Your code only works if you test the booleans like this:

bResult = objShell.AppActivate("App Title")
if bResult then
'do something
end if
if not bResult then
'do something else
end if

AppActivate seems to return TRUE if it has found a window title beginning or
ending with/in the specified string (not case sensitive), FALSE otherwise.
The wild thing is that if you set

bResult=TRUE

then the code in the if-clause is run:

MsgBox(bResult) 'the popup contains True or Wahr or ... (it's
localised!)
if bResult=TRUE then ... end if

BUT! Even if AppActivate returns a boolean value TRUE, the same clause won't
run now:

bResult=objShell.AppActivate("Explorer")
MsgBox(bResult) 'the same message as before
if bResult=TRUE then
... 'this won't be executed!
end if

So, the docs should be updated to cover the return result of AppActivate and
something about boolean arithmetics, this would be really enlightning.


D Samuelsson <IMCEAEX-> schrieb in im Newsbeitrag:
143C6B82A8F1D211BBC200105A67CEF816B41C@JIM...
I've seen a few postings on the AppActivate method and have just done a
little function to sit in an ie5 browser to launch applications (a simple
"control panel" for a terminal server environment)
I have the following VB script to check for an instance of an application
running and either switch to or launch this app.
Function RunTheApp()
Dim iReturn
Dim objShell
Dim bResult
Set objShell = CreateObject("WScript.Shell")
bResult = objShell.AppActivate("App Title")
If bResult<>False then
objShell.SendKeys "%( x)"
End If
If bResult=False then
iReturn = objShell.Run("App Command Line")
End If
End Function
Or words to that effect ...
Now what has me puzzled is what is returned from the AppActivate method.
Looking at what it returns it looks to be a boolean result but if I have my
first condition as "if bResult=True" that clause never gets run.
Have I missed something here ? Does AppActivate return a False if it can't
find the app and something other than true if it does ?

Michael Bürgi

unread,
Feb 28, 2000, 3:00:00 AM2/28/00
to
AppActivate Return Valueoops, I forgot to enclose a sample file to test
with. Here you go...

Michael Harris

unread,
Feb 28, 2000, 3:00:00 AM2/28/00
to
AppActivate returns 0 or 1.  Literally speaking, True is -1 and False is 0.  Logically speaking, any numeric expression that evaluates to anything other than 0 is considered true.
 

if (1 + 1) then
  msgbox "true"
else
  msgbox "false"
end if
 
if (1 - 1) then
  msgbox "true"
else
  msgbox "false"
end if
if (1234567890) then
  msgbox "true"
else
  msgbox "false"
end if
=========================================
 
In your case...
 
If CBool(bResult) = True Then
    ...
 
will work or more simply
 
If bResult Then
    ...
 
I tend to use a variable name like bSuccess
 
If bSuccess Then
    ...it worked
Else
    ...it didn't work
End If

--
Michael Harris
MVP - Windows Script
"D Samuelsson" <IMCEAEX-> wrote in message news:143C6B82A8F1D211BBC200105A67CEF816B41C@JIM...
0 new messages