欢迎光临
我们一直在努力

ASP中函数调用对参数的影响

建站超值云服务器,限时71元/月

在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 "初值:" & "&nbsp;"

response.write "a1=" & a1 & "&nbsp;"

response.write "b1=" & b1 & "<br>"

response.write "函数(testvalue)值:" & testvalue(a1,b1) & "<br>"

response.write "终值:" & "&nbsp;"

response.write "a1=" & a1 & "&nbsp;"

response.write "b1=" & b1 & "<br><br><br>"

response.write "初值:" & "&nbsp;"

response.write "a2=" & a2 & "&nbsp;"

response.write "b2=" & b2 & "<br>"

response.write "函数(testaddress)值:" & testaddress(a2,b2) & "<br>"

response.write "终值:" & "&nbsp;"

response.write "a2=" & a2 & "&nbsp;"

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

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP中函数调用对参数的影响
分享到: 更多 (0)

相关推荐

  • 暂无文章