Several have answered already, but I have one thing to add.
You indicate confusion about why parentheses seem to be required
sometimes and not others. Of the following two lines, the first
is invalid and the second is valid (at least as far as the syntax
of using parentheses is concerned), for rather obscure reasons:
ConnectEvent(DesktopWindow, "OnChildActivate", "MyOnChildActivate")
Disconnect(Desktop.Window)
Here's a brief but thorough treatment of why:
If you're keeping the return value, always use parentheses. If you're
not assigning the return value, you can use "call" and use parentheses
or don't use "call" and also don't use parentheses. If you do not use
"call" and still use parentheses, you'll get a syntax error unless the
sub you're calling only takes one argument. This is because VBScript
interprets the parentheses in that case as a request to pass the
argument by value instead of by reference.
To summarize by example, the following lines (which use hypothetical
subs and functions) are all syntactically correct and have the
indicated effects:
' Normal function calls, pass by reference.
result = func1(arg1)
result = func2(arg1, arg2)
' The same but passing all results by value.
result = func1((arg1))
result = func2((arg1), (arg2))
' The same four but for subs that don't return anything.
' First using "call," though this is older and a deprecated style.
call func1(arg1)
call func2(arg1, arg2)
call func1((arg1))
call func2((arg1), (arg2))
' Now using the newer style, without "call."
' First pass-by-reference, the usual case.
func1 arg1
func2 arg1, arg2
' And finally, the pass-by-value case that caused all the confusion.
func1 (arg1)
func2 (arg1), (arg2)
Notice in particular that the next-to-last line above looks just like
a "normal" sub invocation, but using parentheses around the argument.
That line just happens to succeed syntacticatlly because of the
pass-by-value thing. The last line, though, fails, because in order
to pass arguments by value, you have to surround each argument
individually with parentheses, not surround the whole lot of them with
a single set.
I regard the above parentheses issue as one of the more confusing
issues in VBScript for those who get their start in another language.
On Sat, Aug 30, 2008 at 04:43:26AM -0700, martin webster wrote:
Hi all,
I got an example from Doug which disables most hotkeys globally, but I can't
seem to get this routine to work in VB script. I get the error, "cannot call a
sub with parentheses when calling a sub". I've looked at some other examples I
have and this looks correct to me. This script should disable most hotkeys for
5 seconds, and then disconnect this event, in other words, I want this action
only to accur for 5 seconds, and then I want the hotkeys to be enabled again.
Begin VB script.
ConnectEvent(DesktopWindow, "OnChildActivate", "MyOnChildActivate")
Sub MyOnChildActivate(win)
win.Overlap.Settings.General.Hotkeys = FALSE
Sleep 5000
Disconnect(Desktop.Window)
Playsound, "c:\whistle wake.wav"
End Sub
Warm regards.
Martin Webster.
--
Doug Lee, Senior Accessibility Programmer
SSB BART Group - Accessibility-on-Demand
mailto:[EMAIL PROTECTED] http://www.ssbbartgroup.com
"While they were saying among themselves it cannot be done,
it was done." --Helen Keller