classic asp byRef vs. byBal

J

JT

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
 
B

Bob Barrows [MVP]

JT said:
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>"
 
P

Phill. W

JT said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top