Re: Perform OR operation on function return values


  1.    27 May 2010 #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.    27 May 2010 #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.    28 May 2010 #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.    28 May 2010 #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.    30 May 2010 #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

Similar Threads
Thread Forum
Could Not Perform This Operation Because The Default Mail Client Is Not Properly Installed
Hi, The subject says it all, how do I fix this? -- W. K. Mahler "Rough Drafts" On Sale Now Streaming 6 Song EP Online Now...
Vista mail
Return values from functions
I usually like PowerShell very much but there is one feature I absolutely hate: PowerShell returns any output within a function. I have the...
PowerShell
Error on return from function call in ASP.NET "Operation is not supported on this platform."
I am getting the following error on the return from a function call.It specically happens on the assignment of the return value from the function...
.NET General
Could not perform this operation because the default mail client..
I have Vista Home Premium (3 mos old). It was recommended that I have my admin user and then do another one for the main stuff. On the admin side,...
Vista mail
You are not authorized to perform the current operation
I purchased a new machine that came with Vista Home and IE7. I installed Visual Studio 2005, Microsoft FrontPage 2003 and Expression Web. For all...
Vista security
You do not have sufficient rights to perform this operation
I open up windows explorer and click on network. I see my print server and attemp to add a printer. I get the message you do not have sufficient...
Vista account administration
function return values, console output
I'm trying to figure out how to run msbuild in a function and have this function return true or false indicating msbuild's success or failure. Also...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 00:40.
    .