在asp编程中,经常需要自己编写一些函数(或过程)来实现某些特定的功能,这时往往需要向函数(或过程)传递相应的参数
在函数(或过程)中进行数据处理,即有可能需要保留或改变参数的值,下面有相关范例
用下面的函数(testaddress)就可以使一个函数多个返回值成为可能(一个函数返回值,多个参数改变后的值)
范例:
<%@language="vbscript"%>
<%
option explicit
===================================================================
参数传递
1.值传递参数 (call by value)
function testvalue(byval a,byval b)
函数内参数 a、b 改变 不影响 函数的外部变量
2.指针参数 (call by address)
function testaddress(byref a,byref b)
函数内参数 a、b 改变 影响到 函数的外部变量
说明:
1. 参数可以是数字、字符、数组、对象等vbscript语言所支持的大部分类型
2. 函数返回值的类型也可以是数字、字符、数组、对象等vbscript语言所支持的大部分类型
3. 过程调用参数方法与函数类似
===================================================================
dim a1,b1
dim a2,b2
function testvalue(byval a,byval b)
a = a + 1
b = b + 1
testvalue = a + b
end function
function testaddress(byref a,byref b)
a = a + 1
b = b + 1
testaddress = a + b
end function
a1 = 11
b1 = 33
a2 = 11
b2 = 33
response.write "初值:" & " "
response.write "a1=" & a1 & " "
response.write "b1=" & b1 & "<br>"
response.write "函数(testvalue)值:" & testvalue(a1,b1) & "<br>"
response.write "终值:" & " "
response.write "a1=" & a1 & " "
response.write "b1=" & b1 & "<br><br><br>"
response.write "初值:" & " "
response.write "a2=" & a2 & " "
response.write "b2=" & b2 & "<br>"
response.write "函数(testaddress)值:" & testaddress(a2,b2) & "<br>"
response.write "终值:" & " "
response.write "a2=" & a2 & " "
response.write "b2=" & b2
======================
相似过程
======================
sub test_value(byval a,byval b)
a = a + 1
b = b + 1
end sub
sub test_address(byref a,byref b)
a = a + 1
b = b + 1
end sub
类似,传递数组、对象(或者在函数中改变其值、属性)
’对象直接把对象名作为参数即可
数组,把数组名称作为参数
redim arytest(2,2)
dim intnum
function ary_test(byref a)
ary_test = ubound(ary_test,2)
end function
调用
intnum = ary_test(intnum) 值为 3
%>
