sub or function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roland Hall

    sub or function

    I'm tired of getting beat up on this issue so I thought I'd ask what you
    some of you think.

    I know the basic difference between a subroutine and a function is a
    subroutine performs a task and a function performs a task and returns a
    value. The Call keyword is required when using parens with subs with more
    than 1 parameters. Parens around values passed are ByVal vs ByRef and is a
    waste of processing if passed ByRef for no reason.

    I am told there is no reason to ever use a subroutine as a function can be
    used even if it doesn't return a value. While this appears to be true, is
    there any reason why it's ever a bad idea to use a function, instead of a
    subroutine, that doesn't return a value? Are there memory, performance,
    etc. issues?

    TIA...

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp


  • Curt_C [MVP]

    #2
    Re: sub or function

    Roland Hall wrote:[color=blue]
    > I'm tired of getting beat up on this issue so I thought I'd ask what you
    > some of you think.
    >
    > I know the basic difference between a subroutine and a function is a
    > subroutine performs a task and a function performs a task and returns a
    > value. The Call keyword is required when using parens with subs with more
    > than 1 parameters. Parens around values passed are ByVal vs ByRef and is a
    > waste of processing if passed ByRef for no reason.
    >
    > I am told there is no reason to ever use a subroutine as a function can be
    > used even if it doesn't return a value. While this appears to be true, is
    > there any reason why it's ever a bad idea to use a function, instead of a
    > subroutine, that doesn't return a value? Are there memory, performance,
    > etc. issues?
    >
    > TIA...
    >[/color]

    There may be some perf loss but these days I doubt you would notice...
    Best answer is, almost always, do what you feel comfortable with as long
    as it does what you need it to.....

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com

    Comment

    • Bob Barrows [MVP]

      #3
      Re: sub or function

      Roland Hall wrote:[color=blue]
      > I'm tired of getting beat up on this issue so I thought I'd ask what
      > you some of you think.[/color]

      Somebody's beating you up about this ... ??
      [color=blue]
      >[/color]
      <snip>[color=blue]
      > I am told there is no reason to ever use a subroutine as a function
      > can be used even if it doesn't return a value. While this appears to
      > be true, is there any reason why it's ever a bad idea to use a
      > function, instead of a subroutine, that doesn't return a value? Are
      > there memory, performance, etc. issues?
      >[/color]

      As far as performance is concerned, I think Eric says it best:


      The whole "function vs sub" controversy seems to have devolved into a
      religious debate, much like the top-posters vs. inline posters...

      Back in the day of VB3, using a sub instead of a function might have made a
      difference as far as memory or performance is concerned. Nowadays, it's
      really just personal preference.

      Bob Barrows
      --
      Microsoft MVP -- ASP/ASP.NET
      Please reply to the newsgroup. The email account listed in my From
      header is my spam trap, so I don't check it very often. You will get a
      quicker response by posting to the newsgroup.


      Comment

      • Roland Hall

        #4
        Re: sub or function

        "Bob Barrows [MVP]" wrote in message
        news:OSmF%2335l FHA.2180@TK2MSF TNGP15.phx.gbl. ..
        : Roland Hall wrote:
        : > I'm tired of getting beat up on this issue so I thought I'd ask what
        : > you some of you think.
        :
        : Somebody's beating you up about this ... ??

        Two people actually because of what I said to someone else regarding their
        style of coding

        Call somefunction(pa ram1, param2)

        : > I am told there is no reason to ever use a subroutine as a function
        : > can be used even if it doesn't return a value. While this appears to
        : > be true, is there any reason why it's ever a bad idea to use a
        : > function, instead of a subroutine, that doesn't return a value? Are
        : > there memory, performance, etc. issues?
        : >
        :
        : As far as performance is concerned, I think Eric says it best:
        : http://blogs.msdn.com/ericlippert/ar.../17/53237.aspx
        :
        : The whole "function vs sub" controversy seems to have devolved into a
        : religious debate, much like the top-posters vs. inline posters...

        Is vbs now to be thought of as jscript where everything is a function?

        : Back in the day of VB3, using a sub instead of a function might have made
        a
        : difference as far as memory or performance is concerned. Nowadays, it's
        : really just personal preference.

        Are you stating there is not difference other than one can return a value?

        --
        Roland Hall
        /* This information is distributed in the hope that it will be useful, but
        without any warranty; without even the implied warranty of merchantability
        or fitness for a particular purpose. */
        Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
        WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
        MSDN Library - http://msdn.microsoft.com/library/default.asp


        Comment

        • Roland Hall

          #5
          Re: sub or function

          "Curt_C [MVP]" <software_at_da rkfalz.com> wrote in message
          news:eMX1eW5lFH A.2916@TK2MSFTN GP14.phx.gbl...
          : Roland Hall wrote:
          : > I'm tired of getting beat up on this issue so I thought I'd ask what you
          : > some of you think.
          : >
          : > I know the basic difference between a subroutine and a function is a
          : > subroutine performs a task and a function performs a task and returns a
          : > value. The Call keyword is required when using parens with subs with
          more
          : > than 1 parameters. Parens around values passed are ByVal vs ByRef and
          is a
          : > waste of processing if passed ByRef for no reason.
          : >
          : > I am told there is no reason to ever use a subroutine as a function can
          be
          : > used even if it doesn't return a value. While this appears to be true,
          is
          : > there any reason why it's ever a bad idea to use a function, instead of
          a
          : > subroutine, that doesn't return a value? Are there memory, performance,
          : > etc. issues?
          : >
          : > TIA...
          : >
          :
          : There may be some perf loss but these days I doubt you would notice...

          Would that unnoticeable difference be relevant if there were hundreds or
          thousands of users?

          : Best answer is, almost always, do what you feel comfortable with as long
          : as it does what you need it to.....

          I try but the law keeps responding with, "She must be at least 18!"

          --
          Roland Hall
          /* This information is distributed in the hope that it will be useful, but
          without any warranty; without even the implied warranty of merchantability
          or fitness for a particular purpose. */
          Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
          WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
          MSDN Library - http://msdn.microsoft.com/library/default.asp


          Comment

          • Bob Barrows [MVP]

            #6
            Re: sub or function

            Roland Hall wrote:[color=blue]
            > "Bob Barrows [MVP]" wrote in message
            > news:OSmF%2335l FHA.2180@TK2MSF TNGP15.phx.gbl. ..[color=green]
            >> Roland Hall wrote:
            >>
            >> The whole "function vs sub" controversy seems to have devolved into a
            >> religious debate, much like the top-posters vs. inline posters...[/color]
            >
            > Is vbs now to be thought of as jscript where everything is a function?[/color]

            I don't think I said that.

            It CAN be thought of that way. It doesn't have to be. I still use subs
            extensively, I'm accustomed to them - it's mainly a matter of style.
            [color=blue]
            >[color=green]
            >> Back in the day of VB3, using a sub instead of a function might have
            >> made a difference as far as memory or performance is concerned.
            >> Nowadays, it's really just personal preference.[/color]
            >
            > Are you stating there is not difference other than one can return a
            > value?[/color]

            Yeah, pretty much. The slight overhead involved in creating the memory space
            to contain the returned value (in the case of functions) is avoided when
            using a sub. And at some time in the past, perhaps that difference may have
            noticeable in VB. But not with today's machines. And definitely not with
            vbscript which has many more performance issues than using subs vs
            functions.

            There is one advantage to using functions: with a function, you can return a
            boolean to indicate the success/failure of the procedure. With a sub, you
            either have to raise an error or use an extra ByRef argument to let the
            calling procedure know about the sub's outcome. Raising errors definitely
            definitely has a performance impact: much more than using a function instead
            of a sub.

            Also, using functions exclusively will make the transition to jscript or C#
            a little easier (not much, but a little).

            Bob Barrows

            --
            Microsoft MVP - ASP/ASP.NET
            Please reply to the newsgroup. This email account is my spam trap so I
            don't check it very often. If you must reply off-line, then remove the
            "NO SPAM"


            Comment

            • CJM

              #7
              Re: sub or function

              The only thing I can add to Bob's post is that one advantage of using both
              Subs & Functions is that there is a little greater clarity. You can expect a
              return from a Function but not from a Sub, so it's arguably a little easier
              to debug - you know what to expect. Ok, it's not the greatest advantage, but
              it can help!

              CJM


              Comment

              • Roland Hall

                #8
                Re: sub or function

                "CJM" wrote in message news:u9a$QCCmFH A.4056@TK2MSFTN GP10.phx.gbl...
                : The only thing I can add to Bob's post is that one advantage of using both
                : Subs & Functions is that there is a little greater clarity. You can expect
                a
                : return from a Function but not from a Sub, so it's arguably a little
                easier
                : to debug - you know what to expect. Ok, it's not the greatest advantage,
                but
                : it can help!

                Well, I thought there was a memory issue although negligible, it increases
                with each concurrent user. I see no reason to waste memory just because I
                can. And you stated it as I use them to know a sub is not going to return a
                value and a function will return one so it IS easier to read and debug, at
                least for me.

                --
                Roland Hall
                /* This information is distributed in the hope that it will be useful, but
                without any warranty; without even the implied warranty of merchantability
                or fitness for a particular purpose. */
                Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
                WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
                MSDN Library - http://msdn.microsoft.com/library/default.asp


                Comment

                • Roland Hall

                  #9
                  Re: sub or function

                  "Bob Barrows [MVP]" wrote in message
                  news:Olf%23ltBm FHA.3300@TK2MSF TNGP15.phx.gbl. ..
                  : Roland Hall wrote:
                  : > "Bob Barrows [MVP]" wrote in message
                  : > news:OSmF%2335l FHA.2180@TK2MSF TNGP15.phx.gbl. ..
                  : >> Roland Hall wrote:
                  : >>
                  : >> The whole "function vs sub" controversy seems to have devolved into a
                  : >> religious debate, much like the top-posters vs. inline posters...
                  : >
                  : > Is vbs now to be thought of as jscript where everything is a function?
                  :
                  : I don't think I said that.

                  Ok, but if your nose starts to grow...

                  : It CAN be thought of that way. It doesn't have to be. I still use subs
                  : extensively, I'm accustomed to them - it's mainly a matter of style.

                  Outside of mainly...?

                  : >> Back in the day of VB3, using a sub instead of a function might have
                  : >> made a difference as far as memory or performance is concerned.
                  : >> Nowadays, it's really just personal preference.

                  See the first question.

                  : > Are you stating there is not difference other than one can return a
                  : > value?
                  :
                  : Yeah, pretty much. The slight overhead involved in creating the memory
                  space
                  : to contain the returned value (in the case of functions) is avoided when
                  : using a sub. And at some time in the past, perhaps that difference may
                  have
                  : noticeable in VB. But not with today's machines. And definitely not with
                  : vbscript which has many more performance issues than using subs vs
                  : functions.

                  So, this is still no longer an issue in VB either?

                  : There is one advantage to using functions: with a function, you can return
                  a
                  : boolean to indicate the success/failure of the procedure. With a sub, you
                  : either have to raise an error or use an extra ByRef argument to let the
                  : calling procedure know about the sub's outcome. Raising errors definitely
                  : definitely has a performance impact: much more than using a function
                  instead
                  : of a sub.
                  :
                  : Also, using functions exclusively will make the transition to jscript or
                  C#
                  : a little easier (not much, but a little).

                  Transition to jscript? Do you know something? Is everything VB related
                  going away?

                  --
                  Roland Hall
                  /* This information is distributed in the hope that it will be useful, but
                  without any warranty; without even the implied warranty of merchantability
                  or fitness for a particular purpose. */
                  Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
                  WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
                  MSDN Library - http://msdn.microsoft.com/library/default.asp


                  Comment

                  • Bob Barrows [MVP]

                    #10
                    Re: sub or function

                    Roland Hall wrote:[color=blue]
                    > "Bob Barrows [MVP]" wrote in message
                    > news:Olf%23ltBm FHA.3300@TK2MSF TNGP15.phx.gbl. ..[color=green]
                    >> Roland Hall wrote:[color=darkred]
                    >>> "Bob Barrows [MVP]" wrote in message
                    >>> news:OSmF%2335l FHA.2180@TK2MSF TNGP15.phx.gbl. ..
                    >>>> Roland Hall wrote:
                    >>>>
                    >>>> The whole "function vs sub" controversy seems to have devolved
                    >>>> into a religious debate, much like the top-posters vs. inline
                    >>>> posters...
                    >>>
                    >>> Is vbs now to be thought of as jscript where everything is a
                    >>> function?[/color]
                    >>
                    >> I don't think I said that.[/color]
                    >
                    > Ok, but if your nose starts to grow...[/color]

                    Why?
                    [color=blue]
                    >[color=green]
                    >> It CAN be thought of that way. It doesn't have to be. I still use
                    >> subs extensively, I'm accustomed to them - it's mainly a matter of
                    >> style.[/color]
                    >
                    > Outside of mainly...?[/color]

                    Huh?
                    [color=blue]
                    >[color=green][color=darkred]
                    >>>> Back in the day of VB3, using a sub instead of a function might
                    >>>> have made a difference as far as memory or performance is
                    >>>> concerned. Nowadays, it's really just personal preference.[/color][/color]
                    >
                    > See the first question.[/color]

                    Why? How can this be translated into "Is vbs now to be thought of as jscript
                    where everything is a function?"
                    Maybe I'm misinterpreting that question ... the phrase "to be thought of"
                    has overtones of "must be thought of". Did you mean it that way? Or did you
                    mean it more like "can vbs be thought of ... "?
                    [color=blue]
                    >[color=green][color=darkred]
                    >>> Are you stating there is not difference other than one can return a
                    >>> value?[/color]
                    >>
                    >> Yeah, pretty much. The slight overhead involved in creating the
                    >> memory space to contain the returned value (in the case of
                    >> functions) is avoided when using a sub. And at some time in the
                    >> past, perhaps that difference may have noticeable in VB. But not
                    >> with today's machines. And definitely not with vbscript which has
                    >> many more performance issues than using subs vs functions.[/color]
                    >
                    > So, this is still no longer an issue in VB either?[/color]

                    Since VB is compiled, then yes, it may be more of an issue in VB than in
                    vbscript. However, there are likely to be many more things to worry about
                    than this, even in VB. It's a little harder to write an application without
                    subs in VB because all the generated event handlers are created as subs.
                    [color=blue]
                    >[color=green]
                    >> There is one advantage to using functions: with a function, you can
                    >> return a boolean to indicate the success/failure of the procedure.
                    >> With a sub, you either have to raise an error or use an extra ByRef
                    >> argument to let the calling procedure know about the sub's outcome.
                    >> Raising errors definitely definitely has a performance impact: much
                    >> more than using a function instead of a sub.
                    >>
                    >> Also, using functions exclusively will make the transition to
                    >> jscript or C# a little easier (not much, but a little).[/color]
                    >
                    > Transition to jscript? Do you know something? Is everything VB
                    > related going away?
                    >[/color]
                    Nope, you've read a little too much into my statement. I should have said:
                    "IF you are going to learn another language such as jscript, C#, etc., then
                    the transition will be slightly easier ... "

                    Bob

                    --
                    Microsoft MVP -- ASP/ASP.NET
                    Please reply to the newsgroup. The email account listed in my From
                    header is my spam trap, so I don't check it very often. You will get a
                    quicker response by posting to the newsgroup.


                    Comment

                    • !TG

                      #11
                      Re: sub or function

                      Roland Hall wrote:[color=blue]
                      > I'm tired of getting beat up on this issue so I thought I'd ask what you
                      > some of you think.
                      >
                      > I know the basic difference between a subroutine and a function is a
                      > subroutine performs a task and a function performs a task and returns a
                      > value. The Call keyword is required when using parens with subs with more
                      > than 1 parameters. Parens around values passed are ByVal vs ByRef and is a
                      > waste of processing if passed ByRef for no reason.
                      >
                      > I am told there is no reason to ever use a subroutine as a function can be
                      > used even if it doesn't return a value. While this appears to be true, is
                      > there any reason why it's ever a bad idea to use a function, instead of a
                      > subroutine, that doesn't return a value? Are there memory, performance,
                      > etc. issues?
                      >
                      > TIA...
                      >[/color]

                      Subs will change values of preexisting variables if you use the same
                      generic variables by habit.
                      Depending on the purpose, this can be an advantage or trouble.

                      I personally use Subs for mostly simple display tasks and functions for
                      more complicated work.

                      Comment

                      • Roland Hall

                        #12
                        Re: sub or function

                        "Bob Barrows [MVP]" wrote in message
                        news:ek3G2REmFH A.2080@TK2MSFTN GP10.phx.gbl...
                        : Roland Hall wrote:
                        : > "Bob Barrows [MVP]" wrote in message
                        : > news:Olf%23ltBm FHA.3300@TK2MSF TNGP15.phx.gbl. ..
                        : >> Roland Hall wrote:
                        : >>> "Bob Barrows [MVP]" wrote in message
                        : >>> news:OSmF%2335l FHA.2180@TK2MSF TNGP15.phx.gbl. ..
                        : >>>> Roland Hall wrote:
                        : >>>>
                        : >>>> The whole "function vs sub" controversy seems to have devolved
                        : >>>> into a religious debate, much like the top-posters vs. inline
                        : >>>> posters...
                        : >>>
                        : >>> Is vbs now to be thought of as jscript where everything is a
                        : >>> function?
                        : >>
                        : >> I don't think I said that.
                        : >
                        : > Ok, but if your nose starts to grow...
                        :
                        : Why?

                        I said, IF.

                        : >> It CAN be thought of that way. It doesn't have to be. I still use
                        : >> subs extensively, I'm accustomed to them - it's mainly a matter of
                        : >> style.
                        : >
                        : > Outside of mainly...?
                        :
                        : Huh?

                        If it's mainly a matter of style, what else matters?

                        : >>>> Back in the day of VB3, using a sub instead of a function might
                        : >>>> have made a difference as far as memory or performance is
                        : >>>> concerned. Nowadays, it's really just personal preference.
                        : >
                        : > See the first question.
                        :
                        : Why? How can this be translated into "Is vbs now to be thought of as
                        jscript
                        : where everything is a function?"
                        : Maybe I'm misinterpreting that question ... the phrase "to be thought of"
                        : has overtones of "must be thought of". Did you mean it that way? Or did
                        you
                        : mean it more like "can vbs be thought of ... "?

                        'can' could probably work but probably my meaning was 'should'
                        Should I just use functions and eliminate the use of subs in vbscript?
                        (remove the arguments for readability and negligible memory loss)

                        : >>> Are you stating there is not difference other than one can return a
                        : >>> value?
                        : >>
                        : >> Yeah, pretty much. The slight overhead involved in creating the
                        : >> memory space to contain the returned value (in the case of
                        : >> functions) is avoided when using a sub. And at some time in the
                        : >> past, perhaps that difference may have noticeable in VB. But not
                        : >> with today's machines. And definitely not with vbscript which has
                        : >> many more performance issues than using subs vs functions.
                        : >
                        : > So, this is still no longer an issue in VB either?
                        :
                        : Since VB is compiled, then yes, it may be more of an issue in VB than in
                        : vbscript. However, there are likely to be many more things to worry about
                        : than this, even in VB. It's a little harder to write an application
                        without
                        : subs in VB because all the generated event handlers are created as subs.

                        This is the type of answer I was looking for. I guess you're saying
                        vbscript doesn't have requirements like this.

                        : > Transition to jscript? Do you know something? Is everything VB
                        : > related going away?
                        : >
                        : Nope, you've read a little too much into my statement. I should have said:
                        : "IF you are going to learn another language such as jscript, C#, etc.,
                        then
                        : the transition will be slightly easier ... "

                        Nah, I was just yanking your chain on this question. Wonder how many MSFT
                        emps read it and said, "Ya', what has he heard?" or "Aw crap! Cats outta'
                        the bag."

                        --
                        Roland Hall
                        /* This information is distributed in the hope that it will be useful, but
                        without any warranty; without even the implied warranty of merchantability
                        or fitness for a particular purpose. */
                        Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
                        WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
                        MSDN Library - http://msdn.microsoft.com/library/default.asp


                        Comment

                        • Roland Hall

                          #13
                          Re: sub or function

                          "!TG" wrote in message news:%23inB%23d FmFHA.2080@TK2M SFTNGP14.phx.gb l...
                          : Roland Hall wrote:
                          : > I'm tired of getting beat up on this issue so I thought I'd ask what you
                          : > some of you think.
                          : >
                          : > I know the basic difference between a subroutine and a function is a
                          : > subroutine performs a task and a function performs a task and returns a
                          : > value. The Call keyword is required when using parens with subs with
                          more
                          : > than 1 parameters. Parens around values passed are ByVal vs ByRef and
                          is a
                          : > waste of processing if passed ByRef for no reason.
                          : >
                          : > I am told there is no reason to ever use a subroutine as a function can
                          be
                          : > used even if it doesn't return a value. While this appears to be true,
                          is
                          : > there any reason why it's ever a bad idea to use a function, instead of
                          a
                          : > subroutine, that doesn't return a value? Are there memory, performance,
                          : > etc. issues?
                          : >
                          : > TIA...
                          : >
                          :
                          : Subs will change values of preexisting variables if you use the same
                          : generic variables by habit.
                          : Depending on the purpose, this can be an advantage or trouble.

                          Are you saying a passed variable to a sub, if the value changes will change
                          the value of a global variable? Isn't that only true if it's passed ByRef?

                          --
                          Roland Hall
                          /* This information is distributed in the hope that it will be useful, but
                          without any warranty; without even the implied warranty of merchantability
                          or fitness for a particular purpose. */
                          Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
                          WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
                          MSDN Library - http://msdn.microsoft.com/library/default.asp


                          Comment

                          • CJM

                            #14
                            Re: sub or function


                            "Roland Hall" <nobody@nowhere > wrote in message
                            news:OZjYjXHmFH A.2180@TK2MSFTN GP15.phx.gbl...[color=blue]
                            >
                            > Are you saying a passed variable to a sub, if the value changes will
                            > change
                            > the value of a global variable? Isn't that only true if it's passed
                            > ByRef?
                            >[/color]

                            From MSDN:


                            "Variables used in Sub procedures fall into two categories: those that are
                            explicitly declared within the procedure and those that are not. Variables
                            that are explicitly declared in a procedure (using Dim or the equivalent)
                            are always local to the procedure. Variables that are used but not
                            explicitly declared in a procedure are also local, unless they are
                            explicitly declared at some higher level outside the procedure.

                            Caution A procedure can use a variable that is not explicitly declared in
                            the procedure, but a naming conflict can occur if anything you have defined
                            at the script level has the same name. If your procedure refers to an
                            undeclared variable that has the same name as another procedure, constant or
                            variable, it is assumed that your procedure is referring to that
                            script-level name. To avoid this kind of conflict, use an Option Explicit
                            statement to force explicit declaration of variables."

                            I'm not sure this quote entirely answers the question, but it was
                            interesting anyway. But as I see it, if you pass a Global variable ByVal it
                            is treated as a local variable; if you pass it ByRef, any changes are
                            reflected in the calling procedure - which means that if the variable had
                            Global scope it would be changed throughout the application. Which I'm
                            guessing was you original understanding?

                            However, if you were talking about a Global variable, there would be no
                            reason to pass it as a parameter because it already accessible because it
                            is...er.. Global!

                            I hope this hasn't muddied the water any further!

                            Chris



                            Comment

                            • Bob Lehmann

                              #15
                              Re: sub or function

                              >> Isn't that only true if it's passed ByRef?
                              The default is ByRef in VBScript. So, unless you you explicitly pass it
                              ByVal, it will be changed.

                              Bob Lehmann

                              "Roland Hall" <nobody@nowhere > wrote in message
                              news:OZjYjXHmFH A.2180@TK2MSFTN GP15.phx.gbl...[color=blue]
                              > "!TG" wrote in message news:%23inB%23d FmFHA.2080@TK2M SFTNGP14.phx.gb l...
                              > : Roland Hall wrote:
                              > : > I'm tired of getting beat up on this issue so I thought I'd ask what[/color]
                              you[color=blue]
                              > : > some of you think.
                              > : >
                              > : > I know the basic difference between a subroutine and a function is a
                              > : > subroutine performs a task and a function performs a task and returns[/color]
                              a[color=blue]
                              > : > value. The Call keyword is required when using parens with subs with
                              > more
                              > : > than 1 parameters. Parens around values passed are ByVal vs ByRef and
                              > is a
                              > : > waste of processing if passed ByRef for no reason.
                              > : >
                              > : > I am told there is no reason to ever use a subroutine as a function[/color]
                              can[color=blue]
                              > be
                              > : > used even if it doesn't return a value. While this appears to be[/color]
                              true,[color=blue]
                              > is
                              > : > there any reason why it's ever a bad idea to use a function, instead[/color]
                              of[color=blue]
                              > a
                              > : > subroutine, that doesn't return a value? Are there memory,[/color]
                              performance,[color=blue]
                              > : > etc. issues?
                              > : >
                              > : > TIA...
                              > : >
                              > :
                              > : Subs will change values of preexisting variables if you use the same
                              > : generic variables by habit.
                              > : Depending on the purpose, this can be an advantage or trouble.
                              >
                              > Are you saying a passed variable to a sub, if the value changes will[/color]
                              change[color=blue]
                              > the value of a global variable? Isn't that only true if it's passed[/color]
                              ByRef?[color=blue]
                              >
                              > --
                              > Roland Hall
                              > /* This information is distributed in the hope that it will be useful, but
                              > without any warranty; without even the implied warranty of merchantability
                              > or fitness for a particular purpose. */
                              > Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
                              > WSH 5.6 Documentation -[/color]
                              http://msdn.microsoft.com/downloads/list/webdev.asp[color=blue]
                              > MSDN Library - http://msdn.microsoft.com/library/default.asp
                              >
                              >[/color]


                              Comment

                              Working...