Windows Vista Forums

Re: Perform OR operation on function return values
  1. #1


    Tom Lavedas Guest

    Re: Perform OR operation on function return values

    On May 27, 5:05*pm, "M" <m...@newsgroup> wrote:

    > Hello:
    >
    > What's a simple approach for performing an OR operation on multiple callsto 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 onthe 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/d...displaylang=en



    In particular read "Function procedures, about Function procedures".
    _____________________
    Tom Lavedas

      My System SpecsSystem Spec

  2. #2


    Al Dunbar Guest

    Re: Perform OR operation on function return values



    "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

    > See the documentation:
    > WSH 5.6+ documentation download (URL all one line)
    > http://www.microsoft.com/downloads/d...displaylang=en
    >
    > In particular read "Function procedures, about Function procedures".
    > _____________________
    > Tom Lavedas

      My System SpecsSystem Spec

  3. #3


    Tom Lavedas Guest

    Re: Perform OR operation on function return values

    On May 27, 9:14*pm, "Dave \"Crash\" Dummy" <inva...@newsgroup>
    wrote:

    > Al Dunbar wrote:

    > > "Tom Lavedas" <tglba...@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.
    >
    > 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

      My System SpecsSystem Spec

  4. #4


    M Guest

    Re: Perform OR operation on function return values

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

    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/d...displaylang=en

    In particular read "Function procedures, about Function procedures".
    _____________________
    Tom Lavedas



      My System SpecsSystem Spec

  5. #5


    Al Dunbar Guest

    Re: Perform OR operation on function return values



    "Tom Lavedas" <tglbatch@newsgroup> wrote in message
    news:fd752a33-aeab-4b52-aefe-ec656d5c1da9@newsgroup

    > On May 27, 9:14 pm, "Dave \"Crash\" Dummy" <inva...@newsgroup>
    > wrote:

    >> Al Dunbar wrote:

    >> > "Tom Lavedas" <tglba...@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.
    >>
    >> 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 ;-)



      My System SpecsSystem Spec

Re: Perform OR operation on function return values problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error on return from function call in ASP.NET "Operation is not supported on this platform." news.microsoft.com .NET General 0 17 Sep 2008
Could not perform this operation because the default mail client.. Mopsy Vista mail 18 25 Jun 2008
You are not authorized to perform the current operation ChrisW Vista security 0 12 Mar 2008
You do not have sufficient rights to perform this operation BPG Vista account administration 4 04 Feb 2007
function return values, console output =?Utf-8?B?ZnV6enkzMzM=?= PowerShell 3 22 Aug 2006