asp中Byval与Byref的区别(5)
' 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
%>
内容版权声明:除非注明,否则皆为本站原创文章。