VBScript ByVal Parameters



What are ByVal Parameters?

If ByVal is specified, then the arguments are sent as byvalue when the function or procedure is called.

Example

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

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

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

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