VBScript – ByRef Parameters

VBScript : ByRef Parameters

Whenever a function gets called, If ByRef is specified then the arguments are sent as a reference.

Example :

<!DOCTYPE html>
<script language="vbscript" type="text/vbscript">

Function updateValue(ByRef num1, ByRef num2)
   num1 = 11
   num2 = 22
End Function
 Dim n1,n2
 res= updateValue(n1,n2)
 document.write("The value of n1 is " & n1 & "<br />")
 document.write("The value of n2 is " & n2 & "<br />")

Output :

The value of n1 is 11
The value of n2 is 22

Explanation :

In the above example, updateValue() function accepts two parameters using ByRef. It means that calling function has passed both he arguments by reference. Upon execution of the function following output will be printed –

The value of n1 is 11
The value of n2 is 22

before calling function values of n1,n2 were 1 and 2 respectively and after function call values gets changed.