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.htm
廣告
© . All rights reserved.