From: M on
Duh! I got confused since I was reading that functions could be called a few
different ways, with or without parentheses and with or without the call
keyword. I thought that since this was a self-written function I could only
call it a certain way. This is probably the second function I've written in
all my years working with VBS so I'm a bit rusty in this area.

Thanks.

--
Regards,
M
MCTS, MCSA
http://SysAdmin-E.com

"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 ...

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:fd752a33-aeab-4b52-aefe-ec656d5c1da9(a)z33g2000vbb.googlegroups.com...
> 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.

Yes, the OP's script needed the parentheses - not because he used functions,
though, but because his script expected those functions to return values.

/Al

ps: picking as many nits as I can before the lights go out on this ng ;-)


From: Mike B on
Aren't you guys having a DejaVu moment here? I'm pretty sure this function
as a procedure has been beaten into submission on several occasions over the
years.

"Tom Lavedas" <tglbatch(a)verizon.net> wrote in message
news:fd752a33-aeab-4b52-aefe-ec656d5c1da9(a)z33g2000vbb.googlegroups.com...
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


From: Mike B on

"Al Dunbar" <alandrub(a)hotmail.com> wrote in message
news:ey4kQNHALHA.3880(a)TK2MSFTNGP04.phx.gbl...
>
>
> "Tom Lavedas" <tglbatch(a)verizon.net> wrote in message
> news:fd752a33-aeab-4b52-aefe-ec656d5c1da9(a)z33g2000vbb.googlegroups.com...
>> 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.
>
> Yes, the OP's script needed the parentheses - not because he used
> functions, though, but because his script expected those functions to
> return values.
>
> /Al

I haven't seen much discussion about landing in one of the comp.lang.*
groups as an alternative...

> ps: picking as many nits as I can before the lights go out on this ng ;-)
>
>


From: Al Dunbar on
It likely has, but only for those who participated at the time, and
remembered.

/Al

"Mike B" <mDotByerley(a)VerizonDottieNettie> wrote in message
news:OTJgVYLALHA.4308(a)TK2MSFTNGP04.phx.gbl...
> Aren't you guys having a DejaVu moment here? I'm pretty sure this
> function as a procedure has been beaten into submission on several
> occasions over the years.
>
> "Tom Lavedas" <tglbatch(a)verizon.net> wrote in message
> news:fd752a33-aeab-4b52-aefe-ec656d5c1da9(a)z33g2000vbb.googlegroups.com...
> 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
>