[thelist] Friday Freebie
Scott Dexter
sgd at thinksafely.org
Fri Jul 28 17:24:09 CDT 2000
<tip type="ASP,VBScript" Subject"Multiple Return Values">
So you've got this kick ass function you've written, and you're ready to
start using it, only about 3/4 of the way into coding that first
function call you realize that you need more than one value back from
it.
Shit. What to do? --Take a cue from SQL: output parameters.
First an example, then explination
<%
Dim result1, result2
result2 = 0
function kickass(byval strInput, byref out1)
start = Now
for i=0 to 10000000
' think about it
next
strtmp = Replace(strInput, "$", "£")
kickass = Replace(strtmp, "dollars","pounds")
endt = Now
out1= datediff("s", start, endt)
end function
strowe = "You owe me $1 billion dollars."
result1 = kickass(strowe, result2)
pageout = strowe & "<BR>Wait. No you don't. I changed my mind."
pageout = pageout & "<BR>" & result1
pageout = pageout & "<br>(It took me " & result2 & " seconds to
decide.)"
%>
By passing result2 *by reference* we're allowing the function to change
the value. If you run this code, the value will be non-zero (on my
machine, 8 seconds).
Also, if you ever had a hard time understanding the difference between
passing parameters by value and by reference, this should clear things
up some.
</tip>
sgd
--
think safely
More information about the thelist
mailing list