<SCRIPT LANGUAGE="vbScript"> dim a a=0 document.write "a=0" document.write "<br/>sub change(byref ar)<br/>" change a document.write a a=0 document.write "<br/>sub change2(ByVal ar)<br/>" change2 a document.write a a=0 document.write "<br/>sub change3( ar)<br/>" change3 a document.write a a=0 document.write "<br/>function change4(byref ar)<br/>" change4 a document.write a a=0 document.write "<br/>function change5(ByVal ar)<br/>" change5 a document.write a a=0 document.write "<br/>function change6( ar)<br/>" change6 a document.write a a=0 sub change(byref ar) ar=111 end sub sub change2(ByVal ar) ar=222 end sub sub change3( ar) ar=333 end sub function change4(byref ar) ar=444 end function function change5(ByVal ar) ar=555 end function function change6( ar) ar=666 end function </SCRIPT>
======================= 结果: a=0 sub change(byref ar) 111 sub change2(ByVal ar) 0 sub change3( ar) 333 function change4(byref ar) 444 function change5(ByVal ar) 0 function change6( ar) 666 说明vbs默认是byRef,这点和VB一样, 按地址。
再给出一个小例子,大家运行看效果!
复制代码 代码如下:
<% Dim i,j,p,m i = 10 j = 12 Response.Write i&"******"&j&"<br>" Call Fun2 (i,j) Response.Write i&"******"&j&"<br>" i = 10 j = 12 Call Fun (i,j) Response.Write i&"*******"&j&"<br>" Function Fun2 (a,b) a = 5 b = 6 Fun2 = 0 End Function Function Fun (ByVal a,ByRef b) a = 5 b = 6 Fun = 0 End Function %>