VBScript ByRef 参数

什么是 ByRef 参数?

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

示例

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         Function fnadd(ByRef num1, ByRef 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 4
The value of y is 5

vbscript_procedures.html