From: M on
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, MCSA
http://SysAdmin-E.com
From: Tom Lavedas on
On May 27, 5:05 pm, "M" <m...(a)nowhere.com> 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 ...

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.
See the documentation:
WSH 5.6+ documentation download (URL all one line)
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en

In particular read "Function procedures, about Function procedures".
_____________________
Tom Lavedas
From: Al Dunbar on


"Tom Lavedas" <tglbatch(a)verizon.net> wrote in message
news:cbf0af2d-426d-4411-b756-86bf5022ef00(a)o15g2000vbb.googlegroups.com...
> On May 27, 5:05 pm, "M" <m...(a)nowhere.com> 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

> See the documentation:
> WSH 5.6+ documentation download (URL all one line)
> http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
>
> In particular read "Function procedures, about Function procedures".
> _____________________
> Tom Lavedas

From: "Dave "Crash" Dummy" on
Al Dunbar wrote:
> "Tom Lavedas" <tglbatch(a)verizon.net> wrote in message
> news:cbf0af2d-426d-4411-b756-86bf5022ef00(a)o15g2000vbb.googlegroups.com...
>> On May 27, 5:05 pm, "M" <m...(a)nowhere.com> 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.

If the "function" does not return a value it is not a function, it is a
subroutine. A function can be treated like a variable. A subroutine cannot.

Function Hello(txt)
Hello="Hello, " & txt
end Function

This works:
msgbox Hello("World!")

This generates an error:
msgbox Hello "World!"
--
Crash

English is not my native tongue; I'm an American.
From: Tom Lavedas on
On May 27, 9:14 pm, "Dave \"Crash\" Dummy" <inva...(a)invalid.invalid>
wrote:
> Al Dunbar wrote:
> > "Tom Lavedas" <tglba...(a)verizon.net> wrote in message
> >news:cbf0af2d-426d-4411-b756-86bf5022ef00(a)o15g2000vbb.googlegroups.com....
> >> On May 27, 5:05 pm, "M" <m...(a)nowhere.com> 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.
>
> If the "function" does not return a value it is not a function, it is a
> subroutine. A function can be treated like a variable. A subroutine cannot.
>
> Function Hello(txt)
>         Hello="Hello, " & txt
> end Function
>
> This works:
> msgbox Hello("World!")
>
> This generates an error:
> msgbox Hello "World!"
> --
> Crash
>
> English is not my native tongue; I'm an American.

That is also my position - IMHO, for VBS any routine used as a
subroutine is a subroutine, regardless of the word used in its
declaration. Admittedly, this is not the case for the more consistent
C and C-like languages (C+, C++, Java, Javascript, JScript, etc.),
where everything is called a function and all functions, whether used
as a function or subroutine requires the same parentheses treatment.

But, in all seriousness, tomAto, tomAHto ;-) In the OPs case, it
needed parentheses.
_____________________
Tom Lavedas