"Tom Lavedas" <tglbatch@newsgroup> wrote in message
news:cbf0af2d-426d-4411-b756-86bf5022ef00@newsgroup
> On May 27, 5:05 pm, "M" <m...@newsgroup> wrote:
>> Hello:
>>
>> What's a simple approach for performing an OR operation on multiple calls
>> to a function that returns a Boolean value?
>>
>> For example, I have this function that returns either True or False.
>>
>> Function funSomeFunction(strParam1, strParam2)
>> funSomeFunction = True [False]
>>
>> I need to call the function multiple times and perform an OR operation on
>> the return values, like this:
>>
>> If funSomeFunction strABC, strDEF OR funSomeFunction strGHI, strJKL OR
>> funSomeFunction strABC, strDEF Then
>>
>> I've tried the above and also tried putting each function call in
>> parenthesis and it still didn't work. I'm trying to avoid assigning each
>> return value to its own variable so the script doesn't get too bloated (I
>> have to call the function 5 times), but if that's the only way, then I'll
>> do it.
>>
>> Thank you.
>>
>> --
>> Regards,
>> M
>> MCTS, MCSAhttp://SysAdmin-E.com >
> The function parameters need to be enclosed in parentheses, as in ... Agreed, yes they are needed in *this* case...
> If funSomeFunction(strABC, strDEF) OR _
> funSomeFunction(strGHI, strJKL) OR _
> funSomeFunction(strABC, strDEF) Then ...
>
> This is always true for *functions* in VBS, regardless of the use. I disagree. IMHO, the parentheses are *only* required when the function is
expected to return a value. In fact, you can take a subroutine, re-code it
as a function, and call it as if it were just a subroutine. If the function
were coded to return a value but it is called without parenthesizing the
parameters, no error would occur. The returned value, of course, would not
be available to the calling routine.
This example illustrates my point:
fcntest 123, 456 ' ==> function displays [123][456]
returnval = fcntest(111,222) ' ==> function displays [111][222]
msgbox returnval ' ==> msgbox displays [111222]
function fcntest(a,b)
msgbox "[" & a & "][" & b & "]"
fcntest = "[" & a & b & "]"
end function
Of course, if one needed a sub to do something where a return value was not
required, one would generally tend to use a sub rather than a function.
Conversely, where a return value is required, a function is called for. But
the actual behaviour here differs from the obvious intent of the language
syntax.
Those who program in languages where functions are the only type of callable
subprogram will probably be less surprised by this.
/Al