classic asp byRef vs. byBal

Discussion in 'ASP General' started by JT, Oct 20, 2005.

  1. JT

    JT Guest

    what is the default behavior of asp for passing values to a function, byRef
    or byVal? i was under the assumption that if you do not specify, then it
    defaults to passing the parameter byRef.

    so for example, the following function is accepting param1 and param2 as
    "byRef" parameters:

    function myFunction(param1,param2)
    'do something
    end function


    am i correct?

    thanks,

    jt
     
    JT, Oct 20, 2005
    #1
    1. Advertising

  2. JT wrote:
    > what is the default behavior of asp for passing values to a function,
    > byRef or byVal? i was under the assumption that if you do not
    > specify, then it defaults to passing the parameter byRef.
    >
    > so for example, the following function is accepting param1 and param2
    > as "byRef" parameters:
    >
    > function myFunction(param1,param2)
    > 'do something
    > end function
    >
    >
    > am i correct?


    It depends on how you call the function. The default is byref, but the
    method used to call the function can override this. Specifically, enclosing
    an argument in parentheses when not consuming the return value will force it
    to be passed by value (sort of):

    function test(arg)
    arg=arg + 1
    test=arg
    end function

    val = 1

    response.write "Return value discarded, parens not used: " & _
    val & "<BR>"
    test val
    response.write val & "<BR>"

    val=1
    test(val)
    response.write "Return value discarded, parens used: " _
    & val & "<BR>"

    val=1
    newval=test(val)
    response.write "Return value used, parens used: " _
    & val & "<BR>"




    --
    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.
     
    Bob Barrows [MVP], Oct 20, 2005
    #2
    1. Advertising

  3. JT

    Phill. W Guest

    "JT" <> wrote in message
    news:...
    > what is the default behavior of asp for passing values to a function,
    > byRef or byVal?

    .. . .
    > i was under the assumption that if you do not specify, then it defaults
    > to passing the parameter byRef.


    Correct.

    HTH,
    Phill W.
     
    Phill. W, Oct 20, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Goncalo

    ByVal and ByRef

    Goncalo, Dec 4, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    6,098
    Dmitriy Lapshin [C# / .NET MVP]
    Dec 4, 2003
  2. Alex Brown

    StateServer pass byref threading problem

    Alex Brown, Apr 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    351
    Alex Brown
    Apr 22, 2004
  3. Iams

    Byval vs. byref

    Iams, Feb 24, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    4,814
  4. xamman
    Replies:
    1
    Views:
    347
    Marina Levit [MVP]
    Dec 22, 2006
  5. Rob Meade

    Byref / Byval?

    Rob Meade, Dec 28, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    789
    Rob Meade
    Dec 28, 2006
Loading...

Share This Page