Sunday 25 August 2013

How to use ByRef parameter calling in Vb Scripting.

Most of the time automation personnel don't use the ByRef parameter functionality.
They use normal function calling with which is by default byVal.

Now actually most of the time tester don't know these two feature.so first I m gonna explain there two one by one.

1.ByVal Function calling.

Syntax:

var1=ADD(parameter1,parameter2)




Function ADD(val1,val2)

 val1=val1+1
  ADD=val1+val2


End Function


Function ADD(ByVal val1,ByVal val2)

 val1=val1+1
  ADD=val1+val2


End Function


now in this case the parameter calling is ByVal.In fact both of the statements are identical.

when we byval prefix , it means only a copy of the parameter is going within the function.Any Changes made within  the parameter wont reflect the in the actual called value.
but if we use below syntax


var1=ADD(parameter1,parameter2)
Function ADD(ByRef val1,val2)

 val1=val1+1
  ADD=val1+val2


End Function


in this case any changes made in val1 will reflect in parameter1 too.



No comments:

Post a Comment