Using sub with byref Param or Function return value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ghislain Tanguay

    Using sub with byref Param or Function return value

    Hi! I'm maybe from old school but, for me, whebn it's time to call a method
    from DCOM, remoting or web service returning a
    string or anything else I use a function. It's more verbose.

    In my new company, much of my coworker works with Public sub ( byval Itemx
    as integer, byref returnCode as Integer).

    I don't understand why they use this kind of sub and i'm wondering if this
    kind of sub take more time to response?

    So, my question is, I have to debate this point tomorrow PM, is there any
    good raison why we should prefer function to sub with a byref when byref
    variable only seve to return a value?

    Tks


  • Ken Dopierala Jr.

    #2
    Re: Using sub with byref Param or Function return value

    Hi,

    The biggest thing is that if you are using a web service you can't call
    ByRef. So the returnCode would never be valid in those situations. Also I
    don't return error codes. An error is caught in the object and then either
    handled or thrown back up to the calling routine. Returning error codes
    forces you to test for errors at every single line of code that makes the
    call. Using a centralized Error Handling system will make life a lot
    easier. Good luck! Ken.

    --
    Ken Dopierala Jr.
    For great ASP.Net web hosting try:
    Small business web hosting offering additional business services such as: domain name registrations, email accounts, web services, online community resources and various small business solutions.

    If you sign up under me and need help, email me.

    "Ghislain Tanguay" <ghislaintangua y3DELETETHISPAR T@hotmail.com> wrote in
    message news:%23io06xgt EHA.2536@TK2MSF TNGP10.phx.gbl. ..[color=blue]
    > Hi! I'm maybe from old school but, for me, whebn it's time to call a[/color]
    method[color=blue]
    > from DCOM, remoting or web service returning a
    > string or anything else I use a function. It's more verbose.
    >
    > In my new company, much of my coworker works with Public sub ( byval Itemx
    > as integer, byref returnCode as Integer).
    >
    > I don't understand why they use this kind of sub and i'm wondering if this
    > kind of sub take more time to response?
    >
    > So, my question is, I have to debate this point tomorrow PM, is there any
    > good raison why we should prefer function to sub with a byref when byref
    > variable only seve to return a value?
    >
    > Tks
    >
    >[/color]


    Comment

    • Marina

      #3
      Re: Using sub with byref Param or Function return value

      It is clearer as to what the intent of a function is, vs that of a sub with
      a byref parameter. I have no idea why anyone would make it so difficult to
      get a return value by using byref parameters with a sub, instead of
      returning the result in a function.

      Also, using subs you can't nest function calls - you have to have a separate
      line of code for each function call, since you need to pass in the variable,
      instead of just the result of a function call.

      "Ghislain Tanguay" <ghislaintangua y3DELETETHISPAR T@hotmail.com> wrote in
      message news:%23io06xgt EHA.2536@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > Hi! I'm maybe from old school but, for me, whebn it's time to call a[/color]
      method[color=blue]
      > from DCOM, remoting or web service returning a
      > string or anything else I use a function. It's more verbose.
      >
      > In my new company, much of my coworker works with Public sub ( byval Itemx
      > as integer, byref returnCode as Integer).
      >
      > I don't understand why they use this kind of sub and i'm wondering if this
      > kind of sub take more time to response?
      >
      > So, my question is, I have to debate this point tomorrow PM, is there any
      > good raison why we should prefer function to sub with a byref when byref
      > variable only seve to return a value?
      >
      > Tks
      >
      >[/color]


      Comment

      • Imran Koradia

        #4
        Re: Using sub with byref Param or Function return value

        Both techniques have their own uses. You would a pass parameter ByRef if you
        already have some value in it and want the procedure to return a modified
        value. Another place where you would use ByRef variables is if you want to
        return multiple values - since a function can return only one value, one
        would usually change it to a sub and pass in the parameters as ByRef so you
        have sort of 'multiple return values'. For most other purposes, ByVal would
        be the way to go. Also, performance is not really an issue between the two,
        AFAIK. So, that should definitely not be a criteria for using one over the
        other. Another point to note is that we are talking about value types here.
        For reference types, ByVal and ByRef behave differently.




        hope that helps..
        Imran.

        "Ghislain Tanguay" <ghislaintangua y3DELETETHISPAR T@hotmail.com> wrote in
        message news:%23io06xgt EHA.2536@TK2MSF TNGP10.phx.gbl. ..[color=blue]
        > Hi! I'm maybe from old school but, for me, whebn it's time to call a[/color]
        method[color=blue]
        > from DCOM, remoting or web service returning a
        > string or anything else I use a function. It's more verbose.
        >
        > In my new company, much of my coworker works with Public sub ( byval Itemx
        > as integer, byref returnCode as Integer).
        >
        > I don't understand why they use this kind of sub and i'm wondering if this
        > kind of sub take more time to response?
        >
        > So, my question is, I have to debate this point tomorrow PM, is there any
        > good raison why we should prefer function to sub with a byref when byref
        > variable only seve to return a value?
        >
        > Tks
        >
        >[/color]


        Comment

        • Ghislain Tanguay

          #5
          Re: Using sub with byref Param or Function return value

          Tks Ken,

          Acutally I use a Try catch Error and throw a new SoapError.

          But the point is, they use byref in webservice and it's ok too! There is no
          problem using byref parameter with web service. The wsdl created will
          transform those parameters
          for an inout parameter.




          "Ken Dopierala Jr." <kdopierala2@wi .rr.com> a écrit dans le message de
          news:%23WVTW2gt EHA.3188@TK2MSF TNGP15.phx.gbl. ..[color=blue]
          > Hi,
          >
          > The biggest thing is that if you are using a web service you can't call
          > ByRef. So the returnCode would never be valid in those situations. Also[/color]
          I[color=blue]
          > don't return error codes. An error is caught in the object and then[/color]
          either[color=blue]
          > handled or thrown back up to the calling routine. Returning error codes
          > forces you to test for errors at every single line of code that makes the
          > call. Using a centralized Error Handling system will make life a lot
          > easier. Good luck! Ken.
          >
          > --
          > Ken Dopierala Jr.
          > For great ASP.Net web hosting try:
          > http://www.webhost4life.com/default.asp?refid=Spinlight
          > If you sign up under me and need help, email me.
          >
          > "Ghislain Tanguay" <ghislaintangua y3DELETETHISPAR T@hotmail.com> wrote in
          > message news:%23io06xgt EHA.2536@TK2MSF TNGP10.phx.gbl. ..[color=green]
          > > Hi! I'm maybe from old school but, for me, whebn it's time to call a[/color]
          > method[color=green]
          > > from DCOM, remoting or web service returning a
          > > string or anything else I use a function. It's more verbose.
          > >
          > > In my new company, much of my coworker works with Public sub ( byval[/color][/color]
          Itemx[color=blue][color=green]
          > > as integer, byref returnCode as Integer).
          > >
          > > I don't understand why they use this kind of sub and i'm wondering if[/color][/color]
          this[color=blue][color=green]
          > > kind of sub take more time to response?
          > >
          > > So, my question is, I have to debate this point tomorrow PM, is there[/color][/color]
          any[color=blue][color=green]
          > > good raison why we should prefer function to sub with a byref when byref
          > > variable only seve to return a value?
          > >
          > > Tks
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Ghislain Tanguay

            #6
            Re: Using sub with byref Param or Function return value

            For returning multiples values, I usually return an object, so my function
            can do the job.



            "Ghislain Tanguay" <ghislaintangua y3DELETETHISPAR T@hotmail.com> a écrit dans
            le message de news:%23io06xgt EHA.2536@TK2MSF TNGP10.phx.gbl. ..[color=blue]
            > Hi! I'm maybe from old school but, for me, whebn it's time to call a[/color]
            method[color=blue]
            > from DCOM, remoting or web service returning a
            > string or anything else I use a function. It's more verbose.
            >
            > In my new company, much of my coworker works with Public sub ( byval Itemx
            > as integer, byref returnCode as Integer).
            >
            > I don't understand why they use this kind of sub and i'm wondering if this
            > kind of sub take more time to response?
            >
            > So, my question is, I have to debate this point tomorrow PM, is there any
            > good raison why we should prefer function to sub with a byref when byref
            > variable only seve to return a value?
            >
            > Tks
            >
            >[/color]


            Comment

            Working...