Passing parameters - VBA
Hello Readers,
Welcome to Coding by Learning !!! 😀
Most of the programming languages has the concept of passing parameters to functions in different ways. Python, C, C++ and Java programming languages have the concept in the name of Call by value and Call by reference.
In VBA , It is arrived using keywords ByVal and ByRef.
Difference between ByVal and ByRef
Now lets see the concepts with an example
Here in the example, I have written a sub procedure for calculating sum of 2 numbers. I have created 2 functions "add2Numbers_byval" and "add2Numbers_byref" for differentiating the concepts.
Output as follows :-
Look at the output. The value of iNum2 is same using ByVal and It is modified using By Ref.
Happy learning & Happy Coding !!!
Comment and share this post to your friends and colleagues 😀
Helped me understood clearly...
ReplyDeleteThat's my pleasure :)
ReplyDeleteI face this question when in vba interview. This blog helps me to understand the concept easily.
ReplyDeleteHappy to know our blog helped you :), Thanks for the support
Delete