|
Sometimes in
VBScript I get errors if I don't use parentheses around function arguments
and other times I get the error "can't use parentheses when calling
a subroutine" when I *do* use them. What's the problem?
Part of what is going on is VBScript distinguishing between different
kinds of procedures (Sub or Function). Whether there is a return
value being part of that distinction. The upshot is this: You will
need parentheses if you are calling a function that returns a value
and you are using the return value, or if you are using the 'Call'
keyword. For example:
' Parentheses can't be used here. Disregarded
return value
' makes this a subroutine call.
crt.screen.WaitForString "string", 5
' Parentheses needed here. Return value makes
this a
' function call.
Dim result
result = crt.screen.WaitForString("string", 5)
' Parentheses are always needed when using 'Call'
Call crt.screen.WaitForString("string")
Call crt.screen.WaitForString("string", 5)
' With one argument both of these forms are
legal.
crt.screen.WaitForString "string"
crt.screen.WaitForString("string")
Was this information helpful?
|
| Four Fast Ways to Learn More... |
|