Monday, January 14, 2013

About ByVal & ByRef

About ByVal & ByRef
  • If argument is variable, array or array element, vb script use ByRef method.
  • If argument is expression then vbscript use ByVal method
  • By default, argument passed to function and subroutine by reference, that is the address of the argument is provided to the function or subroutine.
Example- By Ref
function fun1(ByRef a)
a=a+1
end function
dim x
x=3
call fun1(x)
msgbox x
- output will be 4

Example - ByVal
function fun1(ByVal a)
a=a+1
end function
dim x
x=3
call fun1(x)
msgbox x
-output will be 3

No comments:

Post a Comment