Quality Testing

Quality is delighting customers

What is the difference in passing values ByRef or ByVal to a function? Can you pls explain with detailed examples?

What is the difference in passing values ByRef or ByVal to a function? Can anyone pls explain with detailed examples?

 

Thanks,

Suma.

Views: 543

Reply to This

Replies to This Discussion

Hi Suma,

 

The paramerters passed to a function can be either call by value or call by ref, the default is call by ref

By Ref: If the value is changed in the function the parameter value is also changed.

By Val: If the value is changed in the function the parameter value is not changed

Eg:

dim a,b

a=10

b=20

function f1(byval x, byref y)

x=100

y=200

end function

call f1(a,b)

msgbox a&" "&b

 

output is 10, 200

Thanks vijay.

 

Hi suma,

 

welcome

http://www.qualitytesting.info/forum/topics/can-any-body-explain-ca...

 

Please refer once Forum posts,Just before post.

 

Just FYI:

If you pass any DP objects you should use ByRef.

QTP use by default ByRef.

 

--Subbu.

Hi,

Check the below link. Very good Example. 

http://www.sstutor.com/cpp/pointer2a.htm

Thanks,

Agreed with Mr.Srini Vuggumudi.

Thanks,

Shiv

In byval function we the value to the arguments

where as in byref we the reference (variable which storing the value) to the argument

 

Eg public function sum(byval a, byvalb)

sum=a+b

End function

call sum(20,30)

eg  public funcation sum(byref a,byref b)

sum =a+b

End funcation

x=10,y=20

call sum(x,y)

 

Regards,

Ramesh kongara

 

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2021   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service