VBScript高级:ByVal-按值传递参数

什么是ByVal参数?

如果指定了ByVal,则在调用函数或过程时,参数将作为副值发送。

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         Function fnadd(Byval num1, Byval num2)
            num1 = 4
            num2 = 5
         End Function
          
         Dim x,y
         x = 6
         y = 4
         res = fnadd(x,y)
         
         document.write("The value of x is " & x & "<br />")
         document.write("The value of y is " & y & "<br />")
       
      </script>
   </body>
</html>

上面的函数将参数x和y作为值。因此,在执行功能后,值不变。

如果上述功能另存为.html并在IE中执行,则输出如下-

The value of x is 6
The value of y is 4

作者:terry,如若转载,请注明出处:https://www.web176.com/vbscript/1107.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2020年12月4日 下午7:23
下一篇 2020年12月7日 上午11:39

相关推荐

发表回复

登录后才能评论