VBScript – ByVal Parameters



VBScript : ByVal Parameters

Whenever a function or procedure gets called, If ByVal is specified then the arguments are sent as a value.

Example :

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

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

Output :

The value of n1 is 1
The value of n2 is 2

Explanation :

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

The value of n1 is 1
The value of n2 is 2

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

See how parameter passing scheme works in case of pass by value –

Local copy of variable is created and is passed to the function then any operations performed on variable in called procedure or function will not affect the value of original copy