VBScript ByRef Parameters



What are ByRef Parameters?

If ByRef is specified, then the arguments are sent as a reference when the function or procedure is called.

Example

<!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>

The above function takes the parameter x and y as by reference. Hence, after executing the function, the values are changed.

If the above function is saved as .html and executed in IE, the output would be as follows −

The value of x is 4
The value of y is 5
vbscript_procedures.htm
Advertisements